Exemple #1
0
        private void _loadReport()
        {
            cls = (Car_Leasings)Session["Leasings"];

            MySqlConnection con = MySQLConnection.connectionMySQL();

            try
            {
                /*
                 * :: StoredProcedure :: [ rpt_payment_schedule ] ::
                 *  rpt_payment_schedule (IN i_Leasing_id varchar(50))
                 *
                 */

                con.Open();
                MySqlCommand cmd = new MySqlCommand("rpt_payment_schedule", con);
                cmd.CommandType    = CommandType.StoredProcedure;
                cmd.CommandTimeout = 0;

                cmd.Parameters.AddWithValue("@i_Leasing_id", cls.Leasing_id);

                MySqlDataReader reader = cmd.ExecuteReader();

                Payment_Schedule_Ds pay_schd_ds = new Payment_Schedule_Ds();
                pay_schd_ds.Clear();
                pay_schd_ds.Tables["r_payment_schedule"].Load(reader);

                /*Payment_Schedule rpt = new Payment_Schedule();
                 * rpt.SetDataSource(pay_schd_ds);*/

                Payment_Schedule_001 rpt = new Payment_Schedule_001();
                rpt.SetDataSource(pay_schd_ds);

                CRV_Payment_Schedule.ReportSource = rpt;

                /// Export Report to PDF File with Save As Mode
                /// rpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Payment_Schedule_" + cls.Deps_no);
                /// Response.End();

                ExportReport(rpt);
            }
            catch (MySqlException ex)
            {
                error = "MysqlException ==> Payment_Schedule_Prv --> _loadReport() ";
                Log_Error._writeErrorFile(error, ex);
            }
            catch (Exception ex)
            {
                error = "Exception ==> Payment_Schedule_Prv --> _loadReport() ";
                Log_Error._writeErrorFile(error, ex);
            }
            finally
            {
                con.Close();
                con.Dispose();
            }

            GC.Collect();
        }
        private void _GetHomePhoto()
        {
            cls = (Car_Leasings)Session["Leasings"];

            List <Car_Leasings_Photo> list_cls_photo = cls_mng.getLeasingsCarPhoto(cls.Leasing_id);

            Session["list_cls_photo"] = list_cls_photo;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Login"] == null || Session["Package"] == null)
            {
                Response.Redirect("/Authorization/Login");
            }

            if (Session["Leasings"] != null)
            {
                cls = (Car_Leasings)Session["Leasings"];
            }
            else
            {
                Response.Redirect("/Form_Leasings/Leasing_Add");
            }

            if (!IsPostBack)
            {
                if (Session["Remove_Message"] != null)
                {
                    Alert_Danger_Panel.Visible  = false;
                    Alert_Success_Panel.Visible = true;

                    alert_header_success_Lbl.Text = "ลบรูปภาพสำเร็จ";
                    alert_success_Lbl.Text        = "ระบบได้ลบข้อมลรูปภาพเป็นที่เรียบร้อยแล้ว";
                }

                if (Session["Uploaded_Leasing"] != null)
                {
                    if (Session["Uploaded_Leasing"].Equals("1"))
                    {
                        Alert_Danger_Panel.Visible  = false;
                        Alert_Success_Panel.Visible = true;

                        alert_header_success_Lbl.Text = "อัพโหลดภาพสำเร็จ";
                        alert_success_Lbl.Text        = "ระบบได้เพิ่มข้อมลรูปภาพเป็นที่เรียบร้อยแล้ว";
                    }
                    else if (Session["Uploaded_Leasing"].Equals("0"))
                    {
                        Alert_Danger_Panel.Visible  = true;
                        Alert_Success_Panel.Visible = false;

                        alert_header_danger_Lbl.Text = "อัพโหลดภาพไม่สำเร็จ";
                        alert_danger_Lbl.Text        = "ระบบไม่สามารถอัพโหลดรูปภาพดังกล่าวได้กรุณาตรวจสอบภาพ หรือ ติดต่อผู้เกี่ยวข้อง";
                    }
                }

                _GetHomePhoto();

                if (Session["Remove_Message"] != null)
                {
                    Session.Remove("Remove_Message");
                }
            }
        }
Exemple #4
0
        public void ExportReport(Certified_Leasing_Result rpt)
        {
            try
            {
                cls = (Car_Leasings)Session["Leasings"];

                /// Create Main Folder for Detected Images of Contact Leasing
                string mainDirectory = cls.Leasing_id;

                string mainDirectoryPath = "C:/ReportExport/" + mainDirectory;

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

                string FilePath = "C:/ReportExport/" + mainDirectory + "/หนังสือรับรองการเช่า-ซื้อ_" + cls.Deps_no + ".pdf";

                if (File.Exists(FilePath))
                {
                    File.Delete(FilePath);
                }

                /// Export Report to PDF File with Save As Mode
                rpt.ExportToDisk(ExportFormatType.PortableDocFormat, @"C:/ReportExport/" + mainDirectory + "/หนังสือรับรองการเช่า-ซื้อ_" + cls.Deps_no + ".pdf");

                /// Display PDF File to PDF Program
                /// Process process = new Process();
                /// process.StartInfo.UseShellExecute = true;
                /// process.StartInfo.FileName = FilePath;
                /// process.Start();

                WebClient User       = new WebClient();
                Byte[]    FileBuffer = User.DownloadData(FilePath);
                if (FileBuffer != null)
                {
                    Response.ContentType = "application/pdf";
                    Response.AddHeader("content-length", FileBuffer.Length.ToString());
                    Response.BinaryWrite(FileBuffer);
                }

                User.Dispose();
            }
            catch (Exception ex)
            {
                error = "Exception ==> Certified_Leasing : Page --> ExportReport() ";
                Log_Error._writeErrorFile(error, ex);
            }

            rpt.Dispose();

            GC.Collect();
        }
Exemple #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Login"] == null || Session["Package"] == null)
            {
                Response.Redirect("/Authorization/Login");
            }

            if (!IsPostBack)
            {
                if (Session["Uploaded"] != null)
                {
                    Session.Remove("Uploaded");
                }

                if (Request.Params["code"] != null)
                {
                    string[] code       = Request.Params["code"].Split('U');
                    string   Leasing_id = code[1];
                    string   number_img = code[2];

                    cls_photo = cls_mng.getLeasingsCarPhotoSelected(Leasing_id, number_img);

                    if (string.IsNullOrEmpty(cls_photo.Car_img_path))
                    {
                        cls_mng.removeLeasingsCarPhoto(cls_photo.Leasing_id, cls_photo.Car_img_num);
                    }
                    else
                    {
                        File.Delete(cls_photo.Car_img_local_path);
                        cls_mng.removeLeasingsCarPhoto(cls_photo.Leasing_id, cls_photo.Car_img_num);
                    }

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

                    /// 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["Remove_Message"]        = 1;
                    Session["Class_Active_Customer"] = 9;
                    Response.Redirect("/Form_Leasings/Leasing_Car_Img");
                }
            }
        }
Exemple #6
0
        private void _loadCustomer(Car_Leasings cls)
        {
            MySqlConnection con_ctm = MySQLConnection.connectionMySQL();

            try
            {
                con_ctm.Open();
                MySqlCommand cmd_ctm = new MySqlCommand("rpt_leasings_customers", con_ctm);
                cmd_ctm.CommandType = CommandType.StoredProcedure;
                cmd_ctm.Parameters.AddWithValue("@i_Leasing_id", cls.Leasing_id);
                cmd_ctm.Parameters.AddWithValue("@i_Cust_id", cls.ctm.Cust_id);

                MySqlDataReader reader_ctm = cmd_ctm.ExecuteReader();

                string defaultString = "";

                if (reader_ctm.Read())
                {
                    Ctm_Name_TBx.Text        = reader_ctm.IsDBNull(3) ? defaultString : reader_ctm.GetString(3);
                    Ctm_Name_TBx.Text       += reader_ctm.IsDBNull(4) ? defaultString : " " + reader_ctm.GetString(4);
                    Ctm_Address_No_TBx.Text  = reader_ctm.IsDBNull(77) ? defaultString : reader_ctm.GetString(77);
                    Ctm_Moo_TBx.Text         = reader_ctm.IsDBNull(79) ? defaultString : reader_ctm.GetString(79).Split('.')[1];
                    Ctm_Alley_TBx.Text       = reader_ctm.IsDBNull(80) ? defaultString : reader_ctm.GetString(80).Split('.')[1];
                    Ctm_Road_TBx.Text        = reader_ctm.IsDBNull(81) ? defaultString : reader_ctm.GetString(81).Split('.')[1];
                    Ctm_Subdistrict_TBx.Text = reader_ctm.IsDBNull(82) ? defaultString : reader_ctm.GetString(82).Split('.')[1];
                    Ctm_District_TBx.Text    = reader_ctm.IsDBNull(83) ? defaultString : reader_ctm.GetString(83).Split('.')[1];
                    Ctm_Province_TBx.Text    = reader_ctm.IsDBNull(85) ? defaultString : reader_ctm.GetString(85);

                    Ctm_Name_II_TBx.Text = Ctm_Name_TBx.Text;
                }
            }
            catch (MySqlException ex)
            {
                error = "MysqlException ==> Certified_Leasing_Result_Prv : Page--> _loadCustomer() ";
                Log_Error._writeErrorFile(error, ex);
            }
            catch (Exception ex)
            {
                error = "Exception ==> Certified_Leasing_Result_Prv : Page--> _loadCustomer() ";
                Log_Error._writeErrorFile(error, ex);
            }
            finally
            {
                con_ctm.Close();
                con_ctm.Dispose();
            }

            GC.Collect();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Login"] == null || Session["Package"] == null)
            {
                Response.Redirect("/Authorization/Login");
            }

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

            if (acc_lgn.acc_lv.level_access < 7)
            {
                Save_Btn.Visible = false;
            }

            if (acc_lgn.acc_lv.level_access == 2)
            {
                Save_Btn.Visible = true;
            }

            if (Session["Leasings"] == null)
            {
                Session["Class_Active"] = 2;
                Response.Redirect("/Form_Leasings/Leasing_Add");
            }

            if (!IsPostBack)
            {
                _loadCarType();
                _loadCarBrand();
                _loadCarYear();
                _loadCarUsed();
                _loadCompanys();
                _loadCourt();
                _loadLeasingCode();
                _loadPaymentSchedule();
                _loadTentsCar();
                _loadZoneService();
                _loadTotalPaymentTime();
                _loadThaiProvinces();

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

                _GetLeasing(cls_tmp.Leasing_id);
            }
        }
        private void _getLeasing()
        {
            cls = (Car_Leasings)Session["Leasings"];

            MySqlConnection con_cls = MySQLConnection.connectionMySQL();

            try
            {
                con_cls.Open();
                MySqlCommand cmd_cls = new MySqlCommand("rpt_leasings", con_cls);
                cmd_cls.CommandType = CommandType.StoredProcedure;
                cmd_cls.Parameters.AddWithValue("@i_Leasing_id", cls.Leasing_id);

                MySqlDataReader reader_cls = cmd_cls.ExecuteReader();

                string defaultString = "";

                if (reader_cls.Read())
                {
                    Payment_Amount_TBx.Text = reader_cls.IsDBNull(32) ? defaultString : reader_cls.GetString(32);
                    Car_Plate_TBx.Text      = reader_cls.IsDBNull(54) ? defaultString : reader_cls.GetString(54);
                    Car_Plate_TBx.Text     += reader_cls.IsDBNull(56) ? defaultString : " " + reader_cls.GetString(56);
                    Car_TBx.Text            = reader_cls.IsDBNull(57) ? defaultString : reader_cls.GetString(57);
                    Car_Brand_TBx.Text      = reader_cls.IsDBNull(61) ? defaultString : reader_cls.GetString(61);
                    Car_Brand_TBx.Text     += reader_cls.IsDBNull(60) ? defaultString : " (" + reader_cls.GetString(60) + ")";
                    Car_Brand_TBx.Text     += reader_cls.IsDBNull(62) ? defaultString : " " + reader_cls.GetString(62);
                    Car_Engine_TBx.Text     = reader_cls.IsDBNull(65) ? defaultString : reader_cls.GetString(65);
                    Car_Chassis_TBx.Text    = reader_cls.IsDBNull(68) ? defaultString : reader_cls.GetString(68);
                }
            }
            catch (MySqlException ex)
            {
                error = "MysqlException ==> Confirm_Payment_Web_Outline Page --> _getLeasing() ";
                Log_Error._writeErrorFile(error, ex);
            }
            catch (Exception ex)
            {
                error = "Exception ==> Confirm_Payment_Web_Outline  Page --> _getLeasing() ";
                Log_Error._writeErrorFile(error, ex);
            }
            finally
            {
                con_cls.Close();
                con_cls.Dispose();
            }
        }
        public void ExportReport(Car_Leasing_KH2 rpt)
        {
            cls = (Car_Leasings)Session["Leasings"];

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

            string mainDirectoryPath = "C:/ReportExport/" + mainDirectory;

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

            string FilePath = "C:/ReportExport/" + mainDirectory + "/สัญญา_ข_2_" + cls.Deps_no + ".pdf";

            if (File.Exists(FilePath))
            {
                File.Delete(FilePath);
            }

            /// Export Report to PDF File with Save As Mode
            rpt.ExportToDisk(ExportFormatType.PortableDocFormat, @"C:/ReportExport/" + mainDirectory + "/สัญญา_ข_2_" + cls.Deps_no + ".pdf");

            /// Display PDF File to PDF Program
            /// Process process = new Process();
            /// process.StartInfo.UseShellExecute = true;
            /// process.StartInfo.FileName = FilePath;
            /// process.Start();

            WebClient User = new WebClient();

            Byte[] FileBuffer = User.DownloadData(FilePath);
            if (FileBuffer != null)
            {
                Response.ContentType = "application/pdf";
                Response.AddHeader("content-length", FileBuffer.Length.ToString());
                Response.BinaryWrite(FileBuffer);
            }

            User.Dispose();
            rpt.Dispose();

            GC.Collect();
        }
Exemple #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Login"] == null || Session["Package"] == null)
            {
                Response.Redirect("/Authorization/Login");
            }

            if (Session["Leasings"] != null)
            {
                cls = (Car_Leasings)Session["Leasings"];

                List <Car_Leasings_Payment> list_cls_pay = cls_pay_mng.getRealPaymentInfo(cls.Leasing_id);

                Session["list_cls_pay"] = list_cls_pay;
            }
            else
            {
                Response.Redirect("/Form_Leasings/Leasing_Add");
            }
        }
Exemple #11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Login"] == null || Session["Package"] == null)
            {
                Response.Redirect("/Authorization/Login");
            }

            if (!IsPostBack)
            {
                if (Session["Leasings"] != null)
                {
                    cls = (Car_Leasings)Session["Leasings"];

                    cls.ctm = new Customers();
                    cls.ctm = (Customers)Session["Customer_Leasing"];

                    _loadLeasing(cls);
                    _loadCustomer(cls);
                }
            }
        }
        public void printReport()
        {
            try
            {
                cls = (Car_Leasings)Session["Leasings"];

                string Company_Values = (string)Session["Data_CFPM_Values"];

                string[] Array_Data = Company_Values.Split('|');

                Confirm_Payment_Outline rpt = new Confirm_Payment_Outline();
                rpt.SetParameterValue("Company_Name", Array_Data[0]);
                rpt.SetParameterValue("Company_Type", Array_Data[1]);
                rpt.SetParameterValue("Car_Plate", Array_Data[2]);
                rpt.SetParameterValue("Car_Type", Array_Data[3]);
                rpt.SetParameterValue("Car_Brand", Array_Data[4]);
                rpt.SetParameterValue("Car_Engine_No", Array_Data[5]);
                rpt.SetParameterValue("Car_Chassis_No", Array_Data[6]);
                rpt.SetParameterValue("Payment_To", Array_Data[7]);
                rpt.SetParameterValue("Payment_Amount", Convert.ToDouble(Array_Data[8]));
                rpt.SetParameterValue("Bottom_Address", Array_Data[9]);
                rpt.SetParameterValue("Print_Date", DateTimeUtility.convertDateToPage(cls.Leasing_date));

                CRV_Display_Report.ReportSource = rpt;

                /// Export Report to PDF File with Save As Mode
                /// rpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Payment_Schedule_" + cls.Deps_no);
                /// Response.End();

                ExportReport(rpt);
            }
            catch (Exception ex)
            {
                error = "Exception ==> Confirm_Payment : Page --> printReport() ";
                Log_Error._writeErrorFile(error, ex);
            }

            GC.Collect();
        }
