void Contract_Update()
        {
            try
            {
                c_row_select = dgrContract.SelectedIndex;
                Contract_Info _Contract_Info = (Contract_Info)dgrContract.SelectedItem;

                if (_Contract_Info == null)
                {
                    return;
                }
                Update_Contract_Tenant _Update_Contract_Insert_Tenant = new Update_Contract_Tenant();
                _Update_Contract_Insert_Tenant.c_Contract_Info = _Contract_Info;
                _Update_Contract_Insert_Tenant.Owner           = Window.GetWindow(this);
                _Update_Contract_Insert_Tenant.ShowDialog();

                if (_Update_Contract_Insert_Tenant.c_id_insert != 0)
                {
                    Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

                    LoadData(true);
                    DBMemory.LoadFeeTenant();

                    Mouse.OverrideCursor = null;
                }

                DataGridHelper.NVSFocus(dgrContract, c_row_select, 0);
            }
            catch (Exception ex)
            {
                Mouse.OverrideCursor = null;
                CommonData.log.Error(ex.ToString());
            }
        }
        void View_Contract()
        {
            try
            {
                c_row_select = dgrContract.SelectedIndex;
                Contract_Info _Contract_Info = (Contract_Info)dgrContract.SelectedItem;

                if (_Contract_Info == null)
                {
                    return;
                }

                //Contract_Info _Contract_Info1 = c_Contract_Controller.Contract_GetById(_Contract_Info.Contract_Id);

                View_Contract_Renter _View_Contract_Renter = new View_Contract_Renter();
                _View_Contract_Renter.Owner = Window.GetWindow(this);

                _View_Contract_Renter.c_Contract_Info = _Contract_Info;
                _View_Contract_Renter.ShowDialog();

                DataGridHelper.NVSFocus(dgrContract, c_row_select, 0);
            }
            catch (Exception ex)
            {
                CommonData.log.Error(ex.ToString());
            }
        }
Esempio n. 3
0
        void View_Contract()
        {
            try
            {
                c_row_select = dgrContract.SelectedIndex;
                Contract_Info _Contract_Info = (Contract_Info)dgrContract.SelectedItem;

                if (_Contract_Info == null)
                {
                    return;
                }

                View_Contract_Tenant _View_Contract_Tenant = new View_Contract_Tenant();
                _View_Contract_Tenant.Owner = Window.GetWindow(this);

                _View_Contract_Tenant.c_Contract_Info = _Contract_Info;
                _View_Contract_Tenant.ShowDialog();

                DataGridHelper.NVSFocus(dgrContract, c_row_select, 0);
            }
            catch (Exception ex)
            {
                CommonData.log.Error(ex.ToString());
            }
        }
