示例#1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Begin server");

            IPEndPoint tcpEndPoint = new IPEndPoint(IPAddress.Any, port);
            Socket     tcpSocket   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            tcpSocket.Bind(tcpEndPoint);
            tcpSocket.Listen(backlog);

            while (true)
            {
                Socket        Listener = tcpSocket.Accept();
                StringBuilder data     = tcpGetData(Listener);
                string        CodeName = Code.GetCode(data.ToString());

                switch (CodeName)
                {
                case Code.login:
                    Login login = new Login(Listener, data.ToString());
                    login.Result();
                    break;

                case Code.exit:
                    Exit exit = new Exit(Listener, data.ToString());
                    exit.Result();
                    break;

                case Code.ArchCostAvg:
                    ArCostAvg arCostAvg = new ArCostAvg(Listener, data.ToString());
                    arCostAvg.Result();
                    break;

                case Code.ManEnBet:
                    ManEnergyBetween manEnergyBetween = new ManEnergyBetween(Listener, data.ToString());
                    manEnergyBetween.Result();
                    break;

                case Code.ManMemEaYe:
                    ManMemEachYear manMemEachYear = new ManMemEachYear(Listener, data.ToString());
                    manMemEachYear.Result();
                    break;
                }

                Listener.Shutdown(SocketShutdown.Both);
                Listener.Close();
            }

            Console.WriteLine("End server");
            Console.ReadLine();
        }
        private void Ready_Click(object sender, RoutedEventArgs e)
        {
            string path       = @Path.Text;
            bool   checkPath0 = (path != "");
            bool   checkPath1 = checkPath0? path[path.Length - 1] == '\\': false;

            if (checkPath0 && checkPath1)
            {
                switch (QueriesTab.SelectedIndex)
                {
                case 0:
                    InpArchCostAvg data;
                    bool           check0 = Code.CheckSQL(ArchNameSQL1.Text);
                    if (check0)
                    {
                        data.Arch = ArchNameSQL1.Text;
                        using (AvgCostArch avgCostArch = new AvgCostArch(data, User.Text, path))
                        {
                            avgCostArch.Result();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Неправильный формат заданных данных");
                    }
                    break;

                case 1:
                    InpManEnergBeetw data1;
                    data1.ManName = ManufactNameSQL2.Text;
                    bool check11 = Int32.TryParse(MinEnergySQL2.Text, out data1.MinEnerg);
                    bool check12 = Int32.TryParse(MaxEnergySQL2.Text, out data1.MaxEnerg);
                    bool check13 = Code.CheckSQL(ManufactNameSQL2.Text);

                    if (check11 && check12 && check13)
                    {
                        using (ManEnergyBetween manEnergyBetween = new ManEnergyBetween(data1, User.Text, path))
                        {
                            manEnergyBetween.Result();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Неправильный формат заданных данных");
                    }
                    break;

                case 2:
                    InpManMemEachYear data2;
                    data2.ManName = ManufactNameSQL3.Text;
                    bool check21 = Code.CheckSQL(ManufactNameSQL3.Text);
                    if (check21)
                    {
                        using (ManMemEachYear manMemEachYear = new ManMemEachYear(data2, User.Text, path))
                        {
                            manMemEachYear.Result();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Неправильный формат заданных данных");
                    }
                    break;
                }
            }
            else
            {
                MessageBox.Show("Неправильно указан путь");
            }
        }