private void openAllFormToolStripMenuItem_Click(object sender, EventArgs e) { // Close all opened form closeAllChildrenFormExcept(null, null); CriteriaForm criteriaForm = null; if (isFormOpened(typeof(CriteriaForm)) == null) { criteriaForm = new CriteriaForm(); criteriaForm.MdiParent = this; criteriaForm.StartPosition = FormStartPosition.Manual; criteriaForm.Location = new Point(0, 0); criteriaForm.Show(); } CriteriaRankingForm criteriaRankingForm = null; if (isFormOpened(typeof(CriteriaRankingForm)) == null) { criteriaRankingForm = new CriteriaRankingForm(); criteriaRankingForm.MdiParent = this; criteriaRankingForm.StartPosition = FormStartPosition.Manual; criteriaRankingForm.Location = new Point(criteriaForm.Width, 0); criteriaRankingForm.Show(); } AlternativeListForm alternativeListForm = null; if (isFormOpened(typeof(AlternativeListForm)) == null) { alternativeListForm = new AlternativeListForm(); alternativeListForm.MdiParent = this; alternativeListForm.StartPosition = FormStartPosition.Manual; alternativeListForm.Location = new Point(0, criteriaForm.Height); alternativeListForm.Show(); } int countAlternative = alternativeListController.getAlternativeList(currentTopic.topicId.ToString()).Count; ResultForm resultForm = null; if (isFormOpened(typeof(ResultForm)) == null && countAlternative >= 2) { resultForm = new ResultForm(); resultForm.MdiParent = this; resultForm.StartPosition = FormStartPosition.Manual; resultForm.Location = new Point(alternativeListForm.Width, criteriaForm.Height); resultForm.Show(); } }
private void alternativeListToolStripMenuItem1_Click(object sender, EventArgs e) { AlternativeListForm alternativeListForm = null; if (isFormOpened(typeof(AlternativeListForm)) == null) { alternativeListForm = new AlternativeListForm(); alternativeListForm.MdiParent = this; alternativeListForm.Show(); } }
private void AddAlternativeForm_Load(object sender, EventArgs e) { foreach (var form in this.Owner.MdiChildren) { if (form.GetType() == typeof(AlternativeListForm)) { alternativeListForm = (AlternativeListForm)form; } } mainForm = (MainForm)this.Owner; criteriaController = new CriteriaController(); alternativeListController = new AlternativeListController(); currentTopicId = alternativeListForm.getCurrentTopicId(); currentUserName = alternativeListForm.getCurrentUserName(); if (action == "Edit") { this.Text = "Edit Alternative: " + selectedAlternativeName; txtAlternativeName.Text = selectedAlternativeName; btnAdd.Visible = false; btnEdit.Visible = true; } else if (action == "Add") { this.Text = "Add Alternative"; txtAlternativeName.Text = ""; btnAdd.Visible = true; btnEdit.Visible = false; } flowLayoutPanel1.Controls.Clear(); foreach (Criteria criteria in criteriaController.getCriteriaList(currentTopicId)) { int criteriaId = criteria.criteriaId; string criteriaName = criteria.criteriaName; string criteriaUnit = criteria.criteriaUnit; bool isBoolean = criteria.isBoolean; double value = 0; if (action == "Edit") { value = alternativeListController.valueLookup(criteriaId, selectedAlternativeName); } AddAlternativeUserControl addAlternativeUserControl = new AddAlternativeUserControl(criteriaId, criteriaName, criteriaUnit, isBoolean, value); addAlternativeUserControl.Parent = flowLayoutPanel1; flowLayoutPanel1.Controls.Add(addAlternativeUserControl); } }
public AlternativeListForm getAlternativeListForm() { AlternativeListForm alternativeListForm = alternativeListToolStripMenuItem_Click(this, new EventArgs()); return(alternativeListForm); }
private void btnExport_Click(object sender, EventArgs e) { saveFileDialog1.Title = "Export to PDF"; saveFileDialog1.Filter = "(*.pdf)|*.pdf"; saveFileDialog1.InitialDirectory = @"D:\"; saveFileDialog1.FileName = "AHP_" + mainForm.getCurrentTopic().topicName + "_" + mainForm.getCurrentUser().userName; saveFileDialog1.FileOk += saveFileDialog1_FileOk; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { try { iTextSharp.text.Document doc = new iTextSharp.text.Document(); PdfWriter pdfWriter = PdfWriter.GetInstance(doc, new FileStream(saveFileDialog1.FileName, FileMode.Create)); //pdfWriter.PageEvent = new ITextEvents(mainForm.getCurrentTopic().topicName.ToUpper()); // FONT DEFINITION //iTextSharp.text.pdf.BaseFont bfTitle = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.HELVETICA_BOLD, iTextSharp.text.pdf.BaseFont.CP1252, iTextSharp.text.pdf.BaseFont.EMBEDDED); //iTextSharp.text.Font fontTitle = new iTextSharp.text.Font(bfTitle, 15); //fontTitle.SetStyle(iTextSharp.text.Font.UNDERLINE); iTextSharp.text.pdf.BaseFont bfNormal = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.HELVETICA, iTextSharp.text.pdf.BaseFont.CP1252, iTextSharp.text.pdf.BaseFont.EMBEDDED); iTextSharp.text.pdf.BaseFont bfBold = iTextSharp.text.pdf.BaseFont.CreateFont(iTextSharp.text.pdf.BaseFont.HELVETICA_BOLD, iTextSharp.text.pdf.BaseFont.CP1252, iTextSharp.text.pdf.BaseFont.EMBEDDED); iTextSharp.text.Font fontSubtitle = new iTextSharp.text.Font(bfBold, 13); iTextSharp.text.Font fontColHeader = new iTextSharp.text.Font(bfBold, 11); iTextSharp.text.Font fontTable = new iTextSharp.text.Font(bfNormal, 10); iTextSharp.text.Font fontConclusion = new iTextSharp.text.Font(bfNormal, 10); fontConclusion.SetStyle(iTextSharp.text.Font.UNDERLINE); // HEADER AND FOOTER TwoColumnHeaderFooter PageEventHandler = new TwoColumnHeaderFooter(mainForm.getCurrentUser().userName); pdfWriter.PageEvent = PageEventHandler; PageEventHandler.Title = "AHP RESULT"; PageEventHandler.HeaderFont = FontFactory.GetFont(BaseFont.COURIER_BOLD, 10, iTextSharp.text.Font.BOLD); PageEventHandler.HeaderLeft = "Topic"; PageEventHandler.HeaderRight = mainForm.getCurrentTopic().topicName.ToUpper(); doc.Open(); // TITLE //Paragraph title = new Paragraph(mainForm.getCurrentTopic().topicName.ToUpper(), fontTitle); //title.Alignment = Element.ALIGN_CENTER; //doc.Add(title); doc.Add(new Paragraph(" ")); // SUBTITLE: DETAIL ALTERNATIVE Paragraph subtitle1 = new Paragraph("DETAIL ALTERNATIVE", fontSubtitle); subtitle1.Alignment = Element.ALIGN_CENTER; subtitle1.SpacingBefore = 25; subtitle1.SpacingAfter = 20; doc.Add(subtitle1); // TABLE DETAIL bool switchCloseAlternativeListForm = true; AlternativeListForm alternativeListForm = null; if (mainForm.isFormOpened(typeof(AlternativeListForm)) != null) { switchCloseAlternativeListForm = false; alternativeListForm = (AlternativeListForm)mainForm.isFormOpened(typeof(AlternativeListForm)); alternativeListForm.MdiParent = mainForm; alternativeListForm.Show(); } else { alternativeListForm = mainForm.getAlternativeListForm(); } DataGridView dataGridView = alternativeListForm.getDGV(); PdfPTable pdfPTable = new PdfPTable(dataGridView.ColumnCount); // Header Column foreach (DataGridViewColumn column in dataGridView.Columns) { PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText, fontColHeader)); //cell.BackgroundColor = new iTextSharp.text.Color(240, 240, 240); cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; pdfPTable.AddCell(cell); } // Adding DataRow foreach (DataGridViewRow row in dataGridView.Rows) { foreach (DataGridViewCell cell in row.Cells) { PdfPCell pdfPCell = new PdfPCell(new Phrase(cell.Value.ToString(), fontTable)); pdfPCell.HorizontalAlignment = Element.ALIGN_CENTER; pdfPCell.VerticalAlignment = Element.ALIGN_MIDDLE; pdfPTable.AddCell(pdfPCell); } } doc.Add(pdfPTable); mainForm.refreshAllChildrenForm(); if (switchCloseAlternativeListForm) { alternativeListForm.Close(); } // SUBTITLE: COMPARISON Paragraph subtitle2 = new Paragraph("COMPARISON", fontSubtitle); subtitle2.Alignment = Element.ALIGN_CENTER; subtitle2.SpacingBefore = 25; doc.Add(subtitle2); // CHART IMAGE MemoryStream ms = new MemoryStream(); chart1.SaveImage(ms, ChartImageFormat.Png); iTextSharp.text.Image chart_img = iTextSharp.text.Image.GetInstance(ms.ToArray()); chart_img.SetDpi(300, 300); chart_img.ScaleToFit(300f, 300f); chart_img.Alignment = Element.ALIGN_CENTER; doc.Add(chart_img); // SUBTITLE: CONCLUSION Paragraph subtitle3 = new Paragraph("CONCLUSION", fontSubtitle); subtitle3.Alignment = Element.ALIGN_CENTER; subtitle3.SpacingBefore = 25; doc.Add(subtitle3); // CONCLUSION List <List <string> > conclusion = resultController.conclusionBestWorst(currentTopicId); if (conclusion == null) { doc.Add(new Paragraph("Cannot conclude anything, since the data is all the same.", fontTable)); } else { // SUB SUBTITLE BEST ALTERNATIVE Paragraph subtitleBest = new Paragraph("Best Alternative(s)", fontConclusion); subtitleBest.SpacingBefore = 10; subtitleBest.SpacingAfter = 5; subtitleBest.Alignment = Element.ALIGN_CENTER; doc.Add(subtitleBest); int numbering = 1; foreach (List <string> conc in conclusion) { if (conc[0] == "Best") { string oneLine = /*numbering + ". " +*/ conc[1] + " (Best criteria: "; foreach (string crit in resultController.bestWorstCriteria(currentTopicId, conc)) { oneLine += crit + ", "; } Paragraph text = new Paragraph(oneLine.Substring(0, oneLine.Length - 2) + ")\n", fontTable); text.Alignment = Element.ALIGN_CENTER; doc.Add(text); numbering++; } } // SUB SUBTITLE WORST ALTERNATIVE Paragraph subtitleWorst = new Paragraph("Worst Alternative(s)", fontConclusion); subtitleWorst.SpacingBefore = 10; subtitleWorst.SpacingAfter = 5; subtitleWorst.Alignment = Element.ALIGN_CENTER; doc.Add(subtitleWorst); numbering = 1; foreach (List <string> conc in conclusion) { if (conc[0] == "Worst") { string oneLine = /*numbering + ". " +*/ conc[1] + " (Worst criteria: "; foreach (string crit in resultController.bestWorstCriteria(currentTopicId, conc)) { oneLine += crit + ", "; } Paragraph text = new Paragraph(oneLine.Substring(0, oneLine.Length - 2) + ")\n", fontTable); text.Alignment = Element.ALIGN_CENTER; doc.Add(text); numbering++; } } } doc.Close(); // DIALOG int start = saveFileDialog1.FileName.LastIndexOf('\\') + 1; int length = saveFileDialog1.FileName.Length; var mboxResponse = MessageBox.Show(this, "Successfully exported \"" + saveFileDialog1.FileName.Substring(start, length - start) + "\" to\n" + saveFileDialog1.FileName.Substring(0, start) + "\nDo you want to open the file?", "Export to PDF", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (mboxResponse == DialogResult.Yes) { System.Diagnostics.Process.Start(saveFileDialog1.FileName); } } catch (Exception ex) { MessageBox.Show(this, "An error occured:\n" + ex.Message, "Export to PDF", MessageBoxButtons.OK, MessageBoxIcon.Hand); } } }