using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HySoft.BaseCallCenter.Web.telmanage
{
    public partial class mobiledatalistAddandEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Expires = -1;
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["singleFlage"]))
                {
                    Initialize(Request.QueryString["singleFlage"]);
                }
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            SaveInfo();
        }
        private void SaveInfo()
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(Request.QueryString["actionFlag"].Trim()))
                {
                    string actionFlag = Request.QueryString["actionFlag"].Trim();
                    if (actionFlag == "add")
                    {
                        bool bl = new BLL.T_Sys_MobileData().Add(T_Sys_MobileData);
                        if (bl)
                        {
                            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>SaveInfo('success')</script>");
                        }
                        else
                        {
                            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>SaveInfo('warn')</script>");
                        }
                    }
                    if (actionFlag == "edit")
                    {
                        bool b2 = new BLL.T_Sys_MobileData().Update(T_Sys_MobileData);
                        if (b2)
                        {
                            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>SaveInfo('success')</script>");
                        }
                        else
                        {
                            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>SaveInfo('warn')</script>");
                        }
                    }
                }
            }
            catch
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>SaveInfo('error')</script>");
            }
        }
        #region 信息初始化

        private void Initialize(string id)
        {
            T_Sys_MobileData = new BLL.T_Sys_MobileData().GetModel(id);
        }
        #endregion
        #region 公共属性
        private Model.T_Sys_MobileData T_Sys_MobileData
        {
            get
            {
                Model.T_Sys_MobileData _model = new Model.T_Sys_MobileData();
                if (!string.IsNullOrWhiteSpace(txtMobileNum.Text.Trim()))
                {
                    _model.F_MobileNum = txtMobileNum.Text.Trim();
                }
                if (!string.IsNullOrWhiteSpace(txtZipCode.Text.Trim()))
                {
                    _model.F_ZipCode = txtZipCode.Text.Trim();
                }
                if (!string.IsNullOrWhiteSpace(txtCityDes.Text.Trim()))
                {
                    _model.F_CityDes = txtCityDes.Text.Trim();
                }
                if (!string.IsNullOrWhiteSpace(txtCardDes.Text.Trim()))
                {
                    _model.F_CardDes = txtCardDes.Text.Trim();
                }
                return _model;
            }
            set
            {
                if (value != null)
                {
                    txtMobileNum.Text = value.F_MobileNum;
                    txtZipCode.Text = value.F_ZipCode;
                    txtCityDes.Text = value.F_CityDes;
                    txtCardDes.Text = value.F_CardDes;
                }
            }
        }
        #endregion
    }
}