protected void btnProcessAll_Click(object sender, EventArgs e) { if (BillingService.IsMerchantCodeValid(Convert.ToInt32(ddlBranch.SelectedValue))) { string[] contractNumbers = gvwBilling.Rows.Cast <GridViewRow>() .Where(row => (row.Cells[row.Cells.Count - 1].Controls[1] as CheckBox).Checked) .Select(row => row.Cells[4].Text).ToArray(); BillingService.DeleteBillingHistoryByProcessDate(DateTime.Today); try { string billingFile = BillingService.ProcessBilling( Convert.ToInt32(ddlBranch.SelectedValue), Convert.ToInt32(ddlBillingType.SelectedValue), contractNumbers, DateTime.Today, User.Identity.Name, calFindDateFrom.SelectedDate.GetValueOrDefault(DateTime.Today), calFindDateTo.SelectedDate.GetValueOrDefault(DateTime.Today), Server.MapPath("~/billing/")); ClientScript.RegisterStartupScript(this.GetType(), "billing", String.Format("alert('Billing file created {0}');", billingFile), true); } catch (Exception ex) { WebFormHelper.SetLabelTextWithCssClass(lblStatus, ex.Message, LabelStyleNames.ErrorMessage); LogService.ErrorException(GetType().FullName, ex); } } else { ClientScript.RegisterStartupScript(this.GetType(), "billing", String.Format("alert('Invalid Merchant Code, please go to master Branch menu to set it up.');"), true); } }