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.BulletinBoard { public partial class FrmInternalMail : LYFZ.Software.UI.BulletinBoard.FrmInternalMail { bool bl = false; public FrmInternalMail() { //绑定部门表 LYFZ.BLL.BLL_ErpDepartment depbll = new BLL.BLL_ErpDepartment(); DataTable dt = depbll.GetAllList().Tables[0]; this.cmbUser_Department.DataSource = dt; this.cmbUser_Department.ValueMember = "ID"; this.cmbUser_Department.DisplayMember = "Dt_Name"; DataRow dr = dt.NewRow(); dr["ID"] = "-1"; dr["Dt_Name"] = ""; dt.Rows.InsertAt(dr, 0); cmbUser_Department.SelectedIndex = 0; this.FormClosed += FrmInternalMail_FormClosed; } void FrmInternalMail_FormClosed(object sender, FormClosedEventArgs e) { if (bl) { this.DialogResult = DialogResult.OK; } } #region 加载 protected override void FrmInternalMail_Load(object sender, EventArgs e) { try { bind(); } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } public void bind() { //获取用户表 LYFZ.BLL.BLL_ErpUser user_viewbll = new BLL.BLL_ErpUser(); DataTable dt = user_viewbll.GetView_tb_ErpUser("").Tables[0]; this.dgv.AutoGenerateColumns = false; this.dgv.DataSource = dt; this.dgv.SelectAll(); Xz(); } #endregion #region 选择部门事件 protected override void cmbUser_Department_SelectedValueChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(cmbUser_Department.Text)) { //获取用户表 LYFZ.BLL.BLL_ErpUser user_viewbll = new BLL.BLL_ErpUser(); DataTable dt = user_viewbll.GetView_tb_ErpUser("User_Department='" + cmbUser_Department.SelectedValue + "'").Tables[0]; this.dgv.AutoGenerateColumns = false; this.dgv.DataSource = dt; this.dgv.SelectAll(); txtImail_ToName.Text = ""; txtCount.Text = ""; if (dgv.Rows.Count > 0) { string User_Name = ""; for (int i = 0; i < dgv.Rows.Count; i++) { User_Name += dgv.Rows[i].Cells["User_Name"].Value.ToString() + ","; } txtImail_ToName.Text = User_Name.Substring(0, User_Name.Length - 1); int count = txtImail_ToName.Text.Length - txtImail_ToName.Text.Replace(",", "").Length; txtCount.Text = Convert.ToInt32(count + 1).ToString(); } else { txtCount.Text = ""; } } else { bind(); } } #endregion #region dgv事件 protected override void dgv_Click(object sender, EventArgs e) { Xz(); } public void Xz() { if (dgv.Rows.Count > 0) { string User_Name = ""; string User_EmployeeID = ""; for (int i = 0; i < dgv.SelectedRows.Count; i++) { User_Name += dgv.SelectedRows[i].Cells["User_Name"].Value.ToString() + ","; User_EmployeeID += dgv.SelectedRows[i].Cells["User_EmployeeID"].Value.ToString() + ","; } txtImail_ToName.Text = User_Name.Substring(0, User_Name.Length - 1); lblImail_ToName.Text = User_EmployeeID.Substring(0, User_EmployeeID.Length - 1); int count = txtImail_ToName.Text.Length - txtImail_ToName.Text.Replace(",", "").Length; txtCount.Text = Convert.ToInt32(count + 1).ToString(); } else { txtCount.Text = ""; } } #endregion #region 发送消息 protected override void btnRelease_Click(object sender, EventArgs e) { try { LYFZ.Model.Model_ErpInternalMail model = new Model.Model_ErpInternalMail(); LYFZ.BLL.BLL_ErpInternalMail bll = new BLL.BLL_ErpInternalMail(); if (string.IsNullOrEmpty(txtImail_ToName.Text)) { MessageBoxCustom.Show("接收人不能为空!"); return; } if (string.IsNullOrEmpty(txtImail_Content.Text)) { MessageBoxCustom.Show("消息内容不能为空!"); return; } model.Imail_Type = "1"; model.Imail_Title = ""; model.Imail_Content = txtImail_Content.Text; model.Imail_FromName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID; model.Imail_ToName = lblImail_ToName.Text; model.Imail_Attachment = ""; model.Imail_Status = "OK"; model.Imail_ReadList = ""; model.Imail_OwnerList = ""; model.Imail_ToSendDatetime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime(); model.Imail_DeleteList = ""; model.Imail_CreateDatetime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime(); model.Imail_UpdateDatetime = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetServerDateTime(); if (bll.Add(model) == true) { MessageBoxCustom.Show("发送成功!"); txtImail_Content.Text = ""; bl = true; } } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } #endregion #region 关闭 protected override void btnClose_Click(object sender, EventArgs e) { this.Close(); } #endregion } }