private void btnCusName_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtComname.Text))
            {
                PurchaseReportCom objPur  = new PurchaseReportCom();
                rptViewer         objView = new rptViewer();
                objPur.SetParameterValue("@CompanyID", txtComname.Text);
                PurchaseInvoiceBL obj = new PurchaseInvoiceBL()
                {
                    companyID = Convert.ToInt32(txtComname.Text)
                };
                DataTable dt = obj.SelectByCompany();
                if (dt.Rows.Count > 0)
                {
                    objPur.SetDataSource(dt);
                    objView.crptViewer.ReportSource = objPur;
                    objView.WindowState             = FormWindowState.Maximized;
                    objView.ShowDialog();
                }

                else
                {
                    MessageBox.Show("No Record Found");
                }
                // crptViewerPurchase.ReportSource = objPur;
            }
            else if (!string.IsNullOrEmpty(txtInvoice.Text))
            {
                PurchaseInvoiceReport objPurchase = new PurchaseInvoiceReport();
                rptViewer             objView     = new rptViewer();
                objPurchase.SetParameterValue("@PInvoice", txtInvoice.Text);
                PurchaseInvoiceBL obj = new PurchaseInvoiceBL()
                {
                    PInvoice = Convert.ToInt32(txtInvoice.Text)
                };
                DataTable dt = obj.Search();
                if (dt.Rows.Count > 0)
                {
                    objPurchase.SetDataSource(dt);
                    objView.crptViewer.ReportSource = objPurchase;
                    objView.WindowState             = FormWindowState.Maximized;
                    objView.ShowDialog();
                }
                else
                {
                    MessageBox.Show("No Record Found");
                }
                //crptViewerPurchase.ReportSource = objPurchase;
                txtInvoice.Clear();
            }
            else
            {
                MessageBox.Show("Please Enter Company ID");
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            PurchaseInvoiceBL objpur = new PurchaseInvoiceBL();

            for (int i = 0; i < dgvProduct.Rows.Count; i++)
            {
                objpur.ProductID = Convert.ToInt32(dgvProduct.Rows[i].Cells[1].Value.ToString());
                objpur.Quantity  = Convert.ToInt32(dgvProduct.Rows[i].Cells[4].Value.ToString());
                objpur.ProdUpdate();
            }
            PurchaseInvoiceBL objCtn = new PurchaseInvoiceBL();

            for (int i = 0; i < dgvProduct.Rows.Count; i++)
            {
                objCtn.ProductID = Convert.ToInt32(dgvProduct.Rows[i].Cells[1].Value.ToString());
                objCtn.Ctn       = Convert.ToInt32(dgvProduct.Rows[i].Cells[7].Value.ToString());
                objCtn.CtnUpdate();
            }



            PurchaseInvoiceBL objmas = new PurchaseInvoiceBL()
            {
                PInvoice     = Convert.ToInt32(txtInvoiceID.Text),
                companyID    = Convert.ToInt32(txtComID.Text),
                Discount     = Convert.ToDecimal(txtBillDiscount.Text),
                PurchaseDate = DateTime.Parse(txtPurInvoiceDate.Text),
                TotalAmount  = Convert.ToDecimal(txttotalAmount.Text),
                Payment      = Convert.ToDecimal(txtTotalPay.Text),
                DuePayment   = Convert.ToDecimal(txtPayDue.Text),
                furDiscount  = Convert.ToDecimal(txtfurDiscount.Text),
                GrandTotal   = Convert.ToDecimal(txtGrandTotal.Text)
            };

            PurchaseInvoiceBL objDet = new PurchaseInvoiceBL();

            for (int i = 0; i < dgvProduct.Rows.Count; i++)
            {
                objDet.PInvoice  = Convert.ToInt32(txtInvoiceID.Text);
                objDet.ProductID = Convert.ToInt32(dgvProduct.Rows[i].Cells[1].Value.ToString());
                objDet.TP        = Convert.ToDecimal(dgvProduct.Rows[i].Cells[3].Value.ToString());
                objDet.Quantity  = Convert.ToInt32(dgvProduct.Rows[i].Cells[4].Value.ToString());
                objDet.frieght   = Convert.ToDecimal(dgvProduct.Rows[i].Cells[6].Value.ToString());
                objDet.Ctn       = Convert.ToDecimal(dgvProduct.Rows[i].Cells[7].Value.ToString());
                objDet.Amount    = Convert.ToDecimal(dgvProduct.Rows[i].Cells[8].Value.ToString());
                objDet.SaveDetail();
            }
            objmas.SaveMaster();
            PurchaseLedgerBL objLedger = new PurchaseLedgerBL();

            objLedger.PInvoice    = Convert.ToInt32(txtInvoiceID.Text);
            objLedger.CompanyID   = Convert.ToInt32(txtComID.Text);
            objLedger.Credit      = Convert.ToDecimal(txtPayDue.Text);
            objLedger.Debit       = 0;
            objLedger.Date        = Convert.ToDateTime(txtPurInvoiceDate.Text);
            objLedger.Balance     = Convert.ToDecimal(txtnewBalance.Text);
            objLedger.Description = "Debit";
            objLedger.save();
            (new PurchaseLedgerBL()).UpdateBalance(objLedger.Balance, objLedger.CompanyID);

            PurchaseInvoiceReport objretp = new PurchaseInvoiceReport();
            rptViewer             objView = new rptViewer();

            objretp.SetParameterValue("@PInvoice", txtInvoiceID.Text);
            PurchaseInvoiceBL objBl = new PurchaseInvoiceBL()
            {
                PInvoice = Convert.ToInt32(txtInvoiceID.Text)
            };
            var dt = objBl.Search();

            if (dt != null)
            {
                objretp.SetDataSource(dt);
                objView.crptViewer.ReportSource = objretp;
                objView.WindowState             = FormWindowState.Maximized;
                objView.ShowDialog();
            }
            ClearForm();
            ChkFrieghtOrder.Checked = false;
            btnNew.Enabled          = true;
        }