Exemplo n.º 1
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            Exception     exError       = null;
            ITransactions pTransactions = null;

            //保存查询配置文件(由本地向数据库保存)
            try
            {
                IMemoryBlobStream pBlobStream = new MemoryBlobStreamClass();

                pBlobStream.LoadFromFile(_QueryConfigPath);
                //启动事务
                pTransactions = (ITransactions)_TmpWorkSpace;
                if (!pTransactions.InTransaction)
                {
                    pTransactions.StartTransaction();
                }
                SysGisTable sysTable = new SysGisTable(_TmpWorkSpace);
                Dictionary <string, object> dicData = new Dictionary <string, object>();
                dicData.Add("SETTINGVALUE2", pBlobStream);
                dicData.Add("SETTINGNAME", "统计配置");
                //判断是更新还是添加
                //不存在则添加,已存在则更新
                if (!sysTable.ExistData("SYSSETTING", "SETTINGNAME='统计配置'"))
                {
                    if (!sysTable.NewRow("SYSSETTING", dicData, out exError))
                    {
                        MessageBox.Show(exError.Message);
                        return;
                    }
                }
                else
                {
                    if (!sysTable.UpdateRow("SYSSETTING", "SETTINGNAME='统计配置'", dicData, out exError))
                    {
                        MessageBox.Show(exError.Message);
                        return;
                    }
                }
                //提交事务
                if (pTransactions.InTransaction)
                {
                    pTransactions.CommitTransaction();
                }
            }
            catch (Exception ex)
            {
                //出错则放弃提交
                if (pTransactions.InTransaction)
                {
                    pTransactions.AbortTransaction();
                }
                MessageBox.Show(exError.Message);
                return;
            }
            this.DialogResult = DialogResult.OK;
        }
        public long unversionedEdit(IQueryFilter qFilterGen, int sequenceColumnNum, int idxSeqField, int curLoop, ref ITransactions transactions)
        {
            long sequenceValue = -1;
            using (ComReleaser comReleaser = new ComReleaser())
            {

                if (AAState._gentabWorkspace.IsInEditOperation)
                {
                    // throw new Exception("Cannot use ITransactions during an edit operation.");
                }
                // Begin a transaction.
                if (transactions == null)
                {
                    transactions = (ITransactions)AAState._gentabWorkspace;
                }

                transactions.StartTransaction();
                try
                {
                    // Use ITable.Update to create an update cursor.
                    ICursor seq_updateCursor = AAState._gentab.Update(qFilterGen, true);
                    comReleaser.ManageLifetime(seq_updateCursor);

                    IRow seq_row = null;
                    seq_row = seq_updateCursor.NextRow();
                    int sequenceInt = 1;

                    if (seq_row != null)
                    {
                        if (idxSeqField > 0)
                        {
                            object seqInt = seq_row.get_Value(idxSeqField);
                            if (seqInt != null)
                            {
                                if (seqInt != DBNull.Value)
                                    try
                                    {
                                        sequenceInt = Convert.ToInt32(seqInt);
                                    }
                                    catch
                                    {

                                    }
                            }
                        }
                        object seqValue = seq_row.get_Value(sequenceColumnNum);

                        if (seqValue == null)
                        {
                            sequenceValue = 0;
                        }
                        else if (seqValue.ToString() == "")
                        {
                            sequenceValue = 0;
                        }
                        else
                            try
                            {
                                sequenceValue = Convert.ToInt64(seqValue);
                            }
                            catch
                            {
                                sequenceValue = 0;
                            }

                        AAState.WriteLine("                  " + sequenceValue + " is the existing value and the interval is " + sequenceInt + ": " + DateTime.Now.ToString("h:mm:ss tt"));

                        sequenceValue = sequenceValue + sequenceInt;

                        seq_row.set_Value(sequenceColumnNum, sequenceValue);
                        AAState.WriteLine("                  " + seq_row.Fields.get_Field(sequenceColumnNum).AliasName + " changed to " + sequenceValue + ": " + DateTime.Now.ToString("h:mm:ss tt"));

                        seq_updateCursor.UpdateRow(seq_row);

                        transactions.CommitTransaction();

                        seq_updateCursor = AAState._gentab.Search(qFilter, true);
                        if (seq_row != null)
                        {
                            seqValue = seq_row.get_Value(sequenceColumnNum);

                            if (seqValue == null)
                            {
                                return sequenceValue;
                            }
                            else if (seqValue.ToString() == "")
                            {
                                return sequenceValue;
                            }
                            else
                                try
                                {
                                    if (sequenceValue == Convert.ToInt64(seqValue))
                                    {
                                        return sequenceValue;
                                    }
                                    else
                                    {
                                        if (curLoop > 30)
                                        {
                                            MessageBox.Show("A unique ID could not be generated after 30 attempts: " + DateTime.Now.ToString("h:mm:ss tt"));
                                        }
                                        else
                                        {
                                            return unversionedEdit(qFilterGen, sequenceColumnNum, idxSeqField, curLoop + 1, ref transactions);
                                        }
                                    }
                                }
                                catch
                                {
                                    return sequenceValue;
                                }
                        }
                        return sequenceValue;
                    }
                    else
                    {
                        AAState.WriteLine("                  No records found in Generate ID table" + ": " + DateTime.Now.ToString("h:mm:ss tt"));
                        transactions.AbortTransaction();
                        return -1;
                    }
                }
                catch (COMException comExc)
                {
                    AAState.WriteLine("                  Error saving transaction to DB" + ": " + DateTime.Now.ToString("h:mm:ss tt"));

                    // If an error occurs during the inserts and updates, rollback the transaction.
                    transactions.AbortTransaction();
                    return -1;
                }

            }
        }
