Пример #1
0
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            bool removeOldPos = true;
            if (chkRemoveOldPos.CheckState == CheckState.Unchecked)
            {
                removeOldPos = false;
            }
            SdeConnection conn = new SdeConnection();
            ISdeConnectionInfo sdeConn = conn as ISdeConnectionInfo;
            IWorkspaceEdit wspEdit = (IWorkspaceEdit)sdeConn.Workspace;
            IMultiuserWorkspaceEdit mwspEdit = (IMultiuserWorkspaceEdit)sdeConn.Workspace;
            ITnFeatureClassName _fcName = new TnFeatureClassName(sdeConn.Workspace);
            ITnTableName _tblName = new TnTableName(sdeConn.Workspace);
            IFeatureWorkspace fw = (IFeatureWorkspace)sdeConn.Workspace;
            ICopyFeatures copyTool = new DataManager(sdeConn.Workspace, sdeConn.Environment);
            IQueryFilter qrf = new QueryFilterClass();
            IFeatureClass tgdFeatureClass = null;
            ICurrentConfig config = CurrentConfig.CallMe();
            List<object[,]> pairColValTgd = new List<object[,]>();
            int rowTgdNnHandleUpdate = 0;
            List<object> newId = new List<object>();
            string tgdDraft = string.Format("{0}_{1}", DataNameTemplate.Thua_Gia_Dat_Draft, config.NamApDung);
            _fcName.FC_THUA_GIADAT_DRAFT.NAME = tgdDraft;
            _fcName.FC_THUA_GIADAT_DRAFT.InitIndex();
            try
            {
                tgdFeatureClass = fw.OpenFeatureClass(tgdDraft);
            }
            catch (Exception exc)
            {
                //evt.Log = string.Format("Không tìm thấy lớp dữ liệu: {0}", tgdDraft);
                //onCalculating(evt);
                //onFinished(evt);
                return;
            }
            ITable tblThuaGiaDat = (ITable)tgdFeatureClass;
            ISDETableEditor sdeTblTgdEditor = new SDETable(tblThuaGiaDat, sdeConn.Workspace);

            //lay thong tin thua
            for (int i=0;i< _lstThuaFt.Count;i++)
            {
                IFeature thuaFt = _lstThuaFt[i];

                //string lockTimVitri = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.LOCKED)).ToString();
                object dientichpl = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.DIEN_TICH));

                object mathua = _lstMaThua[i];//txtMathua.Text;
                string maduong = txtMaDuong.Text;
                string mahem = txtMaHem.Text;

                if (maduong == "" || maduong ==null)
                {
                    maduong = "0";
                }
                if (mahem == "" || mahem == null)
                {
                    mahem = "0";
                }
                string hesoVitri = txtHsk.Text;
                ICursor tgdFcs1;
                IRow tgdRow = null;
                if (removeOldPos)
                {
                    qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_THUA_GIADAT_DRAFT.MA_THUA, mathua);
                    tgdFcs1=tblThuaGiaDat.Search(qrf, false);
                    try
                    {
                        while ((tgdRow = tgdFcs1.NextRow()) != null)
                        {
                            #region xoa feature cu
                            mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
                            wspEdit.StartEditOperation();
                            //qrf.WhereClause = string.Format("{0}='{1}'", "OBJECTID", tgdRow.OID);
                            //tblThuaGiaDat.DeleteSearchedRows(qrf);
                            tgdRow.Delete();
                            wspEdit.StopEditOperation();
                            wspEdit.StopEditing(true);
                            #endregion
                        }
                    }
                    catch { }
                    finally { Marshal.ReleaseComObject(tgdFcs1); }
                }

                if (mahem == "0")
                {
                    qrf.WhereClause = string.Format("({0}='{1}' or {2} is null) and {3}='{4}' and {5}='{6}' and {7}='{8}'",
                                    _fcName.FC_THUA_GIADAT_DRAFT.LOCKED, 0, _fcName.FC_THUA_GIADAT_DRAFT.LOCKED,
                                    _fcName.FC_THUA_GIADAT_DRAFT.MA_THUA, mathua,
                                    _fcName.FC_THUA_GIADAT_DRAFT.MA_DUONG, maduong,
                                    _fcName.FC_THUA_GIADAT_DRAFT.HE_SO_K, hesoVitri);
                }
                else if (mahem != "0")
                {
                    qrf.WhereClause = string.Format("({0}='{1}' or {2} is null) and {3}='{4}' and {5}='{6}' and {7}='{8}'",
                                    _fcName.FC_THUA_GIADAT_DRAFT.LOCKED, 0, _fcName.FC_THUA_GIADAT_DRAFT.LOCKED,
                                    _fcName.FC_THUA_GIADAT_DRAFT.MA_THUA, mathua,
                                    _fcName.FC_THUA_GIADAT_DRAFT.MA_HEM, mahem,
                                    _fcName.FC_THUA_GIADAT_DRAFT.HE_SO_K, hesoVitri);
                }
                //MessageBox.Show("line 157 FrmSet.., ",+ qrf.WhereClause);
                ICursor tgdFcs = tblThuaGiaDat.Search(qrf, false);

                try
                {
                    tgdRow = tgdFcs.NextRow();//dam bao la chi co 1 hang ket qua
                    if (tgdRow != null)
                    {
                        //MessageBox.Show("co");
                        //kiem tra co cho phep tinh lai vi tri
                        //neu co:xoa feater cu,them feature moi
                        #region xet thua da co vi tri

                        bool isOverWritePos = true;

                        if (!isOverWritePos)
                        {
                            newId.Add(tgdRow.OID);
                            //continue;
                        }
                        else
                        {
                            //[kodoi]
                            //===================
                            #region xoa feature cu
                            mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
                            wspEdit.StartEditOperation();
                            //qrf.WhereClause = string.Format("{0}='{1}'", "OBJECTID", tgdRow.OID);
                            //tblThuaGiaDat.DeleteSearchedRows(qrf);
                            tgdRow.Delete();
                            wspEdit.StopEditOperation();
                            wspEdit.StopEditing(true);
                            #endregion
                            //===================

                            //[thaydoi] - them gia tri
                            //**********************
                            #region them feature moi
                            mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
                            wspEdit.StartEditOperation();
                            object copiedId = copyTool.Copy(thuaFt, tgdFeatureClass);
                            wspEdit.StopEditOperation();
                            wspEdit.StopEditing(true);

                            //them gia tri mathua,maduong,hesovitri
                            pairColValTgd.Add(new object[,] { { tgdRow.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.MA_THUA), mathua } });
                            pairColValTgd.Add(new object[,] { { tgdRow.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.MA_DUONG), maduong } });
                            pairColValTgd.Add(new object[,] { { tgdRow.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.MA_HEM), mahem } });
                            pairColValTgd.Add(new object[,] { { tgdRow.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.HE_SO_K), hesoVitri } });
                            pairColValTgd.Add(new object[,] { { tgdRow.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.DIEN_TICH_PHAP_LY), dientichpl } });
                            sdeTblTgdEditor.CacheData(copiedId, rowTgdNnHandleUpdate, pairColValTgd, EnumTypeOfEdit.UPDATE);
                            rowTgdNnHandleUpdate++;
                            pairColValTgd.Clear();
                            newId.Add(copiedId);
                            #endregion
                            //**********************
                        }

                        #endregion

                    }
                    else
                    {
                        //MessageBox.Show("ko co");
                        //MessageBox.Show("line 220 FrmSet.., " + thuaFt.ToString());
                        //[thaydoi] - them cac gia tri thich hop vao thua_giadat
                        //***********************************
                        #region them feature moi
                        mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
                        wspEdit.StartEditOperation();
                        object copiedId = copyTool.Copy(thuaFt, tgdFeatureClass);
                        //MessageBox.Show("line 220 FrmSet.., copiedid" + copiedId.ToString());
                        wspEdit.StopEditOperation();
                        wspEdit.StopEditing(true);

                        //them gia tri mathua,maduong,hesovitri
                        pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.MA_THUA), mathua } });
                        pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.MA_DUONG), maduong } });
                        pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.MA_HEM), mahem } });
                        pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.HE_SO_K), hesoVitri } });
                        pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.DIEN_TICH_PHAP_LY), dientichpl } });
                        //MessageBox.Show(string.Format("line 248 FrmSet.., mathua={0},maduong={1},hsk={2}, dientich={3}" , mathua,maduong,hesoVitri,dientichpl));
                        //MessageBox.Show(string.Format("line 249 FrmSet..,index mathua={0},maduong={1},hsk={2}, dientich={3}" , _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.MA_THUA), _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.MA_DUONG), _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.HE_SO_K), _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.DIEN_TICH_PHAP_LY)));
                        sdeTblTgdEditor.CacheData(copiedId, rowTgdNnHandleUpdate, pairColValTgd, EnumTypeOfEdit.UPDATE);
                        rowTgdNnHandleUpdate++;
                        pairColValTgd.Clear();
                        newId.Add(copiedId);
                        #endregion
                        //***********************************
                    }
                    //MessageBox.Show(newId.Count.ToString());
                }
                catch (Exception e1) { MessageBox.Show(string.Format("CalcPosThuaMattien, line 1448-\n{0}", e1)); }
                finally { Marshal.ReleaseComObject(tgdFcs); }
            }
            #region luu thong tin vao bang gia dat
            //MessageBox.Show("line 250 FrmSet..., "+wspEdit.IsBeingEdited().ToString());
            if (!sdeTblTgdEditor.IsEditing())
            {
                sdeTblTgdEditor.StartEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
                //MessageBox.Show("line 250 FrmSet..., " + wspEdit.IsBeingEdited().ToString());
                sdeTblTgdEditor.StartEditOperation();
            }
            try
            {
                sdeTblTgdEditor.SaveEdit();
                sdeTblTgdEditor.StopEditOperation();
                sdeTblTgdEditor.StopEditing(true);
            }
            catch
            {
                sdeTblTgdEditor.AbortEditOperation();
                sdeTblTgdEditor.StopEditing(false);
            }

            #endregion

            #region tinh gia dat cho cac thua vua them vi tri
            CalcLandprice calc = new CalcLandprice();
            calc.Calculate(newId);
            newId.Clear();
            #endregion
            this.Close();
        }
