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.calloutmanage
{
    public partial class callplanedit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    txtId.Value = Request.QueryString["id"].Trim();
                    InitObj(Request.QueryString["id"].Trim());
                }
            }
        }
        void InitObj(string id)
        {
            try
            {
                T_CTI_TaskObj = new BLL.T_CTI_Task().GetModel(Convert.ToInt32(id));
            }
            catch (Exception ex)
            {
            }
        }

        private Model.T_CTI_Task T_CTI_TaskObj
        {
            get
            {
                Model.T_CTI_Task model = new Model.T_CTI_Task();
                if (Request.QueryString["otype"].Trim() == "modify")
                {
                    model.TaskID = Convert.ToInt32(Request.QueryString["id"].Trim());
                }
                else
                {
                    model.TaskID = 0;
                }

                model.TaskName = TaskName.Text.Trim();
                model.TrunkGroupID = 0;
                model.CallType = 1;
                model.State = 0;
                model.AddTime = DateTime.Now;
                model.y_PSort = 2;
                model.y_TkModelId = 0;
                try
                {
                    model.y_TkModelId = Convert.ToInt32(txtPagerId.Value.Trim());
                }
                catch (Exception ex)
                { 
                }
                model.y_SXH = 0;
                model.y_FPCount = 0;
                model.y_YJCount = 0;
                model.y_HCCount = 0;
                model.y_HSCount = 0;
                model.y_HTCount = 0;
                model.y_HMCount = 0;
                model.y_OkCount = 0;
                model.y_RFCount = 0;
                model.y_ConsCount = 0;
                model.y_InvlCount = 0;
                model.y_NoAnswerCount = 0;
                model.y_ShutDownCount = 0;

                return model;
            }
            set
            {
                if (value != null)
                {
                    this.txtId.Value = value.TaskID.ToString();
                    this.TaskName.Text = value.TaskName;
                    this.txtPagerId.Value = value.y_TkModelId.ToString();
                    try
                    {
                        if (value.y_TkModelId != 0)
                        {
                            txtPagerName.Text = new BLL.T_Ask_PagerInfo().GetModel(Convert.ToInt32(value.y_TkModelId.ToString())).F_Title;
                        }
                    }
                    catch (Exception ex)
                    { 
                    }

                }
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                if (Request.QueryString["otype"] == "new")
                {
                    long id=new BLL.T_CTI_Task().Add(T_CTI_TaskObj);
                    if (id > 0)
                    {
                        //生成任务表
                        MessageBoxToWindow("新增成功", "新增提示", "success");
                    }
                    else
                    {
                        MessageBoxToWindow("新增失败", "新增提示！", "error");
                    }
                }
                if (Request.QueryString["otype"] == "modify")
                {
                    if (new BLL.T_CTI_Task().Update(T_CTI_TaskObj))
                    {
                        MessageBoxToWindow("修改成功", "修改提示！", "success");
                    }
                    else
                    {
                        MessageBoxToWindow("修改失败！", "修改提示！", "error");
                    }
                }
            }
            catch
            {
                MessageBoxToWindow("保存失败！", "保存提示！", "error");
            }

        }

        #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
    }
}