//选中表格某一行事件
 private void gridView1_MouseDown(object sender, MouseEventArgs e)
 {
     DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hi = this.gridView1.CalcHitInfo(new Point(e.X, e.Y));
     if (e.Button == MouseButtons.Left && e.Clicks == 2)
     {
         //判断光标是否在行范围内
         if (hi.InRow)
         {
             int vsRowNum = hi.RowHandle;//鼠标选中行号
             //每次抽样得到的样本
             sampleTable = SampleZones[vsRowNum];
             string outfile = Path.Combine(ConstDef.PATH_TEMP, DateTime.Now.ToFileTime().ToString() + ".shp");
             try
             {
                 SampleSimulation Sim = new SampleSimulation();
                 if (Sim.CreateShpFile(cBFile.Text, sampleTable, outfile))
                 {
                     //添加第i次得到的样本结果到主地图视图
                     //MapAPI.AddShpFileToMap(outfile);
                     MapAPI.AddShpFileToMap(outfile);
                 }
             }
             catch (Exception ex)
             {
                 XtraMessageBox.Show(ex.Message);
             }
         }
     }
 }
 //选中表格某一行事件
 private void gridView1_MouseDown(object sender, MouseEventArgs e)
 {
     DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hi = this.gridView1.CalcHitInfo(new Point(e.X, e.Y));
     if (e.Button == MouseButtons.Left && e.Clicks == 2)
     {
         //判断光标是否在行范围内
         if (hi.InRow)
         {
             int vsRowNum = hi.RowHandle;//鼠标选中行号
             //每次抽样得到的样本
             sampleTable = SampleZones[vsRowNum];
             string outfile = Path.Combine(ConstDef.PATH_TEMP, DateTime.Now.ToFileTime().ToString() + ".shp");
             try
             {
                 SampleSimulation Sim = new SampleSimulation();
                 if (Sim.CreateShpFile(cBFile.Text, sampleTable, outfile))
                 {
                     //添加第i次得到的样本结果到主地图视图
                     //MapAPI.AddShpFileToMap(outfile);
                     string layerName = string.Format("第{0}次抽样结果", vsRowNum + 1);
                     for (int i = 0; i < _pMapControl.LayerCount; i++)
                     {
                         ILayer pLayer = _pMapControl.get_Layer(i);
                         if (pLayer is IFeatureLayer)
                         {
                             if (pLayer.Name == layerName)
                             {
                                 _pMapControl.Map.DeleteLayer(pLayer);
                             }
                         }
                     }
                     IFeatureClass pFC = EngineAPI.OpenFeatureClass(outfile);
                     IFeatureLayer pFL = new FeatureLayerClass();
                     pFL.Name         = layerName;
                     pFL.FeatureClass = pFC;
                     _pMapControl.AddLayer(pFL);
                 }
             }
             catch (Exception ex)
             {
                 XtraMessageBox.Show(ex.Message);
             }
         }
     }
 }
        private void siBDistribute_Click(object sender, EventArgs e)
        {
            int vsRowNum = gridView1.FocusedRowHandle;//鼠标选中行号

            //每次抽样得到的样本
            sampleTable = SampleZones[vsRowNum];
            string outfile = Path.Combine(ConstDef.PATH_TEMP, DateTime.Now.ToFileTime().ToString() + ".shp");

            try
            {
                SampleSimulation Sim = new SampleSimulation();
                if (Sim.CreateShpFile(cBFile.Text, sampleTable, outfile))
                {
                    //添加第i次得到的样本结果到主地图视图
                    //MapAPI.AddShpFileToMap(outfile);
                    string layerName = string.Format("第{0}次抽样结果", vsRowNum + 1);
                    for (int i = 0; i < _pMapControl.LayerCount; i++)
                    {
                        ILayer pLayer = _pMapControl.get_Layer(i);
                        if (pLayer is IFeatureLayer)
                        {
                            if (pLayer.Name == layerName)
                            {
                                _pMapControl.Map.DeleteLayer(pLayer);
                            }
                        }
                    }
                    IFeatureClass pFC = EngineAPI.OpenFeatureClass(outfile);
                    IFeatureLayer pFL = new FeatureLayerClass();
                    pFL.Name         = layerName;
                    pFL.FeatureClass = pFC;
                    _pMapControl.AddLayer(pFL);
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }
        }
 private void siBOK_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(cBESave.Text.Trim()))
     {
         MessageBox.Show("错误信息:\n输出结果的值:是必需的");
     }
     else
     {
         frmWaitDialog frmWait = new frmWaitDialog("正在生成...", "提示信息");
         try
         {
             DataTable        ExtandTable = new DataTable();
             SampleSimulation Sim         = new SampleSimulation();
             int sampleSum       = SamplingSum - sampleNum; //第一次抽样,剩余的样本总量
             int sampleExtandNum = 0;                       //扩充的样本量
             //每次抽样得到的样本
             sampleTable = SampleZones[gridView1.FocusedRowHandle];
             if (string.IsNullOrEmpty(tEExtend.Text.Trim()) && string.IsNullOrEmpty(tEScale.Text.Trim()))
             {
                 ExtandTable = sampleTable;
             }
             else
             {
                 if (cEExtend.Checked == true)
                 {
                     sampleExtandNum = Convert.ToInt32(tEExtend.Text);
                 }
                 else
                 {
                     sampleExtandNum = Convert.ToInt32(sampleSum * (Convert.ToDouble(tEScale.Text) / 100));
                 }
                 if (0 > sampleExtandNum || sampleExtandNum > sampleSum)
                 {
                     MessageBox.Show("输入的扩充样本量超出范围,请重新输入!");
                     return;
                 }
                 else if (sampleExtandNum == 0)
                 {
                     ExtandTable = sampleTable;
                 }
                 else
                 {
                     ExtandTable = Sim.ExtendSample(sampleSumTable, sampleTable, sampleExtandNum, cBELayer.Text, cBEBasis.Text);
                 }
             }
             if (ExtandTable != null)
             {
                 if (Sim.CreateShpFile(cBFile.Text, ExtandTable, cBESave.Text))
                 {
                     BLL.ProductMeta meta = new ProductMeta(cBESave.Text.TrimEnd(), "", "", "一级样本村", "抽样和面积推算结果");
                     meta.WriteShpMeta();
                     BLL.ProductQuickView view = new BLL.ProductQuickView(cBESave.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)
                     {
                         //添加结果到主地图视图
                         IFeatureClass pFC = EngineAPI.OpenFeatureClass(cBESave.Text);
                         if (pFC != null)
                         {
                             IFeatureLayer pFLyr = new FeatureLayerClass();
                             pFLyr.FeatureClass = pFC;
                             pFLyr.Name         = (pFC as IDataset).Name;
                             MapAPI.UniqueValueRender(pFLyr, "KC");
                             EnviVars.instance.MapControl.AddLayer(pFLyr);
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             XtraMessageBox.Show(ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             Log.WriteLog(typeof(frmSampleSimulation), ex);
         }
         finally
         {
             frmWait.Close();
             this.Close();
         }
     }
 }
 private void siBOK_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(cBESave.Text.Trim()))
     {
         MessageBox.Show("错误信息:\n输出结果的值:是必需的");
     }
     else
     {
         WaitDialogForm frmWait = new WaitDialogForm("正在生成...", "提示信息");
         try
         {
             DataTable        ExtandTable = new DataTable();
             SampleSimulation Sim         = new SampleSimulation();
             int sampleSum       = SamplingSum - sampleNum; //第一次抽样,剩余的样本总量
             int sampleExtandNum = 0;                       //扩充的样本量
             if (string.IsNullOrEmpty(tEExtend.Text.Trim()) && string.IsNullOrEmpty(tEScale.Text.Trim()))
             {
                 ExtandTable = sampleTable;
             }
             else
             {
                 if (cEExtend.Checked == true)
                 {
                     sampleExtandNum = Convert.ToInt32(tEExtend.Text);
                 }
                 else
                 {
                     sampleExtandNum = Convert.ToInt32(sampleSum * (Convert.ToDouble(tEScale.Text) / 100));
                 }
                 if (0 > sampleExtandNum || sampleExtandNum > sampleSum)
                 {
                     MessageBox.Show("输入的扩充样本量超出范围,请重新输入!");
                     return;
                 }
                 else if (sampleExtandNum == 0)
                 {
                     ExtandTable = sampleTable;
                 }
                 else
                 {
                     ExtandTable = Sim.ExtendSample(sampleSumTable, sampleTable, sampleExtandNum, cBELayer.Text, cBEBasis.Text);
                 }
             }
             if (ExtandTable != null)
             {
                 if (Sim.CreateShpFile(cBFile.Text, ExtandTable, cBESave.Text))
                 {
                     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(cBESave.Text);
                         MapAPI.AddShpFileToMap(cBESave.Text);
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             XtraMessageBox.Show(ex.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             Log.WriteLog(typeof(frmSampleSimulation), ex);
         }
         finally
         {
             frmWait.Close();
             this.Close();
         }
     }
 }