Esempio n. 4
0
        void Delete_Contract()
        {
            try
            {
                c_row_select = dgrContract.SelectedIndex;
                Contract_Info _Contract_Info = (Contract_Info)dgrContract.SelectedItem;

                if (_Contract_Info == null)
                {
                    return;
                }

                MessageBoxResult result = NoteBox.Show("Bạn chắc chắn muốn xóa hợp đồng này hay không?", "Thông báo", NoteBoxLevel.Question);
                if (MessageBoxResult.Yes == result)
                {
                    if (c_Contract_Controller.Contract_Delete(_Contract_Info.Contract_Id))
                    {
                        NoteBox.Show("Xóa dữ liệu thành công");
                        Search();
                        DBMemory.LoadFeeRender();
                    }
                }
                else
                {
                    DataGridHelper.NVSFocus(dgrContract, c_row_select, 0);
                }
            }
            catch (Exception ex)
            {
                CommonData.log.Error(ex.ToString());
            }
        }
        Contract_Info Get_Contract_Info(decimal p_object_id)
        {
            try
            {
                Contract_Info _Contract_Info = new Contract_Info();
                _Contract_Info.Contract_Code = txtContract_Code.Text;
                _Contract_Info.Contract_Name = txtContract_Name.Text;
                _Contract_Info.Contract_Date = ConvertData.ConvertString2Date(dpContractDate.Text);
                _Contract_Info.Status        = (decimal)Enum_Contract_Status.Con_Han;

                _Contract_Info.Fee       = Convert.ToDecimal(txtFee.Text);
                _Contract_Info.Price     = Convert.ToDecimal(txtPrice.Text);
                _Contract_Info.Pay_Count = c_lst_Fee.Count;
                _Contract_Info.Term      = Convert.ToDecimal(cboTerm.SelectedValue);

                _Contract_Info.Currency = Convert.ToDecimal(cboCurrency.SelectedValue);

                _Contract_Info.Contract_FromDate = ConvertData.ConvertString2Date(dpFromDate.Text);
                _Contract_Info.Contract_ToDate   = ConvertData.ConvertString2Date(dpToDate.Text);
                _Contract_Info.Object_Type       = (decimal)Enum_Contract_Type.Tenant;
                _Contract_Info.Contract_Type     = (decimal)Enum_Contract_Type.Tenant;

                _Contract_Info.Object_Id = p_object_id;
                _Contract_Info.Estate_Id = c_Estate_Object_Info_Search.Estate_Id;

                _Contract_Info.Contract_FromDate = ConvertData.ConvertString2Date(dpContractDate.Text);
                _Contract_Info.FeeOnePay         = Convert.ToDecimal(txtFeeOnePay.Text);

                _Contract_Info.Created_Date       = DateTime.Now;
                _Contract_Info.Created_By         = CommonData.c_Urser_Info.User_Name;
                _Contract_Info.Users              = txtUsers.Text;
                _Contract_Info.Representive       = txtRepresentive.Text;
                _Contract_Info.Contract_ToDate_Ex = _Contract_Info.Contract_ToDate;

                foreach (Fees_Revenue_Info item in c_lst_Fee)
                {
                    if (item.Fee == 0)
                    {
                        _Contract_Info.Fee_Status = (decimal)Enum_Fee_Status.No_Pay;
                        break;
                    }
                    else
                    {
                        _Contract_Info.Fee_Status = (decimal)Enum_Fee_Status.Payed;
                    }
                }

                return(_Contract_Info);
            }
            catch (Exception ex)
            {
                ErrorLog.log.Error(ex.ToString());
                return(null);
            }
        }
Esempio n. 6
0
        void Search()
        {
            try
            {
                Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

                c_lst = new List <Contract_Info>();

                string _code = txtCode.Text.ToUpper();

                if (_code == "")
                {
                    _code = CommonData.c_All_Value;
                }

                string _Building = "-1";
                if (cboBuilding.Text != CommonData.c_All_Content)
                {
                    _Building = cboBuilding.SelectedValue.ToString();
                }

                List <Contract_Info> _lst = c_Contract_Controller.Contract_Search_ByExtend(CommonData.c_All_Value, _code,
                                                                                           cboStatus.SelectedValue.ToString(), CommonData.c_All_Value, _Building);

                Hashtable _hs = new Hashtable();

                if (_lst.Count > 0)
                {
                    for (int i = 0; i < _lst.Count; i++)
                    {
                        Contract_Info _Contract_Info = _lst[i];

                        if (_hs.ContainsKey(_Contract_Info.Contract_Id) == false)
                        {
                            _hs[_Contract_Info.Contract_Id] = _Contract_Info;
                            c_lst.Add(_Contract_Info);
                        }
                    }
                }

                Mouse.OverrideCursor    = null;
                dgrContract.ItemsSource = c_lst;
                DataGridHelper.NVSFocus(dgrContract, 0, 0);
            }
            catch (Exception ex)
            {
                Mouse.OverrideCursor = null;
                ErrorLog.log.Error(ex.ToString());
            }
        }
