private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (ofdReport.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { using (var xmlfile = new FileStream(ofdReport.FileName, FileMode.Open, FileAccess.Read)) { XmlDocument xmlreport = new XmlDocument(); xmlreport.Load(xmlfile); //TODO: Validate scheme against XSD: //metadata.Validate(...) WFReport.DataReport.Report report = new DataReport.Report(); XmlNode node = xmlreport.ChildNodes[0]; while (node.Name != "report") { node = node.NextSibling; } string cTable = null, cColumn = null; string rTable = null, rColumn = null; string aColumn = null; string cGroup = null, rGroup = null; string metadatapath = null; string dbname = null; currentReport = new DataReport.Report(); foreach (XmlElement i in node) { if (i.Name == "dbname") { dbname = i.InnerText; metadatapath = i.Attributes["metadata"].Value; if (currentPathMetadata == null) { try { LoadMetadataFromFile(metadatapath); } catch(Exception ex) { MessageBox.Show("Error while loading metadata from the report. Please try to load the metadata manually.\nThe error description:\n" + ex.Message, "Error while loading metadata", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } if (i.Name == "visible") { var dict = ParseVisibleData(i); if (dict.Keys.Contains("ctable")) cTable = dict["ctable" ]; if (dict.Keys.Contains("ccolumn")) cColumn = dict["ccolumn"]; if (dict.Keys.Contains("cgroup")) cGroup = dict["cgroup"]; if (dict.Keys.Contains("rtable")) rTable = dict["rtable"]; if (dict.Keys.Contains("rcolumn")) rColumn = dict["rcolumn"]; if (dict.Keys.Contains("rgroup")) rGroup = dict["rgroup"]; if (dict.Keys.Contains("aggrname")) aColumn = dict["aggrname"]; currentReport.cTable = currentDB.Tables[cTable]; currentReport.cColumn = currentReport.cTable.Columns[cColumn]; currentReport.cGroup = cGroup ?? ""; currentReport.rTable = currentDB.Tables[rTable]; currentReport.rColumn = currentReport.rTable.Columns[rColumn]; currentReport.rGroup = rGroup ?? ""; currentReport.aTable = currentDB.Operations; currentReport.aColumn = currentReport.aTable.Columns[aColumn]; } if (i.Name == "fixeddata") { currentReport.restrictions = ParseFixedData(i); } } currentPathReport = ofdReport.FileName; pnlLeft.Enabled = true; UpdateUIwithMetadata(); for (int k = 0; k < lbxImportantFields.Items.Count; k++) lbxImportantFields.SetItemChecked(k, true); UpdateUIwithReportData(); } } catch (Exception ex) { MessageBox.Show("Error while opening the file \"" + ofdReport.FileName + "\":\n" + ex.Message, "Unable to read the report", MessageBoxButtons.OK, MessageBoxIcon.Error); currentReport = null; currentPathReport = null; } } }
private void mimFileNew_Click(object sender, EventArgs e) { if (currentDB == null) { MessageBox.Show("Database is not loaded. Please use \"Open metadata\" command (Ctrl+M)", "No database", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } currentReport = new DataReport.Report(); currentPathReport = null; pnlLeft.Enabled = true; }
private void openMetadataToolStripMenuItem_Click(object sender, EventArgs e) { if (ofdMetadata.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { LoadMetadataFromFile(ofdMetadata.FileName); UpdateUIwithMetadata(); for (int i = 0; i < lbxImportantFields.Items.Count; i++) lbxImportantFields.SetItemChecked(i, true); MessageBox.Show("The description of the database \"" + currentDB.Name + "\"" + " was loaded successfully!", "Database metadata loaded", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Error while opening the file \"" + ofdMetadata.FileName + "\":\n" + ex.Message, "Unable to open the file", MessageBoxButtons.OK, MessageBoxIcon.Error); currentDB = null; currentReport = null; currentPathMetadata = null; currentPathReport = null; } } }