public static IKDProgressBar getInstance(int BarNum) { IKDProgressBar tppb = null; switch (BarNum) { case 1: tppb = new frmProgressBar1(); break; case 2: tppb = new frmProgressBar2(); break; case 3: tppb = new frmProgressBar3(); break; case 4: tppb = new frmProgressBar4(); break; default: tppb = new frmProgressBar4(); break; } return(tppb); }
//开始批量更新 事件 private void BtnUpdate_Click(object sender, EventArgs e) { frmProgressBar2 pb2 = null; try { this.BtnUpdate.Enabled = false; this.Cursor = Cursors.WaitCursor; string LineText = ""; if (MessageBox.Show("请确认是否要对选中项进行批量更新BSM字段的值操作?", "提示", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.Cancel) { this.BtnUpdate.Enabled = true; this.Cursor = Cursors.Default; return; } //获取选中的要素类 List <IFeatureClass> fcList = new List <IFeatureClass>(); for (int i = 0; i < this.checkedListBox1.Items.Count; i++) { if (this.checkedListBox1.GetItemChecked(i) == true) { //选中要素类 CommonComboBoxItem cbitem = this.checkedListBox1.Items[i] as CommonComboBoxItem; fcList.Add(cbitem.Tag as IFeatureClass); } } if (fcList != null && fcList.Count > 0) { pb2 = new frmProgressBar2(); pb2.Text = "批量更新BSM字段进度..."; pb2.progressBar1.Maximum = fcList.Count + 1; pb2.progressBar1.Value = 0; pb2.Caption1.Text = "正在更新..."; pb2.Show(this); Application.DoEvents(); // ZHFeaturePoint zhfeat = null; int featIndex = 0; int featCount = 0; // int BSMIndex = 0; for (int i = 0; i < fcList.Count; i++) { featIndex = 0; IFeatureClass fc = fcList[i]; pb2.Caption1.Text = "正在更新图层:" + fc.AliasName + "..."; pb2.progressBar1.Value = i; Application.DoEvents(); // featCount = fc.FeatureCount(null); pb2.progressBar2.Value = 0; pb2.progressBar2.Maximum = featCount + 1; pb2.Caption2.Text = "正在更新要素..."; Application.DoEvents(); // IFeatureCursor fcur = fc.Update(null, false); IFeature feat = fcur.NextFeature(); while (feat != null) { featIndex += 1; //--- BSMIndex += 1; //--- if (featIndex % 200 == 0) { pb2.Caption2.Text = "正在更新图层:" + fc.AliasName + "(当前:" + featIndex.ToString() + "/" + featCount.ToString() + ")"; pb2.progressBar2.Value = featIndex; Application.DoEvents(); fcur.Flush(); } zhfeat = new ZHFeaturePoint(feat); zhfeat.setFieldValue("BSM", BSMIndex); fcur.UpdateFeature(feat); // feat = fcur.NextFeature(); } fcur.Flush(); if (fcur != null) { TokayWorkspace.ComRelease(fcur); fcur = null; } } if (pb2 != null) { pb2.Close(); pb2.Dispose(); pb2 = null; } MessageBox.Show("更新BSM完毕!", "提示"); } } catch (Exception ee) { Log.WriteLine(ee); MessageBox.Show(ee.Message, "提示"); } finally { this.BtnUpdate.Enabled = true; this.Cursor = Cursors.Default; if (pb2 != null) { pb2.Close(); pb2.Dispose(); pb2 = null; } } }
//开始平移 事件 private void Btn_MapMove_Click(object sender, EventArgs e) { frmProgressBar2 pb2 = null; try { this.Btn_MapMove.Enabled = false; this.Cursor = Cursors.WaitCursor; string LineText = ""; double dx = 0.0; double dy = 0.0; dx = CommonClass.TNum(this.numericBox1.Text.Trim()); dy = CommonClass.TNum(this.numericBox2.Text.Trim()); if (MessageBox.Show("请确认是否要对选中项进行整体平移操作?", "提示", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.Cancel) { this.Btn_MapMove.Enabled = true; this.Cursor = Cursors.Default; return; } //获取选中的要素类 List <IFeatureClass> fcList = new List <IFeatureClass>(); for (int i = 0; i < this.checkedListBox1.Items.Count; i++) { if (this.checkedListBox1.GetItemChecked(i) == true) { //选中要素类 CommonComboBoxItem cbitem = this.checkedListBox1.Items[i] as CommonComboBoxItem; fcList.Add(cbitem.Tag as IFeatureClass); } } if (fcList != null && fcList.Count > 0) { pb2 = new frmProgressBar2(); pb2.Text = "平移进度..."; pb2.progressBar1.Maximum = fcList.Count + 1; pb2.progressBar1.Value = 0; pb2.Caption1.Text = "正在平移..."; pb2.Show(this); Application.DoEvents(); // ZHFeaturePoint zhfeat = null; int featIndex = 0; int featCount = 0; for (int i = 0; i < fcList.Count; i++) { featIndex = 0; IFeatureClass fc = fcList[i]; pb2.Caption1.Text = "正在平移图层:" + fc.AliasName + "..."; pb2.progressBar1.Value = i; Application.DoEvents(); // featCount = fc.FeatureCount(null); pb2.progressBar2.Value = 0; pb2.progressBar2.Maximum = featCount + 1; pb2.Caption2.Text = "正在平移要素..."; Application.DoEvents(); // IFeatureCursor fcur = fc.Update(null, false); IFeature feat = fcur.NextFeature(); while (feat != null) { featIndex += 1; if (featIndex % 200 == 0) { pb2.Caption2.Text = "正在平移图层:" + fc.AliasName + "(当前:" + featIndex.ToString() + "/" + featCount.ToString() + ")"; pb2.progressBar2.Value = featIndex; Application.DoEvents(); fcur.Flush(); } zhfeat = new ZHFeaturePoint(feat); if (fc.FeatureType == esriFeatureType.esriFTAnnotation) { //注记要素移动 OK IAnnotationFeature anFeat = feat as IAnnotationFeature; IElement TextEl = (IElement)((IClone)anFeat.Annotation).Clone(); ITransform2D trans = TextEl as ITransform2D; trans.Move(dx, dy); anFeat.Annotation = TextEl; fcur.UpdateFeature(feat); } else { //一般要素移动 OK zhfeat.Move(dx, dy); fcur.UpdateFeature(feat); } // feat = fcur.NextFeature(); } fcur.Flush(); if (fcur != null) { TokayWorkspace.ComRelease(fcur); fcur = null; } pb2.Caption2.Text = "正在重新计算Extent范围..."; Application.DoEvents(); //重新计算Extent范围 TokayWorkspace.UpdateExtent(fc); } if (pb2 != null) { pb2.Close(); pb2.Dispose(); pb2 = null; } MessageBox.Show("地图平移完毕!", "提示"); } } catch (Exception ee) { Log.WriteLine(ee); MessageBox.Show(ee.Message, "提示"); } finally { this.Btn_MapMove.Enabled = true; this.Cursor = Cursors.Default; if (pb2 != null) { pb2.Close(); pb2.Dispose(); pb2 = null; } } }
private void BtnUpdate_Click(object sender, EventArgs e) { frmProgressBar2 pb2 = null; try { this.BtnUpdate.Enabled = false; this.Cursor = Cursors.WaitCursor; // string txtPath = this.textBox1.Text.Trim(); if (txtPath == "" || System.IO.File.Exists(txtPath) == false) { MessageBox.Show("请先选择YSDM对照txt文件", "提示"); this.BtnUpdate.Enabled = true; this.Cursor = Cursors.Default; return; } // if (MessageBox.Show("请确认是否要对选中项进行批量更新YSDM字段的值操作?", "提示", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.Cancel) { this.BtnUpdate.Enabled = true; this.Cursor = Cursors.Default; return; } //-------------------------------------- List <ItemClass> ItemList = new List <ItemClass>(); StreamReader sr = new StreamReader(txtPath, Encoding.Default); while (sr.EndOfStream == false) { string line = sr.ReadLine(); string[] lineArray = line.Split(new char[] { ',' }); if (lineArray != null && lineArray.Length >= 3) { ItemClass item = new ItemClass(); item.Value = lineArray[0].Trim(); //YSDM item.Caption = lineArray[1].Trim(); //YSDMName item.Tag = lineArray[2].Trim(); //LayerName // ItemList.Add(item); } } if (sr != null) { sr.Close(); sr.Dispose(); sr = null; } //-------------------------------------- //获取选中的要素类 List <IFeatureClass> fcList = new List <IFeatureClass>(); for (int i = 0; i < this.checkedListBox1.Items.Count; i++) { if (this.checkedListBox1.GetItemChecked(i) == true) { //选中要素类 CommonComboBoxItem cbitem = this.checkedListBox1.Items[i] as CommonComboBoxItem; fcList.Add(cbitem.Tag as IFeatureClass); } } if (fcList != null && fcList.Count > 0) { pb2 = new frmProgressBar2(); pb2.Text = "批量更新YSDM字段进度..."; pb2.progressBar1.Maximum = fcList.Count + 1; pb2.progressBar1.Value = 0; pb2.Caption1.Text = "正在更新..."; pb2.Show(this); Application.DoEvents(); // ZHFeaturePoint zhfeat = null; int featIndex = 0; int featCount = 0; // string YSDM = ""; for (int i = 0; i < fcList.Count; i++) { featIndex = 0; IFeatureClass fc = fcList[i]; pb2.Caption1.Text = "正在更新图层:" + fc.AliasName + "..."; pb2.progressBar1.Value = i; Application.DoEvents(); // featCount = fc.FeatureCount(null); pb2.progressBar2.Value = 0; pb2.progressBar2.Maximum = featCount + 1; pb2.Caption2.Text = "正在更新要素..."; Application.DoEvents(); //获取图层对应的要素代码值 string fcName = fc.AliasName; if (fc is IDataset) { fcName = (fc as IDataset).Name; } foreach (ItemClass item in ItemList) { string txtLayerName = item.Tag.ToString(); //------------------------------- if (cb_IsLayerLastPreStr.Checked == true) { //是后缀字符串 txtLayerName = txtLayerName + this.txt_LayerPreStr.Text.Trim(); } else { //是前缀字符串 txtLayerName = this.txt_LayerPreStr.Text.Trim() + txtLayerName; } //------------------------------- if (fcName.ToUpper() == txtLayerName.ToUpper()) { YSDM = item.Value.ToString(); break; } } // IFeatureCursor fcur = fc.Update(null, false); IFeature feat = fcur.NextFeature(); while (feat != null) { featIndex += 1; if (featIndex % 200 == 0) { pb2.Caption2.Text = "正在更新图层:" + fc.AliasName + "(当前:" + featIndex.ToString() + "/" + featCount.ToString() + ")"; pb2.progressBar2.Value = featIndex; Application.DoEvents(); fcur.Flush(); } zhfeat = new ZHFeaturePoint(feat); zhfeat.setFieldValue("YSDM", YSDM); fcur.UpdateFeature(feat); // feat = fcur.NextFeature(); } fcur.Flush(); if (fcur != null) { TokayWorkspace.ComRelease(fcur); fcur = null; } } if (pb2 != null) { pb2.Close(); pb2.Dispose(); pb2 = null; } MessageBox.Show("更新YSDM完毕!", "提示"); } } catch (Exception ee) { Log.WriteLine(ee); MessageBox.Show(ee.Message, "提示"); } finally { this.BtnUpdate.Enabled = true; this.Cursor = Cursors.Default; if (pb2 != null) { pb2.Close(); pb2.Dispose(); pb2 = null; } } }