Exemple #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            OPU oPU = db.OPUs.Find(id);

            db.OPUs.Remove(oPU);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #2
0
 public ActionResult Edit([Bind(Include = "Id,AdresId,OtopGkal,GWM3,HWM3,OtopRub,GWRub,HWRub,Primech,Date")] OPU oPU)
 {
     if (ModelState.IsValid)
     {
         db.Entry(oPU).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AdresId = new SelectList(db.Adres, "Id", "Adress", oPU.AdresId);
     return(View(oPU));
 }
Exemple #3
0
        // GET: OPUs/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            OPU oPU = db.OPUs.Find(id);

            if (oPU == null)
            {
                return(HttpNotFound());
            }
            return(View(oPU));
        }
Exemple #4
0
        // GET: OPUs/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            OPU oPU = db.OPUs.Find(id);

            if (oPU == null)
            {
                return(HttpNotFound());
            }
            ViewBag.AdresId = new SelectList(db.Adres, "Id", "Adress", oPU.AdresId);
            return(View(oPU));
        }
Exemple #5
0
        public async void Poisk(List <List <string> > excel, DateTime Date, List <Adres> Adresa)
        {
            int    progress = 0;
            double pro100   = 0;
            int    procount = 0;

            pro100 = excel.Count;
            OPU OPUKA = new OPU();

            //для каждой строки в экселе
            int lastadres = 0;

            foreach (List <string> L in excel)
            {
                if (L[0].Contains("Правды"))
                {
                }
                string adr = L[0].Replace("пр.", "").Replace("М.", "МУСЫ");
                adr = adr.Replace(" ", "").ToUpper() + L[1].Replace(" ", "").Replace("A", "А").ToUpper();//адрес составной из улицы и дома
                // "адрес"0, "№дом"1, "теплотаобщаясОПУ(Гкал)"2, "РасходГВСсОПУкуб,м"3, "РасходХВСкуб,мзамесяц"4, "РУБОТОПЛЕНИЕ"5, "РУБГОР.ВОДА"6, "РУБХОЛ.ВОДА"7
                decimal OtopGkal = 0;
                decimal OtopRub  = 0;
                decimal GWM3     = 0;
                decimal GWRub    = 0;
                decimal HWM3     = 0;
                decimal HWRub    = 0;
                string  Primech  = "";
                string  Primech2 = "";
                bool    ignore   = false;
                try
                {
                    OtopGkal = Math.Round(Convert.ToDecimal(L[2].Replace(",", ".")), 2);
                    if (OtopGkal < 0)
                    {
                        OtopGkal = 0;
                    }
                    OtopRub = Math.Round(Convert.ToDecimal(L[5].Replace(",", ".")), 2);
                    if (OtopRub < 0)
                    {
                        OtopRub = 0;
                    }
                }
                catch
                {
                    if (L[2] != "")
                    {
                        Primech = L[2].Replace(" ", "");
                    }
                }
                try
                {
                    GWM3 = Math.Round(Convert.ToDecimal(L[3].Replace(",", ".")), 2);
                    if (GWM3 < 0)
                    {
                        GWM3 = 0;
                    }
                    GWRub = Math.Round(Convert.ToDecimal(L[6].Replace(",", ".")), 2);
                    if (GWRub < 0)
                    {
                        GWRub = 0;
                    }
                }
                catch
                {
                }
                try
                {
                    HWM3 = Math.Round(Convert.ToDecimal(L[4].Replace(",", ".")), 2);

                    if (HWM3 < 0)
                    {
                        HWM3 = 0;
                    }
                    HWRub = Math.Round(Convert.ToDecimal(L[7].Replace(",", ".")), 2);
                    if (HWRub < 0)
                    {
                        HWRub = 0;
                    }
                }
                catch
                {
                    if (L[4] != "")
                    {
                        Primech2 = L[4].Replace(" ", "");
                        HWM3     = 0;
                        HWRub    = 0;
                    }
                }


                if (OtopGkal + GWM3 + HWM3 == 0)
                {
                    ignore = true;
                }



                if (!ignore)//если ненулевые показания
                {
                    bool nashli = false;

                    for (int A = lastadres; A < Adresa.Count; A++)
                    {
                        if (Adresa[A].Adress.Equals(adr))//и адрес совпал
                        {
                            //если в массиве адресов есть адрес из строчки то сохраняем айдишник

                            OPUKA.AdresId  = Adresa[A].Id;
                            lastadres      = A;
                            nashli         = true;
                            OPUKA.GWM3     = GWM3;
                            OPUKA.HWM3     = HWM3;
                            OPUKA.OtopGkal = OtopGkal;
                            OPUKA.GWRub    = GWRub;
                            OPUKA.HWRub    = HWRub;
                            OPUKA.OtopRub  = OtopRub;
                            string prim = "";
                            if (Primech.Length > Primech2.Length)
                            {
                                prim = Primech;
                            }
                            else
                            {
                                //если в примечании сохранено число -25323563.... что означает не считанные данные, то сохраняем как ремонт (обычно это значит ремонт)
                                if (Primech2.Contains("-2"))
                                {
                                    Primech2 = "*";
                                }

                                prim = Primech2;
                            }
                            OPUKA.Primech = prim;
                            OPUKA.Date    = Date;

                            using (WorkContext db = new WorkContext())
                            {
                                try//сохраняем в БД
                                {
                                    db.OPUs.Add(OPUKA);
                                    await db.SaveChangesAsync();
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine("Ошибка записи в базу данных " + e.Message);
                                }
                            }
                            // OPUKA.Name = "";
                            break;
                        }
                    }
                    if (!nashli && lastadres > 0)//если адрес не нашли то продолжаем поиск с начала списка
                    {
                        for (int A = 0; A < lastadres; A++)
                        {
                            if (Adresa[A].Adress.Equals(adr))//и адрес совпал
                            {
                                //если в массиве адресов есть адрес из строчки то сохраняем айдишник

                                OPUKA.AdresId  = Adresa[A].Id;
                                lastadres      = A;
                                nashli         = true;
                                OPUKA.GWM3     = GWM3;
                                OPUKA.HWM3     = HWM3;
                                OPUKA.OtopGkal = OtopGkal;
                                OPUKA.GWRub    = GWRub;
                                OPUKA.HWRub    = HWRub;
                                OPUKA.OtopRub  = OtopRub;
                                OPUKA.Primech  = Primech;
                                OPUKA.Date     = Date;
                                using (WorkContext db = new WorkContext())
                                {
                                    try//сохраняем в БД
                                    {
                                        db.OPUs.Add(OPUKA);
                                        db.SaveChanges();
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine("Ошибка записи в базу данных " + e.Message);
                                    }
                                }
                                // OPUKA.Name = "";
                                break;
                            }
                        }
                    }
                }
                procount++;
                progress = Convert.ToInt16(50 + procount / pro100 * 50);
                ProgressHub.SendMessage("Обрабатываем файл ОПУ...", progress);
                if (procount > pro100)
                {
                    procount = Convert.ToInt32(pro100);
                }
            }
            List <string> Adr = Adresa.Select(x => x.Adress).ToList();

            for (int a = 0; a < Adr.Count; a++)
            {
                Adr[a] = Adr[a].Replace(" ", "").ToUpper();
            }
        }