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.sysmanage
{
    public partial class configedit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                //初始化方法
                if (Request.QueryString["action"].ToString() == "Edit") {

                    getSystrmConfig(Request.QueryString["param"].ToString());
                }
            
            }
        }


        /// <summary>
        /// 初始化参数方法
        /// </summary>
        /// <param name="fla"></param>
        private void getSystrmConfig(string fla)
        {
            if (!string.IsNullOrEmpty(fla)) {
              HySoft.BaseCallCenter.Model.T_Sys_SystemConfig systemConfigModel =  new BLL.T_Sys_SystemConfig().GetModel(Convert.ToInt32(fla));
              if (systemConfigModel != null) {
                  txtSystemCode.Text = systemConfigModel.F_ParamCode;
                  txtSystemName.Text = systemConfigModel.F_ParamDes;
                  txtSystemValue.Text = systemConfigModel.F_ParamValue;
                  txtId.Value = systemConfigModel.F_ParamId.ToString();
              }
            }
        }

        /// <summary>
        /// 保存参数设置的信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    int res = 0;
            //    bool flage = false;
            //    HySoft.BaseCallCenter.Model.T_Sys_SystemConfig systemConfigModel = new Model.T_Sys_SystemConfig();
            //    HySoft.BaseCallCenter.BLL.T_Sys_SystemConfig systemConfigBll = new BLL.T_Sys_SystemConfig();
            //    HySoft.BaseCallCenter.BLL.T_OrderBase orderBaseBll = new BLL.T_OrderBase();
            //    if (Request.QueryString["action"] == "Add")
            //    {
            //        systemConfigModel.F_ParamCode = orderBaseBll.GetNewOrderCode("F_ParamCode", "F_ParamId", "T_Sys_SystemConfig");
            //    }
            //    else { 
            //       systemConfigModel.F_ParamCode  =new BLL.T_Sys_SystemConfig().GetModel(Convert.ToInt32(Request.QueryString["param"])).F_ParamCode;
            //    }
            //    if (!string.IsNullOrEmpty(txtSystemName.Text))
            //    {
            //        systemConfigModel.F_ParamDes = txtSystemName.Text;
            //    }
            //    else {
            //        MessageBoxToWindow("参数名称不为空!", "提示", "catch");
            //    }


            //    if (!string.IsNullOrEmpty(txtSystemValue.Text))
            //    {
            //        systemConfigModel.F_ParamValue = txtSystemValue.Text;
            //    }
            //    else
            //    {
            //        MessageBoxToWindow("参数值不为空!", "提示", "catch");
            //    }
               
            //    systemConfigModel.F_State = 0;
            //    if (Request.QueryString["action"] == "Add")
            //    {
            //        res = systemConfigBll.Add(systemConfigModel);
            //        if (res > 0)
            //        {
            //            MessageBoxToWindow("新增成功", "新增提示", "success");
            //        }
            //        else
            //        {
            //            MessageBoxToWindow("新增失败", "新增提示！", "error");
            //        }

            //    }
            //    if (Request.QueryString["action"] == "Edit")
            //    {
            //        systemConfigModel.F_ParamId = Convert.ToInt32(Request.QueryString["param"]);
            //        flage = systemConfigBll.Update(systemConfigModel);
            //        if (flage)
            //        {
            //            MessageBoxToWindow("修改成功", "修改提示！", "success");
            //        }
            //        else
            //        {
            //            MessageBoxToWindow("修改失败", "修改提示！", "error");
            //        }
            //    }
            //}
            //catch (Exception ex) {
            //    SysLog.WriteLog(ex);
            //    MessageBoxToWindow("异常提示！" + ex.Message, "提示", "catch");
            //}

        }
        #region 弹出对话框
        /// <summary>
        /// 弹出对话框
        /// </summary>
        /// <param name="title"></param>
        /// <param name="content"></param>
        /// <param name="type"></param>
        public void MessageBoxToWindow(string title, string content, string type)
        {
            string script = "";
            switch (type)
            {
                case "error"://失败
                    type = "error";
                    script = "<script type='text/javascript'>  $.ligerDialog.alert('" + title + "','" + content + "','" + type + "');</script>";
                    break;
                case "success"://成功
                    type = "info";
                    script = "<script type='text/javascript'> $.ligerDialog.alert('" + title + "','" + content + "','" + type + "',CloseThis);</script>";
                    break;
                case "catch"://异常
                    type = "warning";
                    script = "<script type='text/javascript'>  $.ligerDialog.alert('" + title + "','" + content + "','" + type + "');</script>";
                    break;
                default:
                    type = "question";
                    break;
            }
            ClientScript.RegisterClientScriptBlock(this.GetType(), "", script);
        }
        #endregion

    }
}