Beispiel #1
0
 public void UpdateState(TB_PRO_STATE param)
 {
     using (var conn = new OracleConnection(ConnectionString()))
     {
         conn.Execute(
             @"update tb_pro_state 
                 set now_state=:STATE, change_time=sysdate 
                 where user_id=:USER_ID", param);
     }
 }
Beispiel #2
0
        private void Socket_Server_OnReceived(AsyncSocketServer asyncSocketServer, AsyncSocketServer.AsyncSocketServerConsumer asyncSocketClient, byte[] value)
        {
            try
            {
                string a = "";
                foreach (byte i in value)
                {
                    a += i.ToString();
                }
                TbxLogger($"Socket Recv(10진수) [{a}]");
                TbxLogger($"Socket Recv(ASCII) [STX{Encoding.Default.GetString(value)}ETX]");

                HeaderHandler.header head = new HeaderHandler.header();
                head.HandleDataReceive(value);

                switch (head.SocketNo)
                {
                case "20":
                    List <AllState> state_List = CommonData.serverDao.GetStateAll();

                    for (int i = 0; i < state_List.Count; i++)
                    {
                        asyncSocketClient.Send(head.HeadleDataSend("21", state_List[i].NOW_STATE + state_List[i].PRO_ADDRESS));
                        Thread.Sleep(50);
                    }

                    break;

                case "01":    // 로그인
                    TbxLogger($"{asyncSocketClient.Name} : Request Login");

                    string login_id = head.Body.Substring(0, 9);
                    string login_pw = head.Body.Substring(9);

                    List <MD_USER> User_List = CommonData.serverDao.SelectMDUser();

                    MD_USER Select_MD = User_List.Where(i => i.USER_ID == login_id).FirstOrDefault();

                    if (Select_MD == null)   //아이디 없음.
                    {
                        asyncSocketClient.Send(head.HeadleDataSend("11", "1"));
                        TbxLogger($"{asyncSocketClient.Name} : Failed Login - Not exist ID");

                        a = "";
                        foreach (byte i in head.HeadleDataSend("11", "0"))
                        {
                            a += i.ToString();
                        }
                        TbxLogger($"Socket Send(10진수) [{a}]");
                        TbxLogger($"Socket Send(ASCII) [STX{Encoding.Default.GetString(head.HeadleDataSend("11", "1"))}ETX]");
                    }
                    else
                    {
                        if (Select_MD.USER_PW != login_pw)   //비밀번호 틀림.
                        {
                            asyncSocketClient.Send(head.HeadleDataSend("11", "2"));
                            TbxLogger($"{asyncSocketClient.Name} : Failed Login - Not match PW");

                            a = "";
                            foreach (byte i in head.HeadleDataSend("11", "0"))
                            {
                                a += i.ToString();
                            }
                            TbxLogger($"Socket Send(10진수) [{a}]");
                            TbxLogger($"Socket Send(ASCII) [STX{Encoding.Default.GetString(head.HeadleDataSend("11", "2"))}ETX]");
                        }
                        else    //로그인 성공
                        {
                            asyncSocketClient.Send(head.HeadleDataSend("11", "0"));
                            TbxLogger($"{asyncSocketClient.Name} : Success Login");

                            a = "";
                            foreach (byte i in head.HeadleDataSend("11", "0"))
                            {
                                a += i.ToString();
                            }
                            TbxLogger($"Socket Send(10진수) [{a}]");
                            TbxLogger($"Socket Send(ASCII) [STX{Encoding.Default.GetString(head.HeadleDataSend("11", "0"))}ETX]");

                            List <Client> tempList = new List <Client>();
                            foreach (Client item in _context.Client_List)
                            {
                                tempList.Add(item);
                            }
                            tempList.Add(new Client(asyncSocketClient, asyncSocketClient.Name, head.Body.Substring(0, 9)));

                            _context.Client_List = tempList;
                        }
                    }

                    break;

                case "03":    // 상태 변경
                    try
                    {
                        TB_PRO_STATE param = new TB_PRO_STATE();
                        param.USER_ID = head.Body.Substring(0, 9);
                        param.STATE   = head.Body.Substring(9);

                        CommonData.serverDao.UpdateState(param);

                        asyncSocketClient.Send(head.HeadleDataSend("13", param.STATE));
                    }
                    catch (Exception e)
                    {
                        asyncSocketClient.Send(head.HeadleDataSend("00", e.ToString()));
                    }
                    break;

                case "04":    // 특정 교수 검색
                    try
                    {
                        SearchState param = new SearchState();
                        param.PROF_NAME = head.Body;

                        param = CommonData.serverDao.GetState(param);

                        if (param != null)
                        {
                            param.PROF_NAME = head.Body;
                            asyncSocketClient.Send(head.HeadleDataSend("14", param.PROF_ID + param.STATE + param.PROF_NAME));
                        }
                        else
                        {
                            asyncSocketClient.Send(head.HeadleDataSend("00", head.Body + " 교수님은 존재하지 않습니다."));
                        }
                    }
                    catch (Exception e)
                    {
                        asyncSocketClient.Send(head.HeadleDataSend("00", e.ToString()));
                    }
                    break;

                case "05":    // 메시지 조회
                    try
                    {
                        MD_USER param = new MD_USER();
                        param.USER_ID = head.Body.Substring(0, 9);

                        List <Message> searchMessage = new List <Message>();
                        searchMessage = CommonData.serverDao.GetMessage(param);

                        List <MD_USER> user_data_List = CommonData.serverDao.SelectMDUser();


                        for (int i = 0; i < searchMessage.Count; i++)
                        {
                            MD_USER search_MD = user_data_List.Where(j => j.USER_ID == searchMessage[i].FROM_ID).FirstOrDefault();

                            if (search_MD != null)
                            {
                                asyncSocketClient.Send(head.HeadleDataSend("15", searchMessage[i].FROM_ID + search_MD.USER_NAME + searchMessage[i].MESSAGE));
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        asyncSocketClient.Send(head.HeadleDataSend("00", e.ToString()));
                    }
                    break;

                case "06":    // 메시지 답장
                    try
                    {
                        Message param = new Message();
                        param.TO_ID   = head.Body.Substring(0, 9);
                        param.FROM_ID = head.Body.Substring(9, 9);
                        param.MESSAGE = head.Body.Substring(18);

                        List <MD_USER> user_data_List = CommonData.serverDao.SelectMDUser();

                        MD_USER search_MD = user_data_List.Where(j => j.USER_ID == param.TO_ID).FirstOrDefault();

                        if (search_MD != null)   //받는 아이디 존재 확인.
                        {
                            CommonData.serverDao.InsertMessage(param);
                            asyncSocketClient.Send(head.HeadleDataSend("16", "0"));    //성공
                        }
                        else
                        {
                            asyncSocketClient.Send(head.HeadleDataSend("00", "존재하지 않는 USER ID 입니다."));
                        }
                    }
                    catch (Exception e)
                    {
                        asyncSocketClient.Send(head.HeadleDataSend("00", e.ToString()));
                    }
                    break;

                case "02":    // 로그아웃

                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Logger.All.Debug(ex);
            }
        }