Newer
Older
GHFX_REFACTOR / Forms / FrmRanQiEdit.cs
wxn on 2 Nov 2016 15 KB 提交
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using GeoScene.Data;
using GeoScene.Globe;
namespace PipeLine.Forms
{
    public partial class FrmRanQiEdit : DevComponents.DotNetBar.Office2007Form
    {
        private GSOFeature feat;
        private GSOGeoPolyline3D line;
        private string pipeLineName = "燃气管线";
        private GSOLayer m_layer;
        private GSOGlobeControl m_GlobeControl;
        private GSOFeature feat_old;
        public FrmRanQiEdit(GSOFeature feature, GSOLayer layer, GSOGlobeControl globe)
        {
            InitializeComponent();
            feat = feature;
            m_layer = layer;
            feat_old = feature;
            feat_old.CopyModifyFlag(feature);
            m_GlobeControl = globe;
            line = feature.Geometry as GSOGeoPolyline3D;
        }

        private void FrmRanQiEdit_Load(object sender, EventArgs e)
        {
            try
            {
                //材质
                string sqltype1 = "select distinct 材质 from " + pipeLineName + "";
                DataTable table1 = OledbHelper.QueryTable(sqltype1);
                combMaterial.Items.Add("无");
                for (int j = 0; j < table1.Rows.Count; j++)
                {
                    DataRow dr = table1.Rows[j];
                    string colString1 = dr[0].ToString();
                    if (colString1 == null || colString1.Trim() == "")
                        continue;
                    combMaterial.Items.Add(colString1);
                }

                string sqltype2 = "select distinct 埋设方式 from " + pipeLineName + "";
                DataTable table2 = OledbHelper.QueryTable(sqltype2);
                combMaiShe.Items.Add("无");
                for (int k = 0; k < table2.Rows.Count; k++)
                {
                    DataRow dr = table2.Rows[k];
                    string colString1 = dr[0].ToString();
                    if (colString1 == null || colString1.Trim() == "")
                        continue;
                    combMaiShe.Items.Add(colString1);
                }

                string sqltype3 = "select distinct 是否废弃 from " + pipeLineName + "";
                DataTable table3 = OledbHelper.QueryTable(sqltype3);
                combUse.Items.Add("无");
                for (int h = 0; h < table3.Rows.Count; h++)
                {
                    DataRow dr = table3.Rows[h];
                    string colString1 = dr[0].ToString();
                    if (colString1 == null || colString1.Trim() == "")
                        continue;
                    combUse.Items.Add(colString1);
                }
                if (feat.GetValue("建设年代") != null)
                {
                    dateBuild.Value = Convert.ToDateTime(feat.GetValue("建设年代"));
                }
                txtBianHao.Text = feat.GetValue("编号").ToString();
                txtBianMa.Text = feat.GetValue("管线编码").ToString();
                txtGuanJing.Text = feat.GetValue("管径_毫米").ToString();
                combMaterial.SelectedItem = feat.GetValue("材质");
                combMaiShe.SelectedItem = feat.GetValue("埋设方式");
                txtYali.Text = feat.GetValue("压力").ToString();
                combUse.SelectedItem = feat.GetValue("是否废弃");
                txtDEM1.Text = feat.GetValue("起始地面高程").ToString();
                txtDeep1.Text = feat.GetValue("起始埋深").ToString();
                txtDEMDing1.Text = feat.GetValue("起始管顶高程").ToString();
                txtDEM2.Text = feat.GetValue("终止地面高程").ToString();
                txtDeep2.Text = feat.GetValue("终止埋深").ToString();
                txtDEMDing2.Text = feat.GetValue("终止管顶高程").ToString();

                txtYear.Text = feat.GetValue("使用年限").ToString();
                txtQuanShuDanWei.Text = feat.GetValue("权属单位").ToString();
                txtDesign_Com.Text = feat.GetValue("设计单位").ToString();
                txtDesign_Per.Text = feat.GetValue("设计负责人").ToString();
                txtBuilder_Com.Text = feat.GetValue("施工单位").ToString();
                txtBuilder_Per.Text = feat.GetValue("施工负责人").ToString();
                txtMon_Com.Text = feat.GetValue("监理单位").ToString();
                txtMon_Per.Text = feat.GetValue("监理负责人").ToString();
                txtHH_Per.Text = feat.GetValue("业务负责人").ToString();
                txtRemark.Text = feat.GetValue("备注").ToString();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                textBoxValueChanged();
                if (bValueChanged == false)
                {
                    feat.CopyModifyFlag(feat_old);
                    //MessageBox.Show("属性信息未进行修改");
                    return;
                }
                m_GlobeControl.Globe.AddToEditHistroy(m_layer, feat, EnumEditType.Modify);
         
                GSOPoint3ds pts = line[0];
                GSOPoint3d pt1 = pts[0];
                GSOPoint3d pt2 = pts[1];


                //埋深的判断,是管顶还是管底,并就该埋深属性
                float guanjing = float.Parse(txtGuanJing.Text);
                float feat_guanjing = float.Parse(feat.GetValue("管径_毫米").ToString());
                float deep1 = float.Parse(txtDeep1.Text);
                float feat_deep1 = float.Parse(feat.GetValue("起始埋深").ToString());
                float deep2 = float.Parse(txtDeep2.Text);
                float feat_deep2 = float.Parse(feat.GetValue("终止埋深").ToString());

                if (txtBianMa.Text != "")
                {
                    feat.SetValue("管线编码", Convert.ToInt32(txtBianMa.Text));
                }
                if (combMaterial.SelectedIndex > 0)
                {
                    feat.SetValue("材质", combMaterial.SelectedItem.ToString());
                }
                if (txtGuanJing.Text != "")
                {
                    feat.SetValue("管径_毫米", Convert.ToInt32(txtGuanJing.Text));
                }

                if (combMaiShe.SelectedIndex > 0)
                {
                    feat.SetValue("埋设方式", combMaiShe.SelectedItem.ToString());
                }
                if (txtYali.Text != "")
                {
                    feat.SetValue("压力", Convert.ToDouble(txtYali.Text));
                }
                if (combUse.SelectedIndex > 0)
                {
                    feat.SetValue("是否废弃", combUse.SelectedItem.ToString());
                }
                if (txtDEM1.Text != "")
                {
                    feat.SetValue("起始地面高程", Convert.ToDouble(txtDEM1.Text));
                }
                if (txtDeep1.Text != "")
                {
                    feat.SetValue("起始埋深", Convert.ToDouble(txtDeep1.Text));
                }
                if (txtDEMDing1.Text != "")
                {
                    feat.SetValue("起始管顶高程", Convert.ToDouble(txtDEMDing1.Text));
                }
                if (txtDEM2.Text != "")
                {
                    feat.SetValue("终止地面高程", Convert.ToDouble(txtDEM2.Text));
                }
                if (txtDeep2.Text != "")
                {
                    feat.SetValue("终止埋深", Convert.ToDouble(txtDeep2.Text));
                }
                if (txtDEMDing2.Text != "")
                {
                    feat.SetValue("终止管顶高程", Convert.ToDouble(txtDEMDing2.Text));
                }
                if (dtTime != null && dtTime.Year > 1)             // if (dateBuild.Value != null)
                {
                    feat.SetValue("建设年代", dtTime);
                }
                if (txtYear.Text != "")
                {
                    feat.SetValue("使用年限", Convert.ToDouble(txtYear.Text));
                }
                feat.SetValue("权属单位", txtQuanShuDanWei.Text);
                feat.SetValue("设计单位", txtDesign_Com.Text);
                feat.SetValue("设计负责人", txtDesign_Per.Text);
                feat.SetValue("施工单位", txtBuilder_Com.Text);
                feat.SetValue("施工负责人", txtBuilder_Per.Text);
                feat.SetValue("监理单位", txtMon_Com.Text);
                feat.SetValue("监理负责人", txtMon_Per.Text);
                feat.SetValue("业务负责人", txtHH_Per.Text);
                feat.SetValue("备注", txtRemark.Text);

                //判断是否修改管线埋深
                if (guanjing != feat_guanjing || deep1 != feat_deep1 || deep2 != feat_deep2)
                {
                    //因为在管线埋深的时候设置管顶和管底,所以在修改管线埋深的时候要涉及到管线的半径
                    //float det1 = feat_deep1 - float.Parse(Math.Abs(pt1.Z).ToString());
                    //float det2 = feat_deep2 - float.Parse(Math.Abs(pt2.Z).ToString());
                    ////修改埋深后的值
                    //float deepEdit1 = float.Parse(txtDeep1.Text) - det1;
                    //float deepEdit2 = float.Parse(txtDeep2.Text) - det2;
                    float deepEdit1 = float.Parse(txtDeep1.Text);
                    float deepEdit2 = float.Parse(txtDeep2.Text);
                    GSOPipeLineStyle3D style = line.Style as GSOPipeLineStyle3D;
                    style.Radius = guanjing / 2000;
                    pt1.Z = 0 - deepEdit1 - guanjing / 1000;
                    pt2.Z = 0 - deepEdit2 - guanjing / 1000;
                }

                pts[0] = pt1;
                pts[1] = pt2;

                if (MessageBox.Show("确定要修改该管线属性?", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    try
                    {
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                        //MessageBox.Show("修改成功!", "提示!");
                    }
                    catch
                    {
                        MessageBox.Show("管线属性修改有误,请重新修改!", "提示!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            feat.CopyModifyFlag(feat_old);
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void txtBianMa_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextBox text = sender as TextBox;
            if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && (int)e.KeyChar != 46)
            {
                e.Handled = true;
            }
            if ((int)e.KeyChar == 46)                           //小数点
            {
                if (text.Text.Length <= 0)
                    e.Handled = true;   //小数点不能在第一位
                else                                             //处理不规则的小数点
                {
                    float f;
                    float oldf;
                    bool b1 = false, b2 = false;
                    b1 = float.TryParse(text.Text, out oldf);
                    b2 = float.TryParse(text.Text + e.KeyChar.ToString(), out f);
                    if (b2 == false)
                    {
                        if (b1 == true)
                            e.Handled = true;
                        else
                            e.Handled = false;
                    }
                }
            }
        }
        DateTime dtTime;
        private void dateBuild_ValueChanged(object sender, EventArgs e)
        {
            dtTime = dateBuild.Value;
        }
        bool bValueChanged = false;
        public void textBoxValueChanged() //点击确定按钮时,判断文本框中内容是否发生变化
        {
            if (txtGuanJing.Text != feat.GetValue("管径_毫米").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (combMaterial.Text != feat.GetValue("材质").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (combMaiShe.Text != feat.GetValue("埋设方式").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (txtYali.Text != feat.GetValue("压力").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (combUse.Text != feat.GetValue("是否废弃").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (txtDEM1.Text != feat.GetValue("起始地面高程").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (txtDeep1.Text != feat.GetValue("起始埋深").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (txtDEMDing1.Text != feat.GetValue("起始管顶高程").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (txtDEM2.Text != feat.GetValue("终止地面高程").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (txtDeep2.Text != feat.GetValue("终止埋深").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (txtDEMDing2.Text != feat.GetValue("终止管顶高程").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (txtYear.Text != feat.GetValue("使用年限").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (txtQuanShuDanWei.Text != feat.GetValue("权属单位").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (txtDesign_Com.Text != feat.GetValue("设计单位").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (txtDesign_Per.Text != feat.GetValue("设计负责人").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (txtBuilder_Com.Text != feat.GetValue("施工单位").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (txtBuilder_Per.Text != feat.GetValue("施工负责人").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (txtMon_Com.Text != feat.GetValue("监理单位").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (txtMon_Per.Text != feat.GetValue("监理负责人").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (txtHH_Per.Text != feat.GetValue("业务负责人").ToString())
            {
                bValueChanged = true;
                return;
            }
            if (txtRemark.Text != feat.GetValue("备注").ToString())
            {
                bValueChanged = true;
                return;
            }

        }
    }
}