frmSelectSmsInfo.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace LYFZ.Software.MainBusiness.SMSManagement
  10. {
  11. public class frmSelectSmsInfo : LYFZ.Software.UI.SMSManagement.frmSelectSmsInfo
  12. {
  13. LYFZ.DAL.DAL_SMSTemplates smsDal = new DAL.DAL_SMSTemplates();
  14. LYFZ.BLL.BLL_SMSTemplates smsBLL = new BLL.BLL_SMSTemplates();
  15. LYFZ.Model.Model_SMSTemplates smsModel = new Model.Model_SMSTemplates();
  16. public frmSelectSmsInfo()
  17. {
  18. this.Load += frmAddCommonSMS_Load;
  19. this.Shown += frmAddCommonSMS_Shown;
  20. this.cboxSmsClass.SelectedIndexChanged += cboxSmsClass_SelectedIndexChanged;
  21. this.dgvCommonSMS.CellDoubleClick += dgvCommonSMS_CellDoubleClick;
  22. this.btnCommonSMSAdd.Click += btnCommonSMSAdd_Click;
  23. }
  24. void btnCommonSMSAdd_Click(object sender, EventArgs e)
  25. {
  26. frmAddCommonSMS frmAddSms = new frmAddCommonSMS();
  27. if (frmAddSms.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  28. {
  29. BindSmsClass(this.cboxSmsClass);
  30. BindDgvCommonSMS();
  31. }
  32. }
  33. void dgvCommonSMS_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  34. {
  35. if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
  36. {
  37. DataGridViewRow row = this.dgvCommonSMS.Rows[e.RowIndex];
  38. try
  39. {
  40. this.SmsModel = (LYFZ.Model.Model_SMSTemplates)row.Tag;
  41. }
  42. catch { }
  43. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  44. }
  45. }
  46. void cboxSmsClass_SelectedIndexChanged(object sender, EventArgs e)
  47. {
  48. string cClass=this.cboxSmsClass.Text.Trim();
  49. foreach (DataGridViewRow row in this.dgvCommonSMS.Rows)
  50. {
  51. if (cClass == "全部")
  52. {
  53. row.Visible = true;
  54. }
  55. else {
  56. if (row.Cells[0].Value.ToString().Trim() == cClass)
  57. {
  58. row.Visible = true;
  59. }
  60. else {
  61. row.Visible = false;
  62. }
  63. }
  64. }
  65. }
  66. void frmAddCommonSMS_Shown(object sender, EventArgs e)
  67. {
  68. BindDgvCommonSMS();
  69. }
  70. /// <summary>
  71. /// 短信对象
  72. /// </summary>
  73. public LYFZ.Model.Model_SMSTemplates SmsModel
  74. {
  75. get { return smsModel; }
  76. set { smsModel = value; }
  77. }
  78. void BindDgvCommonSMS()
  79. {
  80. this.dgvCommonSMS.Rows.Clear();
  81. try
  82. {
  83. List<LYFZ.Model.Model_SMSTemplates> smsModelList = null;
  84. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  85. {
  86. try
  87. {
  88. smsModelList = smsBLL.GetModelList("ST_Type=0");
  89. }
  90. catch
  91. {
  92. MessageBoxCustom.Show("常用短信加载失败!请检查网络环境或关闭系统后重试!", backgroundWorker: backgroundWorker);
  93. }
  94. });
  95. if (smsModelList != null)
  96. {
  97. foreach (LYFZ.Model.Model_SMSTemplates model in smsModelList)
  98. {
  99. DataGridViewRow row = new DataGridViewRow();
  100. row.CreateCells(this.dgvCommonSMS);
  101. row.Cells[0].Value = model.ST_Title;
  102. row.Cells[1].Value = model.ST_SMSContent;
  103. row.Tag = model;
  104. this.dgvCommonSMS.Rows.Add(row);
  105. }
  106. if (this.dgvCommonSMS.SortedColumn != null)
  107. {
  108. ListSortDirection Direction = ListSortDirection.Descending;
  109. switch (this.dgvCommonSMS.SortOrder)
  110. {
  111. case SortOrder.Ascending:
  112. Direction = ListSortDirection.Ascending;
  113. break;
  114. case SortOrder.Descending:
  115. Direction = ListSortDirection.Descending;
  116. break;
  117. default: break;
  118. }
  119. this.dgvCommonSMS.Sort(this.dgvCommonSMS.SortedColumn, Direction);
  120. }
  121. }
  122. }
  123. catch
  124. {
  125. MessageBoxCustom.Show("常用短信记录加载失败!请检查网络环境或关闭系统后重试!");
  126. }
  127. }
  128. public static void BindSmsClass(ComponentLibrary.ComboBoxEx cbox)
  129. {
  130. LYFZ.DAL.DAL_SMSTemplates smsTDal = new DAL.DAL_SMSTemplates();
  131. List<string> SMSClassList = smsTDal.GetCommonSMSClassList();
  132. SMSClassList.Insert(0, "全部");
  133. cbox.DataSource = SMSClassList;
  134. smsTDal = null;
  135. }
  136. void frmAddCommonSMS_Load(object sender, EventArgs e)
  137. {
  138. BindSmsClass(this.cboxSmsClass);
  139. }
  140. }
  141. }