public ActionResult DeleteConfirmed(int id) { IPU iPU = db.IPUs.Find(id); db.IPUs.Remove(iPU); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,AdresId,OtEnergyRub,OtEnergyGkal,NomerSchetchika,Date")] IPU iPU) { if (ModelState.IsValid) { db.Entry(iPU).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AdresId = new SelectList(db.Adres, "Id", "Adress", iPU.AdresId); return(View(iPU)); }
// GET: IPUs/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IPU iPU = db.IPUs.Find(id); if (iPU == null) { return(HttpNotFound()); } return(View(iPU)); }
// GET: IPUs/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IPU iPU = db.IPUs.Find(id); if (iPU == null) { return(HttpNotFound()); } ViewBag.AdresId = new SelectList(db.Adres, "Id", "Adress", iPU.AdresId); return(View(iPU)); }
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; IPU IPUKA = new IPU(); List <string> NoAdress = new List <string>(); //для каждой строки в экселе int lastadres = 0; int summ = 0; decimal summnorm = 0; decimal summschetchik = 0; foreach (List <string> L in excel) { bool EstService = false; string adr = L[0].Replace(" ", "").ToUpper(); decimal Normativ = 0; decimal Schetchik = 0; bool ignore = false; try { Normativ = Math.Round(Convert.ToDecimal(L[1].Replace(",", ".")), 2); summnorm += Normativ; } catch { } try { Schetchik = Math.Round(Convert.ToDecimal(L[2].Replace(",", ".")), 2); summschetchik += Schetchik; } catch { } if (Normativ + Schetchik == 0) { ignore = true; summ++; } if (!ignore)//если ненулевые показания { bool nashli = false; for (int A = lastadres; A < Adresa.Count; A++) { if (Adresa[A].Adress.Equals(adr))//и адрес совпал { //если в массиве адресов есть адрес из строчки то сохраняем айдишник IPUKA.AdresId = Adresa[A].Id; lastadres = A; nashli = true; IPUKA.Normativ = Normativ; IPUKA.Schetchik = Schetchik; IPUKA.NomerSchetchika = L[3]; IPUKA.Date = Date; using (WorkContext db = new WorkContext()) { try//сохраняем в БД { db.IPUs.Add(IPUKA); await db.SaveChangesAsync(); } catch (Exception e) { Console.WriteLine("Ошибка записи в базу данных " + e.Message); } } // IPUKA.Name = ""; break; } } if (!nashli && lastadres > 0)//если адрес не нашли то продолжаем поиск с начала списка { for (int A = 0; A < lastadres; A++) { if (Adresa[A].Adress.Equals(adr))//и адрес совпал { //если в массиве адресов есть адрес из строчки то сохраняем айдишник IPUKA.AdresId = Adresa[A].Id; lastadres = A; nashli = true; IPUKA.Normativ = Normativ; IPUKA.Schetchik = Schetchik; IPUKA.NomerSchetchika = L[3]; using (WorkContext db = new WorkContext()) { try//сохраняем в БД { db.IPUs.Add(IPUKA); db.SaveChanges(); } catch (Exception e) { Console.WriteLine("Ошибка записи в базу данных " + e.Message); } } // IPUKA.Name = ""; break; } } } if (!nashli) { NoAdress.Add(adr + "Не найден"); } } 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(); } }