public void switchToSimulation() { if (User != null) { if (Client != null) { UIMainForm.getPnUserControl().Controls.Clear(); UIMainForm.getPnUserControl().Controls.Add(UISimulation); this.VMSimulation.printBalance(); this.VMSimulation.getSimulation(); } else { UIMainForm.genMsgBox("You haven't chose a client.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if (UIMainForm.getPnUserControl().Controls.Contains(this.UIClient)) { UIMainForm.getBtClient().PerformClick(); } else if (UIMainForm.getPnUserControl().Controls.Contains(this.UIDashboard)) { UIMainForm.getBtDashboard().PerformClick(); } else if (UIMainForm.getPnUserControl().Controls.Contains(this.UIProduct)) { UIMainForm.getBtProduct().PerformClick(); } } } else { switchToLogin(); } }
public VMMain() { UIMainForm = new UIMainForm(); UIMainForm.VMMain = this; switchToLogin(); // App start page //switchToMainPage(null, new Model.User(1)); UISimulation = new UISimulation(); VMSimulation = new VMSimulation(this, UISimulation); }
/** * Functions to switch between UserControls */ public void switchToLogin() { UILogin = new UILogin(); VMLogin = new VMLogin(this, UILogin); //remove whatever control is currently in the Panel UIMainForm.getPnUserControl().Controls.Clear(); //add the other control, the HomePage control instead now UIMainForm.getPnUserControl().Controls.Add(UILogin); }
public void DatabaseAccessException(UIMainForm form, string dbUpdateExMessage, string dbUpdateExInnerException, int sqlExceptionNumber) { switch (sqlExceptionNumber) { case 1062: form.genMsgBox("Unique constraint failed.", "DataBase Access Exception", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); break; default: form.genMsgBox("Message = " + dbUpdateExMessage + "\nInnerException = " + dbUpdateExInnerException + "\nsqlExceptionNumber = " + sqlExceptionNumber, "DataBase Access Exception", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); break; } }
public void switchToDashboard() { if (User != null) { if (UIDashboard == null) { UIDashboard = new UIDashboard(); VMDashboard = new VMDashboard(this, UIDashboard); } UIMainForm.getPnUserControl().Controls.Clear(); UIMainForm.getPnUserControl().Controls.Add(UIDashboard); } else { switchToLogin(); } }
public void switchToProduct() { if (User != null) { if (UIProduct == null) { UIProduct = new UIProduct(); VMProduct = new VMProduct(this, UIProduct); } UIMainForm.getPnUserControl().Controls.Clear(); UIMainForm.getPnUserControl().Controls.Add(UIProduct); } else { switchToLogin(); } }
// Function to exoprt the given client's simulation list in to format pdf public static void writePdf(Client clt, UIMainForm form) { // Print PDF table string pdfname = string.Empty; SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = "Okinvestir Simulation liste"; dlg.DefaultExt = ".pdf"; dlg.Filter = "Text documents (.pdf)|*.pdf"; var logo = System.Drawing.Image.FromHbitmap(Properties.Resources.logo.GetHbitmap()); Image imageHeader = Image.GetInstance(logo, System.Drawing.Imaging.ImageFormat.Png); if (dlg.ShowDialog() == DialogResult.OK) { pdfname = dlg.FileName; List <Simulation> simus = clt.getSimulationList(); try { FileStream fs = new FileStream(pdfname, FileMode.Create); // Create file stream Document document = new Document(PageSize.A4.Rotate()); // Create file PageSize.A7.Rotate() PdfWriter pdfWriter = PdfWriter.GetInstance(document, fs); // Create objet MyPageEventHandler e = new MyPageEventHandler() { ImageHeader = imageHeader }; pdfWriter.PageEvent = e; document.Open(); // Open file document.Add(PDFTable1(clt)); //add table document.SetPageSize(PageSize.A4); // A4 print in lanscape orientation document.NewPage(); // Open a new page document.Close(); // Close file fs.Close(); } catch { form.genMsgBox("Fail to export pdf file, maybe de file is already openned", "error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); } } }
/** * Functions to handle mysql exception */ public virtual void HandleException(Exception exception, UIMainForm form) { DbUpdateException dbUpdateEx = exception as DbUpdateException; if (dbUpdateEx != null) { if (dbUpdateEx != null && dbUpdateEx.InnerException != null && dbUpdateEx.InnerException.InnerException != null) { MySqlException sqlException = dbUpdateEx.InnerException.InnerException as MySqlException; if (sqlException != null) { DatabaseAccessException(form, dbUpdateEx.Message, sqlException.Message, sqlException.Number); } else { form.genMsgBox("Message = " + dbUpdateEx.Message + "\nInnerException = " + dbUpdateEx.InnerException, "DataBase Access Exception", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } } else { form.genMsgBox("Message = " + dbUpdateEx.Message, "DataBase Access Exception", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } } else { form.genMsgBox("Error\n But not DbUpdateException", "DataBase Access Exception", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } }
// Function to exoprt the given client's simulation list in to format csv public static void writeCsv(Client clt, UIMainForm form) { string csvname = string.Empty; // Name of file SaveFileDialog dlg = new SaveFileDialog(); // Create a save file dialog dlg.FileName = "simulations"; dlg.DefaultExt = ".csv"; dlg.Filter = "Text documents (.csv)|*.csv"; if (dlg.ShowDialog() == DialogResult.OK) { List <Simulation> simus = clt.getSimulationList();// Get clients' simulation list // Write headers StringBuilder str = new StringBuilder(); str.Append("\"sep=;\"\n"); str.Append("Client: "); str.Append(clt.FullName); str.Append(";\n"); str.Append("ID: "); str.Append(clt.Id); str.Append(";\n"); str.Append(DateTime.Now); str.Append(";\n"); str.Append("Simulations: ;\n"); str.Append("Simulation Id;Product name;Price;Start date;End date;Interest rate;Settlement price;Total months;\n"); // build text foreach (Simulation simu in simus) { str.Append(simu.Id); str.Append(";"); str.Append(simu.Product.Name); str.Append(";"); str.Append(simu.Price); str.Append(";"); str.Append(simu.StartDate.ToShortDateString()); str.Append(";"); str.Append(simu.EndDate.ToShortDateString()); str.Append(";"); str.Append(simu.InterestRate); str.Append(";"); str.Append(simu.SettlementPrice); str.Append(";"); str.Append((int)((simu.EndDate - simu.StartDate).TotalDays) / 30); str.Append(";"); str.Append("\n"); } try { using (StreamWriter file = new StreamWriter(@dlg.FileName)) { file.Write(str); file.Close(); } } catch (IOException e) { form.genMsgBox("Cannot write file, maybe file is openned", "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } } }
// Function to exoprt the given client's simulation list in to format Xlsx public static void exportXlsx(Client client, UIMainForm form) { string xlsxname = string.Empty; // Name of file SaveFileDialog dlg = new SaveFileDialog(); // Create a save file dialog dlg.FileName = "simulations"; dlg.DefaultExt = ".xlsx"; dlg.Filter = "Text documents (.xlsx)|*.xlsx"; if (dlg.ShowDialog() == DialogResult.OK) { List <Simulation> ListSimulation = client.getSimulationList(); // Get clients' simulation list DataTable dt = new DataTable(); // Create table of simulations DataColumn column; DataRow row; column = new DataColumn(); // Add columns column.DataType = System.Type.GetType("System.Int32"); column.ColumnName = "Simulation Id"; dt.Columns.Add(column); column = new DataColumn(); column.DataType = System.Type.GetType("System.String"); column.ColumnName = "Product name"; dt.Columns.Add(column); column = new DataColumn(); column.DataType = System.Type.GetType("System.Decimal"); column.ColumnName = "Price"; dt.Columns.Add(column); column = new DataColumn(); column.DataType = System.Type.GetType("System.DateTime"); column.ColumnName = "Start date"; dt.Columns.Add(column); column = new DataColumn(); column.DataType = System.Type.GetType("System.DateTime"); column.ColumnName = "End date"; dt.Columns.Add(column); column = new DataColumn(); column.DataType = System.Type.GetType("System.Decimal"); column.ColumnName = "Interest rate"; dt.Columns.Add(column); column = new DataColumn(); column.DataType = System.Type.GetType("System.Decimal"); column.ColumnName = "Settlement price"; dt.Columns.Add(column); column = new DataColumn(); column.DataType = System.Type.GetType("System.Int32"); column.ColumnName = "Total months"; dt.Columns.Add(column); foreach (Simulation sim in ListSimulation) // Add rows { row = dt.NewRow(); // Add cells in each row row["Simulation Id"] = sim.Id; row["Product name"] = sim.Product.Name; row["Price"] = sim.Price; row["Start date"] = sim.StartDate; row["End date"] = sim.EndDate; row["Interest rate"] = sim.InterestRate; row["Settlement price"] = sim.SettlementPrice; row["Total months"] = (int)(((sim.EndDate - sim.StartDate).TotalDays) / 30); dt.Rows.Add(row); } try { if (File.Exists(dlg.FileName)) // Delect file if file already exist { File.Delete(dlg.FileName); } using (ExcelPackage pck = new ExcelPackage(new FileInfo(dlg.FileName))) // Open the excel file { ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Simulation list "); ws.Cells["A1"].Value = "Simulation list of " + client.FullName; ws.Cells["A4"].LoadFromDataTable(dt, true); pck.Save(); } } catch (IOException e) { form.genMsgBox("Fail to export xlsx file.", "error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); } } }
public void switchToSubProduct(UISubProduct sub) { UIMainForm.getPnUserControl().Controls.Clear(); UIMainForm.getPnUserControl().Controls.Add(sub); }