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

namespace HySoft.BaseCallCenter.Web.smsmanage
{
    public partial class smsTypeEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Expires = -1;
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    Model.T_Sms_SmsModel T_Sms_SmsModel = new BLL.T_Sms_SmsModel().GetModel(Convert.ToInt32(Request.QueryString["id"]));
                    this.txtName.Text = T_Sms_SmsModel.Name;
                    this.txtContents.Text = T_Sms_SmsModel.Contents;
                    this.txtRemark.Text = T_Sms_SmsModel.Remark;
                }
            }
        }

        #region 保存信息

        private void SaveInfo()
        {
            try
            {
                if (!string.IsNullOrEmpty(Request.QueryString["action"]))
                {
                    if (Request.QueryString["action"].Trim() == "Add")
                    {
                        Model.T_Sms_SmsModel T_Sms_SmsModel=new Model.T_Sms_SmsModel();
                        T_Sms_SmsModel.Name = this.txtName.Text;
                        T_Sms_SmsModel.Contents = this.txtContents.Text;
                        T_Sms_SmsModel.Remark = this.txtRemark.Text;
                        T_Sms_SmsModel.AddTime = DateTime.Now;
                        T_Sms_SmsModel.State = "0";
                        LoginUser p_LoginUser = new LoginUser(this.Context);
                        if (p_LoginUser != null)
                        {
                            T_Sms_SmsModel.AddPeople = p_LoginUser.UserCode;
                        }
                        int bl = new BLL.T_Sms_SmsModel().Add(T_Sms_SmsModel);
                        if (bl > 0)
                        {
                            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>SaveInfo('success')</script>");
                        }
                        else
                        {
                            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>SaveInfo('warn')</script>");
                        }
                    }
                    if (Request.QueryString["action"].Trim() == "Modify")
                    {
                        Model.T_Sms_SmsModel T_Sms_SmsModel = new BLL.T_Sms_SmsModel().GetModel(Convert.ToInt32(Request.QueryString["id"])); ;
                        T_Sms_SmsModel.Name = this.txtName.Text;
                        T_Sms_SmsModel.Contents = this.txtContents.Text;
                        T_Sms_SmsModel.Remark = this.txtRemark.Text;
                        LoginUser p_LoginUser = new LoginUser(this.Context);
                        if (p_LoginUser != null)
                        {
                            T_Sms_SmsModel.EditPeople = p_LoginUser.UserCode;
                        }
                        T_Sms_SmsModel.EditTime = DateTime.Now;
                        bool bl = new BLL.T_Sms_SmsModel().Update(T_Sms_SmsModel);
                        if (bl)
                        {
                            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>");
            }
        }

        #endregion

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            SaveInfo();
        }
    }
}