private void Logs_Click(object sender, EventArgs e) { try { DialogResult Proceed = MessageBox.Show("Unsaved changes will be lost, would you like to proceed?", "Proceed?", MessageBoxButtons.YesNo); if (Proceed == DialogResult.No) { return; } File.Copy(@"C:\ProgramData\SummitHealthcare\Summit_Crosswalk_Manager\LogFiles\logfile.txt", "Audit.txt", true); string[] Audit = File.ReadAllLines("Audit.txt"); // Set Progress Bar MainProBar.Visible = true; MainProBar.Minimum = 1; MainProBar.Maximum = (Audit.Length + 3); MainProBar.Value = 1; MainProBar.Step = 1; MainProBar.PerformStep(); Array.Reverse(Audit); List <string> Info = new List <string>(); for (int i = 0; i < Audit.Length; i++) { if (Audit[i].IndexOf("] INFO") != -1) { Info.Add(Audit[i]); } MainProBar.PerformStep(); } String[] AuditLog = Info.ToArray(); MainDataGrid.DataSource = AuditLog.Select(x => new { Audit_Log = x }).ToList(); //Populate Row Count Lable RowCount.Text = MainDataGrid.Rows.Count.ToString(); int Rows = int.Parse(RowCount.Text); RowCount.Text = Rows.ToString(); ColumnCount.Text = MainDataGrid.Columns.Count.ToString(); SourceTXT.Text = "AUDIT"; Tables.Text = "Audit"; Current.Text = ""; Total.Text = ""; Properties.Settings.Default.Search = ""; MainProBar.PerformStep(); log.Info(UserTXT.Text + " - Viewed Audit Log"); } catch (Exception ex) { log.Error(ex); MessageBox.Show(ex.Message.ToString()); } }
private void Report_Click(object sender, EventArgs e) { try { // Set Progress Bar MainProBar.Visible = true; MainProBar.Minimum = 1; MainProBar.Maximum = 18; MainProBar.Value = 1; MainProBar.Step = 1; MainProBar.PerformStep(); //Check if file 1 is safe and valid. if (OriginalPath.Text == null || OriginalPath.Text == string.Empty) { MessageBox.Show("File 1 not selected, please select"); MainProBar.Value = 1; return; } MainProBar.PerformStep(); if (!File.Exists(OriginalPath.Text)) { MessageBox.Show("File 1 doesnt exist, please select another file"); MainProBar.Value = 1; return; } MainProBar.PerformStep(); //Check if file 2 is safe and valid. if (ComparePath.Text == null || ComparePath.Text == string.Empty) { MessageBox.Show("File 2 not selected, please select"); MainProBar.Value = 1; return; } MainProBar.PerformStep(); if (!File.Exists(ComparePath.Text)) { MessageBox.Show("File 2 doesnt exist, please select another file"); MainProBar.Value = 1; return; } MainProBar.PerformStep(); //Call DoCompare which will compare two files. MainProBar.PerformStep(); DoCompare(OriginalPath.Text, ComparePath.Text); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); MainProBar.Value = 1; } }
private void Download_Click(object sender, EventArgs e) { try { log.Info(UserTXT.Text + " - Started SQL Download"); // Set Progress Bar MainProBar.Visible = true; MainProBar.Minimum = 1; MainProBar.Maximum = 7; MainProBar.Value = 1; MainProBar.Step = 1; MainProBar.PerformStep(); //Sql to download Table contents MainProBar.PerformStep(); string strConnection = ConnectionStrings.Text; string strTable = Tables.Text; SqlConnection con = new SqlConnection(strConnection); SqlCommand sqlCmdDownload = new SqlCommand(); sqlCmdDownload.Connection = con; sqlCmdDownload.CommandType = CommandType.Text; sqlCmdDownload.CommandText = "Select * from [" + strTable + "]"; SqlDataAdapter sqlDataAdap = new SqlDataAdapter(sqlCmdDownload); MainProBar.PerformStep(); log.Info(strTable); //Populate DataGrid with Table contents MainProBar.PerformStep(); DataTable dtRecord = new DataTable(); sqlDataAdap.Fill(dtRecord); MainDataGrid.DataSource = dtRecord; MainProBar.PerformStep(); //Populate Row count Lable MainProBar.PerformStep(); RowCount.Text = MainDataGrid.Rows.Count.ToString(); int Rows = int.Parse(RowCount.Text) - 1; RowCount.Text = Rows.ToString(); ColumnCount.Text = MainDataGrid.Columns.Count.ToString(); SourceTXT.Text = "SQL"; Current.Text = ""; Total.Text = ""; Properties.Settings.Default.Search = ""; MainProBar.PerformStep(); log.Info(UserTXT.Text + " - Finished SQL Download"); } catch (Exception ex) { log.Error(ex); MessageBox.Show(ex.Message.ToString()); MainProBar.Value = 1; } }
private void Export_Click(object sender, EventArgs e) { try { MainProBar.Visible = true; MainProBar.Minimum = 1; MainProBar.Maximum = 8; MainProBar.Value = 1; MainProBar.Step = 1; MainProBar.PerformStep(); SaveFileDialog sfd = new SaveFileDialog(); MainProBar.PerformStep(); sfd.Filter = "HTML files (*.htm)|*.htm"; MainProBar.PerformStep(); sfd.FileName = "Compare_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".htm"; MainProBar.PerformStep(); if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { MainProBar.PerformStep(); // If they've selected a save location... using (System.IO.StreamWriter sw = new System.IO.StreamWriter(sfd.FileName, false)) { // Write the stringbuilder text to the the file. sw.WriteLine(ReportWindow.DocumentText.ToString()); MainProBar.PerformStep(); } MainProBar.PerformStep(); MainProBar.PerformStep(); } else { MainProBar.Value = 1; } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); MainProBar.Value = 1; } }
public void DoCompare(string file1, string file2) { try { MainProBar.Visible = true; MainProBar.Minimum = 1; MainProBar.Maximum = 18; MainProBar.Value = 6; MainProBar.Step = 1; MainProBar.PerformStep(); //Convert HL7 to XML System.IO.StreamReader InputFile = new System.IO.StreamReader(file1); string InputHL7 = InputFile.ReadToEnd(); InputFile.Close(); InputHL7 = InputHL7.Replace((Char)127, (Char)13); String InputHL7asXml = HL7ToXmlConverter.ConvertToXml(InputHL7, ""); string myTempFile1 = Path.Combine(Path.GetTempPath(), "Input.xml"); System.IO.StreamWriter fileI = new System.IO.StreamWriter(myTempFile1); fileI.WriteLine(InputHL7asXml); fileI.Close(); file1 = myTempFile1; MainProBar.PerformStep(); System.IO.StreamReader OutputFile = new System.IO.StreamReader(file2); string OutputHL7 = OutputFile.ReadToEnd(); OutputFile.Close(); OutputHL7 = OutputHL7.Replace((Char)127, (Char)13); String OutputHL7asXml = HL7ToXmlConverter.ConvertToXml(OutputHL7, ""); string myTempFile2 = Path.Combine(Path.GetTempPath(), "Output.xml"); System.IO.StreamWriter fileO = new System.IO.StreamWriter(myTempFile2); fileO.WriteLine(OutputHL7asXml); fileO.Close(); file2 = myTempFile2; MainProBar.PerformStep(); string startupPath = Application.StartupPath; //output diff file. diffFile = startupPath + Path.DirectorySeparatorChar + "vxd.out"; XmlTextWriter tw = new XmlTextWriter(new StreamWriter(diffFile)); tw.Formatting = Formatting.Indented; MainProBar.PerformStep(); //This method sets the diff.Options property. SetDiffOptions(); bool isEqual = false; //Now compare the two files. try { isEqual = diff.Compare(file1, file2, compareFragments, tw); } catch (XmlException xe) { xe.StackTrace.ToString(); //MessageBox.Show("An exception occured while comparing\n" + xe.StackTrace); } finally { tw.Close(); } MainProBar.PerformStep(); if (isEqual) { //This means the files were identical for given options. MessageBox.Show("Files Identical for the given options"); MainProBar.Value = 1; return; //dont need to show the differences. } MainProBar.PerformStep(); //Files were not equal, so construct XmlDiffView. XmlDiffView dv = new XmlDiffView(); //Load the original file again and the diff file. XmlTextReader orig = new XmlTextReader(file1); XmlTextReader diffGram = new XmlTextReader(diffFile); dv.Load(orig, diffGram); MainProBar.PerformStep(); //Wrap the HTML file with necessary html and //body tags and prepare it before passing it to the GetHtml method. string tempFile = startupPath + Path.DirectorySeparatorChar + "Compare_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".htm"; StreamWriter sw1 = new StreamWriter(tempFile); MainProBar.PerformStep(); sw1.Write("<html><body><table width='100%'>"); //Write Legend. sw1.Write("<tr><td colspan='2' align='center'><b>Legend:</b> <font style='background-color: yellow'" + " color='black'>added</font> <font style='background-color: red'" + " color='black'>removed</font> <font style='background-color: " + "lightgreen' color='black'>changed</font> " + "<font style='background-color: red' color='blue'>moved from</font>" + " <font style='background-color: yellow' color='blue'>moved to" + "</font> <font style='background-color: white' color='#AAAAAA'>" + "ignored</font></td></tr>"); sw1.Write("<tr><td><b> File Name : "); sw1.Write(OriginalPath.Text); sw1.Write("</b></td><td><b> File Name : "); sw1.Write(ComparePath.Text); sw1.Write("</b></td></tr>"); MainProBar.PerformStep(); //This gets the differences but just has the //rows and columns of an HTML table dv.GetHtml(sw1); MainProBar.PerformStep(); //Finish wrapping up the generated HTML and complete the file. sw1.Write("</table></body></html>"); //Open the IE Control window and pass it the HTML file we created. ReportWindow.Navigate(new Uri(tempFile)); MainProBar.PerformStep(); //HouseKeeping...close everything we dont want to lock. dv = null; file1 = null; file2 = null; sw1.Close(); orig.Close(); diffGram.Close(); orig.Dispose(); diffGram.Dispose(); tw.Dispose(); sw1.Dispose(); fileI.Dispose(); fileO.Dispose(); File.Delete(diffFile); GC.Collect(); MainProBar.PerformStep(); MainProBar.PerformStep(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); MainProBar.Value = 1; } }
private void SearchButton_Click_1(object sender, EventArgs e) { try { log.Info(UserTXT.Text + " - Started Search"); // Set Progress Bar MainProBar.Visible = true; MainProBar.Minimum = 1; MainProBar.Maximum = 5; MainProBar.Value = 1; MainProBar.Step = 1; //Check for Search Criteria if (SearchBox.Text == "") { return; } MainProBar.PerformStep(); log.Info(SearchBox.Text); //Set variables and SB String search = SearchBox.Text; Properties.Settings.Default.Search = ""; StringBuilder sb = new StringBuilder(); int Count = 0; MainProBar.PerformStep(); //Clear already Highlighted values for (int x = 0; x < MainDataGrid.Rows.Count - 1; x++) { for (int i = 0; i < MainDataGrid.Columns.Count; i++) { MainDataGrid.Rows[x].Cells[i].Style.BackColor = Color.White; } } MainProBar.PerformStep(); //Highlight values and store location for (int x = 0; x < MainDataGrid.Rows.Count - 1; x++) { for (int i = 0; i < MainDataGrid.Columns.Count; i++) { if (MainDataGrid.Rows[x].Cells[i].Value.ToString().ToUpper().Contains(search.ToUpper()) == true) { MainDataGrid.Rows[x].Cells[i].Style.BackColor = Color.Yellow; sb.Append(x + "," + i + "|"); Count = Count + 1; } } } MainProBar.PerformStep(); log.Info(Count + " Results"); //Set end Variables Properties.Settings.Default.Search = sb.ToString(); Properties.Settings.Default.Count = "-1"; if (Count.ToString() != "0") { Current.Text = "0"; Total.Text = Count.ToString(); } else { Current.Text = ""; Total.Text = ""; } MainProBar.PerformStep(); log.Info(UserTXT.Text + " - Finished Search"); } catch (Exception ex) { log.Error(ex); MessageBox.Show(ex.Message.ToString()); } }
private void Import_Click(object sender, EventArgs e) { try { DialogResult Proceed = MessageBox.Show("Unsaved changes will be lost, would you like to proceed?", "Proceed?", MessageBoxButtons.YesNo); if (Proceed == DialogResult.No) { return; } log.Info(UserTXT.Text + " - Started Import CSV"); // Set Progress Bar MainProBar.Visible = true; MainProBar.Minimum = 1; MainProBar.Maximum = 5; MainProBar.Value = 1; MainProBar.Step = 1; // Displays an OpenFileDialog so the user can select a file. OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "CSV|*.csv"; openFileDialog1.Title = "Select a CSV File"; MainProBar.PerformStep(); // If the user selected a file if (openFileDialog1.ShowDialog() == DialogResult.OK) { MainProBar.PerformStep(); // Assign the cursor in the Stream to the Form's Cursor property. string strFileName = openFileDialog1.FileName; ADODB.Connection oConn = new ADODB.Connection(); oConn.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = " + System.IO.Path.GetDirectoryName(strFileName) + "; Extended Properties = \"Text;HDR=YES;FMT=Delimited\";", "", "", 0); string strQuery = "SELECT * FROM [" + System.IO.Path.GetFileName(strFileName) + "]"; ADODB.Recordset rs = new ADODB.Recordset(); MainProBar.PerformStep(); log.Info(strFileName); System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter(); DataTable dt = new DataTable(); rs.Open(strQuery, "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = " + System.IO.Path.GetDirectoryName(strFileName) + "; Extended Properties = \"Text;HDR=YES;FMT=Delimited\";", ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 1); adapter.Fill(dt, rs); MainDataGrid.DataSource = dt.DefaultView; //Close Conection oConn.Close(); rs.Close(); MainProBar.PerformStep(); //Populate Row Count Lable RowCount.Text = MainDataGrid.Rows.Count.ToString(); int Rows = int.Parse(RowCount.Text) - 1; RowCount.Text = Rows.ToString(); ColumnCount.Text = MainDataGrid.Columns.Count.ToString(); SourceTXT.Text = "CSV"; Current.Text = ""; Total.Text = ""; Properties.Settings.Default.Search = ""; MainProBar.PerformStep(); log.Info(UserTXT.Text + " - Finished Import CSV"); } else { MainProBar.Value = 1; } } catch (Exception ex) { log.Error(ex); MessageBox.Show(ex.Message.ToString()); MainProBar.Value = 1; } }
private void Export_Click(object sender, EventArgs e) { try { log.Info(UserTXT.Text + " - Started Export CSV"); // Set Progress Bar MainProBar.Visible = true; MainProBar.Minimum = 1; MainProBar.Maximum = 6; MainProBar.Value = 1; MainProBar.Step = 1; // Don't save if no data is returned if (MainDataGrid.Rows.Count == 0) { return; } StringBuilder sb = new StringBuilder(); MainProBar.PerformStep(); // Column headers string columnsHeader = ""; for (int i = 0; i < MainDataGrid.Columns.Count; i++) { columnsHeader += "\"" + MainDataGrid.Columns[i].Name + "\"" + ","; } sb.Append(columnsHeader); sb.Length = sb.Length - 1; sb.Append(Environment.NewLine); MainProBar.PerformStep(); // Go through each cell in the datagridview foreach (DataGridViewRow dgvRow in MainDataGrid.Rows) { // Make sure it's not an empty row. if (!dgvRow.IsNewRow) { for (int c = 0; c < dgvRow.Cells.Count; c++) { // Append the cells data followed by a comma to delimit. sb.Append("\"" + dgvRow.Cells[c].Value + "\"" + ","); } // Add a new line in the text file. sb.Length = sb.Length - 1; sb.Append(Environment.NewLine); } sb.Length = sb.Length - 1; } MainProBar.PerformStep(); // Load up the save file dialog with the default option as saving as a .csv file. SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "CSV files (*.csv)|*.csv"; sfd.FileName = Tables.Text + "_" + DateTime.Now.ToString("yyyyMMddHHmmss"); if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { MainProBar.PerformStep(); // If they've selected a save location... using (System.IO.StreamWriter sw = new System.IO.StreamWriter(sfd.FileName, false)) { // Write the stringbuilder text to the the file. sw.WriteLine(sb.ToString()); MainProBar.PerformStep(); log.Info(sfd.FileName); } MainProBar.PerformStep(); } else { MainProBar.Value = 1; } log.Info(UserTXT.Text + " - Finished Export CSV"); } catch (Exception ex) { log.Error(ex); MessageBox.Show(ex.Message.ToString()); MainProBar.Value = 1; } }
private void Upload_Click(object sender, EventArgs e) { try { log.Info(UserTXT.Text + " - Started SQL Upload"); // Set Progress Bar MainProBar.Visible = true; MainProBar.Minimum = 1; MainProBar.Maximum = MainDataGrid.Rows.Count + 5; MainProBar.Value = 1; MainProBar.Step = 1; MainProBar.PerformStep(); //Create connection string string strConnection = ConnectionStrings.Text; string strTable = Tables.Text; SqlConnection con = new SqlConnection(strConnection); MainProBar.PerformStep(); //Create Insert SQL StringBuilder sb = new StringBuilder(); for (int x = 0; x < MainDataGrid.Rows.Count - 1; x++) { sb.Append("INSERT INTO [" + strTable + "] VALUES "); sb.Append("("); for (int i = 0; i < MainDataGrid.Columns.Count; i++) { string Row = Convert.ToString(MainDataGrid.Rows[x].Cells[i].Value); Row = Row.Replace("'", "''"); sb.Append("'" + Row + "',"); } sb.Length = sb.Length - 1; sb.Append(")"); MainProBar.PerformStep(); } string Insert = (sb.ToString()); MainProBar.PerformStep(); log.Info(strTable); //Setup Insert command SqlCommand Update = new SqlCommand(); Update.Connection = con; Update.CommandType = CommandType.Text; Update.CommandText = Insert; SqlDataAdapter sqlDataAdapUpdate = new SqlDataAdapter(); sqlDataAdapUpdate.InsertCommand = Update; MainProBar.PerformStep(); //Setup Delete command SqlCommand Delete = new SqlCommand(); Delete.Connection = con; Delete.CommandType = CommandType.Text; Delete.CommandText = "TRUNCATE TABLE [" + strTable + "]"; SqlDataAdapter sqlDataAdapDelete = new SqlDataAdapter(); sqlDataAdapDelete.InsertCommand = Delete; MainProBar.PerformStep(); con.Open(); //Run insert to confirm no error Update.ExecuteNonQuery(); //Delete table contents Delete.ExecuteNonQuery(); //Run Insert to recreate table with updated values Update.ExecuteNonQuery(); con.Close(); MainProBar.PerformStep(); log.Info(UserTXT.Text + " - Finished SQL Upload"); } catch (Exception ex) { log.Error(ex); MainProBar.Value = 1; MessageBox.Show(ex.Message.ToString()); } }