/*******************************************************************************************************************************************************************************
        ****************************************************                   Search Leasing Method                            ********************************************************
        ****************************************************                                                                    ********************************************************
        *******************************************************************************************************************************************************************************/

        private void _getLeasing()
        {
            string deposit_no          = Deps_No_TBx.Text;
            string leasing_no          = Leasing_No_TBx.Text;
            string idcard              = Cust_Idcard_TBx.Text;
            string fname               = Cust_FName_TBx.Text.Trim(' ');
            string lname               = Cust_LName_TBx.Text.Trim(' ');
            string date_str            = DateTimeUtility.convertDateToMYSQL(Leasing_Date_str_TBx.Text);
            string date_end            = DateTimeUtility.convertDateToMYSQL(Leasing_Date_end_TBx.Text);
            string car_plate           = Car_Plate_TBx.Text;
            string leasing_Code_inline = _getCheckedLeasing_Code();
            string Company_id_inline   = _getCheckedCompany();
            string zone_id_inline      = _getCheckedZone();

            if (!string.IsNullOrEmpty(deposit_no) || !string.IsNullOrEmpty(leasing_no) || !string.IsNullOrEmpty(idcard) || !string.IsNullOrEmpty(fname) || !string.IsNullOrEmpty(lname) || !string.IsNullOrEmpty(date_str) ||
                !string.IsNullOrEmpty(date_end) || !string.IsNullOrEmpty(car_plate) || !string.IsNullOrEmpty(leasing_Code_inline) || !string.IsNullOrEmpty(Company_id_inline) || !string.IsNullOrEmpty(zone_id_inline))
            {
                cls_mng = new Car_Leasings_Manager();

                List <Car_Leasings> list_cls_all = cls_mng.getCarLeasing(deposit_no, leasing_no, idcard, fname, lname, date_str, date_end, car_plate, leasing_Code_inline, Company_id_inline, zone_id_inline, 0, 0);

                try
                {
                    int row = list_cls_all.Count;

                    _pageCount(row);

                    List <Car_Leasings> list_cls = cls_mng.getCarLeasing(deposit_no, leasing_no, idcard, fname, lname, date_str, date_end, car_plate, leasing_Code_inline, Company_id_inline, zone_id_inline, 0, 20);

                    Session["deposit_no"]          = deposit_no;
                    Session["leasing_no"]          = leasing_no;
                    Session["idcard"]              = idcard;
                    Session["fname"]               = fname;
                    Session["lname"]               = lname;
                    Session["date_str"]            = date_str;
                    Session["date_end"]            = date_end;
                    Session["car_plate"]           = car_plate;
                    Session["leasing_Code_inline"] = leasing_Code_inline;
                    Session["company_id_inline"]   = Company_id_inline;
                    Session["zone_id_inline"]      = zone_id_inline;
                    Session["row_str"]             = 0;

                    Session["List_Leasings"] = list_cls;
                }
                catch (Exception ex)
                {
                    error = "Exception ==> Leasing_Search : Page --> _getLeasing() ";
                    Log_Error._writeErrorFile(error, ex);
                }
            }
        }
        private void _getMoreLeainsg(int current_page)
        {
            string deposit_no          = (string)Session["deposit_no"];
            string leasing_no          = (string)Session["leasing_no"];
            string idcard              = (string)Session["idcard"];
            string fname               = (string)Session["fname"];
            string lname               = (string)Session["lname"];
            string date_str            = (string)Session["date_str"];
            string date_end            = (string)Session["date_end"];
            string car_plate           = (string)Session["car_plate"];
            string leasing_Code_inline = (string)Session["leasing_Code_inline"];
            string Company_id_inline   = (string)Session["company_id_inline"];
            string zone_id_inline      = (string)Session["zone_id_inline"];

            cls_mng = new Car_Leasings_Manager();

            if (current_page > 1)
            {
                int row_str = (current_page - 1) * 20;

                link_Previous.Enabled = true;

                List <Car_Leasings> list_cls = cls_mng.getCarLeasing(deposit_no, leasing_no, idcard, fname, lname, date_str, date_end, car_plate, leasing_Code_inline, Company_id_inline, zone_id_inline, row_str, 20);

                Session["row_str"] = row_str;

                Session["List_Leasings"] = list_cls;
            }
            else
            {
                link_Previous.Enabled = false;

                List <Car_Leasings> list_cls = cls_mng.getCarLeasing(deposit_no, leasing_no, idcard, fname, lname, date_str, date_end, car_plate, leasing_Code_inline, Company_id_inline, zone_id_inline, 0, 20);

                Session["row_str"] = 0;

                Session["List_Leasings"] = list_cls;
            }

            int max_page = (int)Session["max_page"];

            if (current_page == max_page)
            {
                link_Next.Enabled = false;
            }
        }
        private void _CheckLeasingPayment(string Leasing_id)
        {
            Car_Leasings_Manager         cls_mng      = new Car_Leasings_Manager();
            Car_Leasings_Payment_Manager cls_pay_mng  = new Car_Leasings_Payment_Manager();
            List <Car_Leasings_Payment>  list_cls_pay = cls_pay_mng.getPaymentSchedule(Leasing_id);

            if (list_cls_pay.Count > 0)
            {
                Car_Leasings_Payment cls_pay = list_cls_pay[0];

                if (string.IsNullOrEmpty(cls_pay.Real_payment_date))
                {
                    Payment_Schedule_DDL.Enabled   = true;
                    First_Payment_Date_TBx.Enabled = true;
                    Total_Require_TBx.Enabled      = true;
                    Interest_Rate_TBx.Enabled      = true;
                    Total_Period_TBx.Enabled       = true;
                    Vat_TBx.Enabled       = true;
                    Calculate_Btn.Enabled = true;
                }
                else
                {
                    Payment_Schedule_DDL.Enabled   = false;
                    First_Payment_Date_TBx.Enabled = false;
                    Total_Require_TBx.Enabled      = false;
                    Interest_Rate_TBx.Enabled      = false;
                    Total_Period_TBx.Enabled       = false;
                    Vat_TBx.Enabled       = false;
                    Calculate_Btn.Enabled = false;
                }
            }
            else
            {
                Payment_Schedule_DDL.Enabled   = true;
                First_Payment_Date_TBx.Enabled = true;
                Total_Require_TBx.Enabled      = true;
                Interest_Rate_TBx.Enabled      = true;
                Total_Period_TBx.Enabled       = true;
                Vat_TBx.Enabled       = true;
                Calculate_Btn.Enabled = true;
            }
        }
        protected void Upload_Btn_Click(object sender, EventArgs e)
        {
            ctm = (Customers)Session["Customer_Leasing"];

            string server_path = Server.MapPath("/");

            /* Create Main Folder for Detected Images of Contact Leasing  */
            string mainDirectory = ctm.Cust_id;

            string mainDirectoryPath = server_path + "\\Uploaded_Images\\" + mainDirectory;

            if (!Directory.Exists(mainDirectoryPath))
            {
                Directory.CreateDirectory(mainDirectoryPath);
            }

            cls = (Car_Leasings)Session["Leasings"];

            /* Create Sub Folder for Save Images of Car */
            string subDirectory = "Car_Images_" + cls.Leasing_id;

            string subDirectoryPath = mainDirectoryPath + "\\" + subDirectory;

            if (!Directory.Exists(subDirectoryPath))
            {
                Directory.CreateDirectory(subDirectoryPath);
            }


            /* Get File From TextFile  */
            HttpFileCollection uploadedFiles = Request.Files;

            for (int i = 0; i < uploadedFiles.Count; i++)
            {
                HttpPostedFile userPostedFile = uploadedFiles[i];

                try
                {
                    if (userPostedFile.ContentLength > 0)
                    {
                        cls_mng = new Car_Leasings_Manager();
                        string number_img = cls_mng.getLastNumberLeasingsCarPhotoId(cls.Leasing_id);
                        string digit      = cls_mng.generateLeasingsCarDigitID();

                        string old_name = userPostedFile.FileName;
                        string new_name = number_img + "_" + cls.Leasing_id + "_" + digit + Path.GetExtension(userPostedFile.FileName);

                        string db_path       = "../Uploaded_Images/" + mainDirectory + "/" + subDirectory + "/" + new_name;
                        string db_full_path  = subDirectoryPath.Replace('\\', '/') + "/" + new_name;
                        string db_local_path = subDirectoryPath + "\\" + new_name;

                        userPostedFile.SaveAs(subDirectoryPath + "\\" + Path.GetFileName(old_name).Replace(old_name, new_name));

                        Car_Leasings_Photo cls_photo = new Car_Leasings_Photo();

                        cls_photo.Leasing_id         = cls.Leasing_id;
                        cls_photo.Car_img_num        = Convert.ToInt32(number_img);
                        cls_photo.Car_img_old_name   = old_name;
                        cls_photo.Car_img_path       = db_path;
                        cls_photo.Car_img_full_path  = db_full_path;
                        cls_photo.Car_img_local_path = db_local_path;

                        cls_mng.addLeasingsCarPhoto(cls_photo);

                        /// Acticity Logs System
                        ///

                        package_login = (Base_Companys)Session["Package"];
                        acc_lgn       = (Account_Login)Session["Login"];

                        string message = Messages_Logs._messageLogsNormal(acc_lgn.Account_F_name, " เพิ่มรูปรถ ในสัญญา : " + cls.Leasing_no + " เลขที่ฝาก : " + cls.Deps_no, acc_lgn.resu, package_login.Company_N_name);

                        new Activity_Log_Manager().addActivityLogs(message, acc_lgn.Account_id, package_login.Company_id);

                        /// Acticity Logs System
                    }
                }
                catch (Exception ex)
                {
                    Session["Uploaded_Leasing"] = 0;
                    string error = "ไม่สามารถ Upload รูปภาพนี้ได้ ";
                    Log_Error._writeErrorFile(error, ex);
                }
            }

            Session["Uploaded_Leasing"] = 1;

            _GetHomePhoto();
        }
        /*******************************************************************************************************************************************************************************
        ****************************************************                               Add Data Function                    ********************************************************
        ****************************************************                                                                    ********************************************************
        *******************************************************************************************************************************************************************************/


        private void _EditLeasings()
        {
            Car_Leasings_Manager cls_mng = new Car_Leasings_Manager();
            Car_Leasings         cls     = new Car_Leasings();

            Car_Leasings cls_tmp = (Car_Leasings)Session["Leasings"];

            // ข้อมูลสัญญา
            cls.Leasing_id = cls_tmp.Leasing_id;
            cls.Deps_no    = string.IsNullOrEmpty(Deps_No_TBx.Text) ? "" : Deps_No_TBx.Text;
            cls.Leasing_no = string.IsNullOrEmpty(Leasing_No_TBx.Text) ? "" : Leasing_No_TBx.Text;

            cls.bs_ls_code = new Base_Leasing_Code();
            cls.bs_ls_code.Leasing_code_id = Leasing_Code_DDL.SelectedIndex <= 0 ? 1 : Convert.ToInt32(Leasing_Code_DDL.SelectedValue);

            cls.Leasing_date = string.IsNullOrEmpty(Leasing_Date_TBx.Text) ? DateTimeUtility._dateNOWForServer() : DateTimeUtility.convertDateToMYSQL(Leasing_Date_TBx.Text);

            cls.bs_cpn            = new Base_Companys();
            cls.bs_cpn.Company_id = Company_DDL.SelectedIndex <= 0 ? 1 : Convert.ToInt32(Company_DDL.SelectedValue);

            cls.bs_zn         = new Base_Zone_Service();
            cls.bs_zn.Zone_id = Zone_DDL.SelectedIndex <= 0 ? 1 : Convert.ToInt32(Zone_DDL.SelectedValue);

            cls.bs_ct          = new Base_Courts();
            cls.bs_ct.Court_id = Court_DDL.SelectedIndex <= 0 ? 1 : Convert.ToInt32(Court_DDL.SelectedValue);

            cls.PeReT = string.IsNullOrEmpty(Person_Receive_Trasfer_TBx.Text) ? "" : Person_Receive_Trasfer_TBx.Text;

            // ข้อมูลการประเมิน
            cls.TotalPaymentTime   = TotalPaymentTime_DDL.SelectedIndex <= 0 ? 1 : Convert.ToInt32(TotalPaymentTime_DDL.SelectedValue);
            cls.Total_require      = string.IsNullOrEmpty(Total_Require_TBx.Text) ? 0 : Convert.ToDouble(Total_Require_TBx.Text);
            cls.Vat_rate           = string.IsNullOrEmpty(Vat_TBx.Text) ? 0 : Convert.ToDouble(Vat_TBx.Text);
            cls.Interest_rate      = string.IsNullOrEmpty(Interest_Rate_TBx.Text) ? 0 : Convert.ToDouble(Interest_Rate_TBx.Text);
            cls.Total_period       = string.IsNullOrEmpty(Total_Period_TBx.Text) ? 0 : Convert.ToInt32(Total_Period_TBx.Text);
            cls.Total_sum          = string.IsNullOrEmpty(Total_Sum_TBx.Text) ? 0 : Convert.ToDouble(Total_Sum_TBx.Text);
            cls.Total_Interest     = string.IsNullOrEmpty(Total_Interest_TBx.Text) ? 0 : Convert.ToDouble(Total_Interest_TBx.Text);
            cls.Total_Tax          = string.IsNullOrEmpty(Total_Tax_TBx.Text) ? 0 : Convert.ToDouble(Total_Tax_TBx.Text);
            cls.Total_leasing      = string.IsNullOrEmpty(Total_Leasing_TBx.Text) ? 0 : Convert.ToDouble(Total_Leasing_TBx.Text);
            cls.Total_Net_leasing  = string.IsNullOrEmpty(Total_Net_Leasing_TBx.Text) ? 0 : Convert.ToDouble(Total_Net_Leasing_TBx.Text);
            cls.Period_cal         = string.IsNullOrEmpty(Period_Cal_TBx.Text) ? 0 : Convert.ToDouble(Period_Cal_TBx.Text);
            cls.Period_interst     = string.IsNullOrEmpty(Period_interst_TBx.Text) ? 0 : Convert.ToDouble(Period_interst_TBx.Text);
            cls.Period_tax         = string.IsNullOrEmpty(Period_tax_TBx.Text) ? 0 : Convert.ToDouble(Period_tax_TBx.Text);
            cls.Period_pure        = string.IsNullOrEmpty(Period_pure_TBx.Text) ? 0 : Convert.ToDouble(Period_pure_TBx.Text);
            cls.Period_payment     = string.IsNullOrEmpty(Period_Payment_TBx.Text) ? 0 : Convert.ToDouble(Period_Payment_TBx.Text);
            cls.Period_require     = string.IsNullOrEmpty(Period_require_TBx.Text) ? 0 : Convert.ToDouble(Period_require_TBx.Text);
            cls.Total_period_left  = string.IsNullOrEmpty(Total_Period_TBx.Text) ? 0 : Convert.ToInt32(Total_Period_TBx.Text);
            cls.Total_payment_left = string.IsNullOrEmpty(Total_Net_Leasing_TBx.Text) ? 0 : Convert.ToDouble(Total_Net_Leasing_TBx.Text);
            cls.Payment_schedule   = Payment_Schedule_DDL.SelectedIndex <= 0 ? 1 : Convert.ToInt32(Payment_Schedule_DDL.SelectedValue);
            cls.First_payment_date = string.IsNullOrEmpty(First_Payment_Date_TBx.Text) ? DateTimeUtility._dateNOWForServer() : DateTimeUtility.convertDateToMYSQL(First_Payment_Date_TBx.Text);

            // ข้อมูลรถ
            cls.Car_register_date          = string.IsNullOrEmpty(Car_Register_Date_TBx.Text) ? null : DateTimeUtility.convertDateToMYSQL(Car_Register_Date_TBx.Text);
            cls.Car_license_plate          = string.IsNullOrEmpty(Car_Plate_TBx.Text) ? "" : Car_Plate_TBx.Text;
            cls.Car_license_plate_province = Car_Plate_Province_DDL.SelectedIndex <= 0 ? "จ.-" : "จ." + Car_Plate_Province_DDL.SelectedItem.Text;

            cls.Car_type    = string.IsNullOrEmpty(Car_Type_TBx.Text) ? "" : Car_Type_TBx.Text;
            cls.Car_feature = string.IsNullOrEmpty(Car_Feature_TBx.Text) ? "" : Car_Feature_TBx.Text;

            cls.bs_cbrn = new Base_Car_Brands();
            cls.bs_cbrn.car_brand_id = Car_Brand_DDL.SelectedIndex <= 0 ? 1 : Convert.ToInt32(Car_Brand_DDL.SelectedValue);

            cls.Car_model              = string.IsNullOrEmpty(Car_Model_TBx.Text) ? "" : Car_Model_TBx.Text;
            cls.Car_year               = Car_Year_DDL.SelectedIndex <= 0 ? "" : Car_Year_DDL.SelectedValue;
            cls.Car_color              = string.IsNullOrEmpty(Car_Color_TBx.Text) ? "" : Car_Color_TBx.Text;
            cls.Car_engine_no          = string.IsNullOrEmpty(Engine_No_TBx.Text) ? "" : Engine_No_TBx.Text;
            cls.Car_engine_no_at       = string.IsNullOrEmpty(Engine_No_At_TBx.Text) ? "" : Engine_No_At_TBx.Text;
            cls.Car_engine_brand       = string.IsNullOrEmpty(Engine_Brand_TBx.Text) ? "" : Engine_Brand_TBx.Text;
            cls.Car_chassis_no         = string.IsNullOrEmpty(Chassis_No_TBx.Text) ? "" : Chassis_No_TBx.Text;
            cls.Car_chassis_no_at      = string.IsNullOrEmpty(Chassis_No_At_TBx.Text) ? "" : Chassis_No_At_TBx.Text;
            cls.Car_fual_type          = string.IsNullOrEmpty(Car_Fuel_Type_TBx.Text) ? "" : Car_Fuel_Type_TBx.Text;
            cls.Car_gas_No             = string.IsNullOrEmpty(Car_Gas_No_TBx.Text) ? "" : Car_Gas_No_TBx.Text;
            cls.Car_used_id            = Car_Used_DDL.SelectedIndex <= 0 ? 1 : Convert.ToInt32(Car_Used_DDL.SelectedValue);
            cls.Car_distance           = string.IsNullOrEmpty(Car_Distance_TBx.Text) ? 0 : Convert.ToInt32(Car_Distance_TBx.Text);
            cls.Car_next_register_date = string.IsNullOrEmpty(Car_Next_Register_Date_TBx.Text) ? null : DateTimeUtility.convertDateToMYSQL(Car_Next_Register_Date_TBx.Text);
            cls.Car_tax_value          = string.IsNullOrEmpty(Car_Tax_Value_TBx.Text) ? 0 : Convert.ToDouble(Car_Tax_Value_TBx.Text);
            cls.Car_credits            = string.IsNullOrEmpty(Car_Credits_TBx.Text) ? "" : Car_Credits_TBx.Text;
            cls.Car_agent              = string.IsNullOrEmpty(Car_agent_TBx.Text) ? "" : Car_agent_TBx.Text;

            // ข้อมูลเจ้าของรถเดิม
            cls.Car_old_owner             = string.IsNullOrEmpty(Car_Old_Owner_TBx.Text) ? "" : Car_Old_Owner_TBx.Text;
            cls.Car_old_owner_idcard      = string.IsNullOrEmpty(Car_Old_Owner_Idcard_TBx.Text) ? "" : Car_Old_Owner_Idcard_TBx.Text;
            cls.Car_old_owner_b_date      = string.IsNullOrEmpty(Car_old_owner_b_date_TBx.Text) ? null : DateTimeUtility.convertDateToMYSQL(Car_old_owner_b_date_TBx.Text);
            cls.Car_old_owner_address_no  = string.IsNullOrEmpty(Car_Old_Owner_Address_No_TBx.Text) ? "" : Car_Old_Owner_Address_No_TBx.Text;
            cls.Car_old_owner_vilage      = string.IsNullOrEmpty(Car_Old_Owner_Vilage_TBx.Text) ? "บ.-" : "บ." + Car_Old_Owner_Vilage_TBx.Text;
            cls.Car_old_owner_vilage_no   = string.IsNullOrEmpty(Car_Old_Owner_Vilage_No_TBx.Text) ? "ม.-" : "ม." + Car_Old_Owner_Vilage_No_TBx.Text;
            cls.Car_old_owner_alley       = string.IsNullOrEmpty(Car_Old_Owner_alley_TBx.Text) ? "ซ.-" : "ซ." + Car_Old_Owner_alley_TBx.Text;
            cls.Car_old_owner_road        = string.IsNullOrEmpty(Car_Old_Owner_Road_TBx.Text) ? "ถ.-" : "ถ." + Car_Old_Owner_Road_TBx.Text;
            cls.Car_old_owner_subdistrict = string.IsNullOrEmpty(Car_Old_Owner_Subdistrict_TBx.Text) ? "ต.-" : "ต." + Car_Old_Owner_Subdistrict_TBx.Text;
            cls.Car_old_owner_district    = string.IsNullOrEmpty(Car_Old_Owner_District_TBx.Text) ? "อ.-" : "อ." + Car_Old_Owner_District_TBx.Text;
            cls.Car_old_owner_province    = Car_Old_Owner_Province_DDL.SelectedIndex < 0 ? "จ.-" : "จ." + Car_Old_Owner_Province_DDL.SelectedItem.Text;
            cls.Car_old_owner_contry      = string.IsNullOrEmpty(Car_Old_Owner_Contry_TBx.Text) ? "" : Car_Old_Owner_Contry_TBx.Text;
            cls.Car_old_owner_zipcode     = string.IsNullOrEmpty(Car_Old_Owner_Zipcode_TBx.Text) ? "" : Car_Old_Owner_Zipcode_TBx.Text;

            cls.tent_car             = new Base_Tents_Car();
            cls.tent_car.Tent_car_id = Tent_car_DDL.SelectedIndex < 0 ? 0 : Convert.ToInt32(Tent_car_DDL.SelectedValue);

            // ข้อมูลเช็คและการโอน
            cls.Cheque_receiver     = string.IsNullOrEmpty(Cheque_receiver_TBx.Text) ? "" : Cheque_receiver_TBx.Text;
            cls.Cheque_bank         = string.IsNullOrEmpty(Cheque_bank_TBx.Text) ? "" : Cheque_bank_TBx.Text;
            cls.Cheque_bank_branch  = string.IsNullOrEmpty(Cheque_bank_branch_TBx.Text) ? "" : Cheque_bank_branch_TBx.Text;
            cls.Cheque_number       = string.IsNullOrEmpty(Cheque_number_TBx.Text) ? "" : Cheque_number_TBx.Text;
            cls.Cheque_sum          = string.IsNullOrEmpty(Cheque_sum_TBx.Text) ? 0 : Convert.ToDouble(Cheque_sum_TBx.Text);
            cls.Cheque_receive_date = string.IsNullOrEmpty(Cheque_receive_date_TBx.Text) ? null : DateTimeUtility.convertDateToMYSQL(Cheque_receive_date_TBx.Text);
            cls.Guarantee           = string.IsNullOrEmpty(Guarantee_TBx.Text) ? "" : Guarantee_TBx.Text;

            cls.bs_ls_stt = new Base_Leasing_Status();
            cls.bs_ls_stt.Contract_Status_id = 1;

            cls.Leasing_Comment = string.IsNullOrEmpty(Leasing_Comment_TBx.Text) ? "" : Leasing_Comment_TBx.Text;

            Session["Leasings"] = cls;

            if (cls_mng.editCarLeasings(cls))
            {
                /// Acticity Logs System
                ///

                package_login = (Base_Companys)Session["Package"];
                acc_lgn       = (Account_Login)Session["Login"];

                string message = Messages_Logs._messageLogsNormal(acc_lgn.Account_F_name, " แก้ไขข้อมูลสัญญาเช่า-ซื้อ ในสัญญา : " + cls.Leasing_no + " เลขที่ฝาก : " + cls.Deps_no, acc_lgn.resu, package_login.Company_N_name);

                new Activity_Log_Manager().addActivityLogs(message, acc_lgn.Account_id, package_login.Company_id);

                /// Acticity Logs System
                ///

                Session["Class_Active"] = 3;

                if (Session["Agents_Leasing"] == null)
                {
                    Response.Redirect("/Form_Leasings/Leasing_Add_Agent");
                }
                else
                {
                    Response.Redirect("/Form_Leasings/Leasing_Edit_Agent");
                }
            }
            else
            {
                Alert_Danger_Panel.Visible   = true;
                alert_header_danger_Lbl.Text = "แจ้งเตือน!!";
                alert_danger_Lbl.Text        = "กรุณาตรวจสอบ ข้อมูลอีกครั้ง";

                Alert_Danger_Panel.Focus();
            }
        }
        /*******************************************************************************************************************************************************************************
        ****************************************************              Get Data And Replace To Form Function                 ********************************************************
        ****************************************************                                                                    ********************************************************
        *******************************************************************************************************************************************************************************/

        private void _GetLeasing(string Leasing_id)
        {
            Car_Leasings_Manager cls_mng = new Car_Leasings_Manager();

            Car_Leasings cls_tmp = cls_mng.getCarLeasingById(Leasing_id);

            Deps_No_TBx.Text                = cls_tmp.Deps_no;
            Leasing_No_TBx.Text             = cls_tmp.Leasing_no;
            Leasing_Code_DDL.SelectedValue  = cls_tmp.bs_ls_code.Leasing_code_id.ToString();
            Leasing_Date_TBx.Text           = DateTimeUtility.convertDateToPageRealServer(cls_tmp.Leasing_date);
            Company_DDL.SelectedValue       = cls_tmp.bs_cpn.Company_id.ToString();
            Zone_DDL.SelectedValue          = cls_tmp.bs_zn.Zone_id.ToString();
            Court_DDL.SelectedValue         = cls_tmp.bs_ct.Court_id.ToString();
            Person_Receive_Trasfer_TBx.Text = cls_tmp.PeReT;

            TotalPaymentTime_DDL.SelectedValue = cls_tmp.TotalPaymentTime.ToString();
            Total_Require_TBx.Text             = cls_tmp.Total_require.ToString();
            Interest_Rate_TBx.Text             = cls_tmp.Interest_rate.ToString();
            Total_Period_TBx.Text      = cls_tmp.Total_period.ToString();
            Total_Sum_TBx.Text         = cls_tmp.Total_sum.ToString("#,##0.00");
            Total_Interest_TBx.Text    = cls_tmp.Total_Interest.ToString("#,##0.00");
            Total_Tax_TBx.Text         = cls_tmp.Total_Tax.ToString("#,##0.00");
            Total_Leasing_TBx.Text     = cls_tmp.Total_leasing.ToString("#,##0.00");
            Total_Net_Leasing_TBx.Text = cls_tmp.Total_Net_leasing.ToString("#,##0.00");
            Period_Cal_TBx.Text        = cls_tmp.Period_cal.ToString("#,##0.00");
            Period_interst_TBx.Text    = cls_tmp.Period_interst.ToString("#,##0.00");
            Period_tax_TBx.Text        = cls_tmp.Period_tax.ToString("#,##0.00");
            Period_pure_TBx.Text       = cls_tmp.Period_pure.ToString("#,##0.00");
            Period_Payment_TBx.Text    = cls_tmp.Period_payment.ToString("#,##0.00");
            Period_require_TBx.Text    = cls_tmp.Period_require.ToString("#,##0.00");

            Payment_Schedule_DDL.SelectedValue = cls_tmp.Payment_schedule.ToString();
            First_Payment_Date_TBx.Text        = DateTimeUtility.convertDateToPageRealServer(cls_tmp.First_payment_date);

            // ข้อมูลรถ
            Car_Register_Date_TBx.Text           = string.IsNullOrEmpty(cls_tmp.Car_register_date) ? "" : DateTimeUtility.convertDateToPageRealServer(cls_tmp.Car_register_date);
            Car_Plate_TBx.Text                   = cls_tmp.Car_license_plate;
            Car_Plate_Province_DDL.SelectedValue = cls_tmp.Car_license_plate_province.IndexOf('.') >= 1 ? Thai_Province._getThaiProvinces(cls_tmp.Car_license_plate_province.Split('.')[1]) : "0";
            Car_Type_TBx.Text               = cls_tmp.Car_type;
            Car_Feature_TBx.Text            = cls_tmp.Car_feature;
            Car_Brand_DDL.SelectedValue     = cls_tmp.bs_cbrn.car_brand_id.ToString();
            Car_Model_TBx.Text              = cls_tmp.Car_model;
            Car_Year_DDL.SelectedValue      = cls_tmp.Car_year;
            Car_Color_TBx.Text              = cls_tmp.Car_color;
            Engine_No_TBx.Text              = cls_tmp.Car_engine_no;
            Engine_No_At_TBx.Text           = cls_tmp.Car_engine_no_at;
            Engine_Brand_TBx.Text           = cls_tmp.Car_engine_brand;
            Chassis_No_TBx.Text             = cls_tmp.Car_chassis_no;
            Chassis_No_At_TBx.Text          = cls_tmp.Car_chassis_no_at;
            Car_Fuel_Type_TBx.Text          = cls_tmp.Car_fual_type;
            Car_Gas_No_TBx.Text             = cls_tmp.Car_gas_No;
            Car_Used_DDL.SelectedValue      = cls_tmp.Car_used_id.ToString();
            Car_Distance_TBx.Text           = cls_tmp.Car_distance.ToString();
            Car_Next_Register_Date_TBx.Text = string.IsNullOrEmpty(cls_tmp.Car_next_register_date) ? "" : DateTimeUtility.convertDateToPageRealServer(cls_tmp.Car_next_register_date);
            Car_Tax_Value_TBx.Text          = cls_tmp.Car_tax_value.ToString();
            Car_Credits_TBx.Text            = cls_tmp.Car_credits;
            Car_agent_TBx.Text              = cls_tmp.Car_agent;

            Car_Old_Owner_TBx.Text                   = cls_tmp.Car_old_owner;
            Car_Old_Owner_Idcard_TBx.Text            = cls_tmp.Car_old_owner_idcard;
            Car_old_owner_b_date_TBx.Text            = string.IsNullOrEmpty(cls_tmp.Car_old_owner_b_date) ? "" : DateTimeUtility.convertDateToPageRealServer(cls_tmp.Car_old_owner_b_date);
            Car_Old_Owner_Address_No_TBx.Text        = cls_tmp.Car_old_owner_address_no;
            Car_Old_Owner_Vilage_TBx.Text            = cls_tmp.Car_old_owner_vilage.IndexOf('.') >= 1 ? cls_tmp.Car_old_owner_vilage.Split('.')[1] : "";
            Car_Old_Owner_Vilage_No_TBx.Text         = cls_tmp.Car_old_owner_vilage_no.IndexOf('.') >= 1 ? cls_tmp.Car_old_owner_vilage_no.Split('.')[1] : "";
            Car_Old_Owner_alley_TBx.Text             = cls_tmp.Car_old_owner_alley.IndexOf('.') >= 1 ? cls_tmp.Car_old_owner_alley.Split('.')[1] : "";
            Car_Old_Owner_Road_TBx.Text              = cls_tmp.Car_old_owner_road.IndexOf('.') >= 1 ? cls_tmp.Car_old_owner_road.Split('.')[1] : "";
            Car_Old_Owner_Subdistrict_TBx.Text       = cls_tmp.Car_old_owner_subdistrict.IndexOf('.') >= 1 ? cls_tmp.Car_old_owner_subdistrict.Split('.')[1] : "";
            Car_Old_Owner_District_TBx.Text          = cls_tmp.Car_old_owner_district.IndexOf('.') >= 1 ? cls_tmp.Car_old_owner_district.Split('.')[1] : "";
            Car_Old_Owner_Province_DDL.SelectedValue = cls_tmp.Car_old_owner_province.IndexOf('.') >= 1 ? Thai_Province._getThaiProvinces(cls_tmp.Car_old_owner_province.Split('.')[1]) : "0";
            Car_Old_Owner_Contry_TBx.Text            = cls_tmp.Car_old_owner_contry;
            Car_Old_Owner_Zipcode_TBx.Text           = cls_tmp.Car_old_owner_zipcode;

            Tent_car_DDL.SelectedValue   = cls_tmp.tent_car.Tent_car_id.ToString();
            Cheque_receiver_TBx.Text     = cls_tmp.Cheque_receiver;
            Cheque_bank_TBx.Text         = cls_tmp.Cheque_bank;
            Cheque_bank_branch_TBx.Text  = cls_tmp.Cheque_bank_branch;
            Cheque_number_TBx.Text       = cls_tmp.Cheque_number;
            Cheque_sum_TBx.Text          = cls_tmp.Cheque_sum.ToString();
            Cheque_receive_date_TBx.Text = string.IsNullOrEmpty(cls_tmp.Cheque_receive_date) ? "" : DateTimeUtility.convertDateToPageRealServer(cls_tmp.Cheque_receive_date);

            Leasing_Comment_TBx.Text = cls_tmp.Leasing_Comment;

            _CheckLeasingPayment(Leasing_id);
        }