private void ShowReportLoadSheet(DataTable dtHeader, DataTable dtLinetest) { try { DataTable dtLine = new DataTable(); CreamBell_DMS_WebApps.App_Code.AmountToWords obj1 = new AmountToWords(); DataTable dtAmountWords = null; dtLine = dtLinetest; string query = "Select VALUE from ax.ACXLOADSHEETHEADER where LOADSHEET_NO='" + dtLinetest.Rows[0]["LOADSHEET_NO"].ToString() + "' and SITEID='" + Session["SiteCode"].ToString() + "'"; DataTable dt = obj.GetData(query); decimal amount = Math.Round(Convert.ToDecimal(dt.Rows[0]["VALUE"].ToString())); string Words = obj1.words(Convert.ToInt32(amount)); string queryAmountWords = "Select VALUE, '" + Words + "' as AMNTWORDS from ax.ACXLOADSHEETHEADER where LOADSHEET_NO='" + dtLinetest.Rows[0]["LOADSHEET_NO"].ToString() + "' and SITEID='" + Session["SiteCode"].ToString() + "'"; dtAmountWords = obj.GetData(queryAmountWords); ReportViewer1.ProcessingMode = ProcessingMode.Local; ReportViewer1.AsyncRendering = true; ReportDataSource RDS1 = new ReportDataSource("DSetHeader", dtHeader); ReportViewer1.LocalReport.DataSources.Clear(); ReportViewer1.LocalReport.DataSources.Add(RDS1); ReportDataSource RDS2 = new ReportDataSource("DSetLine", dtLine); ReportViewer1.LocalReport.DataSources.Add(RDS2); ReportDataSource RDS3 = new ReportDataSource("DSetAmountWords", dtAmountWords); ReportViewer1.LocalReport.DataSources.Add(RDS3); ReportViewer1.LocalReport.ReportPath = Server.MapPath("Reports\\LoadSheet.rdl"); ReportViewer1.ShowPrintButton = true; ReportViewer1.LocalReport.DisplayName = dtLinetest.Rows[0]["LOADSHEET_NO"].ToString(); #region generate PDF of ReportViewer string savePath = Server.MapPath("Downloads\\" + "LoaSheet" + ".pdf"); byte[] Bytes = ReportViewer1.LocalReport.Render(format: "PDF", deviceInfo: ""); Warning[] warnings; string[] streamIds; string mimeType = string.Empty; string encoding = string.Empty; string extension = string.Empty; byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings); bytelist.Add(bytes); #endregion } catch (Exception ex) { ErrorSignal.FromCurrentContext().Raise(ex); } }
private void ShowReportSaleInvoice_New(DataTable dtHeader, DataTable dtLinetest, string strIdSavePDF) { try { decimal GlobalTaxAmount = 0; DataTable dtAmountWords = null; DataTable dtLine = new DataTable(); CreamBell_DMS_WebApps.App_Code.AmountToWords obj1 = new AmountToWords(); decimal TotalAmount = 0; string InvoiceNo = dtHeader.Rows[0]["INVOICE_NO"].ToString(); if (dtLinetest.Rows.Count > 0) { dtLine.Columns.Add("SRNO"); dtLine.Columns.Add("PRODUCT_CODE"); dtLine.Columns.Add("PRODUCT_NAME"); dtLine.Columns.Add("PRODUCT_PACKSIZE"); dtLine.Columns.Add("BOX"); dtLine.Columns.Add("BoxConv"); dtLine.Columns.Add("MRP"); dtLine.Columns.Add("RATE"); dtLine.Columns.Add("LTR"); dtLine.Columns.Add("TAX_CODE"); dtLine.Columns.Add("CRATES"); dtLine.Columns.Add("AMOUNT"); dtLine.Columns.Add("TAX_AMOUNT"); dtLine.Columns.Add("LINEAMOUNT"); dtLine.Columns.Add("DISC_AMOUNT"); dtLine.Columns.Add("SEC_DISC_AMOUNT"); dtLine.Columns.Add("ADDTAX_AMOUNT"); dtLine.Columns.Add("ADDTAX_CODE"); dtLine.Columns.Add("PEValue"); dtLine.Columns.Add("TDValue"); dtLine.Columns.Add("TaxableAmt"); dtLine.Columns.Add("basic"); h1 = new HashSet <string>(); for (int i = 0; i < dtLinetest.Rows.Count; i++) { if (!h1.Contains(dtLinetest.Rows[i]["TAX_CODE"].ToString())) { h1.Add(dtLinetest.Rows[i]["TAX_CODE"].ToString()); } dtLine.Rows.Add(); dtLine.Rows[i]["SRNO"] = dtLinetest.Rows[i]["SRNO"].ToString(); dtLine.Rows[i]["PRODUCT_CODE"] = dtLinetest.Rows[i]["PRODUCT_CODE"].ToString(); dtLine.Rows[i]["PRODUCT_NAME"] = dtLinetest.Rows[i]["PRODUCT_NAME"].ToString(); dtLine.Rows[i]["PRODUCT_PACKSIZE"] = dtLinetest.Rows[i]["PRODUCT_PACKSIZE"]; dtLine.Rows[i]["BOX"] = Convert.ToDecimal(dtLinetest.Rows[i]["BOX"]); dtLine.Rows[i]["BoxConv"] = Convert.ToDecimal(dtLinetest.Rows[i]["BoxConv"]); dtLine.Rows[i]["MRP"] = Convert.ToDecimal(dtLinetest.Rows[i]["MRP"]); dtLine.Rows[i]["RATE"] = Convert.ToDecimal(dtLinetest.Rows[i]["RATE"]); dtLine.Rows[i]["LTR"] = Convert.ToDecimal(dtLinetest.Rows[i]["LTR"]); dtLine.Rows[i]["TAX_CODE"] = Convert.ToDecimal(dtLinetest.Rows[i]["TAX_CODE"]); dtLine.Rows[i]["CRATES"] = Convert.ToDecimal(dtLinetest.Rows[i]["CRATES"]); dtLine.Rows[i]["AMOUNT"] = Convert.ToDecimal(dtLinetest.Rows[i]["AMOUNT"]); dtLine.Rows[i]["TAX_AMOUNT"] = Convert.ToDecimal(dtLinetest.Rows[i]["TAX_AMOUNT"]); GlobalTaxAmount += Convert.ToDecimal(dtLinetest.Rows[i]["TAX_AMOUNT"]); dtLine.Rows[i]["LINEAMOUNT"] = Convert.ToDecimal(dtLinetest.Rows[i]["LINEAMOUNT"]); dtLine.Rows[i]["DISC_AMOUNT"] = Convert.ToDecimal(dtLinetest.Rows[i]["DISC_AMOUNT"]); dtLine.Rows[i]["ADDTAX_AMOUNT"] = Convert.ToDecimal(dtLinetest.Rows[i]["ADDTAX_AMOUNT"]); dtLine.Rows[i]["SEC_DISC_AMOUNT"] = Convert.ToDecimal(dtLinetest.Rows[i]["SEC_DISC_AMOUNT"]); dtLine.Rows[i]["ADDTAX_CODE"] = Convert.ToDecimal(dtLinetest.Rows[i]["ADDTAX_CODE"]); dtLine.Rows[i]["PEValue"] = Convert.ToDecimal(dtLinetest.Rows[i]["PEValue"]); dtLine.Rows[i]["TDValue"] = Convert.ToDecimal(dtLinetest.Rows[i]["TDValue"]); dtLine.Rows[i]["TaxableAmt"] = Convert.ToDecimal(dtLinetest.Rows[i]["TaxableAmt"]); dtLine.Rows[i]["basic"] = Convert.ToDecimal(dtLinetest.Rows[i]["basic"]); TotalAmount += Convert.ToDecimal(dtLinetest.Rows[i]["AMOUNT"]); } //decimal HeaderAmount = Convert.ToDecimal(dtHeader.Rows[0]["INVOICE_VALUE"].ToString());// decimal HeaderAmount = TotalAmount; decimal TotalTaxAmount = GlobalTaxAmount; //dtLine.AsEnumerable().Sum(row => row.Field<decimal>("TAX_AMOUNT")); //decimal TotalTaxAmount = 12 ; decimal TotalNetValue = HeaderAmount; // +TotalTaxAmount; //Math.Round(HeaderAmount + TotalTaxAmount); //---Calculating Round Off Value for the Sale Invoice Bill---// decimal RoundOffValue = 0; decimal FinalValueForWords = 0; double decimalpoints = Convert.ToDouble(Math.Abs(TotalNetValue - Math.Floor(TotalNetValue))); if (decimalpoints > 0.5) { RoundOffValue = (decimal)Math.Round(TotalNetValue); FinalValueForWords = RoundOffValue; //+ Convert.ToDecimal(decimalpoints); decimalpoints = 1 - decimalpoints; // if Rounding Value is greater than 0.50 then plus sign with decimal points. } else { decimalpoints = 0 - decimalpoints; // if Rounding Value is less than 0.50 then negative sign with decimal points. RoundOffValue = (decimal)Math.Floor(TotalNetValue); FinalValueForWords = RoundOffValue; } if (dtLinetest.Rows.Count > 0) { // h1.Remove("0.00"); //----For Finding the different TAX AMOUNT CODE----// int TaxCodeCount = (h1.Count) * 2; //--- Count the TAX_CODE rows----// int dtlinecount = dtLine.Rows.Count + 6 + TaxCodeCount; //---6 is for FOOTER ROWS COUNTS [TOTAL]---// int totalrec = dtlinecount % 41; if ((dtLinetest.Rows.Count > 41 && dtLinetest.Rows.Count < 49) || (totalrec > 0 && totalrec <= 8)) { totalrec = dtlinecount % 32; int totalcount = 32 - totalrec; ///------Total Rows on a single page is 25 if (totalrec != 0) { for (int i = 0; i < totalcount; i++) // -For adding the empty rows in a report. { DataRow dr = dtLine.NewRow(); dr[0] = ""; dr[1] = ""; dr[2] = ""; dr[3] = 0; dr[4] = 0; dr[5] = 0; dr[6] = 0; dr[7] = 0; dr[8] = 0; dr[9] = 0; dr[10] = 0; dr[11] = 0; dr[12] = 0; dr[13] = 0; dr[14] = 0; dr[15] = 0; dr[16] = 0; dr[17] = 0; dr[18] = 0; dr[19] = 0; dr[20] = 0; dr[21] = 0; dtLine.Rows.InsertAt(dr, dtLine.Rows.Count + 1); } } string Words = obj1.words(Convert.ToInt32(FinalValueForWords)); string queryAmountWords = "Select INVOICE_VALUE , '" + Words + "' as AMNTWORDS, " + decimalpoints + " as RoundOffValue from ax.ACXSALEINVOICEHEADER where INVOICE_NO='" + dtLinetest.Rows[0]["Invoice_No"].ToString() + "' and SITEID='" + Session["SiteCode"].ToString() + "'"; dtAmountWords = obj.GetData(queryAmountWords); ReportViewer1.AsyncRendering = true; ReportViewer1.ProcessingMode = ProcessingMode.Local; ReportDataSource RDS1 = new ReportDataSource("DSetHeader", dtHeader); ReportViewer1.LocalReport.DataSources.Clear(); ReportViewer1.LocalReport.DataSources.Add(RDS1); ReportDataSource RDS2 = new ReportDataSource("DSetLine", dtLine); ReportViewer1.LocalReport.DataSources.Add(RDS2); ReportDataSource RDS3 = new ReportDataSource("DSetAmountWords", dtAmountWords); ReportViewer1.LocalReport.DataSources.Add(RDS3); ReportViewer1.LocalReport.ReportPath = Server.MapPath("Reports\\SaleInvoice.rdl"); ReportViewer1.ShowPrintButton = true; } else { totalrec = dtlinecount % 41; int totalcount = 41 - totalrec; ///------Total Rows on a single page is 25 if (totalrec != 0) { for (int i = 0; i <= totalcount; i++) //-For adding the empty rows in a report. { DataRow dr = dtLine.NewRow(); dr[0] = ""; dr[1] = ""; dr[2] = ""; dr[3] = 0; dr[4] = 0; dr[5] = 0; dr[6] = 0; dr[7] = 0; dr[8] = 0; dr[9] = 0; dr[10] = 0; dr[11] = 0; dr[12] = 0; dr[13] = 0; dr[14] = 0; dr[15] = 0; dr[16] = 0; dr[17] = 0; dr[18] = 0; dr[19] = 0; dr[20] = 0; dr[21] = 0; dtLine.Rows.InsertAt(dr, dtLine.Rows.Count + 1); } } string Words = obj1.words(Convert.ToInt32(FinalValueForWords)); string queryAmountWords = "Select INVOICE_VALUE , '" + Words + "' as AMNTWORDS, " + decimalpoints + " as RoundOffValue from ax.ACXSALEINVOICEHEADER where INVOICE_NO='" + dtLinetest.Rows[0]["Invoice_No"].ToString() + "' and SITEID='" + Session["SiteCode"].ToString() + "'"; dtAmountWords = obj.GetData(queryAmountWords); ReportViewer1.AsyncRendering = true; ReportViewer1.ProcessingMode = ProcessingMode.Local; ReportDataSource RDS1 = new ReportDataSource("DSetHeader", dtHeader); ReportViewer1.LocalReport.DataSources.Clear(); ReportViewer1.LocalReport.DataSources.Add(RDS1); ReportDataSource RDS2 = new ReportDataSource("DSetLine", dtLine); ReportViewer1.LocalReport.DataSources.Add(RDS2); ReportDataSource RDS3 = new ReportDataSource("DSetAmountWords", dtAmountWords); ReportViewer1.LocalReport.DataSources.Add(RDS3); ReportViewer1.LocalReport.ReportPath = Server.MapPath("Reports\\SaleInvoice1.rdl"); ReportViewer1.ShowPrintButton = true; } } } ReportViewer1.LocalReport.DisplayName = dtLinetest.Rows[0]["Invoice_No"].ToString(); //ReportViewer1.LocalReport.Refresh(); //UpdatePanel1.Update(); #region generate PDF of ReportViewer string savePath = Server.MapPath("Downloads\\" + strIdSavePDF + ".pdf"); byte[] Bytes = ReportViewer1.LocalReport.Render(format: "PDF", deviceInfo: ""); using (FileStream stream = new FileStream(savePath, FileMode.Create)) { stream.Write(Bytes, 0, Bytes.Length); } //Warning[] warnings; //string[] streamIds; //string mimeType = string.Empty; //string encoding = string.Empty; //string extension = string.Empty; //byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings); //bytelist.Add(Bytes); #endregion } catch (Exception ex) { ErrorSignal.FromCurrentContext().Raise(ex); } }