private void cmdGenerateInvoices_Click(object sender, EventArgs e) { Cursor = System.Windows.Forms.Cursors.WaitCursor; using (Reports.PrintInvoicesReport frmPrintInvoiceReport = new Reports.PrintInvoicesReport()) { string sInvoiceDateFrom = ""; string sInvoiceDateTo = ""; if (chkFilterByDate.Checked) { sInvoiceDateFrom = txtInvoiceDateFrom.Text.Substring(6, 4) + "-" + txtInvoiceDateFrom.Text.Substring(3, 2) + "-" + txtInvoiceDateFrom.Text.Substring(0, 2); sInvoiceDateTo = txtInvoiceDateTo.Text.Substring(6, 4) + "-" + txtInvoiceDateTo.Text.Substring(3, 2) + "-" + txtInvoiceDateTo.Text.Substring(0, 2); } frmPrintInvoiceReport.ShowDialog(txtInvoiceFrom.Text, txtInvoiceTo.Text, txtCustomerFrom.Text, txtCustomerTo.Text, sInvoiceDateFrom, sInvoiceDateTo); } Cursor = System.Windows.Forms.Cursors.Default; }
private void cmdProcess_Click_1(object sender, EventArgs e) { cmdClose.Enabled = false; picFinish.Visible = false; picBusy.Visible = true; lblBusy.Text = "Processing Emails..."; int iEmailSelectedCount = 0; int iEmailErrorCount = 0; string[] aPrintInvoices = new string[0]; string sInvoicePrint = " WHERE HistoryHeader.DocumentNumber in ("; //validate email addresses foreach (DataGridViewRow dgRow in dgInvoiceList.Rows) { if (dgRow.Cells["clSendEmail"].Value == clSendEmail.TrueValue) { iEmailSelectedCount++; if (dgRow.Cells["clEmailAddress"].Value.ToString().Trim() != "") { bool bIsMail = isEmail(dgRow.Cells["clEmailAddress"].Value.ToString().Trim()); if (!bIsMail) { dgRow.DefaultCellStyle.BackColor = Color.Red; dgRow.Cells["clSendEmail"].Value = clSendEmail.FalseValue; iEmailErrorCount++; } } else { dgRow.DefaultCellStyle.BackColor = Color.Red; dgRow.Cells["clSendEmail"].Value = clSendEmail.FalseValue; iEmailErrorCount++; } } if (dgRow.Cells["clSendFax"].Value == clSendFax.TrueValue) { //iFaxSelectedCount++; } } if (iEmailSelectedCount > 0) { if (iEmailSelectedCount == iEmailErrorCount) { MessageBox.Show("All selected Email addresses have errors in", "Email Address Error"); } else { if (MessageBox.Show("You have selected '" + iEmailSelectedCount + "' Invoice(s) to send. \n\n " + iEmailErrorCount + " selected email addresses have errors in. \n\nDo you want to continue sending?", "Send Emails and Faxes", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { bPrintInvoice = false; pnlStatus.Visible = true; thrSendEmail = new Thread(delegate() { ProcessEmails(iEmailSelectedCount); }); thrSendEmail.Start(); } else { pnlStatus.Visible = false; } } } else { MessageBox.Show("No Invoices were selected to Email or Fax"); } //print selected Invoices int iPrintCount = 0; foreach (DataGridViewRow dgRow in dgInvoiceList.Rows) { if (dgRow.Cells["clPrintInvoice"].Value == clPrintInvoice.TrueValue) { iPrintCount++; sInvoicePrint += ",'" + dgRow.Cells["clInvoiceNr"].Value.ToString() + "'"; } } if (iPrintCount > 0) { sInvoicePrint = sInvoicePrint.Remove(40, 1); if (MessageBox.Show("You have selected '" + iPrintCount.ToString() + "' Invoice(s) to print. \n\n Do you want to continue printing?", "Print Emails and Faxes", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { Cursor = System.Windows.Forms.Cursors.WaitCursor; using (Reports.PrintInvoicesReport frmPrintInvoiceReport = new Reports.PrintInvoicesReport()) { frmPrintInvoiceReport.ShowDialog(sInvoicePrint, "", "", "", "", ""); } Cursor = System.Windows.Forms.Cursors.Default; } } }