private void metroTile5_Click(object sender, EventArgs e) { if (txt_reg_fee_paying.Text.Any(char.IsLetter) == true || txt_reg_fee_paying.Text == "" || Convert.ToDouble(txt_reg_fee_of_course.Text.Remove(txt_reg_fee_of_course.Text.Length - 2, 2)) < Convert.ToDouble(txt_reg_fee_paying.Text)) { MessageBox.Show("Please enter valid registration fee", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { DialogResult dr = MessageBox.Show("You are about to save a payment. Press yes to confirm", "Notification", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { d.insert("INSERT INTO PaymentDetails (Gross_amount,Discount_percent,Net_amount,Date,Time,stud_no_org_no,program_no,Remark) VALUES('" + txt_reg_fee_of_course.Text.Remove(txt_reg_fee_of_course.Text.Length - 2, 2) + "','0','" + txt_reg_fee_paying.Text + "','" + General_methods.get_current_date() + "','" + General_methods.get_current_time().ToString() + "','" + txt_studno.Text + "','None','Registration fee for diploma course')"); d.update("UPDATE Stud_details SET reg_fee='" + d.singleInt("SELECT MAX(Payment_No) FROM PaymentDetails").ToString() + "' WHERE stud_no='" + txt_studno.Text + "'"); MessageBox.Show("Details Saved Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult a1 = MessageBox.Show("Generate Recipt?", "Notofication", MessageBoxButtons.OK, MessageBoxIcon.Information); //this label is used for event firing label1.Text = General_methods.Generate_RandomNumber(0, 2837872).ToString(); if (a1 == DialogResult.Yes) { } else { } } } }
/// <summary> /// FUNCTION FOR EXPORT TO EXCEL /// </summary> /// <param name="dataTable"></param> /// <param name="worksheetName"></param> /// <param name="saveAsLocation"></param> /// <returns></returns> public bool WriteDataTableToExcel(System.Data.DataTable dataTable, string worksheetName, string saveAsLocation, string ReporType, string progtype, string user) { Microsoft.Office.Interop.Excel.Application excel; Microsoft.Office.Interop.Excel.Workbook excelworkBook; Microsoft.Office.Interop.Excel.Worksheet excelSheet; Microsoft.Office.Interop.Excel.Range excelCellrange; try { // Start Excel and get Application object. excel = new Microsoft.Office.Interop.Excel.Application(); // for making Excel visible excel.Visible = true; excel.DisplayAlerts = true; // Creation a new Workbook excelworkBook = excel.Workbooks.Add(Type.Missing); // Workk sheet excelSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelworkBook.ActiveSheet; excelSheet.Name = worksheetName; excelSheet.Cells[1, 1] = "Report Name - " + ReporType; excelSheet.Cells[2, 1] = "Date of Report Generation : " + General_methods.get_current_date(); excelSheet.Cells[3, 1] = "Time of Report Generation :" + General_methods.get_current_time(); excelSheet.Cells[4, 1] = "Report Created By :" + user; excelSheet.Cells[5, 1] = "Program Type :" + progtype; // loop through each row and add values to our sheet int rowcount = 6; foreach (DataRow datarow in dataTable.Rows) { //adding one to rowcount rowcount += 1; for (int i = 1; i <= dataTable.Columns.Count; i++) { // on the first iteration we add the column headers if (rowcount == 7) { excelSheet.Cells[6, i] = dataTable.Columns[i - 1].ColumnName; excelSheet.Cells.Font.Color = System.Drawing.Color.Black; excelSheet.Cells[6, i].Font.Bold = true; } excelSheet.Cells[rowcount, i] = datarow[i - 1].ToString(); //for alternate rows if (rowcount > 7) { if (i == dataTable.Columns.Count) { if (rowcount % 4 == 0) { excelCellrange = excelSheet.Range[excelSheet.Cells[rowcount, 1], excelSheet.Cells[rowcount, dataTable.Columns.Count]]; FormattingExcelCells(excelCellrange, "#CCCCFF", System.Drawing.Color.Black, false); } } } } } // now we resize the columns excelCellrange = excelSheet.Range[excelSheet.Cells[1, 1], excelSheet.Cells[rowcount, dataTable.Columns.Count]]; excelCellrange.EntireColumn.AutoFit(); Microsoft.Office.Interop.Excel.Borders border = excelCellrange.Borders; border.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; border.Weight = 2d; excelCellrange = excelSheet.Range[excelSheet.Cells[1, 1], excelSheet.Cells[5, dataTable.Columns.Count]]; FormattingExcelCells(excelCellrange, "#000099", System.Drawing.Color.White, true); excelSheet.Cells[1, 1].Font.Size = 20; //now save the workbook and exit Excel /*var worksheet = excelworkBook.Worksheets[1] as * Microsoft.Office.Interop.Excel.Worksheet; * * Microsoft.Office.Interop.Excel.Range chartRange; * * Microsoft.Office.Interop.Excel.ChartObjects xlCharts = (Microsoft.Office.Interop.Excel.ChartObjects)worksheet.ChartObjects(Type.Missing); * Microsoft.Office.Interop.Excel.ChartObject myChart = (Microsoft.Office.Interop.Excel.ChartObject)xlCharts.Add(10, 80, 300, 250); * Microsoft.Office.Interop.Excel.Chart chartPage = myChart.Chart; * * myChart.Name = "Program Budget Report - Expenses"; * chartRange = worksheet.get_Range("M4", "S6"); * chartPage.SetSourceData(chartRange); * chartPage.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlColumnClustered;*/ //excelworkBook.SaveAs(saveAsLocation); //excelworkBook.Close(); //excel.Quit(); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } finally { excelSheet = null; excelCellrange = null; excelworkBook = null; } }
private void metroTile4_Click(object sender, EventArgs e) { if (txt_mosule_wise_amount_after_discount.Text == "") { MessageBox.Show("Please calculate the final amount", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txt_amount_paying_module_wise.Text == "") { MessageBox.Show("Paying amounts for modules have not been confirmed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (cmb_payment_mode.Text == "") { MessageBox.Show("Please select payment method", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (cmb_payment_mode.SelectedIndex == 2 && txt_chequeno.Text == "") { MessageBox.Show("Please enter the cheque number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { DialogResult dr = MessageBox.Show("You are about to save a payment. Press yes to confirm", "Notification", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { d.insert("INSERT INTO PaymentDetails(Gross_amount,Discount_percent,Net_amount,Date,Time,stud_no_org_no,program_no,Remark,Payment_mode) VALUES ('" + txt_amount_paying_module_wise.Text.Remove(txt_amount_paying_module_wise.Text.Length - 2, 2).ToString() + "','" + txt_mod_wise_discount.Text + "','" + txt_mosule_wise_amount_after_discount.Text.Remove(txt_mosule_wise_amount_after_discount.Text.Length - 2, 2).ToString() + "','" + General_methods.get_current_date() + "','" + General_methods.get_current_time() + "','" + txt_studno.Text + "','None','Module wise Payement for Diploma course','" + cmb_payment_mode.Text + "')"); int id = d.singleInt("SELECT MAX(Payment_No) FROM PaymentDetails"); for (int i = 0; i < checkedListBox1.Items.Count; i++) { if (checkedListBox1.CheckedItems.Contains(checkedListBox1.Items[i]) == true && a.Contains(i) == false) { d.update("UPDATE Dip_stud_modules SET payement_no='" + id + "' WHERE stud_no='" + txt_studno.Text + "' AND module_no='" + General_methods.get_module_no_from_module_name(checkedListBox1.Items[i].ToString(), General_methods.get_course_no_from_course_name(txt_course_name.Text)) + "'"); } else { } } if (cmb_payment_mode.SelectedIndex == 2) { d.insert("INSERT INTO Cheque_payments (Payment_no,Cheque_no) VALUES ('" + d.singleInt("SELECT MAX(Payment_No) FROM PaymentDetails") + "','" + txt_chequeno.Text + "')"); } MessageBox.Show("Details Saved Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult a1 = MessageBox.Show("Generate Recipt?", "Notofication", MessageBoxButtons.OK, MessageBoxIcon.Information); //this label is used for event firing label1.Text = General_methods.Generate_RandomNumber(1, 678767).ToString(); ////////////// if (a1 == DialogResult.Yes) { } else { } } else { } } }
/// <summary> /// FUNCTION FOR EXPORT TO EXCEL /// </summary> /// <param name="dataTable"></param> /// <param name="worksheetName"></param> /// <param name="saveAsLocation"></param> /// <returns></returns> public bool WriteDataTableToExcel(DataTable dataTable1, DataTable dataTable2, string worksheetName, string saveAsLocation, string ReporType, string progtype, string user) { Microsoft.Office.Interop.Excel.Application excel; Microsoft.Office.Interop.Excel.Workbook excelworkBook; Microsoft.Office.Interop.Excel.Worksheet excelSheet; Microsoft.Office.Interop.Excel.Range excelCellrange; try { // Start Excel and get Application object. excel = new Microsoft.Office.Interop.Excel.Application(); // for making Excel visible excel.Visible = true; excel.DisplayAlerts = true; // Creation a new Workbook excelworkBook = excel.Workbooks.Add(Type.Missing); // Workk sheet excelSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelworkBook.ActiveSheet; excelSheet.Name = worksheetName; excelSheet.Cells[1, 1] = "Report Name - " + ReporType; excelSheet.Cells[2, 1] = "Date of Report Generation : " + General_methods.get_current_date(); excelSheet.Cells[3, 1] = "Time of Report Generation :" + General_methods.get_current_time(); excelSheet.Cells[4, 1] = "Report Created By :" + user; excelSheet.Cells[5, 1] = "Program Type :" + progtype; excelSheet.Cells[6, 1] = "Company Participants"; // loop through each row and add values to our sheet int rowcount = 7; foreach (DataRow datarow in dataTable1.Rows) { //adding one to rowcount rowcount += 1; for (int i = 1; i <= dataTable1.Columns.Count; i++) { // on the first iteration we add the column headers if (rowcount == 8) { excelSheet.Cells[7, i] = dataTable1.Columns[i - 1].ColumnName; excelSheet.Cells.Font.Color = System.Drawing.Color.Black; excelSheet.Cells[7, i].Font.Bold = true; } excelSheet.Cells[rowcount, i] = datarow[i - 1].ToString(); //for alternate rows if (rowcount > 8) { if (i == dataTable1.Columns.Count) { if (rowcount % 4 == 0) { excelCellrange = excelSheet.Range[excelSheet.Cells[rowcount, 1], excelSheet.Cells[rowcount, dataTable1.Columns.Count]]; FormattingExcelCells(excelCellrange, "#CCCCFF", System.Drawing.Color.Black, false); } } } } } // now we resize the columns excelCellrange = excelSheet.Range[excelSheet.Cells[1, 1], excelSheet.Cells[rowcount, dataTable1.Columns.Count]]; excelCellrange.EntireColumn.AutoFit(); Microsoft.Office.Interop.Excel.Borders border = excelCellrange.Borders; border.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; border.Weight = 2d; int newrowcount = rowcount + 5; int y = newrowcount; excelSheet.Cells[newrowcount - 1, 1] = "Individual Participants"; int x = newrowcount; //newrowcount =2; foreach (DataRow datarow in dataTable2.Rows) { //adding one to rowcount newrowcount += 1; for (int i = 1; i <= dataTable2.Columns.Count; i++) { // on the first iteration we add the column headers if (newrowcount == x + 1) { excelSheet.Cells[x, i] = dataTable2.Columns[i - 1].ColumnName; excelSheet.Cells.Font.Color = System.Drawing.Color.Black; excelSheet.Cells[x, i].Font.Bold = true; } excelSheet.Cells[newrowcount, i] = datarow[i - 1].ToString(); //for alternate rows if (newrowcount > x + 1) { if (i == dataTable2.Columns.Count) { if (newrowcount % 4 == 0) { excelCellrange = excelSheet.Range[excelSheet.Cells[newrowcount, 1], excelSheet.Cells[newrowcount, dataTable2.Columns.Count]]; FormattingExcelCells(excelCellrange, "#CCCCFF", System.Drawing.Color.Black, false); } } } } } excelCellrange = excelSheet.Range[excelSheet.Cells[x, 1], excelSheet.Cells[newrowcount, dataTable2.Columns.Count]]; excelCellrange.EntireColumn.AutoFit(); Microsoft.Office.Interop.Excel.Borders border2 = excelCellrange.Borders; border2.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; border2.Weight = 2d; excelCellrange = excelSheet.Range[excelSheet.Cells[1, 1], excelSheet.Cells[5, dataTable1.Columns.Count]]; FormattingExcelCells(excelCellrange, "#000099", System.Drawing.Color.White, true); excelSheet.Cells[1, 1].Font.Size = 20; excelSheet.Cells[6, 1].Font.Color = System.Drawing.Color.Red; excelSheet.Cells[6, 1].Font.Bold = true; excelSheet.Cells[y - 1, 1].Font.Color = System.Drawing.Color.Red; excelSheet.Cells[y - 1, 1].Font.Bold = true; Microsoft.Office.Interop.Excel.Worksheet newWorksheet; newWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)excelworkBook.ActiveSheet(); return(true); } catch (Exception ex) { //MessageBox.Show(ex.Message); return(false); } finally { excelSheet = null; excelCellrange = null; excelworkBook = null; } }
private void metroTile4_Click(object sender, EventArgs e) { string remark = "Payament for short programs / workshops (Individual) -" + txt_remark_individual.Text; if (txt_amount_payable_individual.Text == "") { MessageBox.Show("Please select participant", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txt_amount_paying_individual.Text == "") { MessageBox.Show("Please enter amount paying", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txt_discount_individual.Text == "") { MessageBox.Show("Please enter discount", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txt_netamount_individual.Text == "") { MessageBox.Show("Final amount not calculated", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (cmb_payment_mode2.Text == "") { MessageBox.Show("Please select payment method", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (cmb_payment_mode2.SelectedIndex == 2 && txt_cheque_no2.Text == "") { MessageBox.Show("Please enter the cheque number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { DialogResult dr = MessageBox.Show("You are about to save a payment. Press yes to confirm", "Notification", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { d.insert("INSERT INTO PaymentDetails(Gross_amount,Discount_percent,Net_amount,Date,Time,stud_no_org_no,program_no,Remark) VALUES ('" + txt_amount_paying_individual.Text.ToString() + "','" + txt_discount.Text + "','" + txt_netamount_individual.Text.Remove(txt_netamount_individual.Text.Length - 2, 2).ToString() + "','" + General_methods.get_current_date() + "','" + General_methods.get_current_time() + "','" + cmb_individual_participants.Text.Split('-').GetValue(0).ToString() + "','" + txt_progno.Text + "','" + remark + "')"); int id = d.singleInt("SELECT MAX(Payment_No) FROM PaymentDetails"); d.update("UPDATE Short_program_participation SET payment_no='" + id + "' WHERE ref_no='" + cmb_individual_participants.Text.Split('-').GetValue(0).ToString() + "'"); if (cmb_payment_mode2.SelectedIndex == 2) { d.insert("INSERT INTO Cheque_payments (Payment_no,Cheque_no) VALUES ('" + d.singleInt("SELECT MAX(Payment_No) FROM PaymentDetails") + "','" + txt_cheque_no2.Text + "')"); } MessageBox.Show("Details Saved Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult a1 = MessageBox.Show("Generate Recipt?", "Notofication", MessageBoxButtons.OK, MessageBoxIcon.Information); //this label is used for event firing label1.Text = General_methods.Generate_RandomNumber(1, 678767).ToString(); ////////////// if (a1 == DialogResult.Yes) { } else { } } else { } } }
private void metroTile1_Click(object sender, EventArgs e) { string remark = "Payament for short programs / workshops (Company) -" + txt_remark.Text; if (txt_netamount.Text == "") { MessageBox.Show("Please calculate the final amount", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (txt_amount.Text == "") { MessageBox.Show("Participants have not been selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (cmb_payment_mode.Text == "") { MessageBox.Show("Please select payment method", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (cmb_payment_mode.SelectedIndex == 2 && txt_chequeno.Text == "") { MessageBox.Show("Please enter the cheque number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { DialogResult dr = MessageBox.Show("You are about to save a payment. Press yes to confirm", "Notification", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { d.insert("INSERT INTO PaymentDetails(Gross_amount,Discount_percent,Net_amount,Date,Time,stud_no_org_no,program_no,Remark,Payment_mode) VALUES ('" + txt_amount.Text.Remove(txt_amount.Text.Length - 2, 2).ToString() + "','" + txt_discount.Text + "','" + txt_netamount.Text.Remove(txt_netamount.Text.Length - 2, 2).ToString() + "','" + General_methods.get_current_date() + "','" + General_methods.get_current_time() + "','" + General_methods.find_organization_no_from_organization_name(cmb_companies.Text) + "','" + txt_progno.Text + "','" + remark + "','" + cmb_payment_mode.Text + "')"); int id = d.singleInt("SELECT MAX(Payment_No) FROM PaymentDetails"); for (int i = 0; i < checkedListBox1.Items.Count; i++) { if (checkedListBox1.CheckedItems.Contains(checkedListBox1.Items[i]) == true && a.Contains(i) == false) { d.update("UPDATE Short_program_participation SET payment_no='" + id + "' WHERE ref_no='" + checkedListBox1.Items[i].ToString().Split('-').GetValue(1) + "'"); } else { } } if (cmb_payment_mode.SelectedIndex == 2) { d.insert("INSERT INTO Cheque_payments (Payment_no,Cheque_no) VALUES ('" + d.singleInt("SELECT MAX(Payment_No) FROM PaymentDetails") + "','" + txt_chequeno.Text + "')"); } MessageBox.Show("Details Saved Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult a1 = MessageBox.Show("Generate Recipt?", "Notofication", MessageBoxButtons.OK, MessageBoxIcon.Information); //this label is used for event firing label1.Text = General_methods.Generate_RandomNumber(1, 678767).ToString(); ////////////// if (a1 == DialogResult.Yes) { } else { } } else { } } }
/// <summary> /// FUNCTION FOR EXPORT TO EXCEL /// </summary> /// <param name="dataTable"></param> /// <param name="worksheetName"></param> /// <param name="saveAsLocation"></param> /// <returns></returns> public bool WriteDataTableToExcel(System.Data.DataTable dataTable, string worksheetName, string saveAsLocation, string ReporType, string progtype, string user, int No_of_individual_participants, string type = "program", string coursno = "null", string type2 = null) { Microsoft.Office.Interop.Excel.Application excel; Microsoft.Office.Interop.Excel.Workbook excelworkBook; Microsoft.Office.Interop.Excel.Worksheet excelSheet; Microsoft.Office.Interop.Excel.Range excelCellrange; try { // Start Excel and get Application object. excel = new Microsoft.Office.Interop.Excel.Application(); // for making Excel visible excel.Visible = true; excel.DisplayAlerts = true; // Creation a new Workbook excelworkBook = excel.Workbooks.Add(Type.Missing); // Workk sheet excelSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelworkBook.ActiveSheet; excelSheet.Name = worksheetName; excelSheet.Cells[1, 1] = "Report Name - " + ReporType; excelSheet.Cells[2, 1] = "Date of Report Generation : " + General_methods.get_current_date(); excelSheet.Cells[3, 1] = "Time of Report Generation :" + General_methods.get_current_time(); excelSheet.Cells[4, 1] = "Report Created By :" + user; if (type == "program") { excelSheet.Cells[5, 1] = "Program Type :" + progtype; } else if (type == "diploma") { excelSheet.Cells[5, 1] = "Course name :" + General_methods.get_course_name_from_course_no(coursno); } else if (type == "diploma-all batches") { excelSheet.Cells[5, 1] = "All Batches"; } // loop through each row and add values to our sheet int rowcount = 6; foreach (DataRow datarow in dataTable.Rows) { //adding one to rowcount rowcount += 1; for (int i = 1; i <= dataTable.Columns.Count; i++) { // on the first iteration we add the column headers if (rowcount == 7) { excelSheet.Cells[6, i] = dataTable.Columns[i - 1].ColumnName; excelSheet.Cells.Font.Color = System.Drawing.Color.Black; excelSheet.Cells[6, i].Font.Bold = true; } excelSheet.Cells[rowcount, i] = datarow[i - 1].ToString(); //for alternate rows if (rowcount > 7) { if (i == dataTable.Columns.Count) { if (rowcount % 4 == 0) { excelCellrange = excelSheet.Range[excelSheet.Cells[rowcount, 1], excelSheet.Cells[rowcount, dataTable.Columns.Count]]; FormattingExcelCells(excelCellrange, "#CCCCFF", System.Drawing.Color.Black, false); } } } } } if (type2 == null) { excelSheet.Cells[rowcount + 1, 1] = "Number of Individual Participants - "; excelSheet.Cells[rowcount + 1, 2] = No_of_individual_participants; } // now we resize the columns excelCellrange = excelSheet.Range[excelSheet.Cells[1, 1], excelSheet.Cells[rowcount + 1, dataTable.Columns.Count]]; excelCellrange.EntireColumn.AutoFit(); Microsoft.Office.Interop.Excel.Borders border = excelCellrange.Borders; border.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous; border.Weight = 2d; excelCellrange = excelSheet.Range[excelSheet.Cells[1, 1], excelSheet.Cells[5, dataTable.Columns.Count + 12]]; FormattingExcelCells(excelCellrange, "#000099", System.Drawing.Color.White, true); excelSheet.Cells[1, 1].Font.Size = 20; Microsoft.Office.Interop.Excel.Range chartRange; Microsoft.Office.Interop.Excel.ChartObjects xlCharts = (Microsoft.Office.Interop.Excel.ChartObjects)excelSheet.ChartObjects(Type.Missing); Microsoft.Office.Interop.Excel.ChartObject myChart = (Microsoft.Office.Interop.Excel.ChartObject)xlCharts.Add(10, 80, 300, 250); Microsoft.Office.Interop.Excel.Chart chartPage = myChart.Chart; chartRange = excelSheet.Range[excelSheet.Cells[7, 1], excelSheet.Cells[rowcount + 1, dataTable.Columns.Count]]; chartPage.SetSourceData(chartRange); chartPage.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlColumnClustered; return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } finally { excelSheet = null; excelCellrange = null; excelworkBook = null; } }