public static void RunWorkerCompleted <T>( RunWorkerCompletedEventArgs e, string names, ref List <T> records, FormCSV form, Label label, ProgressBar progressBar, EnableDisableDelegate EnableDisable, int numFiles) { if (records != null) { if (e.Error != null) { // Failed string msg = string.Format("Failed to parse {0} CSV File(s).", names); MessageBox.Show(msg, form.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); records = null; } else if ((bool)e.Result) { // Cancelled string msg = string.Format("Parsing {0} CSV File(s) cancelled by user.", names); MessageBox.Show(msg, form.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); form.Cursor = Cursors.Default; records = null; } else { // Parsed string msg; if (records.Count == 0) { msg = string.Format("There is no records in the selected {0} CSV File(s).", names); MessageBox.Show(msg, form.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); records = null; } else { msg = string.Format("{0} {1} CSV File(s) parsed successfully.", numFiles, names); MessageBox.Show(msg, form.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } } label.Text = string.Empty; progressBar.Value = 0; EnableDisable(false); ParsedData.OnParseComplete(); }
private void checkBoxFuturesOnly_CheckedChanged(object sender, EventArgs e) { bool isChecked = checkBoxFuturesOnly.Checked; ParsedData.FuturesOnly = isChecked; button_InputOption.Visible = !isChecked; label_InputOption.Visible = !isChecked; button_CancelOption.Visible = !isChecked; label_ParsedOption.Visible = !isChecked; progressBar_ParsingOption.Visible = !isChecked; ParsedData.OnParseComplete(); }
private void button_InputJson_Click(object sender, EventArgs e) { label_InputJson.Text = NotSelected; ParsedData.JsonConfig = null; using (var dialog = new OpenFileDialog()) { dialog.Filter = "Data file|*.json"; dialog.Title = "Select data file(s)"; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.Cancel) { return; } try { string text = File.ReadAllText(dialog.FileName); ParsedData.JsonConfig = JsonConvert.DeserializeObject <JsonConfig>(text); } catch (Exception ex) { MessageBox.Show( ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string msg = ParsedData.JsonConfig.Validate(ParsedData.FuturesOnly); if (msg != null) { MessageBox.Show( msg, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); ParsedData.JsonConfig = null; return; } label_InputJson.Text = dialog.FileName; ParsedData.OnParseComplete(); } }
private void button_InputFuture_Click(object sender, EventArgs e) { ParsedData.FutureRecords = null; ParsedData.OnParseComplete(); FutureFilePaths = SelectFiles( "Futures", label_InputFuture, progressBar_ParsingFuture); if (FutureFilePaths != null) { // Parse the selected CSV files EnableDisableFuture(true); backgroundWorker_ParsingFutures.RunWorkerAsync(); } }
private void button_InputOption_Click(object sender, EventArgs e) { ParsedData.OptionRecords = null; ParsedData.OnParseComplete(); OptionFilePaths = SelectFiles( "Options", label_InputOption, progressBar_ParsingOption); if (OptionFilePaths != null) { // Parse the selected CSV files EnableDisableOption(true); backgroundWorker_ParsingOptions.RunWorkerAsync(); } }
/// <summary> /// Check conformity between future CSV file(s), option CSV file(s) and JSON file. /// Also, initialize IsConform data member to skip double checks. /// </summary> private static bool CsvCsvJsonConformityCheck() { IsConform = false; // We already checked that FutureRecords (and OptionRecords) are not empty string futureProductName = ParsedData.FutureProductName.Replace(" Futures", string.Empty); if (!FuturesOnly) { // Check conformity of ProductName between futures and options string optionProductName = ParsedData.OptionProductName.Replace(" Options", string.Empty); if (futureProductName != optionProductName) { MessageBox.Show( "The selected Futures CSV File(s) and Options CSV File(s) do not conform to each other by \"ProductName\" column.", FormText, MessageBoxButtons.OK, MessageBoxIcon.Error); return(IsConform); } } if (!IsJsonParsed) { return(IsConform); } else { // Check JSON string msg = JsonConfig.Validate(FuturesOnly); if (msg != null) { MessageBox.Show( msg, FormText, MessageBoxButtons.OK, MessageBoxIcon.Error); return(IsConform); } } // Check conformity of ProductName between CSV and JSON if (futureProductName != JsonConfig.ICE_ProductName) { MessageBox.Show( "The selected CSV File(s) do not conform to the JSON File by the product name.", FormText, MessageBoxButtons.OK, MessageBoxIcon.Error); return(IsConform); } if (FuturesOnly) { IsConform = true; return(IsConform); } List <DateTime> jsonConfigDates = ParsedData.ParseRegularOptions(); // Check conformity of StripName var futureStripNames = new HashSet <DateTime>(FutureRecords.Select(item => item.StripName)); HashSet <DateTime> optionNotFound = new HashSet <DateTime>(); OptionsRecordsSelected = new List <EOD_Option_Selected>(); foreach (var option in OptionRecords) { if (futureStripNames.Contains(option.StripName)) { OptionsRecordsSelected.Add(new EOD_Option_Selected(option.StripName, option)); } else if (!jsonConfigDates.Contains(option.StripName)) { var stripName = futureStripNames.Where(item => item < option.StripName).First(); OptionsRecordsSelected.Add(new EOD_Option_Selected(stripName, option)); } else { optionNotFound.Add(option.StripName); } } IsConform = optionNotFound.Count == 0; if (!IsConform) { var sb = new StringBuilder( "The selected Futures CSV File(s) and Options CSV File(s) do not conform to each other.\n\n" + "Options with the following values of StripName do not have corresponding futures " + "(only the first 10 values are shown):\n\n"); int i = 0; foreach (DateTime optionStripName in optionNotFound) { if (i < 10) { sb.Append(optionStripName.ToString("MMMyy") + "\n"); i++; } OptionRecords.RemoveAll(option => option.StripName == optionStripName); } sb.Append( "\nDo you want to proceed anyway?\n\n" + "(If you select \"Yes\", the extra options will not be pushed to database.)"); DialogResult result = MessageBox.Show( sb.ToString(), FormText, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); IsConform = (result == DialogResult.Yes); } return(IsConform); }