Example #1
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //1煤2碳化灰岩3粉砂质泥岩4泥岩5泥质粉砂岩
            IWorkspaceEdit workspaceEdit = null;

            try
            {
                labelSC.Visible = true;
                Application.DoEvents();
                //去除无用空行
                for (int i = 0; i < dgrdvZhzzt.RowCount - 1; i++)
                {
                    if (this.dgrdvZhzzt.Rows[i].Cells[0].Value == null &&
                        this.dgrdvZhzzt.Rows[i].Cells[1].Value == null &&
                        this.dgrdvZhzzt.Rows[i].Cells[2].Value == null)
                    {
                        this.dgrdvZhzzt.Rows.RemoveAt(i);
                    }
                }
                //验证
                if (!check())
                {
                    this.DialogResult = DialogResult.None;
                    return;
                }
                this.DialogResult = DialogResult.OK;
                if (isadd)
                {
                    bid = IDGenerator.NewBindingID();
                }
                //实体赋值
                Histogram historam = new Histogram();
                historam.HistogramEntName = txtname.Text.Trim();
                historam.BLC    = Convert.ToDouble(txtBlc.Text.Trim());
                historam.ID     = bid;
                historam.listMY = new List <Historgramlist>();
                double height = 0;
                for (int i = 0; i < dgrdvZhzzt.RowCount - 1; i++)
                {
                    Historgramlist hisl = new Historgramlist();
                    hisl.BID   = bid;
                    hisl.Index = (i + 1);
                    //煤岩名称
                    DataGridViewTextBoxCell cell = dgrdvZhzzt.Rows[i].Cells[0] as DataGridViewTextBoxCell;
                    hisl.MYName  = cell.Value.ToString();
                    cell         = dgrdvZhzzt.Rows[i].Cells[1] as DataGridViewTextBoxCell;
                    hisl.Height  = Convert.ToDouble(cell.Value.ToString());
                    height      += hisl.Height;
                    hisl.SHeight = height;
                    hisl.ZZType  = ZZStrToCode(dgrdvZhzzt.Rows[i].Cells[2].Value.ToString());
                    cell         = dgrdvZhzzt.Rows[i].Cells[3] as DataGridViewTextBoxCell;
                    if (cell.Value != null)
                    {
                        hisl.Describe = cell.Value.ToString();
                    }
                    historam.listMY.Add(hisl);
                }
                if (!isadd)
                {
                    DataEditCommon.DeleteFeatureByWhereClause(frmZhzzt.pFeatureClass, "BID='" + bid + "'");
                }

                progressBar1.Maximum = historam.listMY.Count * 6 + 9;
                progressBar1.Value   = 0;


                IFeatureClass pFeatureClass = frmZhzzt.pFeatureClass;
                progressBar1.Value += 1;
                Application.DoEvents();
                IDataset   dataset   = (IDataset)pFeatureClass;
                IWorkspace workspace = dataset.Workspace;
                workspaceEdit = workspace as IWorkspaceEdit;

                workspaceEdit.StartEditing(true);
                workspaceEdit.StartEditOperation();


                ISegmentCollection pSegmentCollection = new PolygonClass();

                double xbasic = 100;
                double xmin = xbasic, ymin = 99.5, xmax = 110, ymax = 100;

                List <IGeometry> listgeo   = new List <IGeometry>();
                IEnvelope        pEnvelope = new EnvelopeClass();
                pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                List <ziduan> listzd = new List <ziduan>();
                listzd.Add(new ziduan("textstr", historam.HistogramEntName));
                listzd.Add(new ziduan("zztype", "6"));
                listzd.Add(new ziduan("strtype", "1"));
                listzd.Add(new ziduan("bilici", historam.BLC.ToString()));
                listzd.Add(new ziduan("BID", historam.ID));
                pSegmentCollection.SetRectangle(pEnvelope);
                DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                listgeo.Add(pSegmentCollection as IGeometry);
                progressBar1.Value += 1;
                Application.DoEvents();

                pEnvelope = new EnvelopeClass();
                ymax      = ymin;
                ymin     -= 0.3;
                pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                listzd = new List <ziduan>();
                listzd.Add(new ziduan("textstr", "比例 1:" + historam.BLC.ToString() + "  单位:米"));
                listzd.Add(new ziduan("zztype", "6"));
                listzd.Add(new ziduan("strtype", "2"));
                listzd.Add(new ziduan("bilici", historam.BLC.ToString()));
                listzd.Add(new ziduan("BID", historam.ID));
                pSegmentCollection = new PolygonClass();
                pSegmentCollection.SetRectangle(pEnvelope);
                DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                listgeo.Add(pSegmentCollection as IGeometry);
                progressBar1.Value += 1;
                Application.DoEvents();

                pEnvelope = new EnvelopeClass();
                ymax      = ymin;
                ymin     -= 0.3; xmax = xmin + 0.6;
                pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                listzd = new List <ziduan>();
                listzd.Add(new ziduan("textstr", "序号"));
                listzd.Add(new ziduan("zztype", "0"));
                listzd.Add(new ziduan("strtype", "0"));
                listzd.Add(new ziduan("BID", historam.ID));
                pSegmentCollection = new PolygonClass();
                pSegmentCollection.SetRectangle(pEnvelope);
                DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                listgeo.Add(pSegmentCollection as IGeometry);
                progressBar1.Value += 1;
                Application.DoEvents();

                pEnvelope = new EnvelopeClass();
                xmin      = xmax; xmax += 1.8;
                pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                listzd = new List <ziduan>();
                listzd.Add(new ziduan("textstr", "煤 岩 名 称"));
                listzd.Add(new ziduan("zztype", "0"));
                listzd.Add(new ziduan("strtype", "0"));
                listzd.Add(new ziduan("BID", historam.ID));
                pSegmentCollection = new PolygonClass();
                pSegmentCollection.SetRectangle(pEnvelope);
                DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                listgeo.Add(pSegmentCollection as IGeometry);
                progressBar1.Value += 1;
                Application.DoEvents();

                pEnvelope = new EnvelopeClass();
                xmin      = xmax; xmax += 0.8;
                pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                listzd = new List <ziduan>();
                listzd.Add(new ziduan("textstr", "真厚"));
                listzd.Add(new ziduan("zztype", "0"));
                listzd.Add(new ziduan("strtype", "0"));
                listzd.Add(new ziduan("BID", historam.ID));
                pSegmentCollection = new PolygonClass();
                pSegmentCollection.SetRectangle(pEnvelope);
                DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                listgeo.Add(pSegmentCollection as IGeometry);
                progressBar1.Value += 1;
                Application.DoEvents();

                pEnvelope = new EnvelopeClass();
                xmin      = xmax; xmax += 1;
                pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                listzd = new List <ziduan>();
                listzd.Add(new ziduan("textstr", "累厚"));
                listzd.Add(new ziduan("zztype", "0"));
                listzd.Add(new ziduan("strtype", "0"));
                listzd.Add(new ziduan("BID", historam.ID));
                pSegmentCollection = new PolygonClass();
                pSegmentCollection.SetRectangle(pEnvelope);
                DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                listgeo.Add(pSegmentCollection as IGeometry);
                progressBar1.Value += 1;
                Application.DoEvents();

                pEnvelope = new EnvelopeClass();
                xmin      = xmax; xmax += 1.2;
                pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                listzd = new List <ziduan>();
                listzd.Add(new ziduan("textstr", "柱  状"));
                listzd.Add(new ziduan("zztype", "0"));
                listzd.Add(new ziduan("strtype", "0"));
                listzd.Add(new ziduan("BID", historam.ID));
                pSegmentCollection = new PolygonClass();
                pSegmentCollection.SetRectangle(pEnvelope);
                DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                listgeo.Add(pSegmentCollection as IGeometry);
                progressBar1.Value += 1;
                Application.DoEvents();

                pEnvelope = new EnvelopeClass();
                xmin      = xmax; xmax += 4.6;
                pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                listzd = new List <ziduan>();
                listzd.Add(new ziduan("textstr", "岩 性 描 述"));
                listzd.Add(new ziduan("zztype", "0"));
                listzd.Add(new ziduan("strtype", "0"));
                listzd.Add(new ziduan("BID", historam.ID));
                pSegmentCollection = new PolygonClass();
                pSegmentCollection.SetRectangle(pEnvelope);
                DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                listgeo.Add(pSegmentCollection as IGeometry);
                progressBar1.Value += 1;
                Application.DoEvents();


                List <Historgramlist> list = historam.ListMY;
                for (int i = 0; i < list.Count; i++)
                {
                    xmin = xbasic;

                    double m_height = list[i].Height;
                    if (m_height < 0.3)
                    {
                        m_height = 0.3;
                    }
                    pEnvelope = new EnvelopeClass();
                    ymax      = ymin;
                    ymin     -= m_height; xmax = xmin + 0.6;
                    pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                    listzd = new List <ziduan>();
                    listzd.Add(new ziduan("textstr", list[i].Index.ToString()));
                    listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString()));
                    listzd.Add(new ziduan("xuhaoC", "1"));
                    listzd.Add(new ziduan("zztype", "0"));
                    listzd.Add(new ziduan("strtype", "0"));
                    listzd.Add(new ziduan("BID", historam.ID));
                    pSegmentCollection = new PolygonClass();
                    pSegmentCollection.SetRectangle(pEnvelope);
                    DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                    listgeo.Add(pSegmentCollection as IGeometry);
                    progressBar1.Value += 1;
                    Application.DoEvents();

                    pEnvelope = new EnvelopeClass();
                    xmin      = xmax; xmax += 1.8;
                    pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                    listzd = new List <ziduan>();
                    listzd.Add(new ziduan("textstr", list[i].MYName));
                    listzd.Add(new ziduan("zztype", "0"));
                    listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString()));
                    listzd.Add(new ziduan("xuhaoC", "2"));
                    listzd.Add(new ziduan("strtype", "0"));
                    listzd.Add(new ziduan("BID", historam.ID));
                    pSegmentCollection = new PolygonClass();
                    pSegmentCollection.SetRectangle(pEnvelope);
                    DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                    listgeo.Add(pSegmentCollection as IGeometry);
                    progressBar1.Value += 1;
                    Application.DoEvents();

                    pEnvelope = new EnvelopeClass();
                    xmin      = xmax; xmax += 0.8;
                    pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                    listzd = new List <ziduan>();
                    listzd.Add(new ziduan("textstr", list[i].Height.ToString()));
                    listzd.Add(new ziduan("zztype", "0"));
                    listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString()));
                    listzd.Add(new ziduan("xuhaoC", "3"));
                    listzd.Add(new ziduan("strtype", "0"));
                    listzd.Add(new ziduan("BID", historam.ID));
                    pSegmentCollection = new PolygonClass();
                    pSegmentCollection.SetRectangle(pEnvelope);
                    DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                    listgeo.Add(pSegmentCollection as IGeometry);
                    progressBar1.Value += 1;
                    Application.DoEvents();

                    pEnvelope = new EnvelopeClass();
                    xmin      = xmax; xmax += 1;
                    pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                    listzd = new List <ziduan>();
                    listzd.Add(new ziduan("textstr", Math.Round(list[i].SHeight, 1).ToString()));
                    listzd.Add(new ziduan("zztype", "0"));
                    listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString()));
                    listzd.Add(new ziduan("xuhaoC", "4"));
                    listzd.Add(new ziduan("strtype", "0"));
                    listzd.Add(new ziduan("BID", historam.ID));
                    pSegmentCollection = new PolygonClass();
                    pSegmentCollection.SetRectangle(pEnvelope);
                    DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                    listgeo.Add(pSegmentCollection as IGeometry);
                    progressBar1.Value += 1;
                    Application.DoEvents();

                    pEnvelope = new EnvelopeClass();
                    xmin      = xmax; xmax += 1.2;
                    pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                    listzd = new List <ziduan>();
                    listzd.Add(new ziduan("textstr", ""));
                    listzd.Add(new ziduan("zztype", list[i].ZZType));
                    listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString()));
                    listzd.Add(new ziduan("xuhaoC", "5"));
                    listzd.Add(new ziduan("strtype", "0"));
                    listzd.Add(new ziduan("BID", historam.ID));
                    pSegmentCollection = new PolygonClass();
                    pSegmentCollection.SetRectangle(pEnvelope);
                    DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                    listgeo.Add(pSegmentCollection as IGeometry);
                    progressBar1.Value += 1;
                    Application.DoEvents();

                    pEnvelope = new EnvelopeClass();
                    xmin      = xmax; xmax += 4.6;
                    pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                    listzd = new List <ziduan>();
                    string strms   = list[i].Describe;
                    string miaoshu = "";
                    if (strms != null && strms.Length > 0)
                    {
                        ASCIIEncoding ascii  = new ASCIIEncoding();
                        int           temLen = 0;
                        byte[]        s      = ascii.GetBytes(strms);

                        for (int j = 0; j < s.Length; j++)
                        {
                            if ((int)s[j] == 63)
                            {
                                temLen += 2;
                            }
                            else
                            {
                                temLen += 1;
                            }
                            miaoshu += strms[j];
                            if (temLen % 38 == 0 || (temLen + 1) % 38 == 0)
                            {
                                if (miaoshu.LastIndexOf('|') != miaoshu.Length - 1)
                                {
                                    miaoshu += "|";
                                }
                            }
                        }
                    }

                    listzd.Add(new ziduan("textstr", miaoshu));
                    listzd.Add(new ziduan("zztype", "0"));
                    listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString()));
                    listzd.Add(new ziduan("xuhaoC", "6"));
                    listzd.Add(new ziduan("strtype", "3"));
                    listzd.Add(new ziduan("BID", historam.ID));
                    pSegmentCollection = new PolygonClass();
                    pSegmentCollection.SetRectangle(pEnvelope);
                    DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                    listgeo.Add(pSegmentCollection as IGeometry);
                    progressBar1.Value += 1;
                    Application.DoEvents();
                }
                workspaceEdit.StopEditOperation();
                workspaceEdit.StopEditing(true);

                frmZhzzt.pGeometry = MyMapHelp.GetGeoFromGeos(listgeo);
                frmZhzzt.BID       = historam.ID;
                frmZhzzt.blc       = historam.BLC;

                DialogResult = DialogResult.OK;
                this.Close();
                if (!isadd)
                {
                    frmZhzzt.refresh();
                }
            }
            catch (Exception ex)
            {
                labelSC.Visible = false;
                MessageBox.Show(ex.Message);
                if (workspaceEdit != null)
                {
                    workspaceEdit.AbortEditOperation();
                    workspaceEdit.StopEditing(false);
                }
            }
        }