private void ExportAsBtn_Click(object sender, EventArgs e) { int GeneralNumber = -1; if (int.TryParse(RefNumberTxtBox.Text, out GeneralNumber)) { /*OK DO NOTHING*/ } else { MessageBox.Show("Please Select Reference Number by clicking on the desired row", MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } /* if (ExportAsComboBox.Text == ExportAsComboBox.Items[0].ToString())/*PDF*/ /* { * * } * else if (ExportAsComboBox.Text == ExportAsComboBox.Items[1].ToString())/*Excel*/ /*{ * * } * else * { * MessageBox.Show("Please Select Report Type", MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); * return; * }*/ string SaveAsPath = "", ExportPath = ""; bool ExportToPdf = false, ExportToExcel = false; SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "PDF file|*.pdf|Excel Sheet|*.xls"; saveFileDialog1.Title = "Save Report (A4)"; saveFileDialog1.FileName = "Adjust Inventory Report" + DateTime.Now.ToShortDateString(); saveFileDialog1.FileName = saveFileDialog1.FileName.ToString().Replace(@"/", "-"); saveFileDialog1.FileName = saveFileDialog1.FileName.ToString().Replace(@"\\", "-"); if (saveFileDialog1.ShowDialog() == DialogResult.OK) { SaveAsPath = saveFileDialog1.FileName; switch (saveFileDialog1.FilterIndex) { case 1: ExportToPdf = true; ExportPath = SaveAsPath; break; case 2: //THIS IS ONLY EXCEL ExportToExcel = true; ExportPath = SaveAsPath; break; } } bool retval = false; if (ExportToPdf) { retval = InventoryReports.InventoryAdjustReport(GeneralNumber, true, false, false, true, false, ExportPath, false); } else if (ExportToExcel) { retval = InventoryReports.InventoryAdjustReport(GeneralNumber, true, false, false, false, true, ExportPath, false); } if (retval) { if (ExportToPdf || ExportToExcel) { Process.Start(ExportPath); } } else { MessageBox.Show(MsgTxt.NoDataTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Hand); } }