Esempio n. 7
0
 public decimal Contract_Insert(Contract_Info p_Contract_Info)
 {
     try
     {
         return(CommonData.c_serviceWCF.Contract_Insert(p_Contract_Info.Contract_Code, p_Contract_Info.Contract_Name,
                                                        p_Contract_Info.Status, p_Contract_Info.Estate_Id, p_Contract_Info.Object_Id, p_Contract_Info.Contract_Type, p_Contract_Info.Price,
                                                        p_Contract_Info.Fee, p_Contract_Info.Currency, p_Contract_Info.Fee_Status, p_Contract_Info.Contract_FromDate, p_Contract_Info.Contract_ToDate,
                                                        p_Contract_Info.Term, p_Contract_Info.Pay_Count, p_Contract_Info.Object_Type, p_Contract_Info.Contract_Date, p_Contract_Info.FeeOnePay,
                                                        p_Contract_Info.Created_By, p_Contract_Info.Created_Date, p_Contract_Info.Users, p_Contract_Info.Representive, p_Contract_Info.Contract_ToDate_Ex));
     }
     catch (Exception ex)
     {
         ErrorLog.log.Error(ex.ToString());
         return(-1);
     }
 }
        void Export_Payment()
        {
            try
            {
                c_row_select = dgrContract.SelectedIndex;
                Contract_Info _Contract_Info = (Contract_Info)dgrContract.SelectedItem;

                if (_Contract_Info == null)
                {
                    return;
                }

                List <Fees_Revenue_Info> _lst = _Fees_Revenue_Controller.Fees_Revenue_GetByContract(_Contract_Info.Contract_Id);
                Fees_Revenue_Info        _Fees_Revenue_Info = new Fees_Revenue_Info();

                bool _is_not_pay = false;

                // kiểm tra xem đã thanh toán hết chưa
                foreach (Fees_Revenue_Info item in _lst)
                {
                    if (item.Pay_Status == (decimal)Enum_Fee_Status.No_Pay)
                    {
                        _is_not_pay        = true;
                        _Fees_Revenue_Info = item;
                        break;
                    }
                }

                if (_is_not_pay == false)
                {
                    NoteBox.Show("Đã thanh toán hết, không thể yêu cầu thanh toán", "", NoteBoxLevel.Error);
                    return;
                }

                Estate_Object_Info _Estate_Object_Info = _Estate_Object_Controller.Estate_Object_GetById(_Contract_Info.Estate_Id, (decimal)Enum_Contract_Type.Renter);
                Customer_Info      _Customer_Info      = _Customer_Controller.Customer_GetById(_Contract_Info.Object_Id);

                CommonFunction.Export_payment(_Contract_Info, _Customer_Info, _Estate_Object_Info, _Fees_Revenue_Info);
            }
            catch (Exception ex)
            {
                ErrorLog.log.Error(ex.ToString());
            }
        }
Esempio n. 9
0
        public bool Contract_Update(decimal p_Contract_Id, Contract_Info p_Contract_Info, Contract_Info p_old)
        {
            try
            {
                Traces_Log_Controllers _traceControler = new Traces_Log_Controllers();
                _traceControler.Trace_Insert("CONTRACT", "UPDATE", p_Contract_Info.Modifi_By, p_Contract_Info, p_old);

                return(CommonData.c_serviceWCF.Contract_Update(p_Contract_Id, p_Contract_Info.Contract_Code, p_Contract_Info.Contract_Name,
                                                               p_Contract_Info.Status, p_Contract_Info.Estate_Id, p_Contract_Info.Object_Id, p_Contract_Info.Contract_Type, p_Contract_Info.Price,
                                                               p_Contract_Info.Fee, p_Contract_Info.Currency, p_Contract_Info.Fee_Status, p_Contract_Info.Contract_FromDate, p_Contract_Info.Contract_ToDate,
                                                               p_Contract_Info.Term, p_Contract_Info.Pay_Count, p_Contract_Info.Object_Type, p_Contract_Info.Contract_Date, p_Contract_Info.FeeOnePay,
                                                               p_Contract_Info.Modifi_By, p_Contract_Info.Modifi_Date, p_Contract_Info.Users, p_Contract_Info.Representive, p_Contract_Info.Contract_ToDate_Ex));
            }
            catch (Exception ex)
            {
                ErrorLog.log.Error(ex.ToString());
                return(false);
            }
        }
