using LYFZ.BLL; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace LYFZ.Software.MainBusiness.OAShopManagement { public class frmBulletinBoard : LYFZ.Software.UI.OAShopManagement.frmBulletinBoard { LYFZ.BLL.BLL_ErpShopBulletin sbbll = new BLL_ErpShopBulletin(); LYFZ.BLL.BLL_ErpShopDesignatedAnnounced sdbll = new BLL_ErpShopDesignatedAnnounced(); public frmBulletinBoard() { this.tabControlBulletinBoard.SelectedIndexChanged += tabControlBulletinBoard_SelectedIndexChanged; this.btndel.Click += btndel_Click; this.btnClose.Click += btnClose_Click; this.btnAdd.Click += btnAdd_Click; this.dgvBulletinBoard.CellDoubleClick += dgvBulletinBoard_CellDoubleClick; this.ucNotice.EventPaging += ucNotice_EventPaging; this.ucNotice.PageSize = LYFZ.BLL.BLL_SystemGlobalSetting.SysTemGlobalSetMoel.ReportFormPageSize; this.Shown += frmBulletinBoard_Shown; this.btnAdd.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.BulletinBoardCompetence, CustomAttributes.OperatingAuthority.Announcement); this.btndel.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.BulletinBoardCompetence, CustomAttributes.OperatingAuthority.Delete); } DataTable dtUser = LYFZ.DAL.DAL_ErpUser.SimpleUserDataTable; /// /// 当前用户ID /// string EmployeeID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID; /// /// 窗体加载事件 /// /// /// void frmBulletinBoard_Shown(object sender, EventArgs e) { this.PublicFunctionRows(); } /// /// 列表双击事件 /// /// /// void dgvBulletinBoard_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (this.dgvBulletinBoard.Rows.Count > 0) { if (this.dgvBulletinBoard.CurrentRow != null) { if (e.ColumnIndex >= 0 && e.RowIndex >= 0) { frmReleaseBulletinBoard frm = new frmReleaseBulletinBoard(); frm.StrGGNumber = this.dgvBulletinBoard.CurrentRow.Cells["公告ID"].Value.ToString().Trim(); frm.ShowDialog(); if (frm.IsSaveed) { this.PublicFunctionRows(); } } } } } /// /// 发布公告 /// /// /// void btnAdd_Click(object sender, EventArgs e) { frmReleaseBulletinBoard frm = new frmReleaseBulletinBoard(); frm.StartPosition = System.Windows.Forms.FormStartPosition.Manual; frm.Location = new Point(LYFZ.EnumPublic.FormLocation_X, LYFZ.EnumPublic.FormLocation_Y); frm.Size = new Size(LYFZ.EnumPublic.FormSize_Width, LYFZ.EnumPublic.FormSize_Height); frm.StrType = this.tabControlType(); frm.ShowDialog(); if (frm.IsSaveed) { if (frm.CurrentBulletinModel != null) { System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(BulletinBoardPushMessage),new object[]{ frm.CurrentBulletinModel,frm.CurrentPersonModel}); } this.PublicFunctionRows(); } } /// /// 发布公告时推送消息 /// void BulletinBoardPushMessage(object b) { try { if (b != null) { object[] barry = (object[])b; LYFZ.Model.Model_ErpShopBulletin buuletinModel = (Model.Model_ErpShopBulletin)barry[0]; LYFZ.Model.Model_ErpShopDesignatedAnnounced personModel = (LYFZ.Model.Model_ErpShopDesignatedAnnounced)barry[1]; sbbll.BulletinBoardPushMessage(buuletinModel, personModel); } } catch { } } /// /// 关闭窗体 /// /// /// void btnClose_Click(object sender, EventArgs e) { this.Close(); } /// /// 删除公告 /// /// /// void btndel_Click(object sender, EventArgs e) { if (this.dgvBulletinBoard.Rows.Count > 0) { if (this.dgvBulletinBoard.SelectedRows != null) { if (this.dgvBulletinBoard.CurrentCell.RowIndex >= 0 && this.dgvBulletinBoard.CurrentRow.Index >= 0) { if (MessageBoxCustom.Show("是否删除?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { string StrGGNumber = dgvBulletinBoard.Rows[dgvBulletinBoard.CurrentRow.Index].Cells["公告ID"].Value.ToString(); string StrPath = dgvBulletinBoard.Rows[dgvBulletinBoard.CurrentRow.Index].Cells["文件路径"].Value.ToString(); List clist = new List(); clist.Add(sbbll.GetDeleteCommandInfo(whereStr: "Bulletin_TheID = '" + StrGGNumber + "'")); clist.Add(sdbll.GetDeleteCommandInfo(whereStr: "Announced_announcement = '" + StrGGNumber + "'")); if (StrPath != "") { string[] StrArray = StrPath.Split('|'); LYFZ.Software.MainBusiness.TCPFileTransfer tcpFile = new MainBusiness.TCPFileTransfer(); LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker) { backgroundWorker.ReportProgress(0, "正在连接服务器..."); try { for (int i = 0; i < StrArray.Length; i++) { if (!string.IsNullOrEmpty(StrArray[i].Trim())) { string ret = tcpFile.DeleteFile(StrArray[i].Trim(), backgroundWorker); } } } catch (Exception ex) { MessageBoxCustom.Show(ex.Message, backgroundWorker: backgroundWorker); } }); } if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) > 0) { this.PublicFunctionRows(); } else { MessageBoxCustom.Show("删除失败"); } } } } else { MessageBoxCustom.Show("请选择想要删除的公告"); } } } /// /// 选项卡选择事件 /// /// /// void tabControlBulletinBoard_SelectedIndexChanged(object sender, EventArgs e) { ucNotice.Bind(); ShowDgvBulletinBoard(this.tabControlBulletinBoard.TabPages[this.tabControlBulletinBoard.SelectedIndex]); } void ShowDgvBulletinBoard(TabPage pge) { pge.Margin = new System.Windows.Forms.Padding(0); pge.Padding = new Padding(0); this.dgvBulletinBoard.Margin = new System.Windows.Forms.Padding(0); this.dgvBulletinBoard.Dock = DockStyle.Fill; this.dgvBulletinBoard.Location = new Point(0, 0); pge.Controls.Clear(); pge.Controls.Add(this.dgvBulletinBoard); } private delegate void UpdateControl(); /// /// 公共刷新方法 /// public void PublicFunctionRows() { ucNotice.Bind(); } //分页 public int ucNotice_EventPaging(UCPager.EventPagingArg e) { if (dgvBulletinBoard.Rows.Count > 0) { dgvBulletinBoard.Rows.Clear(); } LYFZ.UCPager.PageData pageData = new LYFZ.UCPager.PageData(); pageData.TableName = "Vw_ErpShopBulletin"; pageData.PageIndex = this.ucNotice.PageCurrent; pageData.PageSize = this.ucNotice.PageSize; pageData.QueryCondition = " (可看指定人ID like '%" + EmployeeID + "%' or 可看指定人ID is null or 可看指定人ID='1') and 公告类型 like '%" + tabControlType() + "%'"; pageData.QueryFieldName = "发布人姓名,公告类型,标题,内容,发布时间,发布人ID,文件路径,可看指定人ID,公告ID,可看公告ID,已读人员";//可看指定人姓名 pageData.OrderStr = "ID desc"; pageData.OrderType = 1; DataTable dt = pageData.QueryDataTable().Tables[0]; LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker) { this.Invoke(new UpdateControl(delegate() { #region for (int t = 0; t < dt.Rows.Count; t++) { DataGridViewRow dgvr = new DataGridViewRow(); DataGridViewCell cell = null; //标题 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["已读人员"].ToString().IndexOf(EmployeeID) == -1 ? "【新】 " + dt.Rows[t]["标题"].ToString().Trim() : dt.Rows[t]["标题"].ToString().Trim(); dgvr.Cells.Add(cell); //内容 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["内容"].ToString().Trim(); dgvr.Cells.Add(cell); //公告类型 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["公告类型"].ToString().Trim(); dgvr.Cells.Add(cell); //发布人姓名 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["发布人姓名"].ToString().Trim(); dgvr.Cells.Add(cell); //发布时间 cell = new DataGridViewTextBoxCell(); cell.Value = LYFZ.Command.Command_Validate.DateTimeToString(dt.Rows[t]["发布时间"], "yyyy-MM-dd HH:mm"); dgvr.Cells.Add(cell); //可看指定人姓名 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["可看指定人ID"].ToString().Trim(); dgvr.Cells.Add(cell); //发布人 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["发布人ID"].ToString().Trim(); dgvr.Cells.Add(cell); //文件路径 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["文件路径"].ToString().Trim(); dgvr.Cells.Add(cell); //可看指定人 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["可看指定人ID"].ToString(); dgvr.Cells.Add(cell); //公告 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["公告ID"].ToString(); dgvr.Cells.Add(cell); //是否已看 cell = new DataGridViewTextBoxCell(); cell.Value = dt.Rows[t]["已读人员"].ToString().IndexOf(EmployeeID) == -1 ? "on" : "ok"; dgvr.Cells.Add(cell); //已看人员 cell = new DataGridViewTextBoxCell(); string[] strArray = dt.Rows[t]["已读人员"].ToString().Trim().Split(','); string StrSeenPerson = ""; string StrSeenPersonNumber = ""; for (int i = 0; i < strArray.Length; i++) { if (strArray[i].Trim() != LYFZ.BLL.BLL_ErpUser.Admin_20141125111443713) { StrSeenPersonNumber += strArray[i].Trim() + ","; DataRow dtRow = dtUser.Rows.Find(strArray[i].Trim()); if (dtRow != null) { StrSeenPerson += dtRow["User_Name"].ToString() + ","; } } } cell.Value = StrSeenPerson;// Nsername(dt.Rows[t]["已读人员"].ToString().Trim()); dgvr.Cells.Add(cell); this.dgvBulletinBoard.Rows.Add(dgvr); dgvBulletinBoard.ClearSelection(); } #endregion })); }); try { if (dt != null) { this.ucNotice.TbDataSource = dt; } } catch { } return pageData.TotalCount; } /// /// 返回当前选项卡的值 /// /// string tabControlType() { string StrBulletinType = ""; switch (tabControlBulletinBoard.SelectedIndex) { case 0: StrBulletinType = ""; break; case 1: StrBulletinType = enumBulletinType.日常公告.ToString(); break; case 2: StrBulletinType = enumBulletinType.规章制度.ToString(); break; case 3: StrBulletinType = enumBulletinType.荣誉表彰.ToString(); break; case 4: StrBulletinType = enumBulletinType.惩罚警示.ToString(); break; case 5: StrBulletinType = enumBulletinType.员工手册.ToString(); break; case 6: StrBulletinType = enumBulletinType.学习资料.ToString(); break; } return StrBulletinType; } enum enumBulletinType { 最新公告, 日常公告, 规章制度, 荣誉表彰, 惩罚警示, 员工手册, 学习资料 } } }