Ejemplo n.º 1
0
 private void Btn_ordered_Click(object sender, EventArgs e)
 {
     try
     {
         //현재 열려있는 chattingForm 중에서 ID가 같은 폼을 탐색
         ChattingForm chattingForm = FindByID("SYSTEM_SERVER");
         //ID가 존재하지 않으면 새로운 폼 생성
         if (chattingForm == null)
         {
             chattingForm = new ChattingForm("SYSTEM_SERVER", this);
             chatFormList.AddLast(chattingForm).Value.ShowDialog();
         }
     }
     catch (Exception except)
     {
         MessageBox.Show(except.Message, "Open order log Err");
     }
 }
Ejemplo n.º 2
0
 private void Btn_chat_Click(object sender, EventArgs e)
 {
     try
     {
         if (grid_customer_table[2, selectedRow].Value.ToString() == "")
         {
             return;
         }
         //현재 열려있는 chattingForm 중에서 ID가 같은 폼을 탐색
         ChattingForm chattingForm = FindByID(grid_customer_table[2, selectedRow].Value.ToString());
         //ID가 존재하지 않으면 새로운 폼 생성
         if (chattingForm == null)
         {
             chattingForm = new ChattingForm(grid_customer_table[2, selectedRow].Value.ToString(), this);
             chatFormList.AddLast(chattingForm).Value.ShowDialog();
         }
     }
     catch (Exception except)
     {
         MessageBox.Show(except.Message, "Open chat form Err");
     }
 }
Ejemplo n.º 3
0
 public void CloseForm(ChattingForm form)
 {
     mutex.WaitOne();
     chatFormList.Remove(form);
     mutex.ReleaseMutex();
 }
Ejemplo n.º 4
0
        //수신 메시지 별 행동
        private void CommandAction(string cmd)
        {
            if (cmd == null || cmd.Length == 0)
            {
                return;
            }

            string[] strSplit = cmd.Split(':');

            try
            {
                switch (strSplit[0])
                {
                //채팅방 호출 명령어 (CHTCALL:id)
                case "CHTCALL":
                {
                    //args 부족
                    if (strSplit.Length <= 1)
                    {
                        break;
                    }
                    //현재 열려있는 chattingForm 중에서 ID가 같은 폼을 탐색
                    ChattingForm chattingForm = FindByID(strSplit[1]);
                    //ID가 존재하지 않으면 새로운 폼 생성
                    if (chattingForm == null)
                    {
                        chattingForm = new ChattingForm(strSplit[1], this);
                        Application.Run(chatFormList.AddLast(chattingForm).Value);
                    }
                    //ID가 존재하고 연결 상태가 끊김이면 상태를 변경
                    else if (chattingForm.IsConnected() == false)
                    {
                        chattingForm.Reconnected();
                    }
                    break;
                }

                //채팅 내용 전달 명령어 (CHAT:id:내용)
                case "CHAT":
                {
                    //args 부족
                    if (strSplit.Length <= 2)
                    {
                        break;
                    }

                    //현재 열려있는 chattingForm 중에서 ID가 같은 폼을 탐색
                    ChattingForm chattingForm = FindByID(strSplit[1]);
                    if (chattingForm == null)
                    {
                        break;
                    }

                    for (int i = 3; i < strSplit.Length; i++)
                    {
                        strSplit[2] += $":{strSplit[i]}";
                    }
                    chattingForm.ReceiveChat(strSplit[2]);
                    break;
                }

                //어플의 연결이 끊겼음을 알리는 명령어
                case "CCLOSE":
                {
                    //args 부족
                    if (strSplit.Length <= 1)
                    {
                        break;
                    }

                    ChattingForm chattingForm = FindByID(strSplit[1]);
                    if (chattingForm != null)
                    {
                        chattingForm.Disconnected();
                    }
                    break;
                }

                //어플이 재연결 됨을 알리는 명령어
                case "CCON":
                {
                    //args 부족
                    if (strSplit.Length <= 1)
                    {
                        break;
                    }

                    ChattingForm chattingForm = FindByID(strSplit[1]);
                    if (chattingForm != null)
                    {
                        chattingForm.Reconnected();
                    }
                    break;
                }

                //고객 정보를 전송하는 명령어(CLIST:고객수:{i}@ID:nid:{i}@NM:name:{i}@PN:phone:{i}@AG:age:{i}@AD:address:{i}@RM:rid) => {i}는 정수, 괄호는 넣지않음
                case "CLIST":
                {
                    //args 부족
                    if (strSplit.Length <= 2)
                    {
                        break;
                    }
                    //고객 수 파싱
                    int nCount = 0;
                    if (int.TryParse(strSplit[1], out nCount) == false)
                    {
                        MessageBox.Show("서버에서 고객 정보를 받아오는 데 실패하였습니다 : Failed parsing customer count");
                        break;
                    }
                    //고객의 수가 0이하면 무시
                    if (nCount <= 0)
                    {
                        break;
                    }

                    //Row(행)의 수를 고객 수와 동일하게 맞춤
                    while (grid_customer_table.Rows.Count != nCount)
                    {
                        //테이블 행의 수가 고객 수보다 많으면 같은 수가 될 때까지 뒤에서부터 행을 제거
                        if (grid_customer_table.Rows.Count > nCount)
                        {
                            grid_customer_table.Rows.RemoveAt(grid_customer_table.Rows.Count - 1);
                        }
                        //테이블 행의 수가 고객 수보다 적으면 같은 수가 될 때까지 행을 추가
                        else if (grid_customer_table.Rows.Count < nCount)
                        {
                            grid_customer_table.Rows.Add();
                        }
                    }

                    int      index    = 0;
                    string[] strField = null;
                    //i -> 콜론(:)으로 나눈 문자열들의 인덱스
                    //index -> 고객의 인덱스
                    for (int i = 2; i < strSplit.Length; i++)
                    {
                        //문자열을 @키워드를 기준으로 분리
                        strField = strSplit[i].Split('@');
                        //고객 인덱스를 얻어옴
                        index = Convert.ToInt32(strField[0]);
                        //문자 @NULL은 빈 값
                        switch (strField[1])
                        {
                        case "ID":
                        {
                            i++;
                            grid_customer_table[0, index].Value = (strSplit[i] == "@NULL") ? string.Empty : strSplit[i];
                            break;
                        }

                        case "NM":
                        {
                            i++;
                            grid_customer_table[1, index].Value = (strSplit[i] == "@NULL") ? string.Empty : strSplit[i];
                            break;
                        }

                        case "PN":
                        {
                            i++;
                            grid_customer_table[2, index].Value = (strSplit[i] == "@NULL") ? string.Empty : strSplit[i];
                            break;
                        }

                        case "AG":
                        {
                            i++;
                            grid_customer_table[3, index].Value = (strSplit[i] == "@NULL") ? string.Empty : strSplit[i];
                            break;
                        }

                        case "AD":
                        {
                            i++;
                            grid_customer_table[4, index].Value = (strSplit[i] == "@NULL") ? string.Empty : strSplit[i];
                            break;
                        }

                        case "RM":
                        {
                            i++;
                            grid_customer_table[5, index].Value = (strSplit[i] == "@NULL") ? string.Empty : strSplit[i];
                            break;
                        }
                        }
                    }

                    break;
                }
                }

                return;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }