-
UserHelper..cs
类代码
using
System;
using
c;
using
namespace
MyQQ
{
//
记录登录的用户
Id
class
UserHelper
{
public
static
int
loginId;
//
登录的用户
Id
}
}
using
System;
using
c;
using
entModel;
using
using
g;
using
using
using
ent;
namespace
MyQQ
{
///
///
聊天窗体
///
public
partial
class
ChatForm
:
Form
{
public
int
friendId;
//
当前聊天的好友号码
public
string
nickName;
//
当前聊天的好友昵称
public
int
faceId;
//
当前聊天的好友头像
Id
public
ChatForm()
{
InitializeComponent();
}
//
窗体加载时的动作
private
void
ChatForm_Load(
object
sender,
EventArgs
e)
{
//
设置窗体标题
this
.Text =
strin
g
.Format(
与
{0}
聊天中
,nickNa
me);
//
设置窗体顶部显示的好友信息
= [faceId];
=
string
.Format(
<
/p>
,nickName,friendId);
//
读取所有的未读消息,显示在窗体中
ShowMessage();
}
//
关闭窗体
private
void
btnClose_Click(
object
sender,
EventArgs
e)
{
this
.Close();
}
//
发送消息
private
void
btnSend_Click(
object
sender,
EventArgs
e)
{
if
(() ==
)
//
不能发送空消息
{
MessageBox
.Show(
不能发送空消息!
,
提示
,
MessageBoxButtons
.OK,
MessageBoxIcon
.Information);
return
;
}
else
if
(().Length > 50)
{
MessageBox
.Show(
<
/p>
消息内容过长,
请分为几条发送!
,
提示
,
MessageBoxButtons
.OK,
MessageBoxIcon
.Information);
return
;
}
else
//
发送消息,写入数据库
{
//
MessageTypeId:1-
表示聊天消息,为简化操作没有读取数据表
,到
S2
可以用常量或者
枚举实现
p>
//
MessageState:0-
表示消息状态是未读
int
result = -1;
//
表示操作数据库的结果
string
sql =
string
.Format(
MessageState) VALUES
({0},{1},'{2}',{3},{4})
,
UserHelper
.loginId,
friendId, (), 1, 0);
try
{
//
执行命令
SqlCommand
command =
new
SqlCommand
(sql,
DBHelper
.connection);
DBHelper
.();
result = eNonQuery();
}
catch
(
Exception
ex)
{
Console
.WriteLine(e);
}
finally
{
DBHelper
.();
}
if
(result != 1)
{
Messag
eBox
.Show(
服务器出现意外
错误!
,
抱歉
,
MessageBoxButtons
.OK,
MessageBoxIcon
.Error);
}
=
;
//
输入消息清空
this
.Close();
}
}
///
///
读取所有的未读消息,显示在窗体中
///
private
void
ShowMessage()
{
string
messageIdsString =
;
//
消息的
Id
组成的字符串
string
message;
//
消息内容
string
messageTime;
//
消息发出的时间
// <
/p>
读取消息的
SQL
语句
< br>
string
sql =
string
.Format(
ToUserId={1} AND
MessageTypeId=1 AND MessageState=0
,
friendId,
Use
rHelper
.loginId);
try
{
SqlCommand
command =
new
SqlCommand
(sql,
DBHelper
.connection);
DBHelper
.();
SqlDataReader
reader =
eReader();
//
循环将消息添加到窗体上
while
(())
{
messageIdsString
+=
Convert
.ToString(reader[<
/p>
]) +
;
message =
Convert
.ToString(reader[
p>
]);
messageTime
=
Convert
.ToDateTime(reader[
]).To
String();
//
转
换为日期类型,告诉学员
+=
string
.Format(
{2}
,nickName,messageTime,message);
}
();
}
catch
(
Exception
ex)
{
Console
.WriteLine(e);
}
finally
{
DBHelper
.();
}
//
把显示出的消息置为已读
if
( > 1)
{
( - 1);
SetMessageRead(messageIdsString,
'_'
);
}
}
///
///
把显示出的消息置为已读
///
private
void
SetMessageRead(
string
messageIdsString,
char
separator)
{
string
[] messageIds =
(separator);
//
分割出每个消息
Id
string
sql =
;
//
更
新状态的
SQL
语句
的固定部分
string
updateSql;
//
执行的
SQL
< br>语句
try
{
SqlCommand
command =
new
SqlCommand
();
//
创建
Command
对象
tion =
DBHelper
.connection;
//
指定数据库连接
DBHelper
.();
//
打开数据库连接
foreach
(
string
id
in
messageIds)
{
if
(id !=
)
{
updateSql =
sql + id;
//
补充
完整的
SQL
语句
dText =
updateSql;
//
指定要执行的
SQL
语句
int
result = eNonQuery();
}
}
}
catch
(
Exception
ex)
{
Console
.WriteLine(e);
}
finally
{
DBHelper
.();
}
}
代码
using
System;
using
c;
using
entModel;
using
using
g;
using
using
using
ent;
namespace
MyQQ
{
///
///
聊天窗体
///
public
partial
class
ChatForm
:
Form
{
public
int
friendId;
//
当前聊天的好友号码
public
string
nickName;
//
当前聊天的好友昵称
public
int
faceId;
//
当前聊天的好友头像
Id
public
ChatForm()
//
执行命令
{
InitializeComponent();
}
//
窗体加载时的动作
private
void
ChatForm_Load(
object
sender,
EventArgs
e)
{
//
设置窗体标题
this
.Text =
strin
g
.Format(
与
{0}
聊天中
,nickNa
me);
//
设置窗体顶部显示的好友信息
= [faceId];
=
string
.Format(
<
/p>
,nickName,friendId);
//
读取所有的未读消息,显示在窗体中
ShowMessage();
}
//
关闭窗体
private
void
btnClose_Click(
object
sender,
EventArgs
e)
{
this
.Close();
}
//
发送消息
private
void
btnSend_Click(
object
sender,
EventArgs
e)
{
if
(() ==
)
//
不能发送空消息
{
MessageBox
.Show(
不能发送空消息!
,
提示
,
MessageBoxButtons
.OK,
MessageBoxIcon
.Information);
return
;
}
else
if
(().Length > 50)
{
MessageBox
.Show(
<
/p>
消息内容过长,
请分为几条发送!
,
提示
,
MessageBoxButtons
.OK,
MessageBoxIcon
.Information);
return
;
}
else
//
发送消息,写入数据库
{
//
MessageTypeId:1-
表示聊天消息,为简化操作没有读取数据表
,到
S2
可以用常量或者
枚举实现
p>
//
MessageState:0-
表示消息状态是未读
int
result = -1;
//
表示操作数据库的结果
string
sql =
string
.Format(
MessageState) VALUES
({0},{1},'{2}',{3},{4})
,
UserHelper
.loginId,
friendId, (), 1, 0);
try
{
//
执行命令
SqlCommand
command =
new
SqlCommand
(sql,
DBHelper
.connection);
DBHelper
.();
result = eNonQuery();
}
catch
(
Exception
ex)
{
Console
.WriteLine(e);
}
finally
{
DBHelper
.();
}
if
(result != 1)
{
Messag
eBox
.Show(
服务器出现意外
错误!
,
抱歉
,
MessageBoxButtons
.OK,
MessageBoxIcon
.Error);
}
=
;
//
输入消息清空
this
.Close();
}
}
///
///
读取所有的未读消息,显示在窗体中
///
private
void
ShowMessage()
{
string
messageIdsString =
;
//
消息的
Id
组成的字符串
string
message;
//
消息内容
string
messageTime;
//
消息发出的时间
// <
/p>
读取消息的
SQL
语句
< br>
string
sql =
string
.Format(
ToUserId={1} AND
MessageTypeId=1 AND MessageState=0
,
friendId,
Use
rHelper
.loginId);
try
{
SqlCommand
command =
new
SqlCommand
(sql,
DBHelper
.connection);
DBHelper
.();
SqlDataReader
reader =
eReader();
//
循环将消息添加到窗体上
while
(())
{
messageIdsString
+=
Convert
.ToString(reader[<
/p>
]) +
;
message =
Convert
.ToString(reader[
p>
]);
messageTime
=
Convert
.ToDateTime(reader[
]).To
String();
//
转
换为日期类型,告诉学员
+=
string
.Format(
{2}
,nickName,messageTime,message);
}
();
}
catch
(
Exception
ex)
{
Console
.WriteLine(e);
}
finally
{
DBHelper
.();
}
//
把显示出的消息置为已读
if
( > 1)
{
( - 1);
SetMessageRead(messageIdsString,
'_'
);
}
}
///
///
把显示出的消息置为已读
///
private
void
SetMessageRead(
string
messageIdsString,
char
separator)
{
string
[] messageIds =
(separator);
//
分割出每个消息
Id
string
sql =
;
//
更
新状态的
SQL
语句
的固定部分
string
updateSql;
//
执行的
SQL
< br>语句
try
{
SqlCommand
command =
new
SqlCommand
();
//
创建
Command
对象
tion =
DBHelper
.connection;
//
指定数据库连接
DBHelper
.();
//
打开数据库连接
foreach
(
string
id
in
messageIds)
{
if
(id !=
)
{
updateSql =
sql + id;
//
补充
完整的
SQL
语句
dText =
updateSql;
//
指定要执行的
SQL
语句
int
result = eNonQuery();
//
执行命令
}
}
}
catch
(
Exception
ex)
{
Console
.WriteLine(e);
}
finally
{
DBHelper
.();
}
}
private
void
lblMessages_Click(
object
sender,
EventArgs
e)
{
}
}
}
类代码
using
System;
using
c;
using
using
ent;
namespace
MyQQ
{
//
数据库帮助类,维护数据库连接字符串和数据库连接对象
class
DBHelper
{
private
static
string
connString =
security=sspi
;
public
static
SqlConnection
connection =
new
SqlConnection
(connString);
}
}
using
System;
using
c;
using
entModel;
using
using
g;
using
using
namespace
MyQQ
{
///
///
头像选择窗体
///
public
partial
class
FacesForm
:
Form
{
public
PersonalInfoForm
personalInfoForm;
public
FacesForm()
{
InitializeComponent();
}
//
个人信息窗体
代码
private
void
FacesForm_Load(
object
sender,
EventArgs
e)
{
for
(
int
i = 0; i < i++)
{
(ng());
[i].ImageIndex
= i;
}
}
//
确定选择头像
private
void
btnOK_Click(
object
sender,
EventArgs
e)
{
if
( == 0)
{
MessageBox
.Show(
<
/p>
请选择一个头像!
,
提示
,
MessageBoxButtons
.OK,
MessageBoxIcon
.Information);
}
else
{
int
faceId =
edItems[0].ImageIndex;
//
获得当前选中的头像的索
引
ce(faceId);
//
设置个人信息窗体中显示的头像
this
.Close();
}
}
//
双击时选择头像
private
void
lvIcons_MouseDoubleClic
k(
object
sender,
MouseEventArgs
e)
{
int
faceId =
edItems[0].ImageIndex;
//
获得当前选中的头像的索引
ce(faceId);
//
设置个人信息窗体中显示的头像
this
.Close();
}
//
关闭窗体
private
void
btnCancel_Click(
object
sender,
EventArgs
e)
{
this
.Close();
}
}
}
using
System;
using
c;
using
entModel;
using
using
g;
using
using
using
ent;
namespace
MyQQ
{
///
///
登录窗体
///
public
partial
class
LoginForm
:
Form
{
public
LoginForm()
{
InitializeComponent();
}
//
取消按钮的事件处理
private
void
btnCancel_Click(
object
sender,
EventArgs
e)
{
Application
.Exit();
}
//
打开申请号码界面
private
void
llbl_LinkClicked(
object
sender,
LinkLabelLinkClickedEventArgs
p>
e)
{
RegisterForm
registerForm =
new
RegisterForm
();
();
}
//
登录按钮事件处理
private
void
btnLogin_Click(
object
sender,
EventArgs
e)
{
bool
error =
false
;
//
标志在执行数据库操作的过程中是否出错
//
如果输入验证成功,就验证身份,并转到相应的窗体
if
(ValidateInput())
{
int
num = 0;
//
数据库操作结果
try
{
//
查询用的
sql
语句
-
-
-
-
-
-
-
-
-
上一篇:(全)高考英语真题详解-阅读七选五-解题技巧与实例
下一篇:24产品撤回和召回程序