Esempio n. 1
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     if (this.xtraTabControl1.SelectedTabPageIndex == 0)
     {
         SampleFrame   sampleFrame = new SampleFrame();
         frmWaitDialog frmWait     = new frmWaitDialog("正在处理...", "提示信息");
         try
         {
             frmWait.Owner   = this;
             frmWait.TopMost = false;
             string msg = string.Empty;
             if (chkArea.Checked)
             {
                 SampleData.hasArea    = true;
                 SampleData.areaField  = cmbAreaField.Text;
                 SampleData.firstUnit  = this.cmbUnit.Text.TrimEnd();
                 SampleData.farmLand   = this.cmbCrop.Text.TrimEnd();
                 SampleData.ASCDL      = cmbASCDL.Text;
                 SampleData.targetCrop = this.cmbDestination.SelectedIndex;
                 frmWait.Caption       = "参数检查...";
                 if (!sampleFrame.ChkData(out msg))
                 {
                     XtraMessageBox.Show(msg);
                     return;
                 }
                 frmWait.Caption = "计算分类面积...";
                 if (!sampleFrame.CalClassArea(SampleData.firstUnit, SampleData.ASCDL, SampleData.targetCrop, out msg))
                 {
                     XtraMessageBox.Show(msg);
                     return;
                 }
             }
             else
             {
                 SampleData.hasArea    = false;
                 SampleData.areaField  = string.Empty;
                 SampleData.firstUnit  = this.cmbUnit.Text.TrimEnd();
                 SampleData.farmLand   = this.cmbCrop.Text.TrimEnd();
                 SampleData.ASCDL      = cmbASCDL.Text;
                 SampleData.targetCrop = this.cmbDestination.SelectedIndex;
                 frmWait.Caption       = "参数检查...";
                 if (!sampleFrame.ChkData(out msg))
                 {
                     XtraMessageBox.Show(msg);
                     return;
                 }
                 frmWait.Caption = "计算耕地面积...";
                 if (!sampleFrame.CalLandArea(SampleData.firstUnit, SampleData.farmLand, out msg))
                 {
                     XtraMessageBox.Show(msg);
                     return;
                 }
                 frmWait.Caption = "计算分类面积...";
                 if (!sampleFrame.CalClassArea(SampleData.firstUnit, SampleData.ASCDL, SampleData.targetCrop, out msg))
                 {
                     XtraMessageBox.Show(msg);
                     return;
                 }
             }
             if (DialogResult.OK == XtraMessageBox.Show("处理完毕.", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information))
             {
                 MapAPI.AddShpFileToMap(SampleData.firstUnit);
                 MapAPI.AddShpFileToMap(SampleData.farmLand);
                 MapAPI.AddRasterFileToMap(SampleData.ASCDL);
             }
         }
         catch (Exception ex)
         {
             XtraMessageBox.Show(ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         finally
         {
             frmWait.Close();
         }
     }
 }
Esempio n. 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string        msg     = string.Empty;
            frmWaitDialog frmWait = new frmWaitDialog("正在执行...", "提示信息");

            try
            {
                frmWait.Owner   = this;
                frmWait.TopMost = false;
                string fishNet   = string.Empty;
                string firstUnit = this.cmbFirstUnit.Text;
                if (chkNewNet.Checked)
                {
                    SampleData.firstSample  = cmbFirstUnit.Text;
                    SampleData.villageField = cmbVillage.Text;
                    SampleData.layerField   = cmbLayer.Text;
                    SampleData.farmLand     = cmbCultivation.Text;
                    SampleData.ASCDL        = cmbASCDL.Text;
                    SampleData.targetCrop   = cmbCrop.SelectedIndex;

                    if (!SampleSelection.ChkData(out msg))
                    {
                        XtraMessageBox.Show(msg);
                        return;
                    }
                    //一级单元范围内创建渔网
                    frmWait.Caption = "创建二级抽样单元...";
                    fishNet         = System.IO.Path.Combine(ConstDef.PATH_TEMP, DateTime.Now.ToFileTime().ToString() + ".shp");
                    int width  = int.Parse(spinLength.EditValue.ToString());
                    int height = int.Parse(this.spinWidth.EditValue.ToString());
                    if (!EnviVars.instance.GpExecutor.CreateFishNet(firstUnit, width, height, fishNet, out msg))
                    {
                        XtraMessageBox.Show(msg);
                        return;
                    }
                }
                else
                {
                    SampleData.firstSample  = cmbFirstUnit.Text;
                    SampleData.villageField = cmbVillage.Text;
                    SampleData.layerField   = cmbLayer.Text;
                    SampleData.farmLand     = cmbCultivation.Text;
                    SampleData.ASCDL        = cmbASCDL.Text;
                    SampleData.targetCrop   = cmbCrop.SelectedIndex;

                    if (!SampleSelection.ChkData(out msg))
                    {
                        XtraMessageBox.Show(msg);
                        return;
                    }

                    if (string.IsNullOrEmpty(cmbSecondUint.Text))
                    {
                        XtraMessageBox.Show("二级抽样单元为空!");
                        return;
                    }
                    fishNet = cmbSecondUint.Text;
                }

                //抽选样本
                frmWait.Caption = "抽选样本...";
                SamplePara para = new SamplePara();
                para.isNum      = chkSampleNum.Checked;
                para.sampleNum  = int.Parse(this.spinSampleNum.EditValue.ToString());
                para.sampleRate = double.Parse(this.spinPercent.EditValue.ToString()) / 100;
                SampleSelection.Sampling(firstUnit, cmbVillage.Text, cmbLayer.Text, fishNet, cmbCultivation.Text, para, txtOut.Text);

                SampleFrame sampleFrame = new SampleFrame();
                frmWait.Caption = "计算耕地面积...";
                if (!SampleSelection.CalLandArea(txtOut.Text, SampleData.farmLand, out msg))
                {
                    XtraMessageBox.Show(msg);
                    return;
                }
                frmWait.Caption = "计算分类面积...";
                if (!sampleFrame.CalClassArea(txtOut.Text, SampleData.ASCDL, SampleData.targetCrop, out msg))
                {
                    XtraMessageBox.Show(msg);
                    return;
                }
                BLL.ProductMeta meta = new ProductMeta(txtOut.Text.TrimEnd(), "", "", "二级样方", "抽样和面积推算结果");
                meta.WriteShpMeta();
                BLL.ProductQuickView view = new BLL.ProductQuickView(txtOut.Text.TrimEnd());
                view.Create();

                System.Windows.Forms.DialogResult dialogResult = XtraMessageBox.Show("抽样完成,是否加载结果?", "提示信息", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Asterisk);
                if (dialogResult == System.Windows.Forms.DialogResult.Yes)
                {
                    MapAPI.AddShpFileToMap(txtOut.Text);
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
                Log.WriteLog(typeof(frmSymbolSelector), ex);
            }
            finally
            {
                frmWait.Close();
            }
        }