private void ErrorMessage(Exception ex)
        {
            WriteLog(ex);
            FormCollection frms = Application.OpenForms;

            for (int i = 0; i < frms.Count; i++)
            {
                if (frms[i] == null)
                {
                    i++;
                    continue;
                }
                if (frms[i] is PopMain)
                {
                    PopMain pop = (PopMain)frms[i];
                    // 해당 POP의 라인아이디와 같은 경우
                    if (pop.WorkerInfo.LineID == LineID)
                    {
                        ReceiveEventArgs e = new ReceiveEventArgs();
                        e.Message     = string.Join("오류", ex.Message);
                        e.LineID      = LineID;
                        e.IsCompleted = false;

                        if (!pop.IsDisposed)
                        {
                            if (Received != null)
                            {
                                Received.Invoke(this, e);
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        // 연결(로그인) 선택시
        private void btnConnect_Click(object sender, EventArgs e)
        {
            StringBuilder msg = new StringBuilder();

            if (cboFactory.SelectedIndex < 1)
            {
                msg.AppendLine(string.Format(Properties.Resources.MsgChoice2, "공장"));
            }

            if (cboLine.SelectedIndex < 1)
            {
                msg.AppendLine(string.Format(Properties.Resources.MsgChoice2, "공정"));
            }

            if (cboWorker.SelectedIndex < 1)
            {
                msg.AppendLine(string.Format(Properties.Resources.MsgChoice1, "작업자"));
            }

            if (msg.Length > 1)
            {
                CustomMessageBox.ShowDialog("접속실패", msg.ToString(), MessageBoxIcon.Warning, MessageBoxButtons.OK);
                return;
            }

            // 유효성 검사(Login 성공시 => POPWorkInfo로 데이터를 담음)
            workerInfo = new WorkerInfoPOP
            {
                WorkID      = Convert.ToInt32(cboWorker.SelectedValue),
                Worker      = cboWorker.Text,
                LineID      = Convert.ToInt32(cboLine.SelectedValue),
                LineName    = cboLine.Text,
                FactoryID   = cboFactory.SelectedValue.ToString(),
                FactoryName = cboFactory.Text
            };

            // 로그인이 완료되면 메인 화면을 띄워주는 코드
            PopMain Main = new PopMain();

            Hide();
            Main.WorkerInfo = workerInfo;

            // 로그아웃버튼을 누른 경우
            // 폼을 다시 로드하는 효과를 줌.
            if (Main.ShowDialog() == DialogResult.OK)
            {
                InitData();

                cboFactory.SelectedValue = Main.WorkerInfo.FactoryID;
                Show();
            }
            // 종료 버튼을 누른 경우
            // 로그인 화면도 닫음
            else
            {
                Close();
            }
        }
        // 서버 수신메서드
        public async Task Read()
        {
            if (!netStream.CanRead)
            {
                return;
            }

            try
            {
                StreamReader reader = new StreamReader(netStream);

                string[] msg = (await reader.ReadLineAsync()).Split(',');

                if (msg.Length > 1)
                {
                    FormCollection frms = Application.OpenForms;

                    for (int i = 0; i < frms.Count; i++)
                    {
                        if (frms[i] == null)
                        {
                            continue;
                        }

                        if (frms[i] is PopMain)
                        {
                            PopMain pop = (PopMain)frms[i];
                            // 해당 POP의 라인아이디와 같은 경우
                            if (pop.WorkerInfo.LineID == Convert.ToInt32(msg[0]))
                            {
                                //respone 형태 (실시간모니터인지 아닌지(0), 라인아이디(1),메세지(2),생산실적아이디(3),완료여부(4),총 투입수량(5))
                                ReceiveEventArgs e = new ReceiveEventArgs();
                                if (msg.Length == 5)
                                {
                                    e.LineID        = int.Parse(msg[0]);
                                    e.Message       = msg[1];
                                    e.PerformanceID = msg[2];
                                    e.IsCompleted   = bool.Parse(msg[3]);
                                    e.QtyImport     = int.Parse(msg[4]);
                                }
                                else if (msg.Length == 3)
                                {
                                    e.LineID      = int.Parse(msg[0]);
                                    e.Message     = msg[1];
                                    e.IsCompleted = bool.Parse(msg[2]);
                                }

                                if (e.Message != null)
                                {
                                    Debug.WriteLine(msg[0]);
                                    if (Received != null)
                                    {
                                        Received?.Invoke(this, e);
                                    }
                                }
                            }
                        }
                    }
                }
            }


            catch (Exception ex)
            {
                WriteLog(ex);
                ErrorMessage(ex);
            }
        }