FrmShortSmsMessage.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. using LYFZ.ComponentLibrary;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. namespace LYFZ.Software.MainBusiness.SMSManagement
  11. {
  12. public partial class FrmShortSmsMessage : LYFZ.Software.UI.SMSManagement.FrmShortSmsMessage
  13. {
  14. private delegate void UpdateControl();
  15. int SumCount = 0; //短信条数
  16. public FrmShortSmsMessage()
  17. {
  18. this.btnContentSelection.Click += new EventHandler(btnContentSelection_Click);
  19. this.richNr.TextChanged += new EventHandler(richNr_TextChanged);
  20. this.btnScreening.Click += new EventHandler(btnScreening_Click);
  21. this.btnClear.Click += new EventHandler(btnClear_Click);
  22. this.btnDelete.Click += new EventHandler(btnDelete_Click);
  23. this.btnImportNumbers.Click += new EventHandler(btnImportNumbers_Click);
  24. this.btnSendSMS.Click += new EventHandler(btnSendSMS_Click);
  25. this.Shown += FrmShortSmsMessage_Shown;
  26. this.dgvPhoneNumbers.CellClick += dgvPhoneNumbers_CellClick;
  27. this.dgvPhoneNumbers.Click += dgvPhoneNumbers_Click;
  28. this.rdoAllSelect.Click += rdoAll_Click;
  29. this.rdoUnselected.Click += rdoUnselected_Click;
  30. #region 短信发送
  31. if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.ShortSmsMessageCompetence, CustomAttributes.OperatingAuthority.SMSSend))
  32. {
  33. btnSendSMS.Enabled = true;
  34. }
  35. else
  36. {
  37. btnSendSMS.Enabled = false;
  38. }
  39. #endregion
  40. }
  41. void rdoUnselected_Click(object sender, EventArgs e)
  42. {
  43. Unselected();
  44. dgvPhoneNumbers_Click(sender, e);
  45. }
  46. //反选
  47. private void Unselected()
  48. {
  49. if (this.dgvPhoneNumbers.Rows.Count > 0)
  50. {
  51. for (int i = 0; i < this.dgvPhoneNumbers.Rows.Count; i++)
  52. {
  53. this.dgvPhoneNumbers.Rows[i].Selected = !dgvPhoneNumbers.Rows[i].Selected;
  54. }
  55. }
  56. }
  57. void rdoAll_Click(object sender, EventArgs e)
  58. {
  59. this.dgvPhoneNumbers.SelectAll();
  60. dgvPhoneNumbers_Click(sender, e);
  61. }
  62. void dgvPhoneNumbers_Click(object sender, EventArgs e)
  63. {
  64. string Sj = "";
  65. this.richTelPhone.Text = "";
  66. if (this.dgvPhoneNumbers.SelectedRows != null && this.dgvPhoneNumbers.SelectedRows.Count > 0)
  67. {
  68. for (int i = 0; i < this.dgvPhoneNumbers.SelectedRows.Count; i++)
  69. {
  70. string tempPhones = dgvPhoneNumbers.SelectedRows[i].Cells["TelPhone"].Value.ToString();
  71. string[] phones = tempPhones.Split('/');
  72. foreach (string phone in phones)
  73. {
  74. if (phone.Trim().Length > 0 && !Sj.Contains(phone))
  75. {
  76. if (LYFZ.WinAPI.CustomPublicMethod.ValidationPhones(phone).Trim().Length <= 0)
  77. {
  78. Sj += phone + ",";
  79. }
  80. }
  81. }
  82. }
  83. richTelPhone.Text = Sj.Trim().Trim(',');
  84. txtPhoneCount.Text = richTelPhone.Text.Split(',').Length.ToString();
  85. }
  86. }
  87. void dgvPhoneNumbers_CellClick(object sender, DataGridViewCellEventArgs e)
  88. {
  89. if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
  90. {
  91. }
  92. }
  93. #region 加载
  94. protected void FrmShortSmsMessage_Shown(object sender, EventArgs e)
  95. {
  96. lblName.Text = SmsSend.FrmSendSms.GetlblNameTextString(0, 0) + " 特别说明:群发(营销类)短信结尾必须加“回TD退订”字样";
  97. }
  98. #endregion
  99. #region 选择发送内容模板
  100. protected void btnContentSelection_Click(object sender, EventArgs e)
  101. {
  102. frmSelectSmsInfo selectInfo = new frmSelectSmsInfo();
  103. if (selectInfo.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  104. {
  105. if (selectInfo.SmsModel.ID > 0)
  106. {
  107. this.richNr.Text = selectInfo.SmsModel.ST_SMSContent;
  108. SumCount = SmsSend.FrmSendSms.GetSmsSizeCount(selectInfo.SmsModel.ST_SMSContent, SmsSend.FrmSendSms.Works64);
  109. lblName.Text = SmsSend.FrmSendSms.GetlblNameTextString(selectInfo.SmsModel.ST_SMSContent.Length, SumCount * richTelPhone.Text.Trim().Split(',').Length) + " 特别说明:群发(营销类)短信结尾必须加“回TD退订”字样";
  110. }
  111. }
  112. }
  113. #endregion
  114. #region 内容输入事件
  115. protected void richNr_TextChanged(object sender, EventArgs e)
  116. {
  117. #region 获取67字数
  118. string Nr = richNr.Text;
  119. lblName.Text = SmsSend.FrmSendSms.GetlblNameTextString(Nr.Length, SmsSend.FrmSendSms.GetSmsSizeCount(Nr.ToString(), SmsSend.FrmSendSms.Works64) * richTelPhone.Text.Trim().Split(',').Length) + " 特别说明:群发(营销类)短信结尾必须加“回TD退订”字样";
  120. #endregion
  121. }
  122. #endregion
  123. #region 筛选
  124. List<string> tempPhoneNumbers = new List<string>();
  125. /// <summary>
  126. /// 临时手机号集合
  127. /// </summary>
  128. public List<string> TempPhoneNumbers
  129. {
  130. get { return tempPhoneNumbers; }
  131. set { tempPhoneNumbers = value; }
  132. }
  133. protected void btnScreening_Click(object sender, EventArgs e)
  134. {
  135. LYFZ.Software.MainBusiness.SMSManagement.ShortSmsMessage.FrmScreening smsFilter = new ShortSmsMessage.FrmScreening();
  136. if (smsFilter.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
  137. if (smsFilter.SelectPhoneNumbers.Count > 0)
  138. {
  139. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  140. {
  141. int iCount=1;
  142. foreach (ItemValue item in smsFilter.SelectPhoneNumbers)
  143. {
  144. backgroundWorker.ReportProgress(0, "共" + smsFilter.SelectPhoneNumbers.Count.ToString() + "个,已添加" + iCount.ToString()+"个");
  145. DataGridViewRow row = new DataGridViewRow();
  146. this.Invoke(new UpdateControl(delegate()
  147. {
  148. row.CreateCells(this.dgvPhoneNumbers);
  149. row.Cells[0].Value = item.Text.Trim();
  150. row.Cells[1].Value = item.Value.ToString().Trim();
  151. if (!this.TempPhoneNumbers.Contains(item.Value.ToString().Trim()))
  152. {
  153. this.TempPhoneNumbers.Add(item.Value.ToString().Trim());
  154. this.dgvPhoneNumbers.Rows.Add(row);
  155. }
  156. }));
  157. iCount++;
  158. }
  159. });
  160. }
  161. }
  162. }
  163. #endregion
  164. #region 清空
  165. protected void btnClear_Click(object sender, EventArgs e)
  166. {
  167. TempPhoneNumbers.Clear();
  168. dgvPhoneNumbers.Rows.Clear();
  169. this.richTelPhone.Text = "";
  170. txtPhoneCount.Text = "0";
  171. }
  172. #endregion
  173. #region 删除
  174. protected void btnDelete_Click(object sender, EventArgs e)
  175. {
  176. if (this.dgvPhoneNumbers.SelectedRows != null && this.dgvPhoneNumbers.SelectedRows.Count > 0)
  177. {
  178. int count = this.dgvPhoneNumbers.SelectedRows.Count;
  179. for (int i = 0; i < count; i++)
  180. {
  181. string delPhone = this.dgvPhoneNumbers.SelectedRows[0].Cells[1].Value.ToString();
  182. this.dgvPhoneNumbers.Rows.Remove(this.dgvPhoneNumbers.SelectedRows[0]);
  183. TempPhoneNumbers.Remove(delPhone);
  184. }
  185. this.richTelPhone.Text = "";
  186. txtPhoneCount.Text = "0";
  187. }
  188. else {
  189. MessageBoxCustom.Show("请选择你要删除的客户!");
  190. }
  191. }
  192. #endregion
  193. #region 导入号码
  194. protected void btnImportNumbers_Click(object sender, EventArgs e)
  195. {
  196. LYFZ.Software.MainBusiness.SMSManagement.ShortSmsMessage.FrmImportNumbers set = new ShortSmsMessage.FrmImportNumbers();
  197. if (set.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  198. {
  199. if (!string.IsNullOrEmpty(set.Telphone))
  200. {
  201. richTelPhone.Text = set.Telphone;
  202. txtPhoneCount.Text = richTelPhone.Text.Trim().Split(',').Length.ToString();
  203. }
  204. }
  205. }
  206. #endregion
  207. #region 发送短信
  208. protected void btnSendSMS_Click(object sender, EventArgs e)
  209. {
  210. SmsSend.FrmSendSms.AddSendSMS(richTelPhone.Text, richNr.Text);
  211. }
  212. #endregion
  213. }
  214. }