Пример #2
0
        private void _bwk_DoWork(object sender, DoWorkEventArgs e)
        {
            List<object> newId = (List<object>)e.Argument;
            ICurrentConfig _currentConfig = CurrentConfig.CallMe();

            #region khoi tao connection
            SdeConnection conn = new SdeConnection();
            ISdeConnectionInfo sdeConn = conn as ISdeConnectionInfo;
            IFeatureWorkspace fw = (IFeatureWorkspace)sdeConn.Workspace;
            IWorkspaceEdit _wspEdit = (IWorkspaceEdit)sdeConn.Workspace;
            IMultiuserWorkspaceEdit _mwspEdit = (IMultiuserWorkspaceEdit)sdeConn.Workspace;
            ITnFeatureClassName _fcName = new TnFeatureClassName(sdeConn.Workspace);
            ITnTableName _tblName = new TnTableName(sdeConn.Workspace);
            #endregion

            #region khoi tao cac bien
            string tgd = string.Format("{0}_{1}", DataNameTemplate.Thua_Gia_Dat, _currentConfig.NamApDung);
            string thua = string.Format("{0}_{1}", DataNameTemplate.Thua, _currentConfig.NamApDung);
            _fcName.FC_THUA_GIADAT.NAME = tgd;
            _fcName.FC_THUA_GIADAT.InitIndex();
            _fcName.FC_THUA.NAME = thua;
            _fcName.FC_THUA.InitIndex();
            IFeatureClass tgdFeatureClass = null;
            IFeatureClass thuaFeatureClass = null;
            try
            {
                tgdFeatureClass = fw.OpenFeatureClass(tgd);
            }
            catch
            {
                MessageBox.Show("Không tìm thấy bảng " + tgd);
                return;
            }
            try
            {
                thuaFeatureClass = fw.OpenFeatureClass(thua);
            }
            catch
            {
                MessageBox.Show("Không tìm thấy bảng " + thua);
                return;
            }
            ITable tblThua = (ITable)thuaFeatureClass;
            ITable tblThuaGiaDat = (ITable)tgdFeatureClass;
            ISDETableEditor sdeTblThuaEditor = new SDETable(tblThua, sdeConn.Workspace);
            IQueryFilter qrf = new QueryFilterClass();
            bool result = false;
            #endregion

            #region vong lap tung id

            #region khoi dau

            List<object[,]> pairColValTgd = new List<object[,]>();
            CalculationEventArg evt = new CalculationEventArg();
            //evt.Reset();
            //evt.Log = "\n\nBắt đầu chọn lọc giá cho các thửa vừa tính...";
            //_caller.onCalculating(evt);
            int len = newId.Count;
            int thuaCount = 1;
            //MessageBox.Show(string.Format("line 620 CalcLandprice {0}",len.ToString()));
            #endregion

            List<object> mathuaCalced = new List<object>();
            foreach (object o in newId)
            {
                if (thuaCount < len)
                {
                    decimal i = (decimal)thuaCount / (decimal)len * 100;
                    int i1 = Convert.ToInt32(i);
                    _bwk.ReportProgress(i1);
                    //MessageBox.Show("log 009");
                }
                else
                {
                    _bwk.ReportProgress(99);
                }
                thuaCount++;
                IRow tgdRowNew=null;
                try
                {
                    tgdRowNew = tblThuaGiaDat.GetRow((int)o);
                }
                catch(Exception ex) { continue; }
                if (tgdRowNew == null)
                {
                    continue;
                }
                string mathuaNew = tgdRowNew.get_Value(tgdRowNew.Fields.FindField(_fcName.FC_THUA_GIADAT.MA_THUA)).ToString();
                //MessageBox.Show(string.Format("line 156 Sum: mathua={0}", mathuaNew));
                if (mathuaCalced.Count > 0)
                {
                    foreach (object ob in mathuaCalced)
                    {
                        if (string.Compare(mathuaNew.ToString(), ob.ToString()) == 0)
                        {

                            continue;
                        }
                    }
                }
                mathuaCalced.Add(mathuaNew);
                #region vong lap xet vung gia co ma mathuaNew
                qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_THUA_GIADAT.MA_THUA, mathuaNew);
                IFeatureCursor tgdCur = tgdFeatureClass.Search(qrf, false);
                IFeature tgdFt = null;
                try
                {
                    double giadatTong = 0;
                    double giadat = 0;
                    object id = 0;
                    int maduong = 0;
                    while ((tgdFt = tgdCur.NextFeature()) != null)
                    {
                        id = tgdFt.OID;
                        result = double.TryParse(tgdFt.get_Value(tgdFt.Fields.FindField(_fcName.FC_THUA_GIADAT.GIA_DAT)).ToString(), out giadat);
                        if (!result)
                        {
                            giadat = 0;
                        }
                        giadatTong += giadat;
                        result =int.TryParse(tgdFt.get_Value(tgdFt.Fields.FindField(_fcName.FC_THUA_GIADAT.MA_DUONG)).ToString(),out maduong);
                        if (!result)
                        {
                            maduong = 0;
                        }
                        //MessageBox.Show(string.Format("line 187 id= {0}, Sum: giadat={1}",id, giadatTong));
                    }
                    pairColValTgd.Add(new object[,] { { _fcName.FC_THUA.GetIndex(_fcName.FC_THUA.GIA_DAT), giadatTong } });
                    pairColValTgd.Add(new object[,] { { _fcName.FC_THUA.GetIndex(_fcName.FC_THUA.MA_DUONG), maduong } });
                    qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_THUA.MA_THUA, mathuaNew);
                    IFeatureCursor thuaCur = thuaFeatureClass.Search(qrf, false);
                    IFeature thuaFt = null;
                    try
                    {
                        if ((thuaFt = thuaCur.NextFeature()) != null)
                        {
                            object tid = thuaFt.OID;
                            //MessageBox.Show(string.Format("line 199 Sum: id={0}", tid));
                            //MessageBox.Show(string.Format("line 187 id= {0}, Sum: giadat={1}", tid, giadatTong));
                            sdeTblThuaEditor.CacheData(tid, 0, pairColValTgd, EnumTypeOfEdit.UPDATE);
                            pairColValTgd.Clear();
                        }
                    }
                    catch (Exception ex) { continue; }
                    finally { Marshal.ReleaseComObject(thuaCur); }

                }
                catch (Exception ex)
                {
                    continue;
                }
                finally
                {
                    Marshal.ReleaseComObject(tgdCur);
                }

                #endregion
            }
            if (!sdeTblThuaEditor.IsEditing())
            {
                sdeTblThuaEditor.StartEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
                sdeTblThuaEditor.StartEditOperation();
            }
            else
            {
                try
                {
                    sdeTblThuaEditor.SaveEdit();
                    sdeTblThuaEditor.StopEditOperation();
                    sdeTblThuaEditor.StopEditing(true);
                }
                catch
                {
                    sdeTblThuaEditor.StopEditOperation();
                    sdeTblThuaEditor.StopEditing(false);
                }
                sdeTblThuaEditor.StartEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
                sdeTblThuaEditor.StartEditOperation();
            }
            try
            {
                sdeTblThuaEditor.SaveEdit();
                sdeTblThuaEditor.StopEditOperation();
                sdeTblThuaEditor.StopEditing(true);
            }
            catch (Exception ex)
            {
                sdeTblThuaEditor.StopEditOperation();
                sdeTblThuaEditor.StopEditing(false);
            }
            #endregion
        }
