Esempio n. 1
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            ProgressDialog pd = null;

            try
            {
                ItemClass item = this.comboBox1.SelectedItem as ItemClass;
                if (item == null)
                {
                    MessageBox.Show("请先选择要更新的图层", "提示");
                    return;
                }
                ItemClass fd_item = this.comboBox2.SelectedItem as ItemClass;
                if (fd_item == null)
                {
                    MessageBox.Show("请先选择要更新的字段", "提示");
                    return;
                }
                int totalWidth = 0;
                int.TryParse(this.fd_totalWidth.Text, out totalWidth);
                //
                ILayer        layer     = item.Value as ILayer;
                IFeatureLayer featLayer = layer as IFeatureLayer;
                IFeatureClass fc        = featLayer.FeatureClass;
                //
                string fdName = fd_item.Caption;
                //
                int fCount = fc.FeatureCount(null);
                if (fCount > 0)
                {
                    pd         = new ProgressDialog();
                    pd.Text    = "进度";
                    pd.Message = "自动补零前缀长度中......";
                    pd.Minimum = 0;
                    pd.Maximum = fCount;
                    pd.Show(this);
                    //
                    Application.DoEvents();
                    //
                    IFeatureCursor pcursor = fc.Update(null, false);
                    IFeature       pf      = pcursor.NextFeature();
                    int            index   = fc.FindField(fdName);
                    //
                    int n = 0;
                    while (pf != null)
                    {
                        n = n + 1;
                        if (n % 200 == 0)
                        {
                            pd.Value   = n;
                            pd.Message = "自动补零前缀长度中......" + pd.Value.ToString() + "/" + pd.Maximum.ToString();
                            Application.DoEvents();
                            pcursor.Flush();
                        }
                        object v = pf.get_Value(index);
                        if (v != null)
                        {
                            string prex = v.ToString();
                            if (cb_IsPreAdd0.Checked == true)
                            {   //是向前补0     10->00010
                                prex = prex.PadLeft(totalWidth, '0');
                            }
                            else
                            {   //是向后补0     10->10000
                                prex = prex.PadRight(totalWidth, '0');
                            }
                            pf.set_Value(index, prex);
                            pcursor.UpdateFeature(pf);
                            //
                        }
                        pf = pcursor.NextFeature();
                    }
                    pcursor.Flush();
                    if (pcursor != null)
                    {
                        TokayWorkspace.ComRelease(pcursor);
                        pcursor = null;
                    }
                    if (pd != null)
                    {
                        pd.Dispose();
                        pd = null;
                    }
                    MessageBox.Show("更新完毕!", "提示");
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.StackTrace, "提示");
            }
            finally
            {
                if (pd != null)
                {
                    pd.Dispose();
                    pd = null;
                }
            }
        }
Esempio n. 2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            ProgressDialog pd = null;

            try
            {
                ItemClass item = this.comboBox1.SelectedItem as ItemClass;
                if (item == null)
                {
                    MessageBox.Show("请先选择要更新的图层", "提示");
                    return;
                }
                ItemClass fd_item = this.comboBox2.SelectedItem as ItemClass;
                if (fd_item == null)
                {
                    MessageBox.Show("请先选择要更新的字段", "提示");
                    return;
                }
                ILayer        layer     = item.Value as ILayer;
                IFeatureLayer featLayer = layer as IFeatureLayer;
                IFeatureClass fc        = featLayer.FeatureClass;
                //
                string fdName = fd_item.Caption;
                //
                int fCount = fc.FeatureCount(null);
                if (fCount > 0)
                {
                    IFeatureCursor pcursor = fc.Update(null, false);
                    IFeature       pf      = pcursor.NextFeature();
                    int            index   = fc.FindField(fdName);
                    pd         = new ProgressDialog();
                    pd.Text    = "进度";
                    pd.Message = "更新字段索引Index中......";
                    pd.Minimum = 0;
                    pd.Maximum = fCount;
                    pd.Show(this);
                    int n = 0;
                    while (pf != null)
                    {
                        n = n + 1;
                        if (n % 200 == 0)
                        {
                            pd.Value   = n;
                            pd.Message = "更新字段索引Index中......" + pd.Value.ToString() + "/" + pd.Maximum.ToString();
                            Application.DoEvents();
                            pcursor.Flush();
                        }
                        pf.set_Value(index, n);
                        pcursor.UpdateFeature(pf);
                        //
                        pf = pcursor.NextFeature();
                    }
                    pcursor.Flush();
                    if (pcursor != null)
                    {
                        TokayWorkspace.ComRelease(pcursor);
                        pcursor = null;
                    }
                    if (pd != null)
                    {
                        pd.Dispose();
                        pd = null;
                    }
                    MessageBox.Show("更新完毕!", "提示");
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.StackTrace, "提示");
            }
            finally
            {
                if (pd != null)
                {
                    pd.Dispose();
                    pd = null;
                }
            }
        }