コード例 #1
0
        private void btnSell_Click(object sender, EventArgs e)
        {
            if (grv.RowCount <= 0)
            {
                XtraMessageBox.Show("Please add some product to sell");
                return;
            }

            Sale s = new Sale();

            s.InvoiceNo  = txtINV.Text;
            s.SaleDate   = dtpSDT.DateTime;
            s.CustomerID = Convert.ToInt32(lueCNM.EditValue);
            s.Amount     = Convert.ToDouble(txtAMT.EditValue);
            s.Discount   = Convert.ToDouble(txtDSC.EditValue);
            s.Payment    = Convert.ToDouble(txtPAM.EditValue);
            s.Balance    = Convert.ToDouble(txtBAL.EditValue);

            Server2Client sc  = new Server2Client();
            Sales         sls = new Sales();

            sc = sls.AddSale(s);
            if (sc.Message != null)
            {
                XtraMessageBox.Show(sc.Message);
                return;
            }

            CustomerAccounts cas = new CustomerAccounts();
            CustomerAccount  ca  = new CustomerAccount();
            Customer         c   = new Customer();

            cas            = new CustomerAccounts();
            ca.CustomerID  = Convert.ToInt32(lueCNM.EditValue);
            ca.TransDate   = s.SaleDate;
            ca.Description = s.InvoiceNo;
            if (s.Balance == 0)
            {
                ca.Debit  = s.Payment;
                ca.Credit = s.Payment;
            }
            else
            {
                ca.Debit  = s.Amount - s.Discount;
                ca.Credit = s.Payment;
            }
            ca.Balance = CustomerBalance + s.Balance;
            sc         = cas.addTrans(ca);


            if (sc.Message != null)
            {
                XtraMessageBox.Show(sc.Message);
                return;
            }

            for (int i = 0; i <= grv.RowCount - 1; i++)
            {
                Products   prd = new Products();
                SaleDetail sd  = new SaleDetail();
                sd.InvoiceNo    = txtINV.Text;
                sd.ProductID    = Convert.ToInt32(grv.GetRowCellValue(i, colPID));
                sd.Quantity     = Convert.ToInt32(grv.GetRowCellValue(i, colQTY));
                sd.BuyingValue  = Convert.ToDouble(grv.GetRowCellValue(i, colBVL));
                sd.SellingValue = Convert.ToDouble(grv.GetRowCellValue(i, colSVL));
                sd.Amount       = sd.Quantity * sd.SellingValue;

                sc = new Server2Client();
                sc = sls.AddSaleDetails(sd);
                sc = prd.updateQuantity(sd.ProductID, sd.Quantity, "-");
            }

            if (XtraMessageBox.Show("Do you want to print receipt?", "Print Receipt", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                rptCashMemo rpt = new rptCashMemo()
                {
                    DataSource = dt
                };
                rpt.lblCNM.Text = cc.CustomerName;
                rpt.lblADR.Text = cc.Address;
                rpt.lblPHN.Text = cc.Phone;

                rpt.lblINV.Text = txtINV.Text;
                rpt.lblSDT.Text = dtpSDT.DateTime.ToShortDateString();

                rpt.lblPNM.DataBindings.Add("Text", null, "ProductName");
                rpt.lbSNO.DataBindings.Add("Text", null, "BarCode");
                rpt.lblQTY.DataBindings.Add("Text", null, "Quantity");
                rpt.lblPRC.DataBindings.Add("Text", null, "SellingValue", "{0:c}");
                rpt.lblAMT.DataBindings.Add("Text", null, "Amount", "{0:c}");
                rpt.lblDSC.Text = "(-) " + s.Discount.ToString("c2");
                rpt.lblTTL.Text = s.Payment.ToString("c2");
                rpt.lblAMW.Text = "Rupees " + Utils.NumbersToWords(Convert.ToInt32(s.Payment)) + " only";

                rpt.ShowPreviewDialog();
            }
            grd.DataSource = null;
            InitInvoiceNo();
            lueCAT.EditValue             = null;
            luePNM.EditValue             = null;
            lueCAT.Properties.DataSource = null;
            luePNM.Properties.DataSource = null;
            InitCategories();
            InitProducts();
            Reset();
        }