Newer
Older
GHFX_REFACTOR / Forms / FrmTongXunAttribute.cs
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using GeoScene.Data;
using GeoScene.Engine;
using GeoScene.Globe;

namespace Cyberpipe.Forms
{
    public partial class FrmTongXunAttribute : Office2007Form
    {
        private GSOFeatureDataset featDataSet;
        private GSOLayer layer;
        public GSOFeature feat_old;
        public GSOFeature feat;
        public GSOGeoPolyline3D line;
        private Color color;
        private string strReference;
        public FrmTongXunAttribute(GSOLayer _layer, GSOFeature feature, Color color1, string referenceText)
        {
            InitializeComponent();
            layer = _layer;
            featDataSet = layer.Dataset as GSOFeatureDataset;
            feat_old = feature;
            color = color1;
            strReference = referenceText;
        }

        private GSOLineStyle3D getPipeLineStyle()
        {
            try
            {
                double width = Convert.ToDouble(textBoxWidth.Text)/1000;
                double height = Convert.ToDouble(textBoxHeight.Text)/1000;
                GSOExtendSectionLineStyle3D style1 = new GSOExtendSectionLineStyle3D();
                style1.LineColor = Color.FromArgb(255, color);
                
                GSOPoint3ds sectionpts = new GSOPoint3ds();
                sectionpts.Add(new GSOPoint3d(width / -2, height / 2, 0));
                sectionpts.Add(new GSOPoint3d(width / -2, height / -2, 0));
                sectionpts.Add(new GSOPoint3d(width / 2, height / -2, 0));
                sectionpts.Add(new GSOPoint3d(width / 2, height / 2, 0));

                style1.SetSectionPoints(sectionpts);
                style1.IsClosed = true;
                style1.SetAnchorByAlign(EnumAlign.MiddleCenter);
                return style1;
            }
            catch (Exception ex)
            {
                MessageBox.Show("请输入正确的管径!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return null;
            }
        }

        private bool getBoxValResult()
        {
            if (textBoxWidth.Text == "" || textBoxWidth.Text == "0")
            {
                if (textBoxWidth.Text == "")
                    MessageBox.Show("沟道宽不能为空!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                else
                    MessageBox.Show("沟道宽不能为零!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            if (textBoxHeight.Text == "" || textBoxHeight.Text == "0")
            {
                if (textBoxHeight.Text == "")
                    MessageBox.Show("沟道高不能为空!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                else
                    MessageBox.Show("沟道高不能为零!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            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 false;
            }
            return true;
        }

        private void setValueToFiled()
        {
            if (txtBianHao.Text != "")
            {
                feat.SetValue("编号", txtBianHao.Text);
            }
            if (txtBianMa.Text != "")
            {
                feat.SetValue("编码", Convert.ToInt32(txtBianMa.Text));
            }
            if (txtAllNumKong.Text != "")
            {
                feat.SetValue("总孔数", Convert.ToInt32(txtAllNumKong.Text));
            }
            if (txtUseNumKong.Text != "")
            {
                feat.SetValue("已用孔数", Convert.ToInt32(txtUseNumKong.Text));
            }
            if (txtDianlanNum.Text != "")
            {
                feat.SetValue("电缆条数", Convert.ToInt32(txtDianlanNum.Text));
            }
            if (combMaterial.SelectedIndex > 0)
            {
                feat.SetValue("材质", combMaterial.SelectedItem.ToString());
            }
            if (combMaiShe.SelectedIndex > 0)
            {
                feat.SetValue("埋设方式", combMaiShe.SelectedItem.ToString());
            }
            if (textBoxWidth.Text != "")
            {
                feat.SetValue("沟道宽", Convert.ToDouble(textBoxWidth.Text));
            }
            if (textBoxHeight.Text != "")
            {
                feat.SetValue("沟道高", Convert.ToDouble(textBoxHeight.Text));
            }
            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 (txtroad.Text != "")
            {
                feat.SetValue("所属道路", txtroad.Text);
            }
            if (dateBuild.Text != "")
            {
                feat.SetValue("建设年代", dateBuild.Text);
            }
            if (txtQuanShuDanWei.Text != "")
            {
                feat.SetValue("权属单位", txtQuanShuDanWei.Text);
            }
            if (txtRemark.Text != "")
            {
                feat.SetValue("备注", txtRemark.Text);
            }
        }

        private GSOGeometry updateGemotry()
        {
            feat_old.Geometry.AltitudeMode = EnumAltitudeMode.Absolute;
            line = feat_old.Geometry as GSOGeoPolyline3D;
            if (line == null || line.GetSpaceLength(true, 6378137) == 0)
                return null;

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

            try
            {
                pt1.Z = 0 - Convert.ToDouble(txtDeep1.Text);
                pt2.Z = 0 - Convert.ToDouble(txtDeep2.Text);
                if (strReference == "管顶")
                {
                    pt1.Z += Convert.ToDouble(textBoxHeight.Text) / 1000;
                    pt2.Z += Convert.ToDouble(textBoxHeight.Text) / 1000;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("请输入正确的沟道高和埋深!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return null;
            }

            pts[0] = pt1;
            pts[1] = pt2;
            return line;
        }

        /// <summary>
        /// 确定按钮事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (getBoxValResult() == false) return;

            feat = featDataSet.CreateFeature();

            feat.Geometry = updateGemotry();
            feat.Geometry.Style = getPipeLineStyle();
            feat.Name = txtBianHao.Text;
            setValueToFiled();
            
            layer.AddFeature(feat);
            feat_old.Delete();
            if (MessageBox.Show("是否保存到数据库?", "提示", MessageBoxButtons.YesNo,
                MessageBoxIcon.Question) == DialogResult.Yes)
                layer.Save();
            
            //layer.Reload();
            DialogResult = DialogResult.OK;
            Close();
        }
        /// <summary>
        /// 取消按钮事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            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) && e.KeyChar != 46)
            {
                e.Handled = true;
            }
            if (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, out f);
                    if (b2 == false)
                    {
                        if (b1)
                            e.Handled = true;
                        else
                            e.Handled = false;
                    }
                }
            }
        }
        /// <summary>
        /// 窗体初始化事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmTongXunAttribute_Load(object sender, EventArgs e)
        {
            string sqltype3 = "select distinct 编码 from " + layer.Caption;
            DataTable table3 = OledbHelper.QueryTable(sqltype3);
            txtBianMa.Text = table3.Rows[0][0].ToString();

            txtBianHao.Text = Guid.NewGuid().ToString();

            if (layer.Caption.Contains("移动"))
            {
                txtBianHao.Text = txtBianHao.Text = "GX_YDL_" + txtBianMa.Text + "_"
                   + Guid.NewGuid();
            }
            else if (layer.Caption.Contains("联通"))
            {
                txtBianHao.Text = txtBianHao.Text = "GX_LTL_" + txtBianMa.Text + "_"
                       + Guid.NewGuid();
            }
            else if (layer.Caption.Contains("电信"))
            {
                txtBianHao.Text = txtBianHao.Text = "GX_DXL_" + txtBianMa.Text + "_"
                       + Guid.NewGuid();
            }
            else if (layer.Caption.Contains("电通"))
            {
                txtBianHao.Text = txtBianHao.Text = "GX_DTL_" + txtBianMa.Text + "_"
                       + Guid.NewGuid();
            }
            else if (layer.Caption.Contains("网通"))
            {
                txtBianHao.Text = txtBianHao.Text = "GX_WTL_" + txtBianMa.Text + "_"
                       + Guid.NewGuid();
            }
            else if (layer.Caption.Contains("路灯"))
            {
                txtBianHao.Text = txtBianHao.Text = "GX_LDL_" + txtBianMa.Text + "_"
                       + Guid.NewGuid();
            }
            else if (layer.Caption.Contains("有线"))
            {
                txtBianHao.Text = txtBianHao.Text = "GX_DSL_" + txtBianMa.Text + "_"
                       + Guid.NewGuid();
            }

            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);
            }
        }

    }
}