Esempio n. 1
0
        private bool InsertData()
        {
            try
            {
                ConnectDataDataContext context = new ConnectDataDataContext();
                /*==========Get Max CusNo======================================================================================*/
                string CustNo;
                if (context.Accounts.Max(a => a.CustNo) == null)
                {
                    CustNo = "ACC00001";
                }
                else
                {
                    CustNo = context.Accounts.Max(a => a.CustNo).Substring(3, 5);//.Substring(3, 7);
                    CustNo = "ACC" + String.Format("{0:D5}", (Convert.ToInt32(CustNo) + 1));
                }
                /*==========Get Max CusNo======================================================================================*/
                /*==========Account======================================================================================*/
                refNo = CustNo;
                Account acc = new Account();
                acc.draft_date     = Request.Form.Get("draft_date");
                acc.suggester_name = Request.Form.Get("suggester_name");
                acc.type_Account   = Request.Form.Get("u_type") == "1" ? "บุคคลธรรมดา" : "นิติบุคคล";
                acc.CustNo         = CustNo;
                acc.total_limit    = ConvertDecimal(Request.Form.Get("t_4")) + ConvertDecimal(Request.Form.Get("t_5")) + ConvertDecimal(Request.Form.Get("t_6")) + ConvertDecimal(Request.Form.Get("t_7")) + ConvertDecimal(Request.Form.Get("t_8")) + ConvertDecimal(Request.Form.Get("t_9")) + ConvertDecimal(Request.Form.Get("t10"));
                acc.a_1            = Request.Form.Get("1") != null?Request.Form.Get("1").Contains("1") ? true : false : false;

                acc.a_2 = Request.Form.Get("2") != null?Request.Form.Get("2").Contains("1") ? true : false : false;

                acc.a_3 = Request.Form.Get("3") != null?Request.Form.Get("3").Contains("1") ? true : false : false;

                acc.CustNo_Mate = Request.Form.Get("yesno") == "2" ? "Mate_" + CustNo : null;
                acc.SendAddr    = Request.Form.Get("sendadd") != null?Request.Form.Get("sendadd") : "1";

                context.Accounts.InsertOnSubmit(acc);
                context.SubmitChanges();
                /*==========End_Account======================================================================================*/
                /*==========LimitAccount======================================================================================*/
                try
                {
                    List <LimitAccount> listLimitAccount = new List <LimitAccount>();
                    for (int i = 0; i < 9; i++)
                    {
                        LimitAccount LimitAcc = new LimitAccount();
                        if (i == 0)
                        {
                            if (Request.Form.Get("account") != null && Request.Form.Get("account").Contains("1"))
                            {
                                LimitAcc.Limt   = ConvertDecimal(Request.Form.Get("t_4"));
                                LimitAcc.CustNo = CustNo;
                                LimitAcc.TypeID = i + 1;
                                listLimitAccount.Add(LimitAcc);
                            }
                        }
                        else
                        {
                            if (Request.Form.Get("account" + i.ToString()) != null && Request.Form.Get("account" + i.ToString()).Contains("1"))
                            {
                                LimitAcc.Limt   = ConvertDecimal(Request.Form.Get("t_" + (4 + i).ToString()));
                                LimitAcc.CustNo = CustNo;
                                LimitAcc.TypeID = i + 1;
                                listLimitAccount.Add(LimitAcc);
                            }
                        }
                    }
                    context.LimitAccounts.InsertAllOnSubmit(listLimitAccount);
                    context.SubmitChanges();
                }
                catch (Exception f) { }
                /*==========End LimitAccount======================================================================================*/
                if (Request.Form.Get("u_type") != null && Request.Form.Get("u_type") == "1")//บุคคลธรรมดา
                {
                    /*========== CustInformation======================================================================================*/
                    CustInformation infor = new CustInformation();
                    string          Status;


                    switch (Request.Form.Get("yesno"))
                    {
                    case "1":
                        Status = "โสด";
                        break;

                    case "2":
                        Status = "สมรส";
                        break;

                    case "3":
                        Status = "หม้าย";
                        break;

                    case "4":
                        Status = "อย่าร้าง";
                        break;

                    default:
                        Status = null;
                        break;
                    }
                    infor.CustNo        = CustNo;
                    infor.Prefix1       = getPrefix("TH", "sex");
                    infor.Prefix2       = getPrefix("EN", "sex1");;
                    infor.FName1        = Request.Form.Get("t_12");
                    infor.LName1        = Request.Form.Get("t_13");
                    infor.FName2        = Request.Form.Get("t_14");
                    infor.LName2        = Request.Form.Get("t_15");
                    infor.BirthDate     = Request.Form.Get("birthday_date");
                    infor.IDCard        = Request.Form.Get("t_16") + Request.Form.Get("t_17") + Request.Form.Get("t_18") + Request.Form.Get("t_19") + Request.Form.Get("t_20");
                    infor.IDGovernment  = Request.Form.Get("t_21");
                    infor.Nationality   = Request.Form.Get("t_22");
                    infor.PassportNo    = Request.Form.Get("t_23");
                    infor.Expired       = Request.Form.Get("t_25");
                    infor.CreateDate    = Request.Form.Get("t_24");
                    infor.Tel           = Request.Form.Get("t_26");
                    infor.MaritalStatus = Status;
                    infor.Guilty        = Request.Form.Get("ever") != null?Request.Form.Get("ever").Contains("2") ? true : false : false;

                    infor.GuiltyDes  = Request.Form.Get("t_121");
                    infor.GuiltyYear = Request.Form.Get("t_122");
                    context.CustInformations.InsertOnSubmit(infor);
                    context.SubmitChanges();
                    /*==========End CustInformation======================================================================================*/
                    /*========== addrwork======================================================================================*/
                    AddrCurrent addrWork = new AddrCurrent();
                    addrWork.CustNo     = CustNo;
                    addrWork.TypeIDAdrr = 2;
                    addrWork.NameLocal  = Request.Form.Get("t_27");
                    addrWork.No         = Request.Form.Get("t_28");
                    addrWork.Street     = Request.Form.Get("t_28_1");
                    addrWork.Building   = Request.Form.Get("t_28_2");
                    addrWork.Alley      = Request.Form.Get("t_28_7");
                    addrWork.Locality   = Request.Form.Get("t_28_3");
                    addrWork.District   = Request.Form.Get("t_28_4");
                    addrWork.Province   = Request.Form.Get("t_28_5");
                    addrWork.ZipCode    = Request.Form.Get("t_28_6");
                    context.AddrCurrents.InsertOnSubmit(addrWork);
                    context.SubmitChanges();
                    /*==========End work======================================================================================*/
                    /*========== AddrCurrent======================================================================================*/
                    AddrCurrent addrCurr = new AddrCurrent();
                    addrCurr.CustNo     = CustNo;
                    addrCurr.TypeIDAdrr = 1;
                    addrCurr.No         = Request.Form.Get("t_29");
                    addrCurr.Street     = Request.Form.Get("t_30");
                    addrCurr.Building   = Request.Form.Get("t_31");
                    addrCurr.Alley      = Request.Form.Get("t_31_1");
                    addrCurr.Locality   = Request.Form.Get("t_32");
                    addrCurr.District   = Request.Form.Get("t_32_1");
                    addrCurr.Province   = Request.Form.Get("t_32_2");
                    addrCurr.ZipCode    = Request.Form.Get("t_32_3");
                    addrCurr.Tel        = Request.Form.Get("t_33");
                    addrCurr.fax        = Request.Form.Get("t_34");
                    context.AddrCurrents.InsertOnSubmit(addrCurr);
                    context.SubmitChanges();
                    /*==========End AddrCurrent======================================================================================*/
                    int IDTypeCareer = 0;
                    if (Request.Form.Get("Job") != null && Request.Form.Get("Job").Contains("4"))
                    {
                        IDTypeCareer = context.TypeCareers.Max(a => a.ID) + 1;
                        TypeCareer pTypecareer = new TypeCareer();
                        pTypecareer.Code        = "990";
                        pTypecareer.ID          = IDTypeCareer;
                        pTypecareer.Description = Request.Form.Get("t_35");
                        context.TypeCareers.InsertOnSubmit(pTypecareer);
                        context.SubmitChanges();
                    }
                    CareerInformation pcareer = new CareerInformation();
                    pcareer.CustNo = CustNo;
                    pcareer.ID     = Request.Form.Get("Job") != null?Request.Form.Get("Job") == "4" ? IDTypeCareer : Convert.ToInt32(Request.Form.Get("Job")) : 1;

                    pcareer.Business           = Request.Form.Get("t_36");
                    pcareer.Position           = Request.Form.Get("t_37");
                    pcareer.Salary             = Request.Form.Get("t_38");
                    pcareer.Experience         = Request.Form.Get("t_39");
                    pcareer.OtherIncome        = Request.Form.Get("t_40");
                    pcareer.OtherSourcesIncome = Request.Form.Get("t_41");
                    pcareer.AnnualSales        = Request.Form.Get("t_127");
                    pcareer.Political          = Request.Form.Get("YesorNo").Contains("2") ? true : false;
                    pcareer.PoliticalPosition  = Request.Form.Get("t_42");
                    context.CareerInformations.InsertOnSubmit(pcareer);
                    context.SubmitChanges();


                    if (Request.Form.Get("yesno") != null && Request.Form.Get("yesno") == "2")//คู่สมรส
                    {
                        /*========== CustInformation======================================================================================*/
                        infor = new CustInformation();


                        infor.CustNo        = "Mate_" + CustNo;
                        infor.Prefix1       = getPrefix("TH", "sex2");
                        infor.Prefix2       = getPrefix("EN", "sex3");
                        infor.FName1        = Request.Form.Get("t_43");
                        infor.LName1        = Request.Form.Get("t_44");
                        infor.FName2        = Request.Form.Get("t_45");
                        infor.LName2        = Request.Form.Get("t_46");
                        infor.BirthDate     = Request.Form.Get("Birthday_day2");
                        infor.IDCard        = Request.Form.Get("t_47") + Request.Form.Get("t_48") + Request.Form.Get("t_49") + Request.Form.Get("t_50") + Request.Form.Get("t_51");
                        infor.IDGovernment  = Request.Form.Get("t_52");
                        infor.Nationality   = Request.Form.Get("t_53");
                        infor.Expired       = Request.Form.Get("t_55");
                        infor.CreateDate    = Request.Form.Get("t_54");
                        infor.Tel           = Request.Form.Get("t_56");
                        infor.MaritalStatus = "สมรส";
                        context.CustInformations.InsertOnSubmit(infor);
                        context.SubmitChanges();
                        /*==========End CustInformation======================================================================================*/
                        /*========== addrwork======================================================================================*/
                        addrWork            = new AddrCurrent();
                        addrWork.CustNo     = "Mate_" + CustNo;
                        addrWork.TypeIDAdrr = 2;
                        addrWork.NameLocal  = Request.Form.Get("t_57");
                        addrWork.No         = Request.Form.Get("t_58");
                        addrWork.Street     = Request.Form.Get("t_59");
                        addrWork.Building   = Request.Form.Get("t_60");
                        addrWork.Alley      = Request.Form.Get("t_60_1");
                        addrWork.Locality   = Request.Form.Get("t_61");
                        addrWork.District   = Request.Form.Get("t_61_1");
                        addrWork.Province   = Request.Form.Get("t_61_2");
                        addrWork.ZipCode    = Request.Form.Get("t_61_3");
                        addrWork.Tel        = Request.Form.Get("t_62");
                        addrWork.fax        = Request.Form.Get("t_63");
                        context.AddrCurrents.InsertOnSubmit(addrWork);
                        context.SubmitChanges();
                        /*==========End work======================================================================================*/


                        if (Request.Form.Get("Job2") != null && Request.Form.Get("Job2") == "4")
                        {
                            IDTypeCareer = context.TypeCareers.Max(a => a.ID) + 1;
                            TypeCareer pTypecareer = new TypeCareer();
                            pTypecareer.Code        = "990";
                            pTypecareer.ID          = IDTypeCareer;
                            pTypecareer.Description = Request.Form.Get("t_64");
                            context.TypeCareers.InsertOnSubmit(pTypecareer);
                            context.SubmitChanges();
                        }
                        pcareer                    = new CareerInformation();
                        pcareer.CustNo             = "Mate_" + CustNo;
                        pcareer.ID                 = Request.Form.Get("Job2") == "4" ? IDTypeCareer : Convert.ToInt32(Request.Form.Get("Job2"));
                        pcareer.Business           = Request.Form.Get("t_65");
                        pcareer.Position           = Request.Form.Get("t_66");
                        pcareer.Salary             = Request.Form.Get("t_67");
                        pcareer.Experience         = Request.Form.Get("t_68");
                        pcareer.OtherIncome        = Request.Form.Get("t_69");
                        pcareer.OtherSourcesIncome = Request.Form.Get("t_70");
                        pcareer.AnnualSales        = Request.Form.Get("t_128");
                        pcareer.Political          = Request.Form.Get("YesorNo2") != null?Request.Form.Get("YesorNo2").Contains("2") ? true : false : false;

                        pcareer.PoliticalPosition = Request.Form.Get("t_71");
                        context.CareerInformations.InsertOnSubmit(pcareer);
                        context.SubmitChanges();
                    } //คู่สมรส
                }     //บุคคลธรรมดา
                else
                {
                    //ประวัติลูกค้า กรณีนิติบุคคล
                    string typeCompany;
                    switch (Request.Form.Get("company1"))
                    {
                    case "1":
                        typeCompany = "บริษัทจำกัด";
                        break;

                    case "2":
                        typeCompany = "ห้างหุ้นส่วนจำกัด";
                        break;

                    case "3":
                        typeCompany = "ห้างหุ้นส่วนสามัญนิติบุคคล";
                        break;

                    case "4":
                        typeCompany = "บริษัทมหาชน";
                        break;

                    case "5":
                        typeCompany = Request.Form.Get("t_72");
                        break;

                    default:
                        typeCompany = null;
                        break;
                    }
                    InforCorporate company = new InforCorporate();
                    company.CustNo            = CustNo;
                    company.typecompany       = typeCompany;
                    company.Name              = Request.Form.Get("t_73");
                    company.Nationality       = Request.Form.Get("t_74");
                    company.RegisterNo        = Request.Form.Get("t_75");
                    company.RegisterDate      = Request.Form.Get("t_76");
                    company.RegisteCountry    = Request.Form.Get("t_77");
                    company.TaxID             = Request.Form.Get("t_78");
                    company.typebisiness      = Request.Form.Get("t_79");
                    company.RegisteredCapital = Request.Form.Get("t_80");
                    company.Paid_up_capital   = Request.Form.Get("t_81");
                    company.Another1          = Request.Form.Get("t_82");
                    company.Another2          = Request.Form.Get("t_83");
                    context.InforCorporates.InsertOnSubmit(company);
                    context.SubmitChanges();

                    CustInformation custinfor = new CustInformation();
                    custinfor.Guilty = Request.Form.Get("ever") != null?Request.Form.Get("ever").Contains("1") ? true : false : false;

                    custinfor.GuiltyDes  = Request.Form.Get("t_121");
                    custinfor.GuiltyYear = Request.Form.Get("t_122");
                    custinfor.CustNo     = CustNo;
                    context.CustInformations.InsertOnSubmit(custinfor);
                    context.SubmitChanges();

                    Attorney attorneys = new Attorney();
                    attorneys.CustNo       = CustNo;
                    attorneys.Name         = Request.Form.Get("t_84");
                    attorneys.IDCard       = Request.Form.Get("t_85") + Request.Form.Get("t_86") + Request.Form.Get("t_87") + Request.Form.Get("t_88") + Request.Form.Get("t_89");
                    attorneys.IDGovernment = Request.Form.Get("t_90");
                    attorneys.Another      = Request.Form.Get("t_91");
                    attorneys.Nationality  = Request.Form.Get("t_92");
                    attorneys.Expired      = Request.Form.Get("t_94");
                    attorneys.CreateDate   = Request.Form.Get("t_93");
                    attorneys.relationship = Request.Form.Get("t_95");
                    context.Attorneys.InsertOnSubmit(attorneys);
                    context.SubmitChanges();
                }



                // ข้อมูลที่อยู่
                //ที่อยู่ปัจจุบัน อีกแล้ว
                AddrCurrent update = new AddrCurrent();

                if (update != null)
                {
                    update.CustNo     = CustNo;
                    update.No         = Request.Form.Get("t_96");
                    update.Street     = Request.Form.Get("t_96_1");
                    update.TypeIDAdrr = 6;
                    update.Building   = Request.Form.Get("t_96_2");
                    update.Alley      = Request.Form.Get("t_96_7");
                    update.Locality   = Request.Form.Get("t_96_3");
                    update.District   = Request.Form.Get("t_96_4");
                    update.Province   = Request.Form.Get("t_96_5");
                    update.ZipCode    = Request.Form.Get("t_96_6");
                    update.Tel        = Request.Form.Get("t_97");
                    update.TelPhone   = Request.Form.Get("t_99");
                    update.fax        = Request.Form.Get("t_98");
                    update.Email      = Request.Form.Get("t_100");
                    context.AddrCurrents.InsertOnSubmit(update);
                    context.SubmitChanges();
                }

                //ที่อยู่อื่นๆ
                AddrCurrent adrrAnotor = new AddrCurrent();
                adrrAnotor.CustNo     = CustNo;
                adrrAnotor.TypeIDAdrr = 4;
                adrrAnotor.No         = Request.Form.Get("t_101");
                adrrAnotor.Street     = Request.Form.Get("t_101_1");
                adrrAnotor.Building   = Request.Form.Get("t_101_2");
                adrrAnotor.Alley      = Request.Form.Get("t_101_7");
                adrrAnotor.Locality   = Request.Form.Get("t_101_3");
                adrrAnotor.District   = Request.Form.Get("t_101_4");
                adrrAnotor.Province   = Request.Form.Get("t_101_5");
                adrrAnotor.ZipCode    = Request.Form.Get("t_101_6");
                adrrAnotor.Tel        = Request.Form.Get("t_102");
                adrrAnotor.fax        = Request.Form.Get("t_103");
                adrrAnotor.TelPhone   = Request.Form.Get("t_104");
                adrrAnotor.Email      = Request.Form.Get("t_105");
                context.AddrCurrents.InsertOnSubmit(adrrAnotor);
                context.SubmitChanges();
                //  กรณีติดต่อโดยตรงไม่ได้ให้ติดต่อบุคคลดังนี้
                AddrCurrent adrrref = new AddrCurrent();
                adrrref.CustNo     = CustNo;
                adrrref.TypeIDAdrr = 5;
                adrrref.No         = Request.Form.Get("t_110");
                adrrref.Street     = Request.Form.Get("t_110_1");
                adrrref.Building   = Request.Form.Get("t_110_2");
                adrrref.Alley      = Request.Form.Get("t_110_7");
                adrrref.Locality   = Request.Form.Get("t_110_3");
                adrrref.District   = Request.Form.Get("t_110_4");
                adrrref.Province   = Request.Form.Get("t_110_5");
                adrrref.ZipCode    = Request.Form.Get("t_101_6");
                adrrref.Tel        = Request.Form.Get("t_111");
                adrrref.fax        = Request.Form.Get("t_112");
                adrrref.TelPhone   = Request.Form.Get("t_113");
                adrrref.Email      = Request.Form.Get("t_114");
                context.AddrCurrents.InsertOnSubmit(adrrref);

                RefPerSonInformation refdata = new RefPerSonInformation();
                refdata.Prefix1      = getPrefix("TH", "sex4");
                refdata.FName1       = Request.Form.Get("t_106");
                refdata.LName1       = Request.Form.Get("t_107");
                refdata.career       = Request.Form.Get("t_109");
                refdata.TypeIDAdrr   = 5;
                refdata.CustNo       = CustNo;
                refdata.relationship = Request.Form.Get("t_108");
                context.RefPerSonInformations.InsertOnSubmit(refdata);
                context.SubmitChanges();


                InforPayment payInfor = new InforPayment();
                payInfor.CustNo       = CustNo;
                payInfor.ATS          = Request.Form.Get("check1") != null ? true : false;
                payInfor.e_Dividend   = Request.Form.Get("check1") != null ? true : false;
                payInfor.Bank_1       = Request.Form.Get("t_115");
                payInfor.Branch1      = Request.Form.Get("t_116");
                payInfor.AccountN01   = Request.Form.Get("t_117");
                payInfor.Bank2        = Request.Form.Get("t_118");
                payInfor.Branch2      = Request.Form.Get("t_119");
                payInfor.AccountN02   = Request.Form.Get("t_120");
                payInfor.TypeAccount1 = Request.Form.Get("check2") != null?Request.Form.Get("check2").Contains("1") ? "ออมทรัพย์" : "กระแสรายวัน" : "";

                payInfor.TypeAccount2 = Request.Form.Get("check3") != null?Request.Form.Get("check3").Contains("1") ? "ออมทรัพย์" : "กระแสรายวัน" : "";

                context.InforPayments.InsertOnSubmit(payInfor);
                context.SubmitChanges();
                Response.Write("<script>alert('บันทึกสำเร็จ')</script>");
                try
                {
                    string sendEmail = ConfigurationManager.AppSettings["SendEmail"];
                    if (sendEmail.ToLower() == "true")
                    {
                        bool checkMail = SendEmail("", CustNo);
                        if (!checkMail)
                        {
                            Response.Write("<script>alert('ขออภัย ไม่สามารถส่งอีเมลล์ได้')</script>");
                        }
                    }
                    //else { Response.Write("<script>alert('ขออภัย ไม่สามารถส่งอีเมลล์ถึงคุณ " + Request.Form.Get("t_100") + " ได้')</script>"); }
                    return(true);
                }catch (Exception e) {
                    System.Diagnostics.Debug.WriteLine("ERROR ==>" + e);
                    return(true);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("ERROR ==>" + e);
                Response.Write("<script>alert('การบันทึกไม่สำเร็จ ')</script>");
                return(false);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string ActivationCode = Request.QueryString["ActivationCode"];

                ConnectDataDataContext connect = new ConnectDataDataContext();
                GenerateLink           gen     = new GenerateLink();
                gen = connect.GenerateLinks.Where(a => a.htmlGen == ActivationCode).FirstOrDefault();
                if (gen != null)
                {
                    string  custAcc = gen.CustNo;// "ACC00002";//
                    Account acc     = new Account();
                    acc = connect.Accounts.Where(a => a.CustNo == custAcc).FirstOrDefault();
                    if (acc != null)
                    {
                        List <AddrCurrent> addr      = new List <AddrCurrent>();
                        AddrCurrent        addrIndex = new AddrCurrent();
                        addr = connect.AddrCurrents.Where(a => a.CustNo.Contains(acc.CustNo)).ToList();
                        if (acc.type_Account != null && acc.type_Account.Contains("บุคคลธรรมดา"))
                        {
                            RadioButton9.Checked = true;
                            mate.Visible         = false;
                            u2_2.Visible         = false;
                            u2_3.Visible         = false;
                        }
                        else
                        {
                            RadioButton10.Checked = true;
                            u1_2.Visible          = false;
                            mate.Visible          = false;
                            u1_3.Visible          = false;
                        }
                        List <LimitAccount> limit = new List <LimitAccount>();
                        limit = connect.LimitAccounts.Where(a => a.CustNo == acc.CustNo).ToList();
                        if (limit != null)
                        {
                            foreach (var a in limit)
                            {
                                switch (a.TypeID)
                                {
                                case 1:
                                    cash_checkbox.Checked = true;
                                    cash.Value            = ((decimal)a.Limt).ToString();
                                    break;

                                case 2:
                                    cash_balance_checkbox.Checked = true;
                                    cash_balance.Value            = ((decimal)a.Limt).ToString();
                                    break;

                                case 3:
                                    credit_balance_checkbox.Checked = true;
                                    credit_balance.Value            = ((decimal)a.Limt).ToString();
                                    break;

                                case 4:
                                    derivatives_checkbox.Checked = true;
                                    derivatives.Value            = ((decimal)a.Limt).ToString();
                                    break;

                                case 5:
                                    sbl_checkbox.Checked = true;
                                    sbl.Value            = ((decimal)a.Limt).ToString();
                                    break;

                                case 6:
                                    bond_checkbox.Checked = true;
                                    bond.Value            = ((decimal)a.Limt).ToString();
                                    break;

                                case 7:
                                    account6.Checked = true;

                                    break;

                                case 8:
                                    account07.Checked = true;
                                    anoter.Value      = ((decimal)a.Limt).ToString();

                                    break;

                                case 9:
                                    account7.Checked = true;

                                    break;

                                default:

                                    break;
                                }
                            }
                        }



                        drafDate.Value       = acc.draft_date;
                        suggester_name.Value = acc.suggester_name;
                        if (acc.type_Account.Contains("นิติบุคคล"))
                        {
                            InforCorporate commpany = new InforCorporate();
                            commpany = connect.InforCorporates.Where(a => a.CustNo == acc.CustNo).FirstOrDefault();
                            RadioTypeCompany.SelectedValue = commpany.typecompany;
                            string[] typelist = { "บริษัทจำกัด", "ห้างหุ้นส่วนจำกัด", "ห้างหุ้นส่วนสามัญนิติบุคคล", "บริษัทมหาชน" };
                            if (commpany.typecompany != null && !typelist.Contains(commpany.typecompany))
                            {
                                RadioTypeCompany.SelectedValue = "อื่นๆ";
                                txtOther.Value = commpany.typecompany;
                            }
                            nation.Value       = commpany.Nationality;
                            accComNo.Value     = commpany.RegisterNo;
                            regisDate.Value    = commpany.RegisterDate;
                            regiscontry.Value  = commpany.RegisteCountry;
                            taxNo.Value        = commpany.TaxID;
                            typeBisiness.Value = commpany.typebisiness;
                            regisCap.Value     = commpany.RegisteredCapital;
                            regisCapPaid.Value = commpany.Paid_up_capital;
                            another1.Value     = commpany.Another1;
                            another2.Value     = commpany.Another2;

                            Attorney atto = new Attorney();
                            atto                 = connect.Attorneys.Where(a => a.CustNo == acc.CustNo).FirstOrDefault();
                            NameNiti.Value       = atto.Name;
                            NITIEMPID.Value      = atto.IDCard;
                            idgov.Value          = atto.IDGovernment;
                            anothervisa.Value    = atto.Another;
                            attonation.Value     = atto.Nationality;
                            attodateexpire.Value = atto.Expired;
                            attodateget.Value    = atto.CreateDate;
                            attorelation.Value   = atto.relationship;
                            if (atto.IDCard != null)
                            {
                                visa.Checked = true;
                            }
                            if (atto.IDGovernment != null)
                            {
                                visa2.Checked = true;
                            }
                            if (atto.Another != null)
                            {
                                visa3.Checked = true;
                            }
                        }
                        else
                        {
                            CustInformation infor = new CustInformation();
                            infor = connect.CustInformations.Where(a => a.CustNo == acc.CustNo).FirstOrDefault();
                            if (infor != null)
                            {
                                sex_th_main.SelectedValue      = infor.Prefix1 != null ? infor.Prefix1 : "";
                                sex_en_main.SelectedValue      = infor.Prefix2 != null ? infor.Prefix2 : "";
                                fname_th_main.Value            = infor.FName1;
                                fname_en_main.Value            = infor.FName2;
                                lname_th_main.Value            = infor.LName1;
                                lname_en_main.Value            = infor.LName2;
                                birth_main.Value               = infor.BirthDate;
                                idCard_main.Value              = infor.IDCard;
                                IDGov_main.Value               = infor.IDGovernment;
                                nation_main.Value              = infor.Nationality;
                                passport_main.Value            = infor.PassportNo;
                                create_main.Value              = infor.CreateDate;
                                expire_main.Value              = infor.Expired;
                                tel_main.Value                 = infor.Tel;
                                RadioButtonList6.SelectedValue = infor.MaritalStatus != null ? infor.MaritalStatus : "";
                            }
                            addrIndex = new AddrCurrent();//work
                            addrIndex = addr.Where(a => a.TypeIDAdrr == 2 && a.CustNo == acc.CustNo).FirstOrDefault();
                            if (addrIndex != null)
                            {
                                workname_main.Value      = addrIndex.NameLocal;
                                no_work_main.Value       = addrIndex.No;
                                street_work_main.Value   = addrIndex.Street;
                                build_work_main.Value    = addrIndex.Building;
                                alley_work_main.Value    = addrIndex.Alley;
                                location_work_main.Value = addrIndex.Locality;
                                distric_work_main.Value  = addrIndex.District;
                                province_work_main.Value = addrIndex.Province;
                                zip_work_main.Value      = addrIndex.ZipCode;
                            }
                            addrIndex = new AddrCurrent();
                            addrIndex = addr.Where(a => a.TypeIDAdrr == 1 && a.CustNo == acc.CustNo).FirstOrDefault();
                            if (addrIndex != null)
                            {
                                no_main.Value       = addrIndex.No;
                                street_main.Value   = addrIndex.Street;
                                build_main.Value    = addrIndex.Building;
                                alley_main.Value    = addrIndex.Alley;
                                locatin_main.Value  = addrIndex.Locality;
                                distric_main.Value  = addrIndex.District;
                                province_main.Value = addrIndex.Province;
                                zip_main.Value      = addrIndex.ZipCode;
                                tel_main2.Value     = addrIndex.Tel;
                                fax_main.Value      = addrIndex.fax;
                            }

                            CareerInformation career = new CareerInformation();
                            career = connect.CareerInformations.Where(a => a.CustNo == acc.CustNo).FirstOrDefault();
                            if (career != null)
                            {
                                switch (career.ID)
                                {
                                case 1:
                                    RadioButton5.Checked = true;
                                    des910.Value         = career.AnnualSales;
                                    break;

                                case 2:
                                    RadioButton6.Checked = true;
                                    break;

                                case 3:
                                    RadioButton7.Checked = true;
                                    break;

                                default:
                                    RadioButton8.Checked = true;
                                    des990.Value         = connect.TypeCareers.Where(a => a.ID == career.ID).Select(a => a.Description).FirstOrDefault();
                                    break;
                                }
                                typebiss.Value          = career.Business;
                                positionbiss.Value      = career.Position;
                                salarybiss.Value        = career.Salary;
                                experanceworkbiss.Value = career.Experience;
                                incomebiss.Value        = career.OtherIncome;
                                incomebissHow.Value     = career.OtherSourcesIncome;
                                Political.SelectedValue = career.Political != null?career.Political.ToString() : "";

                                positionPolitical.Value = career.PoliticalPosition;
                            }


                            if (!String.IsNullOrEmpty(acc.CustNo_Mate))
                            {
                                mate.Visible = true;
                                infor        = new CustInformation();
                                infor        = connect.CustInformations.Where(a => a.CustNo == acc.CustNo_Mate).FirstOrDefault();
                                if (infor != null)
                                {
                                    RadioButtonList5.SelectedValue = infor.Prefix1 != null ? infor.Prefix1 : "";
                                    RadioButtonList4.SelectedValue = infor.Prefix2 != null ? infor.Prefix2 : "";
                                    mFnameTH.Value   = infor.FName1;
                                    mFnameEn.Value   = infor.FName2;
                                    mLnameTH.Value   = infor.LName1;
                                    mLnameEn.Value   = infor.LName2;
                                    mbirthDate.Value = infor.BirthDate;
                                    mIDCard.Value    = infor.IDCard;
                                    mIDGov0.Value    = infor.IDGovernment;
                                    mnation0.Value   = infor.Nationality;
                                    //  passport_main.Value = infor.PassportNo;
                                    mcreate0.Value   = infor.CreateDate;
                                    mexpire0.Value   = infor.Expired;
                                    mtelphone0.Value = infor.Tel;
                                }
                                addrIndex = new AddrCurrent();//work
                                addrIndex = addr.Where(a => a.TypeIDAdrr == 2 && a.CustNo == acc.CustNo_Mate).FirstOrDefault();
                                if (addrIndex != null)
                                {
                                    mWorkName.Value = addrIndex.NameLocal;
                                    mno.Value       = addrIndex.No;
                                    mstreet.Value   = addrIndex.Street;
                                    mbuild.Value    = addrIndex.Building;
                                    malley.Value    = addrIndex.Alley;
                                    mlocation.Value = addrIndex.Locality;
                                    mdistrict.Value = addrIndex.District;
                                    mprovine.Value  = addrIndex.Province;
                                    mzip.Value      = addrIndex.ZipCode;
                                    mtel.Value      = addrIndex.Tel;
                                    mfax.Value      = addrIndex.fax;
                                }


                                career = new CareerInformation();
                                career = connect.CareerInformations.Where(a => a.CustNo == acc.CustNo_Mate).FirstOrDefault();
                                if (career != null)
                                {
                                    switch (career.ID)
                                    {
                                    case 1:
                                        RadioButton1.Checked = true;
                                        mdes910.Value        = career.AnnualSales;
                                        break;

                                    case 2:
                                        RadioButton2.Checked = true;
                                        break;

                                    case 3:
                                        RadioButton3.Checked = true;
                                        break;

                                    default:
                                        RadioButton4.Checked = true;
                                        anotherType.Value    = connect.TypeCareers.Where(a => a.ID == career.ID).Select(a => a.Description).FirstOrDefault();
                                        break;
                                    }
                                    mtypebis.Value   = career.Business;
                                    mpositon.Value   = career.Position;
                                    msarary.Value    = career.Salary;
                                    mexperance.Value = career.Experience;
                                    income.Value     = career.OtherIncome;
                                    incomeHow.Value  = career.OtherSourcesIncome;
                                    RadioButtonList3.SelectedValue = career.Political != null?career.Political.ToString() : "";

                                    TEXT1.Value = career.PoliticalPosition;
                                }
                            }
                        }
                        addrIndex = new AddrCurrent();
                        addrIndex = addr.Where(a => a.TypeIDAdrr == 6 && a.CustNo == acc.CustNo).FirstOrDefault();
                        if (addrIndex != null)
                        {
                            No6.Value       = addrIndex.No;
                            street6.Value   = addrIndex.Street;
                            build6.Value    = addrIndex.Building;
                            alley6.Value    = addrIndex.Alley;
                            Locality6.Value = addrIndex.Locality;
                            District6.Value = addrIndex.District;
                            Province6.Value = addrIndex.Province;
                            zip6.Value      = addrIndex.ZipCode;
                            tel6.Value      = addrIndex.Tel;
                            fax6.Value      = addrIndex.TelPhone;
                            telphone6.Value = addrIndex.fax;
                            email6.Value    = addrIndex.Email;
                        }
                        addrIndex = new AddrCurrent();
                        addrIndex = addr.Where(a => a.TypeIDAdrr == 4 && a.CustNo == acc.CustNo).FirstOrDefault();
                        if (addrIndex != null)
                        {
                            No4.Value       = addrIndex.No;
                            street4.Value   = addrIndex.Street;
                            build4.Value    = addrIndex.Building;
                            alley4.Value    = addrIndex.Alley;
                            Locality4.Value = addrIndex.Locality;
                            District4.Value = addrIndex.District;
                            Province4.Value = addrIndex.Province;
                            zip4.Value      = addrIndex.ZipCode;
                            tel4.Value      = addrIndex.Tel;
                            fax4.Value      = addrIndex.TelPhone;
                            telphone4.Value = addrIndex.fax;
                            email4.Value    = addrIndex.Email;
                        }
                        addrIndex = new AddrCurrent();
                        addrIndex = addr.Where(a => a.TypeIDAdrr == 5 && a.CustNo == acc.CustNo).FirstOrDefault();
                        if (addrIndex != null)
                        {
                            No5.Value       = addrIndex.No;
                            street5.Value   = addrIndex.Street;
                            build5.Value    = addrIndex.Building;
                            alley5.Value    = addrIndex.Alley;
                            Locality5.Value = addrIndex.Locality;
                            District5.Value = addrIndex.District;
                            Province5.Value = addrIndex.Province;
                            zip5.Value      = addrIndex.ZipCode;
                            tel5.Value      = addrIndex.Tel;
                            fax5.Value      = addrIndex.TelPhone;
                            telphone5.Value = addrIndex.fax;
                            email5.Value    = addrIndex.Email;
                        }
                        RefPerSonInformation refPerson = new RefPerSonInformation();
                        refPerson = connect.RefPerSonInformations.Where(a => a.CustNo == acc.CustNo).FirstOrDefault();
                        if (refPerson != null)
                        {
                            RadiosexAnother.SelectedValue = refPerson.Prefix1;
                            FnamePerson.Value             = refPerson.FName1;
                            LnamePerson.Value             = refPerson.LName1;
                            relationPerson.Value          = refPerson.relationship;
                            Radioaddr.SelectedValue       = acc.SendAddr;
                        }
                        InforPayment payAcc = new InforPayment();
                        payAcc = connect.InforPayments.Where(a => a.CustNo == acc.CustNo).FirstOrDefault();
                        if (payAcc != null)
                        {
                            ATS.Checked                  = payAcc.ATS == null ? false : (bool)payAcc.ATS;
                            Bank1.Value                  = payAcc.Bank_1;
                            Bank2.Value                  = payAcc.Bank2;
                            ACC01.Value                  = payAcc.AccountN01;
                            ACC02.Value                  = payAcc.AccountN02;
                            Branch1.Value                = payAcc.Branch1;
                            Branch2.Value                = payAcc.Branch2;
                            e_Dividend.Checked           = payAcc.e_Dividend == null ? false : (bool)payAcc.e_Dividend;
                            RadioTypeACC01.SelectedValue = payAcc.TypeAccount1 != null ? payAcc.TypeAccount1 : "";
                            RadioTypeACC02.SelectedValue = payAcc.TypeAccount2 != null ? payAcc.TypeAccount2 : "";
                        }

                        CustInformation guilds = new CustInformation();
                        guilds = connect.CustInformations.Where(a => a.CustNo == acc.CustNo).FirstOrDefault();
                        if (guilds != null)
                        {
                            if (guilds.Guilty != null)
                            {
                                if ((bool)guilds.Guilty)
                                {
                                    guild.Checked = true;
                                }
                                else
                                {
                                    noguild.Checked = true;
                                }
                            }
                            dataguilds.Value = guilds.GuiltyDes;
                            yearguilds.Value = guilds.GuiltyYear;
                        }
                        role1.SelectedValue = acc.a_1.ToString();
                        role2.SelectedValue = acc.a_2.ToString();
                        role3.SelectedValue = acc.a_3.ToString();
                    }
                }
            }catch (Exception ee) {}
        }