📄 msgobj.cs
字号:
using System;
using qminoa.Common.Data;
using System.Data;
using System.Data.SqlClient;
namespace qminoa.DA
{
public class MsgObj
{
private SqlConnection conn;
public MsgObj()
{
conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
}
public void InsertMessage(MsgCont msgobj,string Type,int personid)
{
SqlCommand command = new SqlCommand();
command.CommandText = "Msg_SendSave";
command.CommandType = CommandType.StoredProcedure;
command.Connection = conn;
SqlParameter [] paras = { new SqlParameter("@MessagePersonID",SqlDbType.Int),
new SqlParameter("@SendTo",SqlDbType.NVarChar,200),
new SqlParameter("@SecretTo",SqlDbType.NVarChar,200),
new SqlParameter("@SendToID",SqlDbType.NVarChar,200),
new SqlParameter("@SecretToID",SqlDbType.NVarChar,200),
new SqlParameter("@Title",SqlDbType.NVarChar,50),
new SqlParameter("@Content",SqlDbType.Text),
new SqlParameter("@SendDate",SqlDbType.DateTime),
new SqlParameter("@Accessory",SqlDbType.NVarChar,200),
new SqlParameter("@AccessoryID",SqlDbType.NVarChar,200),
new SqlParameter("@Status",SqlDbType.Int),
new SqlParameter("@Important",SqlDbType.Bit),
new SqlParameter("@RetValue",SqlDbType.Int)
};
paras[0].Value = personid;
paras[1].Value = msgobj.SendTo;
paras[2].Value = msgobj.SecretTo;
paras[3].Value = msgobj.SendToID;
paras[4].Value = msgobj.SecretToID;
paras[5].Value = msgobj.Title;
paras[6].Value = msgobj.Content;
paras[7].Value = msgobj.SendTime;
paras[8].Value = msgobj.Accessory;
paras[9].Value = msgobj.AccessoryID;
if("发送" == Type)
{
paras[10].Value = 0;
}
else if( "保存" == Type)
{
paras[10].Value = 2;
}
paras[11].Value = msgobj.Important;
paras[12].Direction = ParameterDirection.ReturnValue;
foreach(SqlParameter para in paras)
{
command.Parameters.Add(para);
}
conn.Open();
command.ExecuteNonQuery();
int msgkey = Convert.ToInt32(command.Parameters["@RetValue"].Value.ToString(),10);
conn.Close();
if("发送" == Type)
{
AddMsgIndex(msgkey,msgobj.SendToID,msgobj.SecretToID,msgobj.SendTime,msgobj.Important);
}
}
public void AddMsgIndex(int MsgKey,string SendToID,string SecretToID,DateTime senddate,bool Important)
{
char [] separator = new char[1];
char [] separator2 = new Char[1];
separator[0] = ',';
separator2[0] = '*';
MsgAdd msgindex = new MsgAdd();
DataRow row ;
if( SendToID != "" && SendToID != null)
{
string [] senddepartid = SendToID.Split(separator,50);
for(int i = 0; i < senddepartid.Length; i ++)
{
int pos = senddepartid[i].IndexOf("*");
string [] sendid = senddepartid[i].Split(separator2,2);
if( pos != -1)
{
row = msgindex.Tables["MsgAdd"].NewRow();
row[MsgAdd.MSGID_FIELD] = MsgKey;
row[MsgAdd.MSGPERSONID_FIELD] = Convert.ToInt32(sendid[1],10);
row[MsgAdd.SENDLEVEL_FIELD] = 0;
row[MsgAdd.TIMES_FIELD] = 0;
row[MsgAdd.STATUS_FIELD] = 4;
row[MsgAdd.DELETEFLAG_FIELD] = 0;
row[MsgAdd.SENDDATE_FIELD] = senddate;
row[MsgAdd.IMPORTANT_FIELD] = Important;
msgindex.Tables[MsgAdd.MSGADD_TABLE].Rows.Add(row);
}
else
{
int departid = Convert.ToInt32(senddepartid[i],10);
SelectPersonByDepart(departid,msgindex,MsgKey,senddate,0,Important);
}
}
}
if( SecretToID != "" && SecretToID != null)
{
string [] secretdepartid = SecretToID.Split(separator,10);
for(int j = 0; j < secretdepartid.Length; j ++)
{
int pos = secretdepartid[j].IndexOf("*");
string [] secretid = secretdepartid[j].Split(separator2,2);
if(pos != -1)
{
row = msgindex.Tables["MsgAdd"].NewRow();
row[MsgAdd.MSGID_FIELD] = MsgKey;
row[MsgAdd.MSGPERSONID_FIELD] = Convert.ToInt32(secretid[1],10);
row[MsgAdd.SENDLEVEL_FIELD] = 1;
row[MsgAdd.TIMES_FIELD] = 0;
row[MsgAdd.STATUS_FIELD] = 4;
row[MsgAdd.DELETEFLAG_FIELD] = 0;
row[MsgAdd.SENDDATE_FIELD] = senddate;
row[MsgAdd.IMPORTANT_FIELD] = Important;
msgindex.Tables[MsgAdd.MSGADD_TABLE].Rows.Add(row);
}
else
{
int depart = Convert.ToInt32(secretdepartid[j],10);
SelectPersonByDepart(depart,msgindex,MsgKey,senddate,1,Important);
}
}
}
SqlDataAdapter cscommand = new SqlDataAdapter();
cscommand.SelectCommand = new SqlCommand("select * from MsgAdd");
cscommand.SelectCommand.Connection = conn;
SqlCommandBuilder objBuilder = new SqlCommandBuilder(cscommand);
cscommand.Update(msgindex,"MsgAdd");
}
public void SelectPersonByDepart(int DepartID,MsgAdd msgobj,int MsgKey,DateTime senddate,int send_level,bool Important)
{
SqlCommand command = new SqlCommand();
command.CommandText = "Msg_GetEmpByDep";
SqlParameter para = new SqlParameter("@DepartID",SqlDbType.Int);
command.CommandType = CommandType.StoredProcedure;
para.Value = DepartID;
command.Parameters.Add(para);
command.Connection = conn;
if(conn.State == ConnectionState.Closed)
conn.Open();
SqlDataReader reader;
reader = command.ExecuteReader();
DataRow row;
while(reader.Read())
{
row = msgobj.Tables["MsgAdd"].NewRow();
row[MsgAdd.MSGID_FIELD] = MsgKey;
row[MsgAdd.MSGPERSONID_FIELD] = Convert.ToInt32(reader["EmpID"].ToString(),10);
row[MsgAdd.SENDLEVEL_FIELD] = send_level;
row[MsgAdd.TIMES_FIELD] = 0;
row[MsgAdd.STATUS_FIELD] = 4;
row[MsgAdd.DELETEFLAG_FIELD] = 0;
row[MsgAdd.SENDDATE_FIELD] = senddate;
row[MsgAdd.IMPORTANT_FIELD] = Important;
msgobj.Tables[MsgAdd.MSGADD_TABLE].Rows.Add(row);
}
reader.Close();
conn.Close();
}
public DataSet SeeMessage(string type,int PersonID)
{
DataSet msgobj = new DataSet();
SqlDataAdapter csCommand = new SqlDataAdapter();
SqlCommand command = new SqlCommand();
csCommand.SelectCommand = command;
command.CommandText = "Msg_GetMsgById";
command.CommandType = CommandType.StoredProcedure;
SqlParameter [] paras = { new SqlParameter("@Type",SqlDbType.Int),
new SqlParameter("@PersonID",SqlDbType.Int)
};
if("recnote" == type)
{
paras[0].Value = 0;
}
else if ("sendnote" == type)
{
paras[0].Value = 1;
}
else if ( "caonote" == type)
{
paras[0].Value = 2;
}
else
{
paras[0].Value = 3;
}
paras[1].Value = PersonID;
foreach(SqlParameter para in paras)
{
command.Parameters.Add(para);
}
csCommand.SelectCommand.Connection = conn;
csCommand.Fill(msgobj,"simpleobj");
return msgobj;
}
public MessageData SeeAllMessage(string messageid,string status)
{
MessageData msgobj = new MessageData();
SqlDataAdapter csCommand = new SqlDataAdapter();
SqlCommand command = new SqlCommand();
csCommand.SelectCommand = command;
command.CommandText = "Msg_GetAllMsg";
command.CommandType = CommandType.StoredProcedure;
SqlParameter [] paras = {
new SqlParameter("@MessageID",SqlDbType.Int),
new SqlParameter("@sendperson",SqlDbType.NVarChar,50),
new SqlParameter("@Status",SqlDbType.Int)
};
paras[0].Value = Convert.ToInt32(messageid,10);
paras[1].Direction = ParameterDirection.Output;
paras[2].Value = Convert.ToInt32(status,10);
foreach(SqlParameter para in paras)
{
command.Parameters.Add(para);
}
csCommand.SelectCommand.Connection = conn;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -