using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using DSWeb.DataAccess;
using System.Data.SqlClient;
using DSWeb.Models;
using DSWeb.EntityDA;
using System.Web.Script.Serialization;

namespace DSWeb.CRM
{
    public partial class CRMClientContactInfo : System.Web.UI.Page
    {
        public string strHandleType = String.Empty;
        public string sSQL = String.Empty;
        public string gvid = String.Empty;
        T_ALL_DA T_ALL_DA = new T_ALL_DA();
        MoneyConvert MoneyConvert = new MoneyConvert();
        TopSeaeEntity TopSeaeEntity = new TopSeaeEntity();
        SeaExportInfoDA SeaExportInfoDA = new SeaExportInfoDA();
        RangeDA RangeDA = new RangeDA();
        public string strUserID;//用户GID

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["USERID"] != null)
            {
                strUserID = Session["USERID"].ToString().Trim();
                hdUserID.Value = strUserID.Trim();
            }
            else
            {
                Server.Transfer("~/Error/FriendError.aspx");
                return;
                //strUserID = ""; 
                //hdUserID.Value = strUserID.Trim();
            }
            //
            if (Request.QueryString["isenabled"] != null)//if (Request.QueryString["id"] != null)
            {
                ViewState["isenabled"] = Request.QueryString["isenabled"].ToString();
                this.hdEnabled.Value = ViewState["isenabled"].ToString().Trim();
            }
            //
            if (!IsPostBack)
            {
                if (Request.QueryString["handle"] != null) //if (Request.QueryString["handle"] != null)
                {
                    ViewState["strHandleType"] = Request.QueryString["handle"].ToString();//"edit";
                    strHandleType = ViewState["strHandleType"].ToString().Trim();
                    if (Request.QueryString["id"] != null)//if (Request.QueryString["id"] != null)
                    {
                        ViewState["GID"] = Request.QueryString["id"].ToString();//"topseaeusername129481962859531250";
                        this.hdGid.Value = ViewState["GID"].ToString().Trim();
                    }
                    if (Request.QueryString["LINKID"] != null)//if (Request.QueryString["id"] != null)
                    {
                        ViewState["LINKID"] = Request.QueryString["LINKID"].ToString();
                    }
                    else
                    {
                        ViewState["LINKID"] = "";
                        if (Request.QueryString["id"] != null)//if (Request.QueryString["id"] != null)
                        {
                            ViewState["LINKID"] = T_ALL_DA.GetStrSQL("LINKID", "select LINKID from info_client_contact where GID='" + ViewState["GID"].ToString().Trim() + "'");
                        }
                    }
                    if (Request.QueryString["isenabled"] != null)//if (Request.QueryString["id"] != null)
                    {
                        ViewState["isenabled"] = Request.QueryString["isenabled"].ToString();
                        this.hdEnabled.Value = ViewState["isenabled"].ToString().Trim();
                    }
                    //
                    switch (strHandleType)
                    {
                        case "add"://新增
                            ViewState["GID"] = getBSNO();
                            this.hdGid.Value = ViewState["GID"].ToString().Trim();
                            //
                            cbISSTOP.Checked = false;
                            tbSHOWNAME.Text = "";
                            tbADDR.Text = "";
                            tbEMAIL.Text = "";
                            tbTEL1.Text = "86";
                            tbTEL2.Text = "";
                            tbTEL.Text = "";
                            tbFAX1.Text = "86";
                            tbFAX2.Text = "";
                            tbFAX.Text = "";
                            tbMOBILE1.Text = "86";
                            tbMOBILE.Text = "";
                            tbREMARK.Text = "";
                            tbBIRTHDAY.Text = "";
                            tbANNIVERSARY1.Text = "";
                            tbAREMARK1.Text = "";
                            tbANNIVERSARY2.Text = "";
                            tbAREMARK2.Text = "";
                            cbBIRTHDAY.Checked = false;
                            cbANNIVERSARY1.Checked = false;
                            cbANNIVERSARY2.Checked = false;
                            tbBIRTHDAYDAY.Text = "0";
                            tbANNIVERSARYDAY1.Text = "0";
                            tbANNIVERSARYDAY2.Text = "0";
                            tbJOB.Text = "";
                            //rblSEX.SelectedValue.Text = "";
                            tbAGE.Text = "";
                            //ddlMARRY.Text = "";
                            tbCHILDREN.Text = "";
                            tbHOBBIES.Text = "";
                            break;
                        case "edit"://录入
                            DataSet ds = T_ALL_DA.GetAllSQL(" select * from info_client_contact where ISDELETED=0 and GID='" + ViewState["GID"].ToString().Trim() + "'");
                            //
                            if (ds == null)
                            {
                                return;
                            }
                            if (ds.Tables[0].Rows[0]["ISSTOP"].ToString().Trim() == "True")
                            {
                                cbISSTOP.Checked = true;
                            }
                            else
                            {
                                cbISSTOP.Checked = false;
                            }
                            //
                            tbSHOWNAME.Text = ds.Tables[0].Rows[0]["SHOWNAME"].ToString().Trim();
                            tbADDR.Text = ds.Tables[0].Rows[0]["ADDR"].ToString().Trim();
                            tbEMAIL.Text = ds.Tables[0].Rows[0]["EMAIL"].ToString().Trim();
                            //
                            int itel = ds.Tables[0].Rows[0]["TEL"].ToString().Trim().IndexOf("-");
                            if (itel != 0)
                            {
                                string[] strTELs = ds.Tables[0].Rows[0]["TEL"].ToString().Trim().Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
                                for (int i = 1; i < strTELs.Length; i++)
                                {
                                    if (strTELs[i].Trim() == "" && i == 0)
                                    {
                                        tbTEL1.Text = "86";
                                    }
                                    else
                                    {
                                        tbTEL1.Text = strTELs[0].Trim();
                                    }
                                    if (strTELs[i].Trim() == "" && i == 1)
                                    {
                                        tbTEL2.Text = "";
                                    }
                                    else
                                    {
                                        tbTEL2.Text = strTELs[1].Trim();
                                    }
                                    if (strTELs[i].Trim() == "" && i == 2)
                                    {
                                        tbTEL.Text = "";
                                    }
                                    else
                                    {
                                        tbTEL.Text = strTELs[2].Trim();
                                    }
                                }
                            }
                            else
                            {
                                tbTEL1.Text = "86";
                                tbTEL2.Text = "";
                                tbTEL.Text = "";
                            }
                            //
                            int iFAX = ds.Tables[0].Rows[0]["FAX"].ToString().Trim().IndexOf("-");
                            if (iFAX != 0)
                            {
                                string[] strFAXs = ds.Tables[0].Rows[0]["FAX"].ToString().Trim().Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
                                for (int i = 1; i < strFAXs.Length; i++)
                                {
                                    if (strFAXs[i].Trim() == "" && i == 0)
                                    {
                                        tbFAX1.Text = "86";
                                    }
                                    else
                                    {
                                        tbFAX1.Text = strFAXs[0].Trim();
                                    }
                                    if (strFAXs[i].Trim() == "" && i == 1)
                                    {
                                        tbFAX2.Text = "";
                                    }
                                    else
                                    {
                                        tbFAX2.Text = strFAXs[1].Trim();
                                    }
                                    if (strFAXs[i].Trim() == "" && i == 2)
                                    {
                                        tbFAX.Text = "";
                                    }
                                    else
                                    {
                                        tbFAX.Text = strFAXs[2].Trim();
                                    }
                                }
                            }
                            else
                            {
                                tbFAX1.Text = "86";
                                tbFAX2.Text = "";
                                tbFAX.Text = "";
                            }
                            //
                            int iMOBILE = ds.Tables[0].Rows[0]["MOBILE"].ToString().Trim().IndexOf("-");
                            if (iMOBILE != 0)
                            {
                                string[] strMOBILEs = ds.Tables[0].Rows[0]["MOBILE"].ToString().Trim().Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
                                for (int i = 1; i < strMOBILEs.Length; i++)
                                {
                                    if (strMOBILEs[i].Trim() == "" && i == 0)
                                    {
                                        tbMOBILE1.Text = "86";
                                    }
                                    else
                                    {
                                        tbMOBILE1.Text = strMOBILEs[0].Trim();
                                    }
                                    if (strMOBILEs[i].Trim() == "" && i == 1)
                                    {
                                        tbMOBILE.Text = "";
                                    }
                                    else
                                    {
                                        tbMOBILE.Text = strMOBILEs[1].Trim();
                                    }
                                }
                            }
                            else
                            {
                                tbMOBILE1.Text = "86";
                                tbMOBILE.Text = "";
                            }
                            //
                            tbREMARK.Text = ds.Tables[0].Rows[0]["REMARK"].ToString().Trim();
                            tbBIRTHDAY.Text = "";
                            tbANNIVERSARY1.Text = "";
                            tbANNIVERSARY2.Text = "";
                            if (ds.Tables[0].Rows[0]["BIRTHDAY"].ToString().Trim() != "")
                            {
                                tbBIRTHDAY.Text = DateTime.Parse(ds.Tables[0].Rows[0]["BIRTHDAY"].ToString().Trim()).ToString("yyyy-MM-dd");
                            }
                            if (ds.Tables[0].Rows[0]["ANNIVERSARY1"].ToString().Trim() != "")
                            {
                                tbANNIVERSARY1.Text = DateTime.Parse(ds.Tables[0].Rows[0]["ANNIVERSARY1"].ToString().Trim()).ToString("yyyy-MM-dd");
                            }
                            if (ds.Tables[0].Rows[0]["ANNIVERSARY2"].ToString().Trim() != "")
                            {
                                tbANNIVERSARY2.Text = DateTime.Parse(ds.Tables[0].Rows[0]["ANNIVERSARY2"].ToString().Trim()).ToString("yyyy-MM-dd");
                            }
                            tbAREMARK1.Text = ds.Tables[0].Rows[0]["AREMARK1"].ToString().Trim();
                            tbAREMARK2.Text = ds.Tables[0].Rows[0]["AREMARK2"].ToString().Trim();
                            cbBIRTHDAY.Checked = ds.Tables[0].Rows[0]["ISBIRTHDAY"].ToString().Trim() == "False" ? false : true;
                            cbANNIVERSARY1.Checked = ds.Tables[0].Rows[0]["ISANNIVERSARY1"].ToString().Trim() == "False" ? false : true;
                            cbANNIVERSARY2.Checked = ds.Tables[0].Rows[0]["ISANNIVERSARY2"].ToString().Trim() == "False" ? false : true;
                            tbBIRTHDAYDAY.Text = ds.Tables[0].Rows[0]["BIRTHDAYDAY"].ToString().Trim() == "" ? "0" : ds.Tables[0].Rows[0]["BIRTHDAYDAY"].ToString().Trim();
                            tbANNIVERSARYDAY1.Text = ds.Tables[0].Rows[0]["ANNIVERSARYDAY1"].ToString().Trim() == "" ? "0" : ds.Tables[0].Rows[0]["ANNIVERSARYDAY1"].ToString().Trim();
                            tbANNIVERSARYDAY2.Text = ds.Tables[0].Rows[0]["ANNIVERSARYDAY2"].ToString().Trim() == "" ? "0" : ds.Tables[0].Rows[0]["ANNIVERSARYDAY2"].ToString().Trim();
                            tbJOB.Text = ds.Tables[0].Rows[0]["AREMARK2"].ToString().Trim();
                            rblSEX.SelectedValue = ds.Tables[0].Rows[0]["SEX"].ToString().Trim();
                            tbAGE.Text = ds.Tables[0].Rows[0]["AGE"].ToString().Trim();
                            ddlMARRY.Text = ds.Tables[0].Rows[0]["MARRY"].ToString().Trim();
                            tbCHILDREN.Text = ds.Tables[0].Rows[0]["CHILDREN"].ToString().Trim();
                            tbHOBBIES.Text = ds.Tables[0].Rows[0]["HOBBIES"].ToString().Trim();

                            //权限可视范围
                            string strV = RangeDA.GetVISIBLERANGE(strUserID.Trim(), "modCRMClientList");
                            string strO = RangeDA.GetOPERATERANGE(strUserID.Trim(), "modCRMClientList");
                            string alt = "";
                            if (strV.Trim().Equals("4"))//全部
                            {
                                ibAdd.Enabled = true;
                            }
                            else if (strV.Trim().Equals("1"))//分公司
                            {
                                if (strO.Trim().Equals("1"))//公司
                                {
                                    alt = RangeDA.GetCRMClientListCompany(strUserID.Trim(), ViewState["LINKID"].ToString().Trim());
                                    if (alt == "")
                                    {
                                        getEnabled();
                                    }
                                }
                                else if (strO.Trim().Equals("3"))//个人
                                {
                                    alt = RangeDA.GetCRMClientListPerson(strUserID.Trim(), ViewState["LINKID"].ToString().Trim());
                                    if (alt == "")
                                    {
                                        getEnabled();
                                    }
                                }
                            }
                            else if (strV.Trim().Equals("3"))
                            {
                                if (strO.Trim().Equals("3"))//个人
                                {
                                    alt = RangeDA.GetCRMClientListPerson(strUserID.Trim(), ViewState["LINKID"].ToString().Trim());
                                    if (alt == "")
                                    {
                                        getEnabled();
                                    }
                                }
                                else if (strO.Trim().Equals("4"))//无
                                {
                                    getEnabled();
                                }
                            }
                            //
                            break;
                    }
                    //
                    if (this.hdEnabled.Value.Trim() == "false")
                    {
                        getEnabled();
                    }
                }
                else
                {
                }
            }
            //
            if (this.hdEnabled.Value.ToString() == "false")
            {
                getEnabled();
            }
        }
        protected void getEnabled()
        {
            ibAdd.Enabled = false;
            ibEnter.Disabled = true;
            ibDel.Enabled = false;
            //
            cbISSTOP.Enabled = false;
            tbSHOWNAME.Enabled = false;
            tbADDR.Enabled = false;
            tbEMAIL.Enabled = false;
            tbTEL1.Enabled = false;
            tbTEL2.Enabled = false;
            tbTEL.Enabled = false;
            tbFAX1.Enabled = false;
            tbFAX2.Enabled = false;
            tbFAX.Enabled = false;
            tbMOBILE1.Enabled = false;
            tbMOBILE.Enabled = false;
            tbREMARK.Enabled = false;
            tbBIRTHDAY.Enabled = false;
            tbANNIVERSARY1.Enabled = false;
            tbAREMARK1.Enabled = false;
            tbANNIVERSARY2.Enabled = false;
            tbAREMARK2.Enabled = false;
            cbBIRTHDAY.Enabled = false;
            cbANNIVERSARY1.Enabled = false;
            cbANNIVERSARY2.Enabled = false;
            tbBIRTHDAYDAY.Enabled = false;
            tbANNIVERSARYDAY1.Enabled = false;
            tbANNIVERSARYDAY2.Enabled = false;
            tbJOB.Enabled = false;
            rblSEX.Enabled = false;
            tbAGE.Enabled = false;
            ddlMARRY.Enabled = false;
            tbCHILDREN.Enabled = false;
            tbHOBBIES.Enabled = false;
        }
        protected String getBSNO()
        {
            string strBSNO = Guid.NewGuid().ToString();
            strBSNO = strBSNO.Replace("-", "");
            strBSNO = "Clie" + strBSNO;
            return strBSNO;
        }
        protected bool getAdd()
        {
            
            string alt = "";
            int iBIRTHDAYDAY = tbBIRTHDAYDAY.Text.Trim() == "" ? 0 : int.Parse(tbBIRTHDAYDAY.Text.Trim());
            int iANNIVERSARYDAY1 = tbANNIVERSARYDAY1.Text.Trim() == "" ? 0 : int.Parse(tbANNIVERSARYDAY1.Text.Trim());
            int iANNIVERSARYDAY2 = tbANNIVERSARYDAY2.Text.Trim() == "" ? 0 : int.Parse(tbANNIVERSARYDAY2.Text.Trim());
            alt = T_ALL_DA.GetInfoClientInsertContact(ViewState["GID"].ToString().Trim(), ViewState["LINKID"].ToString().Trim(), cbISSTOP.Checked, false, false, false, false, "", tbSHOWNAME.Text, tbTEL1.Text + "-" + tbTEL2.Text + "-" + tbTEL.Text, tbFAX1.Text + "-" + tbFAX2.Text + "-" + tbFAX.Text, tbMOBILE1.Text.Trim() + "-" + tbMOBILE.Text.Trim(), tbADDR.Text, tbEMAIL.Text, tbREMARK.Text, strUserID.Trim(), tbBIRTHDAY.Text, tbANNIVERSARY1.Text, tbAREMARK1.Text, tbANNIVERSARY2.Text, tbAREMARK2.Text, cbBIRTHDAY.Checked, cbANNIVERSARY1.Checked, cbANNIVERSARY2.Checked, iBIRTHDAYDAY, iANNIVERSARYDAY1, iANNIVERSARYDAY2, tbJOB.Text, rblSEX.SelectedValue.Trim(), tbAGE.Text, ddlMARRY.Text, tbCHILDREN.Text, tbHOBBIES.Text);
            if (alt == "")
            {
                ViewState["strHandleType"] = "edit";
                return true;
            }
            else
            {
                return false;
            }
        }
        protected bool getEdit()
        {
            string alt = "";
            int iBIRTHDAYDAY = tbBIRTHDAYDAY.Text.Trim() == "" ? 0 : int.Parse(tbBIRTHDAYDAY.Text.Trim());
            int iANNIVERSARYDAY1 = tbANNIVERSARYDAY1.Text.Trim() == "" ? 0 : int.Parse(tbANNIVERSARYDAY1.Text.Trim());
            int iANNIVERSARYDAY2 = tbANNIVERSARYDAY2.Text.Trim() == "" ? 0 : int.Parse(tbANNIVERSARYDAY2.Text.Trim());
            alt = T_ALL_DA.GetInfoClientUpdateContact(ViewState["LINKID"].ToString().Trim(), ViewState["GID"].ToString().Trim(), cbISSTOP.Checked, false, false, false, false, "", tbSHOWNAME.Text, tbTEL1.Text + "-" + tbTEL2.Text + "-" + tbTEL.Text, tbFAX1.Text + "-" + tbFAX2.Text + "-" + tbFAX.Text, tbMOBILE1.Text.Trim() + "-" + tbMOBILE.Text.Trim(), tbADDR.Text, tbEMAIL.Text, tbREMARK.Text, strUserID.Trim(), tbBIRTHDAY.Text, tbANNIVERSARY1.Text, tbAREMARK1.Text, tbANNIVERSARY2.Text, tbAREMARK2.Text, cbBIRTHDAY.Checked, cbANNIVERSARY1.Checked, cbANNIVERSARY2.Checked, iBIRTHDAYDAY, iANNIVERSARYDAY1, iANNIVERSARYDAY2, tbJOB.Text, rblSEX.SelectedValue.Trim(), tbAGE.Text, ddlMARRY.Text, tbCHILDREN.Text, tbHOBBIES.Text);
            if (alt == "")
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        protected void btnEnter_Click(object sender, EventArgs e)
        {
            bool bl = false;
            strHandleType = ViewState["strHandleType"].ToString();
            if (strHandleType.Equals("add"))//新增
            {
                bl = getAdd();
            }
            else if (strHandleType.Equals("edit"))//录入
            {
                bl = getEdit();
            }
            ibDel.Enabled = true;
            ibAdd.Enabled = true;
            if (bl)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "key0", "<script>alert('成功提交!');</script>");
                return;
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('出错,请重新填写!');</script>");
                return;
            }
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            ViewState["strHandleType"] = "add";
            ViewState["GID"] = getBSNO();
            this.hdGid.Value = ViewState["GID"].ToString().Trim();
            //
            cbISSTOP.Checked = false;
            tbSHOWNAME.Text = "";
            tbADDR.Text = "";
            tbEMAIL.Text = "";
            tbTEL1.Text = "86";
            tbTEL2.Text = "";
            tbTEL.Text = "";
            tbFAX1.Text = "86";
            tbFAX2.Text = "";
            tbFAX.Text = "";
            tbREMARK.Text = "";
            tbBIRTHDAY.Text = "";
            tbANNIVERSARY1.Text = "";
            tbAREMARK1.Text = "";
            tbANNIVERSARY2.Text = "";
            tbAREMARK2.Text = "";
            cbBIRTHDAY.Checked = false;
            cbANNIVERSARY1.Checked = false;
            cbANNIVERSARY2.Checked = false;
            tbBIRTHDAYDAY.Text = "0";
            tbANNIVERSARYDAY1.Text = "0";
            tbANNIVERSARYDAY2.Text = "0";
            tbJOB.Text = "";
            //rblSEX.SelectedValue.Text = "";
            tbAGE.Text = "";
            //ddlMARRY.Text = "";
            tbCHILDREN.Text = "";
            tbHOBBIES.Text = "";
            //
            ibDel.Enabled = false;
            ibAdd.Enabled = true;
            ibEnter.Disabled = false;
        }
        protected void btnDel_Click(object sender, EventArgs e)
        {
            string alt = T_ALL_DA.GetInfoClientContactDel(ViewState["GID"].ToString().Trim(), strUserID.Trim());
            if (alt != "")
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('" + alt + "');</script>");
                return;
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "key3", "<script>alert('删除成功!');window.opener.location.reload();history.back();</script>");
            }
            //
            ViewState["strHandleType"] = "edit";
            DataSet ds = T_ALL_DA.GetAllSQL("select top 1 * from info_client order by CODENAME");
            //
            if (ds == null)
            {
                return;
            }
            //
            if (ds.Tables[0].Rows[0]["ISSTOP"].ToString().Trim() == "True")
            {
                cbISSTOP.Checked = true;
            }
            else
            {
                cbISSTOP.Checked = false;
            }
            //
            tbSHOWNAME.Text = ds.Tables[0].Rows[0]["SHOWNAME"].ToString().Trim();
            tbADDR.Text = ds.Tables[0].Rows[0]["ADDR"].ToString().Trim();
            tbEMAIL.Text = ds.Tables[0].Rows[0]["EMAIL"].ToString().Trim();
            //
            int itel = ds.Tables[0].Rows[0]["TEL"].ToString().Trim().IndexOf("-");
            if (itel != 0)
            {
                string[] strTELs = ds.Tables[0].Rows[0]["TEL"].ToString().Trim().Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 1; i < strTELs.Length; i++)
                {
                    if (strTELs[i].Trim() == "" && i == 0)
                    {
                        tbTEL1.Text = "86";
                    }
                    else
                    {
                        tbTEL1.Text = strTELs[0].Trim();
                    }
                    if (strTELs[i].Trim() == "" && i == 1)
                    {
                        tbTEL2.Text = "";
                    }
                    else
                    {
                        tbTEL2.Text = strTELs[1].Trim();
                    }
                    if (strTELs[i].Trim() == "" && i == 2)
                    {
                        tbTEL.Text = "";
                    }
                    else
                    {
                        tbTEL.Text = strTELs[2].Trim();
                    }
                }
            }
            else
            {
                tbTEL1.Text = "86";
                tbTEL2.Text = "";
                tbTEL.Text = "";
            }
            //
            int iFAX = ds.Tables[0].Rows[0]["FAX"].ToString().Trim().IndexOf("-");
            if (iFAX != 0)
            {
                string[] strFAXs = ds.Tables[0].Rows[0]["FAX"].ToString().Trim().Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 1; i < strFAXs.Length; i++)
                {
                    if (strFAXs[i].Trim() == "" && i == 0)
                    {
                        tbFAX1.Text = "86";
                    }
                    else
                    {
                        tbFAX1.Text = strFAXs[0].Trim();
                    }
                    if (strFAXs[i].Trim() == "" && i == 1)
                    {
                        tbFAX2.Text = "";
                    }
                    else
                    {
                        tbFAX2.Text = strFAXs[1].Trim();
                    }
                    if (strFAXs[i].Trim() == "" && i == 2)
                    {
                        tbFAX.Text = "";
                    }
                    else
                    {
                        tbFAX.Text = strFAXs[2].Trim();
                    }
                }
            }
            else
            {
                tbFAX1.Text = "86";
                tbFAX2.Text = "";
                tbFAX.Text = "";
            }
            //
            int iMOBILE = ds.Tables[0].Rows[0]["MOBILE"].ToString().Trim().IndexOf("-");
            if (iMOBILE != 0)
            {
                string[] strMOBILEs = ds.Tables[0].Rows[0]["MOBILE"].ToString().Trim().Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 1; i < strMOBILEs.Length; i++)
                {
                    if (strMOBILEs[i].Trim() == "" && i == 0)
                    {
                        tbMOBILE1.Text = "86";
                    }
                    else
                    {
                        tbMOBILE1.Text = strMOBILEs[0].Trim();
                    }
                    if (strMOBILEs[i].Trim() == "" && i == 1)
                    {
                        tbMOBILE.Text = "";
                    }
                    else
                    {
                        tbMOBILE.Text = strMOBILEs[1].Trim();
                    }
                }
            }
            else
            {
                tbMOBILE1.Text = "86";
                tbMOBILE.Text = "";
            }
            //
            tbREMARK.Text = ds.Tables[0].Rows[0]["REMARK"].ToString().Trim();
            tbBIRTHDAY.Text = "";
            tbANNIVERSARY1.Text = "";
            tbANNIVERSARY2.Text = "";
            if (ds.Tables[0].Rows[0]["BIRTHDAY"].ToString().Trim() != "")
            {
                tbBIRTHDAY.Text = DateTime.Parse(ds.Tables[0].Rows[0]["BIRTHDAY"].ToString().Trim()).ToString("yyyy-MM-dd");
            }
            if (ds.Tables[0].Rows[0]["ANNIVERSARY1"].ToString().Trim() != "")
            {
                tbANNIVERSARY1.Text = DateTime.Parse(ds.Tables[0].Rows[0]["ANNIVERSARY1"].ToString().Trim()).ToString("yyyy-MM-dd");
            }
            if (ds.Tables[0].Rows[0]["ANNIVERSARY2"].ToString().Trim() != "")
            {
                tbANNIVERSARY2.Text = DateTime.Parse(ds.Tables[0].Rows[0]["ANNIVERSARY2"].ToString().Trim()).ToString("yyyy-MM-dd");
            }
            tbAREMARK1.Text = ds.Tables[0].Rows[0]["AREMARK1"].ToString().Trim();
            tbAREMARK2.Text = ds.Tables[0].Rows[0]["AREMARK2"].ToString().Trim();
            cbBIRTHDAY.Checked = ds.Tables[0].Rows[0]["ISBIRTHDAY"].ToString().Trim() == "False" ? false : true;
            cbANNIVERSARY1.Checked = ds.Tables[0].Rows[0]["ISANNIVERSARY1"].ToString().Trim() == "False" ? false : true;
            cbANNIVERSARY2.Checked = ds.Tables[0].Rows[0]["ISANNIVERSARY2"].ToString().Trim() == "False" ? false : true;
            tbBIRTHDAYDAY.Text = ds.Tables[0].Rows[0]["BIRTHDAYDAY"].ToString().Trim() == "" ? "0" : ds.Tables[0].Rows[0]["BIRTHDAYDAY"].ToString().Trim();
            tbANNIVERSARYDAY1.Text = ds.Tables[0].Rows[0]["ANNIVERSARYDAY1"].ToString().Trim() == "" ? "0" : ds.Tables[0].Rows[0]["ANNIVERSARYDAY1"].ToString().Trim();
            tbANNIVERSARYDAY2.Text = ds.Tables[0].Rows[0]["ANNIVERSARYDAY2"].ToString().Trim() == "" ? "0" : ds.Tables[0].Rows[0]["ANNIVERSARYDAY2"].ToString().Trim();
            tbJOB.Text = ds.Tables[0].Rows[0]["AREMARK2"].ToString().Trim();
            rblSEX.SelectedValue = ds.Tables[0].Rows[0]["SEX"].ToString().Trim();
            tbAGE.Text = ds.Tables[0].Rows[0]["AGE"].ToString().Trim();
            ddlMARRY.Text = ds.Tables[0].Rows[0]["MARRY"].ToString().Trim();
            tbCHILDREN.Text = ds.Tables[0].Rows[0]["CHILDREN"].ToString().Trim();
            tbHOBBIES.Text = ds.Tables[0].Rows[0]["HOBBIES"].ToString().Trim();
            //
            ibDel.Enabled = false;
            ibAdd.Enabled = false;
        }
        public bool IsNumeric(string s)
        {
            bool bReturn = true;
            try
            {
                int inum = int.Parse(s);
            }
            catch
            {
                bReturn = false;
            }
            return bReturn;
        }

    }
}