public decimal Extend_Contract_Insert(Extend_Contract_Info p_Extend_Contract_Info)
 {
     try
     {
         return(CommonData.c_serviceWCF.Extend_Contract_Insert(p_Extend_Contract_Info.Contract_Id, p_Extend_Contract_Info.Contract_FromDate, p_Extend_Contract_Info.Contract_ToDate,
                                                               p_Extend_Contract_Info.Extend_Date, p_Extend_Contract_Info.Term, p_Extend_Contract_Info.Fee, p_Extend_Contract_Info.FeeOnePay, p_Extend_Contract_Info.Price, p_Extend_Contract_Info.Number_Extend));
     }
     catch (Exception ex)
     {
         ErrorLog.log.Error(ex.ToString());
         return(-1);
     }
 }
        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());
            }
        }
        void LoadData()
        {
            try
            {
                List <AllCode_Info> _lst_C_T = DBMemory.AllCode_GetBy_CdNameCdType("CONTRACT", "STATUS");

                cboStatusContract.ItemsSource       = _lst_C_T;
                cboStatusContract.DisplayMemberPath = "Content";
                cboStatusContract.SelectedValuePath = "CdValue";

                List <AllCode_Info> _lst_Currency = DBMemory.AllCode_GetBy_CdNameCdType("CONTRACT", "CURENCY");
                cboCurrency.ItemsSource       = _lst_Currency;
                cboCurrency.DisplayMemberPath = "Content";
                cboCurrency.SelectedValuePath = "CdValue";

                Estate_Object_Info _Estate_Object_Info = _Estate_Object_Controller.Estate_Object_GetById(c_Contract_Info.Estate_Id, (decimal)Enum_Contract_Type.Renter);
                lbl_Estate_Name.Content      = _Estate_Object_Info.Estate_Name;
                lbl_Estate_Type_Name.Content = _Estate_Object_Info.Estate_Type_Name;
                lbl_Estate_Code.Content      = _Estate_Object_Info.Estate_Code;
                lbl_Estate_Area.Content      = _Estate_Object_Info.Area;
                lbl_Address.Content          = _Estate_Object_Info.Address;

                Customer_Info _Customer_Info = c_Customer_Controller.Customer_GetById(c_Contract_Info.Object_Id);
                if (_Customer_Info != null)
                {
                    txtRenter_Name.Text   = _Customer_Info.Customer_Name;
                    txtAddress.Text       = _Customer_Info.Address;
                    txtPhone.Text         = _Customer_Info.Phone;
                    txtFax.Text           = _Customer_Info.Fax;
                    txtTaxCode.Text       = _Customer_Info.Tax_Code;
                    txtIdentity_Card.Text = _Customer_Info.Identity_Card;
                }

                txtRepresentive.Text      = c_Contract_Info.Representive;
                txtUsers.Text             = c_Contract_Info.Users;
                txtContract_Code.Text     = c_Contract_Info.Contract_Code;
                txtContract_Name.Text     = c_Contract_Info.Contract_Name;
                dpContractDate.Text       = c_Contract_Info.Contract_Date.ToString("dd/MM/yyyy");
                txtPrice.Text             = c_Contract_Info.Price.ToString("#,##0.#");
                cboCurrency.SelectedValue = c_Contract_Info.Currency;

                #region Fee VND
                if (c_Contract_Info.Currency == (decimal)Enum_Contract_Currency.USD)
                {
                    if (c_Contract_Info.Status == (decimal)Enum_Contract_Status.Gia_Han)
                    {
                        lblThanhTien_Extend.Visibility = Visibility.Visible;
                        txtFee_Vnd_Extend.Visibility   = Visibility.Visible;
                        lblVND_Extend.Visibility       = Visibility.Visible;

                        lblThanhTien.Visibility = Visibility.Collapsed;
                        txtFee_Vnd.Visibility   = Visibility.Collapsed;
                        lblVND.Visibility       = Visibility.Collapsed;
                    }
                    else
                    {
                        lblThanhTien.Visibility = Visibility.Visible;
                        txtFee_Vnd.Visibility   = Visibility.Visible;
                        lblVND.Visibility       = Visibility.Visible;

                        lblThanhTien_Extend.Visibility = Visibility.Collapsed;
                        txtFee_Vnd_Extend.Visibility   = Visibility.Collapsed;
                        lblVND_Extend.Visibility       = Visibility.Collapsed;
                    }
                }
                else
                {
                    lblThanhTien.Visibility = Visibility.Collapsed;
                    txtFee_Vnd.Visibility   = Visibility.Collapsed;
                    lblVND.Visibility       = Visibility.Collapsed;

                    lblThanhTien_Extend.Visibility = Visibility.Collapsed;
                    txtFee_Vnd_Extend.Visibility   = Visibility.Collapsed;
                    lblVND_Extend.Visibility       = Visibility.Collapsed;
                }
                #endregion

                dpFromDate.Text = c_Contract_Info.Contract_FromDate.ToString("dd/MM/yyyy");
                dpToDate.Text   = c_Contract_Info.Contract_ToDate.ToString("dd/MM/yyyy");
                cboStatusContract.SelectedValue = c_Contract_Info.Status;
                txtFee.Text         = c_Contract_Info.Fee.ToString("#,##0.#");
                c_max_number_extend = _Extend_Contract_Controller.Get_Number_ExtendContract(c_Contract_Info.Contract_Id);

                if (c_Contract_Info.Status == (decimal)Enum_Contract_Status.Gia_Han)
                {
                    List <Extend_Contract_Info> _lst_ex = _Extend_Contract_Controller.Extend_Contract_GetByContractId(c_Contract_Info.Contract_Id);
                    if (_lst_ex.Count > 0)
                    {
                        c_Extend_Contract_Info = _lst_ex[0];

                        txtFee_Extend.Text     = c_Extend_Contract_Info.Fee.ToString("#,##0.#");
                        dpFromDate_Extend.Text = c_Extend_Contract_Info.Contract_FromDate.ToString("dd/MM/yyyy");
                        dpToDate_Extend.Text   = c_Extend_Contract_Info.Contract_ToDate.ToString("dd/MM/yyyy");
                    }

                    tabExtend.Visibility = Visibility.Visible;
                    List <Fees_Revenue_Info> _lst = _Fees_Revenue_Controller.Fees_Revenue_GetByContract(c_Contract_Info.Contract_Id);

                    foreach (Fees_Revenue_Info item in _lst)
                    {
                        if (item.Is_Extend == c_max_number_extend)
                        {
                            c_lst_Fee_Extend.Add(item);
                        }
                        else
                        {
                            c_lst_Fee.Add(item);
                        }
                    }

                    txtFee_Vnd_Extend.Text = c_lst_Fee_Extend[c_lst_Fee_Extend.Count - 1].Fee_Vnd.ToString("#,##0.#");

                    btnCall.Visibility   = Visibility.Collapsed;
                    txtFee.IsEnabled     = false;
                    txtFee_Vnd.IsEnabled = false;
                }
                else
                {
                    tabExtend.Visibility = Visibility.Collapsed;
                    c_lst_Fee            = _Fees_Revenue_Controller.Fees_Revenue_GetByContract(c_Contract_Info.Contract_Id);
                    txtFee_Vnd.Text      = c_lst_Fee[c_lst_Fee.Count - 1].Fee_Vnd.ToString("#,##0.#");
                }

                dgrFee.ItemsSource        = c_lst_Fee;
                dgrFee_Extend.ItemsSource = c_lst_Fee_Extend;
            }
            catch (Exception ex)
            {
                ErrorLog.log.Error(ex.ToString());
            }
        }