using System; using System.Data ; using System.Data.SqlClient; namespace OI.cs { public class Message { protected OI.DatabaseOper .DatabaseConnect Dbc= new OI.DatabaseOper.DatabaseConnect (); protected System.DateTime sendtime,receivetime; protected int senduserid,receiveuserid; protected string title,messagecontent,modename,documentpath; protected int id; protected VisitState readstate; protected Transact istransact ; protected MessageType messagetype=0; public enum Transact { NO=0, Yes=1 } public enum VisitState { NO=0, Yes=1 } public enum MessageType { MessageAndDesk=0, MessageOnly=1 } public Message() { } public MessageType messageType { set { messagetype=value; } } public int ID { get { return id; } set { id=value; } } public System.DateTime SendTime { get { return sendtime; } set { sendtime =value; } } public System.DateTime ReceiveTime { get { return receivetime; } set { receivetime =value; } } public int SendUserID { get { return senduserid; } set { senduserid=value; } } public Transact IsTransact { set { istransact=value; } } public VisitState IsReaded { set { readstate=value; } } public int ReceiveUserID { get { return receiveuserid; } set { receiveuserid=value; } } public string Title { get { return title; } set { title=value; } } public string MessageContent { get { return messagecontent; } set { messagecontent=value; } } public string ModeName { get { return modename; } set { modename=value; } } public string DocumentPath { get { return documentpath; } set { documentpath=value; } } public void ADD() { checkData(); string Sql="select count(*) from message where receiveuserid=" +receiveuserid.ToString ()+ " and id=" +id.ToString ()+ " and modename ='" +modename+ "'" ; int o= int .Parse (Dbc.GetObjectBySql (Sql).ToString ()); if (o>0) { Dbc.ExecuteSQL ("delete message where receiveuserid=" +receiveuserid.ToString ()+ " and id=" +id.ToString ()+ " and modename ='" +modename+ "'" ); } string values=id.ToString ()+"," ; values +="'" +sendtime.ToString() + "'," ; values +=senduserid.ToString () +"," ; values +=receiveuserid.ToString ()+"," ; values +="'" +title+ "'," ; values +="'" +messagecontent+ "'," ; values +="'" +modename+ "'," ; values +="'" +documentpath+ "'" ; Sql=" insert message (id,sendtime,senduserid,receiveuserid,title,MessageContent,modename,Documentpath) values (" +values+ ")" ; Dbc.ExecuteSQL (Sql); } public void AddMessageOnly() { int intmessagetype=( int )messagetype; string values="" ; values +="'" +sendtime.ToString() + "'," ; values +=senduserid.ToString () +"," ; values +=receiveuserid.ToString ()+"," ; values +="'" +title+ "'," ; values +="'" +messagecontent+ "'," ; values += intmessagetype .ToString (); values +=",1" ; string Sql=" insert message (sendtime,senduserid,receiveuserid,title,MessageContent,MessageType,istransact) values (" +values+ ")" ; Dbc.ExecuteSQL (Sql); } public void Modify() { string update; update = " set sendtime='" +sendtime.ToString ()+ "'" ; update +=", title='" +title+ "'" ; update +=", MessageContent='" +messagecontent+ "'" ; update +=" ,receivetime='" +receivetime.ToString ()+ "'" ; update +=",modename='" +modename.ToString ()+ "'" ; update +=",Documentpath='" +documentpath+ "'" ; update +=",isTransact=" +istransact.ToString (); update +=",readstate" +readstate.ToString (); update +=" where id=" +id.ToString (); update +=" and documentpath='" +documentpath+ "'" ; string Sql="update message " +update ; } public DataTable GetAllNoReadingMessage( int userid) { string Sql="select m.*,a.username,d.departmentname from message m,Accounts_Users a ,departments d " ; Sql +=" where m.SendUserId=a.userid and m.Readstate=0 and d.departmentid=a.departmentid and m.ReceiveUserId=" +userid.ToString () ; DataTable dt= Dbc.getBinding (Sql,"t" ).Tables[0] ; Sql="update message set readstate=1 where readstate=0 and ReceiveUserId=" +userid ; Dbc.ExecuteSQL (Sql); return dt; } public DataRow GetRow( int id,string documentpath) { try { string Sql=" select * from message where id" +id.ToString () + " and documentpath='" +documentpath.ToString ()+ "'" ; DataTable dt=Dbc.getBinding (Sql,"t" ).Tables[0] ; if (dt.Rows .Count !=1) { throw new ApplicationException ( "没有找到数据或找到多条数据" ); } return dt.Rows[0] ; } catch (Exception er) { throw new ApplicationException (er.Message ); } } public void ExcuteSql(string Sql) { Dbc.ExecuteSQL (Sql); } public void checkData() { } public DataTable deskGetAllNoTransact( int userid) { string Sql=" select m.*,a.username,d.departmentname from message m,Accounts_Users a ,departments d where m.SendUserId=a.userid and m.istransact=0 and d.departmentid=a.departmentid and MessageType=0 and m.ReceiveUserId=" +userid.ToString () ; return Dbc.getBinding (Sql, "t" ).Tables[0] ; } public void finishOprate( int finishUserID, int id,string modename) { string Sql=" update message set istransact=1 ,ReceiveTime='" +System.DateTime.Now .ToString () + "'" ; Sql +=" where id=" +id.ToString ()+ " and modename='" +modename+ "' and ReceiveUserId=" +finishUserID.ToString (); Dbc.ExecuteSQL (Sql); } public void deleteMessage( int sendUserID, int id,string modename) { string Sql =" delete from message where senduserid=" +sendUserID.ToString ()+ " and id=" +id.ToString ()+ " and modename='" +modename+ "'" ; try { Dbc.ExecuteSQL (Sql); } catch (Exception er) { throw new ApplicationException (er.Message + "" +Sql); } } public void deleteMessage( int lsh) { string Sql =" delete from message where lsh=" +lsh.ToString (); try { Dbc.ExecuteSQL (Sql); } catch (Exception er) { throw new ApplicationException (er.Message + "" +Sql); } } public DataSet GetALLMessageByUserID( int userid) { string Sql = " select lsh,istransact,sendTime,ReceiveTime,Senduserid,a.username,d.departmentname,title,MessageContent, " ; Sql +=" case readstate when 1 then '己读' else '末读' end as readstate , " ; Sql += " case istransact when 1 then '己处理' else '末处理' end as transact " ; Sql +=" from message m, departments d,accounts_users a where m.senduserid=a.userid and a.departmentid=d.departmentid " ; Sql +=" and m.ReceiveUserId=" + userid.ToString (); try { return Dbc.getBinding (Sql, "t" ); } catch (Exception er) { throw new ApplicationException (er.Message + "" +Sql); } } } } using System;
using System.Data ;
using System.Data.SqlClient;
namespace OI.cs
{
///
/// Message :待办事宜,消息小精灵管理。
///
///
public class Message
{
protected OI.DatabaseOper .DatabaseConnect Dbc=new OI.DatabaseOper.DatabaseConnect ();
protected System.DateTime sendtime,receivetime;
protected int senduserid,receiveuserid;
protected string title,messagecontent,modename,documentpath;
protected int id;
//protected int transact;
protected VisitState readstate;
protected Transact istransact ;
protected MessageType messagetype=0;
///
/// 处理类型
///
public enum Transact
{
NO=0,//no
Yes=1
}
///
/// 访问状态
///
public enum VisitState
{
NO=0,
Yes=1
}
///
/// 消息类型
///
public enum MessageType
{
MessageAndDesk=0,
MessageOnly=1
}
public Message()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public MessageType messageType
{
set
{
messagetype=value;
}
}
///
/// 主键1:你所操作模块的主键编号。
///
public int ID
{
get
{
return id;
}
set
{
id=value;
}
}
///
/// 发送日期
///
public System.DateTime SendTime
{
get
{
return sendtime;
}
set
{
sendtime =value;
}
}
///
/// 收文用户处理日期
///
public System.DateTime ReceiveTime
{
get
{
return receivetime;
}
set
{
receivetime =value;
}
}
///
/// 发文用户ID
///
public int SendUserID
{
get
{
return senduserid;
}
set
{
senduserid=value;
}
}
public Transact IsTransact
{
set
{
istransact=value;
}
}
///
/// 是否己读
///
public VisitState IsReaded
{
set
{
readstate=value;
}
}
///
/// 收文用户ID
///
public int ReceiveUserID
{
get
{
return receiveuserid;
}
set
{
receiveuserid=value;
}
}
///
/// 文档标题
///
public string Title
{
get
{
return title;
}
set
{
title=value;
}
}
///
/// 消息内容
///
public string MessageContent
{
get
{
return messagecontent;
}
set
{
messagecontent=value;
}
}
///
/// 主键:待办事宜模块名称
///
public string ModeName
{
get
{
return modename;
}
set
{
modename=value;
}
}
///
/// 文档访问路径
///
public string DocumentPath
{
get
{
return documentpath;
}
set
{
documentpath=value;
}
}
///
/// 新增
///
///
public void ADD()
{
checkData();
string Sql="select count(*) from message where receiveuserid="+receiveuserid.ToString ()+" and id="+id.ToString ()+" and modename ='" +modename+"'";
int o= int.Parse (Dbc.GetObjectBySql (Sql).ToString ());
if (o>0)
{
Dbc.ExecuteSQL ("delete message where receiveuserid="+receiveuserid.ToString ()+" and id="+id.ToString ()+" and modename ='" +modename+"'");
}
string values=id.ToString ()+",";
values +="'"+sendtime.ToString() +"'," ;
values +=senduserid.ToString () +",";
values +=receiveuserid.ToString ()+",";
values +="'"+title+"',";
values +="'"+messagecontent+"',";
values +="'"+modename+"',";
values +="'"+documentpath+"'";
Sql=" insert message (id,sendtime,senduserid,receiveuserid,title,MessageContent,modename,Documentpath) values ("+values+")";
Dbc.ExecuteSQL (Sql);
}
///
/// 仅仅插入消息
///
public void AddMessageOnly()
{
int intmessagetype=(int)messagetype;
string values="";
values +="'"+sendtime.ToString() +"'," ;
values +=senduserid.ToString () +",";
values +=receiveuserid.ToString ()+",";
values +="'"+title+"',";
values +="'"+messagecontent+"',";
values += intmessagetype .ToString ();
values +=",1";
string Sql=" insert message (sendtime,senduserid,receiveuserid,title,MessageContent,MessageType,istransact) values ("+values+")";
Dbc.ExecuteSQL (Sql);
}
///
/// 修改
///
///
public void Modify()
{
string update;
update = " set sendtime='"+sendtime.ToString ()+"'";
update +=", title='"+title+"'";
update +=", MessageContent='"+messagecontent+"'";
update +=" ,receivetime='"+receivetime.ToString ()+"'";
update +=",modename='"+modename.ToString ()+"'";
update +=",Documentpath='"+documentpath+"'";
update +=",isTransact="+istransact.ToString ();
update +=",readstate"+readstate.ToString ();
update +=" where id="+id.ToString ();
update +=" and documentpath='"+documentpath+"'";
string Sql="update message "+update ;
}
///
/// 返回用户所有没读过的消息。包括发送者的姓名,部门。
///
///
///
public DataTable GetAllNoReadingMessage(int userid)
{
string Sql="select m.*,a.username,d.departmentname from message m,Accounts_Users a ,departments d ";
Sql +=" where m.SendUserId=a.userid and m.Readstate=0 and d.departmentid=a.departmentid and m.ReceiveUserId="+userid.ToString () ;
DataTable dt= Dbc.getBinding (Sql,"t").Tables[0] ;
Sql="update message set readstate=1 where readstate=0 and ReceiveUserId="+userid ; //减少服务器的压务,将用户看过的消息置为己读
Dbc.ExecuteSQL (Sql);
return dt;
}
///
/// 得到一条记录
///
///
///
///
public DataRow GetRow(int id,string documentpath)
{
try
{
string Sql=" select * from message where id" +id.ToString () +" and documentpath='"+documentpath.ToString ()+"'";
DataTable dt=Dbc.getBinding (Sql,"t").Tables[0] ;
if (dt.Rows .Count !=1)
{
throw new ApplicationException ("没有找到数据或找到多条数据" );
}
return dt.Rows[0] ;
}
catch(Exception er)
{
throw new ApplicationException (er.Message );
}
}
///
/// 执行一条sql
///
///
public void ExcuteSql(string Sql)
{
Dbc.ExecuteSQL (Sql);
}
public void checkData()
{
// if(id.ToString ()==null)
// {
// throw new ApplicationException ("ID不能为空!");
// }
// if(sendtime.ToString ()==null)
// {
// throw new ApplicationException ("发送时期不能为空!");
//
// }
// if(senduserid.ToString ()==null)
// {
// throw new ApplicationException ("发送人不能为空!");
// }
// if (receiveuserid.ToString ()==null)
// {
// throw new ApplicationException ("接收人不能为空!");
//
// }
// if(title==null||title=="")
// {
// throw new ApplicationException ("标题不能为空!");
// }
//
// if(messagecontent==null||messagecontent=="")
// {
// throw new ApplicationException ("消息内容不能为空!");
// }
// if(modename==null||modename=="")
// {
// throw new ApplicationException ("待办事宜名称不能为空!");
// }
// if(documentpath==null||documentpath=="")
// {
// throw new ApplicationException ("文档访问路径不能为空!");
// }
}
///
/// `````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
/// 得到桌面上的待办事宜
///
///
public DataTable deskGetAllNoTransact(int userid)
{
string Sql=" select m.*,a.username,d.departmentname from message m,Accounts_Users a ,departments d where m.SendUserId=a.userid and m.istransact=0 and d.departmentid=a.departmentid and MessageType=0 and m.ReceiveUserId="+userid.ToString () ;
return Dbc.getBinding (Sql,"t").Tables[0] ;
}
public void finishOprate(int finishUserID,int id,string modename)
{
string Sql=" update message set istransact=1 ,ReceiveTime='"+System.DateTime.Now .ToString () +"'" ;
Sql +=" where id="+id.ToString ()+ " and modename='"+modename+"' and ReceiveUserId="+finishUserID.ToString ();
Dbc.ExecuteSQL (Sql);
}
public void deleteMessage(int sendUserID,int id,string modename)
{
string Sql =" delete from message where senduserid="+sendUserID.ToString ()+" and id="+id.ToString ()+ " and modename='"+modename+"'";
try
{
Dbc.ExecuteSQL (Sql);
}
catch(Exception er)
{
throw new ApplicationException (er.Message +""+Sql);
}
}
public void deleteMessage(int lsh)
{
string Sql =" delete from message where lsh="+lsh.ToString ();
try
{
Dbc.ExecuteSQL (Sql);
}
catch(Exception er)
{
throw new ApplicationException (er.Message +""+Sql);
}
}
public DataSet GetALLMessageByUserID(int userid)
{
string Sql = " select lsh,istransact,sendTime,ReceiveTime,Senduserid,a.username,d.departmentname,title,MessageContent, ";
Sql +=" case readstate when 1 then '己读' else '末读' end as readstate , " ;
Sql += " case istransact when 1 then '己处理' else '末处理' end as transact ";
Sql +=" from message m, departments d,accounts_users a where m.senduserid=a.userid and a.departmentid=d.departmentid ";
Sql +=" and m.ReceiveUserId="+ userid.ToString ();
try
{
return Dbc.getBinding (Sql,"t");
}
catch(Exception er)
{
throw new ApplicationException (er.Message +""+Sql);
}
}
}
}