FrmInternalMail.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.BulletinBoard
  10. {
  11. public partial class FrmInternalMail : LYFZ.Software.UI.BulletinBoard.FrmInternalMail
  12. {
  13. bool bl = false;
  14. public FrmInternalMail()
  15. {
  16. //绑定部门表
  17. LYFZ.BLL.BLL_ErpDepartment depbll = new BLL.BLL_ErpDepartment();
  18. DataTable dt = depbll.GetAllList().Tables[0];
  19. this.cmbUser_Department.DataSource = dt;
  20. this.cmbUser_Department.ValueMember = "ID";
  21. this.cmbUser_Department.DisplayMember = "Dt_Name";
  22. DataRow dr = dt.NewRow();
  23. dr["ID"] = "-1";
  24. dr["Dt_Name"] = "";
  25. dt.Rows.InsertAt(dr, 0);
  26. cmbUser_Department.SelectedIndex = 0;
  27. this.FormClosed += FrmInternalMail_FormClosed;
  28. }
  29. void FrmInternalMail_FormClosed(object sender, FormClosedEventArgs e)
  30. {
  31. if (bl)
  32. {
  33. this.DialogResult = DialogResult.OK;
  34. }
  35. }
  36. #region 加载
  37. protected override void FrmInternalMail_Load(object sender, EventArgs e)
  38. {
  39. try
  40. {
  41. bind();
  42. }
  43. catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
  44. }
  45. public void bind()
  46. {
  47. //获取用户表
  48. LYFZ.BLL.BLL_ErpUser user_viewbll = new BLL.BLL_ErpUser();
  49. DataTable dt = user_viewbll.GetView_tb_ErpUser("").Tables[0];
  50. this.dgv.AutoGenerateColumns = false;
  51. this.dgv.DataSource = dt;
  52. this.dgv.SelectAll();
  53. Xz();
  54. }
  55. #endregion
  56. #region 选择部门事件
  57. protected override void cmbUser_Department_SelectedValueChanged(object sender, EventArgs e)
  58. {
  59. if (!string.IsNullOrEmpty(cmbUser_Department.Text))
  60. {
  61. //获取用户表
  62. LYFZ.BLL.BLL_ErpUser user_viewbll = new BLL.BLL_ErpUser();
  63. DataTable dt = user_viewbll.GetView_tb_ErpUser("User_Department='" + cmbUser_Department.SelectedValue + "'").Tables[0];
  64. this.dgv.AutoGenerateColumns = false;
  65. this.dgv.DataSource = dt;
  66. this.dgv.SelectAll();
  67. txtImail_ToName.Text = "";
  68. txtCount.Text = "";
  69. if (dgv.Rows.Count > 0)
  70. {
  71. string User_Name = "";
  72. for (int i = 0; i < dgv.Rows.Count; i++)
  73. {
  74. User_Name += dgv.Rows[i].Cells["User_Name"].Value.ToString() + ",";
  75. }
  76. txtImail_ToName.Text = User_Name.Substring(0, User_Name.Length - 1);
  77. int count = txtImail_ToName.Text.Length - txtImail_ToName.Text.Replace(",", "").Length;
  78. txtCount.Text = Convert.ToInt32(count + 1).ToString();
  79. }
  80. else { txtCount.Text = ""; }
  81. }
  82. else { bind(); }
  83. }
  84. #endregion
  85. #region dgv事件
  86. protected override void dgv_Click(object sender, EventArgs e)
  87. {
  88. Xz();
  89. }
  90. public void Xz()
  91. {
  92. if (dgv.Rows.Count > 0)
  93. {
  94. string User_Name = "";
  95. string User_EmployeeID = "";
  96. for (int i = 0; i < dgv.SelectedRows.Count; i++)
  97. {
  98. User_Name += dgv.SelectedRows[i].Cells["User_Name"].Value.ToString() + ",";
  99. User_EmployeeID += dgv.SelectedRows[i].Cells["User_EmployeeID"].Value.ToString() + ",";
  100. }
  101. txtImail_ToName.Text = User_Name.Substring(0, User_Name.Length - 1);
  102. lblImail_ToName.Text = User_EmployeeID.Substring(0, User_EmployeeID.Length - 1);
  103. int count = txtImail_ToName.Text.Length - txtImail_ToName.Text.Replace(",", "").Length;
  104. txtCount.Text = Convert.ToInt32(count + 1).ToString();
  105. }
  106. else { txtCount.Text = ""; }
  107. }
  108. #endregion
  109. #region 发送消息
  110. protected override void btnRelease_Click(object sender, EventArgs e)
  111. {
  112. try
  113. {
  114. LYFZ.Model.Model_ErpInternalMail model = new Model.Model_ErpInternalMail();
  115. LYFZ.BLL.BLL_ErpInternalMail bll = new BLL.BLL_ErpInternalMail();
  116. if (string.IsNullOrEmpty(txtImail_ToName.Text))
  117. {
  118. MessageBoxCustom.Show("接收人不能为空!");
  119. return;
  120. }
  121. if (string.IsNullOrEmpty(txtImail_Content.Text))
  122. {
  123. MessageBoxCustom.Show("消息内容不能为空!");
  124. return;
  125. }
  126. model.Imail_Type = "1";
  127. model.Imail_Title = "";
  128. model.Imail_Content = txtImail_Content.Text;
  129. model.Imail_FromName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  130. model.Imail_ToName = lblImail_ToName.Text;
  131. model.Imail_Attachment = "";
  132. model.Imail_Status = "OK";
  133. model.Imail_ReadList = "";
  134. model.Imail_OwnerList = "";
  135. model.Imail_ToSendDatetime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime();
  136. model.Imail_DeleteList = "";
  137. model.Imail_CreateDatetime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime();
  138. model.Imail_UpdateDatetime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime();
  139. if (bll.Add(model) == true)
  140. {
  141. MessageBoxCustom.Show("发送成功!");
  142. txtImail_Content.Text = "";
  143. bl = true;
  144. }
  145. }
  146. catch (Exception ex)
  147. {
  148. MessageBoxCustom.Show(ex.Message);
  149. }
  150. }
  151. #endregion
  152. #region 关闭
  153. protected override void btnClose_Click(object sender, EventArgs e)
  154. {
  155. this.Close();
  156. }
  157. #endregion
  158. }
  159. }