Beispiel #1
0
        ISelectionSet ISpatialAlgrorithm.Execute()
        {
            SdeConnection conn = new SdeConnection();
            ISdeConnectionInfo sdeConn = conn as ISdeConnectionInfo;
            IFeatureWorkspace fw = (IFeatureWorkspace)sdeConn.Workspace;
            ITnFeatureClassName fcName = new TnFeatureClassName(sdeConn.Workspace);
            ITnTableName tblName = new TnTableName(sdeConn.Workspace);
            IFeatureClass xaFeatureClass = fw.OpenFeatureClass(fcName.FC_RANH_XA_POLY.NAME);
            IFeatureLayer xaFeatureLayer = new FeatureLayerClass();
            xaFeatureLayer.FeatureClass = xaFeatureClass;
            IFeatureClass duongFeatureClass = fw.OpenFeatureClass(fcName.FC_DUONG.NAME);
            IFeatureLayer duongFeatureLayer = new FeatureLayerClass();
            duongFeatureLayer.FeatureClass = duongFeatureClass;
            //IQueryFilter qrf = new QueryFilterClass();
            //qrf.WhereClause = string.Format("{0}='{1}'", fcName.FC_RANH_XA_POLY.MA_XA, 5);
            //ISelectionSet xaSelectionSet = xaFeatureClass.Select(qrf, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionOnlyOne, sdeConn.Workspace);
            //IFeatureSelection xaFeatureSelection = (IFeatureSelection)xaFeatureLayer;
            //xaFeatureSelection.SelectionSet = xaSelectionSet;
            //if (this._fromLayer == null || this._byLayer == null)
            //{
            //    return null;
            //}
            //this._resultSelectionSet=this._queryByLayer.Select();
            //IFeatureLayer f=new FeatureLayerClass();
            //f.FeatureClass=this._frmFc;
            //IFeatureLayer b=new FeatureLayerClass();
            //b.FeatureClass = this._byFc;
            //IFeatureSelection fs = (IFeatureSelection)this._byLayer;
            //MessageBox.Show(fs.SelectionSet.Count.ToString());
            IQueryByLayer qrbl = new QueryByLayerClass();
            qrbl.FromLayer = duongFeatureLayer;
            qrbl.ByLayer = xaFeatureLayer;
            qrbl.LayerSelectionMethod = esriLayerSelectionMethod.esriLayerSelectIntersect;
            qrbl.ResultType = esriSelectionResultEnum.esriSelectionResultNew;
            qrbl.UseSelectedFeatures = true;

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

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

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

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

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

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

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

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

                        bool isOverWritePos = true;

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

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

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

                        #endregion

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

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

            #endregion

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

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

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

            #region vong lap tung id

            #region khoi dau

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

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

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

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

                #endregion
            }
            if (!sdeTblThuaEditor.IsEditing())
            {
                sdeTblThuaEditor.StartEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
                sdeTblThuaEditor.StartEditOperation();
            }
            else
            {
                try
                {
                    sdeTblThuaEditor.SaveEdit();
                    sdeTblThuaEditor.StopEditOperation();
                    sdeTblThuaEditor.StopEditing(true);
                }
                catch
                {
                    sdeTblThuaEditor.StopEditOperation();
                    sdeTblThuaEditor.StopEditing(false);
                }
                sdeTblThuaEditor.StartEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
                sdeTblThuaEditor.StartEditOperation();
            }
            try
            {
                sdeTblThuaEditor.SaveEdit();
                sdeTblThuaEditor.StopEditOperation();
                sdeTblThuaEditor.StopEditing(true);
            }
            catch (Exception ex)
            {
                sdeTblThuaEditor.StopEditOperation();
                sdeTblThuaEditor.StopEditing(false);
            }
            #endregion
        }