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.smsmanage
{
    public partial class smsSent : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                LoadDic();
            }
        }



        public void LoadDic() {
        BLL.T_Sms_SmsModel bll_T_Sms_InfoType = new BLL.T_Sms_SmsModel();
        //指定DropDownList使用的数据源
        ddlInfoType.DataSource = bll_T_Sms_InfoType.GetModelList(" State=0");
        //指定DropDownList使用的表里的那些字段
        ddlInfoType.DataTextField = "Name"; //dropdownlist的Text的字段
        ddlInfoType.DataValueField = "ModelId";//dropdownlist的Value的字段
        ddlInfoType.DataBind();
        this.ddlInfoType.Items.Insert(0, new ListItem("--请选择--", ""));
        
        }

        public void Button1_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtTelephone.Value)) {
                string[] arrStr = txtTelephone.Value.Split(',');
                foreach(string str in arrStr){
                    AddSentSms(str);
                
                }
             
            }


        }
        public void AddSentSms(string strSent) {
            try
            {
                Model.T_SMS_SendSMSTask sentSmsModel = new Model.T_SMS_SendSMSTask();
                BLL.T_SMS_SendSMSTask sentSmsBll = new BLL.T_SMS_SendSMSTask();
                LoginUser p_LoginUser = new LoginUser(this.Context);
                sentSmsModel.TelNum = strSent;
                sentSmsModel.F_Name = p_LoginUser.UserName.ToString();
                sentSmsModel.Content = txtContent.Value;
                sentSmsModel.CommitTime = DateTime.Now;
                sentSmsModel.SendTime = DateTime.Now;
                sentSmsModel.LastSentTime = DateTime.Now;

               int refa = sentSmsBll.Add(sentSmsModel);
                if (refa>0)
                {
                    MessageBoxToWindow("新增成功", "新增提示！", "success");

                }
                else
                {
                    MessageBoxToWindow("新增失败", "新增提示！", "error");
                }
            }catch(Exception ex){
            
            }
        }
 
        #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
    }
}