private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { try { EDIInformation par = e.Argument as EDIInformation; StreamReader sr = new StreamReader(par.EDIFileName); string fileContent = sr.ReadToEnd(); sr.Close(); sr.Dispose(); XmlToDataTable xmlToDataTable = new XmlToDataTable(DataSource); e.Result = xmlToDataTable.Parse(par.Xslt, fileContent).ToString(); } catch (Exception ex) { e.Result = "Error:" + ex.Message; } }
private void lvwSamples_SelectedIndexChanged(object sender, EventArgs e) { if (lvwSamples.SelectedItems.Count > 0) { btnSelect.Enabled = true; btnExport1.Enabled = true; btnExport2.Enabled = true; btnExport3.Enabled = true; btnExport4.Enabled = true; btnExportAll.Enabled = true; this.Cursor = Cursors.WaitCursor; SampleInformation = (XmlSampleInformation)lvwSamples.SelectedItems[0].Tag; StreamWriter sw = new StreamWriter(SampleInformation.XmlFileName); sw.Write(SampleInformation.Xml); sw.Close(); webBrowser2.Url = new Uri(SampleInformation.XmlFileName); sw = new StreamWriter(SampleInformation.XsltFileName); sw.Write(SampleInformation.Xslt); sw.Close(); webBrowser1.Url = new Uri(SampleInformation.XsltFileName); rtbCSharpCode.Rtf = SampleInformation.CSharpCode; XmlToDataTable xmlToDataTable = new XmlToDataTable(); rtbFlatFile.Text = xmlToDataTable.Parse(SampleInformation.Xslt, SampleInformation.Xml).ToString(); this.Cursor = Cursors.Default; } else { btnSelect.Enabled = false; btnExport1.Enabled = false; btnExport2.Enabled = false; btnExport3.Enabled = false; btnExport4.Enabled = false; btnExportAll.Enabled = false; } }
private void btnTransform_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; try { StreamReader sr = new StreamReader(txtSampleFile.Text); string fileContent = sr.ReadToEnd(); sr.Close(); sr.Dispose(); if (radXslt.Checked) { XmlToDataTable xmlToDataTable = new XmlToDataTable(DataSource); rtbSampleOutput.Text = xmlToDataTable.Parse(rtbXslt.Text, fileContent).ToString(); } else if (radCSharpCode.Checked) { rtbSampleOutput.Text = ""; CSharpCodeToDataTable cSharpCodeToDataTable = new CSharpCodeToDataTable(DataSource); DataTable table = cSharpCodeToDataTable.Parse(new StringBuilder(fileContent), cSharpExpression1.CSharpCodeInformation); string tempFileName = Path.Combine(Information.TempDirectoryTempData, "temp.csv"); table.ToCsv(tempFileName); StreamReader srTempFile = new StreamReader(tempFileName); string oneLine = srTempFile.ReadLine(); //skip first line while ((oneLine = srTempFile.ReadLine()) != null) { rtbSampleOutput.Text += oneLine + Environment.NewLine; } srTempFile.Close(); } } catch (Exception ex) { this.Cursor = Cursors.Default; MessageBox.Show(ex.Message); } this.Cursor = Cursors.Default; }