示例#1
0
        private void ReceiveMessage()
        {
            //UdpClient
            receiver = new UdpClient(12345); // UdpClient для получения данных
            IPEndPoint remoteIp = null;      // адрес входящего подключения

            try
            {
                while (runung)
                {
                    byte[] data    = receiver.Receive(ref remoteIp); // получаем данные
                    string message = Encoding.UTF8.GetString(data);
                    //Console.WriteLine("Собеседник: {0}", message);
                    CustomerScreen customerScreen = JsonConvert.DeserializeObject <CustomerScreen>(message);
                    DataTable      dataTable      = new DataTable();
                    dataTable.Columns.Add("Наименование");
                    dataTable.Columns.Add("Количество", new Int32().GetType());
                    dataTable.Columns.Add("Цена", new Decimal().GetType());
                    foreach (CheckPosition checkPosition in customerScreen.ListCheckPositions)
                    {
                        DataRow row = dataTable.NewRow();
                        row[0] = checkPosition.NamePosition;
                        row[1] = checkPosition.Quantity;
                        row[2] = checkPosition.Price;
                        dataTable.Rows.Add(row);
                    }
                    load_datain_datagrid(dataTable);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (receiver != null)
                {
                    receiver.Close();
                }
            }
        }
示例#2
0
        public static void MainMenu()
        {
            IScreen _screen = null;
            string  consoleVal;

            string[] menuItems = new string[] { "1-Car Manager", "2-Brand Manager", "3-Color Manager",
                                                "4-User Manager", "5-Customer Manager", "6-Rental Manager", "7-Settings", "8-EXIT" };
            ConsoleTexts.WriteConsoleMenuInFrame(Messages.MainMenuTitle, menuItems);

            consoleVal = ConsoleTexts.ConsoleWriteReadLine(Messages.SelectNumberOfMenuItem);
            if (consoleVal == "")
            {
                consoleVal = "0";
            }
            int selected = Convert.ToInt32(consoleVal);

            switch (selected)
            {
            case 1:
                _screen = new CarScreen(GetCarManager().Data);
                break;

            case 2:
                _screen = new BrandScreen(GetBrandManager().Data);
                break;

            case 3:
                _screen = new ColorScreen(GetColorManager().Data);
                break;

            case 4:
                _screen = new UserScreen(GetUserManager().Data);
                break;

            case 5:
                _screen = new CustomerScreen(GetCustomerManager().Data);
                break;

            case 6:
                _screen = new RentalScreen(GetRentalManager().Data);
                break;

            case 7:
                //SettingMenu();
                //MainMenu();
                break;

            case 8:
                Environment.Exit(0);
                break;

            default:
                Console.WriteLine(Messages.WrongChoice);
                MainMenu();
                break;
            }
            if (_screen != null)
            {
                _screen.Menu();
            }
            MainMenu();
        }