123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace LYFZ.Software.MainBusiness.SMSManagement.SmsSend
- {
- public partial class FrmSendSms : LYFZ.Software.UI.SMSManagement.SmsSend.FrmSendSms
- {
- private string _Phone;
-
-
-
- public string Phone
- {
- get { return _Phone; }
- set { _Phone = value.Replace('/', ','); }
- }
- int SumCount = 0;
- private static int _Works64 = 67;
-
-
-
- public static int Works64
- {
- get { return FrmSendSms._Works64; }
- set { FrmSendSms._Works64 = value; }
- }
-
- public FrmSendSms()
- {
- this.Load += new EventHandler(FrmSendSms_Load);
- radN_M.Click += new EventHandler(radN_M_Click);
- this.radN.Click += new EventHandler(radN_Click);
- this.radM.Click += new EventHandler(radM_Click);
- this.btnContentSelection.Click += new EventHandler(btnContentSelection_Click);
- this.btnSendSMS.Click += new EventHandler(btnSendSMS_Click);
- this.richNr.TextChanged += new EventHandler(richNr_TextChanged);
- this.richTelPhone.MouseDoubleClick += richTelPhone_MouseDoubleClick;
- this.richTelPhone.TextChanged += richTelPhone_TextChanged;
- }
- void richTelPhone_TextChanged(object sender, EventArgs e)
- {
- richNr_TextChanged(sender, e);
- }
- void richTelPhone_MouseDoubleClick(object sender, MouseEventArgs e)
- {
- this.richTelPhone.ReadOnly = !this.richTelPhone.ReadOnly;
- }
- public void SetDefaultSmsText(string text)
- {
- this.richNr.Text = text.Trim();
- }
- #region 加载
-
-
-
-
-
-
- public static string GetlblNameTextString(int i, int j)
- {
- string Smsa_AccountName = "";
- if (frmSMSTemplateSet.CurrentSmsAccount != null) {
- Smsa_AccountName = frmSMSTemplateSet.CurrentSmsAccount.Smsa_AccountName;
- i = i + frmSMSTemplateSet.CurrentSmsAccount.Smsa_AccountName.Length;
- }
- return "短信内容(手机67字/条)(现" + i.ToString() + "字 加上签名:" + Smsa_AccountName + ",共" + j.ToString() + "条短信)";
- }
- protected void FrmSendSms_Load(object sender, EventArgs e)
- {
- try
- {
- lblName.Text = GetlblNameTextString(0, 0);
- richTelPhone.Text = Phone.TrimEnd(',');
- #region 检查手机合法性
- string phone = richTelPhone.Text;
-
- string[] sj = phone.Split(',');
- List<string> strReturn = new List<string>();
- foreach (string name in sj)
- {
- if (strReturn.Contains(name) == false) strReturn.Add(name);
- }
- string[] Sx = strReturn.ToArray();
-
- string Lj = "";
- for (int i = 0; i < Sx.Length; i++)
- {
- Lj += Sx[i] + ",";
- }
- richTelPhone.Text = Lj.TrimEnd(',');
- #endregion
- int count = richTelPhone.Text.Length - richTelPhone.Text.Replace(",", "").Length;
- txtPhoneCount.Text = Convert.ToInt32(count + 1).ToString();
- }
- catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
- }
- #endregion
- #region 男+女
- protected void radN_M_Click(object sender, EventArgs e)
- {
- txtPhoneCount.Text = "";
- richTelPhone.Text = "";
- richTelPhone.Text = Phone.TrimEnd(',');
- int count = richTelPhone.Text.Length - richTelPhone.Text.Replace(",", "").Length;
- txtPhoneCount.Text = Convert.ToInt32(count + 1).ToString();
- }
- #endregion
- #region 男
- protected void radN_Click(object sender, EventArgs e)
- {
- if (!string.IsNullOrEmpty(Phone))
- {
- txtPhoneCount.Text = "";
- richTelPhone.Text = "";
- LYFZ.BLL.BLL_ErpCustomer bll = new BLL.BLL_ErpCustomer();
- string[] sz = Phone.TrimEnd(',').Split(',');
- for (int i = 0; i < sz.Length; i++)
- {
- DataTable dt = bll.View_tb_ErpCustomer("Cus_Telephone='" + sz[i] + "'").Tables[0];
- if (dt.Rows[0]["sex"].ToString() == "男")
- {
- richTelPhone.Text = sz[i];
- int count = richTelPhone.Text.Length - richTelPhone.Text.Replace(",", "").Length;
- txtPhoneCount.Text = Convert.ToInt32(count + 1).ToString();
- }
- }
- }
- }
- #endregion
- #region 女
- protected void radM_Click(object sender, EventArgs e)
- {
- if (!string.IsNullOrEmpty(Phone))
- {
- txtPhoneCount.Text = "";
- richTelPhone.Text = "";
- LYFZ.BLL.BLL_ErpCustomer bll = new BLL.BLL_ErpCustomer();
- string[] sz = Phone.TrimEnd(',').Split(',');
- for (int i = 0; i < sz.Length; i++)
- {
- DataTable dt = bll.View_tb_ErpCustomer("Cus_Telephone='" + sz[i] + "'").Tables[0];
- if (dt.Rows[0]["sex"].ToString() == "女")
- {
- richTelPhone.Text = sz[i];
- int count = richTelPhone.Text.Length - richTelPhone.Text.Replace(",", "").Length;
- txtPhoneCount.Text = Convert.ToInt32(count + 1).ToString();
- }
- }
- }
- }
- #endregion
- #region 选择
- protected void btnContentSelection_Click(object sender, EventArgs e)
- {
- frmSelectSmsInfo selectInfo = new frmSelectSmsInfo();
- if (selectInfo.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- if (selectInfo.SmsModel.ID > 0)
- {
- this.richNr.Text = selectInfo.SmsModel.ST_SMSContent;
- SumCount = GetSmsSizeCount(selectInfo.SmsModel.ST_SMSContent, Works64);
- lblName.Text = GetlblNameTextString(selectInfo.SmsModel.ST_SMSContent.Length, SumCount * richTelPhone.Text.Trim().Split(',').Length);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
- }
-
-
-
-
-
-
- public static int GetSmsSizeCount(string NR, int MSG_LENGTH)
- {
- int nNumberOfTextMsg = 0;
- int nWCharLen = NR.Length;
- if (frmSMSTemplateSet.CurrentSmsAccount != null)
- {
- nWCharLen = NR.Length + frmSMSTemplateSet.CurrentSmsAccount.Smsa_AccountName.Length;
- }
- if (MSG_LENGTH != 0)
- {
-
-
-
-
-
- nNumberOfTextMsg = nWCharLen / MSG_LENGTH;
- if (nWCharLen % MSG_LENGTH > 0)
- nNumberOfTextMsg++;
- }
- return nNumberOfTextMsg;
- }
- #endregion
- #region 内容输入事件
- protected void richNr_TextChanged(object sender, EventArgs e)
- {
- #region 获取64字数
- string Nr = richNr.Text;
- lblName.Text = GetlblNameTextString(Nr.Length, GetSmsSizeCount(Nr.ToString(), Works64) * richTelPhone.Text.Trim().Trim(',').Split(',').Length);
- this.txtPhoneCount.Text = richTelPhone.Text.Trim().Trim(',').Split(',').Length.ToString();
- #endregion
- }
- #endregion
- #region 发送
- protected void btnSendSMS_Click(object sender, EventArgs e)
- {
- AddSendSMS(richTelPhone.Text, richNr.Text);
- }
-
-
-
-
-
- public static void AddSendSMS(string Phones, string smsContent)
- {
- try
- {
- #region 判断不能为空
- if (string.IsNullOrEmpty(Phones))
- {
- MessageBoxCustom.Show("手机号码不能为空!");
- return;
- }
- if (string.IsNullOrEmpty(smsContent))
- {
- MessageBoxCustom.Show("短信内容不能为空!");
- return;
- }
- #endregion
- #region 检查手机合法性
- string phone = Phones.Trim().Trim(',').Replace(",,", ",");
- string ret = LYFZ.WinAPI.CustomPublicMethod.ValidationPhones(phone);
- if (ret.Trim().Length > 0)
- {
- MessageBoxCustom.Show("手机号无效:" + ret);
- return;
- }
-
- string[] sj = phone.Split(',');
- StringBuilder phoneString = new StringBuilder();
- foreach (string name in sj)
- {
- if (!phoneString.ToString().Contains(name))
- phoneString.Append(name + ",");
- }
- phone = phoneString.ToString().Trim(',');
- #endregion
- #region 发送
- LYFZ.BLL.BLL_SMSTemplates smsTemplates = new BLL.BLL_SMSTemplates();
- if (phone.Trim().Length > 0)
- {
- if (phone.Trim().Length >= 60 && (!smsContent.Contains("回TD退订") && !smsContent.Contains("退订回TD") && !smsContent.Contains("退订回N") && !smsContent.Contains("回N退订")))
- {
- string tempSms = smsContent + "回TD退订";
- int nWCharLen =0;
- int tempcount = tempSms.Length;
- int tempSumCount = 0;
- if (frmSMSTemplateSet.CurrentSmsAccount != null)
- {
- nWCharLen =frmSMSTemplateSet.CurrentSmsAccount.Smsa_AccountName.Length;
- if (!smsContent.StartsWith(frmSMSTemplateSet.CurrentSmsAccount.Smsa_AccountName) && !smsContent.EndsWith(frmSMSTemplateSet.CurrentSmsAccount.Smsa_AccountName))
- {
- tempcount = tempcount + nWCharLen;
- tempSms = tempSms + frmSMSTemplateSet.CurrentSmsAccount.Smsa_AccountName;
- }
- }
- tempSumCount = tempcount / Works64;
- if (tempcount % Works64 > 0)
- tempSumCount++;
- if (MessageBoxCustom.Show("系统检查到您发送的短信为“群发(营销类)短信”,且未加入“回TD退订”字样,系统将自动加上该字样,此时实际短信字数为 " + tempcount + " 个字, " + (tempSumCount* phone.Split(',').Length).ToString() + " 条,是否确定发送此短信?", msgBoxButton: MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- smsContent = smsContent + "回TD退订";
- }
- else {
- return;
- }
- }
- string retMsg = smsTemplates.GenerateManuallySendSMS(phone, smsContent.Trim(), SDateTime.Now, LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_Name
- , LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID());
- MessageBoxCustom.Show(retMsg);
- }
- else
- {
- MessageBoxCustom.Show("没有找到有效的手机号");
- }
- #endregion
- }
- catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
- }
- #region 验证手机
- private bool CheckPhoneNumber(string number)
- {
- return System.Text.RegularExpressions.Regex.IsMatch(number, @"^(1[3,5,8][0-9])\d{8}$");
- }
- #endregion
- #endregion
- }
- }
|