Exemple #13
0
        private void _loadLeasing(Car_Leasings cls)
        {
            MySqlConnection con_cls = MySQLConnection.connectionMySQL();

            try
            {
                con_cls.Open();
                MySqlCommand cmd_cls = new MySqlCommand("rpt_leasings", con_cls);
                cmd_cls.CommandType = CommandType.StoredProcedure;
                cmd_cls.Parameters.AddWithValue("@i_Leasing_id", cls.Leasing_id);

                MySqlDataReader reader_cls = cmd_cls.ExecuteReader();

                string defaultString = "";

                if (reader_cls.Read())
                {
                    Print_Date_TBx.Text = reader_cls.IsDBNull(5) ? defaultString : reader_cls.GetString(5);
                    Registrar_TBx.Text  = reader_cls.IsDBNull(56) ? defaultString : "จังหวัด" + reader_cls.GetString(56);

                    Car_TBx.Text  = reader_cls.IsDBNull(57) ? defaultString : reader_cls.GetString(57);
                    Car_TBx.Text += reader_cls.IsDBNull(61) ? defaultString : " " + reader_cls.GetString(61);
                    Car_TBx.Text += reader_cls.IsDBNull(60) ? defaultString : " (" + reader_cls.GetString(60) + ")";
                    Car_TBx.Text += reader_cls.IsDBNull(64) ? defaultString : " สี " + reader_cls.GetString(64);

                    Model_TBx.Text = reader_cls.IsDBNull(62) ? defaultString : " " + reader_cls.GetString(62);

                    Car_Engine_TBx.Text  = reader_cls.IsDBNull(65) ? defaultString : reader_cls.GetString(65);
                    Car_Chassis_TBx.Text = reader_cls.IsDBNull(68) ? defaultString : reader_cls.GetString(68);

                    Car_II_TBx.Text = Car_TBx.Text;

                    Leasing_Date_TBx.Text = Print_Date_TBx.Text;

                    double Finance              = reader_cls.IsDBNull(32) ? 0 : reader_cls.GetDouble(32);
                    int    Total_Period         = reader_cls.IsDBNull(35) ? 0 : reader_cls.GetInt32(35);
                    double Interest             = reader_cls.IsDBNull(37) ? 0 : reader_cls.GetDouble(37);
                    double Total_Period_Payment = reader_cls.IsDBNull(45) ? 0 : reader_cls.GetDouble(45);
                    double Period_Pay           = reader_cls.IsDBNull(41) ? 0 : reader_cls.GetDouble(41);


                    double Period_Vat    = Total_Period_Payment - Period_Pay;
                    double Total_Finance = Finance + Interest;

                    Finance_TBx.Text              = Finance.ToString("#,###.00");
                    Interest_TBx.Text             = Interest.ToString("#,###.00");
                    Total_Finance_TBx.Text        = Total_Finance.ToString("#,###.00");
                    Total_Period_TBx.Text         = Total_Period.ToString();
                    Payment_Period_TBx.Text       = Period_Pay.ToString("#,###.00");
                    Period_Pay_TBx.Text           = Period_Pay.ToString("#,###.00");
                    Period_Vat_TBx.Text           = Period_Vat.ToString("#,###.00");
                    Total_Period_Payment_TBx.Text = Total_Period_Payment.ToString("#,###.00");

                    Car_III_TBx.Text = Car_TBx.Text;
                    Car_IV_TBx.Text  = Car_TBx.Text;
                }
            }
            catch (MySqlException ex)
            {
                error = "MysqlException ==> Certified_Leasing_Result_Prv : Page --> _loadReport() ";
                Log_Error._writeErrorFile(error, ex);
            }
            catch (Exception ex)
            {
                error = "Exception ==> Certified_Leasing_Result_Prv : Page --> _loadReport() ";
                Log_Error._writeErrorFile(error, ex);
            }
            finally
            {
                con_cls.Close();

                con_cls.Dispose();
            }

            GC.Collect();
        }
Exemple #14
0
        /*******************************************************************************************************************************************************************************
        ****************************************************                               Add Data Function                    ********************************************************
        ****************************************************                                                                    ********************************************************
        *******************************************************************************************************************************************************************************/

        private void _EditAgent()
        {
            Agents_Manager cag_mng = new Agents_Manager();
            Agents         cag     = new Agents();

            bool past_page = false;

            if (Session["chk_agent_leasing"] != null)
            {
                Agents cag_tmp = (Agents)Session["chk_agent_leasing"];

                cag.Agent_id          = cag_tmp.Agent_id;
                cag.Agent_Fname       = string.IsNullOrEmpty(Agent_fname_TBx.Text) ? "" : Agent_fname_TBx.Text;
                cag.Agent_Lname       = string.IsNullOrEmpty(Agent_lname_TBx.Text) ? "" : Agent_lname_TBx.Text;
                cag.Agent_Idcard      = string.IsNullOrEmpty(Agent_idcard_TBx.Text) ? "" : Agent_idcard_TBx.Text;
                cag.Agent_Address_no  = string.IsNullOrEmpty(Agent_address_no_TBx.Text) ? "" : Agent_address_no_TBx.Text;
                cag.Agent_Vilage      = string.IsNullOrEmpty(Agent_vilage_TBx.Text) ? "บ.-" : "บ." + Agent_vilage_TBx.Text;
                cag.Agent_Vilage_no   = string.IsNullOrEmpty(Agent_vilage_no_TBx.Text) ? "ม.-" : "ม." + Agent_vilage_no_TBx.Text;
                cag.Agent_Alley       = string.IsNullOrEmpty(Agent_alley_TBx.Text) ? "ซ.-" : "ซ." + Agent_alley_TBx.Text;
                cag.Agent_Road        = string.IsNullOrEmpty(Agent_road_TBx.Text) ? "ถ.-" : "ถ." + Agent_road_TBx.Text;
                cag.Agent_Subdistrict = string.IsNullOrEmpty(Agent_subdistrict_TBx.Text) ? "ต.-" : "ต." + Agent_subdistrict_TBx.Text;
                cag.Agent_District    = string.IsNullOrEmpty(Agent_district_TBx.Text) ? "อ.-" : "อ." + Agent_district_TBx.Text;
                cag.Agent_Province    = Agent_province_DDL.SelectedIndex <= 0 ? "จ.-" : "จ." + Agent_province_DDL.SelectedItem.Text;
                cag.Agent_Country     = string.IsNullOrEmpty(Agent_country_TBx.Text) ? "" : Agent_country_TBx.Text;
                cag.Agent_Zipcode     = string.IsNullOrEmpty(Agent_zipcode_TBx.Text) ? "" : Agent_zipcode_TBx.Text;

                past_page = cag_mng.editAgent(cag);
            }
            else
            {
                cag.Agent_id          = cag_mng.generateAgentID();
                cag.Agent_Fname       = string.IsNullOrEmpty(Agent_fname_TBx.Text) ? "" : Agent_fname_TBx.Text;
                cag.Agent_Lname       = string.IsNullOrEmpty(Agent_lname_TBx.Text) ? "" : Agent_lname_TBx.Text;
                cag.Agent_Idcard      = string.IsNullOrEmpty(Agent_idcard_TBx.Text) ? "" : Agent_idcard_TBx.Text;
                cag.Agent_Address_no  = string.IsNullOrEmpty(Agent_address_no_TBx.Text) ? "" : Agent_address_no_TBx.Text;
                cag.Agent_Vilage      = string.IsNullOrEmpty(Agent_vilage_TBx.Text) ? "บ.-" : "บ." + Agent_vilage_TBx.Text;
                cag.Agent_Vilage_no   = string.IsNullOrEmpty(Agent_vilage_no_TBx.Text) ? "ม.-" : "ม." + Agent_vilage_no_TBx.Text;
                cag.Agent_Alley       = string.IsNullOrEmpty(Agent_alley_TBx.Text) ? "ซ.-" : "ซ." + Agent_alley_TBx.Text;
                cag.Agent_Road        = string.IsNullOrEmpty(Agent_road_TBx.Text) ? "ถ.-" : "ถ." + Agent_road_TBx.Text;
                cag.Agent_Subdistrict = string.IsNullOrEmpty(Agent_subdistrict_TBx.Text) ? "ต.-" : "ต." + Agent_subdistrict_TBx.Text;
                cag.Agent_District    = string.IsNullOrEmpty(Agent_district_TBx.Text) ? "อ.-" : "อ." + Agent_district_TBx.Text;
                cag.Agent_Province    = Agent_province_DDL.SelectedIndex <= 0 ? "จ.-" : "จ." + Agent_province_DDL.SelectedItem.Text;
                cag.Agent_Country     = string.IsNullOrEmpty(Agent_country_TBx.Text) ? "" : Agent_country_TBx.Text;
                cag.Agent_Zipcode     = string.IsNullOrEmpty(Agent_zipcode_TBx.Text) ? "" : Agent_zipcode_TBx.Text;

                past_page = cag_mng.addAgent(cag);
            }

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

            Agents_Commission cag_com = new Agents_Commission();

            cag_com.Leasing_id = cls_tmp.Leasing_id;

            cag_com.cag = new Agents();
            cag_com.cag = cag;

            cag_com.Agent_commission = string.IsNullOrEmpty(Agent_commission_TBx.Text) ? 0 : Convert.ToDouble(Agent_commission_TBx.Text);
            cag_com.Agent_percen     = string.IsNullOrEmpty(Agent_percen_TBx.Text) ? 0 : Convert.ToDouble(Agent_percen_TBx.Text);
            cag_com.Agent_cash       = string.IsNullOrEmpty(Agent_cash_TBx.Text) ? 0 : Convert.ToDouble(Agent_cash_TBx.Text);
            cag_com.Agent_net_com    = string.IsNullOrEmpty(Agent_net_com_TBx.Text) ? 0 : Convert.ToDouble(Agent_net_com_TBx.Text);
            cag_com.Agent_num_code   = string.IsNullOrEmpty(Agent_com_code_TBx.Text) ? "" : Agent_com_code_TBx.Text;
            cag_com.Agent_book_code  = string.IsNullOrEmpty(Agent_bookcode_TBx.Text) ? "" : Agent_bookcode_TBx.Text;
            cag_com.Agent_date_print = string.IsNullOrEmpty(Agent_date_print_TBx.Text) ? DateTimeUtility._dateNOWForServer() : DateTimeUtility.convertDateToMYSQL(Agent_date_print_TBx.Text);

            if (cag_mng.editAgentCommission(cag_com) && past_page)
            {
                cag_com = cag_mng.getAgentCommission(cag_com.cag.Agent_id, cls_tmp.Leasing_id);

                Session["Agents_Leasing"] = string.IsNullOrEmpty(cag_com.cag.Agent_id) ? null : cag_com;

                /// 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_tmp.Leasing_no + " เลขที่ฝาก : " + cls_tmp.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.Remove("chk_agent_leasing");

                Session["Class_Active"] = 4;

                Session["Number_Of_Guarantor"] = "1";

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

                Alert_Danger_Panel.Focus();
            }
        }
