Exemplo n.º 1
0
        /// <summary>
        /// 处理通知类消息
        /// </summary>
        /// <param name="mode">初始化模式</param>
        /// <param name="source">消息源</param>
        private void InitNodiceMessage(InitMode mode, NoticeSource source)
        {
            List <Flow_Notice> dataSource =
                (from r in m_flowNotice.GetNotice(BasicInfo.LoginID, source)
                 orderby r.标题, r.发送时间, r.发送人
                 select r).ToList();

            if (source == NoticeSource.日常事务)
            {
                treeView.Nodes.Find("通知_日常事务", true)[0].Text = string.Format("日常事务({0})", dataSource.Count);
            }
            else if (source == NoticeSource.单据处理后知会)
            {
                treeView.Nodes.Find("通知_单据处理后知会", true)[0].Text = string.Format("单据处理后知会({0})", dataSource.Count);
            }

            if (mode == InitMode.刷新数据显示)
            {
                dataGridView1.DataSource = new BindingCollection <Flow_Notice>(dataSource);

                DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();

                column.Visible    = true;
                column.Name       = "天数";
                column.HeaderText = "天数";
                column.ValueType  = typeof(int);
                column.ReadOnly   = true;
                column.Width      = 40;

                dataGridView1.Columns[1].Width = 60;
                dataGridView1.Columns[2].Width = 80;
                dataGridView1.Columns[4].Width = 80;
                dataGridView1.Columns[5].Width = 80;

                dataGridView1.Columns.Insert(0, column);

                column = new DataGridViewTextBoxColumn();

                column.Visible    = true;
                column.Name       = "接收人姓名";
                column.HeaderText = "接收人姓名";
                column.ValueType  = typeof(string);
                column.ReadOnly   = true;
                dataGridView1.Columns.Insert(5, column);

                dataGridView1.Tag = dataSource;

                dataGridView1.Columns["发送人"].Visible = false;
                dataGridView1.Columns["接收人"].Visible = false;

                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if (dataGridView1.Columns.Contains("接收方类型") &&
                        dataGridView1.Columns.Contains("接收方姓名") &&
                        dataGridView1.Columns.Contains("接收方") &&
                        dataGridView1.Columns.Contains("状态"))
                    {
                        dataGridView1.Rows[i].Cells["接收人姓名"].Value =
                            m_user.GetUser(dataGridView1.Rows[i].Cells["接收人"].Value.ToString()).姓名;

                        dataGridView1.Rows[i].Cells["状态"].Value = dataGridView1.Rows[i].Cells["状态"].Value.ToString();
                        dataGridView1.Rows[i].Cells["天数"].Value = (ServerModule.ServerTime.Time -
                                                                   (DateTime)dataGridView1.Rows[i].Cells["发送时间"].Value).Days;
                    }
                }
            }
        }
        /// <summary>
        /// 检查是否有新的知会类消息
        /// </summary>
        private void CheckNoticeMessage()
        {
            // 发消息到主窗体的标志
            bool sendMsgToMainForm = false;

            foreach (NoticeSource noticeEnum in Enum.GetValues(typeof(NoticeSource)))
            {
                IQueryable <Flow_Notice> noticeData = m_flowNotice.GetNotice(BasicInfo.LoginID, noticeEnum);

                List <Flow_Notice> dataSource = new List <Flow_Notice>();

                // 按时间顺序逆向排序
                noticeData = from r in noticeData
                             orderby r.发送时间 descending
                             select r;

                // 剔除自己发送的信息
                if (noticeData.Count() > 0)
                {
                    dataSource = (from r in noticeData where r.发送人 != BasicInfo.LoginID select r).Take(20).ToList();
                }

                string prefix = noticeEnum.ToString().Substring(0, 2);

                foreach (var item in dataSource)
                {
                    if (m_dicMsgLabel.ContainsKey(prefix + item.序号.ToString()))
                    {
                        continue;
                    }

                    UserControlMessageLabel msgLabel = new UserControlMessageLabel(StapleInfo.MainForm, GetNoticeMessage(item));
                    msgLabel.Name         = prefix + item.序号.ToString();
                    msgLabel.MessageID    = item.序号;
                    msgLabel.MessageType  = MessageTypeEnum.知会消息;
                    msgLabel.NoticeSource = noticeEnum;
                    msgLabel.Date         = item.发送时间;

                    if (!GlobalObject.GeneralFunction.IsNullOrEmpty(item.发送人))
                    {
                        if (!m_dicUserName.ContainsKey(item.发送人))
                        {
                            m_dicUserName.Add(item.发送人, m_user.GetUser(item.发送人).姓名);
                        }
                    }

                    msgLabel.UserName = m_dicUserName[item.发送人];

                    if (item.优先级 == "高")
                    {
                        msgLabel.ForeColor = Color.Red;
                    }

                    msgLabel.Dock = DockStyle.Top;
                    this.Controls.Add(msgLabel);

                    m_dicMsgLabel.Add(msgLabel.Name, msgLabel);
                    msgLabel.OnControlClick += new EventHandler(this.UserControlMessageLabel_Clicked);

                    if (!sendMsgToMainForm)
                    {
                        sendMsgToMainForm = true;

                        WndMsgData sendData = new WndMsgData();

                        sendData.MessageType    = msgLabel.MessageType;
                        sendData.NoticeSource   = msgLabel.NoticeSource;
                        sendData.MessageContent = msgLabel.MessageID.ToString();
                        m_wndMsgSender.SendMessage(StapleInfo.MainForm.Handle, WndMsgSender.NewFlowMsg, sendData);
                    }
                }

                for (int i = 0; i < this.Controls.Count; i++)
                {
                    Control msgLabel = this.Controls[i];

                    if (msgLabel.Name.Contains(prefix))
                    {
                        int findIndex = Convert.ToInt32(msgLabel.Name.Substring(2));

                        if (dataSource.FindIndex(p => p.序号 == findIndex) < 0)
                        {
                            this.Controls.RemoveAt(i--);
                            m_dicMsgLabel.Remove(msgLabel.Name);
                            msgLabel.Dispose();
                        }
                    }
                }
            }
        }