Esempio n. 1
0
File: Form1.cs Progetto: AtanasK/VP
 private void btnAddAuto_Click(object sender, EventArgs e)
 {
     if (cbMarka.SelectedIndex == -1)
     {
         MessageBox.Show("Изберете марка");
         return;
     }
     if (tbModel.Text.Trim().Length <= 0)
     {
         MessageBox.Show("Внесете модел");
         return;
     }
     Avtomobil avto = new Avtomobil();
     avto.Marka = cbMarka.SelectedItem as Marka;
     avto.Model = tbModel.Text;
     avto.Potrosuvacka = (double)nudPotrosuvacka.Value;
     avto.Cena = (int)nudCena.Value;
     lbAutos.Items.Add(avto);
     cbMarka.SelectedIndex = -1;
     tbModel.Clear();
     nudCena.Value = 0;
     nudCena.ResetText();
     nudPotrosuvacka.Value = 0;
     nudPotrosuvacka.ResetText();
     presmetaj();
 }
Esempio n. 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            Avtomobil avtomobil = db.Avtomobils.Find(id);

            db.Avtomobils.Remove(avtomobil);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
 public ActionResult Edit([Bind(Include = "Id,MarkaId,TypeId,Number,Date,Garage,Glonass")] Avtomobil avtomobil)
 {
     if (ModelState.IsValid)
     {
         db.Entry(avtomobil).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MarkaId = new SelectList(db.MarkaAvtomobils, "Id", "Name", avtomobil.MarkaId);
     ViewBag.TypeId  = new SelectList(db.TypeAvtos, "Id", "Type", avtomobil.TypeId);
     return(View(avtomobil));
 }
Esempio n. 4
0
        // GET: Avtomobils/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Avtomobil avtomobil = db.Avtomobils.Find(id);

            if (avtomobil == null)
            {
                return(HttpNotFound());
            }
            return(View(avtomobil));
        }
Esempio n. 5
0
        // GET: Avtomobils/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Avtomobil avtomobil = db.Avtomobils.Find(id);

            if (avtomobil == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MarkaId = new SelectList(db.MarkaAvtomobils, "Id", "Name", avtomobil.MarkaId);
            ViewBag.TypeId  = new SelectList(db.TypeAvtos, "Id", "Type", avtomobil.TypeId);
            return(View(avtomobil));
        }
