private void OrderForm_Load(object sender, EventArgs e)
        {
            ClearForm();

            for (int i = 1; i <= 3; i++)
            {
                Ducks d = new Ducks()
                {
                    id_duck = i
                };

                Service1Client service = new Service1Client();
                if (i == 1)
                {
                    lbl_InStockRed.Text = service.GetDucksInStock(d).ToString();
                    lbl_PriceRed.Text   = service.GetDucksPrice(d).ToString();
                }

                if (i == 2)
                {
                    lbl_InStockGreen.Text = service.GetDucksInStock(d).ToString();
                    lbl_PriceGreen.Text   = service.GetDucksPrice(d).ToString();
                }
                if (i == 3)
                {
                    lbl_InStockBlack.Text = service.GetDucksInStock(d).ToString();
                    lbl_PriceBlack.Text   = service.GetDucksPrice(d).ToString();
                }
            }

            numUpDown_Red.Maximum   = Convert.ToDecimal(lbl_InStockRed.Text);
            numUpDown_Green.Maximum = Convert.ToDecimal(lbl_InStockGreen.Text);
            numUpDown_Black.Maximum = Convert.ToDecimal(lbl_InStockBlack.Text);
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            var ducks = new Ducks()
            {
                new Duck(17, Duck.KindOfDuck.Mallard),
                new Duck(18, Duck.KindOfDuck.Muscovy),
                new Duck(14, Duck.KindOfDuck.Decoy),
                new Duck(11, Duck.KindOfDuck.Muscovy),
                new Duck(14, Duck.KindOfDuck.Mallard),
                new Duck(13, Duck.KindOfDuck.Decoy),
            };

            Console.WriteLine(ducks);
            Console.WriteLine("\n");

            Console.WriteLine("Using CompareTo..............................\n");
            ducks.Sort();
            Console.WriteLine(ducks);

            Console.WriteLine("Using DuckComparer SizeThenKind..............................\n");
            DuckComparer comparer = new DuckComparer(DuckComparer.SortCriteria.SizeThenKind);
            ducks.Sort(comparer);
            Console.WriteLine(ducks);

            Console.WriteLine("Using DuckComparer KindThenSize..............................\n");
            comparer.SortCriterion = DuckComparer.SortCriteria.KindThenSize;
            ducks.Sort(comparer);
            Console.WriteLine(ducks);

            Console.ReadKey();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var cityDuck = new Ducks(new SimpleFly(), new LoudQuack());

            cityDuck.Fly();
            cityDuck.Quack();
            Console.ReadKey();
        }
        public long DucksLeased(int i)
        {
            Ducks d = new Ducks()
            {
                id_duck = i
            };

            Service1Client service = new Service1Client();

            return(service.GetDucksLeased(d));
        }
Beispiel #5
0
        private void btn_Delete_Click(object sender, EventArgs e)
        {
            if (tabControl.SelectedIndex == 0)
            {
                int n = dGV_Orders.CurrentRow.Index;

                Orders o = new Orders();
                o.id_order          = Convert.ToInt32(dGV_Orders.Rows[n].Cells[2].Value.ToString());
                o.number_red_duck   = Convert.ToInt32(dGV_Orders.Rows[n].Cells[5].Value.ToString());
                o.number_green_duck = Convert.ToInt32(dGV_Orders.Rows[n].Cells[4].Value.ToString());
                o.number_black_duck = Convert.ToInt32(dGV_Orders.Rows[n].Cells[3].Value.ToString());

                OrderDuck od = new OrderDuck();
                od.id_order = Convert.ToInt32(dGV_Orders.Rows[n].Cells[2].Value.ToString());

                Ducks d = new Ducks();

                Service1Client service = new Service1Client();

                if (o.number_red_duck > 0)
                {
                    d.id_duck         = 1;
                    d.number_in_stock = service.GetDucksInStock(d) + o.number_red_duck;
                    d.number_leased   = service.GetDucksLeased(d) - o.number_red_duck;
                    service.UpdateDuck(d);
                }

                if (o.number_green_duck > 0)
                {
                    d.id_duck         = 2;
                    d.number_in_stock = service.GetDucksInStock(d) + o.number_green_duck;
                    d.number_leased   = service.GetDucksLeased(d) - o.number_green_duck;
                    service.UpdateDuck(d);
                }

                if (o.number_black_duck > 0)
                {
                    d.id_duck         = 3;
                    d.number_in_stock = service.GetDucksInStock(d) + o.number_black_duck;
                    d.number_leased   = service.GetDucksLeased(d) - o.number_black_duck;
                    service.UpdateDuck(d);
                }

                service.DeleteOrderDuck(od);
                service.DeleteOrder(o);

                UpdateDataOrders();
                UpdateDataDucks();
            }
        }
