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

namespace HySoft.BaseCallCenter.Web.telmanage
{
    public partial class callblacklisteditor : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["getPuction"].ToString() == "Edit")
                {
                    getOrderInformerEdit(Request.QueryString["singleFlage"].ToString());
                }
            }
        }
        /// <summary>
        /// 初始化信息
        /// </summary>
        ///
       
        private void getOrderInformerEdit(string Flage)
        {
            DataTable dt = new DataTable();
            DataTable dtItems = new DataTable();
            string sql = "select * from T_Call_Blacklist where F_BlackId=" + Flage + "";
            dt = DBUtility.DbHelperSQL.Query(sql).Tables[0];
            if (dt.Rows.Count > 0)
            {
                F_ParamCode.Text = dt.Rows[0]["F_TelPhone"].ToString();
                F_ParamValue.Text = dt.Rows[0]["F_SetTime"].ToString();
                TextBox1.Text = dt.Rows[0]["F_RemoveTime"].ToString();
                F_ParamDes.Text = dt.Rows[0]["F_Describe"].ToString();
                HiddenField1.Value = dt.Rows[0]["F_InterceptNum"].ToString();
            }
        }
        /// <summary>
        /// 保存订单信息。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            HySoft.BaseCallCenter.Model.T_Call_Blacklist orderModel = new Model.T_Call_Blacklist();
            HySoft.BaseCallCenter.BLL.T_Call_Blacklist orderBll = new BLL.T_Call_Blacklist();
            try
            {
                orderModel.F_TelPhone = F_ParamCode.Text.Trim();
                orderModel.F_SetTime = Convert.ToDateTime(F_ParamValue.Text.Trim());
                orderModel.F_RemoveTime = Convert.ToDateTime(TextBox1.Text.Trim());
                orderModel.F_Describe = F_ParamDes.Text.Trim();
                //orderModel.F_InterceptNum = Convert.ToInt32(HiddenField1.Value) + 1;
                //if (HiddenField1.Value == null)
                //{
                //    orderModel.F_InterceptNum = 1;
                //}
                //else
                //{ orderModel.F_InterceptNum = Convert.ToInt32(HiddenField1.Value) + 1; }
                if (Request.QueryString["getPuction"] == "Add")
                {
                    orderModel.F_InterceptNum = 1;
                    int count = orderBll.Add(orderModel);
                    if (count > 0)
                    {
                        MessageBoxToWindow("新增成功", "新增提示", "success");
                    }
                    else
                    {
                        MessageBoxToWindow("新增失败", "新增提示！", "error");
                    }
                }
                if (Request.QueryString["getPuction"] == "Edit")
                {
                    orderModel.F_InterceptNum = Convert.ToInt32(HiddenField1.Value) + 1;
                    orderModel.F_BlackId = Convert.ToInt32(Request.QueryString["singleFlage"]);
                    if (orderBll.Update(orderModel))
                    {
                        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
    }
}