Exemple #1
0
        public void BillPrint(int v)
        {
            this.RvBills.RefreshReport();
            RvBills.Visible                = true;
            RvBills.ProcessingMode         = ProcessingMode.Local;
            RvBills.LocalReport.ReportPath = "../../Reports/BillsWithFooter.rdlc";

            dAL_Bills = new DAL_Bills();
            var listPDetails = dAL_Bills.GetBillParticularsDetails(new Models.M_BillParticulars_RQ()
            {
                BillID = v
            });
            var listBDetails = dAL_Bills.GetBillDetails(new Models.M_Bills_RQ()
            {
                BillID = v
            });

            if (listBDetails != null && listBDetails.Count > 0)
            {
                listBDetails[0].AmountInWord = "Rupees " + CommonConstants.ConvertNumbertoWords(Convert.ToString(listBDetails[0].BillAmout)) + " Only.";
            }
            DataTable dtBillParticularDetails = new DataTable();
            DataTable dtdsBillReports         = new DataTable();

            dtdsBillReports         = listBDetails.ToDataTable <M_Bills>();
            dtBillParticularDetails = listPDetails.ToDataTable <M_BillParticulars>();
            ReportDataSource rdsBillParticularDetails = new ReportDataSource("dsBillParticularDetails", dtBillParticularDetails);
            ReportDataSource rdsdsBillReports         = new ReportDataSource("dsBillReports", dtdsBillReports);

            RvBills.LocalReport.DataSources.Clear();
            RvBills.LocalReport.DataSources.Add(rdsBillParticularDetails);
            RvBills.LocalReport.DataSources.Add(rdsdsBillReports);
            RvBills.LocalReport.DisplayName = Convert.ToString(dtdsBillReports.Rows[0]["BillTo"]).Replace('/', '_').Replace(' ', '_') + Convert.ToDateTime(dtdsBillReports.Rows[0]["BillDate"]).ToString("dd_MMM_yyyy");
            RvBills.LocalReport.Refresh();
            RvBills.RefreshReport();
            this.RvBills.RefreshReport();
        }
Exemple #2
0
        public void SavePDF(int v, bool sendMail)
        {
            this.RvBills.RefreshReport();
            RvBills.Visible                = true;
            RvBills.ProcessingMode         = ProcessingMode.Local;
            RvBills.LocalReport.ReportPath = "../../Reports/BillsWithFooter.rdlc";

            dAL_Bills = new DAL_Bills();
            var listPDetails = dAL_Bills.GetBillParticularsDetails(new Models.M_BillParticulars_RQ()
            {
                BillID = v
            });
            var listBDetails = dAL_Bills.GetBillDetails(new Models.M_Bills_RQ()
            {
                BillID = v
            });

            if (listBDetails != null && listBDetails.Count > 0)
            {
                listBDetails[0].AmountInWord = "Rupees " + CommonConstants.ConvertNumbertoWords(Convert.ToString(listBDetails[0].BillAmout)) + " Only.";
            }
            DataTable dtBillParticularDetails = new DataTable();
            DataTable dtdsBillReports         = new DataTable();

            dtdsBillReports         = listBDetails.ToDataTable <M_Bills>();
            dtBillParticularDetails = listPDetails.ToDataTable <M_BillParticulars>();
            ReportDataSource rdsBillParticularDetails = new ReportDataSource("dsBillParticularDetails", dtBillParticularDetails);
            ReportDataSource rdsdsBillReports         = new ReportDataSource("dsBillReports", dtdsBillReports);

            RvBills.LocalReport.DataSources.Clear();
            RvBills.LocalReport.DataSources.Add(rdsBillParticularDetails);
            RvBills.LocalReport.DataSources.Add(rdsdsBillReports);
            string filepath = (Convert.ToString(dtdsBillReports.Rows[0]["BillTo"]).Replace('/', '_').Replace(' ', '_')).TrimEnd('_');
            string filename = Convert.ToString(dtdsBillReports.Rows[0]["BillTo"]).Replace('/', '_').Replace(' ', '_') + Convert.ToDateTime(dtdsBillReports.Rows[0]["BillDate"]).ToString("ddMMM_yyyy");

            RvBills.LocalReport.DisplayName = filename;
            RvBills.LocalReport.Refresh();
            RvBills.RefreshReport();
            //   this.RvBills.RefreshReport();
            byte[] Bytes = RvBills.LocalReport.Render(format: "PDF", deviceInfo: "");

            //Create Folder
            string folderpath  = ConfigurationManager.AppSettings["FilePath"].ToString();
            string strFullPath = folderpath;

            if (!Convert.ToBoolean(dtdsBillReports.Rows[0]["IsIndividual"]))
            {
                if (!Directory.Exists(folderpath + filepath))
                {
                    Directory.CreateDirectory(folderpath + filepath);
                }
                strFullPath = strFullPath + filepath + '\\' + filename + ".pdf";
            }
            else
            {
                strFullPath = strFullPath + filename + ".pdf";
            }
            string strFullpathNewName = strFullPath.Substring(0, strFullPath.LastIndexOf('.')) + ".pdf";

            if (File.Exists(strFullpathNewName))
            {
                int index = 1;
                strFullpathNewName = strFullPath.Substring(0, strFullPath.LastIndexOf('.')) + "(" + index + ").pdf";
                strFullPath        = strFullPath.Substring(0, strFullPath.LastIndexOf('.')) + "(" + index + ").pdf";

                while (File.Exists(strFullpathNewName))
                {
                    strFullpathNewName = strFullPath.Substring(0, strFullPath.LastIndexOf('.') - 3) + "(" + ++index + ").pdf";
                    strFullPath        = strFullPath.Substring(0, strFullPath.LastIndexOf('.') - 3) + "(" + index + ").pdf";
                }
            }
            using (FileStream stream = new FileStream(strFullPath, FileMode.Create))
            {
                stream.Write(Bytes, 0, Bytes.Length);
            }
            if (sendMail)
            {
                string subject = "Bill for the month of " + Convert.ToDateTime(dtdsBillReports.Rows[0]["BillDate"]).ToString("MMM yyyy");
                var    IsSent  = EmailSender.SendEmail(Convert.ToString(dtdsBillReports.Rows[0]["EmailID"]), strFullPath, subject);
                if (IsSent)
                {
                    CommonConstants.ShowMessageBox("Successfully, Bill has been emailed !!", "Success !!", MessageBoxIcon.Information);
                }
                else
                {
                    CommonConstants.ShowMessageBox("Bill has not been emailed.Is email id valid? ", "Failed !!", MessageBoxIcon.Warning);
                }
            }
            else
            {
                CommonConstants.ShowMessageBox("Bill has been saved at " + strFullpathNewName, "Success !!", MessageBoxIcon.Information);
            }
        }