using LYFZ.BLL; using LYFZ.ComponentLibrary; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Web.UI.WebControls; using System.Windows.Forms; namespace LYFZ.Software.MainBusiness.OAShopManagement { public class frmReleaseBulletinBoard : LYFZ.Software.UI.OAShopManagement.frmReleaseBulletinBoard { LYFZ.BLL.BLL_ErpOrder orbll = new BLL_ErpOrder(); LYFZ.BLL.BLL_ErpShopBulletin sbbll = new LYFZ.BLL.BLL_ErpShopBulletin(); LYFZ.BLL.BLL_ErpShopDesignatedAnnounced sdbll = new LYFZ.BLL.BLL_ErpShopDesignatedAnnounced(); public frmReleaseBulletinBoard() { this.Load += frmReleaseBulletinBoard_Load; this.Shown += frmReleaseBulletinBoard_Shown; this.cmbSeenPeople.SelectedIndexChanged += comboBoxVisiblePeople_SelectedIndexChanged; this.btnUploadFile.Click += btnUploadFile_Click; this.btnRemoveFile.Click += btnRemoveFile_Click; this.btnDownloadFile.Click += btnDownloadFile_Click; this.btnRelease.Click += btnRelease_Click; this.btnClose.Click += btnClose_Click; this.cmbBulletinType.SelectedIndex = 0; this.cmbSeenPeople.SelectedIndex = 0; this.btnSeenPerson.Click += btnSeenPerson_Click; this.btnNext.Click += btnNext_Click; } /// /// 当前用户ID /// string EmployeeID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID; /// /// 提示变量(true 是提示) /// public bool Prompt = false; /// /// 类型 /// public string StrType = ""; /// /// 公告编号 /// public string StrGGNumber = ""; /// /// 是否保存 /// public bool IsSaveed = false; /// /// 用户集合 /// DataTable dtUser = LYFZ.DAL.DAL_ErpUser.SimpleUserDataTable; /// /// 获取当前服务器路径 /// LYFZ.Model.Model_Config mConfig = new LYFZ.BLL.BLL_Config().GetModel_SysConfig(); /// /// 服务器路径 /// string StrServerPath = @"\UploadFiles\Announcement\"; /// /// 弹窗时用的数据缓存 /// DataTable dtPrompt = new DataTable(); LYFZ.Model.Model_ErpShopBulletin currentBulletinModel = null; /// /// 当前公告内容对象 /// public LYFZ.Model.Model_ErpShopBulletin CurrentBulletinModel { get { return currentBulletinModel; } set { currentBulletinModel = value; } } LYFZ.Model.Model_ErpShopDesignatedAnnounced currentPersonModel = null; /// /// /// public LYFZ.Model.Model_ErpShopDesignatedAnnounced CurrentPersonModel { get { return currentPersonModel; } set { currentPersonModel = value; } } /// /// 窗体加载事件 /// /// /// void frmReleaseBulletinBoard_Load(object sender, EventArgs e) { if (Prompt) { //dtPrompt = sdbll.GetDatatable(this.EmployeeID); dtPrompt = orbll.GetView_Custom("tb_ErpShopBulletin Left Join tb_ErpShopDesignatedAnnounced on Announced_announcement = Bulletin_TheID", StrWhere: "(readID not like '%" + EmployeeID + "%' or readID is null) and (Announced_issuerID like '%" + EmployeeID + "%' or Announced_issuerID is null or Announced_issuerID = '1')", ShowColumnName: "Bulletin_TheID,Bulletin_issuerID,Bulletin_announcement,Bulletin_Title,Bulletin_content,Bulletin_ReleaseTime,Bulletin_Accessory,Announced_issuerID,readID").Tables[0]; this.btnRelease.Visible = false; this.btnNext.Visible = true; if (dtPrompt.Rows.Count > 0) { this.ToViewNext(); } else { this.Close(); } } } LYFZ.BLL.BLL_ErpShopBulletin bulletinBll = new BLL_ErpShopBulletin(); /// /// 窗体加载事件 /// /// /// void frmReleaseBulletinBoard_Shown(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.StrGGNumber)) { DataTable tbl = orbll.GetView_Custom("tb_ErpShopBulletin Left Join tb_ErpShopDesignatedAnnounced on Announced_announcement = Bulletin_TheID", StrWhere: "Bulletin_TheID = '" + this.StrGGNumber + "'", ShowColumnName: "Bulletin_TheID,Bulletin_issuerID,Bulletin_announcement,Bulletin_Title,Bulletin_content,Bulletin_ReleaseTime,Bulletin_Accessory,Announced_issuerID,readID").Tables[0]; this.cmbBulletinType.Text = tbl.Rows[0]["Bulletin_announcement"].ToString().Trim(); this.txtBulletinTitle.Text = tbl.Rows[0]["Bulletin_Title"].ToString().Trim(); if (!string.IsNullOrEmpty(tbl.Rows[0]["Announced_issuerID"].ToString().Trim()) && tbl.Rows[0]["Announced_issuerID"].ToString().Trim() != "1") { this.cmbSeenPeople.Text = "指定人员"; } else { this.cmbSeenPeople.Text = "全员可见"; } this.txtBulletinInfo.Text = tbl.Rows[0]["Bulletin_content"].ToString().Trim(); string[] strArray = tbl.Rows[0]["Announced_issuerID"].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() + ","; } } } this.txtSeenPerson.Text = StrSeenPerson.TrimEnd(','); this.txtSeenPerson.Tag = StrSeenPersonNumber.TrimEnd(','); string[] StrArrayPath = tbl.Rows[0]["Bulletin_Accessory"].ToString().Trim().Split('|'); System.Windows.Forms.TreeNode root = null; for (int i = 0; i < StrArrayPath.Length; i++) { if (!string.IsNullOrEmpty(StrArrayPath[i].Trim())) { root = new System.Windows.Forms.TreeNode(); root.Text = @"\" + StrArrayPath[i].Trim(); root.Tag = @"\" + StrArrayPath[i].Trim(); root.ForeColor = Color.Blue; this.treevFile.Nodes.Add(root); } } this.btnRelease.Text = "修改"; if (tbl.Rows[0]["Bulletin_issuerID"].ToString().Trim() != this.EmployeeID && !LYFZ.BLL.BLL_ErpUser.IsAdministrator()) { this.btnRelease.Enabled = false; } //this.btnRelease.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.BulletinBoardCompetence, CustomAttributes.OperatingAuthority.Update); } else { if (!Prompt) { this.cmbBulletinType.Text = this.StrType; } this.btnRelease.Enabled = LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.BulletinBoardCompetence, CustomAttributes.OperatingAuthority.Announcement); } } Hashtable htDataFile = new Hashtable(); /// /// 可见范围选择事件 /// /// /// void comboBoxVisiblePeople_SelectedIndexChanged(object sender, EventArgs e) { //判断可见范围 if (cmbSeenPeople.SelectedItem.ToString() == "指定人员") { this.panelOrderPerson.Visible = true; } else { this.panelOrderPerson.Visible = false; } } /// /// 选择接单人 /// /// /// void btnSeenPerson_Click(object sender, EventArgs e) { new LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses().txtOrdersPerson(this.txtSeenPerson, false); } /// /// 选择文件 /// /// /// void btnUploadFile_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Multiselect = true; openFileDialog.Title = "选择附件"; if (openFileDialog.ShowDialog() == DialogResult.OK) { string[] StrFileArray = openFileDialog.FileNames; System.Windows.Forms.TreeNode root = null; for (int i = 0; i < StrFileArray.Length; i++) { root = new System.Windows.Forms.TreeNode(); root.Text = StrFileArray[i].Trim(); //new System.IO.FileInfo(StrFileArray[i].Trim()).Name; root.Tag = StrFileArray[i].Trim(); root.ForeColor = Color.Red; this.treevFile.Nodes.Add(root); } } } /// /// 移除文件 /// /// /// void btnRemoveFile_Click(object sender, EventArgs e) { if (this.treevFile.Nodes.Count > 0) { if (this.treevFile.SelectedNode.ForeColor != Color.Red) { if (MessageBoxCustom.Show("您选择的附件已保存在服务上,你确定要移除'" + this.treevFile.SelectedNode.Text.Trim() + "'吗?", "温馨提示!", MessageBoxButtons.YesNo) == DialogResult.No) { return; } string StrTreevServerPathFile = StrServerPath + "\\" + this.StrGGNumber + "\\" + new System.IO.FileInfo(this.treevFile.SelectedNode.Tag.ToString().Trim()).Name; htDataFile[this.treevFile.SelectedNode.Tag.ToString().Trim()] = "移除"; } this.treevFile.Nodes.Remove(this.treevFile.SelectedNode); } } /// /// 下载文件 /// /// /// void btnDownloadFile_Click(object sender, EventArgs e) { if (this.treevFile.Nodes.Count > 0) { if (this.treevFile.SelectedNode != null) { if (this.treevFile.SelectedNode.ForeColor != Color.Red) { SaveFileDialog saveFileDialog = new SaveFileDialog(); string StrOldPath = this.treevFile.SelectedNode.Tag.ToString(); string StrFileName = new System.IO.FileInfo(StrOldPath).Name; saveFileDialog.Filter = "压缩文件(*." + StrFileName.Split('.')[1].ToString() + ")|*." + StrFileName.Split('.')[1].ToString(); saveFileDialog.FilterIndex = 1; if (saveFileDialog.ShowDialog() == DialogResult.OK) { string StrPath = saveFileDialog.FileName; LYFZ.Software.MainBusiness.TCPFileTransfer tcpFile = new MainBusiness.TCPFileTransfer(); LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker) { try { backgroundWorker.ReportProgress(0, "正在连接服务器..."); string ret = tcpFile.DownloadFile(StrPath, StrOldPath, backgroundWorker); MessageBoxCustom.Show(ret, backgroundWorker: backgroundWorker); } catch (Exception ex) { MessageBoxCustom.Show(ex.Message, backgroundWorker: backgroundWorker); } }); } } else { MessageBoxCustom.Show("你选择的附件尚未保存,请先保存后再下载!"); } } } } /// /// 发布 /// /// /// void btnRelease_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.cmbBulletinType.Text.Trim())) { MessageBoxCustom.Show("公告类型不能为空!"); return; } if (string.IsNullOrEmpty(this.txtBulletinInfo.Text.Trim())) { MessageBoxCustom.Show("公告内容不能为空!"); return; } if (this.cmbSeenPeople.Text.Trim() == "指定人员") { if (this.txtSeenPerson.Tag == null) { MessageBoxCustom.Show("请选择公告可见人员!"); return; } } string StrNumber =String.Format("GG{0}", LYFZ.WinAPI.CustomPublicMethod.GenerateId());//SDateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(100, 1000); string SqlPath = ""; for (int i = 0; i < this.treevFile.Nodes.Count; i++) { string StrTreevServerPathFile = StrServerPath + StrNumber + @"\" + new System.IO.FileInfo(this.treevFile.Nodes[i].Tag.ToString().Trim()).Name; SqlPath += StrTreevServerPathFile + "|"; if (this.treevFile.Nodes[i].ForeColor == Color.Red) { htDataFile[StrTreevServerPathFile + "|" + this.treevFile.Nodes[i].Tag.ToString().Trim()] = "新增"; } } // LYFZ.Model.Model_ErpShopBulletin modelBulletin = null; // LYFZ.Model.Model_ErpShopDesignatedAnnounced modelPerson = null; List clist = new List(); if (!string.IsNullOrEmpty(this.StrGGNumber)) { currentBulletinModel = sbbll.GetModel("Bulletin_TheID", this.StrGGNumber); currentBulletinModel.Bulletin_issuerID = this.EmployeeID; currentBulletinModel.Bulletin_announcement = this.cmbBulletinType.Text; currentBulletinModel.Bulletin_Title = this.txtBulletinTitle.Text; currentBulletinModel.Bulletin_content = this.txtBulletinInfo.Text; currentBulletinModel.Bulletin_ReleaseTime = SDateTime.Now; currentBulletinModel.Bulletin_Accessory = SqlPath; currentBulletinModel.Bulletin_ReleaseTime = SDateTime.Now; clist.Add(sbbll.GetUpdateCommandInfo(currentBulletinModel)); CurrentPersonModel = sdbll.GetModel("Announced_announcement", this.StrGGNumber); if (this.txtSeenPerson.Tag != null) { if (!string.IsNullOrEmpty(this.txtSeenPerson.Tag.ToString().Trim()) && this.txtSeenPerson.Tag.ToString().Trim() != "1") { string[] Str = this.txtSeenPerson.Tag.ToString().Trim().Split('|')[0].Split(','); if (Str.Length > 0) { string StrOrderPerson = ""; for (int i = 0; i < Str.Length; i++) { StrOrderPerson += Str[i] + ","; } StrOrderPerson += LYFZ.BLL.BLL_ErpUser.Admin_20141125111443713; CurrentPersonModel.Announced_issuerID = StrOrderPerson; } } } else { CurrentPersonModel.Announced_issuerID = "1"; } CurrentPersonModel.Announced_announcement = this.StrGGNumber; CurrentPersonModel.readID = ""; clist.Add(sdbll.GetUpdateCommandInfo(CurrentPersonModel)); } else { currentBulletinModel = new LYFZ.Model.Model_ErpShopBulletin(); currentBulletinModel.Bulletin_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID(); currentBulletinModel.Bulletin_issuerID = this.EmployeeID; currentBulletinModel.Bulletin_announcement = this.cmbBulletinType.Text; currentBulletinModel.Bulletin_Title = this.txtBulletinTitle.Text; currentBulletinModel.Bulletin_content = this.txtBulletinInfo.Text; currentBulletinModel.Bulletin_ReleaseTime = SDateTime.Now; currentBulletinModel.Bulletin_Accessory = SqlPath; currentBulletinModel.Bulletin_TheID = StrNumber; clist.Add(sbbll.GetAddCommandInfo(currentBulletinModel)); CurrentPersonModel = new Model.Model_ErpShopDesignatedAnnounced(); if (this.txtSeenPerson.Tag != null) { if (!string.IsNullOrEmpty(this.txtSeenPerson.Tag.ToString().Trim()) && this.txtSeenPerson.Tag.ToString().Trim() != "1") { string[] Str = this.txtSeenPerson.Tag.ToString().Trim().Split('|')[0].Split(','); if (Str.Length > 0) { string StrOrderPerson = ""; for (int i = 0; i < Str.Length; i++) { StrOrderPerson += Str[i] + ","; } StrOrderPerson += LYFZ.BLL.BLL_ErpUser.Admin_20141125111443713; CurrentPersonModel.Announced_issuerID = StrOrderPerson; } } } else { CurrentPersonModel.Announced_issuerID = "1"; } CurrentPersonModel.Announced_announcement = currentBulletinModel.Bulletin_TheID; CurrentPersonModel.readID = ""; clist.Add(sdbll.GetAddCommandInfo(CurrentPersonModel)); } LYFZ.Software.MainBusiness.TCPFileTransfer tcpFile = new MainBusiness.TCPFileTransfer(); LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker) { backgroundWorker.ReportProgress(0, "正在连接服务器..."); foreach (DictionaryEntry de in htDataFile) { try { string ret = ""; if (de.Value.ToString().Trim() == "移除") { ret = tcpFile.DeleteFile(de.Key.ToString().Trim(), backgroundWorker); } else { string[] StrArray = de.Key.ToString().Trim().Split('|'); ret = tcpFile.UploadFileToServer(StrArray[1].Trim(), StrArray[0].Trim(), backgroundWorker); } if (ret.IndexOf("成功") == -1) { MessageBoxCustom.Show(ret, backgroundWorker: backgroundWorker); } } catch (Exception ex) { MessageBoxCustom.Show(ex.Message, backgroundWorker: backgroundWorker); } } }); if (LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist) >= 0) { this.IsSaveed = true; if (string.IsNullOrEmpty(this.StrGGNumber)) { this.StrGGNumber = StrNumber; } this.htDataFile.Clear(); for (int i = 0; i < this.treevFile.Nodes.Count; i++) { if (this.treevFile.Nodes[i].Text.Trim() != "" && this.treevFile.Nodes[i].ForeColor == Color.Red) { string StrNodeText = StrServerPath + @"\" + StrNumber + @"\" + new System.IO.FileInfo(this.treevFile.Nodes[i].Tag.ToString().Trim()).Name; this.treevFile.Nodes[i].Text = StrNodeText; this.treevFile.Nodes[i].Tag = StrNodeText; this.treevFile.Nodes[i].ForeColor = Color.Blue; } } MessageBoxCustom.Show("发布成功"); this.DialogResult = System.Windows.Forms.DialogResult.OK; } else { MessageBoxCustom.Show("发布失败"); } } /// /// 下一条 /// /// /// void btnNext_Click(object sender, EventArgs e) { if (this.dtPrompt.Rows.Count > 0) { this.ToViewNext(); } } /// /// 关闭 /// /// /// void btnClose_Click(object sender, EventArgs e) { this.Close(); } /// /// 查看下一条 /// void ToViewNext(int IndexCount = 0) { this.cmbBulletinType.Text = dtPrompt.Rows[IndexCount]["Bulletin_announcement"].ToString().Trim(); this.txtBulletinTitle.Text = dtPrompt.Rows[IndexCount]["Bulletin_Title"].ToString().Trim(); if (!string.IsNullOrEmpty(dtPrompt.Rows[IndexCount]["Announced_issuerID"].ToString().Trim()) && dtPrompt.Rows[IndexCount]["Announced_issuerID"].ToString().Trim() != "1") { this.cmbSeenPeople.Text = "指定人员"; } else { this.cmbSeenPeople.Text = "全员可见"; } this.txtBulletinInfo.Text = dtPrompt.Rows[IndexCount]["Bulletin_content"].ToString().Trim(); string[] strArray = dtPrompt.Rows[IndexCount]["Announced_issuerID"].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() + ","; } } } this.txtSeenPerson.Text = StrSeenPerson.TrimEnd(','); this.txtSeenPerson.Tag = StrSeenPersonNumber.TrimEnd(','); string[] StrArrayPath = dtPrompt.Rows[IndexCount]["Bulletin_Accessory"].ToString().Trim().Split('|'); System.Windows.Forms.TreeNode root = null; for (int i = 0; i < StrArrayPath.Length; i++) { if (!string.IsNullOrEmpty(StrArrayPath[i].Trim())) { root = new System.Windows.Forms.TreeNode(); root.Text = "\\" + StrArrayPath[i].Trim(); root.Tag = "\\" + StrArrayPath[i].Trim(); root.ForeColor = Color.Blue; this.treevFile.Nodes.Add(root); } } if (sdbll.Exists("Announced_announcement", dtPrompt.Rows[IndexCount]["Bulletin_TheID"].ToString().Trim())) { ///存在 Model.Model_ErpShopDesignatedAnnounced model = sdbll.GetModel("Announced_announcement", dtPrompt.Rows[IndexCount]["Bulletin_TheID"].ToString().Trim()); model.readID = model.readID + EmployeeID + ","; if (!sdbll.Update(model)) { MessageBoxCustom.Show("公告发生错误!"); } } this.dtPrompt.Rows.RemoveAt(IndexCount); if (dtPrompt.Rows.Count > 0) { this.Text = "发布公告:【你有:" + dtPrompt.Rows.Count + "条未读公告】"; } else { this.Text = "发布公告"; this.btnNext.Enabled = false; } //this.cmbBulletinType.Text = dgv.Rows[indexlenght].Cells["公告类型"].Value.ToString(); //this.txtBulletinTitle.Text = dgv.Rows[indexlenght].Cells["标题"].Value.ToString(); //this.txtBulletinInfo.Text = dgv.Rows[indexlenght].Cells["内容"].Value.ToString(); //if (dgv.Rows[indexlenght].Cells["文件路径"].Value.ToString() != "") //{ // Shangchuan = true; //} //else { btnUploadFile.Visible = false; } //IsNullAdd(dgv.Rows[indexlenght].Cells["公告ID"].Value.ToString()); } } }