Esempio n. 6
0
        public ActionResult Create([Bind(Include = "Id,MarkaId,TypeId,Number,Date,Garage,Glonass")] Avtomobil avtomobil)
        {
            if (ModelState.IsValid)
            {
                if (avtomobil.Garage == null)
                {
                    avtomobil.Garage = 0;
                }
                db.Avtomobils.Add(avtomobil);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MarkaId = new SelectList(db.MarkaAvtomobils, "Id", "Name", avtomobil.MarkaId);
            ViewBag.TypeId  = new SelectList(db.TypeAvtos, "Id", "Type", avtomobil.TypeId);
            return(View(avtomobil));
        }
Esempio n. 7
0
        public ActionResult AddAvto([Bind(Include = "Number,TypeId,MarkaId,ObiemBunkera,KoefficientSgatiya,KontrAgentId")] Avtomobil A)
        {
            A.Date    = DateTime.Now.Year;
            A.Glonass = false;
            A.Garage  = 0;
            A.GKHNNC  = false;
            A.Number  = A.Number.ToUpper().Replace(" ", "");
            try
            {
                A = db.Avtomobils.Where(x => x.Number.Replace(" ", "").Equals(A.Number)).Include(x => x.Type).First();
                ViewBag.Number          = A.Number;
                ViewBag.TypeAvtos       = new SelectList(db.TypeAvtos, "Id", "Type");
                ViewBag.MarkaAvtomobils = new SelectList(db.MarkaAvtomobils.OrderBy(x => x.Name), "Id", "Name");
                ViewBag.Numbers         = A;
                ViewBag.AvtoType        = A.Type.Type;
                ViewBag.AvtoImage       = A.Type.Ico;
                return(RedirectToAction("Index", new { number = A.Number }));
            }
            catch (Exception e)
            {
                //если не нашли по номеру в бд то сохраняем как новый

                try
                {
                    db.Avtomobils.Add(A);
                    db.SaveChanges();
                    ViewBag.Number          = A.Number;
                    ViewBag.TypeAvtos       = new SelectList(db.TypeAvtos, "Id", "Type");
                    ViewBag.MarkaAvtomobils = new SelectList(db.MarkaAvtomobils.OrderBy(x => x.Name), "Id", "Name");
                    ViewBag.Numbers         = A;

                    ViewBag.AvtoType  = db.TypeAvtos.Where(x => x.Id == A.TypeId).Select(x => x.Type).First();
                    ViewBag.AvtoImage = db.MarkaAvtomobils.Where(x => x.Id == A.MarkaId).Select(x => x.Name).First();
                    return(RedirectToAction("Index", new { number = A.Number }));
                }
                catch (Exception f)
                {
                    return(Json(f.Message));
                }
            }



            return(View("Index", new { number = A.Number }));
        }
Esempio n. 8
0
        public void PoligonZamena(Avtomobil Avto, Avtomobil NewAvto)
        {
            List <Poligon> Polig = db.Poligons.Where(x => x.AvtomobilId == Avto.Id).ToList();

            foreach (Poligon P in Polig)
            {
                P.Number      = NewAvto.Number;
                P.TypeId      = NewAvto.TypeId;
                P.MarkaId     = NewAvto.MarkaId;
                P.AvtomobilId = NewAvto.Id;
                try
                {
                    db.Entry(P).State = EntityState.Modified;
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                }
            }
        }
Esempio n. 9
0
        //Ищем номер и обновляем страницу
        public ActionResult NumberAndRefresh(string term)
        {
            if (term != null)
            {
                term = term.ToUpper().Replace(" ", "");

                List <string> Num = new List <string>();
                Avtomobil     A   = new Avtomobil();
                try
                {
                    //пробуем найти автомобиль по номеру
                    //Num = db.Avtomobils.Where(x => x.Number.StartsWith(term)).Select(x => x.Number).ToList();

                    A = db.Avtomobils.Where(x => x.Number.Replace(" ", "").Equals(term)).Include(x => x.Type).First();
                    ViewBag.Number          = A.Number.ToUpper().Replace(" ", "");
                    ViewBag.TypeAvtos       = new SelectList(db.TypeAvtos, "Id", "Type");
                    ViewBag.MarkaAvtomobils = new SelectList(db.MarkaAvtomobils.OrderBy(x => x.Name), "Id", "Name");
                    ViewBag.AvtoType        = A.Type.Type;
                    ViewBag.AvtoImage       = A.Type.Ico;
                    return(RedirectToAction("Index", new { Number = A.Number.ToUpper().Replace(" ", "") }));

                    return(View("Index", db.Poligons.Include(z => z.Avtomobil).Include(x => x.Marka).Include(x => x.Type).ToList()));
                }
                catch
                {
                    ViewBag.Number          = term;
                    ViewBag.TypeAvtos       = new SelectList(db.TypeAvtos, "Id", "Type");
                    ViewBag.MarkaAvtomobils = new SelectList(db.MarkaAvtomobils.OrderBy(x => x.Name), "Id", "Name");
                    ViewBag.AvtoType        = db.TypeAvtos.Where(x => x.Id == 16).Select(x => x.Type).First();
                    ViewBag.AvtoImage       = db.TypeAvtos.Where(x => x.Id == 16).Select(x => x.Ico).First();
                    term = term.ToUpper().Replace(" ", "");
                }
            }
            return(RedirectToAction("Index", new { Number = term }));

            return(View("Index", db.Poligons.Include(z => z.Avtomobil).Include(x => x.Marka).Include(x => x.Type).ToList()));
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            Voznik voznik1 = new Voznik("Tilen", "Cokan", Spol.M, new DateTime(1997, 6, 22), new DateTime(2018, 6, 22));

            Potnik potnik1 = new Potnik("Teja", "Kolar", Spol.Z, new DateTime(1997, 5, 20), "*****@*****.**", Status.Student);

            Potnik potnik2 = new Potnik("Tomaž", "Kolar", Spol.M, new DateTime(1989, 12, 5), "*****@*****.**", Status.Student);

            Potnik potnik3 = new Potnik("Matej", "Kolar", Spol.M, new DateTime(1991, 7, 3), "*****@*****.**", Status.Student);

            Potnik potnik4 = new Potnik("Gregor", "Kranjc", Spol.M, new DateTime(1950, 7, 3), "*****@*****.**", Status.Upokojenec);

            Potnik potnik5 = new Potnik("Urška", "Kranjc", Spol.Z, new DateTime(2005, 5, 3), "*****@*****.**", Status.Otrok);

            Avtomobil avto1 = new Avtomobil(voznik1, "mazda", "limuzina", 5.7, 50, 5, 2);

            Kombi kombi1 = new Kombi(voznik1, "mercedes", "kombi", 9.5, 80, 500, 1000);

            Avtobus bus1 = new Avtobus(voznik1, "MAN", "avtobus", 20, 120, 51, 20, 40);

            Dictionary <string, Potnik> seznamOseb = new Dictionary <string, Potnik>();

            Termin termin1 = new Termin(new DateTime(2018, 5, 10, 6, 0, 0), new DateTime(2018, 5, 19, 23, 0, 0), bus1, seznamOseb);

            Termin termin2 = new Termin(new DateTime(2018, 6, 10, 6, 0, 0), new DateTime(2018, 6, 18, 23, 0, 0), bus1, seznamOseb);

            List <Termin> termini = new List <Termin>();

            Izlet izlet1 = new Izlet("Nizozemska", 480.50, "Celje", termini);

            izlet1.DodajTermin(termin1);

            Izlet izlet2 = new Izlet("Belgija", 600, "Maribor", termini);

            izlet2.DodajTermin(termin2);

            izlet1.ProdajKarto(termin1, potnik1);

            izlet1.ProdajKarto(termin1, potnik2);

            izlet1.ProdajKarto(termin1, potnik3);

            izlet2.ProdajKarto(termin2, potnik4);

            izlet2.ProdajKarto(termin2, potnik5);

            izlet1.PrekličiKarto(termin1, potnik3);

            izlet2.DodajTermin(termin1);


            List <Potnik> potniki = new List <Potnik>();

            Potovanje.preberiSeznamCSV(potniki);

            var poisciKnez = potniki.Find(x => x.priimek.Equals("Knez"));

            Console.WriteLine(poisciKnez.ime + " " + poisciKnez.priimek + " " + poisciKnez.spol + " " + poisciKnez.status + " " + poisciKnez.datumRojstva + " " + poisciKnez.email);
            if (poisciKnez != null)
            {
                potniki.Remove(poisciKnez);
            }

            var poisciNajstarejsoOsebo = potniki.Find(x => x.datumRojstva == potniki.Min(y => y.datumRojstva));

            Console.WriteLine("Najstarejsi potnik: " + poisciNajstarejsoOsebo.ime + " " + poisciNajstarejsoOsebo.priimek + " " + poisciNajstarejsoOsebo.spol + " " + poisciNajstarejsoOsebo.status + " " + poisciNajstarejsoOsebo.datumRojstva + " " + poisciNajstarejsoOsebo.email);
            if (poisciNajstarejsoOsebo != null)
            {
                potniki.Remove(poisciNajstarejsoOsebo);
            }

            var dodajOsebo = new Potnik(potnik1.ime, potnik1.priimek, potnik1.spol, potnik1.datumRojstva, potnik1.email, potnik1.status);

            potniki.Add(dodajOsebo);
            Console.WriteLine(dodajOsebo.MojIzpis());

            Termin terminOtroci     = new Termin(new DateTime(2018, 6, 20, 7, 0, 0), new DateTime(2018, 6, 27, 22, 0, 0), bus1, new Dictionary <string, Potnik>());
            Termin terminStudenti   = new Termin(new DateTime(2018, 7, 20, 7, 0, 0), new DateTime(2018, 6, 27, 22, 0, 0), bus1, new Dictionary <string, Potnik>());
            Termin terminUpokojenci = new Termin(new DateTime(2018, 8, 20, 7, 0, 0), new DateTime(2018, 6, 27, 22, 0, 0), bus1, new Dictionary <string, Potnik>());

            Izlet izlet = new Izlet("Portugalska", 1200, "Celje", new List <Termin> {
                terminOtroci, terminStudenti, terminUpokojenci
            });

            List <Potnik> otroci = potniki.FindAll(x => x.status == Status.Otrok);

            otroci = otroci.OrderBy(x => x.priimek).ToList();
            terminOtroci.PrijavljeniPotniki = otroci.ToDictionary(x => x.email);

            List <Potnik> studenti = potniki.FindAll(y => y.status == Status.Student);

            studenti = studenti.OrderBy(y => y.priimek).ToList();
            terminStudenti.PrijavljeniPotniki = studenti.ToDictionary(y => y.email);

            List <Potnik> upokojenci = potniki.FindAll(z => z.status == Status.Upokojenec);

            upokojenci = upokojenci.OrderBy(z => z.priimek).ToList();
            terminUpokojenci.PrijavljeniPotniki = upokojenci.ToDictionary(z => z.email);

            Potovanje.zapisiVSeznamCSV(izlet);

            double povprečnaStarost = potniki.Average(popotnik => 2018 - popotnik.datumRojstva.Year);

            Console.WriteLine("Povprečna starost potnikov je: {0:0.00}", povprečnaStarost);

            List <Potnik> seznamPonikov = Potovanje.VrniPotnikeGledeNaStatus(Status.Otrok, potniki);

            for (int i = 0; i < seznamPonikov.Count; i++)
            {
                Console.WriteLine(seznamPonikov[i].ime + " " + seznamPonikov[i].priimek + " " + seznamPonikov[i].spol + " " + seznamPonikov[i].datumRojstva + " " + seznamPonikov[i].email + " " + seznamPonikov[i].status);
            }
        }
Esempio n. 11
0
        public ActionResult EditAvto([Bind(Include = "Id,Number,TypeId,MarkaId,ObiemBunkera,KoefficientSgatiya,KontrAgentId,NePuskat")] Avtomobil A)
        {
            A.Date = DateTime.Now.Year;

            A.Number = A.Number.ToUpper().Replace(" ", "");

            Avtomobil Avto    = new Avtomobil();
            Avtomobil NewAvto = new Avtomobil();

            //грузим авто по айдишнику
            try
            {
                Avto = db.Avtomobils.Where(x => x.Id == A.Id).First();
            }
            catch { }
            if (A.Number != "" && A.Number.Length >= 6)//если номер адекватен
            {
                try
                {
                    NewAvto = db.Avtomobils.Where(x => x.Number.Replace(" ", "").Equals(A.Number)).First();
                    if (NewAvto == Avto)//если номер не поменяли то улучшаем этот автомобиль
                    {
                        try
                        {
                            Avtomobil StarAvto = Avto;
                            Avto.TypeId             = A.TypeId;
                            Avto.Type               = db.TypeAvtos.Where(x => x.Id == Avto.TypeId).First();
                            Avto.ObiemBunkera       = A.ObiemBunkera;
                            Avto.MarkaId            = A.MarkaId;
                            Avto.Marka              = db.MarkaAvtomobils.Where(x => x.Id == Avto.MarkaId).First();
                            Avto.KoefficientSgatiya = A.KoefficientSgatiya;
                            Avto.KontrAgentId       = A.KontrAgentId;
                            Avto.NePuskat           = A.NePuskat;
                            db.Entry(Avto).State    = EntityState.Modified;
                            db.SaveChanges();
                            PoligonZamena(StarAvto, Avto);//чтоб картинка в полигонах заменилась
                        }
                        catch (Exception e)
                        {
                        }
                    }
                    else
                    {
                        //если номер поменяли проверим есть ли номер в базе
                        //если номер не поменяли то улучшаем этот автомобиль

                        try
                        {
                            if (User.Identity.Name.Contains("Администратор"))
                            {
                                //Если номер поменяли то тупо меняем все полигональные записи и машину удаляем (соединяем с другой) без учета полей на изменение
                                PoligonZamena(Avto, NewAvto);
                                db.Avtomobils.Remove(Avto);
                                db.SaveChanges();
                                Avto = NewAvto;
                            }
                            else
                            {
                                return(Json("У вас нет прав на изменение базы данных автомобилей. Обратитесь к администратору для замены автомобиля или его номера."));
                            }
                        }
                        catch (Exception e) { }
                    }
                }
                catch
                {
                    //если такого номера нет, значит поправили номер и просто его заменяем
                    Avtomobil StarAvto = Avto;
                    Avto.Number             = A.Number;
                    Avto.TypeId             = A.TypeId;
                    Avto.ObiemBunkera       = A.ObiemBunkera;
                    Avto.MarkaId            = A.MarkaId;
                    Avto.KoefficientSgatiya = A.KoefficientSgatiya;
                    Avto.KontrAgentId       = A.KontrAgentId;
                    db.Entry(Avto).State    = EntityState.Modified;
                    db.SaveChanges();
                    PoligonZamena(StarAvto, Avto);
                }
            }
            return(RedirectToAction("Index", new { number = Avto.Number }));
        }
Esempio n. 12
0
        public ActionResult Create([Bind(Include = "Number,MassIn,MassOut,Description,Marka,TypeId,KontrAgentId,VibralRab")] Poligon poligon)
        {
            poligon.Date        = DateTime.Now;
            poligon.AvtomobilId = 0;
            poligon.Number      = poligon.Number.Replace(" ", "").ToUpper();
            poligon.User        = User.Identity.Name;

            HttpCookie cookieReq = Request.Cookies["Poligon"];

            if (cookieReq != null)
            {
                poligon.Date = Convert.ToDateTime(cookieReq["Date"]);
            }
            if (poligon.Date.Day == DateTime.Now.Day && poligon.Date.Month == DateTime.Now.Month && poligon.Date.Year == DateTime.Now.Year)
            {
                poligon.Date = DateTime.Now;
            }

            Avtomobil A = new Avtomobil();

            try
            {
                A = db.Avtomobils.Where(x => x.Number.Replace(" ", "").Equals(poligon.Number)).Include(x => x.Marka).Include(x => x.Type).Include(x => x.KontrAgent).First();
                poligon.AvtomobilId = A.Id;
                poligon.MarkaId     = A.Marka.Id;
                poligon.TypeId      = A.Type.Id;
                if (poligon.VibralRab == false)
                {
                    if (A.KontrAgent.Id != poligon.KontrAgentId)
                    {
                        poligon.KontrAgentId = A.KontrAgent.Id;
                    }
                }
                poligon.KontrAgentName = db.KontrAgents.Where(x => x.Id == poligon.KontrAgentId).Select(x => x.Name).First();
            }
            catch (Exception e)
            {
                A.Number             = poligon.Number;
                A.Glonass            = false;
                A.Garage             = 0;
                A.GKHNNC             = false;
                A.KoefficientSgatiya = 1;
                A.ObiemBunkera       = 0;
                A.TypeId             = poligon.TypeId;

                return(RedirectToAction("Index", new { Number = poligon.Number }));

                //если не нашли по номеру в бд то отправляем создать новый
            }

            if (poligon.Description == null)
            {
                poligon.Description = "В пределах нормы.";
                if (poligon.MassIn == 0)
                {
                    poligon.MassIn  = Math.Round(A.ObiemBunkera * A.KoefficientSgatiya * 165.1M, 2);
                    poligon.MassOut = 0;
                }
            }
            else
            {
                poligon.MassIn  = 0;
                poligon.MassOut = 0;
            }



            try
            {
                //сохраняем изменения

                poligon.MassMusor = poligon.MassIn - poligon.MassOut;
                db.Poligons.Add(poligon);
                db.SaveChanges();
                //обновляем суммарную массу на авто в активных маршрутах
                ObnovitMassuVMarshrutah(poligon);
            }
            catch (Exception e)
            {
            }


            ViewBag.Number          = poligon.Number;
            ViewBag.TypeAvtos       = new SelectList(db.TypeAvtos, "Id", "Type");
            ViewBag.MarkaAvtomobils = new SelectList(db.MarkaAvtomobils.OrderBy(x => x.Name), "Id", "Name");
            ViewBag.Numbers         = A;
            ViewBag.AvtoType        = db.TypeAvtos.Where(x => x.Id == 16).Select(x => x.Type).First();
            ViewBag.AvtoImage       = db.TypeAvtos.Where(x => x.Id == 16).Select(x => x.Ico).First();
            return(RedirectToAction("Index", new { number = poligon.Number }));
        }
Esempio n. 13
0
        // GET: Poligons
        public ActionResult Index(string Number, int Poisk = 0, int PoiskKontr = 0, int result = 0, int Vesi = 0, int Avtosort = 0, string TekDate = "")
        {
            DateTime Date = DateTime.Now;

            if (TekDate != "")
            {
                Date = Convert.ToDateTime(TekDate);
                //добавляем куки с осмотром
                HttpCookie cookie = new HttpCookie("Poligon");
                cookie["Date"] = Date.ToString();
                // Добавить куки в ответ
                Response.Cookies.Add(cookie);
            }
            else
            {
                HttpCookie cookieReq = Request.Cookies["Poligon"];
                if (cookieReq != null)
                {
                    Date = Convert.ToDateTime(cookieReq["Date"]);
                }
            }
            if (Date.Day == DateTime.Now.Day && Date.Month == DateTime.Now.Month && Date.Year == DateTime.Now.Year)
            {
                Date = DateTime.Now;
            }
            if (Number != null)
            {
                //если выбрана машина
                ViewBag.Number = Number;
                //и у нее уже были заезды, то забьем массу выезда сразу
                try
                {
                    int idA = db.Avtomobils.Where(x => x.Number.Equals(Number)).Select(x => x.Id).First();
                    ViewBag.MassOut = db.Poligons.Where(x => x.AvtomobilId == idA && x.Date.Day == Date.Day && x.Date.Month == Date.Month && x.Date.Year == Date.Year).Select(x => x.MassOut).First();
                }
                catch
                {
                }
            }
            else
            {
                ViewBag.Number = null;
            }
            List <string> A = new List <string>();

            try
            {
                A = db.Avtomobils.OrderBy(x => x.Number).Select(x => x.Number).ToList();
            }
            catch (Exception e)
            {
            }
            ViewBag.AllKontrAgents = new SelectList(db.KontrAgents, "Id", "Name");
            if (User.Identity.Name.Contains("Администратор") || User.IsInRole("Администратор"))
            {
                ViewBag.KontrAgents = new SelectList(db.KontrAgents, "Id", "Name");
            }
            else
            {//исключаем экологию из списка если не администратор
                ViewBag.KontrAgents = new SelectList(db.KontrAgents.Where(x => x.Id != 2), "Id", "Name");
            }
            ViewBag.TypeAvtos       = new SelectList(db.TypeAvtos, "Id", "Type");
            ViewBag.MarkaAvtomobils = new SelectList(db.MarkaAvtomobils.OrderBy(x => x.Name), "Id", "Name");
            if (Number != null)
            {
                Avtomobil Avto = new Avtomobil();
                try
                {
                    Avto                     = db.Avtomobils.Where(x => x.Number.Replace(" ", "").Equals(Number)).Include(x => x.Type).Include(x => x.KontrAgent).First();
                    ViewBag.Number           = Avto.Number.ToUpper().Replace(" ", "");
                    ViewBag.TypeAvtos        = new SelectList(db.TypeAvtos, "Id", "Type");
                    ViewBag.MarkaAvtomobils  = new SelectList(db.MarkaAvtomobils.OrderBy(x => x.Name), "Id", "Name");
                    ViewBag.AvtoType         = Avto.Type.Type;
                    ViewBag.AvtoImage        = Avto.Type.Ico;
                    ViewBag.AvtoKontragent   = Avto.KontrAgent.Name;
                    ViewBag.AvtoKontragentId = Avto.KontrAgent.Id;
                    ViewBag.Avto             = Avto;
                }
                catch (Exception e)
                {
                    ViewBag.Avto      = null;
                    ViewBag.Number    = null;
                    ViewBag.AvtoType  = db.TypeAvtos.Where(x => x.Id == 16).Select(x => x.Type).First();
                    ViewBag.AvtoImage = db.TypeAvtos.Where(x => x.Id == 16).Select(x => x.Ico).First();
                }
            }
            else
            {
                ViewBag.Avto             = null;
                ViewBag.AvtoType         = db.TypeAvtos.Where(x => x.Id == 16).Select(x => x.Type).First();
                ViewBag.AvtoKontragent   = "Нет";
                ViewBag.AvtoKontragentId = 1;
                ViewBag.AvtoImage        = db.TypeAvtos.Where(x => x.Id == 16).Select(x => x.Ico).First();
            }

            List <Poligon> Poligons = new List <Poligon>();

            ViewBag.Date = Date;//сохраняем дату для передачи
            try
            {
                DateTime D = Date;
                if (Poisk != 0)
                {
                    Poligons        = db.Poligons.Where(x => x.Date.Year == D.Year && x.Date.Month == D.Month && x.Date.Day == D.Day && x.AvtomobilId == Poisk).Include(z => z.Avtomobil).Include(z => z.Avtomobil.Marka).Include(z => z.Avtomobil.Type).Include(x => x.Marka).Include(x => x.Type).Include(x => x.Avtomobil.KontrAgent).ToList();
                    ViewBag.Poisk   = db.Avtomobils.Where(x => x.Id == Poisk).Select(x => x.Number).First();
                    ViewBag.PoiskId = Poisk;
                }
                else
                {
                    Poligons        = db.Poligons.Where(x => x.Date.Year == D.Year && x.Date.Month == D.Month && x.Date.Day == D.Day).Include(z => z.Avtomobil).Include(z => z.Avtomobil.Marka).Include(z => z.Avtomobil.Type).Include(x => x.Marka).Include(x => x.Type).Include(x => x.Avtomobil.KontrAgent).ToList();
                    ViewBag.Poisk   = "0";
                    ViewBag.PoiskId = 0;
                }
                //-2 это экология. Ищем все кроме экологии.
                if (PoiskKontr == -2)
                {
                    Poligons             = Poligons.Where(x => x.KontrAgentId != 2).ToList();
                    ViewBag.PoiskKontr   = "ТАЛОНЫ";
                    ViewBag.PoiskKontrId = -2;
                }
                else
                {
                    if (PoiskKontr != 0)
                    {
                        Poligons             = Poligons.Where(x => x.KontrAgentId == PoiskKontr).ToList();
                        ViewBag.PoiskKontr   = db.KontrAgents.Where(x => x.Id == PoiskKontr).Select(x => x.Name).First();
                        ViewBag.PoiskKontrId = PoiskKontr;
                    }
                    else
                    {
                        ViewBag.PoiskKontr   = "0";
                        ViewBag.PoiskKontrId = 0;
                    }
                }
            }
            catch (Exception e)
            {
            }
            if (Vesi != 0)
            {
                //Только с целыми весами
                if (Vesi == 1)
                {
                    Poligons = Poligons.Where(x => x.MassOut != 0).ToList();
                }
                //Только со сломанными весами
                if (Vesi == 2)
                {
                    Poligons = Poligons.Where(x => x.MassOut == 0).ToList();
                }
            }
            ViewBag.Vesi = Vesi;

            if (Avtosort != 0)
            {
                Poligons = Poligons.OrderBy(x => x.AvtomobilId).ThenBy(x => x.Date).ThenByDescending(x => x.Id).ToList();
                foreach (Poligon P in Poligons)
                {
                    try
                    {
                        P.PoligonIn = db.AutoScans.Where(x => x.AvtoId == P.AvtomobilId && x.Date.Year == P.Date.Year && x.Date.Month == P.Date.Month && x.Date.Day == P.Date.Day).Select(x => x.Poligon).First();
                    }
                    catch { }
                }
            }

            else
            {
                Poligons = Poligons.OrderByDescending(x => x.Date).ThenByDescending(x => x.Id).ToList();
            }
            ViewBag.Avtosort = Avtosort;
            if (result != 0)
            {
                /*List<Avtomobil> Avtomobils = Poligons.Select(x => x.Avtomobil).Distinct().ToList();
                 * List<Poligon> NewPoligons = new List<Poligon>();
                 * foreach (Avtomobil Avto in Avtomobils)
                 * {
                 *  Poligon P = new Poligon();
                 *  P.AvtomobilId = Avto.Id;
                 *  P.Avtomobil = Avto;
                 *  P.Description = "";
                 *  P.MarkaId = Avto.MarkaId;
                 *  P.Marka = Avto.Marka;
                 *  P.TypeId = Avto.TypeId;
                 *  P.Type = Avto.Type;
                 *  P.Number = Avto.Number;
                 *  P.MassMusor = Poligons.Where(x => x.AvtomobilId == Avto.Id).Sum(y => y.MassMusor);
                 *  P.MassIn = Poligons.Where(x => x.AvtomobilId == Avto.Id).Sum(y => y.MassIn);
                 *  P.MassOut = Poligons.Where(x => x.AvtomobilId == Avto.Id).Sum(y => y.MassOut);
                 *  P.Description = Poligons.Where(x => x.AvtomobilId == Avto.Id).ToList().Count.ToString();
                 *  P.KontrAgentName = Avto.KontrAgent.Name;
                 *  P.KontrAgentId = Avto.KontrAgent.Id;
                 *  NewPoligons.Add(P);
                 * }
                 *
                 * Poligons = NewPoligons;
                 */

                Poligons = Poligons.Where(x => x.Avtomobil.GKHNNC).ToList();
            }
            ViewBag.Resultat = result;
            ViewBag.Summ     = Poligons.Sum(x => x.MassMusor);
            return(View(Poligons));
        }