Пример #3
0
        ISelectionSet ISpatialAlgrorithm.Execute()
        {
            SdeConnection conn = new SdeConnection();
            ISdeConnectionInfo sdeConn = conn as ISdeConnectionInfo;
            IFeatureWorkspace fw = (IFeatureWorkspace)sdeConn.Workspace;
            ITnFeatureClassName fcName = new TnFeatureClassName(sdeConn.Workspace);
            ITnTableName tblName = new TnTableName(sdeConn.Workspace);
            IFeatureClass xaFeatureClass = fw.OpenFeatureClass(fcName.FC_RANH_XA_POLY.NAME);
            IFeatureLayer xaFeatureLayer = new FeatureLayerClass();
            xaFeatureLayer.FeatureClass = xaFeatureClass;
            IFeatureClass duongFeatureClass = fw.OpenFeatureClass(fcName.FC_DUONG.NAME);
            IFeatureLayer duongFeatureLayer = new FeatureLayerClass();
            duongFeatureLayer.FeatureClass = duongFeatureClass;
            //IQueryFilter qrf = new QueryFilterClass();
            //qrf.WhereClause = string.Format("{0}='{1}'", fcName.FC_RANH_XA_POLY.MA_XA, 5);
            //ISelectionSet xaSelectionSet = xaFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace);
            //IFeatureSelection xaFeatureSelection = (IFeatureSelection)xaFeatureLayer;
            //xaFeatureSelection.SelectionSet = xaSelectionSet;
            //if (this._fromLayer == null || this._byLayer == null)
            //{
            //    return null;
            //}
            //this._resultSelectionSet=this._queryByLayer.Select();
            //IFeatureLayer f=new FeatureLayerClass();
            //f.FeatureClass=this._frmFc;
            //IFeatureLayer b=new FeatureLayerClass();
            //b.FeatureClass = this._byFc;
            //IFeatureSelection fs = (IFeatureSelection)this._byLayer;
            //MessageBox.Show(fs.SelectionSet.Count.ToString());
            IQueryByLayer qrbl = new QueryByLayerClass();
            qrbl.FromLayer = duongFeatureLayer;
            qrbl.ByLayer = xaFeatureLayer;
            qrbl.LayerSelectionMethod = esriLayerSelectionMethod.esriLayerSelectIntersect;
            qrbl.ResultType = esriSelectionResultEnum.esriSelectionResultNew;
            qrbl.UseSelectedFeatures = true;

            ISelectionSet sl = qrbl.Select();
            MessageBox.Show("Line 125 AlgTimDuong:"+sl.Count.ToString());
            //MessageBox.Show(xaFeatureLayer.FeatureClass.AliasName);
            try
            {
                //this._resultSelectionSet = this._queryByLayer.Select();
                //this._resultSelectionSet =qrbl.Select();
                //MessageBox.Show(string.Format("line 120 AlgrithmTimDuong, so luong duong:{0}", this._resultSelectionSet.Count));
            }
            catch(Exception e)
            {
                MessageBox.Show(e.ToString());
            }

            //this._resultSelectionSet = sls;
            //Dang bi loi cho nay
            this._resultFeatureSelection = (IFeatureSelection)this._resultLayer;
            this._resultFeatureSelection.SelectionSet = this._resultSelectionSet;
            return this._resultSelectionSet;
        }
