private bool InsertAppStructs() { try { foreach (LogApp app in m_apps) { if (AppService.Instance.AddApp(LogApp.CreateApp(app.Name, app.AppGUID, app.IsImportLogsFromFiles))) { foreach (LogTable table in app.Tables) { if (AppService.Instance.AddTable(app.AppGUID, LogTable.CreateLogTable(table.Name, table.GUID))) { if (!AppService.Instance.AddTableItems(app.AppGUID, table.GUID, table.Columns)) { throw new Exception(string.Format("应用程序{0}的表{1}插入列出错", new object[] { app.Name, table.Name })); } } else { throw new Exception(string.Format("在应用程序{0}中插入表{1}出错", new object[] { app.Name, table.Name })); } } } else { throw new Exception(string.Format("插入应用程序{0}记录出错", app.Name)); } } return(true); } catch (Exception ex) { throw new Exception("插入日志表结构失败,错误消息为:" + ex.Message); } }
private void button1_Click(object sender, EventArgs e) { if (!IsAnyLogTableSelected()) { MessageBox.Show("请先选中要导入结构的日志表"); } SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = "日志表结构.xml"; sfd.Filter = "xml 文件(*.xml)|*.xml"; if (sfd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { lblStatus.Text = sfd.FileName; XmlTextWriter writer = null; try { List <LogApp> lstApps = new List <LogApp>(); List <LogTable> lstTables = null; foreach (TreeNode tn in this.treeView1.Nodes) { lstTables = null; string appGuid = Convert.ToString(tn.Tag); foreach (TreeNode tnSon in tn.Nodes) { if (tnSon.Checked) { if (lstTables == null) { lstTables = new List <LogTable>(); } string tableGuid = Convert.ToString(tnSon.Tag); LogTable table = (LogTable)AppService.Instance.GetAppTable(appGuid, tableGuid).Clone(); foreach (LogTableItem item in table.Columns) { item.ColumnName = LogColumnService.Instance.GetColumnName(item.LogColumnIndex); } lstTables.Add(table); } } if (lstTables != null) { LogApp srcApp = AppService.Instance.GetApp(appGuid); LogApp app = LogApp.CreateApp(srcApp.Name, srcApp.AppGUID, srcApp.IsImportLogsFromFiles); app.Tables.AddRange(lstTables); lstApps.Add(app); lstTables = null; } } writer = new XmlTextWriter(sfd.FileName, Encoding.Default); XmlSerializer serializer = new XmlSerializer(typeof(List <LogApp>)); serializer.Serialize(writer, lstApps); } catch (Exception ex) { MessageBox.Show("导出日志表结构失败,错误消息为:" + ex.Message); } finally { if (writer != null) { writer.Close(); } } } }