Beispiel #6
0
        public static void Main(string[] args)
        {
            Ducks[] duck = new Ducks[151];
            for (int i = 0; i <= chern; i++)
            {
                duck[i]          = new Ducks();
                duck[i].swim     = true;
                duck[i].name     = "Чернетти";
                duck[i].lake     = 1;
                duck[i].characht = "Имя: Бобби, Вес: 3.5кг, Форма клюва: плоская, Возраст: 10 лет";
                duck[i].caught   = 0;
                duck[i].num      = i + 1;
            }
            for (int i = chern; i <= chern + nir; i++)
            {
                duck[i]          = new Ducks();
                duck[i].swim     = true;
                duck[i].home     = true;
                duck[i].name     = "Нырки";
                duck[i].lake     = 1;
                duck[i].characht = "Имя: Робби, Вес: 3.2кг, Форма клюва: круглая, Возраст: 9 лет";
                duck[i].caught   = 0;
                duck[i].num      = i + 1;
            }
            for (int i = chern + nir; i <= chern + nir + krya; i++)
            {
                duck[i]          = new Ducks();
                duck[i].run      = true;
                duck[i].name     = "Кряква";
                duck[i].lake     = 1;
                duck[i].characht = "Имя: Добби, Вес: 3.6кг, Форма клюва: острая, Возраст: 5 лет";
                duck[i].caught   = 0;
                duck[i].num      = i + 1;
            }
            for (int i = chern + nir + krya; i <= chern + nir + krya + chern2; i++)
            {
                duck[i]          = new Ducks();
                duck[i].swim     = true;
                duck[i].home     = true;
                duck[i].name     = "Чернетти";
                duck[i].lake     = 2;
                duck[i].characht = "Имя: Тобби, Вес: 2.9кг, Форма клюва: кривая, Возраст: 12 лет";
                duck[i].caught   = 0;
                duck[i].num      = i + 1;
            }
            for (int i = chern + nir + krya + chern2; i <= chern + nir + krya + chern2 + kamen; i++)
            {
                duck[i]          = new Ducks();
                duck[i].fly      = true;
                duck[i].home     = true;
                duck[i].name     = "Каменушки";
                duck[i].lake     = 2;
                duck[i].characht = "Имя: Робби, Вес: 4кг, Форма клюва: сплюснутая, Возраст: 7 лет";
                duck[i].caught   = 0;
                duck[i].num      = i + 1;
            }
            for (int i = chern + nir + krya + chern2 + kamen; i < 151; i++)
            {
                duck[i]          = new Ducks();
                duck[i].fish     = true;
                duck[i].name     = "Чирок";
                duck[i].lake     = 2;
                duck[i].characht = "Имя: Коллин, Вес: 3.8кг, Форма клюва: закругленная, Возраст: 9 лет";
                duck[i].caught   = 0;
                duck[i].num      = i + 1;
            }

            int lake1     = 0;
            int swimming1 = 0;
            int flying1   = 0;
            int running1  = 0;
            int fishing1  = 0;

            int lake2     = 0;
            int swimming2 = 0;
            int flying2   = 0;
            int running2  = 0;
            int fishing2  = 0;


            Console.WriteLine($"Чернетти: {chern}");
            Console.WriteLine($"Нырки: {nir}");
            Console.WriteLine($"Кряква: {krya}");
            Console.WriteLine($"Чернетти: {chern2}");
            Console.WriteLine($"Каменушки: {kamen}");
            Console.WriteLine($"Чирок: {chir}");

            Console.WriteLine("Выберите номер утки, чтобы узнать о ней. Если хотите начать сезон охоты, введите 152");
            int var = Convert.ToInt32(Console.ReadLine());

            while (var != 152)
            {
                var = var - 1;
                duck[var].GetInfo();
                var = Convert.ToInt32(Console.ReadLine()); +
            } //утки рассказывают о себе
            if (var == 152)
            {
                int daynum = 1;
                for (int day = 1; day <= 7; day++)
                {
                    Console.WriteLine($"День {daynum}");
                    daynum = daynum + 1;

                    for (int k = 0; k < 151; k++)
                    {
                        if (duck[k].lake == 1)
                        {
                            lake1 = lake1 + 1;
                            if (duck[k].swim == true)
                            {
                                swimming1 = swimming1 + 1;
                            }
                            if (duck[k].fly == true)
                            {
                                flying1 = flying1 + 1;
                            }
                            if (duck[k].run == true)
                            {
                                running1 = running1 + 1;
                            }
                            if (duck[k].fish == true)
                            {
                                fishing1 = fishing1 + 1;
                            }
                        } //подсчет уток
                        if (duck[k].lake == 2)
                        {
                            lake2 = lake2 + 1;
                            if (duck[k].swim == true)
                            {
                                swimming2 = swimming2 + 1;
                            }
                            if (duck[k].fly == true)
                            {
                                flying2 = flying2 + 1;
                            }
                            if (duck[k].run == true)
                            {
                                running2 = running2 + 1;
                            }
                            if (duck[k].fish == true)
                            {
                                fishing2 = fishing2 + 1;
                            }
                        }
                    }
                    Console.WriteLine($"На первом озере - {lake1}"); //вывод озер
                    Console.WriteLine($"Плавающих - {swimming1}");
                    Console.WriteLine($"Летающих - {flying1}");
                    Console.WriteLine($"Бегающих - {running1}");
                    Console.WriteLine($"Рыбачащих - {fishing1}");
                    Console.WriteLine("----------------------------------"); //разделитель
                    Console.WriteLine($"На втором озере - {lake2}");
                    Console.WriteLine($"Плавающих - {swimming2}");
                    Console.WriteLine($"Летающих - {flying2}");
                    Console.WriteLine($"Бегающих - {running2}");
                    Console.WriteLine($"Рыбачащих - {fishing2}");
                    Console.WriteLine("----------------------------------"); //разделитель


                    int hunt  = rnd.Next(1, 8); //охотники первой фермы
                    int hunt2 = rnd.Next(3, 5);
                    Console.WriteLine($"Охотники 1-й фермы поймали {hunt + hunt2}");

                    for (int i = 1; i <= hunt; i++)
                    {
                        int popal = rnd.Next(1, 151);
                        if (duck[popal].lake == 3 && duck[popal].lake == 4)
                        {
                            while (duck[popal].lake == 3 && duck[popal].lake == 4)
                            {
                                popal = rnd.Next(1, 151);
                            }
                        }
                        duck[popal].lake   = 3;
                        duck[popal].caught = duck[popal].caught + 1;
                    }

                    for (int i = 1; i <= hunt2; i++)
                    {
                        int popal2 = rnd.Next(1, 151);
                        if (duck[popal2].lake == 3 && duck[popal2].lake == 4)
                        {
                            while (duck[popal2].lake == 3 && duck[popal2].lake == 4)
                            {
                                popal2 = rnd.Next(1, 151);
                            }
                        }
                        duck[popal2].lake   = 3;
                        duck[popal2].caught = duck[popal2].caught + 1;
                    }


                    int hunt3 = rnd.Next(1, 7); //охотники второй фермы
                    int hunt4 = rnd.Next(3, 9);
                    Console.WriteLine($"Охотники 2-й фермы поймали {hunt3 + hunt4}");

                    for (int i = 1; i <= hunt; i++)
                    {
                        int popal3 = rnd.Next(1, 151);
                        if (duck[popal3].lake == 3 && duck[popal3].lake == 4)
                        {
                            while (duck[popal3].lake == 3 && duck[popal3].lake == 4)
                            {
                                popal3 = rnd.Next(1, 151);
                            }
                        }
                        duck[popal3].lake   = 4;
                        duck[popal3].caught = duck[popal3].caught + 1;
                    }

                    for (int i = 1; i <= hunt2; i++)
                    {
                        int popal4 = rnd.Next(1, 151);
                        if (duck[popal4].lake == 3 && duck[popal4].lake == 4)
                        {
                            while (duck[popal4].lake == 3 && duck[popal4].lake == 4)
                            {
                                popal4 = rnd.Next(1, 151);
                            }
                        }
                        duck[popal4].lake   = 4;
                        duck[popal4].caught = duck[popal4].caught + 1;
                    }

                    for (int i = 0; i < 151; i++) //побег с фермы
                    {
                        if (duck[i].lake == 3)
                        {
                            if (duck[i].fly == true && duck[i].home == true && duck[i].caught < 2)
                            {
                                duck[i].lake = rnd.Next(1, 2);
                            }
                        }
                        if (duck[i].lake == 4)
                        {
                            if (duck[i].swim == true && duck[i].home == false && duck[i].caught < 2)
                            {
                                duck[i].lake = rnd.Next(1, 2);
                            }
                        }
                    }

                    int farm1 = 0;
                    int farm2 = 0;

                    for (int i = 0; i < 151; i++)
                    {
                        if (duck[i].lake == 3)
                        {
                            farm1 = farm1 + 1;
                        }

                        if (duck[i].lake == 4)
                        {
                            farm2 = farm2 + 1;
                        }
                    } //подсчет кол-ва на фермах
                    Console.WriteLine("----------------------------------"); //разделитель
                    Console.WriteLine($"На ферме 1 - {farm1}");
                    Console.WriteLine($"На ферме 2 - {farm2}");
                    Console.WriteLine("----------------------------------"); //разделитель
                    Console.WriteLine("Нажмите любую кнопку, чтобы продолжить");

                    lake1     = 0;
                    lake2     = 0;
                    swimming1 = 0;
                    swimming2 = 0;
                    flying1   = 0;
                    flying2   = 0;
                    running1  = 0;
                    running2  = 0;
                    fishing1  = 0;
                    fishing2  = 0;

                    Console.ReadKey();
                }
            }
        }
        private void btn_OK_Click(object sender, EventArgs e)
        {
            if (sp.Price(dTP_DateExpiration.Value, dTP_DateBeginning.Value, numUpDown_Red.Value, numUpDown_Green.Value, numUpDown_Black.Value, lbl_PriceRed.Text, lbl_PriceGreen.Text, lbl_PriceBlack.Text) > 0)
            {
                Service1Client service = new Service1Client();

                Orders o = new Orders();
                o.date_beginning    = dTP_DateBeginning.Value;
                o.date_expiration   = dTP_DateExpiration.Value;
                o.price             = sp.Price(dTP_DateExpiration.Value, dTP_DateBeginning.Value, numUpDown_Red.Value, numUpDown_Green.Value, numUpDown_Black.Value, lbl_PriceRed.Text, lbl_PriceGreen.Text, lbl_PriceBlack.Text);
                o.number_red_duck   = Convert.ToInt64(numUpDown_Red.Value);
                o.number_green_duck = Convert.ToInt64(numUpDown_Green.Value);
                o.number_black_duck = Convert.ToInt64(numUpDown_Black.Value);

                bool d_red_ok   = false,
                     d_green_ok = false,
                     d_black_ok = false;

                if (cBx_Red.Checked)
                {
                    Ducks d_red = new Ducks();
                    d_red.id_duck         = 1;
                    d_red.number_in_stock = Convert.ToInt64(lbl_InStockRed.Text) - Convert.ToInt64(numUpDown_Red.Value);
                    long duck_leased = sp.DucksLeased(1);
                    d_red.number_leased = duck_leased + Convert.ToInt64(numUpDown_Red.Value);
                    service.UpdateDuck(d_red);
                    d_red_ok = true;
                }

                if (cBx_Green.Checked)
                {
                    Ducks d_green = new Ducks();
                    d_green.id_duck         = 2;
                    d_green.number_in_stock = Convert.ToInt64(lbl_InStockGreen.Text) - Convert.ToInt64(numUpDown_Green.Value);
                    long duck_leased = sp.DucksLeased(2);
                    d_green.number_leased = duck_leased + Convert.ToInt64(numUpDown_Green.Value);
                    service.UpdateDuck(d_green);
                    d_green_ok = true;
                }

                if (cBx_Black.Checked)
                {
                    Ducks d_black = new Ducks();
                    d_black.id_duck         = 3;
                    d_black.number_in_stock = Convert.ToInt64(lbl_InStockBlack.Text) - Convert.ToInt64(numUpDown_Black.Value);
                    long duck_leased = sp.DucksLeased(3);
                    d_black.number_leased = duck_leased + Convert.ToInt64(numUpDown_Black.Value);
                    service.UpdateDuck(d_black);
                    d_black_ok = true;
                }

                if (service.InsertOrder(o) == 1)
                {
                    OrderDuck od = new OrderDuck();

                    if (d_red_ok)
                    {
                        od.id_order = service.MaxOrderId();
                        od.id_duck  = 1;

                        service.InsertOrderDuck(od);
                    }

                    if (d_green_ok)
                    {
                        od.id_order = service.MaxOrderId();
                        od.id_duck  = 2;

                        service.InsertOrderDuck(od);
                    }

                    if (d_black_ok)
                    {
                        od.id_order = service.MaxOrderId();
                        od.id_duck  = 3;

                        service.InsertOrderDuck(od);
                    }

                    MessageBox.Show("Заказ добавлен.");
                    DialogResult = DialogResult.OK;
                }
            }
            else
            {
                MessageBox.Show("Заказ составлен неверно.");
            }
        }
        private void btn_OK_Click(object sender, EventArgs e)
        {
            if (sp.Price(dTP_DateExpiration.Value, dTP_DateBeginning.Value, numUpDown_Red.Value, numUpDown_Green.Value, numUpDown_Black.Value, lbl_PriceRed.Text, lbl_PriceGreen.Text, lbl_PriceBlack.Text) > 0)
            {
                Service1Client service = new Service1Client();

                Orders o = new Orders();
                o.id_order          = id_order;
                o.date_beginning    = dTP_DateBeginning.Value;
                o.date_expiration   = dTP_DateExpiration.Value;
                o.price             = sp.Price(dTP_DateExpiration.Value, dTP_DateBeginning.Value, numUpDown_Red.Value, numUpDown_Green.Value, numUpDown_Black.Value, lbl_PriceRed.Text, lbl_PriceGreen.Text, lbl_PriceBlack.Text);
                o.number_red_duck   = Convert.ToInt64(numUpDown_Red.Value);
                o.number_green_duck = Convert.ToInt64(numUpDown_Green.Value);
                o.number_black_duck = Convert.ToInt64(numUpDown_Black.Value);

                Ducks d_red = new Ducks();
                d_red.id_duck         = 1;
                d_red.number_in_stock = Convert.ToInt64(lbl_InStockRed.Text) + number_red_duck - Convert.ToInt64(numUpDown_Red.Value);
                long duck_leased = sp.DucksLeased(1);
                d_red.number_leased = duck_leased - number_red_duck + Convert.ToInt64(numUpDown_Red.Value);
                service.UpdateDuck(d_red);

                Ducks d_green = new Ducks();
                d_green.id_duck         = 2;
                d_green.number_in_stock = Convert.ToInt64(lbl_InStockGreen.Text) + number_green_duck - Convert.ToInt64(numUpDown_Green.Value);
                duck_leased             = sp.DucksLeased(2);
                d_green.number_leased   = duck_leased - number_green_duck + Convert.ToInt64(numUpDown_Green.Value);
                service.UpdateDuck(d_green);

                Ducks d_black = new Ducks();
                d_black.id_duck         = 3;
                d_black.number_in_stock = Convert.ToInt64(lbl_InStockBlack.Text) + number_black_duck - Convert.ToInt64(numUpDown_Black.Value);
                duck_leased             = sp.DucksLeased(3);
                d_black.number_leased   = duck_leased - number_black_duck + Convert.ToInt64(numUpDown_Black.Value);
                service.UpdateDuck(d_black);

                service.UpdateOrder(o);
                OrderDuck od = new OrderDuck();

                if (cBx_Red.Checked != d_red_ok_initially)
                {
                    od.id_order = o.id_order;
                    od.id_duck  = 1;

                    if (cBx_Red.Checked)
                    {
                        service.InsertOrderDuck(od);
                    }
                    else
                    {
                        service.DeleteOrderDuck(od);
                    }
                }

                if (cBx_Green.Checked != d_green_ok_initially)
                {
                    od.id_order = o.id_order;
                    od.id_duck  = 2;

                    if (cBx_Green.Checked)
                    {
                        service.InsertOrderDuck(od);
                    }
                    else
                    {
                        service.DeleteOrderDuck(od);
                    }
                }

                if (cBx_Black.Checked != d_black_ok_initially)
                {
                    od.id_order = o.id_order;
                    od.id_duck  = 3;

                    if (cBx_Black.Checked)
                    {
                        service.InsertOrderDuck(od);
                    }
                    else
                    {
                        service.DeleteOrderDuck(od);
                    }
                }

                MessageBox.Show("Заказ отредактирован.");
                DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("Заказ составлен неверно.");
            }
        }
        private void EditOrderForm_Load(object sender, EventArgs e)
        {
            ClearForm();

            Orders o = new Orders();

            o.id_order = id_order;
            Service1Client service = new Service1Client();

            numUpDown_Red.Value   = service.GetNumberDuck(o, "number_red_duck");
            number_red_duck       = Convert.ToInt64(numUpDown_Red.Value);
            numUpDown_Green.Value = service.GetNumberDuck(o, "number_green_duck");
            number_green_duck     = Convert.ToInt64(numUpDown_Green.Value);
            numUpDown_Black.Value = service.GetNumberDuck(o, "number_black_duck");
            number_black_duck     = Convert.ToInt64(numUpDown_Black.Value);

            dTP_DateBeginning.Value  = service.GetDateOrder(o, "date_beginning");
            dTP_DateExpiration.Value = service.GetDateOrder(o, "date_expiration");

            if (numUpDown_Red.Value > 0)
            {
                numUpDown_Red.Enabled = true;
                cBx_Red.Checked       = true;
                d_red_ok_initially    = true;
            }

            if (numUpDown_Green.Value > 0)
            {
                numUpDown_Green.Enabled = true;
                cBx_Green.Checked       = true;
                d_green_ok_initially    = true;
            }

            if (numUpDown_Black.Value > 0)
            {
                numUpDown_Black.Enabled = true;
                cBx_Black.Checked       = true;
                d_black_ok_initially    = true;
            }

            for (int i = 1; i <= 3; i++)
            {
                Ducks d = new Ducks()
                {
                    id_duck = i
                };

                if (i == 1)
                {
                    lbl_InStockRed.Text = service.GetDucksInStock(d).ToString();
                    lbl_PriceRed.Text   = service.GetDucksPrice(d).ToString();
                }

                if (i == 2)
                {
                    lbl_InStockGreen.Text = service.GetDucksInStock(d).ToString();
                    lbl_PriceGreen.Text   = service.GetDucksPrice(d).ToString();
                }
                if (i == 3)
                {
                    lbl_InStockBlack.Text = service.GetDucksInStock(d).ToString();
                    lbl_PriceBlack.Text   = service.GetDucksPrice(d).ToString();
                }
            }

            numUpDown_Red.Maximum   = Convert.ToDecimal(lbl_InStockRed.Text);
            numUpDown_Green.Maximum = Convert.ToDecimal(lbl_InStockGreen.Text);
            numUpDown_Black.Maximum = Convert.ToDecimal(lbl_InStockBlack.Text);
        }