예제 #1
0
        private void Send_Receive(string barcode)
        {
            FormMenu fm = (FormMenu)this.Owner;

            try
            {
                TcpClient    client = new TcpClient(Z_mXML.ServerIP, Convert.ToInt32(Z_mXML.ServerPort));
                Stream       s      = client.GetStream();
                StreamReader sr     = new StreamReader(s);
                StreamWriter sw     = new StreamWriter(s);
                sw.AutoFlush = true;
                Z_TSD_Message ztm = new Z_TSD_Message(Z_mXML.DeviceId, Z_mXML.ActionNumber, barcode);
                sw.WriteLine(ztm.ToString(Z_mXML.Separator));
                string server_answer = sr.ReadLine();
                if (server_answer.StartsWith("#QUERYGROUP"))
                {
                    server_answer = server_answer.Substring(11);
                    FillComboBox(GroupDefCB, server_answer, Z_mXML.Separator);
                    GroupDefCB.SelectedIndex = 0;
                }
                else
                if (server_answer.StartsWith("#QUERYLIST"))
                {
                    server_answer = server_answer.Substring(10);
                    FillComboBox(TypeDefCB, server_answer, Z_mXML.Separator);
                    TypeDefCB.SelectedIndex = 0;
                }
                else
                if (server_answer.StartsWith("#LOADLOC"))
                {
                    server_answer = server_answer.Substring(8);
                    FillComboBox(LocCB, server_answer, Z_mXML.Separator);
                    LocCB.SelectedIndex = Z_mXML.Location;
                }
                else
                {
                    AnswerTB.Text = server_answer;
                }

                s.Close();
                client.Close();
            }
            catch
            {
                MessageBox.Show("Потеряна связь с серверным приложением.", "Ошибка");
            }
        }
예제 #2
0
        private void Send_Receive(string barcode)
        {
            try
            {
                IPEndPoint localEP = new IPEndPoint(IPAddress.Parse(Z_mXML.ServerIP), Convert.ToInt32(Z_mXML.ServerPort));
                TcpClient  client  = new TcpClient();
                client.Connect(localEP);
                Stream       s  = client.GetStream();
                StreamReader sr = new StreamReader(s);
                StreamWriter sw = new StreamWriter(s);
                sw.AutoFlush = true;
                Z_TSD_Message ztm = new Z_TSD_Message(Z_mXML.DeviceId, Z_mXML.ActionNumber, barcode);
                sw.WriteLine(ztm.ToString(Z_mXML.Separator));
                string        server_answer = sr.ReadLine();
                Z_TSD_Message answer        = Z_TSD_Message.ToParams(server_answer, '|');
                AnswerTB.Text = answer[0].Replace(";", "\r\n");
                CountTB.Text  = answer[1];
                SumTB.Text    = answer[2];

                if (server_answer.IndexOf('!') != -1 && objNotify != null)
                {
                    objNotify.State = Symbol.Notification.NotifyState.ON;
                    System.Threading.Thread.Sleep(300);
                    objNotify.State = Symbol.Notification.NotifyState.OFF;
                    System.Threading.Thread.Sleep(200);
                    objNotify.State = Symbol.Notification.NotifyState.ON;
                    System.Threading.Thread.Sleep(300);
                    objNotify.State = Symbol.Notification.NotifyState.OFF;
                }
                s.Close();
                client.Close();
            }
            catch
            {
                MessageBox.Show("Потеряна связь с серверным приложением.", "Ошибка");
            }
        }