Пример #1
0
        //删除记录菜单响应
        public override void OnClick()
        {
            if (m_Hook.GridCtrl == null)
            {
                return;
            }
            FaceControl  pfacecontrol = (FaceControl)m_Hook.MainUserControl;
            DataGridView pGridControl = m_Hook.GridCtrl;

            if (pfacecontrol.getEditable() == false)
            {
                return;
            }
            string connstr, Tablename;

            //获取数据库连接串和表名
            connstr   = pfacecontrol.m_connstr;
            Tablename = pfacecontrol.m_TableName;
            if (Tablename.Contains("."))
            {
                Tablename = Tablename.Split('.')[1];//处理SDE表
            }
            FaceControl pFaceControl = (FaceControl)(m_Hook.MainUserControl);

            if (pGridControl.DataSource == null)
            {
                return;
            }
            //如果未选中记录...
            if (pGridControl.SelectedRows.Count == 0)
            {
                DevComponents.DotNetBar.MessageBoxEx.Show("未选中记录!");
                return;
            }
            int k = pGridControl.SelectedRows.Count;

            //删除数据时,要询问一次
            if (pGridControl.SelectedRows.Count > 0)
            {
                if (DevComponents.DotNetBar.MessageBoxEx.Show("确定要删除选中的记录吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
            }

            //OleDbConnection mycon = new OleDbConnection(connstr);   //定义OleDbConnection对象实例并连接数据库
            //string strExp = "";
            //OleDbCommand aCommand = new OleDbCommand(strExp, mycon);
            //mycon.Open();
            //int i = 0, j = 0;
            if (GeoDataCenterFunLib.LogTable.m_sysTable == null)
            {
                return;
            }
            Exception err;
            ITable    pTable = LogTable.m_sysTable.OpenTable(Tablename, out err);

            if (pTable == null)
            {
                //MessageBox.Show(err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ErrorHandle.ShowFrmErrorHandle("提示", err.Message);
                return;//若日志表不存在,返回null
            }
            if (pGridControl.SelectedRows.Count > 0)
            {
                string objectID = pTable.OIDFieldName;
                string strExp   = objectID + " IN (";
                for (int h = 0; h < pGridControl.SelectedRows.Count; h++)
                {
                    //构造删除记录的语句

                    for (int i = 0; i < pGridControl.ColumnCount; i++)
                    {
                        if (pGridControl.Columns[i].Name.ToUpper().Equals("ID"))
                        {
                            strExp += pGridControl.SelectedRows[h].Cells[i].Value.ToString() + ",";
                        }
                    }
                }
                strExp  = strExp.Substring(0, strExp.Length - 1);
                strExp += ")";
                //执行删除记录的语句段
                IWorkspace    pWorkspace    = LogTable.m_gisDb.WorkSpace;
                ITransactions pTransactions = (ITransactions)pWorkspace;
                try
                {
                    if (!pTransactions.InTransaction)
                    {
                        pTransactions.StartTransaction();
                    }
                }
                catch (Exception eX)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", eX.Message);
                    return;
                }
                Exception exError;
                if (!LogTable.m_sysTable.DeleteRows(Tablename, strExp, out exError))
                {
                    ErrorHandle.ShowFrmErrorHandle("提示", "删除记录失败!" + exError.Message);
                    return;
                }

                try
                {
                    if (pTransactions.InTransaction)
                    {
                        pTransactions.CommitTransaction();
                    }
                }
                catch (Exception eX)
                {
                }
            }


            //再次初始化datagridview控件
            pfacecontrol.InitDataInfoList(Tablename);

            ////ZQ   20111017   add  及时更新数据字典
            switch (Tablename)
            {
            case "属性对照表":
                SysCommon.ModField.InitNameDic(Plugin.ModuleCommon.TmpWorkSpace, SysCommon.ModField._DicFieldName, "属性对照表");
                break;

            case "标准图层代码表":
                SysCommon.ModField.InitLayerNameDic(Plugin.ModuleCommon.TmpWorkSpace, SysCommon.ModField._DicLayerName);
                break;
                //default:
                //    ///ZQ 20111020 add 增加重启提示
                //    MessageBox.Show("删除的记录只有应用系统重启以后才能生效!", "提示!");
                //    break;
            }
            /////
            if (this.WriteLog)
            {
                Plugin.LogTable.Writelog(Caption);//xisheng 2011.07.09 增加日志
            }

            /*       Exception eError;
             *     AddGroup frmGroup = new AddGroup();
             *     if (frmGroup.ShowDialog() == DialogResult.OK)
             *     {
             *         ModuleOperator.DisplayRoleTree("", m_Hook.RoleTree, ref ModData.gisDb, out eError);
             *         if (eError != null)
             *         {
             *             ErrorHandle.ShowFrmError("提示", eError.Message);
             *             return;
             *         }
             *     }
             */
        }
Пример #2
0
        //添加记录菜单响应
        public override void OnClick()
        {
            if (m_Hook.GridCtrl == null)
            {
                return;
            }
            FaceControl  pFaceControl = (FaceControl)m_Hook.MainUserControl;
            DataGridView pGridControl = m_Hook.GridCtrl;

            if (pFaceControl.getEditable() == false)
            {
                return;
            }
            string Tablename = "";

            //获取数据库连接串和表名
            Tablename = pFaceControl.m_TableName;
            OpenFileDialog pOpenFileDlg = new OpenFileDialog();

            pOpenFileDlg.Title  = "选择导入的Excel文件";
            pOpenFileDlg.Filter = "Excel文件(*.xls)|*.xls|文本文档(*.txt)|*.txt";
            if (pOpenFileDlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string       strFileName = pOpenFileDlg.FileName;
            DialogResult pResult     = MessageBox.Show("是覆盖已有记录(Y)还是追加导入(N)?", "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
            bool         isCovered   = true;

            if (pResult == DialogResult.Yes)
            {
                isCovered = true;
            }
            else if (pResult == DialogResult.No)
            {
                isCovered = false;
            }
            else
            {
                return;
            }
            ///增加导入文本文档功能  ZQ 20111101
            switch (System.IO.Path.GetExtension(strFileName))
            {
            case ".xls":
                ModDBOperate.ImportExcelToTableEx(strFileName, Tablename, isCovered);
                break;

            case ".txt":
                ModDBOperate.ImportTextToTable(strFileName, Tablename, isCovered);
                break;
            }

            //if (result == DialogResult.OK)//changed by xisheng 2011.06.16
            //{ //记录添加后再次初始化dataview控件
            pFaceControl.InitDataInfoList(Tablename, true);
            //}
            //else
            //{
            //    pFaceControl.InitDataInfoList(Tablename, false);
            //}
            if (this.WriteLog)
            {
                Plugin.LogTable.Writelog(Caption);//xisheng 2011.07.09 增加日志
            }
        }
Пример #3
0
        //添加记录菜单响应
        public override void OnClick()
        {
            if (m_Hook.GridCtrl == null)
            {
                return;
            }
            FaceControl  pfacecontrol = (FaceControl)m_Hook.MainUserControl;
            DataGridView pGridControl = m_Hook.GridCtrl;

            if (pfacecontrol.getEditable() == false)
            {
                return;
            }
            string connstr, Tablename;

            //获取数据库连接串和表名
            connstr   = pfacecontrol.m_connstr;
            Tablename = pfacecontrol.m_TableName;
            FaceControl pFaceControl = (FaceControl)(m_Hook.MainUserControl);

            if (pGridControl.DataSource == null)
            {
                return;
            }
            //如果未选中记录。。。
            if (pGridControl.SelectedRows.Count == 0)
            {
                MessageBox.Show("未选中记录!");
                return;
            }
            //如果选中多行记录。。。
            if (pGridControl.SelectedRows.Count > 1)
            {
                MessageBox.Show("仅可修改一行!");
                return;
            }
            int idx = pGridControl.SelectedRows[0].Index;//yjl20111103 add
            //初始化修改记录对话框
            TableForm myTableForm = new TableForm(pGridControl, connstr, Tablename);

            myTableForm.InitForm("MODIFY");
            myTableForm.ShowDialog();
            //记录修改后再次初始化dataview控件
            pfacecontrol.InitDataInfoList(Tablename);
            ////ZQ   20111017   add  及时更新数据字典
            switch (Tablename)
            {
            case "属性对照表":
                SysCommon.ModField.InitNameDic(Plugin.ModuleCommon.TmpWorkSpace, SysCommon.ModField._DicFieldName, "属性对照表");
                break;

            case "标准图层代码表":
                SysCommon.ModField.InitLayerNameDic(Plugin.ModuleCommon.TmpWorkSpace, SysCommon.ModField._DicLayerName);
                break;
                //default:
                //    ///ZQ 20111020 add 增加重启提示
                //    MessageBox.Show("修改的记录只有应用系统重启以后才能生效!", "提示!");
                //    break;
            }


            //yjl20111103 add
            if (pGridControl.Rows.Count > idx)
            {
                //取消默认的第1行选中
                pGridControl.Rows[0].Selected = false;
                //设置选择行
                pGridControl.Rows[idx].Selected = true;
                //设置当前行
                pGridControl.CurrentCell = pGridControl.Rows[idx].Cells[0];
            }
            /////
            if (this.WriteLog)
            {
                Plugin.LogTable.Writelog(Caption);//xisheng 2011.07.09 增加日志
            }

            /*       Exception eError;
             *     AddGroup frmGroup = new AddGroup();
             *     if (frmGroup.ShowDialog() == DialogResult.OK)
             *     {
             *         ModuleOperator.DisplayRoleTree("", m_Hook.RoleTree, ref ModData.gisDb, out eError);
             *         if (eError != null)
             *         {
             *             ErrorHandle.ShowFrmError("提示", eError.Message);
             *             return;
             *         }
             *     }
             */
        }
Пример #4
0
        //全部删除菜单响应
        public override void OnClick()
        {
            if (m_Hook.GridCtrl == null)
            {
                return;
            }
            FaceControl  pfacecontrol = (FaceControl)m_Hook.MainUserControl;
            DataGridView pGridControl = m_Hook.GridCtrl;

            if (pfacecontrol.getEditable() == false)
            {
                return;
            }
            string connstr, Tablename;

            //获取数据库连接串和表名
            connstr   = pfacecontrol.m_connstr;
            Tablename = pfacecontrol.m_TableName;
            if (Tablename.Contains("."))
            {
                Tablename = Tablename.Split('.')[1];//处理SDE表
            }
            FaceControl pFaceControl = (FaceControl)(m_Hook.MainUserControl);

            if (pGridControl.DataSource == null)
            {
                return;
            }
            //删除数据时要询问一次
            if (DevComponents.DotNetBar.MessageBoxEx.Show("确定要全部删除吗?删除后不可恢复!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }
            try
            {
                if (GeoDataCenterFunLib.LogTable.m_sysTable == null)
                {
                    return;
                }
                Exception ex = null;
                LogTable.m_sysTable.DeleteRows(Tablename, "", out ex);//删除
                if (ex != null)
                {
                    throw new Exception("删除全部数据失败!", ex);
                }
            }
            catch (Exception pEx)
            {
                DevComponents.DotNetBar.MessageBoxEx.Show(pEx.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            pfacecontrol.InitDataInfoList(Tablename);
            ////ZQ   20111017   add  及时更新数据字典
            switch (Tablename)
            {
            case "属性对照表":
                SysCommon.ModField.InitNameDic(Plugin.ModuleCommon.TmpWorkSpace, SysCommon.ModField._DicFieldName, "属性对照表");
                break;

            case "标准图层代码表":
                SysCommon.ModField.InitLayerNameDic(Plugin.ModuleCommon.TmpWorkSpace, SysCommon.ModField._DicLayerName);
                break;
                //default:
                //    ///ZQ 20111020 add 增加重启提示
                //    MessageBox.Show("删除的记录只有应用系统重启以后才能生效!", "提示!");
                //    break;
            }
            /////
            if (this.WriteLog)
            {
                Plugin.LogTable.Writelog(Caption);//xisheng 2011.07.09 增加日志
            }
            //OleDbConnection mycon = new OleDbConnection(connstr);   //定义OleDbConnection对象实例并连接数据库
            ////构造删除数据的语句
            //string strExp = "delete from " + Tablename ;
            //OleDbCommand aCommand = new OleDbCommand(strExp, mycon);
            //mycon.Open();
            ////执行删除语句
            //aCommand.ExecuteNonQuery();
            //mycon.Close();
            ////再次初始化datagridview控件
            //pfacecontrol.InitDataInfoList(Tablename );

            //if (m_Hook != null)
            //{
            //    LogFile log = new LogFile(m_Hook.tipRichBox, m_Hook.strLogFilePath);
            //    if (log != null)
            //    {
            //        log.Writelog("数据全部删除");

            //    }
            //}

            /*       Exception eError;
             *     AddGroup frmGroup = new AddGroup();
             *     if (frmGroup.ShowDialog() == DialogResult.OK)
             *     {
             *         ModuleOperator.DisplayRoleTree("", m_Hook.RoleTree, ref ModData.gisDb, out eError);
             *         if (eError != null)
             *         {
             *             ErrorHandle.ShowFrmError("提示", eError.Message);
             *             return;
             *         }
             *     }
             */
        }
Пример #5
0
        //添加记录菜单响应
        public override void OnClick()
        {
            if (m_Hook.GridCtrl == null)
            {
                return;
            }
            FaceControl  pfacecontrol = (FaceControl)m_Hook.MainUserControl;
            DataGridView pGridControl = m_Hook.GridCtrl;

            if (pfacecontrol.getEditable() == false)
            {
                return;
            }
            string connstr, Tablename;

            //获取数据库连接串和表名
            connstr   = pfacecontrol.m_connstr;
            Tablename = pfacecontrol.m_TableName;
            FaceControl pFaceControl = ( FaceControl )(m_Hook.MainUserControl);

            if (pGridControl.DataSource == null)
            {
                return;
            }
            //初始化添加记录对话框
            TableForm myTableForm = new TableForm(pGridControl, connstr, Tablename);

            myTableForm.InitForm("ADD");
            DialogResult result = myTableForm.ShowDialog();

            if (result == DialogResult.OK) //changed by xisheng 2011.06.16
            {                              //记录添加后再次初始化dataview控件
                pfacecontrol.InitDataInfoList(Tablename, true);
            }
            else
            {
                pfacecontrol.InitDataInfoList(Tablename, false);
            }
            ////ZQ   20111017   add  及时更新数据字典
            switch (Tablename)
            {
            case "属性对照表":
                SysCommon.ModField.InitNameDic(Plugin.ModuleCommon.TmpWorkSpace, SysCommon.ModField._DicFieldName, "属性对照表");
                break;

            case "标准图层代码表":
                SysCommon.ModField.InitLayerNameDic(Plugin.ModuleCommon.TmpWorkSpace, SysCommon.ModField._DicLayerName);
                break;
                //default:
                //    ///ZQ 20111020 add 增加重启提示
                //    MessageBox.Show("添加的记录只有应用系统重启以后才能生效!","提示!");
                //    break;
            }
            /////
            if (this.WriteLog)
            {
                Plugin.LogTable.Writelog(Caption);//xisheng 2011.07.09 增加日志
            }
            //OleDbCommandBuilder builder = new OleDbCommandBuilder(pFaceControl.m_Adapter );
            ////将数据提交到数据库更新
            //try
            //{
            //    pFaceControl.m_Adapter.Update(pFaceControl.m_dataTable);
            //    //提交后重新获取数据
            //    pFaceControl.m_dataTable.Clear();
            //    pFaceControl.m_Adapter.Fill(pFaceControl.m_dataTable);
            //    pGridControl.DataSource = null;
            //    pGridControl.DataSource = pFaceControl.m_dataTable;
            //    //gridControl.Update();
            //}
            //catch (System.Exception m)
            //{
            //    Console.WriteLine(m.Message);
            //}
            //pGridControl = null;
            //pFaceControl = null;

            /*       Exception eError;
             *     AddGroup frmGroup = new AddGroup();
             *     if (frmGroup.ShowDialog() == DialogResult.OK)
             *     {
             *         ModuleOperator.DisplayRoleTree("", m_Hook.RoleTree, ref ModData.gisDb, out eError);
             *         if (eError != null)
             *         {
             *             ErrorHandle.ShowFrmError("提示", eError.Message);
             *             return;
             *         }
             *     }
             */
        }