Esempio n. 10
0
        void Insert_Contract_Renter()
        {
            try
            {
                Contract_Insert_Renter _Contract_Insert_Renter = new Contract_Insert_Renter();
                _Contract_Insert_Renter.Owner = Window.GetWindow(this);
                _Contract_Insert_Renter.ShowDialog();

                if (_Contract_Insert_Renter.c_id_insert != 0)
                {
                    Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

                    Search();

                    DBMemory.LoadFeeRender();

                    for (int i = 0; i < c_lst.Count; i++)
                    {
                        Contract_Info ui = (Contract_Info)c_lst[i];
                        if (ui.Contract_Id == _Contract_Insert_Renter.c_id_insert)
                        {
                            c_row_select = i;
                            _Contract_Insert_Renter.c_id_insert = 0;
                            break;
                        }
                    }
                }

                Mouse.OverrideCursor = null;
                DataGridHelper.NVSFocus(dgrContract, c_row_select, 0);
            }
            catch (Exception ex)
            {
                Mouse.OverrideCursor = null;
                CommonData.log.Error(ex.ToString());
            }
        }
Esempio n. 11
0
        void Payment_Contract()
        {
            try
            {
                c_row_select = dgrContract.SelectedIndex;
                Contract_Info _Contract_Info = (Contract_Info)dgrContract.SelectedItem;

                if (_Contract_Info == null)
                {
                    return;
                }

                Tenant_Payment _Tenant_Payment = new Tenant_Payment();
                _Tenant_Payment.Owner = Window.GetWindow(this);

                _Tenant_Payment.c_Contract_Info = _Contract_Info;
                _Tenant_Payment.ShowDialog();

                if (_Tenant_Payment.c_ok == true)
                {
                    Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

                    Search();

                    DBMemory.LoadFeeTenant();

                    Mouse.OverrideCursor = null;
                }

                DataGridHelper.NVSFocus(dgrContract, c_row_select, 0);
            }
            catch (Exception ex)
            {
                CommonData.log.Error(ex.ToString());
            }
        }
Esempio n. 12
0
        void Accept()
        {
            try
            {
                if (txtFeePay.Text == "")
                {
                    NoteBox.Show("Số tiền thanh toán không được để trống");
                    txtFeePay.Focus();
                    return;
                }

                if (dpPay_Date.Text == "")
                {
                    NoteBox.Show("Ngày thanh toán không được để trống", "", NoteBoxLevel.Error);
                    dpPay_Date.Focus();
                    return;
                }
                if (CheckValidate.CheckValidDate(dpPay_Date.Text) == false)
                {
                    NoteBox.Show("Ngày thanh toán không đúng định dạng", "", NoteBoxLevel.Error);
                    dpPay_Date.Focus();
                    return;
                }

                Fees_Revenue_Info _Fees_Revenue_Info = new Fees_Revenue_Info();
                _Fees_Revenue_Info.Fee_Id       = c_Fees_MustPay.Fee_Id;
                _Fees_Revenue_Info.Pay_Date     = Common.ConvertData.ConvertString2Date(dpPay_Date.Text);
                _Fees_Revenue_Info.Fee          = Convert.ToDecimal(txtFeePay.Text);
                _Fees_Revenue_Info.Debit_Amount = c_Fees_MustPay.Fee_Expected - _Fees_Revenue_Info.Fee;
                _Fees_Revenue_Info.Pay_Status   = (decimal)Enum_Fee_Status.Payed;

                MessageBoxResult result = NoteBox.Show("Bạn có muốn thanh toán phí môi giới cho hợp đồng này hay không?", "Thông báo", NoteBoxLevel.Question);
                if (MessageBoxResult.Yes != result)
                {
                    return;
                }

                if (_Fees_Revenue_Controller.Fees_Revenue_Update(_Fees_Revenue_Info) == false)
                {
                    NoteBox.Show("Lỗi thanh toán", "", NoteBoxLevel.Error);
                    return;
                }

                Contract_Info _Contract_Info = c_Contract_Info;

                if (c_index == c_lst_Fee_All.Count - 1)
                {
                    _Contract_Info.Fee_Status = (decimal)Enum_Fee_Status.Payed;
                }
                else
                {
                    _Contract_Info.Fee_Status = (decimal)Enum_Fee_Status.No_Pay;
                }

                if (_Contract_Controller.Contract_Update(c_Contract_Info.Contract_Id, _Contract_Info) == false)
                {
                    NoteBox.Show("Lỗi cập nhật hợp đồng cho thuê nhà", "", NoteBoxLevel.Error);
                    return;
                }

                NoteBox.Show("Thanh toán phí thành công");
                c_ok = true;
                this.Close();
            }
            catch (Exception ex)
            {
                ErrorLog.log.Error(ex.ToString());
            }
        }
