}//end tsmSave_Click private void OfficeDocumentProgressForm(SaveDocument doc, string extension) { try { var secondScreener = (tabScreeners.SelectedTab == tabScreener2 ? true : false); frmOfficeDocumentProgress frm; if (extension == "xlsx") { frm = new frmOfficeDocumentProgress(doc, (secondScreener ? CreateTempDictionary(stocksAdditionalInfo.Values.Select(s => s["source"]).Distinct()) : stocks), secondScreener); } else { int rows = (secondScreener ? stocksAdditionalInfo.Values.Select(s => s["source"]).Distinct().Count() : stocks.Keys.Count()) + 1; if (secondScreener) { rows += stocksAdditionalInfo.Keys.Count; } else { foreach (var kvp in stocks.Values) { rows += kvp.Values.Count(); } } frm = new frmOfficeDocumentProgress(doc, (secondScreener ? CreateTempDictionary(stocksAdditionalInfo.Values.Select(s => s["source"]).Distinct()) : stocks), rows, secondScreener); }//end if-else frm.ShowDialog(); } catch (Exception ex) { ErrorMessage(ex); } }//end OfficeDocumentProgressForm
}//end AddArguments /// <summary> /// Runs the basic functions of the from. Assigns the value of the initial message and text of the form. Creates the argument /// object and calls RunWorkerAsync with the arguments. /// </summary> /// <param name="doc">The SaveDocument object being used</param> /// <param name="map">The Stock object dictionary to use</param> /// <param name="rows">The number of rows for the table</param> private void Run(SaveDocument doc, Dictionary <string, Dictionary <string, Stock> > map, int rows = -1) { lblMessage.Text = String.Format("This may take a moment. The file is being saved as a{0} file.", (rows == -1 ? "n Excel" : " Word")); this.Text = String.Format("Saving {0} Document", (rows == -1 ? "Excel" : "Word")); var args = AddArguments(doc, map, rows); bgwSaveDocument.RunWorkerAsync(args); }//end Run
} //end 3 argument constructor private List <object> AddArguments(SaveDocument doc, Dictionary <string, Dictionary <string, Stock> > map, int rows = -1) { List <object> arguments = new List <object>(); arguments.Add(doc); arguments.Add(map); arguments.Add(rows); return(arguments); }//end AddArguments
} //end 2 argument constructor /// <summary> /// Constructor used for creating Word documents /// </summary> /// <param name="doc">The SaveDocument object being used</param> /// <param name="map">The Stock object dictionary to use</param> /// <param name="rows">The number of rows for the table</param> public frmOfficeDocumentProgress(SaveDocument doc, Dictionary <string, Dictionary <string, Stock> > map, int rows) { try { InitializeComponent(); Run(doc, map, rows); } catch { } //end try-catch } //end 3 argument constructor
}//end default constructor /// <summary> /// Constructor used for saving Excel files /// </summary> /// <param name="doc">The SaveDocument object being used</param> /// <param name="map">The Stock object dictionary to use</param> public frmOfficeDocumentProgress(SaveDocument doc, Dictionary <string, Dictionary <string, Stock> > map, bool secondScreener) { try { InitializeComponent(); this.secondScreener = secondScreener; Run(doc, map); } catch { } //end try-catch } //end 2 argument constructor
}//end Run /// <summary> /// Starts the save process for saving an Excel or Word file by calling the appropriate SaveDocument function. /// </summary> /// <param name="doc">The SaveDocument object being used</param> /// <param name="map">The Stock object dictionary to use</param> /// <param name="rows">The number of rows for the table. If anything other than -1 calls SaveWordDocument</param> private void StartSave(SaveDocument doc, Dictionary <string, Dictionary <string, Stock> > map, int rows = -1) { doc.OnProgressUpdate += doc_OnProgressUpdate; if (rows == -1) { doc.SaveExcelDocument(map); } else { doc.SaveWordDocument(map, rows); } //end if-else } //end StartSave
} //end StartSave private void bgwSaveDocument_DoWork(object sender, DoWorkEventArgs e) { try { List <object> objs = (List <object>)e.Argument; SaveDocument doc = (SaveDocument)objs[0]; Dictionary <string, Dictionary <string, Stock> > map = (Dictionary <string, Dictionary <string, Stock> >)objs[1]; int rows = (int)objs[2]; StartSave(doc, map, rows); } catch { } //end try-catch } //end bgwSaveDocument_DoWork
}//end tsmUtilities_Click private void tsmSave_Click(object sender, EventArgs e) { try { if ((tabScreeners.SelectedTab == tabScreener2 && !pnlScreener2NoStocks.Visible) || (tabScreeners.SelectedTab == tabScreener && !pnlScreener1NoStocks.Visible)) { SaveDocument document; SaveFileDialog save = new SaveFileDialog(); save.AddExtension = true; save.Filter = "Excel files (*xlsx)|*.xlsx|Word files (*.docx)|*docx|Xml files (*.xml)|*.xml|Html files (*.html)|*.html"; if (save.ShowDialog() == DialogResult.OK) { string path = save.FileName; string extension = path.Remove(0, path.LastIndexOf('.') + 1); save.DefaultExt = extension; document = new SaveDocument(path.Remove(path.LastIndexOf('\\')), path.Remove(0, path.LastIndexOf('\\') + 1)); if (extension == "xlsx") { OfficeDocumentProgressForm(document, extension); } else if (extension == "docx") { OfficeDocumentProgressForm(document, extension); } else if (extension == "xml") { document.SaveXmlDocument((tabScreeners.SelectedTab == tabScreener2 ? CreateTempDictionary(stocksAdditionalInfo.Values.Select(s => s["source"]).Distinct()) : stocks), (tabScreeners.SelectedTab == tabScreener2 ? true : false)); } else if (extension == "pdf") { pdfPath = Path.Combine(path.Remove(path.LastIndexOf('\\')), path.Remove(0, path.LastIndexOf('\\') + 1)); tsmPrint.PerformClick(); } else { document.SaveHtmlDocument((tabScreeners.SelectedTab == tabScreener2 ? CreateTempDictionary(stocksAdditionalInfo.Values.Select(s => s["source"]).Distinct()) : stocks), (tabScreeners.SelectedTab == tabScreener2 ? true : false)); } }//end nested if } else { MessageBox.Show("There are no stocks to save on this screener", "Unable to Save", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }//end if-else } catch (Exception ex) { ErrorMessage(ex); } }//end tsmSave_Click
}//end tsmUtilities_Click private void tsmSave_Click(object sender, EventArgs e) { try { SaveDocument document; SaveFileDialog save = new SaveFileDialog(); save.AddExtension = true; save.Filter = "Excel files (*xlsx)|*.xlsx|Word files (*.docx)|*docx|Xml files (*.xml)|*.xml|Html files (*.html)|*.html"; if (save.ShowDialog() == DialogResult.OK) { string path = save.FileName; string extension = path.Remove(0, path.LastIndexOf('.') + 1); save.DefaultExt = extension; document = new SaveDocument(path.Remove(path.LastIndexOf('\\')), path.Remove(0, path.LastIndexOf('\\') + 1)); if (extension == "xlsx") { OfficeDocumentProgressForm(document, extension); } else if (extension == "docx") { OfficeDocumentProgressForm(document, extension); } else if (extension == "xml") { document.SaveXmlDocument(stocks); } else { document.SaveHtmlDocument(stocks); } }//end if } catch (Exception ex) { ErrorMessage(ex); } }//end tsmSave_Click
}//end tsmSave_Click private void OfficeDocumentProgressForm(SaveDocument doc, string extension) { try { frmOfficeDocumentProgress frm; if (extension == "xlsx") { frm = new frmOfficeDocumentProgress(doc, stocks); } else { int rows = stocks.Keys.Count() + 1; foreach (var kvp in stocks.Values) { rows += kvp.Values.Count(); } frm = new frmOfficeDocumentProgress(doc, stocks, rows); }//end if-else frm.ShowDialog(); } catch (Exception ex) { ErrorMessage(ex); } }//end OfficeDocumentProgressForm