示例#1
0
        /// <summary>



        public void CustomerBill(string BillNo, string Type)
        {
            string    company        = "SELECT * from CompanyMaster";
            DataTable dt_CompanyInfo = _objsqlhelper.GetDataTable(company);

            string    BillingDetails    = "Select * from CustomerBill Where BillNo='" + BillNo + "' and (PermanentDelete = 0 or PermanentDelete is Null) ";
            DataTable dt_BillingDetails = _objsqlhelper.GetDataTable(BillingDetails);


            string BillType, PayType;

            if (dt_BillingDetails.Rows[0]["State"].ToString() == dt_CompanyInfo.Rows[0]["State"].ToString())
            {
                BillType = "GST_Interstate";
            }
            else
            {
                BillType = "GST_OtherState";
            }

            string         crname     = "Select SaleBill from CrystalReport Where Type='" + BillType + "'";
            string         str_crname = _objsqlhelper.ExecuteScalar(crname);
            ReportDocument _objReport = new ReportDocument();

            _objReport.Load(Environment.CurrentDirectory + "\\" + str_crname);



            _objReport.Database.Tables["CompanyInfo"].SetDataSource(dt_CompanyInfo);


            _objReport.Database.Tables["CustomerBill"].SetDataSource(dt_BillingDetails);

            DataTable dt_CustomerInfo = _sales.GetCustomerByBill(BillNo);

            _objReport.Database.Tables["CustomerDetails"].SetDataSource(dt_CustomerInfo);

            DataTable dt_ItemsDetails = _sales.GetBillItem(BillNo, "Sale");

            _objReport.Database.Tables["BillItem"].SetDataSource(dt_ItemsDetails);
            string qty = Convert.ToString(_common.sumDataTableColumn(dt_ItemsDetails, "Qty"));

            DataTable dt_Payment = _a.getpaymentByBill(BillNo, "Sale", "0");

            _objReport.Database.Tables["Payment"].SetDataSource(dt_Payment);

            try
            {
                string Balance = Convert.ToString(_sales.GetBalance(dt_CustomerInfo.Rows[0]["CustId"].ToString(), "Sale"));
                _objReport.SetParameterValue("Balance", Balance);
            }
            catch (Exception ex)
            {
                _error.AddException(ex, "ReportViewer");
                MessageBox.Show(ex.ToString());
            }

            try
            {
                PayType = "Cash";
                if (dt_Payment.Rows.Count > 0)
                {
                    if (dt_BillingDetails.Rows[0]["BillAmount"] == dt_Payment.Rows[0]["Amt"])
                    {
                        PayType = "Cash";
                    }
                    else
                    {
                        PayType = "Credit";
                    }
                }
                _objReport.SetParameterValue("Type", PayType);
            }
            catch (Exception ex)
            {
                _error.AddException(ex, "ReportViewer");
            }

            try
            {
                double inword = Convert.ToDouble(dt_BillingDetails.Rows[0]["BillAmount"].ToString());
                inword = Math.Round(inword);
                int    number        = Convert.ToInt32(inword);
                string inwordsString = _objCommon.NumberToWords(number);
                _objReport.SetParameterValue("inwords", inwordsString);
            }
            catch (Exception ex)
            {
                _error.AddException(ex, "ReportViewer");
            }

            try
            {
                _objReport.SetParameterValue("Qty", qty);
            }
            catch (Exception ex)
            {
                _error.AddException(ex, "ReportViewer");
            }

            if (Type == "Print")
            {
                if (_objPrinterSetting.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        int Copies = _objPrinterSetting.copies;

                        _objReport.PrintOptions.PrinterName = _objPrinterSetting.PrinterName;
                        _objReport.PrintToPrinter(Copies, true, 0, 0);
                        printresult = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                    if (printresult == true)
                    {
                        printresult = false;
                    }
                }
                else
                {
                    crReportViewer.ReportSource = _objReport;
                    crReportViewer.Show();
                    return;
                }
            }
            else
            {
                crReportViewer.ReportSource = _objReport;
                crReportViewer.Show();
                return;
            }
        }