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; using System.IO; using LYFZ.ComponentLibrary; namespace LYFZ.Software.MainBusiness.BulletinBoard { public partial class FrmBulletinBoard : LYFZ.Software.UI.BulletinBoard.FrmBulletinBoard { public FrmBulletinBoard() { } #region 加载 protected override void FrmBulletinBoard_Shown(object sender, EventArgs e) { try { bindBulletinBoard(); #region 权限设置 #region 发布公告 if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.BulletinBoardCompetence, CustomAttributes.OperatingAuthority.Announcement)) { btnAnnouncement.Enabled = true; } else { btnAnnouncement.Enabled = false; } #endregion #region 发送邮件 if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.BulletinBoardCompetence, CustomAttributes.OperatingAuthority.SendEmail)) { btnReleaseMail.Enabled = true; } else { btnReleaseMail.Enabled = false; } #endregion #region 删除 if (LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.BulletinBoardCompetence, CustomAttributes.OperatingAuthority.Delete)) { btnDelete.Enabled = true; } else { btnDelete.Enabled = false; } #endregion #endregion } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } #region 获取公告栏 /// /// 获取公告栏 /// public void bindBulletinBoard() { dgv.Columns["Imail_FromName"].Visible = true; dgv.Columns["Imail_FromName2"].Visible = false; dgv.Columns["Imail_Attachment"].Visible = true; dgv.Columns["Imail_ToName"].Visible = false; panelBulletinBoard.Visible = false; btnReleaseMail.Visible = false; btnAnnouncement.Visible = true; LYFZ.BLL.BLL_ErpInternalMail bll = new BLL.BLL_ErpInternalMail(); DataTable dt = bll.View_ErpInternalMail("Imail_Type='0'").Tables[0]; this.dgv.AutoGenerateColumns = false; this.dgv.DataSource = dt; lblCount.Text = dt.Rows.Count.ToString(); } #endregion #region 获取内部邮件 /// /// 获取内部邮件 /// public void bindInternalMail() { dgv.Columns["Imail_FromName"].Visible = false; dgv.Columns["Imail_FromName2"].Visible = true; dgv.Columns["Imail_Attachment"].Visible = false; dgv.Columns["Imail_ToName"].Visible = true; panelBulletinBoard.Visible = true; btnReleaseMail.Visible = true; btnAnnouncement.Visible = false; LYFZ.BLL.BLL_ErpInternalMail bll = new BLL.BLL_ErpInternalMail(); DataTable dt = new DataTable(); if (radInbox.Checked) { dt = bll.View_ErpInternalMail("Imail_Type='1' and Imail_ToName like '%" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID + "%'").Tables[0]; } if (radOutbox.Checked) { dt = bll.View_ErpInternalMail("Imail_Type='1' and Imail_FromName like '%" + LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID + "%'").Tables[0]; } this.dgv.AutoGenerateColumns = false; this.dgv.DataSource = dt; lblCount.Text = dt.Rows.Count.ToString(); } #endregion #endregion #region 单选点击公告栏 protected override void radBulletinBoard_Click(object sender, EventArgs e) { bindBulletinBoard(); } #endregion #region 单选点击内部邮件 protected override void radInternalMail_Click(object sender, EventArgs e) { bindInternalMail(); } #endregion #region 发布公告 protected override void btnAnnouncement_Click(object sender, EventArgs e) { LYFZ.Software.MainBusiness.BulletinBoard.FrmAnnouncement set = new FrmAnnouncement(); if (set.ShowDialog() == DialogResult.OK) { bindBulletinBoard(); } } #endregion #region 查询 protected override void btnSelect_Click(object sender, EventArgs e) { if (radBulletinBoard.Checked == true) { if (dgv.Rows.Count > 0) { int id = Convert.ToInt32(dgv.CurrentRow.Cells["ID"].Value); LYFZ.Software.MainBusiness.BulletinBoard.FrmSelectAnnouncement set = new FrmSelectAnnouncement(); set.ID = id; set.ShowDialog(); } } if (radInternalMail.Checked == true) { if (dgv.Rows.Count > 0) { int id = Convert.ToInt32(dgv.CurrentRow.Cells["ID"].Value); LYFZ.Software.MainBusiness.BulletinBoard.FrmSelectInternalMail set = new FrmSelectInternalMail(); set.ID = id; set.ShowDialog(); } } } protected override void dgv_DoubleClick(object sender, EventArgs e) { if (radBulletinBoard.Checked == true) { if (dgv.Rows.Count > 0) { int id = Convert.ToInt32(dgv.CurrentRow.Cells["ID"].Value); LYFZ.Software.MainBusiness.BulletinBoard.FrmSelectAnnouncement set = new FrmSelectAnnouncement(); set.ID = id; set.ShowDialog(); } } if (radInternalMail.Checked == true) { if (dgv.Rows.Count > 0) { int id = Convert.ToInt32(dgv.CurrentRow.Cells["ID"].Value); LYFZ.Software.MainBusiness.BulletinBoard.FrmSelectInternalMail set = new FrmSelectInternalMail(); set.ID = id; set.ShowDialog(); } } } #endregion #region 发送邮件 protected override void btnReleaseMail_Click(object sender, EventArgs e) { LYFZ.Software.MainBusiness.BulletinBoard.FrmInternalMail set = new FrmInternalMail(); if (set.ShowDialog() == DialogResult.OK) { bindInternalMail(); } } #endregion #region 删除 protected override void btnDelete_Click(object sender, EventArgs e) { try{ if (this.dgv.SelectedRows.Count == 0) { MessageBoxCustom.Show("请选中你要删除的数据!"); return; } if (MessageBoxCustom.Show("你确定要删除吗?", "删除提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { LYFZ.BLL.BLL_ErpInternalMail bll = new BLL.BLL_ErpInternalMail(); int id = Convert.ToInt32(this.dgv.CurrentRow.Cells["ID"].Value); //删除图片 DataTable dt = bll.GetList("Id=" + id + "").Tables[0]; if (!string.IsNullOrEmpty(dt.Rows[0]["Imail_Attachment"].ToString())) { File.Delete(BLL.BLL_ErpInternalMail.GetAnnouncementPath() + "\\" + dt.Rows[0]["Imail_Attachment"].ToString()); } if (bll.Delete(id) == true) { MessageBoxCustom.Show("删除成功!"); if (radBulletinBoard.Checked == true) { bindBulletinBoard(); } if (radInternalMail.Checked == true) { bindInternalMail(); } } else { MessageBoxCustom.Show("删除失败!"); } } } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } #endregion #region 关闭 protected override void btnClose_Click(object sender, EventArgs e) { this.Close(); } #endregion #region 发件箱 protected override void radOutbox_Click(object sender, EventArgs e) { bindInternalMail(); } #endregion #region 收件箱 protected override void radInbox_Click(object sender, EventArgs e) { bindInternalMail(); } #endregion } }