private void barButtonItem4_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            int rs_PROVIDER_PAYMENT, rs_PROVIDER_PAYMENT_detail;

            rs_PROVIDER_PAYMENT        = -1;
            rs_PROVIDER_PAYMENT_detail = -1;
            PROVIDER_PAYMENT        _PROVIDER_PAYMENT        = new PROVIDER_PAYMENT();
            PROVIDER_PAYMENT_DETAIL _PROVIDER_PAYMENT_detail = new PROVIDER_PAYMENT_DETAIL();

            if (MessageBox.Show("Bạn Muốn Xóa Phiếu Chi Này?", "Cảnh Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
            {
                if (gridView1.RowCount > 0)
                {
                    string id = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns[0]).ToString();
                    _PROVIDER_PAYMENT          = new PROVIDER_PAYMENTController().PROVIDER_PAYMENT_GetbyRefID(id.Trim());
                    _PROVIDER_PAYMENT_detail   = new PROVIDER_PAYMENT_DETAILController().PROVIDER_PAYMENT_DETAIL_GetbyPaymentID(_PROVIDER_PAYMENT.ID);
                    rs_PROVIDER_PAYMENT        = new PROVIDER_PAYMENTController().PROVIDER_PAYMENT_Delete2011(_PROVIDER_PAYMENT.ID, _PROVIDER_PAYMENT.RefOrgNo);
                    rs_PROVIDER_PAYMENT_detail = new PROVIDER_PAYMENT_DETAILController().PROVIDER_PAYMENT_DETAIL_Delete(_PROVIDER_PAYMENT_detail.ID);
                    if ((rs_PROVIDER_PAYMENT > -1) && (rs_PROVIDER_PAYMENT_detail > -1))
                    {
                        MessageBox.Show("Phiếu Chi đã được xóa", "Thông báo");
                    }
                    else
                    {
                        MessageBox.Show("Phiếu Chi không được xóa", "Thông báo");
                    }
                    gridControl1.DataSource = new PROVIDER_PAYMENTController().PROVIDER_PAYMENT_GetList();
                }
            }
        }
        public string CreatePhieuChi()
        {
            string PhieuChi, Temp_Chi, Number_PC;

            PhieuChi  = ""; //Trả về số phiếu thu
            Temp_Chi  = ""; //Số phiếu tạm
            Number_PC = ""; // Number phiếu thu
            PROVIDER_PAYMENT _provider_PC = new PROVIDER_PAYMENTController().PROVIDER_PAYMENT_Top1RefID("NV000001");

            Temp_Chi = _provider_PC.RefID;
            if (Temp_Chi != "")
            {
                Number_PC = Temp_Chi.Substring(Temp_Chi.Length - 6, 6);
                Number_PC = (long.Parse(Number_PC.ToString()) + 1).ToString();
                PhieuChi  = Number_PC;
                for (int i = 0; i < 6 - Number_PC.Length; i++)
                {
                    PhieuChi = "0" + PhieuChi;
                }
                PhieuChi = Temp_Chi.Substring(0, Temp_Chi.Length - 6) + PhieuChi;
            }
            return(PhieuChi);
        }
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            int rs_provider, rs_provider_detail;

            ////
            if (double.Parse(calcTienTra.Text.Trim()) > double.Parse(calcConNo.Text.Trim()))
            {
                calcTienTra.Text = calcConNo.Text;
            }
            _provider_payment.ID            = Guid.NewGuid();
            _provider_payment.RefID         = txtSoPhieu.Text.Trim();
            _provider_payment.RefDate       = DateTime.Now;
            _provider_payment.RefType       = 42;
            _provider_payment.RefStatus     = 0;
            _provider_payment.RefOrgNo      = lookUpChungTu.Text;
            _provider_payment.CurrencyID    = "VND";
            _provider_payment.PaymentMethod = new STOCK_INWARDController().STOCK_INWARD_Get(lookUpChungTu.Text).PaymentMethod;
            _provider_payment.ExchangeRate  = 1;
            _provider_payment.CustomerID    = MaKhachHang;
            _provider_payment.CustomerName  = lookUpTenKH.Text;
            _provider_payment.Amount        = double.Parse(calcTienTra.Text);
            _provider_payment.CreatedBy     = "admin";
            _provider_payment.ModifiedBy    = "admin";
            _provider_payment.CreatedDate   = DateTime.Now;
            _provider_payment.ModifiedDate  = _provider_payment.CreatedDate;
            _provider_payment.OwnerID       = "NV000001";
            _provider_payment.Description   = memoEdit1.Text.Trim();
            _provider_payment.Active        = true;
            PROVIDER_PAYMENTController _provider_payment_controller = new PROVIDER_PAYMENTController();

            /////
            _provider_payment_detail.PaymentID    = _provider_payment.ID;
            _provider_payment_detail.ID           = Guid.NewGuid();
            _provider_payment_detail.RefOrgNo     = Guid.NewGuid();
            _provider_payment_detail.CurrencyID   = _provider_payment.CurrencyID;
            _provider_payment_detail.ExchangeRate = 1;
            _provider_payment_detail.Quantity     = 1;
            _provider_payment_detail.Amount       = double.Parse(calcSoTien.Text);
            _provider_payment_detail.Debit        = double.Parse(calcConNo.Text);
            _provider_payment_detail.Payment      = double.Parse(calcTienTra.Text);
            _provider_payment_detail.Description  = lookUpTenKH.Text;
            PROVIDER_PAYMENT_DETAILController _provider_payment_detail_controller = new PROVIDER_PAYMENT_DETAILController();
            //////
            DEBT           _debt           = new DEBT();
            DEBTController _debtcontroller = new DEBTController();

            //DEBTController _debtcontroller1 = new DEBTController();
            _debt         = _debtcontroller.DEBT_GetbyRefID(lookUpChungTu.Text.Trim());
            _debt.Payment = _debt.Payment + double.Parse(calcTienTra.Text.Trim());
            _debt.Balance = _debt.Balance - double.Parse(calcTienTra.Text.Trim());
            _debt.FAmount = _debt.Balance;
            _provider_payment_detail.RefOrgNo = _debt.ID;
            _provider_payment.PaymentMethod   = _debt.PaymentMethod;

            if (_debt.Payment == 0)
            {
                _debt.IsChanged = true;
            }
            if (txtSoPhieu.Text != "")
            {
                try
                {
                    rs_provider        = _provider_payment_controller.PROVIDER_PAYMENT_Insert(_provider_payment);
                    rs_provider_detail = _provider_payment_detail_controller.PROVIDER_PAYMENT_DETAIL_Insert(_provider_payment_detail);
                    //rs_debt = new DEBTController().DEBT_UpdateByRefId(_debt, _debt.RefID);
                    if (/*(rs_debt >= 1) && */ (rs_provider >= 1) && (rs_provider_detail >= 1))
                    {
                        stockinward.STOCK_INWARD_Update_RefStatus(lookUpChungTu.Text);
                        MessageBox.Show("Lưu Thành Công", "Cảnh Báo");
                    }
                    else
                    {
                        MessageBox.Show("Lưu Thất Bại", "Cảnh Báo");
                    }
                }
                catch
                {
                    MessageBox.Show("Lưu Thất Bại", "Cảnh Báo");
                }
            }
            else
            {
                MessageBox.Show("Chưa nhập số phiếu", "Cảnh Báo");
            }
        }