Esempio n. 13
0
        void Accept()
        {
            try
            {
                if (Tenat_CheckValidate() == false)
                {
                    return;
                }

                MessageBoxResult result = NoteBox.Show("Bạn có muốn thêm hợp đồng này hay không?", "Thông báo", NoteBoxLevel.Question);
                if (MessageBoxResult.Yes != result)
                {
                    return;
                }

                #region Thêm mới khách hàng
                Customer_Info _Customer_Info = Get_Customer_Info();
                if (_Customer_Info == null)
                {
                    NoteBox.Show("Lỗi khởi tạo khách cho thuê nhà", "", NoteBoxLevel.Error);
                    return;
                }
                decimal _customer_id = -1;

                // kiểm tra xem thằng tên khách hàng đó và số đt đó đã có trong db chưa
                // nếu có rồi thì ko insert nữa
                string _name = txtRenter_Name.Text.ToUpper();
                if (_name == "")
                {
                    _name = CommonData.c_All_Value;
                }

                string _phone = txtPhone.Text.ToUpper();
                if (_phone == "")
                {
                    _phone = CommonData.c_All_Value;
                }

                List <Customer_Info> _lst = c_Customer_Controller.Customer_Search(_name, _phone);

                if (_lst.Count > 0)
                {
                    // có rồi thì sử dụng luôn
                    // update ngược thông tin lại
                    if (c_Customer_Controller.Customer_Update(_lst[0].Customer_Id, _Customer_Info) == false)
                    {
                        NoteBox.Show("Lỗi cập nhật mới khách thuê nhà", "", NoteBoxLevel.Error);
                        return;
                    }

                    _customer_id = _lst[0].Customer_Id;
                }
                else
                {
                    // không có thì thêm mới
                    _customer_id = c_Customer_Controller.Customer_Insert(_Customer_Info);
                    if (_customer_id == -1)
                    {
                        NoteBox.Show("Lỗi thêm mới khách thuê nhà", "", NoteBoxLevel.Error);
                        return;
                    }
                }

                #endregion

                #region Hợp đồng
                Contract_Info _Contract_Info = Get_Contract_Info(_customer_id);
                if (_Contract_Info == null)
                {
                    NoteBox.Show("Lỗi khởi tạo hợp đồng thuê nhà", "", NoteBoxLevel.Error);
                    return;
                }

                decimal _contract_id = _Contract_Controller.Contract_Insert(_Contract_Info);
                if (_contract_id == -1)
                {
                    NoteBox.Show("Lỗi thêm mới hợp đồng cho thuê nhà", "", NoteBoxLevel.Error);
                    c_Customer_Controller.Customer_Delete(_customer_id);
                    return;
                }

                #endregion

                #region Phí môi giới
                foreach (Fees_Revenue_Info _Fees_Revenue_Info in c_lst_Fee)
                {
                    _Fees_Revenue_Info.Contract_Id  = _contract_id;
                    _Fees_Revenue_Info.Object_Id    = _customer_id;
                    _Fees_Revenue_Info.Object_Type  = (decimal)Enum_Contract_Type.Tenant;
                    _Fees_Revenue_Info.Currency     = Convert.ToDecimal(cboCurrency.SelectedValue);
                    _Fees_Revenue_Info.Fee          = 0;
                    _Fees_Revenue_Info.Debit_Amount = _Fees_Revenue_Info.Fee_Expected - _Fees_Revenue_Info.Fee;
                    _Fees_Revenue_Info.Is_Extend    = 0;
                    _Fees_Revenue_Info.Fee_Vnd      = 0;

                    if (_Fees_Revenue_Info.Fee != 0)
                    {
                        _Fees_Revenue_Info.Pay_Status = (decimal)Enum_Fee_Status.Payed;
                    }

                    if (_Fees_Revenue_Controller.Fees_Revenue_Insert(_Fees_Revenue_Info) == false)
                    {
                        NoteBox.Show("Lỗi thanh toán", "", NoteBoxLevel.Error);
                        c_Customer_Controller.Customer_Delete(_customer_id);
                        _Contract_Controller.Contract_Delete(_contract_id);
                        _Fees_Revenue_Controller.Fees_Revenue_DeleteByContract(_contract_id);
                        return;
                    }
                }
                #endregion

                c_id_insert = _contract_id;

                NoteBox.Show("Thêm mới dữ liệu thành công", "");
                this.Close();
            }
            catch (Exception ex)
            {
                ErrorLog.log.Error(ex.ToString());
            }
        }
        void Accept()
        {
            try
            {
                if (Renter_CheckValidate() == false)
                {
                    return;
                }

                MessageBoxResult result = NoteBox.Show("Bạn có muốn cập nhật hợp đồng này hay không?", "Thông báo", NoteBoxLevel.Question);
                if (MessageBoxResult.Yes != result)
                {
                    return;
                }

                //Customer_Info _Customer_Info = Get_Customer_Info();

                //if (_Customer_Info == null)
                //{
                //    NoteBox.Show("Lỗi khởi tạo khách người thuê nhà", "", NoteBoxLevel.Error);
                //    return;
                //}

                //if (c_Customer_Controller.Customer_Update(c_Contract_Info.Object_Id, _Customer_Info) == false)
                //{
                //    NoteBox.Show("Lỗi cập nhật mới khách thuê nhà", "", NoteBoxLevel.Error);
                //    return;
                //}

                Contract_Info _Contract_Info = Get_Contract_Info();
                if (_Contract_Info == null)
                {
                    NoteBox.Show("Lỗi khởi tạo đối tượng hợp đồng thuê nhà", "", NoteBoxLevel.Error);
                    return;
                }

                if (_Contract_Controller.Contract_Update(c_Contract_Info.Contract_Id, _Contract_Info, c_Contract_Info) == false)
                {
                    NoteBox.Show("Lỗi cập nhật mới hợp đồng thuê nhà", "", NoteBoxLevel.Error);
                    return;
                }

                // nếu không phải là gia hạn hợp đồng thì mới xóa đi tạo lại
                if (c_lst_Fee_Extend.Count == 0)
                {
                    // nếu mà kỳ hạn hợp đồng thay đổi thì xóa đi tạo lại dữ liệu thu chi
                    _Fees_Revenue_Controller.Fees_Revenue_DeleteByContract(c_Contract_Info.Contract_Id);

                    #region Thanh toán bình thường
                    foreach (Fees_Revenue_Info _Fees_Revenue_Info in c_lst_Fee)
                    {
                        _Fees_Revenue_Info.Contract_Id = c_Contract_Info.Contract_Id;
                        _Fees_Revenue_Info.Object_Id   = c_Contract_Info.Object_Id;
                        _Fees_Revenue_Info.Object_Type = (decimal)Enum_Contract_Type.Tenant;
                        _Fees_Revenue_Info.Currency    = Convert.ToDecimal(cboCurrency.SelectedValue);

                        if (_Fees_Revenue_Info.Fee_Expected != Convert.ToDecimal(txtFee.Text))
                        {
                            _Fees_Revenue_Info.Fee_Expected = Convert.ToDecimal(txtFee.Text);
                        }

                        _Fees_Revenue_Info.Debit_Amount = _Fees_Revenue_Info.Fee_Expected - _Fees_Revenue_Info.Fee;

                        if (_Contract_Info.Currency == (decimal)Enum_Contract_Currency.USD)
                        {
                            _Fees_Revenue_Info.Fee_Vnd = Convert.ToDecimal(txtFee_Vnd.Text);
                        }
                        else
                        {
                            _Fees_Revenue_Info.Fee_Vnd = 0;
                        }

                        if (_Fees_Revenue_Info.Fee != 0)
                        {
                            _Fees_Revenue_Info.Pay_Status = (decimal)Enum_Fee_Status.Payed;
                        }

                        if (_Fees_Revenue_Controller.Fees_Revenue_Insert(_Fees_Revenue_Info) == false)
                        {
                            NoteBox.Show("Lỗi thanh toán", "", NoteBoxLevel.Error);
                            return;
                        }
                    }
                    #endregion
                }
                else
                {
                    #region Phí gia hạn hợp đồng

                    Extend_Contract_Info _Extend_Contract_Info = new Extend_Contract_Info();
                    _Extend_Contract_Info.Contract_Id = c_Contract_Info.Contract_Id;

                    _Extend_Contract_Info.Contract_FromDate = ConvertData.ConvertString2Date(dpFromDate_Extend.Text);
                    _Extend_Contract_Info.Contract_ToDate   = ConvertData.ConvertString2Date(dpToDate_Extend.Text);

                    _Extend_Contract_Info.Fee       = Convert.ToDecimal(txtFee_Extend.Text);
                    _Extend_Contract_Info.FeeOnePay = _Extend_Contract_Info.Fee;
                    _Extend_Contract_Info.Term      = 1;
                    _Extend_Contract_Info.Price     = 0;

                    bool _is_payed = true;
                    foreach (Fees_Revenue_Info _Fees_Revenue_Info in c_lst_Fee_Extend)
                    {
                        _Fees_Revenue_Info.Contract_Id = c_Contract_Info.Contract_Id;
                        _Fees_Revenue_Info.Object_Id   = c_Contract_Info.Object_Id;
                        _Fees_Revenue_Info.Object_Type = (decimal)Enum_Contract_Type.Tenant;
                        _Fees_Revenue_Info.Currency    = Convert.ToDecimal(cboCurrency.SelectedValue);

                        if (c_Contract_Info.Status == (decimal)Enum_Contract_Status.Het_Han)
                        {
                            _Fees_Revenue_Info.Is_Extend = c_max_number_extend + 1;
                        }
                        else
                        {
                            _Fees_Revenue_Info.Is_Extend = c_max_number_extend;
                        }

                        _Fees_Revenue_Info.Debit_Amount = _Fees_Revenue_Info.Fee_Expected - _Fees_Revenue_Info.Fee;

                        if (_Fees_Revenue_Info.Fee != 0)
                        {
                            _Fees_Revenue_Info.Pay_Status = (decimal)Enum_Fee_Status.Payed;
                        }
                        else
                        {
                            _is_payed = false;
                        }

                        if (_Contract_Info.Currency == (decimal)Enum_Contract_Currency.USD)
                        {
                            _Fees_Revenue_Info.Fee_Vnd = Convert.ToDecimal(txtFee_Vnd_Extend.Text);
                        }
                        else
                        {
                            _Fees_Revenue_Info.Fee_Vnd = 0;
                        }

                        if (_Fees_Revenue_Controller.Fees_Revenue_Insert(_Fees_Revenue_Info) == false)
                        {
                            NoteBox.Show("Lỗi thanh toán", "", NoteBoxLevel.Error);
                            return;
                        }
                    }

                    // lần đầu chuyển trạng thái hợp đồng
                    if (c_Extend_Contract_Info == null)
                    {
                        _Extend_Contract_Info.Extend_Date = DateTime.Now;
                        _Extend_Contract_Controller.Extend_Contract_Insert(_Extend_Contract_Info);
                    }
                    else
                    {
                        if (_is_payed == false)
                        {
                            _Extend_Contract_Info.Fee_Status = (decimal)Enum_Fee_Status.No_Pay;
                        }
                        else
                        {
                            _Extend_Contract_Info.Fee_Status = (decimal)Enum_Fee_Status.Payed;
                        }

                        // update lại thông tin về hợp đồng
                        _Extend_Contract_Info.Extend_Date = c_Extend_Contract_Info.Extend_Date;
                        _Extend_Contract_Controller.Extend_Contract_Update(_Extend_Contract_Info);
                    }

                    #endregion
                }

                c_id_insert = c_Contract_Info.Contract_Id;

                NoteBox.Show("Cập nhật dữ liệu thành công", "");
                this.Close();
            }
            catch (Exception ex)
            {
                ErrorLog.log.Error(ex.ToString());
            }
        }