//按钮的click事件 public override void OnClick() { string pSysName = ""; //数据集成管理子系统Name string pSysCaption = ""; //数据集成管理子系统Caption pSysName = "GeoDBIntegration.ControlDBIntegrationTool"; //根据Name获得子系统的caption XmlDocument sysXml = new XmlDocument(); sysXml.Load(ModFrameData.m_SysXmlPath); XmlNode sysNode = sysXml.SelectSingleNode("//Main//System[@Name='" + pSysName + "']"); if (sysNode == null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "不存在Name为" + pSysName + "的系统"); return; } pSysCaption = (sysNode as XmlElement).GetAttribute("Caption").Trim(); //caption //进入数据中心管理子系统界面 ModDBOperate.InitialForm(pSysName, pSysCaption); //功能日志 enter feature Db Log if (ModFrameData.v_SysLog != null) { List <string> Pra = new List <string>(); ModFrameData.v_SysLog.Write("进入集成管理子系统", Pra, DateTime.Now); } }
//重载,added by xisheng 2011.06.16 public void InitDataInfoList(string strTblName, bool boolreturn) { if (strTblName.Equals("")) { return; } IWorkspace pTmpWorkSpace = Plugin.ModuleCommon.TmpWorkSpace; if (pTmpWorkSpace == null) { return; } ModDBOperate.boolreturn = boolreturn; DataTable pDatatable = ModDBOperate.GetQueryTable(pTmpWorkSpace as IFeatureWorkspace, strTblName, ""); m_dataTable = pDatatable; this.gridControl.DataSource = null; this.gridControl.DataSource = pDatatable; }
//添加记录菜单响应 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 增加日志 } }
//根据tblName获取对应的数据信息填充到listview中 public void InitDataInfoList(string strTblName) { if (strTblName.Equals("")) { return; } IWorkspace pTmpWorkSpace = Plugin.ModuleCommon.TmpWorkSpace; if (pTmpWorkSpace == null) { return; } /* SysCommon.Gis.SysGisTable pSystable = new SysCommon.Gis.SysGisTable(pTmpWorkSpace); * Exception eError = null; * ITable pTable = pSystable.OpenTable(strTblName, out eError); * if (pTable == null) * { * return; * } * DataTable pDatatable = new DataTable(); * DataRow pRow = pDatatable.NewRow(); * DataColumn pColumn = new DataColumn(); * * this.gridControl.DataSource = null; * this.gridControl.DataSource = pTable;*/ DataTable pDatatable = ModDBOperate.GetQueryTable(pTmpWorkSpace as IFeatureWorkspace, strTblName, ""); m_dataTable = pDatatable; this.gridControl.DataSource = null; this.gridControl.DataSource = pDatatable; //目前直接读取mdb文件,需要修改为配置模式 /* GetDataTreeInitIndex dIndex = new GetDataTreeInitIndex(); * string mypath = dIndex.GetDbInfo(); * //string mypath = dIndex.GetDbValue("dbServerPath"); * string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mypath + ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"; //生成连接数据库字符串 * m_connstr = constr; * OleDbConnection mycon = new OleDbConnection(constr); //定义OleDbConnection对象实例并连接数据库 * string strExp = ""; * strExp = "select * from " + strTblName; * OleDbCommand aCommand = new OleDbCommand(strExp, mycon); * try * { * mycon.Open(); * * //创建datareader 对象来连接到表单 * OleDbDataReader aReader = aCommand.ExecuteReader(); * DataTable dt = new DataTable(); * OleDbDataAdapter da = new OleDbDataAdapter(strExp, constr); * m_Adapter = null; * m_dataTable = null; * m_Adapter = da; * m_dataTable = dt; * da.Fill(dt); * this.gridControl.DataSource = null; * this.gridControl.DataSource = dt; * * * //关闭reader对象 * aReader.Close(); * * //关闭连接,这很重要 * mycon.Close(); * * } * catch (System.Exception e) * { * Console.WriteLine(e.Message); * } */ //获取数据库中的内容 }