private void CompanyBankingReport() { int index = 1; string sFileName = System.IO.Path.GetRandomFileName().Substring(0, 8); //int companyId = Account.GetAccountByUserName(Page.User.Identity.Name.ToString()).CompanyId; //int isDairy = 2; //Non Dairy string sGenName = "PREVIEW - FNB PAYMENTS CSV TEMPLATE.csv"; string claimMonth = ""; for (int i = 0; i < ListBoxClaimMonth.Items.Count; i++) { if (ListBoxClaimMonth.Items[i].Selected == true) { if (ListBoxClaimMonth.Items[i].Text == "ALL") { for (int j = 0; j < ListBoxClaimMonth.Items.Count; j++) { claimMonth += ListBoxClaimMonth.Items[j].Text + ","; } } else { claimMonth += ListBoxClaimMonth.Items[i].Text; } } } using (System.IO.StreamWriter SW = new System.IO.StreamWriter(Server.MapPath("Upload/" + sFileName + ".csv"))) { SW.WriteLine(String.Format("{0}", "PREVIEW - BInSol - U ver 1.00")); //SW.WriteLine(String.Format("{0}/{1}/{2}", claimMonth.Substring(5, 2), "01", claimMonth.Substring(0, 4))); SW.WriteLine(String.Format("{0}", DateTime.Now.Date.ToString())); SW.WriteLine("62351986644"); SW.WriteLine(""); SW.WriteLine("RECIPIENT NAME,RECIPIENT ACCOUNT,RECIPIENT ACCOUNT TYPE,BRANCHCODE,AMOUNT,OWN REFERENCE,RECIPIENT REFERENCE"); string row = ""; List <ClaimPaymentStaging> cs = ClaimPaymentStaging.GetClaimPaymentStagingFNBListByClaimMonthAndLocationId(claimMonth, Convert.ToInt32(DropDownListLocation.SelectedValue) /*, isDairy, companyId*/); if (cs.Count > 0) { foreach (ClaimPaymentStaging claim in cs) { row = String.Format("{0},{1},{2},{3},{4},{5},{6}", claim.Store, claim.AccountNumber, claim.AccountType, claim.BranchNumber, claim.TotalStoreValuePaid, claim.OwnReference, claim.RecipientReference); SW.WriteLine(row); index++; } SW.Close(); } else { LabelError.Text = "No rows returned."; PanelError.Visible = true; } } System.IO.FileStream fs = null; fs = System.IO.File.Open(Server.MapPath("Upload/" + sFileName + ".csv"), System.IO.FileMode.Open); byte[] btFile = new byte[fs.Length]; fs.Read(btFile, 0, Convert.ToInt32(fs.Length)); fs.Close(); Response.AddHeader("Content-disposition", "attachment; filename=" + sGenName); Response.ContentType = "application/octet-stream"; Response.BinaryWrite(btFile); Response.End(); }
protected void ButtonFNBPreview_Click(object sender, EventArgs e) { try { LabelError.Text = ""; string claimNumberList = ""; bool hasError = false; PanelErrorSpace.Visible = false; PanelSaveSpace.Visible = false; Guid batchId = Guid.NewGuid(); foreach (GridViewRow gridViewRow in GridViewResult.Rows) { HiddenField hiddenFieldStoreId = (HiddenField)gridViewRow.Cells[1].FindControl("HiddenFieldStoreId"); Label labelStoreCustomEmail = (Label)gridViewRow.Cells[4].FindControl("LabelStoreCustomEmail"); //3 Label labelClaimNumber = (Label)gridViewRow.Cells[5].FindControl("LabelClaimNumber"); //4 Label labelValueCurrent = (Label)gridViewRow.Cells[6].FindControl("LabelClaimValueCurrent"); //5 //Label labelPaidEmail = (Label)gridViewRow.Cells[10].FindControl("LabelStoreCustomEmail"); CheckBox checkBoxPayment = (CheckBox)gridViewRow.Cells[2].FindControl("CheckBoxPayment"); //11 HiddenField hiddenFieldClaimMonth = (HiddenField)gridViewRow.Cells[12].FindControl("HiddenFieldClaimMonth"); if (checkBoxPayment.Checked) { ClaimPaymentStaging claimPaymentStaging = new ClaimPaymentStaging(); claimPaymentStaging.ClaimPaymentStagingId = 0; claimPaymentStaging.ClaimNumber = labelClaimNumber.Text; claimPaymentStaging.StoreId = Convert.ToInt32(hiddenFieldStoreId.Value); claimPaymentStaging.ClaimValueCurrent = Convert.ToDecimal(labelValueCurrent.Text); claimPaymentStaging.PaidEmail = labelStoreCustomEmail.Text; claimPaymentStaging.ClaimMonth = hiddenFieldClaimMonth.Value.ToString();//String.Format("{0}/01",hiddenFieldClaimMonth.Value.ToString()); claimPaymentStaging.BatchId = batchId; claimPaymentStaging.CompanyId = Account.GetAccountByUserName(Page.User.Identity.Name.ToString()).CompanyId; claimPaymentStaging.ModifiedUser = this.Master.LoggedOnAccount; claimPaymentStaging.Save(); } } foreach (GridViewRow gridViewRow in GridViewResult.Rows) { Label labelClaimNumber = (Label)gridViewRow.Cells[5].FindControl("LabelClaimNumber"); CheckBox checkBoxPayment = (CheckBox)gridViewRow.Cells[2].FindControl("CheckBoxPayment"); if (checkBoxPayment.Checked) { claimNumberList += labelClaimNumber.Text + ","; } } if (Convert.ToInt32(DropDownListLocation.SelectedValue) == 0) { SearchByTextBox(); } else { BindGridViewResult(); } CompanyBankingReport(); } catch (System.Data.SqlClient.SqlException sqlEx) { LabelError.Text = ""; for (int i = 0; i < sqlEx.Errors.Count; i++) { LabelError.Text += (sqlEx.Errors[i].Message + "<br />"); } PanelError.Visible = true; } }