protected override void calculate() { #region khoi dau base.calculate(); CalculationEventArg evt = new CalculationEventArg(); //evt.Type = EnumTypeOfLoopCalculation.InListCalculators; evt.CurrentIndexCalculator = this._index; evt.Log = string.Format("********** Bắt đầu tính giá cho hẻm {0} ********", vitri); onCalculating(evt); #endregion //[thaydoi] - them cac khai bao can thiet //************************************ #region khai bao cac bien //Lay connection info hien tai SdeConnection conn = new SdeConnection(); ISdeConnectionInfo sdeConn = conn as ISdeConnectionInfo; IWorkspaceEdit wspEdit = (IWorkspaceEdit)sdeConn.Workspace; IMultiuserWorkspaceEdit mwspEdit = (IMultiuserWorkspaceEdit)sdeConn.Workspace; this._fcName = new TnFeatureClassName(sdeConn.Workspace); this._tblName = new TnTableName(sdeConn.Workspace); IFeatureWorkspace fw = (IFeatureWorkspace)sdeConn.Workspace; ICopyFeatures copyTool = new DataManager(sdeConn.Workspace, sdeConn.Environment); #region thua //string thuaName = string.Format("{0}_{1}", DataNameTemplate.Thua, this._currentConfig.NamApDung); //_fcName.FC_THUA.NAME = thuaName; ////MessageBox.Show(string.Format("line 55 CalcMattien {0}", thuaName)); //_fcName.FC_THUA.InitIndex(); //IFeatureClass thuaFeatureClass = fw.OpenFeatureClass(thuaName); //IFeatureLayer thuaFeatureLayer = new FeatureLayerClass(); //thuaFeatureLayer.FeatureClass = thuaFeatureClass; //IFeatureSelection thuaFeatureSelection; #endregion #region xa IFeatureClass xaFeatureClass = fw.OpenFeatureClass(DataNameTemplate.Ranh_Xa_Poly); IFeatureLayer xaFeatureLayer = new FeatureLayerClass(); xaFeatureLayer.FeatureClass = xaFeatureClass; IFeatureSelection xaFeatureSelection; #endregion #region duong IFeatureClass duongFeatureClass = fw.OpenFeatureClass(DataNameTemplate.Duong); IFeatureLayer duongFeatureLayer = new FeatureLayerClass(); duongFeatureLayer.FeatureClass = duongFeatureClass; IFeatureSelection duongFeatureSelection; //_fcName.FC_DUONG.InitIndex(); #endregion #region hem IFeatureClass hemFeatureClass = fw.OpenFeatureClass(DataNameTemplate.Hem); IFeatureLayer hemChinhFeatureLayer = new FeatureLayerClass(); hemChinhFeatureLayer.FeatureClass = hemFeatureClass; IFeatureSelection hemChinhFeatureSelection; //IFeatureClass hemPhuFeatureClass = fw.OpenFeatureClass(DataNameTemplate.Hem); IFeatureLayer hemPhuFeatureLayer = new FeatureLayerClass(); hemPhuFeatureLayer.FeatureClass = hemFeatureClass; IFeatureSelection hemPhuFeatureSelection; //_fcName.FC_DUONG.InitIndex(); #endregion #region gia dat hem string gdh = DataNameTemplate.Gia_Hem + "_" + _currentConfig.NamApDung.ToString(); _fcName.FC_GIA_DAT_HEM.NAME = gdh; _fcName.FC_GIA_DAT_HEM.InitIndex(); IFeatureClass gdhChinhFeatureClass = fw.OpenFeatureClass(gdh); IFeatureLayer gdhChinhFeatureLayer = new FeatureLayerClass(); gdhChinhFeatureLayer.FeatureClass = gdhChinhFeatureClass; IFeatureSelection gdhChinhFeatureSelection; ITable tblGdhChinh = (ITable)gdhChinhFeatureClass; ISDETableEditor sdeTblGdhEditor = new SDETable(tblGdhChinh, sdeConn.Workspace); #endregion #region thua gia dat //string tgdDraft = string.Format("{0}_{1}", DataNameTemplate.Thua_Gia_Dat_Draft, this._currentConfig.NamApDung); //_fcName.FC_THUA_GIADAT_DRAFT.NAME = tgdDraft; //_fcName.FC_THUA_GIADAT_DRAFT.InitIndex(); ////_fcName.FC_THUA_GIADAT_DRAFT.NAME = tgdDraft; ////_fcName.FC_THUA_GIADAT_DRAFT.InitIndex(); //IFeatureClass tgdFeatureClass=null; //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; //IFeatureLayer tgdFeatureLayer = new FeatureLayerClass(); //ISDETableEditor sdeTblTgdEditor = new SDETable(tblThuaGiaDat, sdeConn.Workspace); #endregion #region gia dat duong //string gdd = string.Format("{0}_{1}", DataNameTemplate.Gia_Dat_Duong, this._currentConfig.NamApDung); //_tblName.GIA_DAT_DUONG.NAME = gdd; //_tblName.GIA_DAT_DUONG.InitIndex(); #endregion #region ten duong ITable tblTenDuong; try { tblTenDuong = fw.OpenTable(DataNameTemplate.Ten_Duong); } catch (Exception exc) { evt.Log = string.Format("Không tìm thấy lớp dữ liệu: {0}", DataNameTemplate.Ten_Duong); onCalculating(evt); onFinished(evt); return; } #endregion #region loai dat //ITable tblLoaiDat; //try //{ // tblLoaiDat = fw.OpenTable(DataNameTemplate.Loai_Dat); //} //catch (Exception exc) //{ // evt.Log = string.Format("Không tìm thấy lớp dữ liệu: {0}", DataNameTemplate.Loai_Dat); // onCalculating(evt); // onFinished(evt); // return; //} #endregion #region he so vi tri //ITable tblHesoVitri; //try //{ // tblHesoVitri = fw.OpenTable(DataNameTemplate.He_So_K); //} //catch (Exception exc) //{ // evt.Log = string.Format("Không tìm thấy lớp dữ liệu: {0}", DataNameTemplate.He_So_K); // onCalculating(evt); // onFinished(evt); // return; //} #endregion #region khac IQueryFilter qrf = new QueryFilterClass(); IDataManager _dataManager; ISdeVersionInfo _version; IBuffer _bufferTool; //IClip _clipTool; IErase _eraseTool; ITnSystemTempPath _sysTempPath; _sysTempPath = new TnSystemTempPath(); bool result = false; int sothuatimthay = 0; int sothuatinhduoc = 0; int sothuaKhongTinhDuoc = 0; _dataManager = new DataManager(sdeConn.Workspace, sdeConn.Environment); _version = SdeVersionsTool.CallMe(); //_clipTool = new GExtractTool(sdeConn.Environment); _eraseTool = new GExtractTool(sdeConn.Environment); string duongBuffer200mNoSde = FilterSdeLayerName.GetActualName(DataNameTemplate.Duong_Buffer_); duongBuffer200mNoSde += "200"; string hemErase200mNoSde = FilterSdeLayerName.GetActualName(DataNameTemplate.Hem_Erase_); hemErase200mNoSde += "200"; //string duongBuffer50mCoSde = string.Format("{0}{1}", DataNameTemplate.Duong_Buffer_, 50); string hemErase200mCoSde = string.Format("{0}{1}", DataNameTemplate.Hem_Erase_, 200); #endregion #endregion //************************************ //******************************************* //=========================================== //=========================================== #region bat dau tinh _bufferTool = new GProximityTool(sdeConn.Environment); if (!_dataManager.LayerExist(duongBuffer200mNoSde)) { _bufferTool.BufferInsideSde(duongFeatureClass.AliasName, duongBuffer200mNoSde, 200); } IFeatureClass duongBuff200FeatureClass = fw.OpenFeatureClass(duongBuffer200mNoSde); IFeatureLayer duongBuff200FeatureLayer = new FeatureLayerClass(); ISelectionSet duongBuff200Sls; IFeatureSelection duongBuff200Fsls; duongBuff200FeatureLayer.FeatureClass = duongBuff200FeatureClass; #region test //string ex = string.Format("VongLap(ChonDuong('dorong=10'),VongLap(ChonThua('dientich<1.5'),test([doituonglap]),[doituonglap]))"); ////ex=string.Format("VongLap(DuongDangChon(),VongLap() //Evaluation evalu = new Evaluation(ex); //evalu.DuongLayer = duongFeatureLayer; //evalu.ThuaLayer = thuaFeatureLayer; //evalu.EvaluateCalculating(); //return; #endregion //[thaydoi] - cac may tinh khac chi can thay dieu kien truy van he so vi tri //****************************************************************** #region lay cac quy tac tim vi tri //#region log--- //evt.Log = string.Format("\n----Lấy các quy tắc tìm vị trí thửa từ bảng {0}, ứng với hệ số {1} ...", DataNameTemplate.He_So_K, TnHeSoK.DatOMtTtDt); //onCalculating(evt); //#endregion ////MessageBox.Show(String.Format("line 189 CalcThuaMattien, hsk={0}",TnHeSoK.DatOMtTtDt)); //qrf.WhereClause = string.Format("{0}='{1}'", "hesovitri", TnHeSoK.DatOMtTtDt); //ICursor cur = tblHesoVitri.Search(qrf, false); //string quytac = ""; //string cachtinh = ""; //string cachtinhdongia = ""; //try //{ // IRow row = cur.NextRow(); // if (row != null) // { // quytac = row.get_Value(_tblName.HESO_VITRI.GetIndex(_tblName.HESO_VITRI.QUY_TAC)).ToString(); // cachtinh = row.get_Value(_tblName.HESO_VITRI.GetIndex(_tblName.HESO_VITRI.CACH_TINH)).ToString(); // cachtinhdongia = row.get_Value(_tblName.HESO_VITRI.GetIndex(_tblName.HESO_VITRI.CACH_TINH_DON_GIA)).ToString(); // //MessageBox.Show(string.Format("line 198 CalcMatTien, quytac={0}", quytac)); // } //} //catch { } //finally //{ // Marshal.ReleaseComObject(cur); //} #endregion #region tinh theo xa if (this._inputParams.MA_XA != "-1") { //[kodoi] //======================= #region chon xa co ma dang xet //neu dang tinh cho 1 xa if (_inputParams.MA_XA != "*") { qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_RANH_XA_POLY.MA_XA, _inputParams.MA_XA); } else//neu dang tinh cho toan huyen { qrf.WhereClause = ""; } ISelectionSet xaSelectionSet = xaFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); xaFeatureSelection = (IFeatureSelection)xaFeatureLayer; xaFeatureSelection.SelectionSet = xaSelectionSet; #endregion //======================= #region vong lap tung xa //[thaydoi] - co the them bien chay //************************* #region khoi dau IEnumIDs xaIds = xaSelectionSet.IDs; int xaId = 0; IFeature xaFt = null; List<object> lstMaDuong = new List<object>(); #endregion //************************* while ((xaId = xaIds.Next()) != -1) { //[kodoi] //======================= #region lay thong tin xa xaFt = xaFeatureClass.GetFeature(xaId); string maxa = xaFt.get_Value(xaFt.Fields.FindField(_fcName.FC_RANH_XA_POLY.MA_XA)).ToString(); string tenxa = xaFt.get_Value(xaFt.Fields.FindField(_fcName.FC_RANH_XA_POLY.TEN_XA)).ToString(); string loaixa = xaFt.get_Value(xaFt.Fields.FindField(_fcName.FC_RANH_XA_POLY.MA_LOAI_XA)).ToString(); #endregion #region -----log evt.Log = string.Format("\n************************************************"); evt.Log += string.Format("\n****** Đang tính cho xã/phường: {0} ******", tenxa); evt.Log += string.Format("\n************************************************"); onCalculating(evt); #endregion #region tim duong trong khu vuc do thi bang qua xa //chon xa dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_RANH_XA_POLY.OID, xaId); xaSelectionSet = xaFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); xaFeatureSelection = (IFeatureSelection)xaFeatureLayer; xaFeatureSelection.SelectionSet = xaSelectionSet; //Chon cac duong co do rong theo quy dinh qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_DUONG.PHAN_LOAI, _isDothi);// "maduong='2'"; ISelectionSet duongSelectionSet = duongFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, sdeConn.Workspace); duongFeatureSelection = (IFeatureSelection)duongFeatureLayer; duongFeatureSelection.SelectionSet = duongSelectionSet; //bat dau truy van khong gian _qrBl.FromLayer = duongFeatureLayer; _qrBl.ByLayer = xaFeatureLayer; _qrBl.LayerSelectionMethod = esriLayerSelectionMethod.esriLayerSelectIntersect; _qrBl.ResultType = esriSelectionResultEnum.esriSelectionResultAnd; _qrBl.UseSelectedFeatures = true; duongSelectionSet = _qrBl.Select(); #endregion //======================= #region vong lap xet tung duong //[thaydoi] - co the them bien chay //=============================== #region khoi dau IEnumIDs eIds = duongSelectionSet.IDs; int duongId; IFeature ftDuong; int iDuong = 0; int progressingTotalCount = 1; evt.Reset(); evt.ProgressingTotal = duongSelectionSet.Count; onCalculating(evt); //List<object> lstMaDuong = new List<object>(); #endregion //================================ while ((duongId = eIds.Next()) != -1) { //[kodoi] //====================== #region log----- evt.Reset(); evt.ProgressingTotalCount = progressingTotalCount; onCalculating(evt); progressingTotalCount++; #endregion //====================== //[capnhat] - lay ten duong tu bang ten duong //++++++++++++++++++++++++ #region lay thong tin cua duong dang xet ftDuong = duongFeatureClass.GetFeature(duongId); string tenduong = "";//ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.TEN_DUONG)).ToString(); object maduong = ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.MA_DUONG)); lstMaDuong.Add(maduong); string batdau = "";// ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.BAT_DAU)).ToString(); string ketthuc = "";// ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.KET_THUC)).ToString(); #endregion //++++++++++++++++++++++++ //[kodoi] //Chon duong dang xet, buoc này de ra layer duong dung de truy van khong gian cac thua dat //==================== #region chon duong dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_DUONG.OID, duongId); duongSelectionSet = duongFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); duongFeatureSelection = (IFeatureSelection)duongFeatureLayer; duongFeatureSelection.SelectionSet = duongSelectionSet; #endregion //==================== //tim cac thua theo dieu kien mat tien //doc cach tim thua trong bang he so vi tri //lay cach tim cho dat o //truyen thong so cach tinh,thualayer,duonglayer,khoangcach //MessageBox.Show(func); //func = "ChongLop([INTERSECT],[NEW_SELECTION],1) Then ChongLop([CONTAINED_BY],[AND_SELECTION],50)"; //[kodoi] //============================ #region chon hem chinh cua duong qrf.WhereClause = string.Format("{0}='{1}' and ({2}='{3}' or {4} is null)", _fcName.FC_HEM.MA_DUONG, maduong, _fcName.FC_HEM.HEM_CHINH, 0, _fcName.FC_HEM.HEM_CHINH); ISelectionSet hemChinhSelectionSet = hemFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, sdeConn.Workspace); hemChinhFeatureSelection = (IFeatureSelection)hemChinhFeatureLayer; hemChinhFeatureSelection.SelectionSet = hemChinhSelectionSet; #endregion #region clip cac hem vua tim duoc #region delete bang hem_sau100m_clip IFeatureClass hemClipFc = null; #region log--- evt.Log = string.Format("\n----Kiểm tra, xóa bảng {0} ...", hemErase200mCoSde); onCalculating(evt); #endregion //if (_dataManager.LayerExist(hemErase200mNoSde)) //{ //thuaClipFc = fw.OpenFeatureClass("sde.thua_sau50m_clip"); //mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); //wspEdit.StartEditing(false); //wspEdit.StartEditOperation(); try { ((IFeatureClassManager)_dataManager).DeleteFcInSde(hemErase200mCoSde); } catch (Exception ex) { MessageBox.Show("line 924 CalGiaHemTren200,ex=" + ex.ToString()); } //((IDataset)thuaClipFc).Delete(); //wspEdit.StopEditOperation(); //wspEdit.StopEditing(true); //} #endregion #region chon duong buffer 100 dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_DUONG.OID, duongId); duongBuff200Sls = duongBuff200FeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); duongBuff200Fsls = (IFeatureSelection)duongBuff200FeatureLayer; duongBuff200Fsls.SelectionSet = duongBuff200Sls; #endregion #region chon hem nam trong vung buffer 200m nhưng khong nam trong vùng buffer 100m _qrBl.FromLayer = hemChinhFeatureLayer; _qrBl.ByLayer = duongFeatureLayer; _qrBl.LayerSelectionMethod = esriLayerSelectionMethod.esriLayerSelectContainedBy; _qrBl.ResultType = esriSelectionResultEnum.esriSelectionResultSubtract; _qrBl.UseSelectedFeatures = true; _qrBl.BufferDistance = 200; try { hemChinhSelectionSet = _qrBl.Select(); hemChinhFeatureSelection = (IFeatureSelection)hemChinhFeatureLayer; hemChinhFeatureSelection.SelectionSet = hemChinhSelectionSet; } catch { continue; } if (!(hemChinhSelectionSet.Count > 0)) { continue; } #endregion #region log--- evt.Log = string.Format("\n----Kiểm tra, clip hẻm theo đường buffer {0}m, lưu vào bảng {1} ...", _currentConfig.DKhoangCach50mMatTien, hemErase200mCoSde); onCalculating(evt); #endregion string hemlyr = string.Format("{0}/{1}", _sysTempPath.TempPath, hemErase200mNoSde); string duonglyr = string.Format("{0}/{1}", _sysTempPath.TempPath, duongBuffer200mNoSde); _eraseTool.EraseByLayerFileInsideSde(hemChinhFeatureLayer, hemlyr, duongBuff200FeatureLayer, duonglyr, hemErase200mNoSde); try { hemClipFc = fw.OpenFeatureClass(hemErase200mCoSde); } catch (Exception ex) { continue; } _version.RegisterDataset((IDataset)hemClipFc, true, true); #endregion #region xet tung hem da clip //[thaydoi] - co the them bien chay //******************** #region khoi dau //IFeatureCursor hemErCur = hemClipFc.Search(null, false); IEnumIDs hemChinhIds = hemChinhSelectionSet.IDs; int hemChinhId; IFeature hemChinhFt; int iHem = 0; List<object[,]> pairColValTgd = new List<object[,]>(); int rowTgdNnHandleUpdate = 0; List<object> newId = new List<object>(); #endregion try { while ((hemChinhId = hemChinhIds.Next()) != -1) { //he so vi tri hem ung voi doan sau <100m int hesoVitri = 3; #region lay thong tin hem dang xet //[kodoi] //============================ #region lay thong tin co ban hemChinhFt = hemFeatureClass.GetFeature(hemChinhId); //hemErId = hemErFt.OID; object maHem = hemChinhFt.get_Value(hemChinhFt.Fields.FindField(_fcName.FC_HEM.MA_HEM)); #endregion #endregion #region kiem tra trong bang giadat_hem, voi dieu kien:mahem,hesovitri,khoagia=0 evt.Reset(); evt.Log = "\n[!]--- Kiểm tra các hẻm đã có giá, cập nhật giá mới ..."; onCalculating(evt); qrf.WhereClause = string.Format("({0}='{1}' or {2} is null) and {3}='{4}' and {5}='{6}'", _fcName.FC_GIA_DAT_HEM.LOCKED, 0, _fcName.FC_GIA_DAT_HEM.LOCKED, _fcName.FC_GIA_DAT_HEM.MA_HEM, maHem, _fcName.FC_GIA_DAT_HEM.HE_SO, hesoVitri); IFeatureCursor gdhChinhFcs = gdhChinhFeatureClass.Search(qrf, false); IFeature gdhChinhFt = null; try { gdhChinhFt = gdhChinhFcs.NextFeature();//dam bao la chi co 1 hang ket qua if (gdhChinhFt != 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(gdhChinhFt.OID); //continue; } else { //[kodoi] //=================== #region xoa feature cu if (mwspEdit.SupportsMultiuserEditSessionMode(esriMultiuserEditSessionMode.esriMESMVersioned)) { mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); } else { wspEdit.StartEditing(true); } wspEdit.StartEditOperation(); //qrf.WhereClause = string.Format("{0}='{1}'", "OBJECTID", tgdRow.OID); //tblThuaGiaDat.DeleteSearchedRows(qrf); gdhChinhFt.Delete(); wspEdit.StopEditOperation(); wspEdit.StopEditing(true); #endregion //=================== #region chon trong bang thua clip qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_HEM.MA_HEM, maHem); IFeatureCursor hemClipFcur = hemClipFc.Search(qrf, false); IFeature hemErFt = null; try { hemErFt = hemClipFcur.NextFeature(); if (hemErFt == null) { continue; } } catch (Exception ex) { return; } finally { Marshal.ReleaseComObject(hemClipFcur); } #region lay thong tin thua clip //IArea area = (IArea)hemClipFt.Shape; #endregion #endregion //[thaydoi] - them gia tri //********************** #region them feature moi if (mwspEdit.SupportsMultiuserEditSessionMode(esriMultiuserEditSessionMode.esriMESMVersioned)) { mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); } else { wspEdit.StartEditing(true); } wspEdit.StartEditOperation(); object copiedId = copyTool.Copy(hemErFt, gdhChinhFeatureClass); try { wspEdit.StopEditOperation(); wspEdit.StopEditing(true); } catch (Exception ex) { MessageBox.Show("line 1292 CalcGiaHemChinh ex=" + ex.ToString()); wspEdit.StopEditOperation(); wspEdit.StopEditing(false); } //them gia tri mathua,maduong,hesovitri pairColValTgd.Add(new object[,] { { gdhChinhFt.Fields.FindField(_fcName.FC_GIA_DAT_HEM.MA_HEM), maHem } }); pairColValTgd.Add(new object[,] { { gdhChinhFt.Fields.FindField(_fcName.FC_GIA_DAT_HEM.MA_DUONG), maduong } }); pairColValTgd.Add(new object[,] { { gdhChinhFt.Fields.FindField(_fcName.FC_GIA_DAT_HEM.LOCKED), 0 } }); pairColValTgd.Add(new object[,] { { gdhChinhFt.Fields.FindField(_fcName.FC_GIA_DAT_HEM.HE_SO), hesoVitri } }); //MessageBox.Show(string.Format("line 1062 CalcGiaHemChinh mahem={0},maduong={1}", maHem, maduong)); sdeTblGdhEditor.CacheData(copiedId, rowTgdNnHandleUpdate, pairColValTgd, EnumTypeOfEdit.UPDATE); rowTgdNnHandleUpdate++; pairColValTgd.Clear(); //MessageBox.Show("line 1066 CalcGiaHemChinh copyid=" + copiedId); newId.Add(copiedId); #endregion //********************** } #endregion } else { //MessageBox.Show("ko co"); //[thaydoi] - them cac gia tri thich hop vao thua_giadat //*********************************** #region chon trong bang thua clip qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_HEM.MA_HEM, maHem); //MessageBox.Show("line 1322 CalcGiaHemChinh, mahem=" + maHem); IFeatureCursor hemClipFcur = hemClipFc.Search(qrf, false); IFeature hemErFt = null; try { hemErFt = hemClipFcur.NextFeature(); if (hemErFt == null) { continue; } } catch (Exception ex) { return; } finally { Marshal.ReleaseComObject(hemClipFcur); } #region lay thong tin thua clip //IArea area = (IArea)hemClipFt.Shape; #endregion #endregion #region them feature moi if (mwspEdit.SupportsMultiuserEditSessionMode(esriMultiuserEditSessionMode.esriMESMVersioned)) { mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); } else { wspEdit.StartEditing(true); } wspEdit.StartEditOperation(); object copiedId = copyTool.Copy(hemErFt, gdhChinhFeatureClass); try { wspEdit.StopEditOperation(); wspEdit.StopEditing(true); } catch (Exception ex) { MessageBox.Show("line 1355 CalcGiaHemChinh ex=" + ex.ToString()); wspEdit.StopEditOperation(); wspEdit.StopEditing(false); } //them gia tri mathua,maduong,hesovitri pairColValTgd.Add(new object[,] { { _fcName.FC_GIA_DAT_HEM.GetIndex(_fcName.FC_GIA_DAT_HEM.MA_HEM), maHem } }); pairColValTgd.Add(new object[,] { { _fcName.FC_GIA_DAT_HEM.GetIndex(_fcName.FC_GIA_DAT_HEM.MA_DUONG), maduong } }); pairColValTgd.Add(new object[,] { { _fcName.FC_GIA_DAT_HEM.GetIndex(_fcName.FC_GIA_DAT_HEM.HE_SO), hesoVitri } }); pairColValTgd.Add(new object[,] { { _fcName.FC_GIA_DAT_HEM.GetIndex(_fcName.FC_GIA_DAT_HEM.LOCKED), 0 } }); //MessageBox.Show(string.Format("line 1125 CalcGiaHemChinh mahem={0},maduong={1}",maHem,maduong)); sdeTblGdhEditor.CacheData(copiedId, rowTgdNnHandleUpdate, pairColValTgd, EnumTypeOfEdit.UPDATE); rowTgdNnHandleUpdate++; pairColValTgd.Clear(); //MessageBox.Show("line 1129 CalcGiaHemChinh copyid=" + copiedId); newId.Add(copiedId); #endregion //*********************************** } //MessageBox.Show(newId.Count.ToString()); } catch (Exception e1) { MessageBox.Show(string.Format("CalcGiaHemChinh, line 1448-\n{0}", e1)); } finally { Marshal.ReleaseComObject(gdhChinhFcs); } #endregion } } catch (Exception ex) { } //finally { Marshal.ReleaseComObject(hemErCur); } #endregion //[kodoi] //============================ #region luu thong tin vao bang gia dat if (!sdeTblGdhEditor.IsEditing()) { sdeTblGdhEditor.StartEditing(esriMultiuserEditSessionMode.esriMESMVersioned); sdeTblGdhEditor.StartEditOperation(); } #region ----log evt.Log = string.Format("\n----||| Đang lưu vị trí các thửa vào bảng {0} |||---- ", gdhChinhFeatureClass.AliasName); onCalculating(evt); #endregion try { sdeTblGdhEditor.SaveEdit(); sdeTblGdhEditor.StopEditOperation(); sdeTblGdhEditor.StopEditing(true); } catch (Exception ex) { MessageBox.Show("line 1405 CalcGiaHemChinh ex=" + ex.ToString()); sdeTblGdhEditor.StopEditOperation(); sdeTblGdhEditor.StopEditing(false); } #region ----log evt.Log = string.Format("\n----||| Đã lưu vị trí các thửa vào bảng {0} |||---- ", gdhChinhFeatureClass.AliasName); onCalculating(evt); #endregion #endregion #region tinh gia dat cho cac hem vua them vi tri CalcLandprice calc = new CalcLandprice(this); //MessageBox.Show(string.Format("final:{0}", newId.Count)); calc.CalcGiaHem(newId); newId.Clear(); #endregion //============================ } #endregion } #endregion } #endregion //===================================================================== //===================================================================== #region tinh theo duong,doan duong else { #region timduong co ten dang xet //tinh theo doan duong #region tinh theo doan duong if (_inputParams.MA_DUONG != "-1") { qrf.WhereClause = string.Format("{0}={1} and {2}={3}", _fcName.FC_DUONG.MA_DUONG, _inputParams.MA_DUONG, _fcName.FC_DUONG.PHAN_LOAI, _isDothi);// "maduong='2'"; #region ----log evt.Log = string.Format("\n************************************************"); evt.Log += string.Format("\n****** Đang tính cho đoạn đường có mã: {0} ******", _inputParams.MA_DUONG); evt.Log += string.Format("\n************************************************"); onCalculating(evt); #endregion } #endregion //tinh cho 1 duong #region tinh cho 1 duong else if (_inputParams.TEN_DUONG != "" && _inputParams.TEN_DUONG != "*") { //phai sua lai thiet ke //dung relationshipclass many to many gia duong va ten duong #region tim trong bang ten duong qrf.WhereClause = string.Format("{0}=N'{1}'", _tblName.TEN_DUONG.TEN_DUONG, _inputParams.TEN_DUONG); ICursor tenduongCur = tblTenDuong.Search(qrf, false); object idDuong; List<object> lstIdDuong = new List<object>(); try { IRow tenduongRow = null; while ((tenduongRow = tenduongCur.NextRow()) != null) { idDuong = tenduongRow.get_Value(tenduongRow.Fields.FindField(_tblName.TEN_DUONG.MA_DUONG)); lstIdDuong.Add(idDuong); } } catch { } finally { Marshal.ReleaseComObject(tenduongCur); } #endregion #region tim trong bang duong string q = ""; for (int i = 0; i < lstIdDuong.Count; i++) { if (i == lstIdDuong.Count - 1) { q += string.Format("{0}='{1}'", _fcName.FC_DUONG.MA_DUONG, lstIdDuong[i]); } else { q += string.Format("{0}='{1}' or ", _fcName.FC_DUONG.MA_DUONG, lstIdDuong[i]); } } qrf.WhereClause = q;// "maduong='2'"; #region ----log evt.Log = string.Format("\n************************************************"); evt.Log += string.Format("\n****** Đang tính cho cả đường: {0} ******", _inputParams.TEN_DUONG); evt.Log += string.Format("\n************************************************"); onCalculating(evt); #endregion #endregion } #endregion //tinh cho ca duong else { qrf.WhereClause = ""; } //MessageBox.Show(string.Format("whereclause:{0}",duong.QueryFilter.WhereClause)); ISelectionSet duongSelectionSet = duongFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, sdeConn.Workspace); if (duongSelectionSet.Count == 0) { return; } duongFeatureSelection = (IFeatureSelection)duongFeatureLayer; duongFeatureSelection.SelectionSet = duongSelectionSet; #endregion #region vong lap xet tung duong //[thaydoi] - co the them bien chay //=============================== #region khoi dau IEnumIDs eIds = duongSelectionSet.IDs; int duongId; IFeature ftDuong; int iDuong = 0; int progressingTotalCount = 1; evt.Reset(); evt.ProgressingTotal = duongSelectionSet.Count; onCalculating(evt); List<object> lstMaDuong = new List<object>(); #endregion //================================ while ((duongId = eIds.Next()) != -1) { //[kodoi] //====================== #region log----- evt.Reset(); evt.ProgressingTotalCount = progressingTotalCount; onCalculating(evt); progressingTotalCount++; #endregion //====================== //[capnhat] - lay ten duong tu bang ten duong //++++++++++++++++++++++++ #region lay thong tin cua duong dang xet ftDuong = duongFeatureClass.GetFeature(duongId); string tenduong = "";//ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.TEN_DUONG)).ToString(); object maduong = ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.MA_DUONG)); lstMaDuong.Add(maduong); string batdau = "";// ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.BAT_DAU)).ToString(); string ketthuc = "";// ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.KET_THUC)).ToString(); #endregion //++++++++++++++++++++++++ //[kodoi] //Chon duong dang xet, buoc này de ra layer duong dung de truy van khong gian cac thua dat //==================== #region chon duong dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_DUONG.OID, duongId); duongSelectionSet = duongFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); duongFeatureSelection = (IFeatureSelection)duongFeatureLayer; duongFeatureSelection.SelectionSet = duongSelectionSet; #endregion //==================== //tim cac thua theo dieu kien mat tien //doc cach tim thua trong bang he so vi tri //lay cach tim cho dat o //truyen thong so cach tinh,thualayer,duonglayer,khoangcach //MessageBox.Show(func); //func = "ChongLop([INTERSECT],[NEW_SELECTION],1) Then ChongLop([CONTAINED_BY],[AND_SELECTION],50)"; //[kodoi] //============================ #region chon hem chinh cua duong qrf.WhereClause = string.Format("{0}='{1}' and ({2}='{3}' or {4} is null)", _fcName.FC_HEM.MA_DUONG, maduong, _fcName.FC_HEM.HEM_CHINH, 0, _fcName.FC_HEM.HEM_CHINH); ISelectionSet hemChinhSelectionSet = hemFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, sdeConn.Workspace); hemChinhFeatureSelection = (IFeatureSelection)hemChinhFeatureLayer; hemChinhFeatureSelection.SelectionSet = hemChinhSelectionSet; #endregion #region clip cac hem vua tim duoc #region delete bang hem_sau100m_clip IFeatureClass hemClipFc = null; #region log--- evt.Log = string.Format("\n----Kiểm tra, xóa bảng {0} ...", hemErase200mCoSde); onCalculating(evt); #endregion //if (_dataManager.LayerExist(hemErase200mNoSde)) //{ //thuaClipFc = fw.OpenFeatureClass("sde.thua_sau50m_clip"); //mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); //wspEdit.StartEditing(false); //wspEdit.StartEditOperation(); try { ((IFeatureClassManager)_dataManager).DeleteFcInSde(hemErase200mCoSde); } catch (Exception ex) { MessageBox.Show("line 924 CalGiaHemTren200,ex=" + ex.ToString()); } //((IDataset)thuaClipFc).Delete(); //wspEdit.StopEditOperation(); //wspEdit.StopEditing(true); //} #endregion #region chon duong buffer 100 dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_DUONG.OID, duongId); duongBuff200Sls = duongBuff200FeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); duongBuff200Fsls = (IFeatureSelection)duongBuff200FeatureLayer; duongBuff200Fsls.SelectionSet = duongBuff200Sls; #endregion #region chon hem nam trong vung buffer 200m nhưng khong nam trong vùng buffer 100m _qrBl.FromLayer = hemChinhFeatureLayer; _qrBl.ByLayer = duongFeatureLayer; _qrBl.LayerSelectionMethod = esriLayerSelectionMethod.esriLayerSelectContainedBy; _qrBl.ResultType = esriSelectionResultEnum.esriSelectionResultSubtract; _qrBl.UseSelectedFeatures = true; _qrBl.BufferDistance = 200; try { hemChinhSelectionSet = _qrBl.Select(); hemChinhFeatureSelection = (IFeatureSelection)hemChinhFeatureLayer; hemChinhFeatureSelection.SelectionSet = hemChinhSelectionSet; } catch { continue; } if (!(hemChinhSelectionSet.Count > 0)) { continue; } #endregion #region log--- evt.Log = string.Format("\n----Kiểm tra, clip hẻm theo đường buffer {0}m, lưu vào bảng {1} ...", _currentConfig.DKhoangCach50mMatTien, hemErase200mCoSde); onCalculating(evt); #endregion string hemlyr = string.Format("{0}/{1}", _sysTempPath.TempPath, hemErase200mNoSde); string duonglyr = string.Format("{0}/{1}", _sysTempPath.TempPath, duongBuffer200mNoSde); _eraseTool.EraseByLayerFileInsideSde(hemChinhFeatureLayer, hemlyr, duongBuff200FeatureLayer, duonglyr, hemErase200mNoSde); try { hemClipFc = fw.OpenFeatureClass(hemErase200mCoSde); } catch (Exception ex) { continue; } _version.RegisterDataset((IDataset)hemClipFc, true, true); #endregion #region xet tung hem da clip //[thaydoi] - co the them bien chay //******************** #region khoi dau //IFeatureCursor hemErCur = hemClipFc.Search(null, false); IEnumIDs hemChinhIds = hemChinhSelectionSet.IDs; int hemChinhId; IFeature hemChinhFt; int iHem = 0; List<object[,]> pairColValTgd = new List<object[,]>(); int rowTgdNnHandleUpdate = 0; List<object> newId = new List<object>(); #endregion try { while ((hemChinhId = hemChinhIds.Next()) != -1) { //he so vi tri hem ung voi doan sau <100m int hesoVitri = 3; #region lay thong tin hem dang xet //[kodoi] //============================ #region lay thong tin co ban hemChinhFt = hemFeatureClass.GetFeature(hemChinhId); //hemErId = hemErFt.OID; object maHem = hemChinhFt.get_Value(hemChinhFt.Fields.FindField(_fcName.FC_HEM.MA_HEM)); #endregion #endregion #region kiem tra trong bang giadat_hem, voi dieu kien:mahem,hesovitri,khoagia=0 evt.Reset(); evt.Log = "\n[!]--- Kiểm tra các hẻm đã có giá, cập nhật giá mới ..."; onCalculating(evt); qrf.WhereClause = string.Format("({0}='{1}' or {2} is null) and {3}='{4}' and {5}='{6}'", _fcName.FC_GIA_DAT_HEM.LOCKED, 0, _fcName.FC_GIA_DAT_HEM.LOCKED, _fcName.FC_GIA_DAT_HEM.MA_HEM, maHem, _fcName.FC_GIA_DAT_HEM.HE_SO, hesoVitri); IFeatureCursor gdhChinhFcs = gdhChinhFeatureClass.Search(qrf, false); IFeature gdhChinhFt = null; try { gdhChinhFt = gdhChinhFcs.NextFeature();//dam bao la chi co 1 hang ket qua if (gdhChinhFt != 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(gdhChinhFt.OID); //continue; } else { //[kodoi] //=================== #region xoa feature cu if (mwspEdit.SupportsMultiuserEditSessionMode(esriMultiuserEditSessionMode.esriMESMVersioned)) { mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); } else { wspEdit.StartEditing(true); } wspEdit.StartEditOperation(); //qrf.WhereClause = string.Format("{0}='{1}'", "OBJECTID", tgdRow.OID); //tblThuaGiaDat.DeleteSearchedRows(qrf); gdhChinhFt.Delete(); wspEdit.StopEditOperation(); wspEdit.StopEditing(true); #endregion //=================== #region chon trong bang thua clip qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_HEM.MA_HEM, maHem); IFeatureCursor hemClipFcur = hemClipFc.Search(qrf, false); IFeature hemErFt = null; try { hemErFt = hemClipFcur.NextFeature(); //MessageBox.Show("line 1058 CalcGiaHemTren200, id="+hemErFt.get_Value(0)); if (hemErFt == null) { continue; } } catch (Exception ex) { continue; } finally { Marshal.ReleaseComObject(hemClipFcur); } #region lay thong tin thua clip //IArea area = (IArea)hemClipFt.Shape; #endregion #endregion //[thaydoi] - them gia tri //********************** #region them feature moi if (mwspEdit.SupportsMultiuserEditSessionMode(esriMultiuserEditSessionMode.esriMESMVersioned)) { mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); } else { wspEdit.StartEditing(true); } wspEdit.StartEditOperation(); object copiedId = copyTool.Copy(hemErFt, gdhChinhFeatureClass); try { wspEdit.StopEditOperation(); wspEdit.StopEditing(true); } catch (Exception ex) { MessageBox.Show("line 1292 CalcGiaHemChinh ex=" + ex.ToString()); wspEdit.StopEditOperation(); wspEdit.StopEditing(false); } //them gia tri mathua,maduong,hesovitri pairColValTgd.Add(new object[,] { { gdhChinhFt.Fields.FindField(_fcName.FC_GIA_DAT_HEM.MA_HEM), maHem } }); pairColValTgd.Add(new object[,] { { gdhChinhFt.Fields.FindField(_fcName.FC_GIA_DAT_HEM.MA_DUONG), maduong } }); pairColValTgd.Add(new object[,] { { gdhChinhFt.Fields.FindField(_fcName.FC_GIA_DAT_HEM.LOCKED), 0 } }); pairColValTgd.Add(new object[,] { { gdhChinhFt.Fields.FindField(_fcName.FC_GIA_DAT_HEM.HE_SO), hesoVitri } }); //MessageBox.Show(string.Format("line 1062 CalcGiaHemChinh mahem={0},maduong={1}", maHem, maduong)); sdeTblGdhEditor.CacheData(copiedId, rowTgdNnHandleUpdate, pairColValTgd, EnumTypeOfEdit.UPDATE); rowTgdNnHandleUpdate++; pairColValTgd.Clear(); //MessageBox.Show("line 1066 CalcGiaHemChinh copyid=" + copiedId); newId.Add(copiedId); #endregion //********************** } #endregion } else { //MessageBox.Show("ko co"); //[thaydoi] - them cac gia tri thich hop vao thua_giadat //*********************************** #region chon trong bang thua clip qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_HEM.MA_HEM, maHem); //MessageBox.Show("line 1322 CalcGiaHemChinh, mahem=" + maHem); IFeatureCursor hemClipFcur = hemClipFc.Search(qrf, false); IFeature hemErFt = null; try { hemErFt = hemClipFcur.NextFeature(); if (hemErFt == null) { continue; } } catch (Exception ex) { return; } finally { Marshal.ReleaseComObject(hemClipFcur); } #region lay thong tin thua clip //IArea area = (IArea)hemClipFt.Shape; #endregion #endregion #region them feature moi if (mwspEdit.SupportsMultiuserEditSessionMode(esriMultiuserEditSessionMode.esriMESMVersioned)) { mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); } else { wspEdit.StartEditing(true); } wspEdit.StartEditOperation(); object copiedId = copyTool.Copy(hemErFt, gdhChinhFeatureClass); try { wspEdit.StopEditOperation(); wspEdit.StopEditing(true); } catch (Exception ex) { MessageBox.Show("line 1355 CalcGiaHemChinh ex=" + ex.ToString()); wspEdit.StopEditOperation(); wspEdit.StopEditing(false); } //them gia tri mathua,maduong,hesovitri pairColValTgd.Add(new object[,] { { _fcName.FC_GIA_DAT_HEM.GetIndex(_fcName.FC_GIA_DAT_HEM.MA_HEM), maHem } }); pairColValTgd.Add(new object[,] { { _fcName.FC_GIA_DAT_HEM.GetIndex(_fcName.FC_GIA_DAT_HEM.MA_DUONG), maduong } }); pairColValTgd.Add(new object[,] { { _fcName.FC_GIA_DAT_HEM.GetIndex(_fcName.FC_GIA_DAT_HEM.HE_SO), hesoVitri } }); pairColValTgd.Add(new object[,] { { _fcName.FC_GIA_DAT_HEM.GetIndex(_fcName.FC_GIA_DAT_HEM.LOCKED), 0 } }); //MessageBox.Show(string.Format("line 1125 CalcGiaHemChinh mahem={0},maduong={1}",maHem,maduong)); sdeTblGdhEditor.CacheData(copiedId, rowTgdNnHandleUpdate, pairColValTgd, EnumTypeOfEdit.UPDATE); rowTgdNnHandleUpdate++; pairColValTgd.Clear(); //MessageBox.Show("line 1129 CalcGiaHemChinh copyid=" + copiedId); newId.Add(copiedId); #endregion //*********************************** } //MessageBox.Show(newId.Count.ToString()); } catch (Exception e1) { MessageBox.Show(string.Format("CalcGiaHemChinh, line 1448-\n{0}", e1)); } finally { Marshal.ReleaseComObject(gdhChinhFcs); } #endregion } } catch (Exception ex) { } //finally { Marshal.ReleaseComObject(hemErCur); } #endregion //[kodoi] //============================ #region luu thong tin vao bang gia dat if (!sdeTblGdhEditor.IsEditing()) { sdeTblGdhEditor.StartEditing(esriMultiuserEditSessionMode.esriMESMVersioned); sdeTblGdhEditor.StartEditOperation(); } #region ----log evt.Log = string.Format("\n----||| Đang lưu vị trí các thửa vào bảng {0} |||---- ", gdhChinhFeatureClass.AliasName); onCalculating(evt); #endregion try { sdeTblGdhEditor.SaveEdit(); sdeTblGdhEditor.StopEditOperation(); sdeTblGdhEditor.StopEditing(true); } catch (Exception ex) { MessageBox.Show("line 1405 CalcGiaHemChinh ex=" + ex.ToString()); sdeTblGdhEditor.StopEditOperation(); sdeTblGdhEditor.StopEditing(false); } #region ----log evt.Log = string.Format("\n----||| Đã lưu vị trí các thửa vào bảng {0} |||---- ", gdhChinhFeatureClass.AliasName); onCalculating(evt); #endregion #endregion #region tinh gia dat cho cac hem vua them vi tri CalcLandprice calc = new CalcLandprice(this); //MessageBox.Show(string.Format("final:{0}", newId.Count)); calc.CalcGiaHem(newId); newId.Clear(); #endregion //============================ } #endregion } #endregion #endregion //=========================================== //=========================================== //******************************************* //[kodoi] //============== #region doan ket sothuatinhduoc = sothuatimthay - sothuaKhongTinhDuoc; #region ----log evt.Log = string.Format("\n\n**************************************\n******* Đã tính xong các thửa phi nông nghiệp tại đô thị vị trí mặt tiền*******\n**********************************"); //evt.Log += string.Format("\n Số thửa tìm thấy: {0}", sothuatimthay); //evt.Log += string.Format("\n Số thửa được tính: {0}", sothuatinhduoc); onCalculating(evt); #endregion evt.Reset(); evt.ProgressingTotalCount = "."; evt.ProgressingTotal = "."; onCalculating(evt); evt.CurrentIndexCalculator = this._index; onFinished(evt); #endregion //============== }
protected override void calculate() { #region khoi dau base.calculate(); CalculationEventArg evt = new CalculationEventArg(); //evt.Type = EnumTypeOfLoopCalculation.InListCalculators; evt.CurrentIndexCalculator = this._index; evt.Log = string.Format("********** Bắt đầu tính cho thửa nông nghiệp ở vị trí {0} ********", vitri); onCalculating(evt); #endregion //[thaydoi] - them cac khai bao can thiet //************************************ #region khai bao cac bien //Lay connection info hien tai SdeConnection conn = new SdeConnection(); ISdeConnectionInfo sdeConn = conn as ISdeConnectionInfo; IWorkspaceEdit wspEdit = (IWorkspaceEdit)sdeConn.Workspace; this._fcName = new TnFeatureClassName(sdeConn.Workspace); this._tblName = new TnTableName(sdeConn.Workspace); IFeatureWorkspace fw = (IFeatureWorkspace)sdeConn.Workspace; ICopyFeatures copyTool = new DataManager(sdeConn.Workspace,sdeConn.Environment); #region thua string thuaName = string.Format("{0}_{1}", DataNameTemplate.Thua, this._currentConfig.NamApDung); _fcName.FC_THUA.NAME = thuaName; _fcName.FC_THUA.InitIndex(); IFeatureClass thuaFeatureClass = fw.OpenFeatureClass(thuaName); IFeatureLayer thuaFeatureLayer = new FeatureLayerClass(); thuaFeatureLayer.FeatureClass = thuaFeatureClass; IFeatureSelection thuaFeatureSelection; #endregion #region xa IFeatureClass xaFeatureClass = fw.OpenFeatureClass(DataNameTemplate.Ranh_Xa_Poly); IFeatureLayer xaFeatureLayer = new FeatureLayerClass(); xaFeatureLayer.FeatureClass = xaFeatureClass; IFeatureSelection xaFeatureSelection; #endregion #region duong IFeatureClass duongFeatureClass = fw.OpenFeatureClass(DataNameTemplate.Duong); IFeatureLayer duongFeatureLayer = new FeatureLayerClass(); duongFeatureLayer.FeatureClass = duongFeatureClass; IFeatureSelection duongFeatureSelection; //_fcName.FC_DUONG.InitIndex(); #endregion #region thua gia dat string tgd = string.Format("{0}_{1}", DataNameTemplate.Thua_Gia_Dat_Draft, this._currentConfig.NamApDung); _fcName.FC_THUA_GIADAT_DRAFT.NAME = tgd; _fcName.FC_THUA_GIADAT_DRAFT.InitIndex(); //_fcName.FC_THUA_GIADAT_DRAFT.NAME = tgd; //_fcName.FC_THUA_GIADAT_DRAFT.InitIndex(); IFeatureClass tgdFeatureClass=null; try { tgdFeatureClass = fw.OpenFeatureClass(tgd); } catch (Exception exc) { evt.Log = string.Format("Không tìm thấy lớp dữ liệu: {0}", tgd); onCalculating(evt); onFinished(evt); return; } ITable tblThuaGiaDat = (ITable)tgdFeatureClass; IFeatureLayer tgdFeatureLayer = new FeatureLayerClass(); ISDETableEditor sdeTblTgdEditor = new SDETable(tblThuaGiaDat, sdeConn.Workspace); #endregion #region gia dat duong //string gdd = string.Format("{0}_{1}", DataNameTemplate.Gia_Dat_Duong, this._currentConfig.NamApDung); //_tblName.GIA_DAT_DUONG.NAME = gdd; //_tblName.GIA_DAT_DUONG.InitIndex(); #endregion #region ten duong ITable tblTenDuong; try { tblTenDuong = fw.OpenTable(DataNameTemplate.Ten_Duong); } catch (Exception exc) { evt.Log = string.Format("Không tìm thấy lớp dữ liệu: {0}", DataNameTemplate.Ten_Duong); onCalculating(evt); onFinished(evt); return; } #endregion #region loai dat ITable tblLoaiDat; try { tblLoaiDat = fw.OpenTable(DataNameTemplate.Loai_Dat); } catch (Exception exc) { evt.Log = string.Format("Không tìm thấy lớp dữ liệu: {0}", DataNameTemplate.Loai_Dat); onCalculating(evt); onFinished(evt); return; } #endregion #region he so vi tri ITable tblHesoVitri; try { tblHesoVitri = fw.OpenTable(DataNameTemplate.He_So_K); } catch (Exception exc) { evt.Log = string.Format("Không tìm thấy lớp dữ liệu: {0}", DataNameTemplate.He_So_K); onCalculating(evt); onFinished(evt); return; } #endregion #region khac IQueryFilter qrf = new QueryFilterClass(); bool result = false; int sothuatimthay = 0; int sothuatinhduoc = 0; int sothuaKhongTinhDuoc = 0; #endregion #endregion //************************************ //******************************************* //=========================================== //=========================================== #region bat dau tinh //[thaydoi] - cac may tinh khac chi can thay dieu kien truy van he so vi tri //****************************************************************** #region lay cac quy tac tim vi tri #region log--- evt.Log = string.Format("\n----Lấy các quy tắc tìm vị trí thửa từ bảng {0}, ứng với hệ số {1} ...", DataNameTemplate.He_So_K, TnHeSoK.DatNongNghiepVt1); onCalculating(evt); #endregion qrf.WhereClause = string.Format("{0}='{1}'", "hesovitri", TnHeSoK.DatNongNghiepVt1); ICursor cur = tblHesoVitri.Search(qrf, false); string quytac = ""; string cachtinh = ""; string cachtinhdongia = ""; try { IRow row = cur.NextRow(); if (row != null) { quytac = row.get_Value(_tblName.HESO_VITRI.GetIndex(_tblName.HESO_VITRI.QUY_TAC)).ToString(); cachtinh = row.get_Value(_tblName.HESO_VITRI.GetIndex(_tblName.HESO_VITRI.CACH_TINH)).ToString(); cachtinhdongia = row.get_Value(_tblName.HESO_VITRI.GetIndex(_tblName.HESO_VITRI.CACH_TINH_DON_GIA)).ToString(); } } catch { } finally { Marshal.ReleaseComObject(cur); } #endregion #region tinh theo xa if (this._inputParams.MA_XA != "-1") { //[kodoi] //======================= #region chon xa co ma dang xet //neu dang tinh cho 1 xa if (_inputParams.MA_XA != "*") { qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_RANH_XA_POLY.MA_XA, _inputParams.MA_XA); } else//neu dang tinh cho toan huyen { qrf.WhereClause = ""; } ISelectionSet xaSelectionSet = xaFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); xaFeatureSelection = (IFeatureSelection)xaFeatureLayer; xaFeatureSelection.SelectionSet = xaSelectionSet; #endregion //======================= #region vong lap tung xa //[thaydoi] - co the them bien chay //************************* #region khoi dau IEnumIDs xaIds = xaSelectionSet.IDs; int xaId = 0; IFeature xaFt = null; List<object> lstMaDuong = new List<object>(); #endregion //************************* while ((xaId = xaIds.Next()) != -1) { //[kodoi] //======================= #region lay thong tin xa xaFt = xaFeatureClass.GetFeature(xaId); string maxa = xaFt.get_Value(xaFt.Fields.FindField(_fcName.FC_RANH_XA_POLY.MA_XA)).ToString(); string tenxa = xaFt.get_Value(xaFt.Fields.FindField(_fcName.FC_RANH_XA_POLY.TEN_XA)).ToString(); string loaixa = xaFt.get_Value(xaFt.Fields.FindField(_fcName.FC_RANH_XA_POLY.MA_LOAI_XA)).ToString(); #endregion #region -----log evt.Log = string.Format("\n************************************************"); evt.Log += string.Format("\n****** Đang tính cho xã/phường: {0} ******", tenxa); evt.Log += string.Format("\n************************************************"); onCalculating(evt); #endregion #region tim duong trong khu vuc do thi bang qua xa //chon xa dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_RANH_XA_POLY.OID, xaId); xaSelectionSet = xaFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); xaFeatureSelection = (IFeatureSelection)xaFeatureLayer; xaFeatureSelection.SelectionSet = xaSelectionSet; //Chon cac duong co do rong theo quy dinh qrf.WhereClause = "";//string.Format("{0}='{1}'", _fcName.FC_DUONG.PHAN_LOAI, _isDothi);// "maduong='2'"; ISelectionSet duongSelectionSet = duongFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, sdeConn.Workspace); duongFeatureSelection = (IFeatureSelection)duongFeatureLayer; duongFeatureSelection.SelectionSet = duongSelectionSet; //bat dau truy van khong gian _qrBl.FromLayer = duongFeatureLayer; _qrBl.ByLayer = xaFeatureLayer; _qrBl.LayerSelectionMethod = esriLayerSelectionMethod.esriLayerSelectIntersect; _qrBl.ResultType = esriSelectionResultEnum.esriSelectionResultAnd; _qrBl.UseSelectedFeatures = true; duongSelectionSet = _qrBl.Select(); #endregion //======================= #region vong lap xet tung duong //[thaydoi] - co the them bien chay //=============================== #region khoi dau IEnumIDs eIds = duongSelectionSet.IDs; int duongId; IFeature ftDuong; int iDuong = 0; int progressingTotalCount = 1; evt.Reset(); evt.ProgressingTotal = duongSelectionSet.Count; onCalculating(evt); #endregion //================================ while ((duongId = eIds.Next()) != -1) { //[kodoi] //====================== #region log----- evt.Reset(); evt.ProgressingTotalCount = progressingTotalCount; onCalculating(evt); progressingTotalCount++; #endregion //====================== //[capnhat] - lay ten duong tu bang ten duong //++++++++++++++++++++++++ #region lay thong tin cua duong dang xet ftDuong = duongFeatureClass.GetFeature(duongId); double dorongDuong; result = double.TryParse(ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.DO_RONG)).ToString(), out dorongDuong); if (!result) { dorongDuong = 0; } if (dorongDuong < _currentConfig.DRongDuongVitri1Nn) { continue; } string tenduong = "";//ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.TEN_DUONG)).ToString(); object maduong = ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.MA_DUONG)); lstMaDuong.Add(maduong); string batdau = "";// ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.BAT_DAU)).ToString(); string ketthuc = "";// ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.KET_THUC)).ToString(); #endregion //++++++++++++++++++++++++ //[kodoi] //Chon duong dang xet, buoc này de ra layer duong dung de truy van khong gian cac thua dat //==================== #region chon duong dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_DUONG.OID, duongId); duongSelectionSet = duongFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); duongFeatureSelection = (IFeatureSelection)duongFeatureLayer; duongFeatureSelection.SelectionSet = duongSelectionSet; #endregion //==================== //tim cac thua theo dieu kien mat tien #region tinh vi tri cho cac thua //doc cach tim thua trong bang he so vi tri //lay cach tim cho dat o //truyen thong so cach tinh,thualayer,duonglayer,khoangcach //MessageBox.Show(func); //func = "ChongLop([INTERSECT],[NEW_SELECTION],1) Then ChongLop([CONTAINED_BY],[AND_SELECTION],50)"; //[kodoi] //============================ #region tim cac thua theo vi tri quy dinh thuaFeatureSelection = (IFeatureSelection)thuaFeatureLayer; thuaFeatureSelection.Clear(); Evaluation eval = new Evaluation(quytac); eval.ThuaLayer = thuaFeatureLayer; eval.DuongLayer = duongFeatureLayer; eval.EvaluateQuery(); //thuaFeatureSelection = (IFeatureSelection)thuaFeatureLayer; ISelectionSet thuaSelectionSet = thuaFeatureSelection.SelectionSet; #endregion //============================ //MessageBox.Show(thuaSelectionSet.Count.ToString()); #endregion //[kodoi] //============================ #region ----log if (thuaSelectionSet.Count == 0) { evt.Log = string.Format("\n !!! Không tìm thấy thửa nào tiếp giáp với đường {0} đoạn từ {1} đến {2} và nằm trong vùng buffer 50m", tenduong, batdau, ketthuc); onCalculating(evt); #region report progressing duong if (iDuong < duongSelectionSet.Count) { decimal i = (decimal)iDuong % (decimal)duongSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iDuong++; #endregion continue; } #endregion sothuatimthay += thuaSelectionSet.Count; //============================ #region xet tung thua //[thaydoi] - co the them bien chay //******************** #region khoi dau IEnumIDs thuaIds = thuaSelectionSet.IDs; int thuaId; IFeature thuaFt; int iThua = 0; List<object[,]> pairColValTgd = new List<object[,]>(); int rowTgdNnHandleUpdate = 0; List<object> newId = new List<object>(); #endregion //******************** while ((thuaId = thuaIds.Next()) != -1) { int hesoVitri = TnHeSoK.DatNongNghiepVt1; //[thaydoi] - co them them dieu kien de xac dinh vi tri cua thua //*********************************** #region lay thong tin thua dang xet //[kodoi] //============================ #region lay thong tin co ban thuaFt = thuaFeatureClass.GetFeature(thuaId); //neu thua bi khoa tim vi tri,bo qua,xet thua ke string lockTimVitri = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.LOCKED)).ToString(); if (lockTimVitri == "1") { sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } //neu thua ko thuoc xa dang xet thi ko tinh tiep object mathua = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.MA_THUA)); object maxaThua = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.MA_XA)); object dientichpl = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.DIEN_TICH)); #endregion //============================ //[kodoi] //============================ #region kiem tra maxa if (maxaThua.ToString() == "" || maxaThua == null) { maxaThua = "0"; #region ----log evt.Log = string.Format("Chưa xác định mã xã cho thửa {0}", mathua); #endregion sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } #region danh rieng khi tinh theo xa else if (maxaThua.ToString() != maxa) { #region ----log evt.Reset(); evt.Log = string.Format("thửa {0} không thuộc xã {1}", mathua, tenxa); onCalculating(evt); #endregion sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } #endregion #endregion //============================ #region lay loai dat //neu ko co dat phi nong nghiep thi bo qua,xet thua ke //neu co dat nong nghiep thi datnn=true //neu la dat hon hop, neu co dat sxkd thi datsxkd=true, //neu co dat o thi codato=true //cac truong hop he so vi tri: //o:3010, sxkd:4010, o+nn:5010, o+sxkd:6010 string loaidat = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.LOAI_DAT)).ToString(); //evt.Log = string.Format("\n loai dat cua thua {0} la {1}", thuaId, loaidat); //onCalculating(evt); //[thaydoi] - may tinh dat nong nghiep co the khac //*********************** #region kiem tra dat nong nghiep bool codatnn = false; object datnn = ""; foreach (string s in TnLoaiDats.NONG_NGHIEP) { if (loaidat == s) { codatnn = true; datnn = s; break; } else { codatnn = false; } } if (!codatnn) { sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } #endregion //*********************** #endregion #endregion //*********************************** //[thaydoi] - thay doi he so vi tri phu hop //*********************************** #region quyet dinh he so vi tri cho thua if (codatnn) { hesoVitri = TnHeSoK.DatNongNghiepVt1; } else { hesoVitri = TnHeSoK.KhongXacDinh; } #endregion //*********************************** //[thaydoi] - thay doi dieu kien truy van ung voi tung may tinh khac nhau //*********************************** #region kiem tra trong bang thua_giadat, voi dieu kien:mathua,maduong,hesovitri,khoagia=0 evt.Reset(); evt.Log = string.Format("\n[!]--- Kiểm tra các vị trí, cập nhật vị trí mới cho thửa {0} ...", mathua); onCalculating(evt); 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); ICursor tgdFcs = tblThuaGiaDat.Search(qrf, false); IRow tgdRow = null; //MessageBox.Show(string.Format("line 1401 CalcPosThuaMattien - bat dau try, query:\n{0}", qrf.WhereClause)); 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 wspEdit.StartEditing(true); 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 wspEdit.StartEditing(true); 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.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(); newId.Add(copiedId); #endregion //********************** } #endregion } else { //MessageBox.Show("ko co"); //[thaydoi] - them cac gia tri thich hop vao thua_giadat //*********************************** #region them feature moi wspEdit.StartEditing(true); wspEdit.StartEditOperation(); object copiedId = copyTool.Copy(thuaFt, tgdFeatureClass); 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.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(); 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); } #endregion //*********************************** #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion } #endregion //[kodoi] //============================ #region luu thong tin vao bang gia dat if (!sdeTblTgdEditor.IsEditing()) { sdeTblTgdEditor.StartEditing(true); sdeTblTgdEditor.StartEditOperation(); } #region ----log evt.Log = string.Format("\n----||| Đang lưu vị trí các thửa vào bảng {0} |||---- ", tgd); onCalculating(evt); #endregion sdeTblTgdEditor.SaveEdit(); sdeTblTgdEditor.StopEditOperation(); sdeTblTgdEditor.StopEditing(true); #region ----log evt.Log = string.Format("\n----||| Đã lưu vị trí các thửa vào bảng {0} |||---- ", tgd); onCalculating(evt); #endregion #endregion #region tinh gia dat cho cac thua vua them vi tri CalcLandprice calc = new CalcLandprice(this); //MessageBox.Show(string.Format("final:{0}", newId.Count)); calc.Maduong = maduong; calc.Calculate(newId); newId.Clear(); #endregion //============================ } #endregion } #endregion } #endregion //===================================================================== //===================================================================== #region tinh theo duong,doan duong else { #region timduong co ten dang xet //tinh theo doan duong #region tinh theo doan duong if (_inputParams.MA_DUONG != "-1") { qrf.WhereClause = string.Format("{0}={1}", _fcName.FC_DUONG.MA_DUONG, _inputParams.MA_DUONG);// "maduong='2'"; #region ----log evt.Log = string.Format("\n************************************************"); evt.Log += string.Format("\n****** Đang tính cho đoạn đường có mã: {0} ******", _inputParams.MA_DUONG); evt.Log += string.Format("\n************************************************"); onCalculating(evt); #endregion } #endregion //tinh cho 1 duong #region tinh cho 1 duong else if (_inputParams.TEN_DUONG != "" && _inputParams.TEN_DUONG != "*") { //phai sua lai thiet ke //dung relationshipclass many to many gia duong va ten duong #region tim trong bang ten duong qrf.WhereClause = string.Format("{0}=N'{1}'", _tblName.TEN_DUONG.TEN_DUONG, _inputParams.TEN_DUONG); //MessageBox.Show(string.Format("line 908 CalPosThuaNnVt1, tenduong={0}", _inputParams.TEN_DUONG)); ICursor tenduongCur = tblTenDuong.Search(qrf, false); object idDuong; List<object> lstIdDuong=new List<object>(); try { IRow tenduongRow = null; while ((tenduongRow = tenduongCur.NextRow()) != null) { idDuong = tenduongRow.get_Value(tenduongRow.Fields.FindField(_tblName.TEN_DUONG.MA_DUONG)); lstIdDuong.Add(idDuong); } } catch { } finally{Marshal.ReleaseComObject(tenduongCur);} #endregion #region tim trong bang duong string q = ""; for (int i = 0; i < lstIdDuong.Count; i++) { if (i == lstIdDuong.Count - 1) { q +=string.Format("{0}='{1}'",_fcName.FC_DUONG.MA_DUONG,lstIdDuong[i]); } else { q += string.Format("{0}='{1}' or ", _fcName.FC_DUONG.MA_DUONG, lstIdDuong[i]); } } qrf.WhereClause = q;// "maduong='2'"; #region ----log evt.Log = string.Format("\n************************************************"); evt.Log += string.Format("\n****** Đang tính cho cả đường: {0} ******", _inputParams.TEN_DUONG); evt.Log += string.Format("\n************************************************"); onCalculating(evt); #endregion #endregion } #endregion //tinh cho ca duong else { qrf.WhereClause = ""; } //MessageBox.Show(string.Format("whereclause:{0}",duong.QueryFilter.WhereClause)); ISelectionSet duongSelectionSet = duongFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, sdeConn.Workspace); if (duongSelectionSet.Count == 0) { return; } duongFeatureSelection = (IFeatureSelection)duongFeatureLayer; duongFeatureSelection.SelectionSet = duongSelectionSet; #endregion #region vong lap xet tung duong //[thaydoi] - co the them bien chay //=============================== #region khoi dau IEnumIDs eIds = duongSelectionSet.IDs; int duongId; IFeature ftDuong; int iDuong = 0; int progressingTotalCount = 1; evt.Reset(); evt.ProgressingTotal = duongSelectionSet.Count; onCalculating(evt); List<object> lstMaDuong = new List<object>(); #endregion //================================ while ((duongId = eIds.Next()) != -1) { //[kodoi] //====================== #region log----- evt.Reset(); evt.ProgressingTotalCount = progressingTotalCount; onCalculating(evt); progressingTotalCount++; #endregion //====================== //[capnhat] - lay ten duong tu bang ten duong //++++++++++++++++++++++++ #region lay thong tin cua duong dang xet ftDuong = duongFeatureClass.GetFeature(duongId); double dorongDuong; result = double.TryParse(ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.DO_RONG)).ToString(), out dorongDuong); if (!result) { dorongDuong = 0; } if (dorongDuong < _currentConfig.DRongDuongVitri1Nn) { continue; } string tenduong = "";//ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.TEN_DUONG)).ToString(); object maduong = ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.MA_DUONG)); lstMaDuong.Add(maduong); string batdau = "";// ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.BAT_DAU)).ToString(); string ketthuc = "";// ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.KET_THUC)).ToString(); #endregion //++++++++++++++++++++++++ //[kodoi] //Chon duong dang xet, buoc này de ra layer duong dung de truy van khong gian cac thua dat //==================== #region chon duong dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_DUONG.OID, duongId); duongSelectionSet = duongFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); duongFeatureSelection = (IFeatureSelection)duongFeatureLayer; duongFeatureSelection.SelectionSet = duongSelectionSet; #endregion //==================== //tim cac thua theo dieu kien mat tien #region tinh vi tri cho cac thua //doc cach tim thua trong bang he so vi tri //lay cach tim cho dat o //truyen thong so cach tinh,thualayer,duonglayer,khoangcach //MessageBox.Show(func); //func = "ChongLop([INTERSECT],[NEW_SELECTION],1) Then ChongLop([CONTAINED_BY],[AND_SELECTION],50)"; //[kodoi] //============================ #region tim cac thua theo vi tri quy dinh thuaFeatureSelection = (IFeatureSelection)thuaFeatureLayer; thuaFeatureSelection.Clear(); Evaluation eval = new Evaluation(quytac); eval.ThuaLayer = thuaFeatureLayer; eval.DuongLayer = duongFeatureLayer; eval.EvaluateQuery(); //thuaFeatureSelection = (IFeatureSelection)thuaFeatureLayer; ISelectionSet thuaSelectionSet = thuaFeatureSelection.SelectionSet; #endregion //============================ //MessageBox.Show(thuaSelectionSet.Count.ToString()); #endregion //[kodoi] //============================ #region ----log if (thuaSelectionSet.Count == 0) { evt.Log = string.Format("\n !!! Không tìm thấy thửa nào tiếp giáp với đường {0} đoạn từ {1} đến {2} và nằm trong vùng buffer 50m", tenduong, batdau, ketthuc); onCalculating(evt); #region report progressing duong if (iDuong < duongSelectionSet.Count) { decimal i = (decimal)iDuong % (decimal)duongSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iDuong++; #endregion continue; } #endregion sothuatimthay += thuaSelectionSet.Count; //============================ #region xet tung thua //[thaydoi] - co the them bien chay //******************** #region khoi dau IEnumIDs thuaIds = thuaSelectionSet.IDs; int thuaId; IFeature thuaFt; int iThua = 0; List<object[,]> pairColValTgd = new List<object[,]>(); int rowTgdNnHandleUpdate = 0; List<object> newId = new List<object>(); #endregion //******************** while ((thuaId = thuaIds.Next()) != -1) { int hesoVitri = TnHeSoK.DatNongNghiepVt1; //[thaydoi] - co them them dieu kien de xac dinh vi tri cua thua //*********************************** #region lay thong tin thua dang xet //[kodoi] //============================ #region lay thong tin co ban thuaFt = thuaFeatureClass.GetFeature(thuaId); //neu thua bi khoa tim vi tri,bo qua,xet thua ke string lockTimVitri = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.LOCKED)).ToString(); if (lockTimVitri == "1") { sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } //neu thua ko thuoc xa dang xet thi ko tinh tiep object mathua = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.MA_THUA)); object maxaThua = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.MA_XA)); object dientichpl = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.DIEN_TICH)); #endregion //============================ //[kodoi] //============================ #region kiem tra maxa if (maxaThua.ToString() == "" || maxaThua==null) { maxaThua = "0"; #region ----log evt.Log = string.Format("Chưa xác định mã xã cho thửa {0}", mathua); #endregion sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } #endregion //============================ #region lay loai dat //neu ko co dat phi nong nghiep thi bo qua,xet thua ke //neu co dat nong nghiep thi datnn=true //neu la dat hon hop, neu co dat sxkd thi datsxkd=true, //neu co dat o thi codato=true //cac truong hop he so vi tri: //o:3010, sxkd:4010, o+nn:5010, o+sxkd:6010 string loaidat = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.LOAI_DAT)).ToString(); //evt.Log = string.Format("\n loai dat cua thua {0} la {1}", thuaId, loaidat); //onCalculating(evt); //[thaydoi] - may tinh dat nong nghiep co the khac //*********************** #region kiem tra dat nong nghiep bool codatnn = false; object datnn=""; foreach (string s in TnLoaiDats.NONG_NGHIEP) { if (loaidat==s) { codatnn = true; datnn = s; break; } else { codatnn = false; } } if (!codatnn) { sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } #endregion //*********************** #endregion #endregion //*********************************** //[thaydoi] - thay doi he so vi tri phu hop //*********************************** #region quyet dinh he so vi tri cho thua if (codatnn) { hesoVitri = TnHeSoK.DatNongNghiepVt1; } else { hesoVitri = TnHeSoK.KhongXacDinh; } #endregion //*********************************** //[thaydoi] - thay doi dieu kien truy van ung voi tung may tinh khac nhau //*********************************** #region kiem tra trong bang thua_giadat, voi dieu kien:mathua,maduong,hesovitri,khoagia=0 evt.Reset(); evt.Log = string.Format("\n[!]--- Kiểm tra các vị trí, cập nhật vị trí mới cho thửa {0} ...", mathua); onCalculating(evt); 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); ICursor tgdFcs = tblThuaGiaDat.Search(qrf, false); IRow tgdRow = null; //MessageBox.Show(string.Format("line 1401 CalcPosThuaMattien - bat dau try, query:\n{0}", qrf.WhereClause)); 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 wspEdit.StartEditing(true); 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 wspEdit.StartEditing(true); 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.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(); newId.Add(copiedId); #endregion //********************** } #endregion } else { //MessageBox.Show("ko co"); //[thaydoi] - them cac gia tri thich hop vao thua_giadat //*********************************** #region them feature moi wspEdit.StartEditing(true); wspEdit.StartEditOperation(); object copiedId = copyTool.Copy(thuaFt, tgdFeatureClass); 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.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(); 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); } #endregion //*********************************** #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion } #endregion //[kodoi] //============================ #region luu thong tin vao bang gia dat if (!sdeTblTgdEditor.IsEditing()) { sdeTblTgdEditor.StartEditing(true); sdeTblTgdEditor.StartEditOperation(); } #region ----log evt.Log = string.Format("\n----||| Đang lưu vị trí các thửa vào bảng {0} |||---- ", tgd); onCalculating(evt); #endregion sdeTblTgdEditor.SaveEdit(); sdeTblTgdEditor.StopEditOperation(); sdeTblTgdEditor.StopEditing(true); #region ----log evt.Log = string.Format("\n----||| Đã lưu vị trí các thửa vào bảng {0} |||---- ", tgd); onCalculating(evt); #endregion #endregion #region tinh gia dat cho cac thua vua them vi tri CalcLandprice calc = new CalcLandprice(this); //MessageBox.Show(string.Format("final:{0}", newId.Count)); calc.Maduong = maduong; calc.Calculate(newId); newId.Clear(); #endregion //============================ } #endregion } #endregion #endregion //=========================================== //=========================================== //******************************************* //[kodoi] //============== #region doan ket sothuatinhduoc = sothuatimthay - sothuaKhongTinhDuoc; #region ----log evt.Log = string.Format("\n\n**************************************\n******* Đã tính xong các thửa phi nông nghiệp tại đô thị vị trí mặt tiền*******\n**********************************"); //evt.Log += string.Format("\n Số thửa tìm thấy: {0}", sothuatimthay); //evt.Log += string.Format("\n Số thửa được tính: {0}", sothuatinhduoc); onCalculating(evt); #endregion evt.Reset(); evt.ProgressingTotalCount = "."; evt.ProgressingTotal = "."; onCalculating(evt); evt.CurrentIndexCalculator = this._index; onFinished(evt); #endregion //============== }
protected override void calculate() { #region khoi dau base.calculate(); CalculationEventArg evt = new CalculationEventArg(); evt.CurrentIndexCalculator = this._index; List<object> newId = new List<object>(); newId.Add(_inputParams.OID_THUA_RIENG_LE); if (this._inputParams.TINH_THUA_RIENG_LE == 1) { evt.Log = string.Format("********** Bắt đầu tính giá cho thửa có id= {0} ********", _inputParams.OID_THUA_RIENG_LE); onCalculating(evt); CalcLandprice calc = new CalcLandprice(this); calc.Calculate(newId); } #region ----log evt.Log = string.Format("\n\n**************************************\n******* Đã tính xong*******\n**********************************"); //evt.Log += string.Format("\n Số thửa tìm thấy: {0}", sothuatimthay); //evt.Log += string.Format("\n Số thửa được tính: {0}", sothuatinhduoc); onCalculating(evt); #endregion evt.Reset(); evt.ProgressingTotalCount = "."; evt.ProgressingTotal = "."; onCalculating(evt); evt.CurrentIndexCalculator = this._index; onFinished(evt); //evt.Type = EnumTypeOfLoopCalculation.InListCalculators; #endregion }
protected override void calculate() { #region khoi dau base.calculate(); CalculationEventArg evt = new CalculationEventArg(); //evt.Type = EnumTypeOfLoopCalculation.InListCalculators; evt.CurrentIndexCalculator = this._index; evt.Log = string.Format("********** Bắt đầu tính cho thửa phi nông nghiệp ở vị trí {0} tại đô thị ********", vitri); onCalculating(evt); #endregion //[thaydoi] - them cac khai bao can thiet //************************************ #region khai bao cac bien //Lay connection info hien tai SdeConnection conn = new SdeConnection(); ISdeConnectionInfo sdeConn = conn as ISdeConnectionInfo; IWorkspaceEdit wspEdit = (IWorkspaceEdit)sdeConn.Workspace; IMultiuserWorkspaceEdit mwspEdit = (IMultiuserWorkspaceEdit)sdeConn.Workspace; this._fcName = new TnFeatureClassName(sdeConn.Workspace); this._tblName = new TnTableName(sdeConn.Workspace); IFeatureWorkspace fw = (IFeatureWorkspace)sdeConn.Workspace; ICopyFeatures copyTool = new DataManager(sdeConn.Workspace, sdeConn.Environment); #region thua string thuaName = string.Format("{0}_{1}", DataNameTemplate.Thua, this._currentConfig.NamApDung); _fcName.FC_THUA.NAME = thuaName; //MessageBox.Show(string.Format("line 55 CalcMattien {0}", thuaName)); _fcName.FC_THUA.InitIndex(); IFeatureClass thuaFeatureClass = fw.OpenFeatureClass(thuaName); IFeatureLayer thuaFeatureLayer = new FeatureLayerClass(); thuaFeatureLayer.FeatureClass = thuaFeatureClass; IFeatureSelection thuaFeatureSelection; #endregion #region xa IFeatureClass xaFeatureClass = fw.OpenFeatureClass(DataNameTemplate.Ranh_Xa_Poly); IFeatureLayer xaFeatureLayer = new FeatureLayerClass(); xaFeatureLayer.FeatureClass = xaFeatureClass; IFeatureSelection xaFeatureSelection; #endregion #region duong IFeatureClass duongFeatureClass = fw.OpenFeatureClass(DataNameTemplate.Duong); IFeatureLayer duongFeatureLayer = new FeatureLayerClass(); duongFeatureLayer.FeatureClass = duongFeatureClass; IFeatureSelection duongFeatureSelection; //_fcName.FC_DUONG.InitIndex(); #endregion #region hem IFeatureClass hemFeatureClass = fw.OpenFeatureClass(DataNameTemplate.Hem); IFeatureLayer hemChinhFeatureLayer = new FeatureLayerClass(); hemChinhFeatureLayer.FeatureClass = hemFeatureClass; IFeatureSelection hemChinhFeatureSelection; #endregion #region thua gia dat string tgdDraft = string.Format("{0}_{1}", DataNameTemplate.Thua_Gia_Dat_Draft, this._currentConfig.NamApDung); _fcName.FC_THUA_GIADAT_DRAFT.NAME = tgdDraft; _fcName.FC_THUA_GIADAT_DRAFT.InitIndex(); //_fcName.FC_THUA_GIADAT_DRAFT.NAME = tgdDraft; //_fcName.FC_THUA_GIADAT_DRAFT.InitIndex(); IFeatureClass tgdFeatureClass = null; 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; IFeatureLayer tgdFeatureLayer = new FeatureLayerClass(); ISDETableEditor sdeTblTgdEditor = new SDETable(tblThuaGiaDat, sdeConn.Workspace); #endregion #region gia dat hem string gdh = DataNameTemplate.Gia_Hem_Phu + "_" + _currentConfig.NamApDung.ToString(); _fcName.FC_GIA_DAT_HEM_PHU.NAME = gdh; _fcName.FC_GIA_DAT_HEM_PHU.InitIndex(); IFeatureClass gdhChinhFeatureClass = fw.OpenFeatureClass(gdh); IFeatureLayer gdhChinhFeatureLayer = new FeatureLayerClass(); gdhChinhFeatureLayer.FeatureClass = gdhChinhFeatureClass; IFeatureSelection gdhChinhFeatureSelection; #endregion #region gia dat duong string gdd = string.Format("{0}_{1}", DataNameTemplate.Gia_Dat_Duong, this._currentConfig.NamApDung); _tblName.GIA_DAT_DUONG.NAME = gdd; _tblName.GIA_DAT_DUONG.InitIndex(); #endregion #region ten duong ITable tblTenDuong; try { tblTenDuong = fw.OpenTable(DataNameTemplate.Ten_Duong); } catch (Exception exc) { evt.Log = string.Format("Không tìm thấy lớp dữ liệu: {0}", DataNameTemplate.Ten_Duong); onCalculating(evt); onFinished(evt); return; } #endregion #region loai dat ITable tblLoaiDat; try { tblLoaiDat = fw.OpenTable(DataNameTemplate.Loai_Dat); } catch (Exception exc) { evt.Log = string.Format("Không tìm thấy lớp dữ liệu: {0}", DataNameTemplate.Loai_Dat); onCalculating(evt); onFinished(evt); return; } #endregion #region he so vi tri ITable tblHesoVitri; try { tblHesoVitri = fw.OpenTable(DataNameTemplate.He_So_K); } catch (Exception exc) { evt.Log = string.Format("Không tìm thấy lớp dữ liệu: {0}", DataNameTemplate.He_So_K); onCalculating(evt); onFinished(evt); return; } #endregion #region khac IQueryFilter qrf = new QueryFilterClass(); bool result = false; int sothuatimthay = 0; int sothuatinhduoc = 0; int sothuaKhongTinhDuoc = 0; #endregion #endregion //************************************ //******************************************* //=========================================== //=========================================== #region bat dau tinh #region test //string ex = string.Format("VongLap(ChonDuong('dorong=10'),VongLap(ChonThua('dientich<1.5'),test([doituonglap]),[doituonglap]))"); ////ex=string.Format("VongLap(DuongDangChon(),VongLap() //Evaluation evalu = new Evaluation(ex); //evalu.DuongLayer = duongFeatureLayer; //evalu.ThuaLayer = thuaFeatureLayer; //evalu.EvaluateCalculating(); //return; #endregion //[thaydoi] - cac may tinh khac chi can thay dieu kien truy van he so vi tri //****************************************************************** #region lay cac quy tac tim vi tri #region log--- evt.Log = string.Format("\n----Lấy các quy tắc tìm vị trí thửa từ bảng {0}, ứng với hệ số {1} ...", DataNameTemplate.He_So_K, TnHeSoK.DatOMtTtDt); onCalculating(evt); #endregion //MessageBox.Show(String.Format("line 189 CalcThuaMattien, hsk={0}",TnHeSoK.DatOMtTtDt)); qrf.WhereClause = string.Format("{0}='{1}'", "hesovitri", TnHeSoK.DatOMtTtDt); ICursor cur = tblHesoVitri.Search(qrf, false); string quytac = ""; string cachtinh = ""; string cachtinhdongia = ""; try { IRow row = cur.NextRow(); if (row != null) { quytac = row.get_Value(_tblName.HESO_VITRI.GetIndex(_tblName.HESO_VITRI.QUY_TAC)).ToString(); cachtinh = row.get_Value(_tblName.HESO_VITRI.GetIndex(_tblName.HESO_VITRI.CACH_TINH)).ToString(); cachtinhdongia = row.get_Value(_tblName.HESO_VITRI.GetIndex(_tblName.HESO_VITRI.CACH_TINH_DON_GIA)).ToString(); //MessageBox.Show(string.Format("line 198 CalcMatTien, quytac={0}", quytac)); } } catch { } finally { Marshal.ReleaseComObject(cur); } #endregion #region tinh theo xa if (this._inputParams.MA_XA != "-1") { //[kodoi] //======================= #region chon xa co ma dang xet //neu dang tinh cho 1 xa if (_inputParams.MA_XA != "*") { qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_RANH_XA_POLY.MA_XA, _inputParams.MA_XA); } else//neu dang tinh cho toan huyen { qrf.WhereClause = ""; } ISelectionSet xaSelectionSet = xaFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); xaFeatureSelection = (IFeatureSelection)xaFeatureLayer; xaFeatureSelection.SelectionSet = xaSelectionSet; #endregion //======================= #region vong lap tung xa //[thaydoi] - co the them bien chay //************************* #region khoi dau IEnumIDs xaIds = xaSelectionSet.IDs; int xaId = 0; IFeature xaFt = null; List<object> lstMaDuong = new List<object>(); #endregion //************************* while ((xaId = xaIds.Next()) != -1) { //[kodoi] //======================= #region lay thong tin xa xaFt = xaFeatureClass.GetFeature(xaId); string maxa = xaFt.get_Value(xaFt.Fields.FindField(_fcName.FC_RANH_XA_POLY.MA_XA)).ToString(); string tenxa = xaFt.get_Value(xaFt.Fields.FindField(_fcName.FC_RANH_XA_POLY.TEN_XA)).ToString(); string loaixa = xaFt.get_Value(xaFt.Fields.FindField(_fcName.FC_RANH_XA_POLY.MA_LOAI_XA)).ToString(); int loaidothi = 0; result = int.TryParse(xaFt.get_Value(xaFt.Fields.FindField(_fcName.FC_RANH_XA_POLY.LOAI_DO_THI)).ToString(), out loaidothi); #endregion if (loaidothi == 0) { continue; } #region -----log evt.Log = string.Format("\n************************************************"); evt.Log += string.Format("\n****** Đang tính cho xã/phường: {0} ******", tenxa); evt.Log += string.Format("\n************************************************"); onCalculating(evt); #endregion #region tim duong trong khu vuc do thi bang qua xa //chon xa dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_RANH_XA_POLY.OID, xaId); xaSelectionSet = xaFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); xaFeatureSelection = (IFeatureSelection)xaFeatureLayer; xaFeatureSelection.SelectionSet = xaSelectionSet; //Chon cac duong co do rong theo quy dinh qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_DUONG.PHAN_LOAI, _isDothi);// "maduong='2'"; ISelectionSet duongSelectionSet = duongFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, sdeConn.Workspace); duongFeatureSelection = (IFeatureSelection)duongFeatureLayer; duongFeatureSelection.SelectionSet = duongSelectionSet; //bat dau truy van khong gian _qrBl.FromLayer = duongFeatureLayer; _qrBl.ByLayer = xaFeatureLayer; _qrBl.LayerSelectionMethod = esriLayerSelectionMethod.esriLayerSelectIntersect; _qrBl.ResultType = esriSelectionResultEnum.esriSelectionResultAnd; _qrBl.UseSelectedFeatures = true; duongSelectionSet = _qrBl.Select(); #endregion //======================= #region vong lap xet tung duong //[thaydoi] - co the them bien chay //=============================== #region khoi dau IEnumIDs eIds = duongSelectionSet.IDs; int duongId; IFeature ftDuong; int iDuong = 0; int progressingTotalCount = 1; evt.Reset(); evt.ProgressingTotal = duongSelectionSet.Count; onCalculating(evt); //List<object> lstMaDuong = new List<object>(); #endregion //================================ while ((duongId = eIds.Next()) != -1) { //[kodoi] //====================== #region log----- evt.Reset(); evt.ProgressingTotalCount = progressingTotalCount; onCalculating(evt); progressingTotalCount++; #endregion //====================== //[capnhat] - lay ten duong tu bang ten duong //++++++++++++++++++++++++ #region lay thong tin cua duong dang xet ftDuong = duongFeatureClass.GetFeature(duongId); string tenduong = "";//ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.TEN_DUONG)).ToString(); object maduong = ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.MA_DUONG)); lstMaDuong.Add(maduong); string batdau = "";// ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.BAT_DAU)).ToString(); string ketthuc = "";// ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.KET_THUC)).ToString(); #endregion //++++++++++++++++++++++++ //[kodoi] //Chon duong dang xet, buoc này de ra layer duong dung de truy van khong gian cac thua dat //==================== #region chon duong dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_DUONG.OID, duongId); duongSelectionSet = duongFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); duongFeatureSelection = (IFeatureSelection)duongFeatureLayer; duongFeatureSelection.SelectionSet = duongSelectionSet; #endregion //==================== #region chon hem gia dat cua duong qrf.WhereClause = string.Format("({0}='{1}' or {2} is null) and {3}='{4}'", _fcName.FC_GIA_DAT_HEM_PHU.LOCKED, 0, _fcName.FC_GIA_DAT_HEM_PHU.LOCKED, _fcName.FC_GIA_DAT_HEM_PHU.MA_DUONG, maduong); ISelectionSet gdhChinhSelectionSet = gdhChinhFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, sdeConn.Workspace); gdhChinhFeatureSelection = (IFeatureSelection)gdhChinhFeatureLayer; gdhChinhFeatureSelection.SelectionSet = gdhChinhSelectionSet; #endregion #region xet tung hem co gia IEnumIDs gdhChinhIds = gdhChinhSelectionSet.IDs; //IFeatureCursor hemClipCur = hemClipFc.Search(null, false); int gdhChinhId; IFeature gdhChinhFt; int iHem = 0; //List<object[,]> pairColValTgd = new List<object[,]>(); //int rowTgdNnHandleUpdate = 0; //List<object> newId = new List<object>(); #endregion while ((gdhChinhId = gdhChinhIds.Next()) != -1) { gdhChinhFt = gdhChinhFeatureClass.GetFeature(gdhChinhId); int hesoHem = 3; result = int.TryParse(gdhChinhFt.get_Value(gdhChinhFt.Fields.FindField(_fcName.FC_GIA_DAT_HEM_PHU.HE_SO)).ToString(), out hesoHem); if (!result) { hesoHem = 3; } object giahem = gdhChinhFt.get_Value(gdhChinhFt.Fields.FindField(_fcName.FC_GIA_DAT_HEM_PHU.GIA_DAT)); #region lay thong tin hem object mahem = gdhChinhFt.get_Value(gdhChinhFt.Fields.FindField(_fcName.FC_GIA_DAT_HEM_PHU.MA_HEM)); qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_HEM.MA_HEM, mahem); IFeatureCursor hemCur = hemFeatureClass.Search(qrf, false); IFeature hemFt = null; double dorong = 0; try { if ((hemFt = hemCur.NextFeature()) != null) { result = double.TryParse(hemFt.get_Value(hemFt.Fields.FindField(_fcName.FC_HEM.DO_RONG)).ToString(), out dorong); if (!result) { dorong = 0; } } } catch { } finally { Marshal.ReleaseComObject(hemCur); } #endregion #region chon hem dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_GIA_DAT_HEM_PHU.OID, gdhChinhId); gdhChinhSelectionSet = gdhChinhFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, sdeConn.Workspace); gdhChinhFeatureSelection = (IFeatureSelection)gdhChinhFeatureLayer; gdhChinhFeatureSelection.SelectionSet = gdhChinhSelectionSet; #endregion #region chon cac thua tiep giap voi hem dang xet //thuaFeatureSelection.Clear(); //IQueryByLayer _qrBl = new QueryByLayerClass(); _qrBl.FromLayer = thuaFeatureLayer; _qrBl.ByLayer = gdhChinhFeatureLayer; _qrBl.LayerSelectionMethod = esriLayerSelectionMethod.esriLayerSelectIntersect; _qrBl.ResultType = esriSelectionResultEnum.esriSelectionResultNew; _qrBl.UseSelectedFeatures = true; _qrBl.BufferDistance = 1; ISelectionSet thuaSelectionSet; try { thuaSelectionSet = _qrBl.Select(); thuaFeatureSelection = (IFeatureSelection)thuaFeatureLayer; thuaFeatureSelection.SelectionSet = thuaSelectionSet; } catch { continue; } #endregion #region xet tung thua if (thuaSelectionSet.Count == 0 || thuaSelectionSet == null) { continue; } #region khoi dau IEnumIDs thuaIds = thuaSelectionSet.IDs; int thuaId; IFeature thuaFt; int iThua = 0; List<object[,]> pairColValTgd = new List<object[,]>(); int rowTgdNnHandleUpdate = 0; List<object> newId = new List<object>(); #endregion while ((thuaId = thuaIds.Next()) != -1) { thuaFt = thuaFeatureClass.GetFeature(thuaId); object mathua = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.MA_THUA)); object maxaThua = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.MA_XA)); //[kodoi] //============================ #region kiem tra maxa if (maxaThua.ToString() == "" || maxaThua == null) { maxaThua = "0"; #region ----log evt.Log = string.Format("Chưa xác định mã xã cho thửa {0}", mathua); #endregion sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } #region danh rieng khi tinh theo xa else if (maxaThua.ToString() != maxa) { #region ----log evt.Reset(); evt.Log = string.Format("thửa {0} không thuộc xã {1} (maxaThua={2},maxa={3})", mathua, tenxa, maxaThua, maxa); onCalculating(evt); #endregion sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } #endregion #endregion object dientichpl = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.DIEN_TICH)); string loaidat = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.LOAI_DAT)).ToString(); int hesoVitri = CalcTool.GetHeSoViTriThuaHem(dorong, hesoHem, loaidat, true); if (hesoVitri == -1) { continue; } //[thaydoi] - thay doi dieu kien truy van ung voi tung may tinh khac nhau //*********************************** #region kiem tra trong bang thua_giadat, voi dieu kien:mathua,maduong,hesovitri,khoagia=0 evt.Reset(); evt.Log = "\n[!]--- Kiểm tra các vị trí, cập nhật vị trí mới ..."; onCalculating(evt); 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); ICursor tgdFcs = tblThuaGiaDat.Search(qrf, false); IRow tgdRow = null; //MessageBox.Show(string.Format("line 1401 CalcPosThuaMattien - bat dau try, query:\n{0}", qrf.WhereClause)); 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 if (mwspEdit.SupportsMultiuserEditSessionMode(esriMultiuserEditSessionMode.esriMESMVersioned)) { mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); } else { wspEdit.StartEditing(true); } 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 if (mwspEdit.SupportsMultiuserEditSessionMode(esriMultiuserEditSessionMode.esriMESMVersioned)) { mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); } else { wspEdit.StartEditing(true); } 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_HEM), mahem } }); 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.HE_SO_K), hesoVitri } }); //pairColValTgd.Add(new object[,] { { tgdRow.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.DON_GIA), giahem } }); 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(); newId.Add(copiedId); #endregion //********************** } #endregion } else { //MessageBox.Show("ko co"); //[thaydoi] - them cac gia tri thich hop vao thua_giadat //*********************************** #region them feature moi if (mwspEdit.SupportsMultiuserEditSessionMode(esriMultiuserEditSessionMode.esriMESMVersioned)) { mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); } else { wspEdit.StartEditing(true); } wspEdit.StartEditOperation(); object copiedId = copyTool.Copy(thuaFt, tgdFeatureClass); 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_HEM), mahem } }); 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.HE_SO_K), hesoVitri } }); //pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.DON_GIA), giahem } }); 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(); 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); } #endregion //*********************************** #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion } #endregion //[kodoi] //============================ #region luu thong tin vao bang gia dat if (!sdeTblTgdEditor.IsEditing()) { sdeTblTgdEditor.StartEditing(esriMultiuserEditSessionMode.esriMESMVersioned); sdeTblTgdEditor.StartEditOperation(); } #region ----log evt.Log = string.Format("\n----||| Đang lưu vị trí các thửa vào bảng {0} |||---- ", tgdDraft); onCalculating(evt); #endregion sdeTblTgdEditor.SaveEdit(); sdeTblTgdEditor.StopEditOperation(); sdeTblTgdEditor.StopEditing(true); #region ----log evt.Log = string.Format("\n----||| Đã lưu vị trí các thửa vào bảng {0} |||---- ", tgdDraft); onCalculating(evt); #endregion #endregion #region tinh gia dat cho cac thua vua them vi tri CalcLandprice calc = new CalcLandprice(this); //MessageBox.Show(string.Format("final:{0}", newId.Count)); calc.Calculate(newId); newId.Clear(); #endregion //============================ } } #endregion } #endregion } #endregion //===================================================================== //===================================================================== #region tinh theo duong,doan duong else { #region timduong co ten dang xet //tinh theo doan duong #region tinh theo doan duong if (_inputParams.MA_DUONG != "-1") { qrf.WhereClause = string.Format("{0}={1} and {2}={3}", _fcName.FC_DUONG.MA_DUONG, _inputParams.MA_DUONG, _fcName.FC_DUONG.PHAN_LOAI, _isDothi);// "maduong='2'"; #region ----log evt.Log = string.Format("\n************************************************"); evt.Log += string.Format("\n****** Đang tính cho đoạn đường có mã: {0} ******", _inputParams.MA_DUONG); evt.Log += string.Format("\n************************************************"); onCalculating(evt); #endregion } #endregion //tinh cho 1 duong #region tinh cho 1 duong else if (_inputParams.TEN_DUONG != "" && _inputParams.TEN_DUONG != "*") { //phai sua lai thiet ke //dung relationshipclass many to many gia duong va ten duong #region tim trong bang ten duong qrf.WhereClause = string.Format("{0}=N'{1}'", _tblName.TEN_DUONG.TEN_DUONG, _inputParams.TEN_DUONG); ICursor tenduongCur = tblTenDuong.Search(qrf, false); object idDuong; List<object> lstIdDuong = new List<object>(); try { IRow tenduongRow = null; while ((tenduongRow = tenduongCur.NextRow()) != null) { idDuong = tenduongRow.get_Value(tenduongRow.Fields.FindField(_tblName.TEN_DUONG.MA_DUONG)); lstIdDuong.Add(idDuong); } } catch { } finally { Marshal.ReleaseComObject(tenduongCur); } #endregion #region tim trong bang duong string q = ""; for (int i = 0; i < lstIdDuong.Count; i++) { if (i == lstIdDuong.Count - 1) { q += string.Format("{0}='{1}'", _fcName.FC_DUONG.MA_DUONG, lstIdDuong[i]); } else { q += string.Format("{0}='{1}' or ", _fcName.FC_DUONG.MA_DUONG, lstIdDuong[i]); } } qrf.WhereClause = q;// "maduong='2'"; #region ----log evt.Log = string.Format("\n************************************************"); evt.Log += string.Format("\n****** Đang tính cho cả đường: {0} ******", _inputParams.TEN_DUONG); evt.Log += string.Format("\n************************************************"); onCalculating(evt); #endregion #endregion } #endregion //tinh cho ca duong else { qrf.WhereClause = ""; } //MessageBox.Show(string.Format("whereclause:{0}",duong.QueryFilter.WhereClause)); ISelectionSet duongSelectionSet = duongFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, sdeConn.Workspace); if (duongSelectionSet.Count == 0) { return; } duongFeatureSelection = (IFeatureSelection)duongFeatureLayer; duongFeatureSelection.SelectionSet = duongSelectionSet; #endregion #region vong lap xet tung duong //[thaydoi] - co the them bien chay //=============================== #region khoi dau IEnumIDs eIds = duongSelectionSet.IDs; int duongId; IFeature ftDuong; int iDuong = 0; int progressingTotalCount = 1; evt.Reset(); evt.ProgressingTotal = duongSelectionSet.Count; onCalculating(evt); List<object> lstMaDuong = new List<object>(); #endregion //================================ while ((duongId = eIds.Next()) != -1) { //[kodoi] //====================== #region log----- evt.Reset(); evt.ProgressingTotalCount = progressingTotalCount; onCalculating(evt); progressingTotalCount++; #endregion //====================== //[capnhat] - lay ten duong tu bang ten duong //++++++++++++++++++++++++ #region lay thong tin cua duong dang xet ftDuong = duongFeatureClass.GetFeature(duongId); string tenduong = "";//ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.TEN_DUONG)).ToString(); object maduong = ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.MA_DUONG)); lstMaDuong.Add(maduong); string batdau = "";// ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.BAT_DAU)).ToString(); string ketthuc = "";// ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.KET_THUC)).ToString(); #endregion //++++++++++++++++++++++++ //[kodoi] //Chon duong dang xet, buoc này de ra layer duong dung de truy van khong gian cac thua dat //==================== #region chon duong dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_DUONG.OID, duongId); duongSelectionSet = duongFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); duongFeatureSelection = (IFeatureSelection)duongFeatureLayer; duongFeatureSelection.SelectionSet = duongSelectionSet; #endregion //==================== #region chon hem gia dat cua duong qrf.WhereClause = string.Format("({0}='{1}' or {2} is null) and {3}='{4}'", _fcName.FC_GIA_DAT_HEM_PHU.LOCKED, 0, _fcName.FC_GIA_DAT_HEM_PHU.LOCKED, _fcName.FC_GIA_DAT_HEM_PHU.MA_DUONG, maduong); ISelectionSet gdhChinhSelectionSet = gdhChinhFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, sdeConn.Workspace); gdhChinhFeatureSelection = (IFeatureSelection)gdhChinhFeatureLayer; gdhChinhFeatureSelection.SelectionSet = gdhChinhSelectionSet; #endregion #region xet tung hem co gia IEnumIDs gdhChinhIds = gdhChinhSelectionSet.IDs; //IFeatureCursor hemClipCur = hemClipFc.Search(null, false); int gdhChinhId; IFeature gdhChinhFt; int iHem = 0; //List<object[,]> pairColValTgd = new List<object[,]>(); //int rowTgdNnHandleUpdate = 0; //List<object> newId = new List<object>(); #endregion while ((gdhChinhId = gdhChinhIds.Next()) != -1) { gdhChinhFt = gdhChinhFeatureClass.GetFeature(gdhChinhId); int hesoHem = 3; result = int.TryParse(gdhChinhFt.get_Value(gdhChinhFt.Fields.FindField(_fcName.FC_GIA_DAT_HEM_PHU.HE_SO)).ToString(), out hesoHem); if (!result) { hesoHem = 3; } object giahem = gdhChinhFt.get_Value(gdhChinhFt.Fields.FindField(_fcName.FC_GIA_DAT_HEM_PHU.GIA_DAT)); #region lay thong tin hem object mahem = gdhChinhFt.get_Value(gdhChinhFt.Fields.FindField(_fcName.FC_GIA_DAT_HEM_PHU.MA_HEM)); qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_HEM.MA_HEM, mahem); IFeatureCursor hemCur = hemFeatureClass.Search(qrf, false); IFeature hemFt = null; double dorong = 0; try { if ((hemFt = hemCur.NextFeature()) != null) { result = double.TryParse(hemFt.get_Value(hemFt.Fields.FindField(_fcName.FC_HEM.DO_RONG)).ToString(), out dorong); if (!result) { dorong = 0; } } } catch { } finally { Marshal.ReleaseComObject(hemCur); } #endregion #region chon hem dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_GIA_DAT_HEM_PHU.OID, gdhChinhId); gdhChinhSelectionSet = gdhChinhFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, sdeConn.Workspace); gdhChinhFeatureSelection = (IFeatureSelection)gdhChinhFeatureLayer; gdhChinhFeatureSelection.SelectionSet = gdhChinhSelectionSet; #endregion #region chon cac thua tiep giap voi hem dang xet //thuaFeatureSelection.Clear(); //IQueryByLayer _qrBl = new QueryByLayerClass(); _qrBl.FromLayer = thuaFeatureLayer; _qrBl.ByLayer = gdhChinhFeatureLayer; _qrBl.LayerSelectionMethod = esriLayerSelectionMethod.esriLayerSelectIntersect; _qrBl.ResultType = esriSelectionResultEnum.esriSelectionResultNew; _qrBl.UseSelectedFeatures = true; _qrBl.BufferDistance = 1; ISelectionSet thuaSelectionSet; try { thuaSelectionSet = _qrBl.Select(); thuaFeatureSelection = (IFeatureSelection)thuaFeatureLayer; thuaFeatureSelection.SelectionSet = thuaSelectionSet; } catch { continue; } #endregion #region xet tung thua if (thuaSelectionSet.Count == 0 || thuaSelectionSet == null) { continue; } #region khoi dau IEnumIDs thuaIds = thuaSelectionSet.IDs; int thuaId; IFeature thuaFt; int iThua = 0; List<object[,]> pairColValTgd = new List<object[,]>(); int rowTgdNnHandleUpdate = 0; List<object> newId = new List<object>(); #endregion while ((thuaId = thuaIds.Next()) != -1) { thuaFt = thuaFeatureClass.GetFeature(thuaId); object mathua = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.MA_THUA)); object maxaThua = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.MA_XA)); //[kodoi] //============================ #region kiem tra maxa if (maxaThua.ToString() == "" || maxaThua == null) { maxaThua = "0"; #region ----log evt.Log = string.Format("Chưa xác định mã xã cho thửa {0}", mathua); #endregion sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } #endregion object dientichpl = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.DIEN_TICH)); string loaidat = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.LOAI_DAT)).ToString(); int hesoVitri = CalcTool.GetHeSoViTriThuaHem(dorong, hesoHem, loaidat,true); if (hesoVitri == -1) { continue; } //[thaydoi] - thay doi dieu kien truy van ung voi tung may tinh khac nhau //*********************************** #region kiem tra trong bang thua_giadat, voi dieu kien:mathua,maduong,hesovitri,khoagia=0 evt.Reset(); evt.Log = "\n[!]--- Kiểm tra các vị trí, cập nhật vị trí mới ..."; onCalculating(evt); 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); ICursor tgdFcs = tblThuaGiaDat.Search(qrf, false); IRow tgdRow = null; //MessageBox.Show(string.Format("line 1401 CalcPosThuaMattien - bat dau try, query:\n{0}", qrf.WhereClause)); 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 if (mwspEdit.SupportsMultiuserEditSessionMode(esriMultiuserEditSessionMode.esriMESMVersioned)) { mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); } else { wspEdit.StartEditing(true); } 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 if (mwspEdit.SupportsMultiuserEditSessionMode(esriMultiuserEditSessionMode.esriMESMVersioned)) { mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); } else { wspEdit.StartEditing(true); } 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_HEM), mahem } }); 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.HE_SO_K), hesoVitri } }); //pairColValTgd.Add(new object[,] { { tgdRow.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.DON_GIA), giahem } }); 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(); newId.Add(copiedId); #endregion //********************** } #endregion } else { //MessageBox.Show("ko co"); //[thaydoi] - them cac gia tri thich hop vao thua_giadat //*********************************** #region them feature moi if (mwspEdit.SupportsMultiuserEditSessionMode(esriMultiuserEditSessionMode.esriMESMVersioned)) { mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); } else { wspEdit.StartEditing(true); } wspEdit.StartEditOperation(); object copiedId = copyTool.Copy(thuaFt, tgdFeatureClass); 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_HEM), mahem } }); 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.HE_SO_K), hesoVitri } }); //pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.DON_GIA), giahem } }); 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(); 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); } #endregion //*********************************** #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion } #endregion //[kodoi] //============================ #region luu thong tin vao bang gia dat if (!sdeTblTgdEditor.IsEditing()) { sdeTblTgdEditor.StartEditing(esriMultiuserEditSessionMode.esriMESMVersioned); sdeTblTgdEditor.StartEditOperation(); } #region ----log evt.Log = string.Format("\n----||| Đang lưu vị trí các thửa vào bảng {0} |||---- ", tgdDraft); onCalculating(evt); #endregion sdeTblTgdEditor.SaveEdit(); sdeTblTgdEditor.StopEditOperation(); sdeTblTgdEditor.StopEditing(true); #region ----log evt.Log = string.Format("\n----||| Đã lưu vị trí các thửa vào bảng {0} |||---- ", tgdDraft); onCalculating(evt); #endregion #endregion #region tinh gia dat cho cac thua vua them vi tri CalcLandprice calc = new CalcLandprice(this); //MessageBox.Show(string.Format("final:{0}", newId.Count)); calc.Calculate(newId); newId.Clear(); #endregion //============================ } } #endregion } #endregion #endregion //=========================================== //=========================================== //******************************************* //[kodoi] //============== #region doan ket sothuatinhduoc = sothuatimthay - sothuaKhongTinhDuoc; #region ----log evt.Log = string.Format("\n\n**************************************\n******* Đã tính xong các thửa phi nông nghiệp tại đô thị vị trí mặt tiền*******\n**********************************"); //evt.Log += string.Format("\n Số thửa tìm thấy: {0}", sothuatimthay); //evt.Log += string.Format("\n Số thửa được tính: {0}", sothuatinhduoc); onCalculating(evt); #endregion evt.Reset(); evt.ProgressingTotalCount = "."; evt.ProgressingTotal = "."; onCalculating(evt); evt.CurrentIndexCalculator = this._index; onFinished(evt); #endregion //============== }
public void Calculate(List<object> newId) { #region tinh gia dat //cachtinhdongia = "[giadatduong] * [hesodatsxkd]"; //cachtinhdongia = "DonGiaSxkdMattienDt(Multiply([giadatduong],[hesodatsxkd]))"; //cachtinhdongia = "DonGiaOcoNnMattienDt([giadatduong])"; //cachtinhdongia = "DonGiaOcoSxkdMattienDt([giadatduong])"; //cachtinh="[giadatduong] * [dientich]"; //cachtinh = "GiaDatSxkdMattienDt([giadatduong] * [hesodatsxkd] * [dientich])"; //cachtinh = "DonGiaOcoNnMattienDt(Multiply([giadatduong],[giadatnongnghiep]))"; #region khoi tao cac bien SdeConnection conn = new SdeConnection(); ISdeConnectionInfo sdeConn = conn as ISdeConnectionInfo; _wspEdit = (IWorkspaceEdit)sdeConn.Workspace; _mwspEdit = (IMultiuserWorkspaceEdit)sdeConn.Workspace; IFeatureWorkspace fw = (IFeatureWorkspace)sdeConn.Workspace; copyTool = new DataManager(sdeConn.Workspace, sdeConn.Environment); this._fcName = new TnFeatureClassName(sdeConn.Workspace); this._tblName = new TnTableName(sdeConn.Workspace); string tgdDraft = string.Format("{0}_{1}", DataNameTemplate.Thua_Gia_Dat_Draft, this._currentConfig.NamApDung); string gdd = string.Format("{0}_{1}", DataNameTemplate.Gia_Dat_Duong, this._currentConfig.NamApDung); string gdhem = string.Format("{0}_{1}", DataNameTemplate.Gia_Hem, this._currentConfig.NamApDung); string gdhemPhu = string.Format("{0}_{1}", DataNameTemplate.Gia_Hem_Phu, this._currentConfig.NamApDung); string thuaName = string.Format("{0}_{1}", DataNameTemplate.Thua, this._currentConfig.NamApDung); string gdNnName=string.Format("{0}_{1}", DataNameTemplate.Gia_Dat_Nongnghiep, this._currentConfig.NamApDung); string gdPnnNtName = string.Format("{0}_{1}", DataNameTemplate.Gia_Dat_Pnn_Nongthon, this._currentConfig.NamApDung); _fcName.FC_THUA.NAME = thuaName; _fcName.FC_THUA.InitIndex(); _fcName.FC_THUA_GIADAT_DRAFT.NAME = tgdDraft; _fcName.FC_THUA_GIADAT_DRAFT.InitIndex(); _tblName.GIA_DAT_DUONG.NAME = gdd; _tblName.GIA_DAT_DUONG.InitIndex(); _fcName.FC_GIA_DAT_HEM.NAME = gdhem; _fcName.FC_GIA_DAT_HEM.InitIndex(); _fcName.FC_GIA_DAT_HEM_PHU.NAME = gdhemPhu; _fcName.FC_GIA_DAT_HEM_PHU.InitIndex(); _tblName.GIA_DAT_NONGNGHIEP.NAME = gdNnName; _tblName.GIA_DAT_NONGNGHIEP.InitIndex(); _tblName.GIA_DAT_O_NONGTHON.NAME = gdPnnNtName; _tblName.GIA_DAT_O_NONGTHON.InitIndex(); IFeatureClass tgdDraftFeatureClass = null; try { tgdDraftFeatureClass = fw.OpenFeatureClass(tgdDraft); } catch { MessageBox.Show("Không tìm thấy bảng " + tgdDraft); return; } IFeatureClass fcGiaDatHem = null; try { fcGiaDatHem = fw.OpenFeatureClass(gdhem); } catch { MessageBox.Show("Không tìm thấy bảng " + gdhem); } IFeatureClass fcGiaDatHemPhu = null; try { fcGiaDatHemPhu = fw.OpenFeatureClass(gdhemPhu); } catch { MessageBox.Show("Không tìm thấy bảng " + gdhemPhu); } ITable tblLoaiDat; ITable tblThuaGiaDatDraft; ITable tblGiaDatDuong; ITable tblHesoVitri; ITable tblTenDuong; ITable tblGiaDatNn; ITable tblGiaDatPnnNt; IFeatureClass fcThua; IFeatureClass fcXa; IFeatureClass fcDuong; IFeatureClass fcKtvhxh; IFeatureClass fcHemChinh; #endregion #region dinh nghia cac bien try { fcThua = fw.OpenFeatureClass(thuaName); } catch { MessageBox.Show("Không tìm thấy bảng " + thuaName); return; } try { tblTenDuong = fw.OpenTable(DataNameTemplate.Ten_Duong); } catch(Exception ex) { MessageBox.Show("Không tìm thấy bảng " + DataNameTemplate.Ten_Duong); return; } try { tblLoaiDat = fw.OpenTable(DataNameTemplate.Loai_Dat); tblThuaGiaDatDraft = (ITable)tgdDraftFeatureClass; //tblThuaGiaDat = fw.OpenTable(_fcName.FC_THUA_GIADAT.NAME); tblGiaDatDuong = fw.OpenTable(gdd); tblHesoVitri = fw.OpenTable(DataNameTemplate.He_So_K); } catch { MessageBox.Show("Không tìm thấy bảng " + tgdDraft); return; } try { tblGiaDatNn = fw.OpenTable(gdNnName); } catch (Exception ex) { MessageBox.Show("Không tìm thấy bảng " + gdNnName); return; } try { tblGiaDatPnnNt = fw.OpenTable(gdPnnNtName); } catch (Exception ex) { MessageBox.Show("Không tìm thấy bảng " + gdPnnNtName); return; } try { fcXa = fw.OpenFeatureClass(DataNameTemplate.Ranh_Xa_Poly); } catch { MessageBox.Show("Không tìm thấy bảng " + DataNameTemplate.Ranh_Xa_Poly); return; } try { fcHemChinh = fw.OpenFeatureClass(DataNameTemplate.Hem); } catch { MessageBox.Show("Không tìm thấy bảng " + DataNameTemplate.Hem); return; } ISDETableEditor sdeTblTgdEditor = new SDETable(tblThuaGiaDatDraft, sdeConn.Workspace); IQueryFilter qrf = new QueryFilterClass(); #endregion string paramTableName = DataNameTemplate.Thong_So + "_" + _currentConfig.NamApDung; ITable paramTable = fw.OpenTable(paramTableName); Dictionary<string, object> pars4TinhGia = new Dictionary<string, object>(); Dictionary<string, object> pars4TinhDonGia = new Dictionary<string, object>(); IQueryFilter q = new QueryFilterClass(); q.WhereClause = ""; ICursor parCursor = paramTable.Search(q, false); IRow parRow = null; try { while ((parRow = parCursor.NextRow()) != null) { string parName = parRow.get_Value(parRow.Fields.FindField(_tblName.THONG_SO.TEN_THONG_SO)).ToString(); object parVal = parRow.get_Value(parRow.Fields.FindField(_tblName.THONG_SO.GIA_TRI)); try { pars4TinhGia.Add(parName, parVal); pars4TinhDonGia.Add(parName, parVal); } catch (Exception ex) { continue; } } } catch (Exception) { } finally { Marshal.ReleaseComObject(parCursor); } pars4TinhGia.Add(ExpressionParameters.GiaDatDuong, 0); pars4TinhGia.Add(ExpressionParameters.DienTichPl, 0); pars4TinhGia.Add(ExpressionParameters.GiaDatNn,0); pars4TinhGia.Add(ExpressionParameters.GiaDatONT, 0); pars4TinhGia.Add(ExpressionParameters.GiaDatHemChinh, 0); pars4TinhGia.Add(ExpressionParameters.GiaDatHemPhu, 0); pars4TinhDonGia.Add(ExpressionParameters.GiaDatDuong,0); pars4TinhDonGia.Add(ExpressionParameters.GiaDatNn,0); pars4TinhDonGia.Add(ExpressionParameters.GiaDatONT, 0); pars4TinhDonGia.Add(ExpressionParameters.GiaDatHemChinh, 0); pars4TinhDonGia.Add(ExpressionParameters.GiaDatHemPhu, 0); #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(); if (_caller != null) { evt.Reset(); evt.Log = "\n\nBắt đầu tính giá cho các thửa vừa xác định vị trí"; _caller.onCalculating(evt); } int len = newId.Count; int thuaCount = 1; //MessageBox.Show(len.ToString()); #endregion foreach (object o in newId) { #region lay thong tin thua gia dat IRow tgdRowNew = tblThuaGiaDatDraft.GetRow((int)o); string mathuaNew = tgdRowNew.get_Value(tgdRowNew.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.MA_THUA)).ToString(); string maduongNew = tgdRowNew.get_Value(tgdRowNew.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.MA_DUONG)).ToString(); string hesovitriNew = tgdRowNew.get_Value(tgdRowNew.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.HE_SO_K)).ToString(); object dientich = tgdRowNew.get_Value(tgdRowNew.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.DIEN_TICH)); object dientichpl = tgdRowNew.get_Value(tgdRowNew.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.DIEN_TICH_PHAP_LY)); object khoagia = tgdRowNew.get_Value(tgdRowNew.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.LOCKED)); object mahem=tgdRowNew.get_Value(tgdRowNew.Fields.FindField(_fcName.FC_THUA_GIADAT_DRAFT.MA_HEM)); object dorongHem=0; object tenHem = ""; //MessageBox.Show("line 237 CalcLandprice, maduong=" + maduongNew); if (khoagia != null) { if (khoagia.ToString() != "0" && khoagia.ToString()!="") { //MessageBox.Show(khoagia.ToString()); if (_caller != null) { evt.Reset(); evt.IdThuaKhoaGia = o; evt.mathua = mathuaNew; _caller.onCalculating(evt); } continue; } } #endregion #region lay cach tinh qrf.WhereClause = string.Format("{0}='{1}'", "hesovitri", hesovitriNew); ICursor curNew = tblHesoVitri.Search(qrf, false); try { IRow rowNew = curNew.NextRow(); if (rowNew != null) { cachtinh = rowNew.get_Value(_tblName.HESO_VITRI.GetIndex(_tblName.HESO_VITRI.CACH_TINH)).ToString(); cachtinhdongia = rowNew.get_Value(_tblName.HESO_VITRI.GetIndex(_tblName.HESO_VITRI.CACH_TINH_DON_GIA)).ToString(); //MessageBox.Show("line 262 CalcLandprice, cachtinhdongia=" + cachtinhdongia); } } catch (COMException comExc) { } finally { Marshal.ReleaseComObject(curNew); } Evaluation evalTinhGia = new Evaluation(cachtinh); Evaluation evalTinhDonGia = new Evaluation(cachtinhdongia); Evaluation evalCachtinh = new Evaluation(cachtinhdongia); #endregion #region lay gia dat duong //MessageBox.Show("line 365 maduong=" + maduongNew); qrf.WhereClause = string.Format("{0}='{1}'", _tblName.GIA_DAT_DUONG.MA_DUONG, maduongNew); ICursor gdDuongCur = null; gdDuongCur = tblGiaDatDuong.Search(qrf, false); IRow gdDuongRow = null; double giaduong = 0; try { if ((gdDuongRow = gdDuongCur.NextRow()) != null) { result = double.TryParse(gdDuongRow.get_Value(_tblName.GIA_DAT_DUONG.GetIndex(_tblName.GIA_DAT_DUONG.GIA_DAT)).ToString(), out giaduong); if (!result) { giaduong = 0; } //MessageBox.Show("line 292 CalcLandprice, giaduong=" + giaduong.ToString()); } } catch (COMException comExc) { } finally { Marshal.ReleaseComObject(gdDuongCur); } #endregion #region lay ten duong qrf.WhereClause = string.Format("{0}='{1}'", _tblName.TEN_DUONG.MA_DUONG, maduongNew); ICursor tenDuongCur = null; tenDuongCur = tblTenDuong.Search(qrf, false); IRow tenDuongRow = null; object tenduong = ""; object batdau = ""; object ketthuc = ""; try { if ((tenDuongRow = tenDuongCur.NextRow()) != null) { tenduong = tenDuongRow.get_Value(_tblName.TEN_DUONG.GetIndex(_tblName.TEN_DUONG.TEN_DUONG)); batdau = tenDuongRow.get_Value(_tblName.TEN_DUONG.GetIndex(_tblName.TEN_DUONG.BAT_DAU)); ketthuc = tenDuongRow.get_Value(_tblName.TEN_DUONG.GetIndex(_tblName.TEN_DUONG.KET_THUC)); } } catch (COMException comExc) { giaduong = 0; } finally { Marshal.ReleaseComObject(tenDuongCur); } #endregion #region lay loai dat, loai xa qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_THUA.MA_THUA, mathuaNew); IFeatureCursor thuaCur = null; thuaCur = fcThua.Search(qrf, false); IFeature thuaFt = null; object loaidat = ""; object maxa = ""; try { if ((thuaFt = thuaCur.NextFeature()) != null) { loaidat = thuaFt.get_Value(_fcName.FC_THUA.GetIndex(_fcName.FC_THUA.LOAI_DAT)); maxa = thuaFt.get_Value(_fcName.FC_THUA.GetIndex(_fcName.FC_THUA.MA_XA)); } #region kiem tra co dat nong nghiep foreach (string s in TnLoaiDats.NONG_NGHIEP) { if (loaidat.ToString().Contains(s)) { _loaidatNn = s; break; } else { _loaidatNn = ""; } } #endregion } catch (COMException comExc) { } finally { Marshal.ReleaseComObject(thuaCur); } #endregion //danh cho thua co dat nong nghiep #region lay ma xa va gia dat nong nghiep object loaixa = ""; object giadatNnDeGhi = 0; object giadatNnDeTinh = 0; int loaiDoThi = 0; object loaiDatNnDeTinh = ""; string nnStart = hesovitriNew.Substring(0, 1); string nnEnd = hesovitriNew.Substring(hesovitriNew.Length - 1, 1); object giadatPnnNt = 0; double giahem = 0; double giahemPhu = 0; if (nnStart=="5" || nnStart=="2"|| nnStart=="1") { qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_RANH_XA_POLY.MA_XA, maxa); IFeatureCursor xaFcr = fcXa.Search(qrf, false); IFeature xaFt = null; try { if ((xaFt = xaFcr.NextFeature()) != null) { loaixa = xaFt.get_Value(xaFt.Fields.FindField(_fcName.FC_RANH_XA_POLY.MA_LOAI_XA)); result = int.TryParse(xaFt.get_Value(xaFt.Fields.FindField(_fcName.FC_RANH_XA_POLY.MA_LOAI_XA)).ToString(), out loaiDoThi); } } catch (Exception ex) { loaixa = ""; } finally { Marshal.ReleaseComObject(xaFcr); } if (loaixa != "") { #region neu la dat o nong thon if (nnStart == "2") { object vitriPnn; object khuvucPnn; getVitriPnnNt(hesovitriNew, out vitriPnn, out khuvucPnn); qrf.WhereClause = string.Format("{0}='{1}' and {2}='{3}' and {4}='{5}'", _tblName.GIA_DAT_O_NONGTHON.MA_LOAI_XA, loaixa, _tblName.GIA_DAT_O_NONGTHON.VI_TRI, vitriPnn, _tblName.GIA_DAT_O_NONGTHON.MA_KHU_VUC, khuvucPnn); //MessageBox.Show("line 471 CalcLandprice, qrf=" + qrf.WhereClause); ICursor gdPnnCur = tblGiaDatPnnNt.Search(qrf, false); IRow gdPnnRow = null; try { if ((gdPnnRow = gdPnnCur.NextRow()) != null) { giadatPnnNt = gdPnnRow.get_Value(gdPnnRow.Fields.FindField(_tblName.GIA_DAT_O_NONGTHON.GIA_DAT)); } else { giadatPnnNt = 0; } //MessageBox.Show("line 484 CalcLandprice, giadat=" + giadatPnnNt); } catch (Exception ex) { giadatPnnNt = 0; } finally { Marshal.ReleaseComObject(gdPnnCur); } } #endregion #region neu co dat nong nghiep if (nnStart == "5" || (nnStart == "2" && nnEnd == "2") || nnStart == "1") { loaiDatNnDeTinh = _loaidatNn; object vitriNn = getVitriNongNghiep(hesovitriNew); if (loaiDoThi != 0) { vitriNn = 1; loaiDatNnDeTinh = "LNQ"; } qrf.WhereClause = string.Format("{0}='{1}' and {2}='{3}' and {4}='{5}'", _tblName.GIA_DAT_NONGNGHIEP.MA_LOAI_DAT, loaiDatNnDeTinh, _tblName.GIA_DAT_NONGNGHIEP.MA_LOAI_XA, loaixa, _tblName.GIA_DAT_NONGNGHIEP.VI_TRI, vitriNn); ICursor gdNnCur = tblGiaDatNn.Search(qrf, false); IRow gdNnRow = null; try { if ((gdNnRow = gdNnCur.NextRow()) != null) { giadatNnDeGhi = gdNnRow.get_Value(gdNnRow.Fields.FindField(_tblName.GIA_DAT_NONGNGHIEP.GIA_DAT)); } else { giadatNnDeGhi = 0; } } catch (Exception ex) { giadatNnDeGhi = 0; } finally { Marshal.ReleaseComObject(gdNnCur); } //MessageBox.Show(string.Format("line 331 CalcLandprice giadatnndegi={0}", giadatNnDeGhi)); //neu ko phai dat thuan nong nghiep if (nnStart != "1") { if (double.Parse(dientichpl.ToString()) < 200) { giadatNnDeTinh = 0; } else { giadatNnDeTinh = giadatNnDeGhi; } } else { giadatNnDeTinh = giadatNnDeGhi; } } #endregion } //lay gia dat nn o vi tri theo quy dinh (vt3) //qrf.WhereClause=string.Format("{0}='{1}' and {2}='{3}'",_tblName.GIA_DAT_NONGNGHIEP.MA_LOAI_DAT,_loaidatNn,_tblName.GIA_DAT_NONGNGHIEP.MA_LOAI_XA,) } #endregion if (mahem != null) { #region lay thong tin hem //MessageBox.Show("line 567 CalcLandprice, mahem=" + mahem); if (mahem.ToString() != "0" && mahem.ToString() != "") { qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_HEM.MA_HEM, mahem); IFeatureCursor hemFcur = fcHemChinh.Search(qrf, false); IFeature hemFt = null; int maHemChinh = 0; try { if ((hemFt = hemFcur.NextFeature()) != null) { dorongHem = hemFt.get_Value(hemFt.Fields.FindField(_fcName.FC_HEM.DO_RONG)); tenHem = hemFt.get_Value(hemFt.Fields.FindField(_fcName.FC_HEM.TEN_HEM)); maduongNew = hemFt.get_Value(hemFt.Fields.FindField(_fcName.FC_HEM.MA_DUONG)).ToString(); result = int.TryParse(hemFt.get_Value(hemFt.Fields.FindField(_fcName.FC_HEM.HEM_CHINH)).ToString(), out maHemChinh); if (!result) { maHemChinh = 0; } //MessageBox.Show("line 586 CalcLandprice,mahemchinh=" + maHemChinh); } } catch (Exception ex) { //MessageBox.Show("line 566 CalcLandprice, ex=" + ex.ToString()); } finally { Marshal.ReleaseComObject(hemFcur); } #region lay gia dat hem chinh string hsvitriHem = getHesoHem(hesovitriNew); //MessageBox.Show("line 597 hsvitrihem=" + hsvitriHem); if (hsvitriHem == "0") { continue; } if (maHemChinh == 0) { qrf.WhereClause = string.Format("{0}='{1}' and {2}='{3}'", _fcName.FC_GIA_DAT_HEM.MA_HEM, mahem, _fcName.FC_GIA_DAT_HEM.HE_SO, hsvitriHem); //MessageBox.Show("line 603 CalcLandprice, qrf=" + qrf.WhereClause); IFeatureCursor gdHemCur = null; gdHemCur = fcGiaDatHem.Search(qrf, false); IFeature gdHemRow = null; //MessageBox.Show("line 588 CalcLandprice, giaHem=" + _fcName.FC_GIA_DAT_HEM.GetIndex(_fcName.FC_GIA_DAT_HEM.GIA_DAT)); try { if ((gdHemRow = gdHemCur.NextFeature()) != null) { result = double.TryParse(gdHemRow.get_Value(_fcName.FC_GIA_DAT_HEM.GetIndex(_fcName.FC_GIA_DAT_HEM.GIA_DAT)).ToString(), out giahem); if (!result) { giahem = 0; } //MessageBox.Show("line 588 CalcLandprice, giaHem=" + giahem.ToString()); } } catch (COMException comExc) { //MessageBox.Show("line 593 CalcLandprice comexc=" + comExc.ToString()); } finally { Marshal.ReleaseComObject(gdHemCur); } } #endregion #region lay gia hem phu else { qrf.WhereClause = string.Format("{0}='{1}' and {2}='{3}'", _fcName.FC_GIA_DAT_HEM_PHU.MA_HEM, mahem, _fcName.FC_GIA_DAT_HEM_PHU.HE_SO, hsvitriHem); //MessageBox.Show("line 632 CalcLandprice, qrf=" + qrf.WhereClause); IFeatureCursor gdHemPhuCur = null; gdHemPhuCur = fcGiaDatHemPhu.Search(qrf, false); IFeature gdHemPhuRow = null; //MessageBox.Show("line 588 CalcLandprice, giaHem=" + _fcName.FC_GIA_DAT_HEM.GetIndex(_fcName.FC_GIA_DAT_HEM.GIA_DAT)); try { if ((gdHemPhuRow = gdHemPhuCur.NextFeature()) != null) { result = double.TryParse(gdHemPhuRow.get_Value(_fcName.FC_GIA_DAT_HEM_PHU.GetIndex(_fcName.FC_GIA_DAT_HEM_PHU.GIA_DAT)).ToString(), out giahemPhu); if (!result) { giahemPhu = 0; } //MessageBox.Show("line 646 CalcLandprice, giaHemPhu=" + giahemPhu.ToString()); } } catch (COMException comExc) { //MessageBox.Show("line 593 CalcLandprice comexc=" + comExc.ToString()); } finally { Marshal.ReleaseComObject(gdHemPhuCur); } } #endregion #region lay gia duong tu lop gia hem qrf.WhereClause = string.Format("{0}='{1}'", _tblName.GIA_DAT_DUONG.MA_DUONG, maduongNew); gdDuongCur = null; gdDuongCur = tblGiaDatDuong.Search(qrf, false); gdDuongRow = null; giaduong = 0; try { if ((gdDuongRow = gdDuongCur.NextRow()) != null) { result = double.TryParse(gdDuongRow.get_Value(_tblName.GIA_DAT_DUONG.GetIndex(_tblName.GIA_DAT_DUONG.GIA_DAT)).ToString(), out giaduong); if (!result) { giaduong = 0; } //MessageBox.Show("line 292 CalcLandprice, giaduong=" + giaduong.ToString()); } } catch (COMException comExc) { } finally { Marshal.ReleaseComObject(gdDuongCur); } #endregion } #endregion } //MessageBox.Show(string.Format("line 346 CalcLandprice giadatnndegi={0}, giadatnndetinh={1}", giadatNnDeGhi, giadatNnDeTinh)); #region lay gia dat o nong thon int intHsk = int.Parse(hesovitriNew); #endregion #region tinh gia //evalTinhGia.Giadatduong = giaduong; //evalTinhGia.Dientich = dientich; //evalTinhGia.Dientichpl = dientichpl; //evalTinhGia.GiadatNn = giadatNnDeTinh; //evalTinhDonGia.Giadatduong = giaduong; //evalTinhDonGia.GiadatNn = giadatNnDeTinh; //Dictionary<string, object> pars = new Dictionary<string, object>(); //MessageBox.Show("line 609 CalcLandprice, giaHem=" + giahem.ToString()); pars4TinhGia[ExpressionParameters.GiaDatDuong] = giaduong; pars4TinhGia[ExpressionParameters.DienTichPl] = dientichpl; pars4TinhGia[ExpressionParameters.GiaDatNn] = giadatNnDeTinh; pars4TinhGia[ExpressionParameters.GiaDatONT] = giadatPnnNt; pars4TinhGia[ExpressionParameters.GiaDatHemChinh] = giahem; pars4TinhGia[ExpressionParameters.GiaDatHemPhu] = giahemPhu; //pars.Add(ExpressionParameters.HeSoDatSxkd, _currentConfig.PGiaDatSxkddt); evalTinhGia.Params = pars4TinhGia; //Dictionary<string, object> pars1 = new Dictionary<string, object>(); //pars1.Add(ExpressionParameters.GiaDatDuong, giaduong); //pars1.Add(ExpressionParameters.GiaDatNn, giadatNnDeTinh); //pars1.Add(ExpressionParameters.HeSoDatSxkd, _currentConfig.PGiaDatSxkddt); pars4TinhDonGia[ExpressionParameters.GiaDatDuong] = giaduong; pars4TinhDonGia[ExpressionParameters.DienTichPl] = dientichpl; pars4TinhDonGia[ExpressionParameters.GiaDatNn] = giadatNnDeTinh; pars4TinhDonGia[ExpressionParameters.GiaDatONT] = giadatPnnNt; pars4TinhDonGia[ExpressionParameters.GiaDatHemChinh] = giahem; pars4TinhDonGia[ExpressionParameters.GiaDatHemPhu] = giahemPhu; evalTinhDonGia.Params = pars4TinhDonGia; object giaMoiTinh = evalTinhGia.EvaluateLandPrice(); object dongiaMoiTinh = evalTinhDonGia.EvaluateLandPrice(); //MessageBox.Show(string.Format("line 660 CalcLandprice dongia={0}", dongiaMoiTinh)); #endregion #region ghi cach tinh _methodBuilder.BatDau = batdau; _methodBuilder.CachTinh = cachtinh; _methodBuilder.CachTinhDonGia = cachtinhdongia; _methodBuilder.GiaDatNN = giadatNnDeGhi; _methodBuilder.GiaDuong = giaduong; _methodBuilder.KetThuc = ketthuc; _methodBuilder.LoaiDat = loaidat; _methodBuilder.TenDuong = tenduong; _methodBuilder.DoRongHem = dorongHem; _methodBuilder.LoaiXa = loaixa; string strCachtinh=_methodBuilder.GetMethodString(hesovitriNew); //evt.Reset(); //evt.Log = string.Format("\n\nĐộ dài cách tính:{0}, cachtinh={1}",strCachtinh.Length,strCachtinh); //_caller.onCalculating(evt); //MessageBox.Show(string.Format("line 241 CalcLandprice {0}, {1}",hesovitriNew,TnHeSoK.DatOMatTienDt)); //if (hesovitriNew == TnHeSoK.DatOMatTienDt.ToString()) //{ // strCachtinh = string.Format("Đất ở đô thị ({0}), mặt tiền đường {1} (giá={2}) đoạn từ {3} đến {4}. Giá đất = {5}", loaidat, tenduong, giaduong, batdau, ketthuc, cachtinhdongia); // //MessageBox.Show(string.Format("line 241 CalcLandprice \n{0}", strCachtinh)); //} //else if (hesovitriNew == TnHeSoK.DatSxkdMatTienDt.ToString()) //{ // strCachtinh = string.Format("Đất sxkd tại đô thị ({0}) (hệ số ={1}), mặt tiền đường {2} (giá={3}) đoạn từ {4} đến {5}. Giá đất = {6}", loaidat, _currentConfig.PGiaDatSxkddt, tenduong,giaduong, batdau, ketthuc, cachtinhdongia); //} //else if (hesovitriNew == TnHeSoK.DatONnMatTien.ToString()) //{ // strCachtinh = string.Format("Đất ở tại đô thị có đất nông nghiệp ({0}) (giá đất nn ={1}), mặt tiền đường {2} (giá={3}) đoạn từ {4} đến {5}. Giá đất = {6}", loaidat, giadatNnDeGhi, tenduong, giaduong, batdau, ketthuc, cachtinhdongia); //} #endregion #region lay cach ghi cach tinh gia //string ct = string.Format(cachtinh); //MessageBox.Show(evalCachtinh.EvaluateMethod().ToString()); #endregion #region luu thong tin gia va cach tinh pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.DON_GIA), dongiaMoiTinh } }); pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.GIA_DAT), giaMoiTinh } }); pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.CACH_TINH), strCachtinh } }); sdeTblTgdEditor.CacheData(o, rowTgdNnHandleUpdate, pairColValTgd, EnumTypeOfEdit.UPDATE); rowTgdNnHandleUpdate++; pairColValTgd.Clear(); #endregion #region ---log if (_caller != null) { evt.Reset(); evt.IdThuaTinhGia = o;// new object[,] { { o, "tui", "soto", "sothua" } }; evt.mathua = mathuaNew; _caller.onCalculating(evt); evt.Reset(); if (thuaCount < len) { if (thuaCount % 10 == 0) { evt.Log = string.Format("\n---Đã tính cho {0} thửa----", thuaCount); } thuaCount++; } else if (thuaCount == len) { evt.Log = string.Format("\n---Đã tính cho {0} thửa---", thuaCount); } _caller.onCalculating(evt); } #endregion } #endregion #region luu thong tin vao bang gia dat if (!sdeTblTgdEditor.IsEditing()) { sdeTblTgdEditor.StartEditing(esriMultiuserEditSessionMode.esriMESMVersioned); sdeTblTgdEditor.StartEditOperation(); } //else //{ // //try // //{ // // sdeTblTgdEditor.SaveEdit(); // // sdeTblTgdEditor.StopEditOperation(); // // sdeTblTgdEditor.StopEditing(true); // //} // //catch // //{ // // sdeTblTgdEditor.StopEditOperation(); // // sdeTblTgdEditor.StopEditing(false); // //} // //sdeTblTgdEditor.StartEditing(esriMultiuserEditSessionMode.esriMESMVersioned); // //sdeTblTgdEditor.StartEditOperation(); //} #region ----log if (_caller != null) { evt.Log = string.Format("\n----||| Đang lưu bảng {0} |||---- ", tgdDraft); _caller.onCalculating(evt); } #endregion try { sdeTblTgdEditor.SaveEdit(); sdeTblTgdEditor.StopEditOperation(); sdeTblTgdEditor.StopEditing(true); } catch (Exception ex) { sdeTblTgdEditor.StopEditOperation(); sdeTblTgdEditor.StopEditing(false); } #region ----log if (_caller != null) { evt.Log = string.Format("\n----||| Đã lưu bảng {0} |||---- ", tgdDraft); _caller.onCalculating(evt); } #endregion #endregion #region loc gia dat ThreadStart filterThread =()=>fil(newId); Thread t = new Thread(filterThread); t.Start(); //while (!t.IsAlive) ; //Thread.Sleep(1); //t.Abort(); t.Join(); #endregion #endregion }
public void CalcGiaHemPhu(List<object> newId) { #region khoi tao cac bien SdeConnection conn = new SdeConnection(); ISdeConnectionInfo sdeConn = conn as ISdeConnectionInfo; _wspEdit = (IWorkspaceEdit)sdeConn.Workspace; _mwspEdit = (IMultiuserWorkspaceEdit)sdeConn.Workspace; IFeatureWorkspace fw = (IFeatureWorkspace)sdeConn.Workspace; copyTool = new DataManager(sdeConn.Workspace, sdeConn.Environment); this._fcName = new TnFeatureClassName(sdeConn.Workspace); this._tblName = new TnTableName(sdeConn.Workspace); string gdHemPhu = string.Format("{0}_{1}", DataNameTemplate.Gia_Hem_Phu, this._currentConfig.NamApDung); string gdHemChinh = string.Format("{0}_{1}", DataNameTemplate.Gia_Hem, this._currentConfig.NamApDung); _fcName.FC_GIA_DAT_HEM_PHU.NAME = gdHemPhu; _fcName.FC_GIA_DAT_HEM_PHU.InitIndex(); _fcName.FC_GIA_DAT_HEM.NAME = gdHemChinh; _fcName.FC_GIA_DAT_HEM.InitIndex(); IFeatureClass gdhPhuFeatureClass = null; ITable tblgdHemPhu = null; try { gdhPhuFeatureClass = fw.OpenFeatureClass(gdHemPhu); tblgdHemPhu = (ITable)gdhPhuFeatureClass; } catch { MessageBox.Show("Không tìm thấy bảng " + gdHemPhu); return; } IFeatureClass gdhChinhFeatureClass; ITable tblHesoVitri; ITable tblTenDuong; ITable tblHemChinh; #endregion #region dinh nghia cac bien try { tblTenDuong = fw.OpenTable(DataNameTemplate.Ten_Duong); } catch (Exception ex) { MessageBox.Show("Không tìm thấy bảng " + DataNameTemplate.Ten_Duong); return; } try { gdhChinhFeatureClass = fw.OpenFeatureClass(gdHemChinh); } catch (Exception ex) { MessageBox.Show("Không tìm thấy bảng " + gdHemChinh); return; } try { tblHemChinh = fw.OpenTable(DataNameTemplate.Hem); } catch (Exception ex) { MessageBox.Show("Không tìm thấy bảng " + DataNameTemplate.Hem); return; } ISDETableEditor sdeTblGdhEditor = new SDETable(tblgdHemPhu, sdeConn.Workspace); IQueryFilter qrf = new QueryFilterClass(); #endregion #region vong lap tung id #region khoi dau int rowGdhHandleUpdate = 0; string cachtinh = ""; string cachtinhdongia = ""; bool result = false; List<object[,]> pairColValTgd = new List<object[,]>(); CalculationEventArg evt = new CalculationEventArg(); if (_caller != null) { evt.Reset(); evt.Log = "\n\nBắt đầu tính giá cho các hẻm vừa xác định vị trí"; _caller.onCalculating(evt); } int len = newId.Count; int thuaCount = 1; //MessageBox.Show(len.ToString()); #endregion foreach (object o in newId) { if (!((int)o > 0)) { //MessageBox.Show("line 737 CalcLandprice: không thể tính cho hẻm có id=" + o); continue; } #region lay thong tin hem gia dat IRow gdhRowNew = null; try { gdhRowNew = tblgdHemPhu.GetRow((int)o); } catch (Exception ex) { } if (gdhRowNew == null) { continue; } string maHemChinhNew = gdhRowNew.get_Value(gdhRowNew.Fields.FindField(_fcName.FC_GIA_DAT_HEM_PHU.MA_HEM_CHINH)).ToString(); int hesovitriNew; result = int.TryParse(gdhRowNew.get_Value(gdhRowNew.Fields.FindField(_fcName.FC_GIA_DAT_HEM_PHU.HE_SO)).ToString(), out hesovitriNew); object khoagia = gdhRowNew.get_Value(gdhRowNew.Fields.FindField(_fcName.FC_GIA_DAT_HEM_PHU.LOCKED)); object mahem = gdhRowNew.get_Value(gdhRowNew.Fields.FindField(_fcName.FC_GIA_DAT_HEM_PHU.MA_HEM)); int dorongHem = 0; object tenHem = ""; //MessageBox.Show("line 237 CalcLandprice, maduong=" + maduongNew); if (khoagia != null) { if (khoagia.ToString() != "0" && khoagia.ToString() != "") { //MessageBox.Show(khoagia.ToString()); //evt.Reset(); //evt.IdThuaKhoaGia = o; //evt.mathua = mahem; //_caller.onCalculating(evt); continue; } } #endregion #region lay gia dat hem chinh qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_GIA_DAT_HEM.MA_HEM, maHemChinhNew); IFeatureCursor gdHemChinhCur = null; gdHemChinhCur = gdhChinhFeatureClass.Search(qrf, false); IFeature gdHemChinhRow = null; double giaHemChinh = 0; object maduong = 0; try { if ((gdHemChinhRow = gdHemChinhCur.NextFeature()) != null) { result = double.TryParse(gdHemChinhRow.get_Value(_fcName.FC_GIA_DAT_HEM.GetIndex(_fcName.FC_GIA_DAT_HEM.GIA_DAT)).ToString(), out giaHemChinh); if (!result) { giaHemChinh = 0; } maduong=gdHemChinhRow.get_Value(_fcName.FC_GIA_DAT_HEM.GetIndex(_fcName.FC_GIA_DAT_HEM.MA_DUONG)); //MessageBox.Show("line 1259 CalcLandprice, giahemchinh=" + giaHemChinh.ToString()); } } catch (COMException comExc) { } finally { Marshal.ReleaseComObject(gdHemChinhCur); } #endregion if (mahem != null) { #region lay thong tin hem if (mahem.ToString() != "0" && mahem.ToString() != "") { qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_HEM.MA_HEM, mahem); ICursor hemFcur = tblHemChinh.Search(qrf, false); IRow hemRow = null; try { if ((hemRow = hemFcur.NextRow()) != null) { object dorong = hemRow.get_Value(hemRow.Fields.FindField(_fcName.FC_HEM.DO_RONG)); result = int.TryParse(dorong.ToString(), out dorongHem); if (!result) { dorongHem = 0; } tenHem = hemRow.get_Value(hemRow.Fields.FindField(_fcName.FC_HEM.TEN_HEM)); } } catch (Exception ex) { } finally { Marshal.ReleaseComObject(hemFcur); } } #endregion } #region lay ten duong qrf.WhereClause = string.Format("{0}='{1}'", _tblName.TEN_DUONG.MA_DUONG, maduong); ICursor tenDuongCur = null; tenDuongCur = tblTenDuong.Search(qrf, false); IRow tenDuongRow = null; object tenduong = ""; object batdau = ""; object ketthuc = ""; try { if ((tenDuongRow = tenDuongCur.NextRow()) != null) { tenduong = tenDuongRow.get_Value(_tblName.TEN_DUONG.GetIndex(_tblName.TEN_DUONG.TEN_DUONG)); batdau = tenDuongRow.get_Value(_tblName.TEN_DUONG.GetIndex(_tblName.TEN_DUONG.BAT_DAU)); ketthuc = tenDuongRow.get_Value(_tblName.TEN_DUONG.GetIndex(_tblName.TEN_DUONG.KET_THUC)); } } catch (COMException comExc) { giaHemChinh = 0; } finally { Marshal.ReleaseComObject(tenDuongCur); } #endregion object giaMoiTinh = 0; double hesorong = 1; double hesosau = 1; #region chon chieu rong if (dorongHem < 3.5) { hesorong = _currentConfig.PHemChinhRongDuoi3_5m; } else if (dorongHem < 6) { hesorong = _currentConfig.PHemChinhRongTren3_5m; } else { hesorong = _currentConfig.PHemChinhRongTren6m; } #endregion #region chon chieu sau if (hesovitriNew == 1) //chieu sau <100m { hesosau = _currentConfig.PHemSauDuoi100m; } else if (hesovitriNew == 2) { hesosau = _currentConfig.PHemSauDuoi200m; } else { hesosau = _currentConfig.PHemSauTren200m; } #endregion giaMoiTinh = giaHemChinh * hesorong * hesosau; //MessageBox.Show("line 868 CalcLandprice giamoitinh=" + giaMoiTinh); pairColValTgd.Add(new object[,] { { _fcName.FC_GIA_DAT_HEM_PHU.GetIndex(_fcName.FC_GIA_DAT_HEM_PHU.GIA_DAT), giaMoiTinh } }); sdeTblGdhEditor.CacheData(o, 0, pairColValTgd, EnumTypeOfEdit.UPDATE); pairColValTgd.Clear(); } #endregion #region luu thong tin vao bang gia dat if (!sdeTblGdhEditor.IsEditing()) { sdeTblGdhEditor.StartEditing(true); sdeTblGdhEditor.StartEditOperation(); } else { try { sdeTblGdhEditor.SaveEdit(); sdeTblGdhEditor.StopEditOperation(); sdeTblGdhEditor.StopEditing(true); } catch { sdeTblGdhEditor.StopEditOperation(); sdeTblGdhEditor.StopEditing(false); } sdeTblGdhEditor.StartEditing(esriMultiuserEditSessionMode.esriMESMVersioned); sdeTblGdhEditor.StartEditOperation(); } #region ----log if (_caller != null) { evt.Log = string.Format("\n----||| Đang lưu vị trí các thửa vào bảng {0} |||---- ", gdHemPhu); _caller.onCalculating(evt); } #endregion try { sdeTblGdhEditor.SaveEdit(); sdeTblGdhEditor.StopEditOperation(); sdeTblGdhEditor.StopEditing(true); } catch (Exception ex) { MessageBox.Show("line 1405 CalcGiaHemChinh ex=" + ex.ToString()); sdeTblGdhEditor.StopEditOperation(); sdeTblGdhEditor.StopEditing(false); } #region ----log if (_caller != null) { evt.Log = string.Format("\n----||| Đã lưu vị trí các thửa vào bảng {0} |||---- ", gdHemPhu); _caller.onCalculating(evt); } #endregion #endregion }
private void getMaxValueWithDistinctKey(List<landpriceInfo> source,out List<landpriceInfo> output) { CalculationEventArg evt = new CalculationEventArg(); List<landpriceInfo> resultList = source; int len = source.Count; if (len == 0) { output = null; return; } else if(len!=1) { object id1 = 0; object hesok1 = 0; double dongia1 = 0; object id2 = 0; object hesok2 = 0; double dongia2 = 0; int decLen=0; int afterLen=len; for (int i = 0; i < len-decLen; i++) { hesok1 = source[i].Hesok; dongia1 = source[i].Dongia; afterLen=source.Count; for (int j = 0; j < afterLen; j++) { hesok2 = source[j].Hesok; dongia2 = source[j].Dongia; if (string.Compare(hesok1.ToString(), hesok2.ToString()) == 0) { if (dongia1 >= dongia2) { if (j != i) { resultList.RemoveAt(j); if (_caller != null) { evt.Reset(); evt.Log = string.Format("\n\n Bỏ vùng giá có id={0}, đơn giá={1}--i={2},j={3}", resultList[j].Id, dongia2, i, j); _caller.onCalculating(evt); } } decLen++; continue; } else if (dongia1 < dongia2) { if (_caller != null) { evt.Reset(); evt.Log = string.Format("\n\n Bỏ vùng giá có id={0}, đơn giá={1}--i={2},j={3}", resultList[j].Id, dongia1, i, j); _caller.onCalculating(evt); } resultList.RemoveAt(i); decLen++; break; } } } } } output = resultList; }
public void FilterPrice(List<object> newId) { #region chon loc gia dat #region khoi tao cac bien SdeConnection conn = new SdeConnection(); ISdeConnectionInfo sdeConn = conn as ISdeConnectionInfo; IFeatureWorkspace fw = (IFeatureWorkspace)sdeConn.Workspace; this._fcName = new TnFeatureClassName(sdeConn.Workspace); this._tblName = new TnTableName(sdeConn.Workspace); string tgd = string.Format("{0}_{1}", DataNameTemplate.Thua_Gia_Dat, this._currentConfig.NamApDung); string tgdDraft = string.Format("{0}_{1}", DataNameTemplate.Thua_Gia_Dat_Draft, this._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); 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(); if (_caller != null) { 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 (_caller != null) { 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; 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; } info.Add(new landpriceInfo(id, hesok, dongia)); //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; if (_caller != null) { 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 656 CalcLandprice, source={0}",info.Count)); 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); //MessageBox.Show("line 716, qrf=" + qrf); IFeatureCursor tgdFcur = tgdFeatureClass.Search(qrf, false); IFeature tgdFt = null; List<object> publicIds = new List<object>(); 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) { publicIds.Add(tgdFt.OID); //continue; } else { //[kodoi] //=================== #region xoa feature cu try { _mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); _wspEdit.StartEditOperation(); //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); } catch(Exception ex) { MessageBox.Show(string.Format("CalcLandprice, xoa feature line 751-\n{0}", ex)); _wspEdit.StopEditOperation(); _wspEdit.StopEditing(false); } #endregion //=================== //[thaydoi] - them gia tri //********************** #region them feature moi object copiedId = null; try { _mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); _wspEdit.StartEditOperation(); copiedId = copyTool.CopyWithAllAttribute(tgdDraftFt, tgdFeatureClass); //MessageBox.Show(string.Format("line 743 CalcLandprice, oid={0}", copiedId)); _wspEdit.StopEditOperation(); _wspEdit.StopEditing(true); } catch (Exception ex) { MessageBox.Show(string.Format("CalcLandprice, them feature line 776-\n{0}", 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(); if (copiedId != null) { publicIds.Add(copiedId); } #endregion //********************** } #endregion } else { #region them feature moi object copiedId = null; try { _mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); _wspEdit.StartEditOperation(); copiedId = copyTool.CopyWithAllAttribute(tgdDraftFt, tgdFeatureClass); //MessageBox.Show(string.Format("line 743 CalcLandprice, oid={0}", copiedId)); _wspEdit.StopEditOperation(); _wspEdit.StopEditing(true); } catch (Exception ex) { MessageBox.Show(string.Format("CalcLandprice, them feature line 818-\n{0}", ex)); _wspEdit.StopEditOperation(); _wspEdit.StopEditing(false); } if (copiedId != null) { publicIds.Add(copiedId); } #endregion } } catch (Exception e1) { MessageBox.Show(string.Format("CalcLandprice, line 1842-\n{0}", e1)); } finally { Marshal.ReleaseComObject(tgdFcur); } } #endregion } catch (Exception ex) { continue; } finally { Marshal.ReleaseComObject(tgdDraftCur); } #endregion } #endregion #endregion }
protected override void calculate() { //base.calculate(); #region khoi dau base.calculate(); CalculationEventArg evt = new CalculationEventArg(); //evt.Type = EnumTypeOfLoopCalculation.InListCalculators; evt.CurrentIndexCalculator = this._index; evt.Log = string.Format("********** Bắt đầu tính cho thửa phi nông nghiệp ở vị trí {0} tại đô thị ********", vitri); onCalculating(evt); #endregion //[thaydoi] - them cac khai bao can thiet //************************************ #region khai bao cac bien //Lay connection info hien tai SdeConnection conn = new SdeConnection(); ISdeConnectionInfo sdeConn = conn as ISdeConnectionInfo; IWorkspaceEdit wspEdit = (IWorkspaceEdit)sdeConn.Workspace; IMultiuserWorkspaceEdit mwspEdit=(IMultiuserWorkspaceEdit)sdeConn.Workspace; this._fcName = new TnFeatureClassName(sdeConn.Workspace); this._tblName = new TnTableName(sdeConn.Workspace); IFeatureWorkspace fw = (IFeatureWorkspace)sdeConn.Workspace; ICopyFeatures copyTool = new DataManager(); #region thua string thuaName = string.Format("{0}_{1}", DataNameTemplate.Thua, this._currentConfig.NamApDung); _fcName.FC_THUA.NAME = thuaName; _fcName.FC_THUA.InitIndex(); IFeatureClass thuaFeatureClass = fw.OpenFeatureClass(thuaName); IFeatureLayer thuaFeatureLayer = new FeatureLayerClass(); thuaFeatureLayer.FeatureClass = thuaFeatureClass; IFeatureSelection thuaFeatureSelection; #endregion #region xa IFeatureClass xaFeatureClass = fw.OpenFeatureClass(DataNameTemplate.Ranh_Xa_Poly); IFeatureLayer xaFeatureLayer = new FeatureLayerClass(); xaFeatureLayer.FeatureClass = xaFeatureClass; IFeatureSelection xaFeatureSelection; #endregion #region duong IFeatureClass duongFeatureClass = fw.OpenFeatureClass(DataNameTemplate.Duong); IFeatureLayer duongFeatureLayer = new FeatureLayerClass(); duongFeatureLayer.FeatureClass = duongFeatureClass; IFeatureSelection duongFeatureSelection; //_fcName.FC_DUONG.InitIndex(); #endregion #region thua gia dat string tgd = string.Format("{0}_{1}", DataNameTemplate.Thua_Gia_Dat_Draft, this._currentConfig.NamApDung); _fcName.FC_THUA_GIADAT_DRAFT.NAME = tgd; _fcName.FC_THUA_GIADAT_DRAFT.InitIndex(); //_fcName.FC_THUA_GIADAT_DRAFT_.NAME = tgd; //_fcName.FC_THUA_GIADAT_DRAFT.InitIndex(); IFeatureClass tgdFeatureClass = null; try { tgdFeatureClass = fw.OpenFeatureClass(tgd); } catch (Exception exc) { evt.Log = string.Format("Không tìm thấy lớp dữ liệu: {0}", tgd); onCalculating(evt); onFinished(evt); return; } //ITable tblThuaGiaDat = (ITable)tgdFeatureClass; IFeatureLayer tgdFeatureLayer = new FeatureLayerClass(); ISDETableEditor sdeTblTgdEditor = new SDETable((ITable)tgdFeatureClass, sdeConn.Workspace); #endregion #region gia dat duong string gdd = string.Format("{0}_{1}", DataNameTemplate.Gia_Dat_Duong, this._currentConfig.NamApDung); _tblName.GIA_DAT_DUONG.NAME = gdd; _tblName.GIA_DAT_DUONG.InitIndex(); #endregion #region ten duong ITable tblTenDuong; try { tblTenDuong = fw.OpenTable(DataNameTemplate.Ten_Duong); } catch (Exception exc) { evt.Log = string.Format("Không tìm thấy lớp dữ liệu: {0}", DataNameTemplate.Ten_Duong); onCalculating(evt); onFinished(evt); return; } #endregion #region loai dat ITable tblLoaiDat; try { tblLoaiDat = fw.OpenTable(DataNameTemplate.Loai_Dat); } catch (Exception exc) { evt.Log = string.Format("Không tìm thấy lớp dữ liệu: {0}", DataNameTemplate.Loai_Dat); onCalculating(evt); onFinished(evt); return; } #endregion #region he so vi tri ITable tblHesoVitri; try { tblHesoVitri = fw.OpenTable(DataNameTemplate.He_So_K); } catch (Exception exc) { evt.Log = string.Format("Không tìm thấy lớp dữ liệu: {0}", DataNameTemplate.He_So_K); onCalculating(evt); onFinished(evt); return; } #endregion #region khac IQueryFilter qrf = new QueryFilterClass(); bool result = false; int sothuatimthay = 0; int sothuatinhduoc = 0; int sothuaKhongTinhDuoc = 0; _dataManager = new DataManager(sdeConn.Workspace, sdeConn.Environment); _version = SdeVersionsTool.CallMe(); _eraseTool = new GExtractTool(sdeConn.Environment); string duongBuffer50mNoSde = FilterSdeLayerName.GetActualName(DataNameTemplate.Duong_Buffer_); duongBuffer50mNoSde += _currentConfig.DKhoangCach50mMatTien; string thuaClip50mNoSde=FilterSdeLayerName.GetActualName(DataNameTemplate.Thua_Erase_); thuaClip50mNoSde += _currentConfig.DKhoangCach50mMatTien; string duongBuffer50mCoSde = string.Format("{0}{1}", DataNameTemplate.Duong_Buffer_, _currentConfig.DKhoangCach50mMatTien); string thuaClip50mCoSde = string.Format("{0}{1}", DataNameTemplate.Thua_Erase_, _currentConfig.DKhoangCach50mMatTien); #endregion #endregion //************************************ //******************************************* //=========================================== //=========================================== #region bat dau tinh _bufferTool = new GProximityTool(sdeConn.Environment); if (!_dataManager.LayerExist(duongBuffer50mNoSde)) { _bufferTool.BufferInsideSde(duongFeatureClass.AliasName, duongBuffer50mNoSde, _currentConfig.DKhoangCach50mMatTien); } IFeatureClass duongBuff50FeatureClass = fw.OpenFeatureClass(duongBuffer50mNoSde); IFeatureLayer duongBuff50FeatureLayer = new FeatureLayerClass(); ISelectionSet duongBuff50Sls; IFeatureSelection duongBuff50Fsls; duongBuff50FeatureLayer.FeatureClass = duongBuff50FeatureClass; #region test //string ex = string.Format("VongLap(ChonDuong('dorong=10'),VongLap(ChonThua('dientich<1.5'),test([doituonglap]),[doituonglap]))"); ////ex=string.Format("VongLap(DuongDangChon(),VongLap() //Evaluation evalu = new Evaluation(ex); //evalu.DuongLayer = duongFeatureLayer; //evalu.ThuaLayer = thuaFeatureLayer; //evalu.EvaluateCalculating(); //return; #endregion //[thaydoi] - cac may tinh khac chi can thay dieu kien truy van he so vi tri //****************************************************************** #region lay cac quy tac tim vi tri #region log--- evt.Log = string.Format("\n----Lấy các quy tắc tìm vị trí thửa từ bảng {0}, ứng với hệ số {1} ...", DataNameTemplate.He_So_K, TnHeSoK.DatOSauMatTien50mDt); onCalculating(evt); #endregion qrf.WhereClause = string.Format("{0}='{1}'", "hesovitri", TnHeSoK.DatOSauMatTien50mDt); ICursor cur = tblHesoVitri.Search(qrf, false); string quytac = ""; string cachtinh = ""; string cachtinhdongia = ""; try { IRow row = cur.NextRow(); if (row != null) { quytac = row.get_Value(_tblName.HESO_VITRI.GetIndex(_tblName.HESO_VITRI.QUY_TAC)).ToString(); cachtinh = row.get_Value(_tblName.HESO_VITRI.GetIndex(_tblName.HESO_VITRI.CACH_TINH)).ToString(); cachtinhdongia = row.get_Value(_tblName.HESO_VITRI.GetIndex(_tblName.HESO_VITRI.CACH_TINH_DON_GIA)).ToString(); } } catch { } finally { Marshal.ReleaseComObject(cur); } #endregion #region tinh theo xa if (this._inputParams.MA_XA != "-1") { //[kodoi] //======================= #region chon xa co ma dang xet //neu dang tinh cho 1 xa if (_inputParams.MA_XA != "*") { qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_RANH_XA_POLY.MA_XA, _inputParams.MA_XA); } else//neu dang tinh cho toan huyen { qrf.WhereClause = ""; } ISelectionSet xaSelectionSet = xaFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); xaFeatureSelection = (IFeatureSelection)xaFeatureLayer; xaFeatureSelection.SelectionSet = xaSelectionSet; #endregion //======================= #region vong lap tung xa //[thaydoi] - co the them bien chay //************************* #region khoi dau IEnumIDs xaIds = xaSelectionSet.IDs; int xaId = 0; IFeature xaFt = null; List<object> lstMaDuong = new List<object>(); #endregion //************************* while ((xaId = xaIds.Next()) != -1) { //[kodoi] //======================= #region lay thong tin xa xaFt = xaFeatureClass.GetFeature(xaId); string maxa = xaFt.get_Value(xaFt.Fields.FindField(_fcName.FC_RANH_XA_POLY.MA_XA)).ToString(); string tenxa = xaFt.get_Value(xaFt.Fields.FindField(_fcName.FC_RANH_XA_POLY.TEN_XA)).ToString(); string loaixa = xaFt.get_Value(xaFt.Fields.FindField(_fcName.FC_RANH_XA_POLY.MA_LOAI_XA)).ToString(); int loaidothi = 0; result = int.TryParse(xaFt.get_Value(xaFt.Fields.FindField(_fcName.FC_RANH_XA_POLY.LOAI_DO_THI)).ToString(), out loaidothi); #endregion if (loaidothi == 0) { continue; } #region -----log evt.Log = string.Format("\n************************************************"); evt.Log += string.Format("\n****** Đang tính cho xã/phường: {0} ******", tenxa); evt.Log += string.Format("\n************************************************"); onCalculating(evt); #endregion #region tim duong trong khu vuc do thi bang qua xa //chon xa dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_RANH_XA_POLY.OID, xaId); xaSelectionSet = xaFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); xaFeatureSelection = (IFeatureSelection)xaFeatureLayer; xaFeatureSelection.SelectionSet = xaSelectionSet; //Chon cac duong co do rong theo quy dinh qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_DUONG.PHAN_LOAI, _isDothi);// "maduong='2'"; ISelectionSet duongSelectionSet = duongFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, sdeConn.Workspace); duongFeatureSelection = (IFeatureSelection)duongFeatureLayer; duongFeatureSelection.SelectionSet = duongSelectionSet; //bat dau truy van khong gian _qrBl.FromLayer = duongFeatureLayer; _qrBl.ByLayer = xaFeatureLayer; _qrBl.LayerSelectionMethod = esriLayerSelectionMethod.esriLayerSelectIntersect; _qrBl.ResultType = esriSelectionResultEnum.esriSelectionResultAnd; _qrBl.UseSelectedFeatures = true; duongSelectionSet = _qrBl.Select(); #endregion //======================= #region vong lap xet tung duong //[thaydoi] - co the them bien chay //=============================== #region khoi dau IEnumIDs eIds = duongSelectionSet.IDs; int duongId; IFeature duongFt; int iDuong = 0; int progressingTotalCount = 1; evt.Reset(); evt.ProgressingTotal = duongSelectionSet.Count; onCalculating(evt); //List<object> lstMaDuong = new List<object>(); #endregion //================================ while ((duongId = eIds.Next()) != -1) { //[kodoi] //====================== #region log----- evt.Reset(); evt.ProgressingTotalCount = progressingTotalCount; onCalculating(evt); progressingTotalCount++; #endregion //====================== //[capnhat] - lay ten duong tu bang ten duong //++++++++++++++++++++++++ #region lay thong tin cua duong dang xet duongFt = duongFeatureClass.GetFeature(duongId); string tenduong = "";//ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.TEN_DUONG)).ToString(); object maduong = duongFt.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.MA_DUONG)); //lstMaDuong.Add(maduong); string batdau = "";// ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.BAT_DAU)).ToString(); string ketthuc = "";// ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.KET_THUC)).ToString(); #endregion //++++++++++++++++++++++++ //[kodoi] //Chon duong dang xet, buoc này de ra layer duong dung de truy van khong gian cac thua dat //==================== #region chon duong dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_DUONG.OID, duongId); duongSelectionSet = duongFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); duongFeatureSelection = (IFeatureSelection)duongFeatureLayer; duongFeatureSelection.SelectionSet = duongSelectionSet; #endregion //==================== //tim cac thua theo dieu kien mat tien #region tinh vi tri cho cac thua //doc cach tim thua trong bang he so vi tri //lay cach tim cho dat o //truyen thong so cach tinh,thualayer,duonglayer,khoangcach //MessageBox.Show(func); //func = "ChongLop([INTERSECT],[NEW_SELECTION],1) Then ChongLop([CONTAINED_BY],[AND_SELECTION],50)"; //[kodoi] //============================ #region tim cac thua theo vi tri quy dinh thuaFeatureSelection = (IFeatureSelection)thuaFeatureLayer; thuaFeatureSelection.Clear(); Evaluation eval = new Evaluation(quytac); eval.ThuaLayer = thuaFeatureLayer; eval.DuongLayer = duongFeatureLayer; eval.EvaluateQuery(); //thuaFeatureSelection = (IFeatureSelection)thuaFeatureLayer; ISelectionSet thuaSelectionSet = thuaFeatureSelection.SelectionSet; #endregion //============================ //MessageBox.Show(thuaSelectionSet.Count.ToString()); #endregion #region clip cac thua vua tim duoc #region delete bang thua_sau50m_clip IFeatureClass thuaClipFc = null; if (_dataManager.LayerExist(thuaClip50mNoSde)) { #region log--- evt.Log = string.Format("\n----Kiểm tra, xóa bảng {0} ...", thuaClip50mCoSde); onCalculating(evt); #endregion //thuaClipFc = fw.OpenFeatureClass("sde.thua_sau50m_clip"); //mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); //wspEdit.StartEditing(false); //wspEdit.StartEditOperation(); ((IFeatureClassManager)_dataManager).DeleteFcInSde(thuaClip50mCoSde); //((IDataset)thuaClipFc).Delete(); //wspEdit.StopEditOperation(); //wspEdit.StopEditing(true); } #endregion #region chon duong buffer 50 dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_DUONG.OID, duongId); duongBuff50Sls = duongBuff50FeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); duongBuff50Fsls = (IFeatureSelection)duongBuff50FeatureLayer; duongBuff50Fsls.SelectionSet = duongBuff50Sls; #endregion #region log--- evt.Log = string.Format("\n----Kiểm tra, clip thửa theo đường buffer {0}m, lưu vào bảng {1} ...", _currentConfig.DKhoangCach50mMatTien, thuaClip50mCoSde); onCalculating(evt); #endregion string thualyr = string.Format("{0}/{1}", _sysTempPath.TempPath, thuaClip50mNoSde); string duonglyr = string.Format("{0}/{1}", _sysTempPath.TempPath, duongBuffer50mNoSde); _eraseTool.EraseByLayerFileInsideSde(thuaFeatureLayer, thualyr, duongBuff50FeatureLayer, duonglyr, thuaClip50mNoSde); try { thuaClipFc = fw.OpenFeatureClass(thuaClip50mCoSde); } catch (Exception ex) { continue; } _version.RegisterDataset((IDataset)thuaClipFc, true, true); #endregion //[kodoi] //============================ #region ----log if (thuaSelectionSet.Count == 0) { evt.Log = string.Format("\n !!! Không tìm thấy thửa nào tiếp giáp với đường {0} đoạn từ {1} đến {2} và nằm trong vùng buffer 50m", tenduong, batdau, ketthuc); onCalculating(evt); #region report progressing duong if (iDuong < duongSelectionSet.Count) { decimal i = (decimal)iDuong % (decimal)duongSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iDuong++; #endregion continue; } #endregion sothuatimthay += thuaSelectionSet.Count; //============================ #region xet tung thua //[thaydoi] - co the them bien chay //******************** #region khoi dau IEnumIDs thuaIds = thuaSelectionSet.IDs; int thuaId; IFeature thuaFt; int iThua = 0; List<object[,]> pairColValTgd = new List<object[,]>(); int rowTgdNnHandleUpdate = 0; List<object> newId = new List<object>(); #endregion //******************** while ((thuaId = thuaIds.Next()) != -1) { int hesoVitri = TnHeSoK.DatOSauMatTien50mDt; #region chon duong dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_THUA.OID, thuaId); thuaSelectionSet = thuaFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); thuaFeatureSelection = (IFeatureSelection)thuaFeatureLayer; thuaFeatureSelection.SelectionSet = thuaSelectionSet; #endregion //[thaydoi] - co them them dieu kien de xac dinh vi tri cua thua //*********************************** #region lay thong tin thua dang xet //[kodoi] //============================ #region lay thong tin co ban thuaFt = thuaFeatureClass.GetFeature(thuaId); //neu thua bi khoa tim vi tri,bo qua,xet thua ke string lockTimVitri = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.LOCKED)).ToString(); if (lockTimVitri == "1") { sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } //neu thua ko thuoc xa dang xet thi ko tinh tiep object mathua = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.MA_THUA)); object maxaThua = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.MA_XA)); object dientichpl = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.DIEN_TICH)); #endregion //============================ //[kodoi] //============================ #region kiem tra maxa if (maxaThua.ToString() == "" || maxaThua == null) { maxaThua = "0"; #region ----log evt.Log = string.Format("Chưa xác định mã xã cho thửa {0}", mathua); #endregion sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } #region danh rieng khi tinh theo xa else if (maxaThua.ToString() != maxa) { #region ----log evt.Reset(); evt.Log = string.Format("thửa {0} không thuộc xã {1}", mathua, tenxa); onCalculating(evt); #endregion sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } #endregion #endregion #region lay thong tin loai do thi //neu ko la do thi thi bo qua,xet thua ke qrf.WhereClause = string.Format("{0}={1}", _fcName.FC_RANH_XA_POLY.MA_XA, maxaThua); IFeatureCursor fcrXa = xaFeatureClass.Search(qrf, false); IFeature ftXa = fcrXa.NextFeature(); string loaiDoThi = ""; if (ftXa != null) { loaiDoThi = ftXa.get_Value(ftXa.Fields.FindField(_fcName.FC_RANH_XA_POLY.LOAI_DO_THI)).ToString(); } else { loaiDoThi = "0"; } if (loaiDoThi == "0") { sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } #endregion //============================ #region lay loai dat //neu ko co dat phi nong nghiep thi bo qua,xet thua ke //neu co dat nong nghiep thi datnn=true //neu la dat hon hop, neu co dat sxkd thi datsxkd=true, //neu co dat o thi codato=true //cac truong hop he so vi tri: //o:3010, sxkd:4010, o+nn:5010, o+sxkd:6010 string loaidat = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.LOAI_DAT)).ToString(); //evt.Log = string.Format("\n loai dat cua thua {0} la {1}", thuaId, loaidat); //onCalculating(evt); //[thaydoi] - may tinh dat nong nghiep co the khac //*********************** #region kiem tra dat phi nong nghiep bool datpnn = false; foreach (string s in TnLoaiDats.PHI_NONG_NGHIEP_DOTHI) { if (loaidat.Contains(s)) { datpnn = true; break; } else { datpnn = false; } } if (!datpnn) { sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } #endregion //*********************** //[thaydoi] - may tinh dat nong nghiep co the khac //*********************** #region kiem tra dat honhop bool codatsxkd = false; bool dathonhop = false; bool codato = false; bool chicodato = false; bool chicodatsxkd = false; bool codatnn = false; string loaidatNn = ""; //evt.Log = string.Format("line 983 mattien, loaidat:{0}", loaidat); //onCalculating(evt); if (loaidat.Contains("+")) { //evt.Log = string.Format("line 987 mattien, loaidat:{0}, co +", loaidat); //onCalculating(evt); dathonhop = true; #region kiem tra co dat o foreach (string dato in TnLoaiDats.PNN_O_DT) { if (loaidat.Contains(dato)) { //evt.Log = string.Format("line 992 mattien, loaidat:{0}, co odt", loaidat); //onCalculating(evt); codato = true; break; } } #endregion #region kiem tra co dat nong nghiep foreach (string s in TnLoaiDats.NONG_NGHIEP) { if (loaidat.Contains(s)) { codatnn = true; loaidatNn = s; break; } else { codatnn = false; } } #endregion #region kiem tra chi co dat sxkd foreach (string s in TnLoaiDats.PNN_SX_KD) { if (loaidat == s) { chicodatsxkd = true; break; } else { chicodatsxkd = false; } } #endregion } else { #region kiem tra chi co dat o foreach (string dato in TnLoaiDats.PNN_O_DT) { if (loaidat.Contains(dato)) { //evt.Log = string.Format("line 992 mattien, loaidat:{0}, co odt", loaidat); //onCalculating(evt); chicodato = true; break; } else { chicodato = false; } } #endregion #region kiem tra chi co dat sxkd foreach (string s in TnLoaiDats.PNN_SX_KD) { if (loaidat == s) { chicodatsxkd = true; break; } else { chicodatsxkd = false; } } #endregion } #endregion //*********************** #endregion #endregion //*********************************** //[thaydoi] - thay doi he so vi tri phu hop //*********************************** #region quyet dinh he so vi tri cho thua if (chicodato) { hesoVitri = TnHeSoK.DatOSauMatTien50mDt; } else if (chicodatsxkd) { hesoVitri = TnHeSoK.DatSxkdSauMatTien50mDt; } else if (dathonhop && codato && codatnn) { hesoVitri = TnHeSoK.DatONnSauMatTien50m; } //else if (dathonhop && codato && codatsxkd) //{ // hesoVitri = TnHeSoK.DatOSxkdSauMatTien50m; //} #endregion //*********************************** //[thaydoi] - thay doi dieu kien truy van ung voi tung may tinh khac nhau //*********************************** #region kiem tra trong bang thua_giadat, voi dieu kien:mathua,maduong,hesovitri,khoagia=0 evt.Reset(); evt.Log = "\n[!]--- Kiểm tra các vị trí, cập nhật vị trí mới ..."; onCalculating(evt); 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); IFeatureCursor tgdFcs = tgdFeatureClass.Search(qrf, false); IFeature tgdRow = null; //MessageBox.Show(string.Format("line 1401 CalcPosThuaMattien - bat dau try, query:\n{0}", qrf.WhereClause)); try { tgdRow = tgdFcs.NextFeature();//dam bao la chi co 1 hang ket qua Marshal.ReleaseComObject(tgdFcs); 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 wspEdit.StartEditing(true); wspEdit.StartEditOperation(); //qrf.WhereClause = string.Format("{0}='{1}'", "OBJECTID", tgdRow.OID); //tblThuaGiaDat.DeleteSearchedRows(qrf); tgdRow.Delete(); wspEdit.StopEditOperation(); wspEdit.StopEditing(true); #endregion //=================== #region chon trong bang thua clip qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_THUA.MA_THUA, mathua); IFeatureCursor thuaClipFcur = thuaClipFc.Search(qrf, false); IFeature thuaClipFt = null; try { thuaClipFt = thuaClipFcur.NextFeature(); } catch (Exception ex) { return; } finally { Marshal.ReleaseComObject(thuaClipFcur); } #region lay thong tin thua clip IArea area = (IArea)thuaClipFt.Shape; #endregion #endregion #region them feature moi object copiedId = null; try { //mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); wspEdit.StartEditing(true); wspEdit.StartEditOperation(); copiedId = copyTool.Copy(thuaClipFt, tgdFeatureClass); wspEdit.StopEditOperation(); wspEdit.StopEditing(true); } catch (Exception ex) { wspEdit.AbortEditOperation(); wspEdit.StopEditing(false); } 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.HE_SO_K), hesoVitri } }); pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.DIEN_TICH_PHAP_LY), Math.Round(area.Area, 2) } }); sdeTblTgdEditor.CacheData(copiedId, rowTgdNnHandleUpdate, pairColValTgd, EnumTypeOfEdit.UPDATE); //MessageBox.Show(string.Format("line 1604 CalcPosThuaSau50m copiedId={0}", copiedId)); rowTgdNnHandleUpdate++; pairColValTgd.Clear(); newId.Add(copiedId); #endregion } #endregion } else { #region chon trong bang thua clip qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_THUA.MA_THUA, mathua); IFeatureCursor thuaClipFcur = thuaClipFc.Search(qrf, false); IFeature thuaClipFt = null; try { thuaClipFt = thuaClipFcur.NextFeature(); } catch (Exception ex) { return; } finally { Marshal.ReleaseComObject(thuaClipFcur); } #region lay thong tin thua clip IArea area = (IArea)thuaClipFt.Shape; #endregion #endregion #region them feature moi object copiedId = null; try { //mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); wspEdit.StartEditing(true); wspEdit.StartEditOperation(); copiedId = copyTool.Copy(thuaClipFt, tgdFeatureClass); wspEdit.StopEditOperation(); wspEdit.StopEditing(true); } catch (Exception ex) { wspEdit.AbortEditOperation(); wspEdit.StopEditing(true); } 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.HE_SO_K), hesoVitri } }); pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.DIEN_TICH_PHAP_LY), Math.Round(area.Area, 2) } }); sdeTblTgdEditor.CacheData(copiedId, rowTgdNnHandleUpdate, pairColValTgd, EnumTypeOfEdit.UPDATE); //MessageBox.Show(string.Format("line 1604 CalcPosThuaSau50m copiedId={0}", copiedId)); rowTgdNnHandleUpdate++; pairColValTgd.Clear(); newId.Add(copiedId); #endregion //MessageBox.Show("ko co"); //*********************************** } //MessageBox.Show(newId.Count.ToString()); } catch (Exception e1) { MessageBox.Show(string.Format("CalcPosThuaSau50m, line 1448-\n{0}", e1)); } finally { Marshal.ReleaseComObject(tgdFcs); } #endregion //*********************************** #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion } #endregion //[kodoi] //============================ #region luu thong tin vao bang gia dat if (!sdeTblTgdEditor.IsEditing()) { sdeTblTgdEditor.StartEditing(true); sdeTblTgdEditor.StartEditOperation(); } #region ----log evt.Log = string.Format("\n----||| Đang lưu vị trí các thửa vào bảng {0} |||---- ", tgd); onCalculating(evt); #endregion sdeTblTgdEditor.SaveEdit(); sdeTblTgdEditor.StopEditOperation(); sdeTblTgdEditor.StopEditing(true); #region ----log evt.Log = string.Format("\n----||| Đã lưu vị trí các thửa vào bảng {0} |||---- ", tgd); onCalculating(evt); #endregion #endregion #region tinh gia dat cho cac thua vua them vi tri CalcLandprice calc = new CalcLandprice(this); //MessageBox.Show(string.Format("final:{0}", newId.Count)); calc.Maduong = maduong; calc.Calculate(newId); newId.Clear(); #endregion //============================ } #endregion } #endregion } #endregion //===================================================================== //===================================================================== #region tinh theo duong,doan duong else { #region timduong co ten dang xet //tinh theo doan duong #region tinh theo doan duong if (_inputParams.MA_DUONG != "-1") { qrf.WhereClause = string.Format("{0}={1} and {2}={3}", _fcName.FC_DUONG.MA_DUONG, _inputParams.MA_DUONG, _fcName.FC_DUONG.PHAN_LOAI, _isDothi);// "maduong='2'"; #region ----log evt.Log = string.Format("\n************************************************"); evt.Log += string.Format("\n****** Đang tính cho đoạn đường có mã: {0} ******", _inputParams.MA_DUONG); evt.Log += string.Format("\n************************************************"); onCalculating(evt); #endregion } #endregion //tinh cho 1 duong #region tinh cho 1 duong else if (_inputParams.TEN_DUONG != "" && _inputParams.TEN_DUONG != "*") { //phai sua lai thiet ke //dung relationshipclass many to many gia duong va ten duong #region tim trong bang ten duong qrf.WhereClause = string.Format("{0}=N'{1}'", _tblName.TEN_DUONG.TEN_DUONG, _inputParams.TEN_DUONG); ICursor tenduongCur = tblTenDuong.Search(qrf, false); object idDuong; List<object> lstIdDuong = new List<object>(); try { IRow tenduongRow = null; while ((tenduongRow = tenduongCur.NextRow()) != null) { idDuong = tenduongRow.get_Value(tenduongRow.Fields.FindField(_tblName.TEN_DUONG.MA_DUONG)); lstIdDuong.Add(idDuong); } } catch { } finally { Marshal.ReleaseComObject(tenduongCur); } #endregion #region tim trong bang duong string q = ""; for (int i = 0; i < lstIdDuong.Count; i++) { if (i == lstIdDuong.Count - 1) { q += string.Format("{0}='{1}'", _fcName.FC_DUONG.MA_DUONG, lstIdDuong[i]); } else { q += string.Format("{0}='{1}' or ", _fcName.FC_DUONG.MA_DUONG, lstIdDuong[i]); } } qrf.WhereClause = q;// "maduong='2'"; #region ----log evt.Log = string.Format("\n************************************************"); evt.Log += string.Format("\n****** Đang tính cho cả đường: {0} ******", _inputParams.TEN_DUONG); evt.Log += string.Format("\n************************************************"); onCalculating(evt); #endregion #endregion } #endregion //tinh cho ca duong else { qrf.WhereClause = ""; } //MessageBox.Show(string.Format("whereclause:{0}",duong.QueryFilter.WhereClause)); ISelectionSet duongSelectionSet = duongFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, sdeConn.Workspace); if (duongSelectionSet.Count == 0) { return; } duongFeatureSelection = (IFeatureSelection)duongFeatureLayer; duongFeatureSelection.SelectionSet = duongSelectionSet; #endregion #region vong lap xet tung duong //[thaydoi] - co the them bien chay //=============================== #region khoi dau IEnumIDs eIds = duongSelectionSet.IDs; int duongId; IFeature duongFt; int iDuong = 0; int progressingTotalCount = 1; evt.Reset(); evt.ProgressingTotal = duongSelectionSet.Count; onCalculating(evt); //List<object> lstMaDuong = new List<object>(); #endregion //================================ while ((duongId = eIds.Next()) != -1) { //[kodoi] //====================== #region log----- evt.Reset(); evt.ProgressingTotalCount = progressingTotalCount; onCalculating(evt); progressingTotalCount++; #endregion //====================== //[capnhat] - lay ten duong tu bang ten duong //++++++++++++++++++++++++ #region lay thong tin cua duong dang xet duongFt = duongFeatureClass.GetFeature(duongId); string tenduong = "";//ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.TEN_DUONG)).ToString(); object maduong = duongFt.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.MA_DUONG)); //lstMaDuong.Add(maduong); string batdau = "";// ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.BAT_DAU)).ToString(); string ketthuc = "";// ftDuong.get_Value(_fcName.FC_DUONG.GetIndex(_fcName.FC_DUONG.KET_THUC)).ToString(); #endregion //++++++++++++++++++++++++ //[kodoi] //Chon duong dang xet, buoc này de ra layer duong dung de truy van khong gian cac thua dat //==================== #region chon duong dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_DUONG.OID, duongId); duongSelectionSet = duongFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); duongFeatureSelection = (IFeatureSelection)duongFeatureLayer; duongFeatureSelection.SelectionSet = duongSelectionSet; #endregion //==================== //tim cac thua theo dieu kien mat tien #region tinh vi tri cho cac thua //doc cach tim thua trong bang he so vi tri //lay cach tim cho dat o //truyen thong so cach tinh,thualayer,duonglayer,khoangcach //MessageBox.Show(func); //func = "ChongLop([INTERSECT],[NEW_SELECTION],1) Then ChongLop([CONTAINED_BY],[AND_SELECTION],50)"; //[kodoi] //============================ #region tim cac thua theo vi tri quy dinh thuaFeatureSelection = (IFeatureSelection)thuaFeatureLayer; thuaFeatureSelection.Clear(); Evaluation eval = new Evaluation(quytac); eval.ThuaLayer = thuaFeatureLayer; eval.DuongLayer = duongFeatureLayer; eval.EvaluateQuery(); //thuaFeatureSelection = (IFeatureSelection)thuaFeatureLayer; ISelectionSet thuaSelectionSet = thuaFeatureSelection.SelectionSet; #endregion //============================ //MessageBox.Show(thuaSelectionSet.Count.ToString()); #endregion #region clip cac thua vua tim duoc #region delete bang thua_sau50m_clip IFeatureClass thuaClipFc=null; #region log--- evt.Log = string.Format("\n----Kiểm tra, xóa bảng {0} ...", thuaClip50mCoSde); onCalculating(evt); #endregion if (_dataManager.LayerExist(thuaClip50mNoSde)) { //thuaClipFc = fw.OpenFeatureClass("sde.thua_sau50m_clip"); //mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); //wspEdit.StartEditing(false); //wspEdit.StartEditOperation(); ((IFeatureClassManager)_dataManager).DeleteFcInSde(thuaClip50mCoSde); //((IDataset)thuaClipFc).Delete(); //wspEdit.StopEditOperation(); //wspEdit.StopEditing(true); } #endregion #region chon duong buffer 50 dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_DUONG.OID, duongId); duongBuff50Sls = duongBuff50FeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); duongBuff50Fsls = (IFeatureSelection)duongBuff50FeatureLayer; duongBuff50Fsls.SelectionSet = duongBuff50Sls; #endregion #region log--- evt.Log = string.Format("\n----Kiểm tra, clip thửa theo đường buffer {0}m, lưu vào bảng {1} ...", _currentConfig.DKhoangCach50mMatTien, thuaClip50mCoSde); onCalculating(evt); #endregion string thualyr = string.Format("{0}/{1}", _sysTempPath.TempPath, thuaClip50mNoSde); string duonglyr = string.Format("{0}/{1}", _sysTempPath.TempPath, duongBuffer50mNoSde); _eraseTool.EraseByLayerFileInsideSde(thuaFeatureLayer, thualyr, duongBuff50FeatureLayer, duonglyr, thuaClip50mNoSde); try { thuaClipFc = fw.OpenFeatureClass(thuaClip50mCoSde); } catch (Exception ex) { continue; } _version.RegisterDataset((IDataset)thuaClipFc, true, true); #endregion //[kodoi] //============================ #region ----log if (thuaSelectionSet.Count == 0) { evt.Log = string.Format("\n !!! Không tìm thấy thửa nào tiếp giáp với đường {0} đoạn từ {1} đến {2} và nằm trong vùng buffer 50m", tenduong, batdau, ketthuc); onCalculating(evt); #region report progressing duong if (iDuong < duongSelectionSet.Count) { decimal i = (decimal)iDuong % (decimal)duongSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iDuong++; #endregion continue; } #endregion sothuatimthay += thuaSelectionSet.Count; //============================ #region xet tung thua //[thaydoi] - co the them bien chay //******************** #region khoi dau IEnumIDs thuaIds = thuaSelectionSet.IDs; int thuaId; IFeature thuaFt; int iThua = 0; List<object[,]> pairColValTgd = new List<object[,]>(); int rowTgdNnHandleUpdate = 0; List<object> newId = new List<object>(); #endregion //******************** while ((thuaId = thuaIds.Next()) != -1) { int hesoVitri = TnHeSoK.DatOSauMatTien50mDt; #region chon duong dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_THUA.OID, thuaId); thuaSelectionSet = thuaFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); thuaFeatureSelection = (IFeatureSelection)thuaFeatureLayer; thuaFeatureSelection.SelectionSet = thuaSelectionSet; #endregion //[thaydoi] - co them them dieu kien de xac dinh vi tri cua thua //*********************************** #region lay thong tin thua dang xet //[kodoi] //============================ #region lay thong tin co ban thuaFt = thuaFeatureClass.GetFeature(thuaId); //neu thua bi khoa tim vi tri,bo qua,xet thua ke string lockTimVitri = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.LOCKED)).ToString(); if (lockTimVitri == "1") { sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } //neu thua ko thuoc xa dang xet thi ko tinh tiep object mathua = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.MA_THUA)); object maxaThua = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.MA_XA)); object dientichpl = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.DIEN_TICH)); #endregion //============================ //[kodoi] //============================ #region kiem tra maxa if (maxaThua.ToString() == "" || maxaThua == null) { maxaThua = "0"; #region ----log evt.Log = string.Format("Chưa xác định mã xã cho thửa {0}", mathua); #endregion sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } #endregion #region lay thong tin loai do thi //neu ko la do thi thi bo qua,xet thua ke qrf.WhereClause = string.Format("{0}={1}", _fcName.FC_RANH_XA_POLY.MA_XA, maxaThua); IFeatureCursor fcrXa = xaFeatureClass.Search(qrf, false); IFeature ftXa = fcrXa.NextFeature(); string loaiDoThi = ""; if (ftXa != null) { loaiDoThi = ftXa.get_Value(ftXa.Fields.FindField(_fcName.FC_RANH_XA_POLY.LOAI_DO_THI)).ToString(); } else { loaiDoThi = "0"; } if (loaiDoThi == "0") { sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } #endregion //============================ #region lay loai dat //neu ko co dat phi nong nghiep thi bo qua,xet thua ke //neu co dat nong nghiep thi datnn=true //neu la dat hon hop, neu co dat sxkd thi datsxkd=true, //neu co dat o thi codato=true //cac truong hop he so vi tri: //o:3010, sxkd:4010, o+nn:5010, o+sxkd:6010 string loaidat = thuaFt.get_Value(thuaFt.Fields.FindField(_fcName.FC_THUA.LOAI_DAT)).ToString(); //evt.Log = string.Format("\n loai dat cua thua {0} la {1}", thuaId, loaidat); //onCalculating(evt); //[thaydoi] - may tinh dat nong nghiep co the khac //*********************** #region kiem tra dat phi nong nghiep bool datpnn = false; foreach (string s in TnLoaiDats.PHI_NONG_NGHIEP_DOTHI) { if (loaidat.Contains(s)) { datpnn = true; break; } else { datpnn = false; } } if (!datpnn) { sothuaKhongTinhDuoc++; #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion continue; } #endregion //*********************** //[thaydoi] - may tinh dat nong nghiep co the khac //*********************** #region kiem tra dat honhop bool codatsxkd = false; bool dathonhop = false; bool codato = false; bool chicodato = false; bool chicodatsxkd = false; bool codatnn = false; string loaidatNn = ""; //evt.Log = string.Format("line 983 mattien, loaidat:{0}", loaidat); //onCalculating(evt); if (loaidat.Contains("+")) { //evt.Log = string.Format("line 987 mattien, loaidat:{0}, co +", loaidat); //onCalculating(evt); dathonhop = true; #region kiem tra co dat o foreach (string dato in TnLoaiDats.PNN_O_DT) { if (loaidat.Contains(dato)) { //evt.Log = string.Format("line 992 mattien, loaidat:{0}, co odt", loaidat); //onCalculating(evt); codato = true; break; } } #endregion #region kiem tra co dat nong nghiep foreach (string s in TnLoaiDats.NONG_NGHIEP) { if (loaidat.Contains(s)) { codatnn = true; loaidatNn = s; break; } else { codatnn = false; } } #endregion #region kiem tra chi co dat sxkd foreach (string s in TnLoaiDats.PNN_SX_KD) { if (loaidat == s) { chicodatsxkd = true; break; } else { chicodatsxkd = false; } } #endregion } else { #region kiem tra chi co dat o foreach (string dato in TnLoaiDats.PNN_O_DT) { if (loaidat.Contains(dato)) { //evt.Log = string.Format("line 992 mattien, loaidat:{0}, co odt", loaidat); //onCalculating(evt); chicodato = true; break; } else { chicodato = false; } } #endregion #region kiem tra chi co dat sxkd foreach (string s in TnLoaiDats.PNN_SX_KD) { if (loaidat == s) { chicodatsxkd = true; break; } else { chicodatsxkd = false; } } #endregion } #endregion //*********************** #endregion #endregion //*********************************** //[thaydoi] - thay doi he so vi tri phu hop //*********************************** #region quyet dinh he so vi tri cho thua if (chicodato) { hesoVitri = TnHeSoK.DatOSauMatTien50mDt; } else if (chicodatsxkd) { hesoVitri = TnHeSoK.DatSxkdSauMatTien50mDt; } else if (dathonhop && codato && codatnn) { hesoVitri = TnHeSoK.DatONnSauMatTien50m; } //else if (dathonhop && codato && codatsxkd) //{ // hesoVitri = TnHeSoK.DatOSxkdSauMatTien50m; //} #endregion //*********************************** //[thaydoi] - thay doi dieu kien truy van ung voi tung may tinh khac nhau //*********************************** #region kiem tra trong bang thua_giadat, voi dieu kien:mathua,maduong,hesovitri,khoagia=0 evt.Reset(); evt.Log = "\n[!]--- Kiểm tra các vị trí, cập nhật vị trí mới ..."; onCalculating(evt); 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); IFeatureCursor tgdFcs = tgdFeatureClass.Search(qrf, false); IFeature tgdRow = null; //MessageBox.Show(string.Format("line 1401 CalcPosThuaMattien - bat dau try, query:\n{0}", qrf.WhereClause)); try { tgdRow = tgdFcs.NextFeature();//dam bao la chi co 1 hang ket qua Marshal.ReleaseComObject(tgdFcs); 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 wspEdit.StartEditing(true); wspEdit.StartEditOperation(); //qrf.WhereClause = string.Format("{0}='{1}'", "OBJECTID", tgdRow.OID); //tblThuaGiaDat.DeleteSearchedRows(qrf); tgdRow.Delete(); wspEdit.StopEditOperation(); wspEdit.StopEditing(true); #endregion //=================== #region chon trong bang thua clip qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_THUA.MA_THUA, mathua); IFeatureCursor thuaClipFcur = thuaClipFc.Search(qrf, false); IFeature thuaClipFt = null; try { thuaClipFt = thuaClipFcur.NextFeature(); } catch (Exception ex) { return; } finally { Marshal.ReleaseComObject(thuaClipFcur); } #region lay thong tin thua clip IArea area = (IArea)thuaClipFt.Shape; #endregion #endregion #region them feature moi object copiedId = null; try { //mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); wspEdit.StartEditing(true); wspEdit.StartEditOperation(); copiedId = copyTool.Copy(thuaClipFt, tgdFeatureClass); wspEdit.StopEditOperation(); wspEdit.StopEditing(true); } catch (Exception ex) { wspEdit.AbortEditOperation(); wspEdit.StopEditing(false); } 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.HE_SO_K), hesoVitri } }); pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.DIEN_TICH_PHAP_LY), Math.Round(area.Area,2) } }); sdeTblTgdEditor.CacheData(copiedId, rowTgdNnHandleUpdate, pairColValTgd, EnumTypeOfEdit.UPDATE); //MessageBox.Show(string.Format("line 1604 CalcPosThuaSau50m copiedId={0}", copiedId)); //evt.Log = string.Format("\n----Lưu thông tin cho vùng giá {0}---- ", copiedId); //onCalculating(evt); //evt.Log = string.Format("\n----Cột mathua:{0},cột maduong:{1}, cot hesovitri:{2}, cot dientichpl:{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)); //onCalculating(evt); rowTgdNnHandleUpdate++; pairColValTgd.Clear(); newId.Add(copiedId); #endregion //[thaydoi] - them gia tri //********************** #region clip thua dang xet /* #region chon duong buffer 50 dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_DUONG.OID, duongId); duongBuff50Sls = duongBuff50FeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); duongBuff50Fsls = (IFeatureSelection)duongBuff50FeatureLayer; duongBuff50Fsls.SelectionSet = duongBuff50Sls; #endregion //_clipTool = new TnClip(sdeConn.Environment); //string thualyr = string.Format("{0}/{1}", _sysTempPath.TempPath, "thua_sau50m_clip.lyr"); //string duonglyr = string.Format("{0}/{1}", _sysTempPath.TempPath, "duong_sau50m_clip.lyr"); //_clipTool.ClipByLayerFileInsideSde(thuaFeatureLayer, thualyr, duongBuff50FeatureLayer, duonglyr, "thua_sau50m_clip"); //_dataManager.SaveToLayerFile((ILayer)thuaFeatureLayer, thualyr); //_dataManager.SaveToLayerFile((ILayer)duongBuff50FeatureLayer, duonglyr); //_clipTool.Clip(thualyr, duonglyr, "thua_sau50m_clip"); //MessageBox.Show(string.Format("line 1459 CalPosThuaSau50m {0}", _sysTempPath.TempFullPathNoEnd)); IFeatureClass fcThuaCliped = _dataManager.TnOpenFeatureClassFromFileMdb(_sysTempPath.TempFullPathNoEnd, "thua_sau50m_clip"); string clipPath = string.Format("{0}{1}", _sysTempPath.TempFullPath, "thua_sau50m_clip"); IFeatureLayer flThuaCliped = new FeatureLayerClass(); flThuaCliped.FeatureClass = fcThuaCliped; IFeatureCursor fcur = fcThuaCliped.Search(null, false); IFeature clipFt = null; try { clipFt = fcur.NextFeature(); } catch { continue; } finally { Marshal.ReleaseComObject(fcur); } if (clipFt == null) { continue; } #endregion #region lay thong tin thua clip IArea area = (IArea)clipFt.Shape; #endregion #region them feature moi wspEdit.StartEditing(true); wspEdit.StartEditOperation(); object copiedId = copyTool.CopyFromMdb(clipFt, tgdFeatureClass); //copyTool.CopyUseGeoprocessing(clipPath, tgdFeatureClass.AliasName); //IFeatureCursor fcurClip = tgdFeatureClass.Search(null, false); //object copiedId = null; //IFeature ftClip = null; //try //{ // while ((ftClip = fcurClip.NextFeature()) != null) // { // copiedId = ftClip.get_Value(0); // } //} //catch { } //finally { Marshal.ReleaseComObject(fcurClip); } 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.HE_SO_K), hesoVitri } }); pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.DIEN_TICH_PHAP_LY), area.Area } }); sdeTblTgdEditor.CacheData(copiedId, rowTgdNnHandleUpdate, pairColValTgd, EnumTypeOfEdit.UPDATE); MessageBox.Show(string.Format("line 1533 CalcPosThuaSau50m copiedId={0}", copiedId)); rowTgdNnHandleUpdate++; pairColValTgd.Clear(); newId.Add(copiedId); * */ #endregion //********************** } #endregion } else { #region chon trong bang thua clip qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_THUA.MA_THUA, mathua); IFeatureCursor thuaClipFcur = thuaClipFc.Search(qrf, false); IFeature thuaClipFt = null; try { thuaClipFt = thuaClipFcur.NextFeature(); } catch (Exception ex) { return; } finally { Marshal.ReleaseComObject(thuaClipFcur); } #region lay thong tin thua clip IArea area = (IArea)thuaClipFt.Shape; #endregion #endregion #region them feature moi object copiedId = null; try { //mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); wspEdit.StartEditing(true); wspEdit.StartEditOperation(); copiedId = copyTool.Copy(thuaClipFt, tgdFeatureClass); wspEdit.StopEditOperation(); wspEdit.StopEditing(true); } catch (Exception ex) { wspEdit.AbortEditOperation(); wspEdit.StopEditing(true); } 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.HE_SO_K), hesoVitri } }); pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.DIEN_TICH_PHAP_LY), Math.Round(area.Area, 2) } }); sdeTblTgdEditor.CacheData(copiedId, rowTgdNnHandleUpdate, pairColValTgd, EnumTypeOfEdit.UPDATE); //MessageBox.Show(string.Format("line 1604 CalcPosThuaSau50m copiedId={0}", copiedId)); rowTgdNnHandleUpdate++; pairColValTgd.Clear(); newId.Add(copiedId); #endregion //MessageBox.Show("ko co"); #region clip thua dang xet /* #region chon duong buffer 50 dang xet qrf.WhereClause = string.Format("{0}='{1}'", _fcName.FC_DUONG.OID, duongId); duongBuff50Sls = duongBuff50FeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace); duongBuff50Fsls = (IFeatureSelection)duongBuff50FeatureLayer; duongBuff50Fsls.SelectionSet = duongBuff50Sls; #endregion //_clipTool = new TnClip(sdeConn.Environment); //string thualyr = string.Format("{0}/{1}", _sysTempPath.TempPath, "thua_sau50m_clip.lyr"); //string duonglyr = string.Format("{0}/{1}", _sysTempPath.TempPath, "duong_sau50m_clip.lyr"); //_dataManager.SaveToLayerFile((ILayer)thuaFeatureLayer, thualyr); //_dataManager.SaveToLayerFile((ILayer)duongBuff50FeatureLayer, duonglyr); //((IFeatureClassManager)_dataManager).DeleteFcInSde("sde.thua_sau50m_clip"); //mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); //wspEdit.StartEditOperation(); IFeatureClass fcThuaCliped; //try //{ // fcThuaCliped = fw.OpenFeatureClass("thua_sau50m_clip"); // IDataset ft = (IDataset)fcThuaCliped; // ft.Delete(); // wspEdit.StopEditOperation(); // wspEdit.StopEditing(true); //} //catch (Exception ex) //{ // MessageBox.Show(string.Format("line 1577 CalcPosThuaSau50m {0}", ex)); // wspEdit.AbortEditOperation(); // wspEdit.StopEditing(false); //} _clipTool.ClipInsideSde(thualyr, duonglyr, "thua_sau50m_clip"); //MessageBox.Show(string.Format("line 1517 CalPosThuaSau50m {0}", _sysTempPath.TempFullPathNoEnd)); fcThuaCliped = fw.OpenFeatureClass("sde.thua_sau50m_clip");//_dataManager.TnOpenFeatureClassFromFileMdb(_sysTempPath.TempFullPathNoEnd, "thua_sau50m_clip"); _version.RegisterDataset((IDataset)fcThuaCliped, true, true); string clipPath = string.Format("{0}{1}", _sysTempPath.TempFullPath, "thua_sau50m_clip"); IFeatureLayer flThuaCliped = new FeatureLayerClass(); flThuaCliped.FeatureClass = fcThuaCliped; IFeatureCursor fcur = fcThuaCliped.Search(null, false); IFeature clipFt = null; try { clipFt = fcur.NextFeature(); } catch { continue; } finally { Marshal.ReleaseComObject(fcur); } if (clipFt == null) { continue; } #endregion #region lay thong tin thua clip IArea area = (IArea)clipFt.Shape; #endregion //[thaydoi] - them cac gia tri thich hop vao thua_giadat //*********************************** #region them feature moi object copiedId = null; try { //MessageBox.Show() mwspEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); wspEdit.StartEditOperation(); copiedId = copyTool.Copy(clipFt, tgdFeatureClass); //copyTool.CopyUseGeoprocessing(clipPath, tgdFeatureClass.AliasName,sdeConn.Environment); //IAppend app = (IAppend)copyTool; //app.Append(fcThuaCliped, thuaFeatureClass); #region //IGeometry g = new PolygonClass(); //MessageBox.Show(string.Format("line 1597 CalcPosThuaSau50m {0}", g.GeometryType.ToString())); //IFeature feature = tgdFeatureClass.CreateFeature(); //feature.Shape = g; //// Apply the appropriate subtype to the feature. //ISubtypes subtypes = (ISubtypes)tgdFeatureClass; //IRowSubtypes rowSubtypes = (IRowSubtypes)feature; //if (subtypes.HasSubtype) //{ // // In this example, the value of 3 represents the PVC subtype. // rowSubtypes.SubtypeCode = 3; //} //// Initialize any default values the feature has. //rowSubtypes.InitDefaultValues(); //// Update the value on a string field that indicates who installed the feature. ////int contractorFieldIndex = tgdFeatureClass.FindField("CONTRACTOR"); ////feature.set_Value(contractorFieldIndex, "K Johnston"); //// Commit the new feature to the geodatabase. //feature.Store(); wspEdit.StopEditOperation(); wspEdit.StopEditing(true); #endregion } catch (Exception e1) { wspEdit.AbortEditOperation(); wspEdit.StopEditing(false); MessageBox.Show(string.Format("line 1593 CalcPosThuaSau50m {0} \n{1}", copiedId, e1)); } MessageBox.Show(string.Format("line 1593 CalcPosThuaSau50m {0}",copiedId)); //copyTool.CopyUseGeoprocessing(clipPath, tgdFeatureClass.AliasName); //IFeatureCursor fcurClip = tgdFeatureClass.Search(null, false); //object copiedId=null; //IFeature ftClip=null; //try //{ // while ((ftClip = fcurClip.NextFeature()) != null) // { // copiedId = ftClip.get_Value(0); // } //} //catch { } //finally { Marshal.ReleaseComObject(fcurClip); } //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.HE_SO_K), hesoVitri } }); pairColValTgd.Add(new object[,] { { _fcName.FC_THUA_GIADAT_DRAFT.GetIndex(_fcName.FC_THUA_GIADAT_DRAFT.DIEN_TICH_PHAP_LY), area.Area } }); sdeTblTgdEditor.CacheData(copiedId, rowTgdNnHandleUpdate, pairColValTgd, EnumTypeOfEdit.UPDATE); MessageBox.Show(string.Format("line 1604 CalcPosThuaSau50m copiedId={0}", copiedId)); rowTgdNnHandleUpdate++; pairColValTgd.Clear(); newId.Add(copiedId); * */ #endregion //*********************************** } //MessageBox.Show(newId.Count.ToString()); } catch (Exception e1) { MessageBox.Show(string.Format("CalcPosThuaSau50m, line 1448-\n{0}", e1)); } finally { Marshal.ReleaseComObject(tgdFcs); } #endregion //*********************************** #region report progressing thua if (iThua < thuaSelectionSet.Count) { decimal i = (decimal)iThua / (decimal)thuaSelectionSet.Count * 100; int i1 = Convert.ToInt32(i); this._bgwCalculating.ReportProgress(i1); //MessageBox.Show("log 009"); } else { this._bgwCalculating.ReportProgress(99); } iThua++; #endregion } #endregion //[kodoi] //============================ #region luu thong tin vao bang gia dat if (!sdeTblTgdEditor.IsEditing()) { sdeTblTgdEditor.StartEditing(true); sdeTblTgdEditor.StartEditOperation(); } #region ----log evt.Log = string.Format("\n----||| Đang lưu vị trí các thửa vào bảng {0} |||---- ", tgd); onCalculating(evt); #endregion sdeTblTgdEditor.SaveEdit(); sdeTblTgdEditor.StopEditOperation(); sdeTblTgdEditor.StopEditing(true); #region ----log evt.Log = string.Format("\n----||| Đã lưu vị trí các thửa vào bảng {0} |||---- ", tgd); onCalculating(evt); #endregion #endregion #region tinh gia dat cho cac thua vua them vi tri CalcLandprice calc = new CalcLandprice(this); //MessageBox.Show(string.Format("final:{0}", newId.Count)); calc.Maduong = maduong; calc.Calculate(newId); newId.Clear(); #endregion //============================ } #endregion } #endregion #endregion //=========================================== //=========================================== //******************************************* //[kodoi] //============== #region doan ket sothuatinhduoc = sothuatimthay - sothuaKhongTinhDuoc; #region ----log evt.Log = string.Format("\n\n=====================================\n******* Đã tính xong*******\n====================================="); //evt.Log += string.Format("\n Số thửa tìm thấy: {0}", sothuatimthay); //evt.Log += string.Format("\n Số thửa được tính: {0}", sothuatinhduoc); onCalculating(evt); #endregion evt.Reset(); evt.ProgressingTotalCount = "."; evt.ProgressingTotal = "."; onCalculating(evt); evt.CurrentIndexCalculator = this._index; onFinished(evt); #endregion //============== }