private void btnMerge_Click(object sender, EventArgs e) { try { //Validate the form fields if (ValidateFields()) { //Ask the enduser to confirm csv file header information DialogResult dialogResult = MessageBox.Show("Given CSV files are going to merged " + (chkHeader.Checked ? "with " : "without ") + " header. Are you sure you want to begin?", "Confirm to begin merge", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (dialogResult == DialogResult.No) { return; } //Save the enduser selection information in tool configuration file CollectAndSaveConfigDetails(); //Call the merge method businessClient.MergeCsvToJson(mergeCSVData); MessageBox.Show("Given CSV files are merged successfully.", "MergeCSVTool"); } } catch (Exception ex) { MergeLog.LogError(ex); MessageBox.Show(ex.Message, "MergeCSVTool"); } }
static void Main(string[] args) { try { MergeLog.Loginformation("Main - Start"); //Create Mutex object & its related varibale to avoid running multiple instances const string appName = "SingleCSVInstanceApp"; bool createdNew; mutex = new Mutex(true, appName, out createdNew); MergeLog.Loginformation("Mutex thread created."); if (!createdNew) { //Prompt the message to enduser and close the current instance MessageBox.Show("Application is already running."); MergeLog.Loginformation("Mutex thread identified already win form instance is running."); return; } //Identify the Windows form exe is launched with/without parameters if (args.Length > 0) { //Declare client object and which will create all required object at runtime BusinessClient businessClient = new BusinessClient(); //Read the saved selection of CSV files and destination paths MergeCSVData data = PackageConfig.ReadMergeCSVData(); //Validating saved tool configuration values if (string.IsNullOrEmpty(data.CSVFilePath1.Trim()) || string.IsNullOrEmpty(data.CSVFilePath2.Trim()) || string.IsNullOrEmpty(data.HeaderExists.Trim()) || string.IsNullOrEmpty(data.JsonFilePath.Trim())) { //Prompt the validation message to enduser and close the current instance MessageBox.Show("Invalid Configuration values. Please use UI execution.", "MergeCSVTool"); MergeLog.Loginformation("Invalid Configuration values."); return; } // Call the merge method businessClient.MergeCsvToJson(data); MessageBox.Show("Given CSV files are merged successfully.", "MergeCSVTool"); } else { //Open Merge win form Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MergeCSVToJson()); } MergeLog.Loginformation("Main - End"); } catch (Exception ex) { MergeLog.LogError(ex); MessageBox.Show(ex.Message, "MergeCSVTool"); } }
public void WriteJson(object data) { try { Common.Common.ListToJSONWithJavaScriptSerializer(data); } catch (Exception e) { MergeLog.LogError(e); throw e; } }
public DataTable ReadCSVFile(string file, bool NoHeader) { try { return(Common.Common.ConvertCSVtoDataTable(file, NoHeader)); } catch (Exception e) { MergeLog.LogError(e); throw e; } }
private void btnCSVFilePath1_Click(object sender, EventArgs e) { try { if (openCSVFileDlg.ShowDialog() == DialogResult.OK) { txtCSVFilePath1.Text = openCSVFileDlg.FileName; } } catch (Exception ex) { MergeLog.LogError(ex); MessageBox.Show(ex.Message, "MergeCSVTool"); } }
private void btnJsonFolderPath_Click(object sender, EventArgs e) { try { if (fldBrowDlgJsonFolderPath.ShowDialog() == DialogResult.OK) { txtJsonFolderPath.Text = fldBrowDlgJsonFolderPath.SelectedPath; } } catch (Exception ex) { MergeLog.LogError(ex); MessageBox.Show(ex.Message, "MergeCSVTool"); } }
private void CollectAndSaveConfigDetails() { try { mergeCSVData = new MergeCSVData(); mergeCSVData.CSVFilePath1 = txtCSVFilePath1.Text; mergeCSVData.CSVFilePath2 = txtCSVFilePath2.Text; mergeCSVData.JsonFilePath = txtJsonFolderPath.Text; mergeCSVData.HeaderExists = chkHeader.Checked.ToString(); PackageConfig.WriteMergeCSVData(mergeCSVData); } catch (Exception e) { MergeLog.LogError(e); throw e; } }
private void btnShowLogFile_Click(object sender, EventArgs e) { try { if (File.Exists(Directory.GetCurrentDirectory() + @"\" + MergeLog.LogFileName)) { System.Diagnostics.Process.Start(Directory.GetCurrentDirectory() + @"\" + MergeLog.LogFileName); } else { MessageBox.Show("Log file does not exists.", "MergeCSVTool"); } } catch (Exception ex) { MergeLog.LogError(ex); throw ex; } }
private void btnSaveConfig_Click(object sender, EventArgs e) { try { if (ValidateFields()) { DialogResult dialogResult = MessageBox.Show("You opted CSV files are " + (chkHeader.Checked ? "having " : "not having ") + " header. Are you sure you want to Save?", "Confirm to begin save", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (dialogResult == DialogResult.No) { return; } CollectAndSaveConfigDetails(); MergeLog.Loginformation("End user selection details are saved successfully."); MessageBox.Show("Form input details are saved successfully.", "MergeCSVTool"); } } catch (Exception ex) { MergeLog.LogError(ex); MessageBox.Show(ex.Message, "MergeCSVTool"); } }