FrmSMSEmployees.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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 FrmSMSEmployees : LYFZ.Software.UI.SMSManagement.FrmSMSEmployees
  13. {
  14. private delegate void UpdateControl();
  15. public FrmSMSEmployees()
  16. {
  17. this.ucPagerEx1.EventPaging += ucPagerEx1_EventPaging;
  18. this.Shown+=FrmSMSEmployees_Shown;
  19. this.btnSelect.Click+=btnSelect_Click;
  20. this.btnAll.Click+=btnAll_Click;
  21. this.btnSmsSend.Click+=btnSmsSend_Click;
  22. this.btnClose.Click+=btnClose_Click;
  23. // dgv.CellValueChanged += dgv_CellValueChanged;
  24. this.buttonBind.Click += buttonBind_Click;
  25. #region 短信发送
  26. this.btnSendMicroMessage.Click += btnSendMicroMessage_Click;
  27. if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.SMSEmployeesCompetence, CustomAttributes.OperatingAuthority.SMSSend))
  28. {
  29. btnSmsSend.Enabled = true;
  30. this.btnSendMicroMessage.Enabled = true;
  31. }
  32. else
  33. {
  34. btnSmsSend.Enabled = false;
  35. this.btnSendMicroMessage.Enabled = false;
  36. }
  37. #endregion
  38. }
  39. /* void dgv_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  40. {
  41. if (e.ColumnIndex == 6)
  42. {
  43. string openID = this.dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  44. this.dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Tag = openID;
  45. if (openID.Trim().Length > 0)
  46. {
  47. this.dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "已绑定";
  48. }
  49. else {
  50. this.dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "";
  51. }
  52. }
  53. }*/
  54. void btnSendMicroMessage_Click(object sender, EventArgs e)
  55. {
  56. if (this.dgv.SelectedRows != null && this.dgv.SelectedRows.Count > 0)
  57. {
  58. LYFZ.Software.MainBusiness.SMSManagement.SmsSend.frmSendMicroTemplateSMS sendMicro = new SmsSend.frmSendMicroTemplateSMS();
  59. string openIDs = "";
  60. for (int i = 0; i < this.dgv.SelectedRows.Count; i++)
  61. {
  62. if (this.dgv.SelectedRows[i].Tag != null)
  63. {
  64. LYFZ.Model.BindWxOpenID bindOpenID = (LYFZ.Model.BindWxOpenID)this.dgv.SelectedRows[i].Tag;
  65. if (bindOpenID.OpenID.Trim().Length > 0 && !openIDs.Contains(bindOpenID.OpenID))
  66. {
  67. openIDs += bindOpenID.OpenID + ",";
  68. }
  69. }
  70. }
  71. sendMicro.IsEmployee = true;
  72. sendMicro.DfTemplateNo = EnumPublic.MicroTemplate.待办事项通知;
  73. sendMicro.ReceiveOPNIDs = openIDs.Trim(',');
  74. if (sendMicro.ReceiveOPNIDs.Trim().Length > 0)
  75. {
  76. sendMicro.ShowDialog();
  77. }
  78. else {
  79. MessageBoxCustom.Show("选择的员工没有绑定微信,不能发送微信消息");
  80. }
  81. }
  82. else
  83. {
  84. MessageBoxCustom.Show("请选择要发送消息的员工");
  85. }
  86. }
  87. #region 加载
  88. protected void FrmSMSEmployees_Shown(object sender, EventArgs e)
  89. {
  90. List<Control> hideControl = new List<Control>();
  91. List<Control> moveControl = new List<Control>();
  92. hideControl.Add(buttonBind);
  93. hideControl.Add(btnSendMicroMessage);
  94. moveControl.Add(btnAll);
  95. moveControl.Add(btnSmsSend);
  96. moveControl.Add(btnClose);
  97. //LYFZSS.SystemSpecterPossessed.ISystemSpecterPossessed.GetMySystemSpecter = LYFZSS.SystemSpecterType.SST_D;
  98. bool b = LYFZ.Software.MainBusiness.VersionControl.StaticVersion.BindVersionShowHideControl(
  99. VersionControl.VersionFunctionEnum.短信管理微信短信推送, hideControl, moveControl, null);
  100. try
  101. {
  102. modInterFace = bllInterface.GetModelMicroInterface(LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID);
  103. bind();
  104. }
  105. catch (Exception ex)
  106. {
  107. MessageBoxCustom.Show(ex.Message);
  108. }
  109. }
  110. public void bind()
  111. {
  112. this.ucPagerEx1.PageCurrent = 1;
  113. this.ucPagerEx1.PageSize = 100;
  114. this.ucPagerEx1.Bind();
  115. }
  116. #endregion
  117. #region 查询
  118. protected void btnSelect_Click(object sender, EventArgs e)
  119. {
  120. try
  121. {
  122. selectOpenID = "";
  123. bind();
  124. }
  125. catch (Exception ex)
  126. {
  127. MessageBoxCustom.Show(ex.Message);
  128. }
  129. }
  130. void buttonBind_Click(object sender, EventArgs e)
  131. {
  132. try
  133. {
  134. selectOpenID = " and len(User_OpenID)>0 ";
  135. bind();
  136. }
  137. catch (Exception ex)
  138. {
  139. MessageBoxCustom.Show(ex.Message);
  140. }
  141. }
  142. #endregion
  143. #region 选中全部
  144. protected void btnAll_Click(object sender, EventArgs e)
  145. {
  146. if (dgv.Rows.Count > 0)
  147. {
  148. dgv.SelectAll();
  149. }
  150. }
  151. #endregion
  152. #region 短信发送
  153. protected void btnSmsSend_Click(object sender, EventArgs e)
  154. {
  155. if (dgv.SelectedRows==null||dgv.SelectedRows.Count == 0)
  156. {
  157. MessageBoxCustom.Show("请选择你要发送短信的员工!");
  158. return;
  159. }
  160. string Sj1 = "";
  161. string User_Telephone = "";
  162. LYFZ.Software.MainBusiness.SMSManagement.SmsSend.FrmSendSms sendSms = new SmsSend.FrmSendSms();
  163. for (int i = 0; i < dgv.SelectedRows.Count; i++)
  164. {
  165. User_Telephone = dgv.SelectedRows[i].Cells["User_Telephone"].Value.ToString();
  166. //检查手机合法性
  167. if (!string.IsNullOrEmpty(User_Telephone))
  168. {
  169. string ret = LYFZ.WinAPI.CustomPublicMethod.ValidationPhones(User_Telephone);
  170. if (ret.Trim().Length <=0)
  171. {
  172. Sj1 += User_Telephone + ",";
  173. }
  174. else if (dgv.SelectedRows.Count==1)
  175. {
  176. MessageBoxCustom.Show("手机号无效:"+ret);
  177. return;
  178. }
  179. }
  180. }
  181. sendSms.Phone = Sj1.Trim(',');
  182. sendSms.ShowDialog();
  183. }
  184. #region 验证手机
  185. private bool CheckPhoneNumber(string number)
  186. {
  187. return System.Text.RegularExpressions.Regex.IsMatch(number, @"^(1[3,5,8][0-9])\d{8}$");
  188. }
  189. #endregion
  190. #endregion
  191. #region 关闭
  192. protected void btnClose_Click(object sender, EventArgs e)
  193. {
  194. this.Close();
  195. }
  196. #endregion
  197. #region 画分页
  198. BLL.BLL_ErpMicroInterface bllInterface = new BLL.BLL_ErpMicroInterface();
  199. LYFZ.Model.Model_ErpMicroInterface modInterFace = new Model.Model_ErpMicroInterface();
  200. LYFZ.BLL.BLL_CustomerAndWxOpen wxOPenBll = new BLL.BLL_CustomerAndWxOpen();
  201. List<LYFZ.Model.BindWxOpenID> wxOpenIDList = new List<LYFZ.Model.BindWxOpenID>();
  202. public List<LYFZ.Model.BindWxOpenID> WxOpenIDList
  203. {
  204. get {
  205. if (wxOpenIDList.Count <= 0)
  206. {
  207. if (modInterFace.AppID != null && modInterFace.AppID.Trim().Length > 0)
  208. {
  209. wxOpenIDList = wxOPenBll.GetWxOpenIdList(1, modInterFace.AppID.Trim());
  210. }
  211. }
  212. return wxOpenIDList; }
  213. }
  214. string selectOpenID = "";
  215. /// <summary>
  216. /// 画分页
  217. /// </summary>
  218. /// <param name="e"></param>
  219. /// <returns></returns>
  220. private int ucPagerEx1_EventPaging(UCPager.EventPagingArg e)
  221. {
  222. LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData();
  223. dgv.DataSource = null;
  224. DataTable dt = new DataTable();
  225. StringBuilder str = new StringBuilder();
  226. if (!string.IsNullOrEmpty(txtKeyWords.Text))
  227. {
  228. str.Append(" User_DividedShop='"+LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID+"' and User_Status='在职' and 1=1 and (User_Name like '%" + txtKeyWords.Text + "%' or User_Telephone like '%" + txtKeyWords.Text + "%' or User_NowAddress like '%" + txtKeyWords.Text + "%') " + selectOpenID + " and id>1");
  229. }
  230. else
  231. {
  232. str.Append(" User_DividedShop='"+LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID+"' and User_Status='在职' and 1=1 and id>1 " + selectOpenID + "");
  233. }
  234. this.dgv.Rows.Clear();
  235. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  236. {
  237. pageData.TableName = "View_tb_ErpUser";
  238. pageData.PageIndex = this.ucPagerEx1.PageCurrent;
  239. pageData.PageSize = this.ucPagerEx1.PageSize;
  240. pageData.QueryCondition = str.ToString();
  241. // pageData.QueryFieldName = "ID,User_DividedShop,User_Account,User_Name,User_EmployeeID,User_Department,User_Positions,User_Competence,User_Sex,User_Status,User_Ethnic,User_Hometown,User_NowAddress,User_HometownAddress,User_IsMarried ,User_ICQAccount,User_Email,User_Attachment,User_CreateDatetime,User_UpdateDatetime,User_SubordinateList,User_Telephone,Dt_Name,User_IsMarriedName,User_DateOfBirthTime,User_DateOfBirth,User_BirthdayLunar,User_OpenID ";
  242. pageData.QueryFieldName = "ID,User_DividedShop,User_Account,User_Name,User_EmployeeID,User_Department,User_Sex,User_Status,User_Telephone,Dt_Name,User_NowAddress,User_DateOfBirthTime,User_DateOfBirth,User_BirthdayLunar,User_OpenID ";
  243. pageData.OrderStr = " ID desc ";
  244. DataSet da = pageData.QueryDataTable();
  245. dt = da.Tables[0];
  246. try
  247. {
  248. if (this.WxOpenIDList.Count > 0)
  249. {
  250. //预加载
  251. }
  252. }
  253. catch { }
  254. });
  255. for (int t = 0; t < dt.Rows.Count; t++)
  256. {
  257. DataRow drow=dt.Rows[t];
  258. DataGridViewRow row = new DataGridViewRow();
  259. row.CreateCells(this.dgv);
  260. string User_EmployeeID=drow["User_EmployeeID"].ToString();
  261. row.Cells[0].Value = User_EmployeeID;
  262. row.Cells[1].Value = drow["User_Name"];
  263. row.Cells[2].Value = drow["Dt_Name"];
  264. row.Cells[3].Value = drow["User_Sex"];
  265. row.Cells[4].Value = drow["User_Telephone"];
  266. row.Cells[5].Value = drow["User_NowAddress"];
  267. row.Cells[6].Value = "";
  268. string oldOpenID = "";
  269. if (drow["User_OpenID"] != null && drow["User_OpenID"].ToString().Trim().Length > 0)
  270. {
  271. oldOpenID = drow["User_OpenID"].ToString().Trim();
  272. }
  273. if (this.WxOpenIDList.Any(s => s.UID.ToLower() == User_EmployeeID.ToLower()))
  274. {
  275. row.Cells[6].Value = "已绑定";
  276. row.Tag = this.WxOpenIDList.Find(s => s.UID.ToLower() == User_EmployeeID.ToLower());
  277. }
  278. else if (drow["User_DividedShop"].ToString() == "SSN001" && LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID == "SSN001" && oldOpenID.Trim().Length > 0)
  279. {
  280. row.Cells[6].Value = "已绑定";
  281. LYFZ.Model.BindWxOpenID oldBindID = new Model.BindWxOpenID();
  282. oldBindID.OpenID = oldOpenID;
  283. oldBindID.UID = User_EmployeeID;
  284. oldBindID.APPID = modInterFace.AppID.Trim();
  285. row.Tag = oldBindID;
  286. }
  287. dgv.Rows.Add(row);
  288. dgv.ClearSelection();
  289. }
  290. try
  291. {
  292. this.ucPagerEx1.TbDataSource = dt;
  293. }
  294. catch { }
  295. return pageData.TotalCount;
  296. }
  297. #endregion
  298. }
  299. }