frmBulletinBoard.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. using LYFZ.BLL;
  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.OAShopManagement
  11. {
  12. public class frmBulletinBoard : LYFZ.Software.UI.OAShopManagement.frmBulletinBoard
  13. {
  14. LYFZ.BLL.BLL_ErpShopBulletin sbbll = new BLL_ErpShopBulletin();
  15. LYFZ.BLL.BLL_ErpShopDesignatedAnnounced sdbll = new BLL_ErpShopDesignatedAnnounced();
  16. public frmBulletinBoard()
  17. {
  18. this.tabControlBulletinBoard.SelectedIndexChanged += tabControlBulletinBoard_SelectedIndexChanged;
  19. this.btndel.Click += btndel_Click;
  20. this.btnClose.Click += btnClose_Click;
  21. this.btnAdd.Click += btnAdd_Click;
  22. this.dgvBulletinBoard.CellDoubleClick += dgvBulletinBoard_CellDoubleClick;
  23. this.ucNotice.EventPaging += ucNotice_EventPaging;
  24. this.ucNotice.PageSize = LYFZ.BLL.BLL_SystemGlobalSetting.SysTemGlobalSetMoel.ReportFormPageSize;
  25. this.Shown += frmBulletinBoard_Shown;
  26. this.btnAdd.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.BulletinBoardCompetence, CustomAttributes.OperatingAuthority.Announcement);
  27. this.btndel.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.BulletinBoardCompetence, CustomAttributes.OperatingAuthority.Delete);
  28. }
  29. DataTable dtUser = LYFZ.DAL.DAL_ErpUser.SimpleUserDataTable;
  30. /// <summary>
  31. /// 当前用户ID
  32. /// </summary>
  33. string EmployeeID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  34. /// <summary>
  35. /// 窗体加载事件
  36. /// </summary>
  37. /// <param name="sender"></param>
  38. /// <param name="e"></param>
  39. void frmBulletinBoard_Shown(object sender, EventArgs e)
  40. {
  41. this.PublicFunctionRows();
  42. }
  43. /// <summary>
  44. /// 列表双击事件
  45. /// </summary>
  46. /// <param name="sender"></param>
  47. /// <param name="e"></param>
  48. void dgvBulletinBoard_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  49. {
  50. if (this.dgvBulletinBoard.Rows.Count > 0)
  51. {
  52. if (this.dgvBulletinBoard.CurrentRow != null)
  53. {
  54. if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
  55. {
  56. frmReleaseBulletinBoard frm = new frmReleaseBulletinBoard();
  57. frm.StrGGNumber = this.dgvBulletinBoard.CurrentRow.Cells["公告ID"].Value.ToString().Trim();
  58. frm.ShowDialog();
  59. if (frm.IsSaveed)
  60. { this.PublicFunctionRows(); }
  61. }
  62. }
  63. }
  64. }
  65. /// <summary>
  66. /// 发布公告
  67. /// </summary>
  68. /// <param name="sender"></param>
  69. /// <param name="e"></param>
  70. void btnAdd_Click(object sender, EventArgs e)
  71. {
  72. frmReleaseBulletinBoard frm = new frmReleaseBulletinBoard();
  73. frm.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
  74. frm.Location = new Point(LYFZ.EnumPublic.FormLocation_X, LYFZ.EnumPublic.FormLocation_Y);
  75. frm.Size = new Size(LYFZ.EnumPublic.FormSize_Width, LYFZ.EnumPublic.FormSize_Height);
  76. frm.StrType = this.tabControlType();
  77. frm.ShowDialog();
  78. if (frm.IsSaveed)
  79. {
  80. if (frm.CurrentBulletinModel != null)
  81. {
  82. System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(BulletinBoardPushMessage),new object[]{ frm.CurrentBulletinModel,frm.CurrentPersonModel});
  83. }
  84. this.PublicFunctionRows();
  85. }
  86. }
  87. /// <summary>
  88. /// 发布公告时推送消息
  89. /// </summary>
  90. void BulletinBoardPushMessage(object b)
  91. {
  92. try
  93. {
  94. if (b != null)
  95. {
  96. object[] barry = (object[])b;
  97. LYFZ.Model.Model_ErpShopBulletin buuletinModel = (Model.Model_ErpShopBulletin)barry[0];
  98. LYFZ.Model.Model_ErpShopDesignatedAnnounced personModel = (LYFZ.Model.Model_ErpShopDesignatedAnnounced)barry[1];
  99. sbbll.BulletinBoardPushMessage(buuletinModel, personModel);
  100. }
  101. }
  102. catch { }
  103. }
  104. /// <summary>
  105. /// 关闭窗体
  106. /// </summary>
  107. /// <param name="sender"></param>
  108. /// <param name="e"></param>
  109. void btnClose_Click(object sender, EventArgs e)
  110. { this.Close(); }
  111. /// <summary>
  112. /// 删除公告
  113. /// </summary>
  114. /// <param name="sender"></param>
  115. /// <param name="e"></param>
  116. void btndel_Click(object sender, EventArgs e)
  117. {
  118. if (this.dgvBulletinBoard.Rows.Count > 0)
  119. {
  120. if (this.dgvBulletinBoard.SelectedRows != null)
  121. {
  122. if (this.dgvBulletinBoard.CurrentCell.RowIndex >= 0 && this.dgvBulletinBoard.CurrentRow.Index >= 0)
  123. {
  124. if (MessageBoxCustom.Show("是否删除?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
  125. {
  126. string StrGGNumber = dgvBulletinBoard.Rows[dgvBulletinBoard.CurrentRow.Index].Cells["公告ID"].Value.ToString();
  127. string StrPath = dgvBulletinBoard.Rows[dgvBulletinBoard.CurrentRow.Index].Cells["文件路径"].Value.ToString();
  128. List<Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  129. clist.Add(sbbll.GetDeleteCommandInfo(whereStr: "Bulletin_TheID = '" + StrGGNumber + "'"));
  130. clist.Add(sdbll.GetDeleteCommandInfo(whereStr: "Announced_announcement = '" + StrGGNumber + "'"));
  131. if (StrPath != "")
  132. {
  133. string[] StrArray = StrPath.Split('|');
  134. LYFZ.Software.MainBusiness.TCPFileTransfer tcpFile = new MainBusiness.TCPFileTransfer();
  135. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  136. {
  137. backgroundWorker.ReportProgress(0, "正在连接服务器...");
  138. try
  139. {
  140. for (int i = 0; i < StrArray.Length; i++)
  141. {
  142. if (!string.IsNullOrEmpty(StrArray[i].Trim()))
  143. { string ret = tcpFile.DeleteFile(StrArray[i].Trim(), backgroundWorker); }
  144. }
  145. }
  146. catch (Exception ex)
  147. { MessageBoxCustom.Show(ex.Message, backgroundWorker: backgroundWorker); }
  148. });
  149. }
  150. if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) > 0)
  151. { this.PublicFunctionRows(); }
  152. else
  153. { MessageBoxCustom.Show("删除失败"); }
  154. }
  155. }
  156. }
  157. else
  158. { MessageBoxCustom.Show("请选择想要删除的公告"); }
  159. }
  160. }
  161. /// <summary>
  162. /// 选项卡选择事件
  163. /// </summary>
  164. /// <param name="sender"></param>
  165. /// <param name="e"></param>
  166. void tabControlBulletinBoard_SelectedIndexChanged(object sender, EventArgs e)
  167. {
  168. ucNotice.Bind();
  169. ShowDgvBulletinBoard(this.tabControlBulletinBoard.TabPages[this.tabControlBulletinBoard.SelectedIndex]);
  170. }
  171. void ShowDgvBulletinBoard(TabPage pge)
  172. {
  173. pge.Margin = new System.Windows.Forms.Padding(0);
  174. pge.Padding = new Padding(0);
  175. this.dgvBulletinBoard.Margin = new System.Windows.Forms.Padding(0);
  176. this.dgvBulletinBoard.Dock = DockStyle.Fill;
  177. this.dgvBulletinBoard.Location = new Point(0, 0);
  178. pge.Controls.Clear();
  179. pge.Controls.Add(this.dgvBulletinBoard);
  180. }
  181. private delegate void UpdateControl();
  182. /// <summary>
  183. /// 公共刷新方法
  184. /// </summary>
  185. public void PublicFunctionRows()
  186. {
  187. ucNotice.Bind();
  188. }
  189. //分页
  190. public int ucNotice_EventPaging(UCPager.EventPagingArg e)
  191. {
  192. if (dgvBulletinBoard.Rows.Count > 0)
  193. { dgvBulletinBoard.Rows.Clear(); }
  194. LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData();
  195. pageData.TableName = "Vw_ErpShopBulletin";
  196. pageData.PageIndex = this.ucNotice.PageCurrent;
  197. pageData.PageSize = this.ucNotice.PageSize;
  198. pageData.QueryCondition = " (可看指定人ID like '%" + EmployeeID + "%' or 可看指定人ID is null or 可看指定人ID='1') and 公告类型 like '%" + tabControlType() + "%'";
  199. pageData.QueryFieldName = "发布人姓名,公告类型,标题,内容,发布时间,发布人ID,文件路径,可看指定人ID,公告ID,可看公告ID,已读人员";//可看指定人姓名
  200. pageData.OrderStr = "ID desc";
  201. pageData.OrderType = 1;
  202. DataTable dt = pageData.QueryDataTable().Tables[0];
  203. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  204. {
  205. this.Invoke(new UpdateControl(delegate()
  206. {
  207. #region
  208. for (int t = 0; t < dt.Rows.Count; t++)
  209. {
  210. DataGridViewRow dgvr = new DataGridViewRow();
  211. DataGridViewCell cell = null;
  212. //标题
  213. cell = new DataGridViewTextBoxCell();
  214. cell.Value = dt.Rows[t]["已读人员"].ToString().IndexOf(EmployeeID) == -1 ? "【新】 " + dt.Rows[t]["标题"].ToString().Trim() : dt.Rows[t]["标题"].ToString().Trim();
  215. dgvr.Cells.Add(cell);
  216. //内容
  217. cell = new DataGridViewTextBoxCell();
  218. cell.Value = dt.Rows[t]["内容"].ToString().Trim();
  219. dgvr.Cells.Add(cell);
  220. //公告类型
  221. cell = new DataGridViewTextBoxCell();
  222. cell.Value = dt.Rows[t]["公告类型"].ToString().Trim();
  223. dgvr.Cells.Add(cell);
  224. //发布人姓名
  225. cell = new DataGridViewTextBoxCell();
  226. cell.Value = dt.Rows[t]["发布人姓名"].ToString().Trim();
  227. dgvr.Cells.Add(cell);
  228. //发布时间
  229. cell = new DataGridViewTextBoxCell();
  230. cell.Value = LYFZ.Command.Command_Validate.DateTimeToString(dt.Rows[t]["发布时间"], "yyyy-MM-dd HH:mm");
  231. dgvr.Cells.Add(cell);
  232. //可看指定人姓名
  233. cell = new DataGridViewTextBoxCell();
  234. cell.Value = dt.Rows[t]["可看指定人ID"].ToString().Trim();
  235. dgvr.Cells.Add(cell);
  236. //发布人
  237. cell = new DataGridViewTextBoxCell();
  238. cell.Value = dt.Rows[t]["发布人ID"].ToString().Trim();
  239. dgvr.Cells.Add(cell);
  240. //文件路径
  241. cell = new DataGridViewTextBoxCell();
  242. cell.Value = dt.Rows[t]["文件路径"].ToString().Trim();
  243. dgvr.Cells.Add(cell);
  244. //可看指定人
  245. cell = new DataGridViewTextBoxCell();
  246. cell.Value = dt.Rows[t]["可看指定人ID"].ToString();
  247. dgvr.Cells.Add(cell);
  248. //公告
  249. cell = new DataGridViewTextBoxCell();
  250. cell.Value = dt.Rows[t]["公告ID"].ToString();
  251. dgvr.Cells.Add(cell);
  252. //是否已看
  253. cell = new DataGridViewTextBoxCell();
  254. cell.Value = dt.Rows[t]["已读人员"].ToString().IndexOf(EmployeeID) == -1 ? "on" : "ok";
  255. dgvr.Cells.Add(cell);
  256. //已看人员
  257. cell = new DataGridViewTextBoxCell();
  258. string[] strArray = dt.Rows[t]["已读人员"].ToString().Trim().Split(',');
  259. string StrSeenPerson = "";
  260. string StrSeenPersonNumber = "";
  261. for (int i = 0; i < strArray.Length; i++)
  262. {
  263. if (strArray[i].Trim() != LYFZ.BLL.BLL_ErpUser.Admin_20141125111443713)
  264. {
  265. StrSeenPersonNumber += strArray[i].Trim() + ",";
  266. DataRow dtRow = dtUser.Rows.Find(strArray[i].Trim());
  267. if (dtRow != null)
  268. { StrSeenPerson += dtRow["User_Name"].ToString() + ","; }
  269. }
  270. }
  271. cell.Value = StrSeenPerson;// Nsername(dt.Rows[t]["已读人员"].ToString().Trim());
  272. dgvr.Cells.Add(cell);
  273. this.dgvBulletinBoard.Rows.Add(dgvr);
  274. dgvBulletinBoard.ClearSelection();
  275. }
  276. #endregion
  277. }));
  278. });
  279. try
  280. {
  281. if (dt != null)
  282. { this.ucNotice.TbDataSource = dt; }
  283. }
  284. catch
  285. { }
  286. return pageData.TotalCount;
  287. }
  288. /// <summary>
  289. /// 返回当前选项卡的值
  290. /// </summary>
  291. /// <returns></returns>
  292. string tabControlType()
  293. {
  294. string StrBulletinType = "";
  295. switch (tabControlBulletinBoard.SelectedIndex)
  296. {
  297. case 0: StrBulletinType = ""; break;
  298. case 1: StrBulletinType = enumBulletinType.日常公告.ToString(); break;
  299. case 2: StrBulletinType = enumBulletinType.规章制度.ToString(); break;
  300. case 3: StrBulletinType = enumBulletinType.荣誉表彰.ToString(); break;
  301. case 4: StrBulletinType = enumBulletinType.惩罚警示.ToString(); break;
  302. case 5: StrBulletinType = enumBulletinType.员工手册.ToString(); break;
  303. case 6: StrBulletinType = enumBulletinType.学习资料.ToString(); break;
  304. }
  305. return StrBulletinType;
  306. }
  307. enum enumBulletinType
  308. {
  309. 最新公告,
  310. 日常公告,
  311. 规章制度,
  312. 荣誉表彰,
  313. 惩罚警示,
  314. 员工手册,
  315. 学习资料
  316. }
  317. }
  318. }