📄 formmsgmis.cs
字号:
}
this.statusBar1.Panels[1].Text="第"+this.CurrPage.ToString()+"页(共"+ this.PageCount.ToString() +"页)";
}
public void selectID(string ID)
{
if(ID=="")return;
if(ID=="Notice")this.TV_user.SelectedNode=this.TV_user.Nodes[1];
else
{
for(int i=0;i<this.TV_user.Nodes[0].Nodes.Count ;i++)
foreach(System.Windows.Forms.TreeNode node in TV_user.Nodes[0].Nodes[i].Nodes)
if(node.Tag.ToString()==ID)
{
node.Parent.Expand();
this.TV_user.SelectedNode=node;
return;
}
}
}
public int CurrPage=0;//当前浏览的页
public int PageCount=0;//页的总数
public int pageSize=20;//每一页显示的记录数
public int firstID=0;
public int LastID=2147483647;
public string CurrUser="";
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=new ClassOptionData(new ClassFormMain().ConStr).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
sql="select * from ["+DBtable+"] where ID in(select top "+ this.pageSize.ToString() +" ID from ["+DBtable+"] where "+Qualification+" ORDER BY ID DESC";
}
this.ButLast.Enabled=true;
this.ButDown.Enabled=true;
this.ButFirst.Enabled=true;
this.ButUp.Enabled=true;
this.ButDelRecord.Enabled=true;
this.menuItemEditFirst.Enabled=true;
this.menuItemEditFUp.Enabled=true;
this.menuItemEditDown.Enabled=true;
this.menuItemEditLast.Enabled=true;
this.menuItemEditDelRecord.Enabled=true;
if(this.CurrPage==this.PageCount)
{
this.ButLast.Enabled=false;
this.ButDown.Enabled=false;
this.menuItemEditDown.Enabled=false;
this.menuItemEditLast.Enabled=false;
}
if(this.CurrPage==1)
{
this.ButFirst.Enabled=false;
this.ButUp.Enabled=false;
this.menuItemEditFirst.Enabled=false;
this.menuItemEditFUp.Enabled=false;
}
System.Data.OleDb.OleDbDataReader dr=new ClassOptionData(new ClassFormMain().ConStr ).ExSQLReDr(sql);
LanMsg.ClassUserInfo sendUserInfo=this.FormMain.formMain.selfInfo ;
int i=0;
bool IsSend=false;//标识此消息是否是对方发送的
if(dr!=null)
{
while(dr.Read())
{
if(i==0)
this.firstID=Convert.ToInt32(dr["ID"]);
i++;
IsSend=false;//标识此消息否是对方发送的
sendUserInfo=null;
LanMsg.MyExtRichTextBox rich=new MyExtRichTextBox();
rich.ForeColor=Color.Blue;
sendUserInfo=this.FormMain.formMain.findUser(Convert.ToString(dr["sendID"]).Trim());
if(sendUserInfo!=null && sendUserInfo.ID==userID)
{
rich.ForeColor=Color.Red;
IsSend=true;//此消息为对方发送的
}
rich.AppendText(sendUserInfo.UserName + "("+sendUserInfo.ID +")" + Convert.ToString(dr["msgDateTime"]));
this.RTBRecord.AppendRtf(rich.Rtf);
rich.Clear();
rich.Dispose();
this.RTBRecord.AppendTextAsRtf(" ");
if(IsNotNotice)
textMsgToRich(Convert.ToString(dr["msgContent"]),Convert.ToString(dr["imageInfo"]),IsSend);
else
this.RTBRecord.AppendText(Convert.ToString(dr["msgContent"])+"\n");
LastID=Convert.ToInt32(dr["ID"]);
}
dr.Close();
}
this.statusBar1.Panels[1].Text="第"+this.CurrPage.ToString()+"页(共"+ this.PageCount.ToString() +"页)";
}
private void textMsgToRich(string msgContent,string ImageInfo,bool IsSend)//添加文本消息与图片到richBox
{
LanMsg.ClassTextMsg textMsg=new ClassTextMsg();
textMsg.MsgContent=msgContent;
textMsg.ImageInfo=ImageInfo;
if(textMsg.ImageInfo!="")//如果消息中有图片,则添加图片
{
string[] imagePos=textMsg.ImageInfo.Split('|');
int addPos=0;//
int currPos=0;//当前正要添加的文本位置
int textPos=0;
for(int i=0;i<imagePos.Length-1;i++)
{
string[] imageContent=imagePos[i].Split(',');//获得图片所在的位置、图片名称、图片宽、高
currPos=Convert.ToInt32(imageContent[0]);
this.RTBRecord.AppendText(textMsg.MsgContent.Substring(textPos,currPos-addPos));
this.RTBRecord.SelectionStart=this.RTBRecord.TextLength;
textPos += currPos-addPos ;
addPos += currPos-addPos;
System.Drawing.Image image=System.Drawing.Image.FromStream(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("LanMsg.Resources.ErrorImage.GIF")) ;
// LanMsg.MyPicture pic=new MyPicture();
// pic.BackColor=this.RTBRecord.BackColor;
// pic.SizeMode=System.Windows.Forms.PictureBoxSizeMode.AutoSize;
if(Convert.ToUInt32(imageContent[1])<96)
// pic.Image=System.Drawing.Image.FromStream(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("LanMsg.Resources."+ imageContent[1] +".gif")) ;
image=System.Drawing.Image.FromStream(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("LanMsg.Resources."+ imageContent[1] +".gif")) ;
else
{
if(IsSend && new System.IO.FileInfo(Application.StartupPath +"\\ArrivalImage\\"+ imageContent[1] +".gif").Exists)
image=System.Drawing.Image.FromFile(Application.StartupPath +"\\ArrivalImage\\"+ imageContent[1] +".gif");
else if(!IsSend && new System.IO.FileInfo(Application.StartupPath +"\\sendImage\\"+ imageContent[1] +".gif").Exists)
image=System.Drawing.Image.FromFile(Application.StartupPath +"\\sendImage\\"+ imageContent[1] +".gif");
// pic.Tag=imageContent[1];
// pic.Image=System.Drawing.Image.FromStream(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("LanMsg.Resources.ErrorImage.GIF")) ;
}
this.RTBRecord.InsertImage(image);
// this.RTBRecord.InsertMyControl(pic);
addPos ++;
}
this.RTBRecord.AppendText(textMsg.MsgContent.Substring(textPos,textMsg.MsgContent.Length-textPos) +"\n");
}
else//如果消息中没有图片,则直接添加消息文本
{
this.RTBRecord.AppendText(textMsg.MsgContent +"\n");
}
}
private void delRecord(bool IsNotNotice)
{
if(MessageBox.Show("确定要删除当前的所有对话记录吗?","提示",System.Windows.Forms.MessageBoxButtons.YesNoCancel,System.Windows.Forms.MessageBoxIcon.Question)!=System.Windows.Forms.DialogResult.Yes)return;
string DBtable="Notice";
if(IsNotNotice)
{
DBtable="MsgRecord";
}
string sql="delete * from ["+DBtable+"] where (sendID='"+ this.CurrUser +"' or ReceiveID='"+ this.CurrUser +"')";
new ClassOptionData(new ClassFormMain().ConStr).ExSQL(sql);
this.RTBRecord.Clear();
this.ButDelRecord.Enabled=false;
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
bool t=true;
if(this.TV_user.Nodes[1].IsSelected )t=false;
switch(e.Button.ToolTipText)
{
case "第一页":
DBRecordToRichTextBox(this.CurrUser,this.FormMain.formMain.selfInfo.ID,t,false,true,false);
break;
case "上一页":
DBRecordToRichTextBox(this.CurrUser,this.FormMain.formMain.selfInfo.ID,t,false,false,false);
break;
case "下一页":
DBRecordToRichTextBox(this.CurrUser,this.FormMain.formMain.selfInfo.ID,t,true,false,false);
break;
case "最后一页":
DBRecordToRichTextBox(this.CurrUser,this.FormMain.formMain.selfInfo.ID,t,false,false,true);
break;
case "关闭":
this.Dispose();
break;
case "删除记录":
delRecord(t);
break;
}
}
private void menuItemCopy_Click(object sender, System.EventArgs e)
{
this.RTBRecord.Copy();
}
private void menuItemSelectAll_Click(object sender, System.EventArgs e)
{
this.RTBRecord.SelectAll();
}
private void menuItemEditCopy_Click(object sender, System.EventArgs e)
{
this.RTBRecord.Copy();
}
private void menuItemEditSelectAll_Click(object sender, System.EventArgs e)
{
this.RTBRecord.Focus();
this.RTBRecord.SelectAll();
}
private void menuItemEditFirst_Click(object sender, System.EventArgs e)
{
bool t=true;
if(this.TV_user.Nodes[1].IsSelected )t=false;
DBRecordToRichTextBox(this.CurrUser,this.FormMain.formMain.selfInfo.ID,t,false,true,false);
}
private void menuItemEditFUp_Click(object sender, System.EventArgs e)
{
bool t=true;
if(this.TV_user.Nodes[1].IsSelected )t=false;
DBRecordToRichTextBox(this.CurrUser,this.FormMain.formMain.selfInfo.ID,t,false,false,false);
}
private void menuItemEditDown_Click(object sender, System.EventArgs e)
{
bool t=true;
if(this.TV_user.Nodes[1].IsSelected )t=false;
DBRecordToRichTextBox(this.CurrUser,this.FormMain.formMain.selfInfo.ID,t,true,false,false);
}
private void menuItemEditLast_Click(object sender, System.EventArgs e)
{
bool t=true;
if(this.TV_user.Nodes[1].IsSelected )t=false;
DBRecordToRichTextBox(this.CurrUser,this.FormMain.formMain.selfInfo.ID,t,false,false,true);
}
private void menuItemEditDelRecord_Click(object sender, System.EventArgs e)
{
bool t=true;
if(this.TV_user.Nodes[1].IsSelected )t=false;
delRecord(t);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -