public void Init(int chatID) { mRoomID = chatID; DataTable rowMsgs = DatabaseMgr.GetChatMessages(mRoomID); if (rowMsgs != null) { foreach (DataRow item in rowMsgs.Rows) { MsgInfo info = new MsgInfo(); string msg = item["info"].ToString(); info.message = msg.Substring(0, msg.Length); info.isSignaled = false; info.msgID = (int)item["recordID"]; info.time = item["time"].ToString(); info.user = item["user"].ToString(); info.tick = 0; mMessages.Add(info); } } int cntMessages = mMessages.Count; DataRow room = DatabaseMgr.GetChatRoomInfo(mRoomID); if (room != null) { mAccess = room["access"].ToString(); UpdateUsersFromDB(mRoomID); UpdateTasksFromDB(mRoomID); } return; }
private void ICD_Login(int clientID, HEADER obj) { User msg = obj as User; DataRow row = DatabaseMgr.GetUserInfo(msg.userID); User pack = new User(); pack.FillServerHeader(DEF.CMD_Login); if (row != null) { if (row["password"].ToString() == msg.userPW) { AddUser(clientID, msg.userID); pack.userID = row["recordID"].ToString(); pack.userPW = row["password"].ToString(); } else { pack.msgErr = DEF.ERR_WorngPW; } } else { pack.msgErr = DEF.ERR_NoID; } ICDPacketMgr.GetInst().sendMsgToClient(clientID, pack); }
private void ICD_ProcWorkHistory(int clientID, HEADER obj) { string user = obj.msgUser; int taskID = int.Parse(obj.ext1); DataTable table = DatabaseMgr.GetTaskHistory(taskID); if (table == null) { return; } List <WorkHistory> vec = new List <WorkHistory>(); foreach (DataRow item in table.Rows) { WorkHistory his = new WorkHistory(); his.recordID = (int)item["recordID"]; his.taskID = (int)item["taskID"]; his.time = item["time"].ToString();; his.editor = item["user"].ToString(); his.columnName = item["columnName"].ToString(); his.fromInfo = item["fromInfo"].ToString(); his.toInfo = item["toInfo"].ToString(); vec.Add(his); } WorkHistoryList msg = new WorkHistoryList(); msg.FillServerHeader(DEF.CMD_TaskHistory, 0); msg.workHistory = vec.ToArray(); sendMsg(user, msg); }
public void DelTask(ChatRoomInfo obj) { DatabaseMgr.DelChatTasks(obj); foreach (int id in obj.body.taskIDs) { string taskID = id.ToString(); if (mTaskIDs.ContainsKey(taskID)) { mTaskIDs.Remove(taskID); } } }
public void AddTask(ChatRoomInfo obj) { if (obj.body.taskIDs == null) { return; } DatabaseMgr.AddChatTasks(obj); foreach (int id in obj.body.taskIDs) { string taskID = id.ToString(); mTaskIDs[taskID] = id; } }
private void ProcAddUsers(ChatRoomInfo obj) { foreach (string name in obj.body.users) { if (mUsers.ContainsKey(name)) { continue; } mUsers[name] = mMessages.Count; } DatabaseMgr.AddChatUsers(obj); BroadcastRoomInfo(GetRoomInfo()); }
private void InitChatRooms() { DataTable table = DatabaseMgr.GetChatRoomList(); if (table == null) { return; } foreach (DataRow row in table.Rows) { int chatID = (int)row["recordID"]; ChatRoom room = new ChatRoom(); room.Init(chatID); mRooms[chatID] = room; } }
private void ProcMessage(ChatRoomInfo obj) { DataRow row = DatabaseMgr.PushChatMessage(obj); int msgID = (int)row["recordID"]; MsgInfo item = new MsgInfo(); item.msgID = msgID; item.time = obj.msgTime; item.user = obj.msgUser; item.tick = mUsers.Count - CountLoginUser(); item.message = obj.body.mesgs[0].message; item.isSignaled = true; mMessages.Add(item); ChatRoomInfo msg = GetRoomInfo(); BroadcastRoomInfo(msg); }
private void AddUsers(ChatRoomInfo obj) { if (obj.body.users == null) { return; } foreach (string name in obj.body.users) { if (mUsers.ContainsKey(name)) { continue; } mUsers[name] = mMessages.Count; } DatabaseMgr.AddChatUsers(obj); }
private void ICD_ProcWorkList(int clientID, HEADER obj) { string user = obj.msgUser; DataTable table = DatabaseMgr.GetTasks(obj.ext1, obj.ext2); if (table == null) { return; } WorkList msg = new WorkList(); msg.FillServerHeader(DEF.CMD_TaskBaseList, 0); msg.works = new Work[table.Rows.Count]; foreach (DataRow row in table.Rows) { int idx = table.Rows.IndexOf(row); msg.works[idx] = new Work(); msg.works[idx].recordID = (int)row["recordID"]; msg.works[idx].type = row["type"].ToString(); msg.works[idx].time = row["time"].ToString(); msg.works[idx].creator = row["creator"].ToString(); msg.works[idx].access = row["access"].ToString(); msg.works[idx].mainCate = row["mainCate"].ToString(); msg.works[idx].subCate = row["subCate"].ToString(); msg.works[idx].title = row["title"].ToString(); msg.works[idx].comment = row["comment"].ToString(); msg.works[idx].director = row["director"].ToString(); msg.works[idx].worker = row["worker"].ToString(); msg.works[idx].launch = row["launch"].ToString(); msg.works[idx].due = row["due"].ToString(); msg.works[idx].term = row["term"].ToString(); msg.works[idx].state = row["state"].ToString(); msg.works[idx].priority = row["priority"].ToString(); msg.works[idx].progress = (int)row["progress"]; msg.works[idx].chatID = (int)row["chatID"]; msg.works[idx].timeFirst = row["timeFirst"].ToString(); msg.works[idx].timeDone = row["timeDone"].ToString(); } sendMsg(user, msg); }
private void ICD_TaskList(int clientID, HEADER obj) { DataTable table = DatabaseMgr.GetTasks(obj.msgUser); if (table == null || table.Rows.Count == 0) { return; } ICD.WorkList msg = new ICD.WorkList(table.Rows.Count); msg.FillServerHeader(DEF.CMD_TaskIDList, 0); foreach (DataRow row in table.Rows) { int index = table.Rows.IndexOf(row); DatabaseMgr.GetTaskLatest((int)row["recordID"], ref msg.works[index]); int state = mRooms[msg.works[index].chatID].GetUserState(obj.msgUser); msg.works[index].currentState = state; } sendMsg(obj.msgUser, msg); }
private void ICD_UserList(int clientID, HEADER obj) { DataTable table = DatabaseMgr.GetUsers(); if (table == null) { return; } Message pack = new Message(); pack.FillServerHeader(DEF.CMD_UserList); foreach (DataRow user in table.Rows) { pack.message += user["recordID"].ToString(); pack.message += ","; } ICDPacketMgr.GetInst().sendMsgToClient(clientID, pack); }
private void ICD_NewUser(int clientID, HEADER obj) { User msg = obj as User; if (DatabaseMgr.GetUserInfo(msg.userID) != null) { HEADER pack = new HEADER(); pack.FillServerHeader(DEF.CMD_NewUser); pack.msgErr = DEF.ERR_HaveID; ICDPacketMgr.GetInst().sendMsgToClient(clientID, pack); } else { DatabaseMgr.NewUser(msg); HEADER pack = new HEADER(); pack.FillServerHeader(DEF.CMD_NewUser); ICDPacketMgr.GetInst().sendMsgToClient(clientID, pack); } }
private void ICD_EditTask(int clientID, HEADER obj) { WorkHistoryList msg = obj as WorkHistoryList; DatabaseMgr.EditTask(msg); int taskID = msg.workHistory[0].taskID; if ((msg.workHistory.Length == 1) && (msg.workHistory[0].columnName == "confirmOK")) { string[] data = new string[2]; data = msg.workHistory[0].toInfo.Split(',', (char)2); DatabaseMgr.EditTaskBase(taskID, "timeDone", data[0]); } ICD.WorkList task = new ICD.WorkList(); task.FillServerHeader(DEF.CMD_TaskLatestInfo, 0); DatabaseMgr.GetTaskLatest(taskID, ref task.works[0]); sendMsg(task.works[0].worker, task); sendMsg(task.works[0].director, task); }
private void ProcDelUser(ChatRoomInfo obj) { foreach (string name in obj.body.users) { if (!mUsers.ContainsKey(name)) { continue; } UpdateTick(name); mUsers.Remove(name); ChatRoomInfo msg = new ChatRoomInfo(); msg.FillServerHeader(DEF.CMD_DelChatUsers, 0); msg.body.recordID = mRoomID; MsgCtrl.GetInst().sendMsg(name, msg); } DatabaseMgr.DelChatUsers(obj); BroadcastRoomInfo(GetRoomInfo()); }
private void ICD_NewTask(int clientID, HEADER obj) { ICD.WorkList msg = obj as ICD.WorkList; if (msg.works == null && msg.works.Length != 1) { LOG.warn(); return; } ICD.Work work = msg.works[0]; ChatRoom room = new ChatRoom(); ChatRoomInfo roomInfo = new ChatRoomInfo(); roomInfo.FillHeader(obj); roomInfo.body.access = work.access; roomInfo.body.users = new string[2]; roomInfo.body.users[0] = work.director; roomInfo.body.users[1] = work.worker; int chatID = room.CreateNewChat(roomInfo); mRooms[chatID] = room; roomInfo.body.recordID = chatID; work.chatID = chatID; DataRow row = DatabaseMgr.NewTask(msg); int taskID = (int)row["recordID"]; roomInfo.body.taskIDs = new int[1]; roomInfo.body.taskIDs[0] = taskID; room.AddTask(roomInfo); ICD.WorkList task = new ICD.WorkList(); task.FillServerHeader(DEF.CMD_TaskLatestInfo, 0); DatabaseMgr.GetTaskLatest(taskID, ref task.works[0]); sendMsg(task.works[0].worker, task); sendMsg(task.works[0].director, task); }
public int CreateNewChat(ChatRoomInfo obj) { DataRow row = DatabaseMgr.PushNewChat(obj); mRoomID = (int)row["recordID"]; mAccess = obj.body.access; mMessages.Clear(); obj.body.recordID = mRoomID; if (obj.body.users != null) { foreach (var user in obj.body.users) { mUsers[user] = 0; } } AddTask(obj); DatabaseMgr.AddChatUsers(obj); //BroadcastRoomInfo( GetRoomInfo() ); return(mRoomID); }
private void UpdateTasksFromDB(int chatID) { mTaskIDs.Clear(); DataTable rowMsgs = DatabaseMgr.GetChatTasks(mRoomID); if (rowMsgs == null) { return; } foreach (DataRow item in rowMsgs.Rows) { if (item["type"].ToString() == "addTask") { string taskID = item["info"].ToString(); mTaskIDs[taskID] = int.Parse(taskID); } else if (item["type"].ToString() == "delTask") { string taskID = item["info"].ToString(); mTaskIDs.Remove(taskID); } } }
private void UpdateUsersFromDB(int chatID) { mUsers.Clear(); DataTable rowMsgs = DatabaseMgr.GetChatUsers(mRoomID); if (rowMsgs == null) { return; } foreach (DataRow item in rowMsgs.Rows) { if (item["type"].ToString() == "addUser") { string user = item["info"].ToString(); mUsers[user] = mMessages.Count; } else if (item["type"].ToString() == "delUser") { string user = item["info"].ToString(); mUsers.Remove(user); } } }
private void btnServer_Click(object sender, EventArgs e) { DatabaseMgr.Open(); MsgCtrl.GetInst().StartService(); }