Пример #4
0
        private void _bwk_DoWork(object sender, DoWorkEventArgs e)
        {
            List<object> newId = (List<object>)e.Argument;
            //frm = new FrmFilterLandprice();
            //showFrm();

            //MessageBox.Show("line 117");
            ICurrentConfig _currentConfig = CurrentConfig.CallMe();
            ICopyFeatures copyTool;

            #region chon loc gia dat

            #region khoi tao cac bien
            SdeConnection conn = new SdeConnection();
            ISdeConnectionInfo sdeConn = conn as ISdeConnectionInfo;
            IFeatureWorkspace fw = (IFeatureWorkspace)sdeConn.Workspace;
            IWorkspaceEdit _wspEdit = (IWorkspaceEdit)sdeConn.Workspace;
            IMultiuserWorkspaceEdit _mwspEdit = (IMultiuserWorkspaceEdit)sdeConn.Workspace;
            copyTool = new DataManager(sdeConn.Workspace, sdeConn.Environment);
            ITnFeatureClassName _fcName = new TnFeatureClassName(sdeConn.Workspace);
            //ITnTableName _tblName = new TnTableName(sdeConn.Workspace);
            string tgd = string.Format("{0}_{1}", DataNameTemplate.Thua_Gia_Dat, _currentConfig.NamApDung);
            string tgdDraft = string.Format("{0}_{1}", DataNameTemplate.Thua_Gia_Dat_Draft, _currentConfig.NamApDung);
            _fcName.FC_THUA_GIADAT_DRAFT.NAME = tgdDraft;
            _fcName.FC_THUA_GIADAT_DRAFT.InitIndex();
            _fcName.FC_THUA_GIADAT.NAME = tgd;
            _fcName.FC_THUA_GIADAT.InitIndex();
            IFeatureClass tgdFeatureClassDraft = null;
            IFeatureClass tgdFeatureClass = null;
            try
            {
                tgdFeatureClassDraft = fw.OpenFeatureClass(tgdDraft);
            }
            catch
            {
                MessageBox.Show("Không tìm thấy bảng " + tgdDraft);
                return;
            }
            try
            {
                tgdFeatureClass = fw.OpenFeatureClass(tgd);
            }
            catch
            {
                MessageBox.Show("Không tìm thấy bảng " + tgd);
                return;
            }
            ITable tblThuaGiaDatDraft = (ITable)tgdFeatureClassDraft;
            ITable tblThuaGiaDat = (ITable)tgdFeatureClass;
            ISDETableEditor sdeTblTgdEditor = new SDETable(tblThuaGiaDat, sdeConn.Workspace);
            ISDETableEditor sdeTblTgdDraftEditor = new SDETable(tblThuaGiaDatDraft, sdeConn.Workspace);
            List<object[,]> pairColValTgdDraft = new List<object[,]>();
            IQueryFilter qrf = new QueryFilterClass();
            bool result = false;
            #endregion

            #region vong lap tung id

            #region khoi dau
            int rowTgdNnHandleUpdate = 0;
            string cachtinh = "";
            string cachtinhdongia = "";
            //bool result = false;
            List<object[,]> pairColValTgd = new List<object[,]>();
            CalculationEventArg evt = new CalculationEventArg();
            //evt.Reset();
            //evt.Log = "\n\nBắt đầu chọn lọc giá cho các thửa vừa tính...";
            //_caller.onCalculating(evt);
            int len = newId.Count;
            int thuaCount = 1;
            //MessageBox.Show(string.Format("line 620 CalcLandprice {0}",len.ToString()));
            #endregion
            List<object> mathuaCalced = new List<object>();
            _publishedId = new List<object>();
            foreach (object o in newId)
            {
                if (thuaCount < len)
                {
                    decimal i = (decimal)thuaCount / (decimal)len * 100;
                    int i1 = Convert.ToInt32(i);
                    _bwk.ReportProgress(i1);
                    //MessageBox.Show("log 009");
                }
                else
                {
                    _bwk.ReportProgress(99);
                }
                thuaCount++;
                //evt.Reset();
                //evt.Log = string.Format("\n\nchọn lọc giá cho thửa {0}", o);
                //_caller.onCalculating(evt);
                IRow tgdDraftRowNew = tblThuaGiaDatDraft.GetRow((int)o);
                string mathuaNew = tgdDraftRowNew.get_Value(tgdDraftRowNew.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.MA_THUA)).ToString();
                if (mathuaCalced.Count > 0)
                {
                    foreach (object ob in mathuaCalced)
                    {
                        if (string.Compare(mathuaNew.ToString(), ob.ToString()) == 0)
                        {
                            continue;
                        }
                    }
                }
                mathuaCalced.Add(mathuaNew);

                #region vong lap xet vung gia co ma mathuaNew
                qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_THUA_GIADAT_DRAFT.MA_THUA, mathuaNew);
                IFeatureCursor tgdDraftCur = tgdFeatureClassDraft.Search(qrf, false);
                IFeature tgdDraftFt = null;
                List<landpriceInfo> info = new List<landpriceInfo>();
                List<landpriceInfo> infoResult;
                //List<
                try
                {
                    double dongia = 0;
                    object id = 0;
                    object hesok = 0;
                    int somattien = 0;
                    while ((tgdDraftFt = tgdDraftCur.NextFeature()) != null)
                    {
                        id = tgdDraftFt.OID;

                        hesok = tgdDraftFt.get_Value(tgdDraftFt.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.HE_SO_K));
                        result = double.TryParse(tgdDraftFt.get_Value(tgdDraftFt.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.DON_GIA)).ToString(), out dongia);
                        if (!result)
                        {
                            dongia = 0;
                        }
                        //result=int.TryParse(tgdDraftFt.get_Value(tgdDraftFt.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.SO_MAT_TIEN)).ToString(), out somattien);
                        //if (!result)
                        //{
                        //    somattien = 0;
                        //}
                        info.Add(new landpriceInfo(id, hesok, dongia));
                        //frm.SetReport(string.Format("\n\nVùng giá {0}, số vùng giá:{1} ", id, info.Count));
                        //evt.Reset();
                        //evt.Log = string.Format("\n\nVùng giá {0}, số vùng giá:{1} ", id,info.Count);
                        //_caller.onCalculating(evt);
                    }

                    #region xet dieu kien de luu cac vung gia vao bang gia cong bo
                    //neu chi co 1 vung gia thi ko can suy nghi
                    int sovunggia = info.Count;
                    this.SetReport(string.Format("Số vùng giá của thửa {0} là {1}", mathuaNew, sovunggia));
                    //evt.Reset();
                    //evt.Log = string.Format("\n\nSố vùng giá của thửa {0} là {1}", mathuaNew, sovunggia);
                    //_caller.onCalculating(evt);
                    if (sovunggia == 0)
                    {
                        continue;
                    }
                    //MessageBox.Show(string.Format("line 266 FrmFilterLandprice, sovung gia={0}", info.Count));

                    //=====================================================
                    //============Loc gia==================================
                    FilterLandprice.GetMaxValueWithDistinctKey(info, out infoResult);
                    //======================================================

                    //MessageBox.Show(string.Format("line 658 CalcLandprice, giadat={0}", infoResult[0].Dongia));
                    foreach (landpriceInfo inf in infoResult)
                    {
                        tgdDraftFt = tgdFeatureClassDraft.GetFeature((int)inf.Id);
                        object mathua = tgdDraftFt.get_Value(tgdDraftFt.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.MA_THUA));
                        qrf.WhereClause = string.Format("{0}='{1}' and {2}='{3}'",
                            _fcName.FC_THUA_GIADAT.HE_SO_K, inf.Hesok,
                            _fcName.FC_THUA_GIADAT.MA_THUA, mathua);
                        IFeatureCursor tgdFcur = tgdFeatureClass.Search(qrf, false);
                        IFeature tgdFt = null;
                        object copiedId = null;
                        try
                        {
                            //MessageBox.Show(string.Format("line 686 CalcLandprice, bat dau"));
                            if ((tgdFt = tgdFcur.NextFeature()) != null)
                            {
                                #region xet thua da co vi tri

                                bool isOverWritePos = true;

                                if (!isOverWritePos)
                                {
                                    _publishedId.Add(tgdFt.OID);
                                    continue;
                                }
                                else
                                {
                                    //[kodoi]
                                    //===================
                                    #region xoa feature cu
                                    //MessageBox.Show("line 303 FrmFilt, isbeingedit:"+_wspEdit.IsBeingEdited());
                                    if (_wspEdit.IsBeingEdited())
                                    {
                                        MessageBox.Show("line 305 FrmFilt, edited");
                                        try
                                        {

                                            _wspEdit.StopEditOperation();
                                            _wspEdit.StopEditing(true);
                                        }
                                        catch (Exception ex)
                                        {
                                            _wspEdit.StopEditOperation();
                                            _wspEdit.StopEditing(false);
                                        }
                                    }
                                    try
                                    {
                                        //_wspEdit.StopEditOperation();
                                        //_wspEdit.StopEditing(false);
                                        _mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
                                        //_wspEdit.StartEditing(true);
                                        _wspEdit.StartEditOperation();
                                    }
                                    catch (Exception ex)
                                    {
                                        MessageBox.Show("line 323 FrmFilt, ex=" + ex);
                                        //_wspEdit.StopEditOperation();
                                        //_wspEdit.StopEditing(false);
                                        //_mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
                                        //_wspEdit.StartEditOperation();
                                    }
                                    this.SetReport(string.Format("Xóa vùng giá {0}", mathua));
                                    //qrf.WhereClause = string.Format("{0}='{1}'", "OBJECTID", tgdRow.OID);
                                    //tblThuaGiaDat.DeleteSearchedRows(qrf);
                                    //MessageBox.Show(string.Format("line 720 CalcLandprice, bat dau xoa thua {0}",mathua));
                                    tgdFt.Delete();
                                    _wspEdit.StopEditOperation();
                                    _wspEdit.StopEditing(true);
                                    #endregion
                                    //===================

                                    //[thaydoi] - them gia tri
                                    //**********************
                                    #region them feature moi
                                    if (_wspEdit.IsBeingEdited())
                                    {
                                        MessageBox.Show("line 334 FrmFilt, edited");
                                        try
                                        {

                                            _wspEdit.StopEditOperation();
                                            _wspEdit.StopEditing(true);
                                        }
                                        catch (Exception ex)
                                        {
                                            _wspEdit.StopEditOperation();
                                            _wspEdit.StopEditing(false);
                                        }
                                    }
                                    _mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
                                    _wspEdit.StartEditOperation();

                                    copiedId = copyTool.CopyWithAllAttribute(tgdDraftFt, tgdFeatureClass);
                                    this.SetReport(string.Format("Công bố vùng giá {0}", copiedId));
                                    //MessageBox.Show(string.Format("line 743 CalcLandprice, oid={0}", copiedId));
                                    try
                                    {
                                        _wspEdit.StopEditOperation();
                                        _wspEdit.StopEditing(true);
                                    }
                                    catch (Exception ex)
                                    {
                                        _wspEdit.StopEditOperation();
                                        _wspEdit.StopEditing(false);
                                    }

                                    //them gia tri mathua,maduong,hesovitri
                                    //pairColValTgd.Add(new object[,] { { tgdFt.Fields.FindField(__fcName.FC_THUA_GIADAT_DRAFT.MA_THUA), mathuaNew } });
                                    //pairColValTgd.Add(new object[,] { { tgdFt.Fields.FindField(__fcName.FC_THUA_GIADAT_DRAFT.MA_DUONG), maduong } });
                                    //pairColValTgd.Add(new object[,] { { tgdFt.Fields.FindField(__fcName.FC_THUA_GIADAT_DRAFT.HE_SO_K), hesoVitri } });
                                    //pairColValTgd.Add(new object[,] { { __fcName.FC_THUA_GIADAT_DRAFT.GetIndex(__fcName.FC_THUA_GIADAT_DRAFT.DIEN_TICH_PHAP_LY), dientichpl } });
                                    //sdeTblTgdEditor.CacheData(copiedId, rowTgdNnHandleUpdate, pairColValTgd, EnumTypeOfEdit.UPDATE);
                                    //rowTgdNnHandleUpdate++;
                                    //pairColValTgd.Clear();
                                    _publishedId.Add(copiedId);
                                    #endregion
                                    //**********************
                                }

                                #endregion
                            }
                            else
                            {
                                #region them feature moi
                                if (_wspEdit.IsBeingEdited())
                                {
                                    MessageBox.Show("line 385 FrmFilt, edited");
                                    try
                                    {

                                        _wspEdit.StopEditOperation();
                                        _wspEdit.StopEditing(true);
                                    }
                                    catch (Exception ex)
                                    {
                                        _wspEdit.StopEditOperation();
                                        _wspEdit.StopEditing(false);
                                    }
                                }
                                _mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
                                _wspEdit.StartEditOperation();
                                copiedId = copyTool.CopyWithAllAttribute(tgdDraftFt, tgdFeatureClass);

                                //MessageBox.Show(string.Format("line 743 CalcLandprice, oid={0}", copiedId));
                                this.SetReport(string.Format("Công bố vùng giá {0}", copiedId));
                                try
                                {
                                    _wspEdit.StopEditOperation();
                                    _wspEdit.StopEditing(true);
                                }
                                catch (Exception ex)
                                {
                                    _wspEdit.StopEditOperation();
                                    _wspEdit.StopEditing(false);
                                }
                                _publishedId.Add(copiedId);
                                #endregion
                            }

                            #region ghi gia dat moi (da nhan he so mat tien neu co)

                            pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT.GetIndex(_fcName.FC_THUA_GIADAT.DON_GIA), inf.Dongia } });
                            pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT.GetIndex(_fcName.FC_THUA_GIADAT.SO_MAT_TIEN), inf.Somattien } });
                            sdeTblTgdEditor.CacheData(copiedId, 0, pairColValTgd, EnumTypeOfEdit.UPDATE);
                            pairColValTgd.Clear();
                            if (!sdeTblTgdEditor.IsEditing())
                            {
                                sdeTblTgdEditor.StartEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
                                sdeTblTgdEditor.StartEditOperation();
                            }
                            try
                            {
                                sdeTblTgdEditor.SaveEdit();
                                sdeTblTgdEditor.StopEditOperation();
                                sdeTblTgdEditor.StopEditing(true);
                            }
                            catch (Exception ex)
                            {
                                sdeTblTgdEditor.StopEditOperation();
                                sdeTblTgdEditor.StopEditing(false);
                            }
                            #endregion
                        }
                        catch (Exception e1) { MessageBox.Show(string.Format("CalcLandprice, line 736-\n{0}", e1)); }
                        finally { Marshal.ReleaseComObject(tgdFcur); }
                    }
                    #endregion
                }
                catch (Exception ex)
                {
                    continue;
                }
                finally
                {
                    Marshal.ReleaseComObject(tgdDraftCur);
                }
                #endregion
            }
            //e.Result = _publishedId;

            #endregion

            #endregion
        }