Exemplo n.º 3
0
        //本地向数据库保存图层目录
        private bool ImportEagleEyset(IWorkspace pWorkspace, string strPath)
        {
            //判断各个参数是否有效
            if (pWorkspace == null)
            {
                return(false);
            }
            Exception     exError       = null;
            ITransactions pTransactions = null;

            //保存图层树(由本地向数据库保存)
            try
            {
                IMemoryBlobStream pBlobStream = new MemoryBlobStreamClass();
                ///读取路径下的mxd文件
                // System.IO.FileStream pFileStream = File.Create(strPath);
                //if (pFileStream == null) { return false; }
                // byte[] bytes = new byte[pFileStream.Length];
                // pBlobStream.ImportFromMemory(ref bytes[0], (uint)bytes.GetLength(0));
                // pFileStream.Close();
                // pFileStream.Dispose();
                ///读取路径下的mxd文件转化成MemoryBlobStreamClass
                pBlobStream.LoadFromFile(strPath);
                //启动事务
                pTransactions = (ITransactions)pWorkspace;
                if (!pTransactions.InTransaction)
                {
                    pTransactions.StartTransaction();
                }
                SysGisTable sysTable = new SysGisTable(pWorkspace);
                Dictionary <string, object> dicData = new Dictionary <string, object>();
                dicData.Add("SETTINGVALUE2", pBlobStream);
                dicData.Add("SETTINGNAME", "鹰眼图");
                //判断是更新还是添加
                //不存在则添加,已存在则更新
                if (!sysTable.ExistData("SYSSETTING", "SETTINGNAME='鹰眼图'"))
                {
                    if (!sysTable.NewRow("SYSSETTING", dicData, out exError))
                    {
                        ErrorHandle.ShowFrmErrorHandle("提示", "添加失败!");
                        return(false);
                    }
                }
                else
                {
                    if (!sysTable.UpdateRow("SYSSETTING", "SETTINGNAME='鹰眼图'", dicData, out exError))
                    {
                        ErrorHandle.ShowFrmErrorHandle("提示", "更新失败!");
                        return(false);
                    }
                }
                //提交事务
                if (pTransactions.InTransaction)
                {
                    pTransactions.CommitTransaction();
                }
                return(true);
            }
            catch (Exception ex)
            {
                //出错则放弃提交
                if (pTransactions.InTransaction)
                {
                    pTransactions.AbortTransaction();
                }
                ErrorHandle.ShowFrmErrorHandle("提示", "更新失败!");
                return(false);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 记录一个要素的编辑信息(针对删除)   guozheng added
        /// </summary>
        /// <param name="in_OID">删除要素的OID</param>
        /// <param name="in_DateTime">编辑的时间</param>
        /// <param name="in_iVersion">版本</param>
        /// <param name="in_sLayerName">要素所在的图层名</param>
        /// <param name="ex"></param>
        private static void RecordLOG(IWorkspace pSDEWS, int in_OID, DateTime in_DateTime, int in_iVersion, string in_sLayerName, out Exception ex)
        {
            ex = null;

            if (in_DateTime == null)
            {
                ex = new Exception("输入的编辑时间为空"); return;
            }

            ///////////////获取必要信息/////////////////
            //////去掉sde图层带的用户名
            if (in_sLayerName.Contains("."))
            {
                in_sLayerName = in_sLayerName.Substring(in_sLayerName.LastIndexOf('.') + 1);
            }
            int    iOID       = in_OID;       /////////////////////////////要素OID
            string sLayerName = string.Empty; //////////要素图层名
            int    iVersion   = -1;           /////////////////////////版本信息

            sLayerName = in_sLayerName;
            iVersion   = in_iVersion;/////////////获取版本
            if (ex != null)
            {
                return;
            }
            //////////////////写入日志////////////////////////////
            try
            {
                ITransactions LOGTran = pSDEWS as ITransactions;
                LOGTran.StartTransaction();
                ////////写入更新日志表///////
                WriteLog(pSDEWS, iOID, sLayerName, iVersion, in_DateTime, 3, null, out ex);
                if (ex != null)
                {
                    LOGTran.AbortTransaction(); return;
                }
                ////////写入数据库版本表/////
                //WriteDBVersion(iVersion, in_DateTime, this.m_Con, out ex);
                //if (ex != null) { myTrans.Rollback(); }
                ///////修改过程库////////////
                //WriteHisDB(sLayerName, this.m_HisWS, null, in_DateTime, 3, iVersion, out ex);
                WriteHisDB(sLayerName, pSDEWS, in_OID, in_DateTime, in_iVersion, out ex);
                if (ex != null)
                {
                    LOGTran.AbortTransaction(); return;
                }
                LOGTran.CommitTransaction();
            }
            catch (Exception eError)
            {
                //*******************************************************************
                //Exception Log
                if (ModData.SysLog == null)
                {
                    ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                }
                ModData.SysLog.Write(eError, null, DateTime.Now);
                //********************************************************************
                ex = new Exception("编辑要素记录失败。\n原因:" + eError.Message);
                return;
            }
        }
Exemplo n.º 5
0
        public long unversionedEdit(IQueryFilter qFilterGen, int sequenceColumnNum, int idxSeqField, int curLoop, ref ITransactions transactions)
        {
            long sequenceValue = -1;

            using (ComReleaser comReleaser = new ComReleaser())
            {
                if (AAState._gentabWorkspace.IsInEditOperation)
                {
                    // throw new Exception("Cannot use ITransactions during an edit operation.");
                }
                // Begin a transaction.
                if (transactions == null)
                {
                    transactions = (ITransactions)AAState._gentabWorkspace;
                }

                transactions.StartTransaction();
                try
                {
                    // Use ITable.Update to create an update cursor.
                    ICursor seq_updateCursor = AAState._gentab.Update(qFilterGen, true);
                    comReleaser.ManageLifetime(seq_updateCursor);

                    IRow seq_row = null;
                    seq_row = seq_updateCursor.NextRow();
                    int sequenceInt = 1;

                    if (seq_row != null)
                    {
                        if (idxSeqField > 0)
                        {
                            object seqInt = seq_row.get_Value(idxSeqField);
                            if (seqInt != null)
                            {
                                if (seqInt != DBNull.Value)
                                {
                                    try
                                    {
                                        sequenceInt = Convert.ToInt32(seqInt);
                                    }
                                    catch
                                    {
                                    }
                                }
                            }
                        }
                        object seqValue = seq_row.get_Value(sequenceColumnNum);

                        if (seqValue == null)
                        {
                            sequenceValue = 0;
                        }
                        else if (seqValue.ToString() == "")
                        {
                            sequenceValue = 0;
                        }
                        else
                        {
                            try
                            {
                                sequenceValue = Convert.ToInt64(seqValue);
                            }
                            catch
                            {
                                sequenceValue = 0;
                            }
                        }

                        AAState.WriteLine("                  " + sequenceValue + " is the existing value and the interval is " + sequenceInt + ": " + DateTime.Now.ToString("h:mm:ss tt"));

                        sequenceValue = sequenceValue + sequenceInt;

                        seq_row.set_Value(sequenceColumnNum, sequenceValue);
                        AAState.WriteLine("                  " + seq_row.Fields.get_Field(sequenceColumnNum).AliasName + " changed to " + sequenceValue + ": " + DateTime.Now.ToString("h:mm:ss tt"));

                        seq_updateCursor.UpdateRow(seq_row);

                        transactions.CommitTransaction();

                        seq_updateCursor = AAState._gentab.Search(qFilter, true);
                        if (seq_row != null)
                        {
                            seqValue = seq_row.get_Value(sequenceColumnNum);

                            if (seqValue == null)
                            {
                                return(sequenceValue);
                            }
                            else if (seqValue.ToString() == "")
                            {
                                return(sequenceValue);
                            }
                            else
                            {
                                try
                                {
                                    if (sequenceValue == Convert.ToInt64(seqValue))
                                    {
                                        return(sequenceValue);
                                    }
                                    else
                                    {
                                        if (curLoop > 30)
                                        {
                                            MessageBox.Show("A unique ID could not be generated after 30 attempts: " + DateTime.Now.ToString("h:mm:ss tt"));
                                        }
                                        else
                                        {
                                            return(unversionedEdit(qFilterGen, sequenceColumnNum, idxSeqField, curLoop + 1, ref transactions));
                                        }
                                    }
                                }
                                catch
                                {
                                    return(sequenceValue);
                                }
                            }
                        }
                        return(sequenceValue);
                    }
                    else
                    {
                        AAState.WriteLine("                  No records found in Generate ID table" + ": " + DateTime.Now.ToString("h:mm:ss tt"));
                        transactions.AbortTransaction();
                        return(-1);
                    }
                }
                catch (COMException comExc)
                {
                    AAState.WriteLine("                  Error saving transaction to DB" + ": " + DateTime.Now.ToString("h:mm:ss tt"));

                    // If an error occurs during the inserts and updates, rollback the transaction.
                    transactions.AbortTransaction();
                    return(-1);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 记录一个要素的编辑信息
        /// </summary>
        /// <param name="in_Row">编辑要素的IRow</param>
        /// <param name="in_iState">编辑状态:1、新增,2、修改,3、删除</param>
        /// <param name="in_DateTime">编辑的时间</param>
        /// <param name="in_iVersion">版本</param>
        /// <param name="in_sLayerName">要素所在的图层名</param>
        /// <param name="ex"></param>
        public void RecordLOG(IRow in_Row, int in_iState, DateTime in_DateTime, int in_iVersion, string in_sLayerName, out Exception ex)
        {
            ex = null;
            if (in_Row == null)
            {
                ex = new Exception("输入要素为空"); return;
            }
            if (in_DateTime == null)
            {
                ex = new Exception("输入的编辑时间为空"); return;
            }
            IFeature getFea = in_Row as IFeature;

            if (getFea == null)
            {
                ex = new Exception("获取要素失败"); return;
            }
            ///////////////获取必要信息/////////////////
            //////去掉sde图层带的用户名
            if (in_sLayerName.Contains("."))
            {
                in_sLayerName = in_sLayerName.Substring(in_sLayerName.LastIndexOf('.') + 1);
            }
            int    iOID       = -1;           /////////////////////////////要素OID
            string sLayerName = string.Empty; //////////要素图层名
            int    iVersion   = -1;           /////////////////////////版本信息

            if (getFea.HasOID)
            {
                iOID = getFea.OID;
            }
            sLayerName = in_sLayerName;
            iVersion   = in_iVersion;/////////////获取版本
            if (ex != null)
            {
                return;
            }
            //////////////////写入日志////////////////////////////
            try
            {
                ITransactions LOGTran = this.m_HisWS as ITransactions;
                LOGTran.StartTransaction();
                ////////写入更新日志表///////
                WriteLog(iOID, sLayerName, iVersion, in_DateTime, in_iState, getFea.Shape.Envelope, out ex);
                if (ex != null)
                {
                    LOGTran.AbortTransaction(); return;
                }
                ////////写入数据库版本表/////
                //WriteDBVersion(iVersion, in_DateTime, this.m_Con, out ex);
                //if (ex != null) { myTrans.Rollback(); }
                ///////修改过程库////////////
                WriteHisDB(sLayerName, this.m_HisWS, getFea, in_DateTime, in_iState, iVersion, out ex);
                if (ex != null)
                {
                    LOGTran.AbortTransaction(); return;
                }
                LOGTran.CommitTransaction();
            }
            catch (Exception eError)
            {
                //******************************************
                //guozheng added System Exception log
                if (SysCommon.Log.Module.SysLog == null)
                {
                    SysCommon.Log.Module.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                }
                SysCommon.Log.Module.SysLog.Write(eError);
                //******************************************
                ex = eError;
                return;
            }
        }