Exemple #15
0
        protected void Payment_Btn_Click(object sender, EventArgs e)
        {
            string[] code       = Request.Params["code"].Split('U');
            string   leasing_id = code[1];
            string   idcard     = code[2];

            cls = cls_mng.getCarLeasingById(leasing_id);

            double real_payment       = string.IsNullOrEmpty(Real_Payment_TBx.Text) ? 0 : Convert.ToDouble(Real_Payment_TBx.Text);
            double cal_payment        = string.IsNullOrEmpty(Cal_Period_Payment_TBx.Text) ? 0 : Convert.ToDouble(Cal_Period_Payment_TBx.Text);
            double total_payment_left = string.IsNullOrEmpty(Total_payment_left_TBx.Text) ? 0 : Convert.ToDouble(Total_payment_left_TBx.Text);
            double period_fine        = string.IsNullOrEmpty(Total_payment_fine_TBx.Text) ? 0 : Convert.ToDouble(Total_payment_fine_TBx.Text);
            double real_payment_fine  = string.IsNullOrEmpty(Real_Payment_Fine_TBx.Text) ? 0 : Convert.ToDouble(Real_Payment_Fine_TBx.Text);
            double discount           = string.IsNullOrEmpty(Discount_TBx.Text) ? 0 : Convert.ToDouble(Discount_TBx.Text);
            double real_discount      = string.IsNullOrEmpty(Real_Discount_TBx.Text) ? 0 : Convert.ToDouble(Real_Discount_TBx.Text);
            double sum_payment_left   = total_payment_left;

            cls_pay.Leasing_id         = leasing_id;
            cls_pay.Period_fee         = string.IsNullOrEmpty(Period_free_TBx.Text) ? 0.00 : Convert.ToDouble(Period_free_TBx.Text);
            cls_pay.Period_track       = string.IsNullOrEmpty(Period_track_TBx.Text) ? 0.00 : Convert.ToDouble(Period_track_TBx.Text);
            cls_pay.Total_payment_fine = Convert.ToDouble(Real_Payment_Fine_TBx.Text);
            cls_pay.Discount           = Convert.ToDouble(Real_Discount_TBx.Text);
            cls_pay.Real_payment       = Convert.ToDouble(Real_Payment_TBx.Text);
            cls_pay.Real_payment_date  = string.IsNullOrEmpty(Payment_Date_TBx.Text) ? DateTimeUtility._dateNOWForServer() : DateTimeUtility.convertDateToMYSQL(Payment_Date_TBx.Text);
            cls_pay.Bill_no_manual_ref = string.IsNullOrEmpty(Bill_No_Manual_Ref_TBx.Text) ? "" : Bill_No_Manual_Ref_TBx.Text;

            Base_Companys package_login = new Base_Companys();
            Account_Login acc_lgn       = new Account_Login();

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

            cls_pay.acc_lgn            = new Account_Login();
            cls_pay.acc_lgn.Account_id = acc_lgn.Account_id;

            cls_pay.bs_cpn            = new Base_Companys();
            cls_pay.bs_cpn.Company_id = package_login.Company_id;

            bool past_page = false;

            if (Cal_Status_Lbl.Visible == false) /* กรณีจ่าค่างวดแบบธรรมดา */
            {
                if (real_payment >= sum_payment_left)
                {
                    if (real_payment <= 0)
                    {
                        Note_Lbl.Text = "*** ระบุยอดชำระมากกว่า : 0.00 บาท ***";

                        Real_Payment_TBx.Focus();
                    }

                    /*else if (period_fine > 0 && real_payment_fine != period_fine)
                     * {
                     *  Note_Lbl.Text = "*** มียอดค่าปรับค้างชำระจำนวน :  " + period_fine.ToString("#,###.00") + " บาท ***";
                     *
                     *  Real_Payment_Fine_TBx.Focus();
                     * }
                     * else if (period_fine == 0 && real_payment_fine != period_fine)
                     * {
                     *  Note_Lbl.Text = "*** ไม่มียอดค่าปรับค้างชำระกรุณาใส่ 0 ในช่องชำระค่าปรับ ***";
                     *
                     *  Real_Payment_Fine_TBx.Focus();
                     * }*/
                    else if (discount == 0 && real_discount != 0)
                    {
                        Note_Lbl.Text = "*** ไม่มียอดส่วนลดกรุณาใส่ 0 ในช่องส่วนลด ***";

                        Real_Payment_Fine_TBx.Focus();
                    }
                    else if (real_payment > sum_payment_left)
                    {
                        Note_Lbl.Text = "*** ยอดปิดบัญชีจำนวน : " + sum_payment_left.ToString("#,###.00") + " บาท ***";
                    }
                    else
                    {
                        Note_Lbl.Text = "";

                        if (!string.IsNullOrEmpty(Bill_No_Manual_Ref_TBx.Text))
                        {
                            past_page = cls_pay_mng.addPayment_Mod_III(cls_pay, 1);
                        }
                        else
                        {
                            past_page = cls_pay_mng.addPayment(cls_pay, 1);
                        }

                        if (past_page)
                        {
                            /// Acticity Logs System
                            ///

                            string message = Messages_Logs._messageLogsNormal(acc_lgn.Account_F_name, " บันทึกข้อมูลการจ่ายเงิน ในสัญญา : " + cls.Leasing_no + " เลขที่ฝาก : " + cls.Deps_no + " จำนวนเงิน [ค่างวด] [ค่าปรับ] [ส่วนลด] : [" + real_payment + "] [" + period_fine + "] [" + real_discount + "] ", 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

                            _clearRealPayment();
                        }
                        else
                        {
                            Alert_Danger_Panel.Visible   = true;
                            alert_header_danger_Lbl.Text = "แจ้งเตือน!!";
                            alert_danger_Lbl.Text        = "กรุณาตรวจสอบ ข้อมูลอีกครั้ง";

                            Alert_Danger_Panel.Focus();
                        }
                    }
                }
                else
                {
                    if (real_payment <= 0)
                    {
                        Note_Lbl.Text = "*** ระบุยอดชำระมากกว่า : 0.00 บาท ***";

                        Real_Payment_TBx.Focus();
                    }

                    /*else if (period_fine > 0 && real_payment_fine > period_fine)
                     * {
                     *  Note_Lbl.Text = "*** มียอดค่าปรับค้างชำระจำนวน :  " + period_fine.ToString("#,###.00") + " บาท ***";
                     *
                     *  Real_Payment_Fine_TBx.Focus();
                     * }
                     * else if (period_fine == 0 && real_payment_fine != period_fine)
                     * {
                     *  Note_Lbl.Text = "*** ไม่มียอดค่าปรับค้างชำระกรุณาใส่ 0 ในช่องชำระค่าปรับ ***";
                     *
                     *  Real_Payment_Fine_TBx.Focus();
                     * }*/
                    else if (discount == 0 && real_discount != 0)
                    {
                        Note_Lbl.Text = "*** ไม่มียอดส่วนลดกรุณาใส่ 0 ในช่องส่วนลด ***";

                        Real_Payment_Fine_TBx.Focus();
                    }
                    else
                    {
                        Note_Lbl.Text = "";

                        if (!string.IsNullOrEmpty(Bill_No_Manual_Ref_TBx.Text))
                        {
                            past_page = cls_pay_mng.addPayment_Mod_III(cls_pay, 1);
                        }
                        else
                        {
                            past_page = cls_pay_mng.addPayment(cls_pay, 1);
                        }

                        if (past_page)
                        {
                            /// Acticity Logs System
                            ///

                            string message = Messages_Logs._messageLogsNormal(acc_lgn.Account_F_name, " บันทึกข้อมูลการจ่ายเงิน ในสัญญา : " + cls.Leasing_no + " เลขที่ฝาก : " + cls.Deps_no + " จำนวนเงิน [ค่างวด] [ค่าปรับ] [ส่วนลด] : [" + real_payment + "] [" + period_fine + "] [" + real_discount + "] ", 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

                            _clearRealPayment();
                        }
                        else
                        {
                            Alert_Danger_Panel.Visible   = true;
                            alert_header_danger_Lbl.Text = "แจ้งเตือน!!";
                            alert_danger_Lbl.Text        = "กรุณาตรวจสอบ ข้อมูลอีกครั้ง";

                            Alert_Danger_Panel.Focus();
                        }
                    }
                }

                _loadLeasingDetails(leasing_id, idcard);
            }
            else /* กรณีปิดบัญชี และมีส่วนลด */
            {
                if (real_payment != cal_payment)
                {
                    Note_Lbl.Text = "*** ไม่สามารถปิดบัญชีได้ เนื่องจาก ยอดชำระไม่ตรงกับที่ระบบคำนวนได้  " + cal_payment.ToString("#,###.00") + " บาท ***";
                }

                /*else if (period_fine > 0 && real_payment_fine != period_fine)
                 * {
                 *  Note_Lbl.Text = "*** มียอดค่าปรับค้างชำระจำนวน :  " + period_fine.ToString("#,###.00") + " บาท ***";
                 *
                 *  Real_Payment_Fine_TBx.Focus();
                 * }
                 * else if (period_fine == 0 && real_payment_fine != period_fine)
                 * {
                 *  Note_Lbl.Text = "*** ไม่มียอดค่าปรับค้างชำระกรุณาใส่ 0 ในช่องชำระค่าปรับ ***";
                 *
                 *  Real_Payment_Fine_TBx.Focus();
                 * }
                 * else if (discount == 0 && real_discount != discount)
                 * {
                 *  Note_Lbl.Text = "*** ไม่มียอดส่วนลดกรุณาใส่ 0 ในช่องส่วนลด ***";
                 *
                 *  Real_Payment_Fine_TBx.Focus();
                 * }
                 * else if (discount > 0 && real_discount != discount)
                 * {
                 *  Note_Lbl.Text = "*** กรุณมระบุยอดส่วนลดจำนวน :  " + discount.ToString("#,###.00") + " บาท ***";
                 *
                 *  Real_Discount_TBx.Focus();
                 * }*/
                else
                {
                    Note_Lbl.Text = "";

                    if (!string.IsNullOrEmpty(Bill_No_Manual_Ref_TBx.Text))
                    {
                        past_page = cls_pay_mng.addPayment_Mod_III(cls_pay, 2);
                    }
                    else
                    {
                        past_page = cls_pay_mng.addPayment(cls_pay, 2);
                    }

                    if (past_page)
                    {
                        /// Acticity Logs System
                        ///

                        string message = Messages_Logs._messageLogsNormal(acc_lgn.Account_F_name, " บันทึกข้อมูลการจ่ายเงินแบบคำนวนการปิดบัญชี ในสัญญา : " + cls.Leasing_no + " เลขที่ฝาก : " + cls.Deps_no + " จำนวนเงิน [ค่างวด] [ค่าปรับ] [ส่วนลด] : [" + real_payment + "] [" + period_fine + "] [" + real_discount + "] ", 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

                        _clearRealPayment();

                        _loadLeasingDetails(leasing_id, idcard);
                    }
                    else
                    {
                        Alert_Danger_Panel.Visible   = true;
                        alert_header_danger_Lbl.Text = "แจ้งเตือน!!";
                        alert_danger_Lbl.Text        = "กรุณาตรวจสอบ ข้อมูลอีกครั้ง";

                        Alert_Danger_Panel.Focus();
                    }
                }
            }
        }
        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();
        }
Exemple #17
0
        private void _checkOldData(string leasing_id)
        {
            cls = cls_mng.getCarLeasingById(leasing_id);

            /*string error = string.Empty;
             *
             * SqlConnection con = MSSQLConnection.connectionMSSQL();
             *
             * List<Car_Leasings_Payment> list_cls_pay_shd = cls_pay_mng.getPaymentSchedule(cls.Leasing_id);
             *
             * Car_Leasings_Payment cls_pay_shd = list_cls_pay_shd[0];
             *
             * if (cls_pay_shd.Period_payment_status == 0)
             * {
             *
             *  try
             *  {
             *      con.Open();
             *
             *      string sql = " SELECT * FROM  view_payment_byday WHERE cntNoTemp = '" + cls.Deps_no + "' ORDER BY scheduleno ";
             *
             *      SqlCommand cmd = new SqlCommand(sql, con);
             *      cmd.CommandTimeout = 0;
             *
             *      SqlDataReader reader = cmd.ExecuteReader();
             *
             *      while (reader.Read())
             *      {
             *          int defaultNum = 0;
             *          string defaultString = "";
             *
             *          Car_Leasings_Payment cls_pay = new Car_Leasings_Payment();
             *
             *          cls_pay.Leasing_id = cls.Leasing_id;
             *          cls_pay.Bill_no = reader.IsDBNull(2) ? defaultString : reader.GetString(2);
             *          cls_pay.Period_fee = reader.IsDBNull(5) ? defaultNum : Convert.ToDouble(reader.GetDecimal(5));
             *          cls_pay.Period_track = reader.IsDBNull(7) ? defaultNum : Convert.ToDouble(reader.GetDecimal(7));
             *          cls_pay.Total_payment_fine = reader.IsDBNull(17) ? defaultNum : Convert.ToDouble(reader.GetDecimal(17));
             *          cls_pay.Discount = reader.IsDBNull(9) ? defaultNum : Convert.ToDouble(reader.GetDecimal(9));
             *          cls_pay.Real_payment = reader.IsDBNull(4) ? defaultNum : Convert.ToDouble(reader.GetDecimal(4));
             *
             *          cls_pay.Real_payment_date = reader.IsDBNull(3) ? null : DateTimeUtility.convertDateToMYSQLRealServer(reader.GetDateTime(3).ToString()); // Real Server JKLFTP
             *
             *          //cls_pay.Real_payment_date = reader.IsDBNull(3) ? null : DateTimeUtility.convertDateToMYSQL(reader.GetDateTime(3).ToString()); // Second Server JKLWebBase
             *
             *          cls_pay.acc_lgn = new Account_Login();
             *
             *          cls_pay.bs_cpn = new Base_Companys();
             *
             *          cls_pay.bs_cpn.Company_id = _getCompanys(reader.GetString(20));
             *
             *          if (cls_pay.Discount <= 0)
             *          {
             *              cls_pay_mng.addPayment_Mod_I(cls_pay, 1);
             *          }
             *          else
             *          {
             *              cls_pay_mng.addPayment_Mod_I(cls_pay, 2);
             *          }
             *      }
             *  }
             *  catch (SqlException ex)
             *  {
             *      error = "SqlException ==> Form_Leasings --> Leasing_Payment --> _checkOldData() ";
             *      Log_Error._writeErrorFile(error, ex);
             *  }
             *  catch (Exception ex)
             *  {
             *      error = "Exception ==> Form_Leasings --> Leasing_Payment --> _checkOldData() ";
             *      Log_Error._writeErrorFile(error, ex);
             *  }
             *  finally
             *  {
             *      con.Close();
             *      con.Dispose();
             *  }
             * }*/

            cls_pay_mng.calculateFine(cls.Leasing_id);
        }
        private void _loadReport()
        {
            cls           = (Car_Leasings)Session["Leasings"];
            package_login = (Base_Companys)Session["Package"];
            acc_lgn       = (Account_Login)Session["Login"];

            MySqlConnection con_cls = MySQLConnection.connectionMySQL();
            MySqlConnection con_cpn = MySQLConnection.connectionMySQL();

            try
            {
                con_cls.Open();
                MySqlCommand cmd_cls = new MySqlCommand("rpt_leasings", con_cls);
                cmd_cls.CommandType = CommandType.StoredProcedure;
                cmd_cls.Parameters.AddWithValue("@i_Leasing_id", cls.Leasing_id);
                MySqlDataReader reader_cls = cmd_cls.ExecuteReader();

                con_cpn.Open();
                MySqlCommand cmd_cpn = new MySqlCommand("rpt_withholding_tax", con_cpn);
                cmd_cpn.CommandType = CommandType.StoredProcedure;
                cmd_cpn.Parameters.AddWithValue("@i_Leasing_id", cls.Leasing_id);
                MySqlDataReader reader_cpn = cmd_cpn.ExecuteReader();

                Leasing_Ds ls_ds = new Leasing_Ds();
                ls_ds.Clear();
                ls_ds.Tables["Leasings"].Load(reader_cls);
                ls_ds.Tables["Agent_Commission"].Load(reader_cpn);


                Withholding_Tax rpt = new Withholding_Tax();
                rpt.SetDataSource(ls_ds);

                CRV_Display_Report.ReportSource = rpt;

                /// Export Report to PDF File with Save As Mode
                /// rpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "หนังสือรับรองหัก_ณ_ที่จ่าย_" + cls.Deps_no);
                /// Response.End();

                ExportReport(rpt);
            }
            catch (MySqlException ex)
            {
                error = "MysqlException ==> Car_Leasing_KH11 : Page --> _loadReport() ";
                Log_Error._writeErrorFile(error, ex);
            }
            catch (Exception ex)
            {
                error = "Exception ==> Car_Leasing_KH11 : Page --> _loadReport() ";
                Log_Error._writeErrorFile(error, ex);
            }
            finally
            {
                con_cls.Close();
                con_cpn.Close();

                con_cls.Dispose();
                con_cpn.Dispose();
            }

            /// Acticity Logs System
            ///

            string message = Messages_Logs._messageLogsNormal(acc_lgn.Account_F_name, " ออกรายงานลูกค้าคงเหลือ ", 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


            GC.Collect();
        }
        /*******************************************************************************************************************************************************************************
        ****************************************************                               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();
            }
        }
Exemple #20
0
        private void _calculateCloseLeasing(string leasing_id, string idcard)
        {
            cls = cls_mng.getCarLeasingById(leasing_id);

            List <Car_Leasings_Payment> list_cls_pay = cls_pay_mng.getRealPaymentInfo(leasing_id);

            double total_lost         = 0;
            double total_payment      = 0;
            double total_payment_fine = 0.00;
            string date_last_payemnt  = string.Empty;
            double payment_fine       = 0.00;
            double real_payment_fine  = 0.00;
            double interest           = 0;
            double interest_per_day   = 0;
            double day_of_cal         = 0;
            double discount           = 0;
            double next_period_no     = 1;
            double real_payment       = 0.00;
            double duplicate_period   = 0;

            for (int i = 0; i < list_cls_pay.Count; i++)
            {
                Car_Leasings_Payment cls_pay = list_cls_pay[i];

                if (string.IsNullOrEmpty(cls.Total_period_length))
                {
                    Period_No_TBx.Text = next_period_no.ToString();
                }
                else
                {
                    int period_str = Convert.ToInt32(cls.Total_period_length.Split('-')[0].Trim());
                    int period_end = Convert.ToInt32(cls.Total_period_length.Split('-')[1].Trim());

                    if (cls_pay.Period_no >= period_str && cls_pay.Period_no <= period_end)
                    {
                        total_lost += cls_pay.Period_current;
                    }
                }

                if (cls_pay.Period_no != duplicate_period)
                {
                    total_payment += cls_pay.Period_current;
                }
                else
                {
                    next_period_no += 1;
                }

                if (cls_pay.Total_payment_fine != 0)
                {
                    total_payment_fine = cls_pay.Total_payment_fine;
                }

                date_last_payemnt = cls_pay.Period_schedule;

                interest = cls_pay.Period_interst;

                if (cls_pay.Period_fine > 0 && cls_pay.Period_no != duplicate_period)
                {
                    payment_fine    += cls_pay.Period_fine;
                    duplicate_period = cls_pay.Period_no;
                }

                if (cls_pay.Real_payment_fine > 0)
                {
                    real_payment_fine += cls_pay.Real_payment_fine;
                }

                if (cls_pay.Real_payment > 0)
                {
                    real_payment += cls_pay.Real_payment;
                }
            }

            total_payment_fine = payment_fine - real_payment_fine;

            Total_payment_fine_TBx.Text = total_payment_fine <= 0 ? "0.00" : total_payment_fine.ToString("#,###.00");

            Total_period_left_TBx.Text = (total_lost - real_payment) <= 0 ? "0.00" : (total_lost - real_payment).ToString("#,###.00");

            Period_fine_TBx.Text = total_payment_fine < 0 ? "0.00" : total_payment_fine.ToString("#,###.00");

            interest_per_day = interest / 30;
            day_of_cal       = (Convert.ToDateTime(date_last_payemnt) - DateTime.Now).TotalDays;
            discount         = Math.Floor((day_of_cal * interest_per_day) / 2);

            Discount_TBx.Text = discount.ToString("#,###.00");

            Cal_Period_Payment_TBx.Text = (cls.Total_Net_leasing - real_payment).ToString("#,###.00");

            Real_Payment_TBx.Focus();

            Close_Leasing_Lbl.Visible = false;
            Cal_Status_Lbl.Visible    = true;
        }
        public Customers getCustomersLeasing(string i_Leasing_id, string i_Cust_idcard)
        {
            MySqlConnection con = MySQLConnection.connectionMySQL();

            try
            {
                con.Open();
                MySqlCommand cmd = new MySqlCommand("g_car_leasings_customers", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@i_Leasing_id", i_Leasing_id);
                cmd.Parameters.AddWithValue("@i_Cust_idcard", i_Cust_idcard);

                MySqlDataReader reader = cmd.ExecuteReader();

                Car_Leasings cls = new Car_Leasings();

                if (reader.Read())
                {
                    int    defaultNum    = 0;
                    string defaultString = "";

                    cls.Leasing_id = reader.IsDBNull(0) ? defaultString : reader.GetString(0);
                    cls.Deps_no    = reader.IsDBNull(1) ? defaultString : reader.GetString(1);
                    cls.Leasing_no = reader.IsDBNull(2) ? defaultString : reader.GetString(2);

                    cls.bs_ls_code = new Base_Leasing_Code();
                    cls.bs_ls_code.Leasing_code_id   = reader.IsDBNull(3) ? defaultNum : reader.GetInt32(3);
                    cls.bs_ls_code.Leasing_code_name = reader.IsDBNull(4) ? defaultString : reader.GetString(4);

                    cls.Leasing_date = reader.IsDBNull(5) ? defaultString : reader.GetString(5);

                    cls.bs_cpn                     = new Base_Companys();
                    cls.bs_cpn.Company_id          = reader.IsDBNull(6) ? defaultNum : reader.GetInt32(6);
                    cls.bs_cpn.Company_code        = reader.IsDBNull(7) ? defaultString : reader.GetString(7);
                    cls.bs_cpn.Company_N_name      = reader.IsDBNull(8) ? defaultString : reader.GetString(8);
                    cls.bs_cpn.Company_F_name      = reader.IsDBNull(9) ? defaultString : reader.GetString(9);
                    cls.bs_cpn.Company_tax_id      = reader.IsDBNull(10) ? defaultString : reader.GetString(10);
                    cls.bs_cpn.Company_tax_subcode = reader.IsDBNull(11) ? defaultString : reader.GetString(11);
                    cls.bs_cpn.Company_address_no  = reader.IsDBNull(12) ? defaultString : reader.GetString(12);
                    cls.bs_cpn.Company_vilage      = reader.IsDBNull(13) ? defaultString : reader.GetString(13);
                    cls.bs_cpn.Company_vilage_no   = reader.IsDBNull(14) ? defaultString : reader.GetString(14);
                    cls.bs_cpn.Company_alley       = reader.IsDBNull(15) ? defaultString : reader.GetString(15);
                    cls.bs_cpn.Company_road        = reader.IsDBNull(16) ? defaultString : reader.GetString(16);
                    cls.bs_cpn.Company_subdistrict = reader.IsDBNull(17) ? defaultString : reader.GetString(17);
                    cls.bs_cpn.Company_district    = reader.IsDBNull(18) ? defaultString : reader.GetString(18);
                    cls.bs_cpn.Company_province    = reader.IsDBNull(19) ? defaultString : reader.GetString(19);
                    cls.bs_cpn.Company_country     = reader.IsDBNull(20) ? defaultString : reader.GetString(20);
                    cls.bs_cpn.Company_zipcode     = reader.IsDBNull(21) ? defaultString : reader.GetString(21);
                    cls.bs_cpn.Company_tel         = reader.IsDBNull(22) ? defaultString : reader.GetString(22);
                    cls.bs_cpn.Company_Save_date   = reader.IsDBNull(23) ? defaultString : reader.GetString(23);

                    cls.bs_zn           = new Base_Zone_Service();
                    cls.bs_zn.Zone_id   = reader.IsDBNull(24) ? defaultNum : reader.GetInt32(24);
                    cls.bs_zn.Zone_code = reader.IsDBNull(25) ? defaultString : reader.GetString(25);
                    cls.bs_zn.Zone_name = reader.IsDBNull(26) ? defaultString : reader.GetString(26);

                    cls.bs_ct            = new Base_Courts();
                    cls.bs_ct.Court_id   = reader.IsDBNull(27) ? defaultNum : reader.GetInt32(27);
                    cls.bs_ct.Court_name = reader.IsDBNull(28) ? defaultString : reader.GetString(28);

                    cls.PeReT = reader.IsDBNull(29) ? defaultString : reader.GetString(29);

                    cls.TotalPaymentTime           = reader.IsDBNull(30) ? defaultNum : reader.GetInt32(30);
                    cls.Total_require              = reader.IsDBNull(31) ? defaultNum : reader.GetDouble(31);
                    cls.Vat_rate                   = reader.IsDBNull(32) ? defaultNum : reader.GetDouble(32);
                    cls.Interest_rate              = reader.IsDBNull(33) ? defaultNum : reader.GetDouble(33);
                    cls.Total_period               = reader.IsDBNull(34) ? defaultNum : reader.GetInt32(34);
                    cls.Total_sum                  = reader.IsDBNull(35) ? defaultNum : reader.GetDouble(35);
                    cls.Total_Interest             = reader.IsDBNull(36) ? defaultNum : reader.GetDouble(36);
                    cls.Total_Tax                  = reader.IsDBNull(37) ? defaultNum : reader.GetDouble(37);
                    cls.Total_leasing              = reader.IsDBNull(38) ? defaultNum : reader.GetDouble(38);
                    cls.Total_Net_leasing          = reader.IsDBNull(39) ? defaultNum : reader.GetDouble(39);
                    cls.Period_cal                 = reader.IsDBNull(40) ? defaultNum : reader.GetDouble(40);
                    cls.Period_interst             = reader.IsDBNull(41) ? defaultNum : reader.GetDouble(41);
                    cls.Period_tax                 = reader.IsDBNull(42) ? defaultNum : reader.GetDouble(42);
                    cls.Period_pure                = reader.IsDBNull(43) ? defaultNum : reader.GetDouble(43);
                    cls.Period_payment             = reader.IsDBNull(44) ? defaultNum : reader.GetDouble(44);
                    cls.Period_require             = reader.IsDBNull(45) ? defaultNum : reader.GetDouble(45);
                    cls.Total_period_length        = reader.IsDBNull(46) ? defaultString : reader.GetString(46);
                    cls.Total_period_lose          = reader.IsDBNull(47) ? defaultNum : reader.GetInt32(47);
                    cls.Total_period_left          = reader.IsDBNull(48) ? defaultNum : reader.GetInt32(48);
                    cls.Total_payment_left         = reader.IsDBNull(49) ? defaultNum : reader.GetDouble(49);
                    cls.Payment_schedule           = reader.IsDBNull(50) ? defaultNum : reader.GetInt32(50);
                    cls.First_payment_date         = reader.IsDBNull(51) ? defaultString : reader.GetString(51);
                    cls.Car_register_date          = reader.IsDBNull(52) ? defaultString : reader.GetString(52);
                    cls.Car_license_plate          = reader.IsDBNull(53) ? defaultString : reader.GetString(53);
                    cls.Car_license_plate_province = reader.IsDBNull(54) ? defaultString : reader.GetString(54);
                    cls.Car_type                   = reader.IsDBNull(55) ? defaultString : reader.GetString(55);
                    cls.Car_feature                = reader.IsDBNull(56) ? defaultString : reader.GetString(56);

                    cls.bs_cbrn = new Base_Car_Brands();
                    cls.bs_cbrn.car_brand_id       = reader.IsDBNull(57) ? defaultNum : reader.GetInt32(57);
                    cls.bs_cbrn.car_brand_name_eng = reader.IsDBNull(58) ? defaultString : reader.GetString(58);
                    cls.bs_cbrn.car_brand_name_th  = reader.IsDBNull(59) ? defaultString : reader.GetString(59);

                    cls.Car_model                 = reader.IsDBNull(60) ? defaultString : reader.GetString(60);
                    cls.Car_year                  = reader.IsDBNull(61) ? defaultString : reader.GetString(61);
                    cls.Car_color                 = reader.IsDBNull(62) ? defaultString : reader.GetString(62);
                    cls.Car_engine_no             = reader.IsDBNull(63) ? defaultString : reader.GetString(63);
                    cls.Car_engine_no_at          = reader.IsDBNull(64) ? defaultString : reader.GetString(64);
                    cls.Car_engine_brand          = reader.IsDBNull(65) ? defaultString : reader.GetString(65);
                    cls.Car_chassis_no            = reader.IsDBNull(66) ? defaultString : reader.GetString(66);
                    cls.Car_chassis_no_at         = reader.IsDBNull(67) ? defaultString : reader.GetString(67);
                    cls.Car_fual_type             = reader.IsDBNull(68) ? defaultString : reader.GetString(68);
                    cls.Car_gas_No                = reader.IsDBNull(69) ? defaultString : reader.GetString(69);
                    cls.Car_used_id               = reader.IsDBNull(70) ? defaultNum : reader.GetInt32(70);
                    cls.Car_distance              = reader.IsDBNull(71) ? defaultNum : reader.GetDouble(71);
                    cls.Car_next_register_date    = reader.IsDBNull(72) ? defaultString : reader.GetString(72);
                    cls.Car_tax_value             = reader.IsDBNull(73) ? defaultNum : reader.GetDouble(73);
                    cls.Car_credits               = reader.IsDBNull(74) ? defaultString : reader.GetString(74);
                    cls.Car_agent                 = reader.IsDBNull(75) ? defaultString : reader.GetString(75);
                    cls.Car_old_owner             = reader.IsDBNull(76) ? defaultString : reader.GetString(76);
                    cls.Car_old_owner_idcard      = reader.IsDBNull(77) ? defaultString : reader.GetString(77);
                    cls.Car_old_owner_b_date      = reader.IsDBNull(78) ? defaultString : reader.GetString(78);
                    cls.Car_old_owner_address_no  = reader.IsDBNull(79) ? defaultString : reader.GetString(79);
                    cls.Car_old_owner_vilage      = reader.IsDBNull(80) ? defaultString : reader.GetString(80);
                    cls.Car_old_owner_vilage_no   = reader.IsDBNull(81) ? defaultString : reader.GetString(81);
                    cls.Car_old_owner_alley       = reader.IsDBNull(82) ? defaultString : reader.GetString(82);
                    cls.Car_old_owner_road        = reader.IsDBNull(83) ? defaultString : reader.GetString(83);
                    cls.Car_old_owner_subdistrict = reader.IsDBNull(84) ? defaultString : reader.GetString(84);
                    cls.Car_old_owner_district    = reader.IsDBNull(85) ? defaultString : reader.GetString(85);
                    cls.Car_old_owner_province    = reader.IsDBNull(86) ? defaultString : reader.GetString(86);
                    cls.Car_old_owner_contry      = reader.IsDBNull(87) ? defaultString : reader.GetString(87);
                    cls.Car_old_owner_zipcode     = reader.IsDBNull(88) ? defaultString : reader.GetString(88);

                    cls.tent_car             = new Base_Tents_Car();
                    cls.tent_car.Tent_car_id = reader.IsDBNull(89) ? defaultNum : reader.GetInt32(89);
                    cls.tent_car.Tent_name   = reader.IsDBNull(90) ? defaultString : reader.GetString(90);
                    cls.tent_car.Tent_local  = reader.IsDBNull(91) ? defaultString : reader.GetString(91);

                    cls.Cheque_receiver     = reader.IsDBNull(92) ? defaultString : reader.GetString(92);
                    cls.Cheque_bank         = reader.IsDBNull(93) ? defaultString : reader.GetString(93);
                    cls.Cheque_bank_branch  = reader.IsDBNull(94) ? defaultString : reader.GetString(94);
                    cls.Cheque_number       = reader.IsDBNull(95) ? defaultString : reader.GetString(95);
                    cls.Cheque_sum          = reader.IsDBNull(96) ? defaultNum : reader.GetDouble(96);
                    cls.Cheque_receive_date = reader.IsDBNull(97) ? defaultString : reader.GetString(97);
                    cls.Guarantee           = reader.IsDBNull(98) ? defaultString : reader.GetString(98);

                    cls.bs_ls_stt = new Base_Leasing_Status();
                    cls.bs_ls_stt.Contract_Status_id   = reader.IsDBNull(99) ? defaultNum : reader.GetInt32(99);
                    cls.bs_ls_stt.Contract_Status_name = reader.IsDBNull(100) ? defaultString : reader.GetString(100);

                    cls.Leasing_Comment    = reader.IsDBNull(101) ? defaultString : reader.GetString(101);
                    cls.Leasings_save_date = reader.IsDBNull(102) ? defaultString : reader.GetString(102);

                    cls.ctm                     = new Customers();
                    cls.ctm.Cust_id             = reader.IsDBNull(103) ? defaultString : reader.GetString(103);
                    cls.ctm.Cust_Idcard         = reader.IsDBNull(104) ? defaultString : reader.GetString(104);
                    cls.ctm.Cust_Fname          = reader.IsDBNull(105) ? defaultString : reader.GetString(105);
                    cls.ctm.Cust_LName          = reader.IsDBNull(106) ? defaultString : reader.GetString(106);
                    cls.ctm.Cust_B_date         = reader.IsDBNull(107) ? defaultString : reader.GetString(107);
                    cls.ctm.Cust_Age            = reader.IsDBNull(108) ? defaultNum : reader.GetInt32(108);
                    cls.ctm.Cust_Idcard_without = reader.IsDBNull(109) ? defaultString : reader.GetString(109);
                    cls.ctm.Cust_Idcard_start   = reader.IsDBNull(110) ? defaultString : reader.GetString(110);
                    cls.ctm.Cust_Idcard_expire  = reader.IsDBNull(111) ? defaultString : reader.GetString(111);

                    cls.ctm.ctm_ntnlt = new Base_Nationalitys();
                    cls.ctm.ctm_ntnlt.Nationality_id       = reader.IsDBNull(112) ? defaultNum : reader.GetInt32(112);
                    cls.ctm.ctm_ntnlt.Nationality_name_ENG = reader.IsDBNull(113) ? defaultString : reader.GetString(113);
                    cls.ctm.ctm_ntnlt.Nationality_name_TH  = reader.IsDBNull(114) ? defaultString : reader.GetString(114);

                    cls.ctm.ctm_org                 = new Base_Origins();
                    cls.ctm.ctm_org.Origin_id       = reader.IsDBNull(115) ? defaultNum : reader.GetInt32(115);
                    cls.ctm.ctm_org.Origin_name_ENG = reader.IsDBNull(116) ? defaultString : reader.GetString(116);
                    cls.ctm.ctm_org.Origin_name_TH  = reader.IsDBNull(117) ? defaultString : reader.GetString(117);

                    cls.ctm.Cust_Tel   = reader.IsDBNull(118) ? defaultString : reader.GetString(118);
                    cls.ctm.Cust_Email = reader.IsDBNull(119) ? defaultString : reader.GetString(119);

                    cls.ctm.ctm_pstt = new Base_Person_Status();
                    cls.ctm.ctm_pstt.person_status_id   = reader.IsDBNull(120) ? defaultNum : reader.GetInt32(120);
                    cls.ctm.ctm_pstt.person_status_name = reader.IsDBNull(121) ? defaultString : reader.GetString(121);

                    cls.ctm.Cust_Marry_idcard = reader.IsDBNull(122) ? defaultString : reader.GetString(122);
                    cls.ctm.Cust_Marry_Fname  = reader.IsDBNull(123) ? defaultString : reader.GetString(123);
                    cls.ctm.Cust_Marry_Lname  = reader.IsDBNull(124) ? defaultString : reader.GetString(124);

                    cls.ctm.ctm_marry_ntnlt = new Base_Nationalitys();
                    cls.ctm.ctm_marry_ntnlt.Nationality_id       = reader.IsDBNull(125) ? defaultNum : reader.GetInt32(125);
                    cls.ctm.ctm_marry_ntnlt.Nationality_name_ENG = reader.IsDBNull(126) ? defaultString : reader.GetString(126);
                    cls.ctm.ctm_marry_ntnlt.Nationality_name_TH  = reader.IsDBNull(127) ? defaultString : reader.GetString(127);

                    cls.ctm.ctm_marry_org                 = new Base_Origins();
                    cls.ctm.ctm_marry_org.Origin_id       = reader.IsDBNull(128) ? defaultNum : reader.GetInt32(128);
                    cls.ctm.ctm_marry_org.Origin_name_ENG = reader.IsDBNull(129) ? defaultString : reader.GetString(129);
                    cls.ctm.ctm_marry_org.Origin_name_TH  = reader.IsDBNull(130) ? defaultString : reader.GetString(130);

                    cls.ctm.Cust_Marry_Address_no      = reader.IsDBNull(131) ? defaultString : reader.GetString(131);
                    cls.ctm.Cust_Marry_vilage          = reader.IsDBNull(132) ? defaultString : reader.GetString(132);
                    cls.ctm.Cust_Marry_vilage_no       = reader.IsDBNull(133) ? defaultString : reader.GetString(133);
                    cls.ctm.Cust_Marry_alley           = reader.IsDBNull(134) ? defaultString : reader.GetString(134);
                    cls.ctm.Cust_Marry_road            = reader.IsDBNull(135) ? defaultString : reader.GetString(135);
                    cls.ctm.Cust_Marry_subdistrict     = reader.IsDBNull(136) ? defaultString : reader.GetString(136);
                    cls.ctm.Cust_Marry_district        = reader.IsDBNull(137) ? defaultString : reader.GetString(137);
                    cls.ctm.Cust_Marry_province        = reader.IsDBNull(138) ? defaultString : reader.GetString(138);
                    cls.ctm.Cust_Marry_country         = reader.IsDBNull(139) ? defaultString : reader.GetString(139);
                    cls.ctm.Cust_Marry_zipcode         = reader.IsDBNull(140) ? defaultString : reader.GetString(140);
                    cls.ctm.Cust_Marry_tel             = reader.IsDBNull(141) ? defaultString : reader.GetString(141);
                    cls.ctm.Cust_Marry_email           = reader.IsDBNull(142) ? defaultString : reader.GetString(142);
                    cls.ctm.Cust_Marry_job             = reader.IsDBNull(143) ? defaultString : reader.GetString(143);
                    cls.ctm.Cust_Marry_job_position    = reader.IsDBNull(144) ? defaultString : reader.GetString(144);
                    cls.ctm.Cust_Marry_job_long        = reader.IsDBNull(145) ? defaultNum : reader.GetInt32(145);
                    cls.ctm.Cust_Marry_job_salary      = reader.IsDBNull(146) ? defaultNum : reader.GetDouble(146);
                    cls.ctm.Cust_Marry_job_local_name  = reader.IsDBNull(147) ? defaultString : reader.GetString(147);
                    cls.ctm.Cust_Marry_job_address_no  = reader.IsDBNull(148) ? defaultString : reader.GetString(148);
                    cls.ctm.Cust_Marry_job_vilage      = reader.IsDBNull(149) ? defaultString : reader.GetString(149);
                    cls.ctm.Cust_Marry_job_vilage_no   = reader.IsDBNull(150) ? defaultString : reader.GetString(150);
                    cls.ctm.Cust_Marry_job_alley       = reader.IsDBNull(151) ? defaultString : reader.GetString(151);
                    cls.ctm.Cust_Marry_job_road        = reader.IsDBNull(152) ? defaultString : reader.GetString(152);
                    cls.ctm.Cust_Marry_job_subdistrict = reader.IsDBNull(153) ? defaultString : reader.GetString(153);
                    cls.ctm.Cust_Marry_job_district    = reader.IsDBNull(154) ? defaultString : reader.GetString(154);
                    cls.ctm.Cust_Marry_job_province    = reader.IsDBNull(155) ? defaultString : reader.GetString(155);
                    cls.ctm.Cust_Marry_job_country     = reader.IsDBNull(156) ? defaultString : reader.GetString(156);
                    cls.ctm.Cust_Marry_job_zipcode     = reader.IsDBNull(157) ? defaultString : reader.GetString(157);
                    cls.ctm.Cust_Marry_job_tel         = reader.IsDBNull(158) ? defaultString : reader.GetString(158);

                    cls.ctm.Cust_Job             = reader.IsDBNull(159) ? defaultString : reader.GetString(159);
                    cls.ctm.Cust_Job_position    = reader.IsDBNull(160) ? defaultString : reader.GetString(160);
                    cls.ctm.Cust_Job_long        = reader.IsDBNull(161) ? defaultNum : reader.GetInt32(161);
                    cls.ctm.Cust_Job_salary      = reader.IsDBNull(162) ? defaultNum : reader.GetDouble(162);
                    cls.ctm.Cust_Job_local_name  = reader.IsDBNull(163) ? defaultString : reader.GetString(163);
                    cls.ctm.Cust_Job_address_no  = reader.IsDBNull(164) ? defaultString : reader.GetString(164);
                    cls.ctm.Cust_Job_vilage      = reader.IsDBNull(165) ? defaultString : reader.GetString(165);
                    cls.ctm.Cust_Job_vilage_no   = reader.IsDBNull(166) ? defaultString : reader.GetString(166);
                    cls.ctm.Cust_Job_alley       = reader.IsDBNull(167) ? defaultString : reader.GetString(167);
                    cls.ctm.Cust_Job_road        = reader.IsDBNull(168) ? defaultString : reader.GetString(168);
                    cls.ctm.Cust_Job_subdistrict = reader.IsDBNull(169) ? defaultString : reader.GetString(169);
                    cls.ctm.Cust_Job_district    = reader.IsDBNull(170) ? defaultString : reader.GetString(170);
                    cls.ctm.Cust_Job_province    = reader.IsDBNull(171) ? defaultString : reader.GetString(171);
                    cls.ctm.Cust_Job_country     = reader.IsDBNull(172) ? defaultString : reader.GetString(172);
                    cls.ctm.Cust_Job_zipcode     = reader.IsDBNull(173) ? defaultString : reader.GetString(173);
                    cls.ctm.Cust_Job_tel         = reader.IsDBNull(174) ? defaultString : reader.GetString(174);
                    cls.ctm.Cust_Job_email       = reader.IsDBNull(175) ? defaultString : reader.GetString(175);

                    cls.ctm.Cust_Home_address_no    = reader.IsDBNull(176) ? defaultString : reader.GetString(176);
                    cls.ctm.Cust_Home_vilage        = reader.IsDBNull(177) ? defaultString : reader.GetString(177);
                    cls.ctm.Cust_Home_vilage_no     = reader.IsDBNull(178) ? defaultString : reader.GetString(178);
                    cls.ctm.Cust_Home_alley         = reader.IsDBNull(179) ? defaultString : reader.GetString(179);
                    cls.ctm.Cust_Home_road          = reader.IsDBNull(180) ? defaultString : reader.GetString(180);
                    cls.ctm.Cust_Home_subdistrict   = reader.IsDBNull(181) ? defaultString : reader.GetString(181);
                    cls.ctm.Cust_Home_district      = reader.IsDBNull(182) ? defaultString : reader.GetString(182);
                    cls.ctm.Cust_Home_province      = reader.IsDBNull(183) ? defaultString : reader.GetString(183);
                    cls.ctm.Cust_Home_country       = reader.IsDBNull(184) ? defaultString : reader.GetString(184);
                    cls.ctm.Cust_Home_zipcode       = reader.IsDBNull(185) ? defaultString : reader.GetString(185);
                    cls.ctm.Cust_Home_tel           = reader.IsDBNull(186) ? defaultString : reader.GetString(186);
                    cls.ctm.Cust_Home_GPS_Latitude  = reader.IsDBNull(187) ? defaultString : reader.GetString(187);
                    cls.ctm.Cust_Home_GPS_Longitude = reader.IsDBNull(188) ? defaultString : reader.GetString(188);

                    cls.ctm.ctm_home_stt = new Base_Home_Status();
                    cls.ctm.ctm_home_stt.Home_status_id   = reader.IsDBNull(189) ? defaultNum : reader.GetInt32(189);
                    cls.ctm.ctm_home_stt.Home_status_name = reader.IsDBNull(190) ? defaultString : reader.GetString(190);

                    cls.ctm.Cust_Idcard_address_no  = reader.IsDBNull(191) ? defaultString : reader.GetString(191);
                    cls.ctm.Cust_Idcard_vilage      = reader.IsDBNull(192) ? defaultString : reader.GetString(192);
                    cls.ctm.Cust_Idcard_vilage_no   = reader.IsDBNull(193) ? defaultString : reader.GetString(193);
                    cls.ctm.Cust_Idcard_alley       = reader.IsDBNull(194) ? defaultString : reader.GetString(194);
                    cls.ctm.Cust_Idcard_road        = reader.IsDBNull(195) ? defaultString : reader.GetString(195);
                    cls.ctm.Cust_Idcard_subdistrict = reader.IsDBNull(196) ? defaultString : reader.GetString(196);
                    cls.ctm.Cust_Idcard_district    = reader.IsDBNull(197) ? defaultString : reader.GetString(197);
                    cls.ctm.Cust_Idcard_province    = reader.IsDBNull(198) ? defaultString : reader.GetString(198);
                    cls.ctm.Cust_Idcard_country     = reader.IsDBNull(199) ? defaultString : reader.GetString(199);
                    cls.ctm.Cust_Idcard_zipcode     = reader.IsDBNull(200) ? defaultString : reader.GetString(200);
                    cls.ctm.Cust_Idcard_tel         = reader.IsDBNull(201) ? defaultString : reader.GetString(201);

                    cls.ctm.ctm_idcard_stt = new Base_Home_Status();
                    cls.ctm.ctm_idcard_stt.Home_status_id   = reader.IsDBNull(202) ? defaultNum : reader.GetInt32(202);
                    cls.ctm.ctm_idcard_stt.Home_status_name = reader.IsDBNull(203) ? defaultString : reader.GetString(203);

                    cls.ctm.Cust_Current_address_no  = reader.IsDBNull(204) ? defaultString : reader.GetString(204);
                    cls.ctm.Cust_Current_vilage      = reader.IsDBNull(205) ? defaultString : reader.GetString(205);
                    cls.ctm.Cust_Current_vilage_no   = reader.IsDBNull(206) ? defaultString : reader.GetString(206);
                    cls.ctm.Cust_Current_alley       = reader.IsDBNull(207) ? defaultString : reader.GetString(207);
                    cls.ctm.Cust_Current_road        = reader.IsDBNull(208) ? defaultString : reader.GetString(208);
                    cls.ctm.Cust_Current_subdistrict = reader.IsDBNull(209) ? defaultString : reader.GetString(209);
                    cls.ctm.Cust_Current_district    = reader.IsDBNull(210) ? defaultString : reader.GetString(210);
                    cls.ctm.Cust_Current_province    = reader.IsDBNull(211) ? defaultString : reader.GetString(211);
                    cls.ctm.Cust_Current_country     = reader.IsDBNull(212) ? defaultString : reader.GetString(212);
                    cls.ctm.Cust_Current_zipcode     = reader.IsDBNull(213) ? defaultString : reader.GetString(213);
                    cls.ctm.Cust_Current_tel         = reader.IsDBNull(214) ? defaultString : reader.GetString(214);

                    cls.ctm.ctm_current_stt = new Base_Home_Status();
                    cls.ctm.ctm_current_stt.Home_status_id   = reader.IsDBNull(215) ? defaultNum : reader.GetInt32(215);
                    cls.ctm.ctm_current_stt.Home_status_name = reader.IsDBNull(216) ? defaultString : reader.GetString(216);

                    cls.ctm.Cust_save_date = reader.IsDBNull(217) ? defaultString : reader.GetString(217);
                }

                return(cls.ctm);
            }
            catch (MySqlException ex)
            {
                error = "MysqlException ==> Managers_Leasings --> Car_Leasings_Customer_Manager --> getCustomersLeasing() ";
                Log_Error._writeErrorFile(error, ex);
                return(null);
            }
            catch (Exception ex)
            {
                error = "Exception ==> Managers_Leasings --> Car_Leasings_Customer_Manager --> getCustomersLeasing() ";
                Log_Error._writeErrorFile(error, ex);
                return(null);
            }
            finally
            {
                con.Close();
            }
        }
        protected void Save_Btn_Click(object sender, EventArgs e)
        {
            string[] code       = Request.Params["code"].Split('U');
            string   leasing_id = code[1];
            string   bill_no    = code[2];
            string   idcard     = (string)Session["ctm_leasing_payment"];

            cls = cls_mng.getCarLeasingById(leasing_id);

            double total_payment_left = string.IsNullOrEmpty(Total_payment_left_TBx.Text) ? 0 : Convert.ToDouble(Total_payment_left_TBx.Text);
            double period_fine        = string.IsNullOrEmpty(Total_payment_fine_TBx.Text) ? 0 : Convert.ToDouble(Total_payment_fine_TBx.Text);

            double old_period_fee   = string.IsNullOrEmpty(Old_Period_fee_TBx.Text) ? 0.00 : Convert.ToDouble(Old_Period_fee_TBx.Text);
            double old_period_track = string.IsNullOrEmpty(Old_Period_track_TBx.Text) ? 0.00 : Convert.ToDouble(Old_Period_track_TBx.Text);
            double old_payment      = string.IsNullOrEmpty(Old_Real_Payment_TBx.Text) ? 0 : Convert.ToDouble(Old_Real_Payment_TBx.Text);
            double old_payment_fine = string.IsNullOrEmpty(Old_Real_Payment_Fine_TBx.Text) ? 0 : Convert.ToDouble(Old_Real_Payment_Fine_TBx.Text);
            double old_discount     = string.IsNullOrEmpty(Old_Real_Discount_TBx.Text) ? 0 : Convert.ToDouble(Old_Real_Discount_TBx.Text);

            double real_period_fee   = string.IsNullOrEmpty(Period_fee_TBx.Text) ? 0.00 : Convert.ToDouble(Period_fee_TBx.Text);
            double real_period_track = string.IsNullOrEmpty(Period_track_TBx.Text) ? 0.00 : Convert.ToDouble(Period_track_TBx.Text);
            double real_payment      = string.IsNullOrEmpty(Real_Payment_TBx.Text) ? 0 : Convert.ToDouble(Real_Payment_TBx.Text);
            double real_payment_fine = string.IsNullOrEmpty(Real_Payment_Fine_TBx.Text) ? 0 : Convert.ToDouble(Real_Payment_Fine_TBx.Text);
            double real_discount     = string.IsNullOrEmpty(Real_Discount_TBx.Text) ? 0 : Convert.ToDouble(Real_Discount_TBx.Text);

            cls_pay.Leasing_id         = leasing_id;
            cls_pay.Period_fee         = real_period_fee;
            cls_pay.Period_track       = real_period_track;
            cls_pay.Total_payment_fine = real_payment_fine;
            cls_pay.Discount           = real_discount;
            cls_pay.Real_payment       = real_payment;
            cls_pay.Real_payment_date  = string.IsNullOrEmpty(Payment_Date_TBx.Text) ? DateTimeUtility._dateNOWForServer() : DateTimeUtility.convertDateToMYSQL(Payment_Date_TBx.Text);
            cls_pay.Bill_no_manual_ref = string.IsNullOrEmpty(Bill_No_Manual_Ref_TBx.Text) ? "" : Bill_No_Manual_Ref_TBx.Text;

            Base_Companys package_login = new Base_Companys();
            Account_Login acc_lgn       = new Account_Login();

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

            cls_pay.acc_lgn            = new Account_Login();
            cls_pay.acc_lgn.Account_id = acc_lgn.Account_id;

            cls_pay.bs_cpn            = new Base_Companys();
            cls_pay.bs_cpn.Company_id = (int)Session["old_company"];

            if (total_payment_left == 0)
            {
                if (real_payment <= 0)
                {
                    Note_Lbl.Text = "*** ระบุยอดชำระมากกว่า : 0.00 บาท ***";

                    Real_Payment_TBx.Focus();
                }
                else if (real_payment > old_payment)
                {
                    Note_Lbl.Text = "*** ยอดชำระเกินกว่ายอดเดิม :  " + old_payment.ToString("#,###.00") + " บาท ***";

                    Real_Payment_TBx.Focus();
                }

                /* else if (period_fine == 0 && old_payment_fine != 0)
                 * {
                 *   Note_Lbl.Text = "*** ระบุยอดชำระค่าปรับ :  " + old_payment_fine.ToString("#,###.00") + " บาท ***";
                 *
                 *   Real_Payment_Fine_TBx.Focus();
                 * }*/
                else if (old_discount != 0)
                {
                    Note_Lbl.Text = "*** ระบุยอดส่วนลด :  " + old_discount.ToString("#,###.00") + " บาท ***";

                    Real_Discount_TBx.Focus();
                }
                else
                {
                    Note_Lbl.Text = "";

                    if (cls_pay_mng.editPayment(cls_pay, bill_no))
                    {
                        /// Acticity Logs System
                        ///

                        string message = Messages_Logs._messageLogsNormal(acc_lgn.Account_F_name, " แก้ไขข้อมูลการจ่ายเงิน ในสัญญา : " + cls.Leasing_no + " เลขที่ฝาก : " + cls.Deps_no + " เลขที่ใบเสร็จ : " + bill_no + " จำนวนเงิน [ค่างวด] [ค่าปรับ] [ส่วนลด] : [" + real_payment + "] [" + period_fine + "] [" + real_discount + "] ", 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

                        string ogn_code = CryptographyCode.GenerateSHA512String(leasing_id);

                        Session.Remove("old_company");

                        Response.Redirect("/Form_Leasings/Leasing_Payment?code=" + CryptographyCode.EncodeTOAddressBar(ogn_code, leasing_id, idcard));
                    }
                    else
                    {
                        Alert_Danger_Panel.Visible   = true;
                        alert_header_danger_Lbl.Text = "แจ้งเตือน!!";
                        alert_danger_Lbl.Text        = "กรุณาตรวจสอบ ข้อมูลอีกครั้ง";

                        Alert_Danger_Panel.Focus();
                    }
                }
            }
            else
            {
                if (real_payment <= 0)
                {
                    Note_Lbl.Text = "*** ระบุยอดชำระมากกว่า : 0.00 บาท ***";

                    Real_Payment_TBx.Focus();
                }

                /*else if(real_payment > total_payment_left && real_payment > 0)
                 * {
                 *  Note_Lbl.Text = "*** ยอดชำระเกินกว่ายอดคงค้าง :  " + total_payment_left.ToString("#,###.00") + " บาท ***";
                 *
                 *  Real_Payment_TBx.Focus();
                 * }*/
                else if (old_discount == 0 && real_discount != 0)
                {
                    Note_Lbl.Text = "*** ไม่มียอดส่วนลดกรุณาใส่ 0 ในช่องส่วนลด ***";

                    Real_Discount_TBx.Focus();
                }
                else
                {
                    Note_Lbl.Text = "";

                    if (cls_pay_mng.editPayment(cls_pay, bill_no))
                    {
                        /// Acticity Logs System
                        ///

                        string message = Messages_Logs._messageLogsNormal(acc_lgn.Account_F_name, " แก้ไขข้อมูลการจ่ายเงิน ในสัญญา : " + cls.Leasing_no + " เลขที่ฝาก : " + cls.Deps_no + " เลขที่ใบเสร็จ : " + bill_no + " จำนวนเงิน [ค่างวด] [ค่าปรับ] [ส่วนลด] : [" + real_payment + "] [" + period_fine + "] [" + real_discount + "] ", 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

                        string ogn_code = CryptographyCode.GenerateSHA512String(leasing_id);

                        Session.Remove("old_company");

                        Response.Redirect("/Form_Leasings/Leasing_Payment?code=" + CryptographyCode.EncodeTOAddressBar(ogn_code, leasing_id, idcard));
                    }
                    else
                    {
                        Alert_Danger_Panel.Visible   = true;
                        alert_header_danger_Lbl.Text = "แจ้งเตือน!!";
                        alert_danger_Lbl.Text        = "กรุณาตรวจสอบ ข้อมูลอีกครั้ง";

                        Alert_Danger_Panel.Focus();
                    }
                }
            }
        }
        private void _loadLeasingDetails(string leasing_id, string idcard, string bill_no)
        {
            cls = cls_mng.getCarLeasingById(leasing_id);

            Leasing_Date_TBx.Text = DateTimeUtility.convertDateToPageRealServer(cls.Leasing_date);
            Deps_No_TBx.Text      = cls.Deps_no;
            Leasing_No_TBx.Text   = cls.Leasing_no;

            Leasing_Comments_Lbl.Text = cls.Leasing_Comment;

            bs_cpn = bs_cpn_mng.getCompanysById(cls.bs_cpn.Company_id.ToString());

            Company_N_Name_TBx.Text = bs_cpn.Company_N_name;
            Company_F_Name_TBx.Text = bs_cpn.Company_F_name;

            bs_zn = bs_zn_mng.getZoneById(cls.bs_zn.Zone_id);

            Zone_Name_TBx.Text = bs_zn.Zone_code + " " + bs_zn.Zone_name;

            ctm = cls_ctm_mng.getCustomersLeasing(leasing_id, idcard);

            if (ctm != null)
            {
                Customer_Name_TBx.Text   = ctm.Cust_Fname + " " + ctm.Cust_LName;
                Customer_Idcard_TBx.Text = ctm.Cust_Idcard.Length == 13 ? ctm.Cust_Idcard.Substring(0, 1) + "-" + ctm.Cust_Idcard.Substring(1, 4) + "-" + ctm.Cust_Idcard.Substring(5, 5) + "-" + ctm.Cust_Idcard.Substring(10, 2) + "-" + ctm.Cust_Idcard.Substring(12) : ctm.Cust_Idcard;
                //Customer_B_Date_TBx.Text = DateTimeUtility.convertDateToPage(ctm.Cust_B_date);
                //Customer_Age_TBx.Text = ctm.Cust_Age.ToString();

                Customer_H_Address_TBx.Text  = string.IsNullOrEmpty(ctm.Cust_Home_address_no) ? "" : ctm.Cust_Home_address_no;
                Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_vilage_no) ? "" : ctm.Cust_Home_vilage_no.IndexOf('.') >= 1 ? ctm.Cust_Home_vilage_no.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_vilage_no : "";
                Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_vilage) ? "" : ctm.Cust_Home_vilage.IndexOf('.') >= 1 ? ctm.Cust_Home_vilage.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_vilage : "";
                Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_alley) ? "" : ctm.Cust_Home_alley.IndexOf('.') >= 1 ? ctm.Cust_Home_alley.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_alley : "";
                Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_road) ? "" : ctm.Cust_Home_road.IndexOf('.') >= 1 ? ctm.Cust_Home_road.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_road : "";
                Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_subdistrict) ? "" : ctm.Cust_Home_subdistrict.IndexOf('.') >= 1 ? ctm.Cust_Home_subdistrict.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_subdistrict : "";
                Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_district) ? "" : ctm.Cust_Home_district.IndexOf('.') >= 1 ? ctm.Cust_Home_district.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_district : "";
                Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_province) ? "" : ctm.Cust_Home_province.IndexOf('.') >= 1 ? ctm.Cust_Home_province.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_province : "";

                Customer_C_Address_TBx.Text  = string.IsNullOrEmpty(ctm.Cust_Current_address_no) ? "" : ctm.Cust_Current_address_no;
                Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_vilage_no) ? "" : ctm.Cust_Current_vilage_no.IndexOf('.') >= 1 ? ctm.Cust_Current_vilage_no.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_vilage_no : "";
                Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_vilage) ? "" : ctm.Cust_Current_vilage.IndexOf('.') >= 1 ? ctm.Cust_Current_vilage.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_vilage : "";
                Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_alley) ? "" : ctm.Cust_Current_alley.IndexOf('.') >= 1 ? ctm.Cust_Current_alley.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_alley : "";
                Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_road) ? "" : ctm.Cust_Current_road.IndexOf('.') >= 1 ? ctm.Cust_Current_road.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_road : "";
                Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_subdistrict) ? "" : ctm.Cust_Current_subdistrict.IndexOf('.') >= 1 ? ctm.Cust_Current_subdistrict.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_subdistrict : "";
                Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_district) ? "" : ctm.Cust_Current_district.IndexOf('.') >= 1 ? ctm.Cust_Current_district.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_district : "";
                Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_province) ? "" : ctm.Cust_Current_province.IndexOf('.') >= 1 ? ctm.Cust_Current_province.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_province : "";
            }

            Car_Type_TBx.Text = cls.Car_type;

            bs_cbrn = cbrn_mng.getCarBrandById(cls.bs_cbrn.car_brand_id);

            if (bs_cbrn != null)
            {
                Car_Brand_TBx.Text = bs_cbrn.car_brand_name_th + " ( " + bs_cbrn.car_brand_name_eng + " )";
            }

            Car_Plate_TBx.Text = cls.Car_license_plate + " " + cls.Car_license_plate_province;

            Car_Chassis_No_TBx.Text = cls.Car_chassis_no;
            Car_Engine_No_TBx.Text  = cls.Car_engine_no;

            cag_com = cag_mng.getAgentCommission("", leasing_id);

            Agent_Commission_TBx.Text = cag_com.Agent_commission.ToString("#,###.00");

            Finance_Cost_TBx.Text       = cls.Total_require.ToString("#,###.00");
            Finance_Value_TBx.Text      = cls.Total_sum.ToString("#,###.00");
            Leasing_Cost_TBx.Text       = cls.Total_Net_leasing.ToString("#,###.00");
            Period_Amount_TBx.Text      = cls.Total_period.ToString();
            Period_Payment_TBx.Text     = cls.Period_payment.ToString("#,###.00");
            Payment_Schedule_TBx.Text   = cls.Payment_schedule.ToString();
            Frist_Payment_Date_TBx.Text = DateTimeUtility.convertDateToPageRealServer(cls.First_payment_date);

            Bill_No_TBx.Text = bill_no;

            Period_fee_TBx.Text   = "0.00";
            Period_track_TBx.Text = "0.00";

            List <Car_Leasings_Payment> list_cls_pay = cls_pay_mng.getRealPaymentInfo(leasing_id);

            double total_payment_left = 0.00;
            double total_payment_fine = 0.00;

            double total_fee              = 0.00;
            double total_track            = 0.00;
            double total_real_payment     = 0.00;
            double total_rea_payment_fine = 0.00;
            double total_discount         = 0.00;

            for (int i = 0; i < list_cls_pay.Count; i++)
            {
                Car_Leasings_Payment cls_pay = list_cls_pay[i];

                if (cls_pay.Bill_no == bill_no)
                {
                    Payment_Date_TBx.Text = DateTimeUtility.convertDateToPageRealServer(cls_pay.Real_payment_date);

                    total_fee              += cls_pay.Period_fee;
                    total_track            += cls_pay.Period_track;
                    total_real_payment     += cls_pay.Real_payment;
                    total_rea_payment_fine += cls_pay.Real_payment_fine;
                    total_discount         += cls_pay.Discount;

                    total_payment_left = cls_pay.Total_payment_left;
                    total_payment_fine = cls_pay.Total_payment_fine;

                    Bill_No_Manual_Ref_TBx.Text = cls_pay.Bill_no_manual_ref;

                    Session["old_company"] = cls_pay.bs_cpn.Company_id;
                }
            }

            Total_payment_left_TBx.Text = total_payment_left.ToString("#,###.00");
            Total_payment_fine_TBx.Text = total_payment_fine.ToString("#,###.00");

            Old_Period_fee_TBx.Text        = total_fee.ToString("#,###.00");
            Old_Period_track_TBx.Text      = total_track.ToString("#,###.00");
            Old_Real_Payment_TBx.Text      = total_real_payment.ToString("#,###.00");
            Old_Real_Payment_Fine_TBx.Text = total_rea_payment_fine.ToString("#,###.00");
            Old_Real_Discount_TBx.Text     = total_discount.ToString("#,###.00");

            Session["list_cls_pay"] = list_cls_pay;

            Real_Payment_TBx.Focus();
        }
        private void _loadReport()
        {
            cls     = (Car_Leasings)Session["Leasings"];
            cls.ctm = new Customers();
            cls.ctm = (Customers)Session["Customer_Leasing"];

            MySqlConnection con_cls   = MySQLConnection.connectionMySQL();
            MySqlConnection con_ctm   = MySQLConnection.connectionMySQL();
            MySqlConnection con_grt_1 = MySQLConnection.connectionMySQL();
            MySqlConnection con_grt_2 = MySQLConnection.connectionMySQL();
            MySqlConnection con_grt_3 = MySQLConnection.connectionMySQL();
            MySqlConnection con_grt_4 = MySQLConnection.connectionMySQL();
            MySqlConnection con_grt_5 = MySQLConnection.connectionMySQL();
            MySqlConnection con_cpn   = MySQLConnection.connectionMySQL();

            try
            {
                con_cls.Open();
                MySqlCommand cmd_cls = new MySqlCommand("rpt_leasings", con_cls);
                cmd_cls.CommandType = CommandType.StoredProcedure;
                cmd_cls.Parameters.AddWithValue("@i_Leasing_id", cls.Leasing_id);
                MySqlDataReader reader_cls = cmd_cls.ExecuteReader();

                con_ctm.Open();
                MySqlCommand cmd_ctm = new MySqlCommand("rpt_leasings_customers", con_ctm);
                cmd_ctm.CommandType = CommandType.StoredProcedure;
                cmd_ctm.Parameters.AddWithValue("@i_Leasing_id", cls.Leasing_id);
                cmd_ctm.Parameters.AddWithValue("@i_Cust_id", cls.ctm.Cust_id);
                MySqlDataReader reader_ctm = cmd_ctm.ExecuteReader();

                con_grt_1.Open();
                MySqlCommand cmd_grt_1 = new MySqlCommand("rpt_leasings_guarantors", con_grt_1);
                cmd_grt_1.CommandType = CommandType.StoredProcedure;
                cmd_grt_1.Parameters.AddWithValue("@i_Leasing_id", cls.Leasing_id);
                cmd_grt_1.Parameters.AddWithValue("@i_Guarantor_no", 1);
                MySqlDataReader reader_grt_1 = cmd_grt_1.ExecuteReader();

                con_grt_2.Open();
                MySqlCommand cmd_grt_2 = new MySqlCommand("rpt_leasings_guarantors", con_grt_2);
                cmd_grt_2.CommandType = CommandType.StoredProcedure;
                cmd_grt_2.Parameters.AddWithValue("@i_Leasing_id", cls.Leasing_id);
                cmd_grt_2.Parameters.AddWithValue("@i_Guarantor_no", 2);
                MySqlDataReader reader_grt_2 = cmd_grt_2.ExecuteReader();

                con_grt_3.Open();
                MySqlCommand cmd_grt_3 = new MySqlCommand("rpt_leasings_guarantors", con_grt_3);
                cmd_grt_3.CommandType = CommandType.StoredProcedure;
                cmd_grt_3.Parameters.AddWithValue("@i_Leasing_id", cls.Leasing_id);
                cmd_grt_3.Parameters.AddWithValue("@i_Guarantor_no", 3);
                MySqlDataReader reader_grt_3 = cmd_grt_3.ExecuteReader();

                con_grt_4.Open();
                MySqlCommand cmd_grt_4 = new MySqlCommand("rpt_leasings_guarantors", con_grt_4);
                cmd_grt_4.CommandType = CommandType.StoredProcedure;
                cmd_grt_4.Parameters.AddWithValue("@i_Leasing_id", cls.Leasing_id);
                cmd_grt_4.Parameters.AddWithValue("@i_Guarantor_no", 4);
                MySqlDataReader reader_grt_4 = cmd_grt_4.ExecuteReader();

                con_grt_5.Open();
                MySqlCommand cmd_grt_5 = new MySqlCommand("rpt_leasings_guarantors", con_grt_5);
                cmd_grt_5.CommandType = CommandType.StoredProcedure;
                cmd_grt_5.Parameters.AddWithValue("@i_Leasing_id", cls.Leasing_id);
                cmd_grt_5.Parameters.AddWithValue("@i_Guarantor_no", 5);
                MySqlDataReader reader_grt_5 = cmd_grt_5.ExecuteReader();

                con_cpn.Open();
                MySqlCommand cmd_cpn = new MySqlCommand("rpt_withholding_tax", con_cpn);
                cmd_cpn.CommandType = CommandType.StoredProcedure;
                cmd_cpn.Parameters.AddWithValue("@i_Leasing_id", cls.Leasing_id);
                MySqlDataReader reader_cpn = cmd_cpn.ExecuteReader();

                Leasing_Ds ls_ds = new Leasing_Ds();
                ls_ds.Clear();
                ls_ds.Tables["Leasings"].Load(reader_cls);
                ls_ds.Tables["Customers"].Load(reader_ctm);
                ls_ds.Tables["Guarantor_1"].Load(reader_grt_1);
                ls_ds.Tables["Guarantor_2"].Load(reader_grt_2);
                ls_ds.Tables["Guarantor_3"].Load(reader_grt_3);
                ls_ds.Tables["Guarantor_4"].Load(reader_grt_4);
                ls_ds.Tables["Guarantor_5"].Load(reader_grt_5);
                ls_ds.Tables["Agent_Commission"].Load(reader_cpn);

                Car_Leasing_KH2 rpt = new Car_Leasing_KH2();
                rpt.SetDataSource(ls_ds);

                CRV_Display_Report.ReportSource = rpt;

                /// Export Report to PDF File with Save As Mode
                /// rpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "สัญญา_ข_2_" + cls.Deps_no);
                /// Response.End();

                ExportReport(rpt);
            }
            catch (MySqlException ex)
            {
                error = "MysqlException ==> Car_Leasing_KH11 : Page --> _loadReport() ";
                Log_Error._writeErrorFile(error, ex);
            }
            catch (Exception ex)
            {
                error = "Exception ==> Car_Leasing_KH11 : Page --> _loadReport() ";
                Log_Error._writeErrorFile(error, ex);
            }
            finally
            {
                con_cls.Close();
                con_ctm.Close();
                con_grt_1.Close();
                con_grt_2.Close();
                con_grt_3.Close();
                con_grt_4.Close();
                con_grt_5.Close();
                con_cpn.Close();

                con_cls.Dispose();
                con_ctm.Dispose();
                con_grt_1.Dispose();
                con_grt_2.Dispose();
                con_grt_3.Dispose();
                con_grt_4.Dispose();
                con_grt_5.Dispose();
                con_cpn.Dispose();
            }

            GC.Collect();
        }
        /*******************************************************************************************************************************************************************************
        ****************************************************              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);
        }
        public bool editCustomersLeasing(Car_Leasings cls, Customers ctm)
        {
            MySqlConnection con = MySQLConnection.connectionMySQL();

            try
            {
                con.Open();
                MySqlCommand cmd = new MySqlCommand("u_car_leasings_customer", con);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@i_Leasing_id", cls.Leasing_id);
                cmd.Parameters.AddWithValue("@i_Cust_id", ctm.Cust_id);
                cmd.Parameters.AddWithValue("@i_Cust_Idcard", ctm.Cust_Idcard);
                cmd.Parameters.AddWithValue("@i_Cust_Fname", ctm.Cust_Fname);
                cmd.Parameters.AddWithValue("@i_Cust_LName", ctm.Cust_LName);
                cmd.Parameters.AddWithValue("@i_Cust_B_date", ctm.Cust_B_date);
                cmd.Parameters.AddWithValue("@i_Cust_Age", ctm.Cust_Age);
                cmd.Parameters.AddWithValue("@i_Cust_Idcard_without", ctm.Cust_Idcard_without);
                cmd.Parameters.AddWithValue("@i_Cust_Idcard_start", ctm.Cust_Idcard_start);
                cmd.Parameters.AddWithValue("@i_Cust_Idcard_expire", ctm.Cust_Idcard_expire);
                cmd.Parameters.AddWithValue("@i_Cust_Nationality_id", ctm.ctm_ntnlt.Nationality_id);
                cmd.Parameters.AddWithValue("@i_Cust_Origin_id", ctm.ctm_org.Origin_id);
                cmd.Parameters.AddWithValue("@i_Cust_Tel", ctm.Cust_Tel);
                cmd.Parameters.AddWithValue("@i_Cust_Email", ctm.Cust_Email);
                cmd.Parameters.AddWithValue("@i_Cust_Status_id", ctm.ctm_pstt.person_status_id);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_idcard", ctm.Cust_Marry_idcard);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_Fname", ctm.Cust_Marry_Fname);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_Lname", ctm.Cust_Marry_Lname);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_Nationality", ctm.ctm_marry_ntnlt.Nationality_id);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_Origin", ctm.ctm_marry_org.Origin_id);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_Address_no", ctm.Cust_Marry_Address_no);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_vilage", ctm.Cust_Marry_vilage);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_vilage_no", ctm.Cust_Marry_vilage_no);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_alley", ctm.Cust_Marry_alley);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_road", ctm.Cust_Marry_road);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_subdistrict", ctm.Cust_Marry_subdistrict);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_district", ctm.Cust_Marry_district);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_province", ctm.Cust_Marry_province);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_country", ctm.Cust_Marry_country);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_zipcode", ctm.Cust_Marry_zipcode);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_tel", ctm.Cust_Marry_tel);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_email", ctm.Cust_Marry_email);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_job", ctm.Cust_Marry_job);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_job_position", ctm.Cust_Marry_job_position);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_job_long", ctm.Cust_Marry_job_long);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_job_salary", ctm.Cust_Marry_job_salary);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_job_local_name", ctm.Cust_Marry_job_local_name);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_job_address_no", ctm.Cust_Marry_job_address_no);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_job_vilage", ctm.Cust_Marry_job_vilage);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_job_vilage_no", ctm.Cust_Marry_job_vilage_no);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_job_alley", ctm.Cust_Marry_job_alley);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_job_road", ctm.Cust_Marry_job_road);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_job_subdistrict", ctm.Cust_Marry_job_subdistrict);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_job_district", ctm.Cust_Marry_job_district);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_job_province", ctm.Cust_Marry_job_province);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_job_country", ctm.Cust_Marry_job_country);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_job_zipcode", ctm.Cust_Marry_job_zipcode);
                cmd.Parameters.AddWithValue("@i_Cust_Marry_job_tel", ctm.Cust_Marry_job_tel);
                cmd.Parameters.AddWithValue("@i_Cust_Job", ctm.Cust_Job);
                cmd.Parameters.AddWithValue("@i_Cust_Job_position", ctm.Cust_Job_position);
                cmd.Parameters.AddWithValue("@i_Cust_Job_long", ctm.Cust_Job_long);
                cmd.Parameters.AddWithValue("@i_Cust_Job_salary", ctm.Cust_Job_salary);
                cmd.Parameters.AddWithValue("@i_Cust_Job_local_name", ctm.Cust_Job_local_name);
                cmd.Parameters.AddWithValue("@i_Cust_Job_address_no", ctm.Cust_Job_address_no);
                cmd.Parameters.AddWithValue("@i_Cust_Job_vilage", ctm.Cust_Job_vilage);
                cmd.Parameters.AddWithValue("@i_Cust_Job_vilage_no", ctm.Cust_Job_vilage_no);
                cmd.Parameters.AddWithValue("@i_Cust_Job_alley", ctm.Cust_Job_alley);
                cmd.Parameters.AddWithValue("@i_Cust_Job_road", ctm.Cust_Job_road);
                cmd.Parameters.AddWithValue("@i_Cust_Job_subdistrict", ctm.Cust_Job_subdistrict);
                cmd.Parameters.AddWithValue("@i_Cust_Job_district", ctm.Cust_Job_district);
                cmd.Parameters.AddWithValue("@i_Cust_Job_province", ctm.Cust_Job_province);
                cmd.Parameters.AddWithValue("@i_Cust_Job_country", ctm.Cust_Job_country);
                cmd.Parameters.AddWithValue("@i_Cust_Job_zipcode", ctm.Cust_Job_zipcode);
                cmd.Parameters.AddWithValue("@i_Cust_Job_tel", ctm.Cust_Job_tel);
                cmd.Parameters.AddWithValue("@i_Cust_Job_email", ctm.Cust_Job_email);
                cmd.Parameters.AddWithValue("@i_Cust_Home_address_no", ctm.Cust_Home_address_no);
                cmd.Parameters.AddWithValue("@i_Cust_Home_vilage", ctm.Cust_Home_vilage);
                cmd.Parameters.AddWithValue("@i_Cust_Home_vilage_no", ctm.Cust_Home_vilage_no);
                cmd.Parameters.AddWithValue("@i_Cust_Home_alley", ctm.Cust_Home_alley);
                cmd.Parameters.AddWithValue("@i_Cust_Home_road", ctm.Cust_Home_road);
                cmd.Parameters.AddWithValue("@i_Cust_Home_subdistrict", ctm.Cust_Home_subdistrict);
                cmd.Parameters.AddWithValue("@i_Cust_Home_district", ctm.Cust_Home_district);
                cmd.Parameters.AddWithValue("@i_Cust_Home_province", ctm.Cust_Home_province);
                cmd.Parameters.AddWithValue("@i_Cust_Home_country", ctm.Cust_Home_country);
                cmd.Parameters.AddWithValue("@i_Cust_Home_zipcode", ctm.Cust_Home_zipcode);
                cmd.Parameters.AddWithValue("@i_Cust_Home_tel", ctm.Cust_Home_tel);
                cmd.Parameters.AddWithValue("@i_Cust_Home_GPS_Latitude", ctm.Cust_Home_GPS_Latitude);
                cmd.Parameters.AddWithValue("@i_Cust_Home_GPS_Longitude", ctm.Cust_Home_GPS_Longitude);
                cmd.Parameters.AddWithValue("@i_Cust_Home_Status_id", ctm.ctm_home_stt.Home_status_id);
                cmd.Parameters.AddWithValue("@i_Cust_Idcard_address_no", ctm.Cust_Idcard_address_no);
                cmd.Parameters.AddWithValue("@i_Cust_Idcard_vilage", ctm.Cust_Idcard_vilage);
                cmd.Parameters.AddWithValue("@i_Cust_Idcard_vilage_no", ctm.Cust_Idcard_vilage_no);
                cmd.Parameters.AddWithValue("@i_Cust_Idcard_alley", ctm.Cust_Idcard_alley);
                cmd.Parameters.AddWithValue("@i_Cust_Idcard_road", ctm.Cust_Idcard_road);
                cmd.Parameters.AddWithValue("@i_Cust_Idcard_subdistrict", ctm.Cust_Idcard_subdistrict);
                cmd.Parameters.AddWithValue("@i_Cust_Idcard_district", ctm.Cust_Idcard_district);
                cmd.Parameters.AddWithValue("@i_Cust_Idcard_province", ctm.Cust_Idcard_province);
                cmd.Parameters.AddWithValue("@i_Cust_Idcard_country", ctm.Cust_Idcard_country);
                cmd.Parameters.AddWithValue("@i_Cust_Idcard_zipcode", ctm.Cust_Idcard_zipcode);
                cmd.Parameters.AddWithValue("@i_Cust_Idcard_tel", ctm.Cust_Idcard_tel);
                cmd.Parameters.AddWithValue("@i_Cust_Idcard_Status_id", ctm.ctm_idcard_stt.Home_status_id);
                cmd.Parameters.AddWithValue("@i_Cust_Current_address_no", ctm.Cust_Current_address_no);
                cmd.Parameters.AddWithValue("@i_Cust_Current_vilage", ctm.Cust_Current_vilage);
                cmd.Parameters.AddWithValue("@i_Cust_Current_vilage_no", ctm.Cust_Current_vilage_no);
                cmd.Parameters.AddWithValue("@i_Cust_Current_alley", ctm.Cust_Current_alley);
                cmd.Parameters.AddWithValue("@i_Cust_Current_road", ctm.Cust_Current_road);
                cmd.Parameters.AddWithValue("@i_Cust_Current_subdistrict", ctm.Cust_Current_subdistrict);
                cmd.Parameters.AddWithValue("@i_Cust_Current_district", ctm.Cust_Current_district);
                cmd.Parameters.AddWithValue("@i_Cust_Current_province", ctm.Cust_Current_province);
                cmd.Parameters.AddWithValue("@i_Cust_Current_country", ctm.Cust_Current_country);
                cmd.Parameters.AddWithValue("@i_Cust_Current_zipcode", ctm.Cust_Current_zipcode);
                cmd.Parameters.AddWithValue("@i_Cust_Current_tel", ctm.Cust_Current_tel);
                cmd.Parameters.AddWithValue("@i_Cust_Current_Status_id", ctm.ctm_current_stt.Home_status_id);

                cmd.ExecuteNonQuery();

                return(true);
            }
            catch (MySqlException ex)
            {
                error = "MysqlException ==> Managers_Leasings --> Car_Leasings_Customer_Manager --> editCustomersLeasing() ";
                Log_Error._writeErrorFile(error, ex);
                return(false);
            }
            catch (Exception ex)
            {
                error = "Exception ==> Managers_Leasings --> Car_Leasings_Customer_Manager --> editCustomersLeasing( ";
                Log_Error._writeErrorFile(error, ex);
                return(false);
            }
            finally
            {
                con.Close();
            }
        }
Exemple #27
0
        private void _loadLeasingDetails(string leasing_id, string idcard)
        {
            cls = cls_mng.getCarLeasingById(leasing_id);

            Leasing_Comments_Lbl.Text = cls.Leasing_Comment;

            if (cls.Total_payment_left == 0)
            {
                Close_Leasing_Lbl.Visible = true;
                Cal_Status_Lbl.Visible    = false;

                Payment_Btn.Visible = false;
                Calculate_Close_Leasing_Btn.Visible = false;
                Back_Before_Page_Btn.Visible        = false;

                Leasing_Date_TBx.Text = DateTimeUtility.convertDateToPageRealServer(cls.Leasing_date);

                Deps_No_TBx.Text    = cls.Deps_no;
                Leasing_No_TBx.Text = cls.Leasing_no;

                bs_cpn = bs_cpn_mng.getCompanysById(cls.bs_cpn.Company_id.ToString());

                Company_N_Name_TBx.Text = bs_cpn.Company_N_name;
                Company_F_Name_TBx.Text = bs_cpn.Company_F_name;

                bs_zn = bs_zn_mng.getZoneById(cls.bs_zn.Zone_id);

                Zone_Name_TBx.Text = bs_zn.Zone_code + " " + bs_zn.Zone_name;

                ctm = cls_ctm_mng.getCustomersLeasing(leasing_id, idcard);

                if (ctm != null)
                {
                    Customer_Name_TBx.Text   = ctm.Cust_Fname + " " + ctm.Cust_LName;
                    Customer_Idcard_TBx.Text = ctm.Cust_Idcard.Length == 13 ? ctm.Cust_Idcard.Substring(0, 1) + "-" + ctm.Cust_Idcard.Substring(1, 4) + "-" + ctm.Cust_Idcard.Substring(5, 5) + "-" + ctm.Cust_Idcard.Substring(10, 2) + "-" + ctm.Cust_Idcard.Substring(12) : ctm.Cust_Idcard;
                    //Customer_B_Date_TBx.Text = DateTimeUtility.convertDateToPage(ctm.Cust_B_date);
                    //Customer_Age_TBx.Text = ctm.Cust_Age.ToString();

                    Customer_H_Address_TBx.Text  = string.IsNullOrEmpty(ctm.Cust_Home_address_no) ? "" : ctm.Cust_Home_address_no;
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_vilage_no) ? "" : ctm.Cust_Home_vilage_no.IndexOf('.') >= 1 ? ctm.Cust_Home_vilage_no.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_vilage_no : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_vilage) ? "" : ctm.Cust_Home_vilage.IndexOf('.') >= 1 ? ctm.Cust_Home_vilage.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_vilage : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_alley) ? "" : ctm.Cust_Home_alley.IndexOf('.') >= 1 ? ctm.Cust_Home_alley.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_alley : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_road) ? "" : ctm.Cust_Home_road.IndexOf('.') >= 1 ? ctm.Cust_Home_road.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_road : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_subdistrict) ? "" : ctm.Cust_Home_subdistrict.IndexOf('.') >= 1 ? ctm.Cust_Home_subdistrict.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_subdistrict : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_district) ? "" : ctm.Cust_Home_district.IndexOf('.') >= 1 ? ctm.Cust_Home_district.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_district : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_province) ? "" : ctm.Cust_Home_province.IndexOf('.') >= 1 ? ctm.Cust_Home_province.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_province : "";

                    Customer_C_Address_TBx.Text  = string.IsNullOrEmpty(ctm.Cust_Current_address_no) ? "" : ctm.Cust_Current_address_no;
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_vilage_no) ? "" : ctm.Cust_Current_vilage_no.IndexOf('.') >= 1 ? ctm.Cust_Current_vilage_no.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_vilage_no : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_vilage) ? "" : ctm.Cust_Current_vilage.IndexOf('.') >= 1 ? ctm.Cust_Current_vilage.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_vilage : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_alley) ? "" : ctm.Cust_Current_alley.IndexOf('.') >= 1 ? ctm.Cust_Current_alley.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_alley : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_road) ? "" : ctm.Cust_Current_road.IndexOf('.') >= 1 ? ctm.Cust_Current_road.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_road : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_subdistrict) ? "" : ctm.Cust_Current_subdistrict.IndexOf('.') >= 1 ? ctm.Cust_Current_subdistrict.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_subdistrict : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_district) ? "" : ctm.Cust_Current_district.IndexOf('.') >= 1 ? ctm.Cust_Current_district.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_district : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_province) ? "" : ctm.Cust_Current_province.IndexOf('.') >= 1 ? ctm.Cust_Current_province.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_province : "";
                }

                Car_Type_TBx.Text = cls.Car_type;

                bs_cbrn = cbrn_mng.getCarBrandById(cls.bs_cbrn.car_brand_id);

                if (bs_cbrn != null)
                {
                    Car_Brand_TBx.Text = bs_cbrn.car_brand_name_th + " ( " + bs_cbrn.car_brand_name_eng + " )";
                }

                Car_Plate_TBx.Text = cls.Car_license_plate + " " + cls.Car_license_plate_province;

                Car_Chassis_No_TBx.Text = cls.Car_chassis_no;
                Car_Engine_No_TBx.Text  = cls.Car_engine_no;

                cag_com = cag_mng.getAgentCommission("", leasing_id);

                Agent_Commission_TBx.Text = cag_com.Agent_commission.ToString("#,###.00");

                Finance_Cost_TBx.Text       = cls.Total_require.ToString("#,###.00");
                Finance_Value_TBx.Text      = cls.Total_sum.ToString("#,###.00");
                Leasing_Cost_TBx.Text       = cls.Total_Net_leasing.ToString("#,###.00");
                Period_Amount_TBx.Text      = cls.Total_period.ToString();
                Period_Payment_TBx.Text     = cls.Period_payment.ToString("#,###.00");
                Payment_Schedule_TBx.Text   = cls.Payment_schedule.ToString();
                Frist_Payment_Date_TBx.Text = DateTimeUtility.convertDateToPageRealServer(cls.First_payment_date);

                Payment_Date_TBx.Enabled = false;

                List <Car_Leasings_Payment> list_cls_pay = cls_pay_mng.getRealPaymentInfo(leasing_id);

                Session["list_cls_pay"] = list_cls_pay;

                Period_free_TBx.Enabled  = false;
                Period_track_TBx.Enabled = false;

                Real_Payment_TBx.Enabled      = false;
                Real_Payment_Fine_TBx.Enabled = false;
                Real_Discount_TBx.Enabled     = false;

                Payment_Date_TBx.Text = "";

                Period_No_TBx.Text            = "";
                Total_Payment_Period_TBx.Text = "";
                Total_payment_left_TBx.Text   = "";
                Period_free_TBx.Text          = "";
                Period_track_TBx.Text         = "";
                Discount_TBx.Text             = "";

                Total_payment_fine_TBx.Text = "";

                Total_period_left_TBx.Text  = "";
                Period_fine_TBx.Text        = "";
                Cal_Period_Payment_TBx.Text = "";
            }
            else
            {
                Leasing_Date_TBx.Text = DateTimeUtility.convertDateToPageRealServer(cls.Leasing_date);
                Deps_No_TBx.Text      = cls.Deps_no;
                Leasing_No_TBx.Text   = cls.Leasing_no;

                bs_cpn = bs_cpn_mng.getCompanysById(cls.bs_cpn.Company_id.ToString());

                Company_N_Name_TBx.Text = bs_cpn.Company_N_name;
                Company_F_Name_TBx.Text = bs_cpn.Company_F_name;

                bs_zn = bs_zn_mng.getZoneById(cls.bs_zn.Zone_id);

                Zone_Name_TBx.Text = bs_zn.Zone_code + " " + bs_zn.Zone_name;

                ctm = cls_ctm_mng.getCustomersLeasing(leasing_id, idcard);

                if (ctm != null)
                {
                    Customer_Name_TBx.Text   = ctm.Cust_Fname + " " + ctm.Cust_LName;
                    Customer_Idcard_TBx.Text = ctm.Cust_Idcard.Length == 13 ? ctm.Cust_Idcard.Substring(0, 1) + "-" + ctm.Cust_Idcard.Substring(1, 4) + "-" + ctm.Cust_Idcard.Substring(5, 5) + "-" + ctm.Cust_Idcard.Substring(10, 2) + "-" + ctm.Cust_Idcard.Substring(12) : ctm.Cust_Idcard;
                    //Customer_B_Date_TBx.Text = DateTimeUtility.convertDateToPage(ctm.Cust_B_date);
                    //Customer_Age_TBx.Text = ctm.Cust_Age.ToString();

                    Customer_H_Address_TBx.Text  = string.IsNullOrEmpty(ctm.Cust_Home_address_no) ? "" : ctm.Cust_Home_address_no;
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_vilage_no) ? "" : ctm.Cust_Home_vilage_no.IndexOf('.') >= 1 ? ctm.Cust_Home_vilage_no.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_vilage_no : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_vilage) ? "" : ctm.Cust_Home_vilage.IndexOf('.') >= 1 ? ctm.Cust_Home_vilage.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_vilage : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_alley) ? "" : ctm.Cust_Home_alley.IndexOf('.') >= 1 ? ctm.Cust_Home_alley.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_alley : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_road) ? "" : ctm.Cust_Home_road.IndexOf('.') >= 1 ? ctm.Cust_Home_road.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_road : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_subdistrict) ? "" : ctm.Cust_Home_subdistrict.IndexOf('.') >= 1 ? ctm.Cust_Home_subdistrict.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_subdistrict : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_district) ? "" : ctm.Cust_Home_district.IndexOf('.') >= 1 ? ctm.Cust_Home_district.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_district : "";
                    Customer_H_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Home_province) ? "" : ctm.Cust_Home_province.IndexOf('.') >= 1 ? ctm.Cust_Home_province.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Home_province : "";

                    Customer_C_Address_TBx.Text  = string.IsNullOrEmpty(ctm.Cust_Current_address_no) ? "" : ctm.Cust_Current_address_no;
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_vilage_no) ? "" : ctm.Cust_Current_vilage_no.IndexOf('.') >= 1 ? ctm.Cust_Current_vilage_no.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_vilage_no : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_vilage) ? "" : ctm.Cust_Current_vilage.IndexOf('.') >= 1 ? ctm.Cust_Current_vilage.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_vilage : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_alley) ? "" : ctm.Cust_Current_alley.IndexOf('.') >= 1 ? ctm.Cust_Current_alley.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_alley : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_road) ? "" : ctm.Cust_Current_road.IndexOf('.') >= 1 ? ctm.Cust_Current_road.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_road : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_subdistrict) ? "" : ctm.Cust_Current_subdistrict.IndexOf('.') >= 1 ? ctm.Cust_Current_subdistrict.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_subdistrict : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_district) ? "" : ctm.Cust_Current_district.IndexOf('.') >= 1 ? ctm.Cust_Current_district.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_district : "";
                    Customer_C_Address_TBx.Text += string.IsNullOrEmpty(ctm.Cust_Current_province) ? "" : ctm.Cust_Current_province.IndexOf('.') >= 1 ? ctm.Cust_Current_province.Split('.')[1] == "-" ? "" : " " + ctm.Cust_Current_province : "";
                }

                Car_Type_TBx.Text = cls.Car_type;

                bs_cbrn = cbrn_mng.getCarBrandById(cls.bs_cbrn.car_brand_id);

                if (bs_cbrn != null)
                {
                    Car_Brand_TBx.Text = bs_cbrn.car_brand_name_th + " ( " + bs_cbrn.car_brand_name_eng + " )";
                }

                Car_Plate_TBx.Text = cls.Car_license_plate + " " + cls.Car_license_plate_province;

                Car_Chassis_No_TBx.Text = cls.Car_chassis_no;
                Car_Engine_No_TBx.Text  = cls.Car_engine_no;

                cag_com = cag_mng.getAgentCommission("", leasing_id);

                Agent_Commission_TBx.Text = cag_com.Agent_commission.ToString("#,###.00");

                Finance_Cost_TBx.Text       = cls.Total_require.ToString("#,###.00");
                Finance_Value_TBx.Text      = cls.Total_sum.ToString("#,###.00");
                Leasing_Cost_TBx.Text       = cls.Total_Net_leasing.ToString("#,###.00");
                Period_Amount_TBx.Text      = cls.Total_period.ToString();
                Period_Payment_TBx.Text     = cls.Period_payment.ToString("#,###.00");
                Payment_Schedule_TBx.Text   = cls.Payment_schedule.ToString();
                Frist_Payment_Date_TBx.Text = DateTimeUtility.convertDateToPageRealServer(cls.First_payment_date);

                Payment_Date_TBx.Text = DateTimeUtility.convertDateToPageRealServer(DateTime.Now.ToString());

                Period_No_TBx.Text            = cls.Total_period_length;
                Total_Payment_Period_TBx.Text = cls.Total_period_lose == 0 ? "1" : cls.Total_period_lose.ToString();
                Total_payment_left_TBx.Text   = cls.Total_payment_left.ToString("#,###.00");
                Period_free_TBx.Text          = "0.00";
                Period_track_TBx.Text         = "0.00";
                Discount_TBx.Text             = "0.00";

                List <Car_Leasings_Payment> list_cls_pay = cls_pay_mng.getRealPaymentInfo(leasing_id);

                double total_lost         = 0.00;
                double total_payment_fine = 0.00;
                double payment_fine       = 0.00;
                double real_payment_fine  = 0.00;
                double real_payment       = 0.00;
                double next_period_no     = 1;
                double duplicate_period   = 0;

                for (int i = 0; i < list_cls_pay.Count; i++)
                {
                    Car_Leasings_Payment cls_pay = list_cls_pay[i];

                    if (string.IsNullOrEmpty(cls.Total_period_length))
                    {
                        total_lost         = cls_pay.Period_current;
                        Period_No_TBx.Text = next_period_no.ToString();
                    }
                    else
                    {
                        int period_str = Convert.ToInt32(cls.Total_period_length.Split('-')[0].Trim());
                        int period_end = Convert.ToInt32(cls.Total_period_length.Split('-')[1].Trim());

                        if (cls_pay.Period_no >= period_str && cls_pay.Period_no <= period_end && cls_pay.Period_no != duplicate_period)
                        {
                            total_lost += cls_pay.Period_current;
                        }
                    }

                    if (cls_pay.Period_fine > 0 && cls_pay.Period_no != duplicate_period)
                    {
                        payment_fine += cls_pay.Period_fine;
                    }

                    if (cls_pay.Real_payment_fine > 0)
                    {
                        real_payment_fine += cls_pay.Real_payment_fine;
                    }

                    if (cls_pay.Real_payment > 0 && cls_pay.Period_payment_status != 9)
                    {
                        real_payment += cls_pay.Real_payment;
                    }

                    if (cls_pay.Period_payment_status == 9 && cls_pay.Period_no != duplicate_period)
                    {
                        next_period_no += 1;
                    }

                    duplicate_period = cls_pay.Period_no;
                }

                total_payment_fine = payment_fine - real_payment_fine;

                Total_payment_fine_TBx.Text = total_payment_fine > 0 ? total_payment_fine.ToString("#,###.00") : "0.00";

                Total_period_left_TBx.Text = string.IsNullOrEmpty(cls.Total_period_length) ? "0.00" : (total_lost - real_payment).ToString("#,###.00");

                Period_fine_TBx.Text = total_payment_fine < 0 ? "0.00" : total_payment_fine.ToString("#,###.00");

                Cal_Period_Payment_TBx.Text = (total_lost - real_payment).ToString("#,###.00");

                Session["list_cls_pay"] = list_cls_pay;

                Real_Payment_TBx.Focus();
            }
        }