📄 formrecordmsgmisg.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using IMLibrary ;
namespace LanMsg
{
public partial class FormRecordMsgMisg : Form
{
public FormRecordMsgMisg()
{
InitializeComponent();
this.treeViewGroup.AfterSelect +=new TreeViewEventHandler(treeViewGroup_AfterSelect);
}
private void FormRecordMsgMisg_Load(object sender, EventArgs e)
{
this.treeViewGroup.ImageList = FormAccess.formMain.imageList1;
foreach (TreeNode node in FormAccess.formMain.TreeUsers.Nodes)
{
this.treeViewGroup.Nodes.Add(node.Clone() as TreeNode);
}
foreach (TreeNode node in this.treeViewGroup.Nodes)
setNodeImage(node);//遍历treeview
TreeNode Node = new TreeNode("通知消息", 16, 16);
this.treeViewGroup.Nodes.Add(Node);
}
#region 遍历treeview
private void setNodeImage(TreeNode Node)
{
Application.DoEvents();
if (Node.Tag.ToString() == "0")
{
Node.ImageIndex = 14;
Node.SelectedImageIndex = 14;
}
else
{
Node.ImageIndex = 1;
Node.SelectedImageIndex = 1;
}
Node.Text = Node.ToolTipText;
foreach (TreeNode node in Node.Nodes)
{
if (node.Tag.ToString() == "0")
{
node.ImageIndex = 14;
node.SelectedImageIndex = 14;
}
else
{
node.ImageIndex = 1;
node.SelectedImageIndex =1;
}
node.Text = node.ToolTipText;
if (node.Nodes.Count != 0)
{
setNodeImage(node);
}
Application.DoEvents();
}
}
#endregion
private void MenuItemClose_Click(object sender, EventArgs e)
{
this.Close();
}
#region 树图节点选中后事件
/// <summary>
/// 树图节点选中后事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void treeViewGroup_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
this.RTBRecord.Clear();
this.ButLast.Enabled = false;
this.ButDown.Enabled = false;
this.ButFirst.Enabled = false;
this.ButUp.Enabled = false;
this.ButDelRecord.Enabled = false;
this.menuItemEditFirst.Enabled = false;
this.menuItemEditFUp.Enabled = false;
this.menuItemEditDown.Enabled = false;
this.menuItemEditLast.Enabled = false;
this.menuItemEditDelRecord.Enabled = false;
this.PageCount = 0;
this.CurrPage = 0;
this.firstID = 0;
this.LastID = 2147483647;
this.StatusLabelUser.Text = "正在查看对话记录";
if (e.Node.Tag == null )
{
CurrUser = FormAccess.selfInfo.UserID;
this.StatusLabelUser.Text = "查看所有通知消息记录";
this.PageCount = GetPageCount(FormAccess.selfInfo.UserID,FormAccess.selfInfo.UserID, false);
if (this.PageCount > 0)
DBRecordToRichTextBox(CurrUser, CurrUser, false, false, true, false);
}
else if (e.Node.Tag.ToString()=="1")
{
exUser user = FormAccess.findUser(e.Node.Name );
CurrUser = user.UserID ;
if (user != null)
this.StatusLabelUser.Text = "查看与" + user.userName + "(" +user.UserID + ") 的对话记录"; //+ user.depId.ToString() + " "
else
this.StatusLabelUser.Text = "查看与(" + e.Node.ToolTipText + ")的对话记录";
this.PageCount = GetPageCount(user.UserID , FormAccess.selfInfo.UserID, true);
if (this.PageCount > 0)
DBRecordToRichTextBox(CurrUser, FormAccess.selfInfo.UserID, true, false, true, false);
}
this.StatusLabelPage.Text = "第" + this.CurrPage.ToString() + "页(共" + this.PageCount.ToString() + "页)";
}
#endregion
#region 选择 用户ID
/// <summary>
/// 选择 用户ID
/// </summary>
/// <param name="ID"></param>
public void selectID(string ID)
{
if (ID == "") return;
if (ID == "Notice") this.treeViewGroup.SelectedNode = this.treeViewGroup.Nodes[1];
else
{
for (int i = 0; i < this.treeViewGroup.Nodes[0].Nodes.Count; i++)
foreach (System.Windows.Forms.TreeNode node in treeViewGroup.Nodes[0].Nodes[i].Nodes)
if (node.Tag.ToString() == ID)
{
node.Parent.Expand();
this.treeViewGroup.SelectedNode = node;
return;
}
}
}
#endregion
private int CurrPage = 0;//当前浏览的页
private int PageCount = 0;//页的总数
private int pageSize = 20;//每一页显示的记录数
private int firstID = 0;
private int LastID = 2147483647;
private string CurrUser = "";
/// <summary>
/// 获得对话记录消息总行数
/// </summary>
/// <param name="userID">发送者ID</param>
/// <param name="MyID">自己的ID</param>
/// <param name="IsNotNotice">是否群发消息</param>
/// <returns></returns>
private int GetPageCount(string userID, string MyID, bool IsNotNotice)//获得页数
{
string DBtable = "Notice";
string sql = "select Null from [" + DBtable + "] where (sendID='" + MyID + "' or ReceiveID='" + MyID + "')";
if (IsNotNotice)
{
DBtable = "MsgRecord";
sql = "select Null from [" + DBtable + "] where (sendID='" + userID + "' and ReceiveID='" + MyID + "') or (sendID='" + MyID + "' and ReceiveID='" + userID + "')";
}
int rows = IMLibrary.OleDb.DataAccess.ExSQLR(sql);
int count = Convert.ToInt32(rows / this.pageSize);
if ((rows % this.pageSize) != 0)
count += 1;
return count;
}
private void DBRecordToRichTextBox(string userID, string MyID, bool IsNotNotice, bool IsDown, bool IsFirst, bool IsLast)
{
this.RTBRecord.Clear();
string DBtable = "Notice";
string Qualification = " (sendID='" + MyID + "' or ReceiveID='" + MyID + "')";
string sql = "";
if (IsNotNotice)
{
DBtable = "MsgRecord";
Qualification = " ((sendID='" + userID + "' and ReceiveID='" + MyID + "') or (sendID='" + MyID + "' and ReceiveID='" + userID + "'))";
}
if (IsDown)
{
this.CurrPage++;
sql = "select top " + this.pageSize.ToString() + " * from [" + DBtable + "] where " + Qualification + " and ID<" + this.LastID.ToString() + " ORDER BY ID DESC";
}
else
{
this.CurrPage--;
sql = "select * from [" + DBtable + "] where ID in(select top " + this.pageSize.ToString() + " ID from [" + DBtable + "] where " + Qualification + " and ID>" + this.firstID.ToString() + ") ORDER BY ID DESC";//+" ORDER BY ID DESC";
}
if (IsFirst)
{
this.CurrPage = 1;
sql = "select top " + this.pageSize.ToString() + " * from [" + DBtable + "] where " + Qualification + " ORDER BY ID DESC";
}
if (IsLast)
{
this.CurrPage = this.PageCount;
int mod = this.PageCount % this.pageSize;
if (mod != 0)
sql = "select * from [" + DBtable + "] where ID in(select top " + mod + " ID from [" + DBtable + "] where " + Qualification + ") ORDER BY ID DESC";
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -