Newer
Older
GHFX_REFACTOR / Backup / Forms / FrmRanQiAttribute.cs
wxn on 2 Nov 2016 12 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.Engine;
using GeoScene.Globe;
using GeoScene.Data;

namespace Cyberpipe.Forms
{
    public partial class FrmRanQiAttribute : Office2007Form
    {
        private GSOFeatureDataset featDataSet;
        private GSOLayer layer;
        public GSOFeature feat_old;
        public GSOFeature feat;
        public GSOGeoPolyline3D line;
        private Color color;
        private string strReference;
        public FrmRanQiAttribute(GSOLayer _layer, GSOFeature feature, Color color1, string referenceText)
        {
            layer = _layer;
            featDataSet = layer.Dataset as GSOFeatureDataset;
            line = feature.Geometry as GSOGeoPolyline3D;
            feat_old = feature;
            InitializeComponent();
            color = color1;
            strReference = referenceText;
        }
        /// <summary>
        /// 窗体初始化事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmRanQiAttribute_Load(object sender, EventArgs e)
        {
            string str = Utility.Pipe_Code["燃气"].ToString();
            string[] aArray = str.Split(',');
            for (int i = 0; i < aArray.Length; i++)
            {
                combBianMa.Items.Add(aArray[i]);
            }
            combBianMa.SelectedIndex = 0;
            txtBianHao.Text = Guid.NewGuid().ToString();

            string sqltype1 = "select distinct 材质 from "+layer.Caption;
            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 " + layer.Caption;
            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  " + layer.Caption;
            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);
            }   
        }
        /// <summary>
        /// 确定按钮事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                feat = featDataSet.CreateFeature();
                GSOPipeLineStyle3D style = new GSOPipeLineStyle3D();
                style.LineColor = color;

                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                /// 设置线风格
                /// 
                //GSOFeatures feats = layer.GetAllFeatures();
                //if (feats.Length > 0)
                //{
                //    GSOFeature colorFeat = feats[0];
                //    GSOPipeLineStyle3D originstyle = colorFeat.Geometry.Style as GSOPipeLineStyle3D;
                //    if (originstyle != null)
                //        style.LineColor = originstyle.LineColor;
                //}
                if (txtGuanJing.Text == "" || txtGuanJing.Text == "0")
                {
                    if (txtGuanJing.Text == "")
                    {
                        MessageBox.Show("管径不能为空!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        MessageBox.Show("管径不能为零!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    return;
                }
                else
                {
                    try
                    {
                        style.Radius = Convert.ToDouble(txtGuanJing.Text) / 2000;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("请输入正确的管径!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
                line.AltitudeMode = EnumAltitudeMode.RelativeToGround;
                line.Style = style;
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


                GSOPoint3ds pts = line[0];
                GSOPoint3d pt1 = pts[0];
                GSOPoint3d pt2 = pts[1];

                if (txtDeep1.Text == "" || txtDeep1.Text == "0" || txtDeep2.Text == "" || txtDeep2.Text == "0")
                {
                    if (txtDeep1.Text == "" || txtDeep2.Text == "")
                    {
                        MessageBox.Show("起始埋深和终止埋深不能为空!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (txtDeep1.Text == "0" || txtDeep2.Text == "0")
                    {
                        MessageBox.Show("起始埋深和终止埋深埋深不能为零!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    return;
                }
                try
                {
                    pt1.Z = 0 - Convert.ToDouble(txtDeep1.Text) - Convert.ToDouble(txtGuanJing.Text) / 1000;
                    pt2.Z = 0 - Convert.ToDouble(txtDeep2.Text) - Convert.ToDouble(txtGuanJing.Text) / 1000;
                    if (strReference == "管顶")
                    {
                        pt1.Z -= Convert.ToDouble(txtGuanJing.Text) / 2000;
                        pt2.Z -= Convert.ToDouble(txtGuanJing.Text) / 2000;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("请输入正确的起始埋深和终止埋深!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }                
                pts[0] = pt1;
                pts[1] = pt2;


                //数据和管线结合
                feat.Geometry = line;

                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //修改管线数据
                if (txtBianHao.Text == "")
                {
                    MessageBox.Show("请输入“编号”,该字段不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                    feat.SetValue("编号", txtBianHao.Text);

                if (combBianMa.SelectedItem != null)
                {
                    feat.SetValue("管线编码", combBianMa.SelectedItem);
                }

                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 (dateBuild.Text != "")
                {
                    feat.SetValue("建设年代", Convert.ToDateTime(dateBuild.Text));
                }
                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);
                feat.Name = txtBianHao.Text;
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                line.Name = txtBianHao.Text;


                layer.AddFeature(feat);
                feat_old.Delete();
                if (MessageBox.Show("是否保存到数据库?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    layer.Save();
                }
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 取消按钮事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
        /// <summary>
        /// 键盘按键按下事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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;
                    }
                }
            }
        }
    }
}