public IActionResult Create() { int reportDtYear = Convert.ToInt32(User.Claims.ToList().FirstOrDefault(x => x.Type == "reportDtYear").Value); int reportDtMonth = Convert.ToInt32(User.Claims.ToList().FirstOrDefault(x => x.Type == "reportDtMonth").Value); ViewBag.RepMoList = spDAL.RepMO1YearList(reportDtYear, reportDtMonth); ViewBag.VetPrepList = spDAL.VetPrepList(); //ViewBag.EdIzmList = spDAL.EdIzmList(); string _kidro = User.Claims.ToList().FirstOrDefault(x => x.Type == "KIDro").Value; long? b = BioPrepDAL.GetByloById(_kidro, DateTime.Today, "AZIN" ); BioPrep tmp = new BioPrep { KIDro = _kidro, RepMO = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), VetPrep = "AZIN", Bylo = b, Ostatok_za_mesyac = b }; ViewBag.Page = "BioPrep"; return(View(tmp)); }
public IActionResult Edit(Guid id) { if (id == null) { return(NotFound()); } BioPrep tmp = BioPrepDAL.GetById_BioPrep(id); if (tmp == null) { return(NotFound()); } int Y = Convert.ToInt32(User.Claims.ToList().FirstOrDefault(x => x.Type == "reportDtYear").Value); int M = Convert.ToInt32(User.Claims.ToList().FirstOrDefault(x => x.Type == "reportDtMonth").Value); ViewBag.RepMoList = spDAL.RepMO1YearList(Y, M); ViewBag.VetPrepList = spDAL.VetPrepList(); ViewBag.EdIzmList = spDAL.EdIzmList(); ViewBag.Page = "BioPrep"; //if(tmp.ByloPredMonth!=tmp.Bylo) // TempData["EM"] = "Остаток на нач. месяца не совпадает с введенными ранее данными"; return(View(tmp)); }
public static void Add_BioPrep(BioPrep tmp) { SqlConnection _conn = new SqlConnection(spDAL.connStr); /* * string q = "SELECT TOP 1 (Bylo+PostupiloVsego+PostupiloRazn-IzrashodVsego-IzrashodDrugoe) " +"as ByloPredMonth FROM BioPrep WHERE (" + * "KIDro=@KIDro and VetPrep=@VetPrep and EdIzm=@EdIzm and "+ * "repMO < @dt) ORDER BY repMO DESC";*/ string q = "SELECT TOP 1 (Bylo+PostupiloVsego-IzrashodVsego) " + "as ByloPredMonth FROM BioPrep WHERE (" + "KIDro=@KIDro and VetPrep=@VetPrep and " + "repMO < @dt) ORDER BY repMO DESC"; var param = new { KIDro = tmp.KIDro, VetPrep = tmp.VetPrep, //EdIzm = spDAL.EdIzmID(tmp.VetPrep), dt = tmp.RepMO, }; tmp.Bylo = _conn.QueryFirstOrDefault <long?>(q, param); if (tmp.Bylo == null) { tmp.Bylo = 0; } _conn.Execute("INSERT INTO BioPrep (KIDro, repMO,VetPrep,EdIzm,Bylo," + "PostupiloVsego,PostupiloRazn,IzrashodVsego,IzrashodDrugoe,Ostatok_za_mesyac) VALUES (" + "@KIDroP,@repMOP,@VetPrepP,@EdIzmP,@ByloP," + "@PostupiloVsegoP,@PostupiloRaznP,@IzrashodVsegoP,@IzrashodDrugoeP,@Ostatok_za_mesyac)", new { KIDroP = tmp.KIDro, repMOP = tmp.RepMO, VetPrepP = tmp.VetPrep, EdIzmP = spDAL.EdIzmID(tmp.VetPrep), ByloP = tmp.Bylo, PostupiloVsegoP = tmp.PostupiloVsego, PostupiloRaznP = tmp.PostupiloRazn, IzrashodDrugoeP = tmp.IzrashodDrugoe, IzrashodVsegoP = tmp.IzrashodVsego, Ostatok_za_mesyac = tmp.Bylo + tmp.PostupiloVsego //tmp.PostupiloRazn - - tmp.IzrashodVsego //tmp.IzrashodDrugoe }); _conn.Close(); }
public IActionResult Delete(Guid id) { if (id == null) { return(NotFound()); } BioPrep tmp = BioPrepDAL.GetById_BioPrep(id); if (tmp == null) { return(NotFound()); } ViewBag.Page = "BioPrep"; return(View(tmp)); }
public IActionResult Edit(Guid id, [Bind] BioPrep objBioPrep) { if (id == null) { return(NotFound()); } if (ModelState.IsValid) { //if(BioPrepDAL.IsUniqueRecord(objBioPrep)) BioPrepDAL.Update_BioPrep(objBioPrep); return(RedirectToAction("Index")); } ViewBag.Page = "BioPrep"; return(View(objBioPrep)); }
public IActionResult Create([Bind] BioPrep tmp) { if (ModelState.IsValid) { //проверка на существования аналогичной записи if (BioPrepDAL.IsUniqueRecord(tmp)) { BioPrepDAL.Add_BioPrep(tmp); } else { TempData["EM"] = "Такая запись уже существует"; //return LocalRedirect("~/Home/Error"); //return RedirectToAction("Error"); }; return(RedirectToAction("Index")); } ViewBag.Page = "BioPrep"; return(View(tmp)); }
public static void Update_BioPrep(BioPrep tmp) { if (tmp == null) { return; } using (SqlConnection _conn = new SqlConnection(spDAL.connStr)) { string q = "UPDATE BioPrep SET KIDro=@KIDroP," + "repMO=@repMOP," + "VetPrep=@VetPrepP," + "EdIzm=@EdIzmP," + "Bylo=@Bylo," + "PostupiloVsego=@PostupiloVsegoP," + "PostupiloRazn=@PostupiloRaznP," + "IzrashodVsego=@IzrashodVsegoP," + "IzrashodDrugoe=@IzrashodDrugoeP," + "Ostatok_za_mesyac=@Ostatok_za_mesyac" + " WHERE ID=@IdP"; var param = new { IdP = tmp.ID, KIDroP = tmp.KIDro, repMOP = tmp.RepMO, VetPrepP = tmp.VetPrep, EdIzmP = spDAL.EdIzmID(tmp.VetPrep), Bylo = tmp.Bylo, PostupiloVsegoP = tmp.PostupiloVsego, PostupiloRaznP = tmp.PostupiloRazn, IzrashodDrugoeP = tmp.IzrashodDrugoe, IzrashodVsegoP = tmp.IzrashodVsego, Ostatok_za_mesyac = tmp.Bylo + tmp.PostupiloVsego //tmp.PostupiloRazn - //tmp.IzrashodDrugoe - - tmp.IzrashodVsego }; _conn.Execute(q, param); _conn.Close(); } }
public static bool IsUniqueRecord(BioPrep tmp) { if (tmp == null) { return(false); } using (SqlConnection _conn = new SqlConnection(spDAL.connStr)) { int count = _conn.QueryFirst <int>("SELECT COUNT(*) FROM BioPrep WHERE (" + "repMO=@repMOP and KIDro=@KIDroP and VetPrep=@VetPrepP)", new { repMOP = tmp.RepMO, KIDroP = tmp.KIDro, VetPrepP = tmp.VetPrep }); _conn.Close(); if (count == 0) { return(true); } else { return(false); } } }
public static BioPrep GetById_BioPrep(Guid Id) { using (SqlConnection _conn = new SqlConnection(spDAL.connStr)) { BioPrep tmp = _conn.QueryFirst <BioPrep>( "SELECT * FROM BioPrep WHERE ID=@IDv", new { IDv = Id }); /* * string q = "SELECT TOP 1 (Bylo+PostupiloVsego+PostupiloRazn-IzrashodVsego-IzrashodDrugoe) " +"as ByloPredMonth FROM BioPrep WHERE (" + * "KIDro=@KIDro and VetPrep=@VetPrep and EdIzm=@EdIzm and "+ * "repMO < @dt) ORDER BY repMO DESC";*/ string q = "SELECT TOP 1 (Bylo+PostupiloVsego-IzrashodVsego) " + "as ByloPredMonth FROM BioPrep WHERE (" + "KIDro=@KIDro and VetPrep=@VetPrep and " + "repMO < @dt) ORDER BY repMO DESC"; var param = new { KIDro = tmp.KIDro, VetPrep = tmp.VetPrep, //EdIzm = tmp.EdIzm, dt = tmp.RepMO, }; tmp.Bylo = _conn.QueryFirstOrDefault <long?>(q, param); if (tmp.Bylo == null) { tmp.Bylo = 0; } _conn.Close(); tmp.VetPrepDisplay = spDAL.VetPrepName(tmp.VetPrep); //tmp.EdIzmDisplay = spDAL.EdIzmName(tmp.EdIzm); tmp.Ostatok_za_mesyac = tmp.Bylo + tmp.PostupiloVsego //+ tmp.PostupiloRazn - tmp.IzrashodVsego; //-tmp.IzrashodDrugoe; return(tmp); } }