MsgObj.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:16k
- 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;
- csCommand.Fill(msgobj,MessageData.MESSAGE_TABLE);
- int count = msgobj.Tables[MessageData.MESSAGE_TABLE].Rows.Count;
- string sendperson = command.Parameters["@sendperson"].Value.ToString();
- for(int i = 0; i < count; i ++)
- {
- msgobj.Tables[MessageData.MESSAGE_TABLE].Rows[i][MessageData.MESSAGEPERSON_FIELD] = sendperson;
- }
- return msgobj;
- }
- public void WatchTimesAdd(string reid)
- {
- SqlCommand command = new SqlCommand();
- command.CommandText = "Mag_AddTimes";
- command.CommandType = CommandType.StoredProcedure;
- command.Connection = conn;
- SqlParameter para = new SqlParameter("@reID",SqlDbType.Int);
- para.Value = Convert.ToInt32(reid,10);
- command.Parameters.Add(para);
- conn.Open();
- command.ExecuteNonQuery();
- conn.Close();
- }
- public int [] MsgNotice(int personid)
- {
- SqlCommand command = new SqlCommand();
- command.CommandText = "Msg_Notice";
- command.CommandType = CommandType.StoredProcedure;
- SqlParameter [] paras = { new SqlParameter("@personid",SqlDbType.Int),
- new SqlParameter("@seen",SqlDbType.Int),
- new SqlParameter("@unseen",SqlDbType.Int)
- };
- paras[0].Value = personid;
- paras[1].Direction = ParameterDirection.Output;
- paras[2].Direction = ParameterDirection.Output;
-
- foreach(SqlParameter para in paras)
- {
- command.Parameters.Add(para);
- }
- command.Connection = conn;
- conn.Open();
- command.ExecuteNonQuery();
- int [] see = new int[2];
- see[0] = Convert.ToInt32(command.Parameters["@seen"].Value.ToString(),10);
- see[1] = Convert.ToInt32(command.Parameters["@unseen"].Value.ToString(),10);
- return see;
- }
- public DataSet SeeDraft(string msgid,string personid)
- {
- SqlDataAdapter csCommand = new SqlDataAdapter();
- SqlCommand command = new SqlCommand();
- command.CommandType = CommandType.StoredProcedure;
- command.CommandText = "Msg_GetDraft";
- SqlParameter [] paras = { new SqlParameter("@personid",SqlDbType.Int),
- new SqlParameter("@msgid",SqlDbType.Int)
- };
- paras[0].Value = personid;
- paras[1].Value = msgid;
- foreach(SqlParameter para in paras)
- command.Parameters.Add(para);
- csCommand.SelectCommand = command;
- csCommand.SelectCommand.Connection = conn;
- DataSet data = new DataSet();
- csCommand.Fill(data,"draftmsg");
- return data;
- }
- public void InsertAgain(string msgid, MsgCont msgobj,int _status)
- {
- SqlCommand command = new SqlCommand();
- command.CommandText = "Msg_SendAgain";
- command.CommandType = CommandType.StoredProcedure;
- command.Connection = conn;
- SqlParameter [] paras = { new SqlParameter("@msgid",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)
- };
- paras[0].Value = Convert.ToInt32(msgid,10);
- 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;
- paras[10].Value = _status; //此参数表示是发送还是再次保存
- paras[11].Value = msgobj.Important;
- foreach(SqlParameter para in paras)
- command.Parameters.Add(para);
- conn.Open();
- command.ExecuteNonQuery();
- conn.Close();
- if(_status == 0)
- {
- int msgkey = Convert.ToInt32(msgid,10);
- AddMsgIndex(msgkey,msgobj.SendToID,msgobj.SecretToID,msgobj.SendTime,msgobj.Important);
- }
- }
- public void DeleteMessage(string msgid,string personid,string status)
- {
- SqlCommand command = new SqlCommand();
- command.CommandText = "Msg_DelMsg";
- command.CommandType = CommandType.StoredProcedure;
- command.Connection = conn;
- SqlParameter [] paras = { new SqlParameter("@msgid",SqlDbType.Int),
- new SqlParameter("@personid", SqlDbType.Int),
- new SqlParameter("@status" ,SqlDbType.Int)
- };
- paras[0].Value = Convert.ToInt32(msgid);
- paras[1].Value = Convert.ToInt32(personid);
- paras[2].Value = Convert.ToInt32(status);
- foreach(SqlParameter para in paras)
- {
- command.Parameters.Add(para);
- }
- conn.Open();
- command.ExecuteNonQuery();
- conn.Close();
- }
- public void MoveMessage(string msgid,string personid, string status)
- {
- SqlCommand command = new SqlCommand();
- command.CommandText = "Msg_MoveMsg";
- command.CommandType = CommandType.StoredProcedure;
- command.Connection = conn;
- SqlParameter [] paras = { new SqlParameter("@msgid",SqlDbType.Int),
- new SqlParameter("@personid", SqlDbType.Int),
- new SqlParameter("@status" ,SqlDbType.Int)
- };
- paras[0].Value = Convert.ToInt32(msgid);
- paras[1].Value = Convert.ToInt32(personid);
- paras[2].Value = Convert.ToInt32(status);
- foreach(SqlParameter para in paras)
- {
- command.Parameters.Add(para);
- }
- conn.Open();
- command.ExecuteNonQuery();
- conn.Close();
- }
- public string [] MsgFolder(string personid)
- {
- SqlCommand command = new SqlCommand();
- command.CommandText = "Msg_Folder";
- command.CommandType = CommandType.StoredProcedure;
- command.Connection = conn;
- SqlParameter [] paras = { new SqlParameter("@personid",SqlDbType.Int),
- new SqlParameter("@send",SqlDbType.Int),
- new SqlParameter("@resive_new",SqlDbType.Int),
- new SqlParameter("@resive_old",SqlDbType.Int),
- new SqlParameter("@draft",SqlDbType.Int),
- new SqlParameter("@rubbish_1",SqlDbType.Int),
- new SqlParameter("@rubbish_2",SqlDbType.Int)
- };
- paras[0].Value = Convert.ToInt32(personid,10);
- paras[1].Direction = ParameterDirection.Output;
- paras[2].Direction = ParameterDirection.Output;
- paras[3].Direction = ParameterDirection.Output;
- paras[4].Direction = ParameterDirection.Output;
- paras[5].Direction = ParameterDirection.Output;
- paras[6].Direction = ParameterDirection.Output;
- foreach(SqlParameter para in paras)
- {
- command.Parameters.Add(para);
- }
- conn.Open();
- command.ExecuteNonQuery();
- string [] info_list = new string [6];
- info_list[0] = command.Parameters["@send"].Value.ToString();
- info_list[1] = command.Parameters["@resive_new"].Value.ToString();
- info_list[2] = command.Parameters["@resive_old"].Value.ToString();
- info_list[3] = command.Parameters["@draft"].Value.ToString();
- info_list[4] = command.Parameters["@rubbish_1"].Value.ToString();
- info_list[5] = command.Parameters["@rubbish_2"].Value.ToString();
- conn.Close();
- return info_list;
- }
- public void RemainMsg(string msgid,string personid,string status)
- {
- SqlCommand command = new SqlCommand();
- command.CommandText = "Msg_RemainMsg";
- command.CommandType = CommandType.StoredProcedure;
- command.Connection = conn;
- SqlParameter [] paras = { new SqlParameter("@msgid",SqlDbType.Int),
- new SqlParameter("@personid", SqlDbType.Int),
- new SqlParameter("@status" ,SqlDbType.Int)
- };
- paras[0].Value = Convert.ToInt32(msgid);
- paras[1].Value = Convert.ToInt32(personid);
- paras[2].Value = Convert.ToInt32(status);
- foreach(SqlParameter para in paras)
- {
- command.Parameters.Add(para);
- }
- conn.Open();
- command.ExecuteNonQuery();
- conn.Close();
- }
- }
- }