static public bool Delete(EGH01DB.IDBContext dbcontext, WaterProperties waterproperties) { bool rc = false; using (SqlCommand cmd = new SqlCommand("EGH.DeleteWaterProperties", dbcontext.connection)) { cmd.CommandType = CommandType.StoredProcedure; { SqlParameter parm = new SqlParameter("@КодПоказателяВоды", SqlDbType.Int); parm.Value = waterproperties.water_code; cmd.Parameters.Add(parm); } { SqlParameter parm = new SqlParameter("@exitrc", SqlDbType.Int); parm.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(parm); } try { cmd.ExecuteNonQuery(); rc = (int)cmd.Parameters["@exitrc"].Value > 0; } catch (Exception e) { rc = false; }; } return(rc); }
public static bool Create(EGH01DB.IDBContext dbcontext, WaterProperties waterproperties) { bool rc = false; using (SqlCommand cmd = new SqlCommand("EGH.CreateWaterProperties", dbcontext.connection)) { cmd.CommandType = CommandType.StoredProcedure; { SqlParameter parm = new SqlParameter("@КодПоказателяВоды", SqlDbType.Int); int new_water_property_code = 0; if (GetNextCode(dbcontext, out new_water_property_code)) { waterproperties.water_code = new_water_property_code; } parm.Value = waterproperties.water_code; cmd.Parameters.Add(parm); } { SqlParameter parm = new SqlParameter("@Температура", SqlDbType.Float); parm.Value = waterproperties.temperature; cmd.Parameters.Add(parm); } { SqlParameter parm = new SqlParameter("@Вязкость", SqlDbType.Float); parm.Value = waterproperties.viscocity; cmd.Parameters.Add(parm); } { SqlParameter parm = new SqlParameter("@Плотность", SqlDbType.Float); parm.Value = waterproperties.density; cmd.Parameters.Add(parm); } { SqlParameter parm = new SqlParameter("@КоэфПовНат", SqlDbType.Float); parm.Value = waterproperties.tension; cmd.Parameters.Add(parm); } { SqlParameter parm = new SqlParameter("@exitrc", SqlDbType.Int); parm.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(parm); } try { cmd.ExecuteNonQuery(); rc = ((int)cmd.Parameters["@exitrc"].Value > 0); } catch (Exception e) { rc = false; }; } return(rc); }
public static bool Get(EGH01DB.IDBContext dbcontext, float temp, out WaterProperties waterproperties, out float delta) { bool rc = false; delta = -1.0f; waterproperties = new WaterProperties(); using (SqlCommand cmd = new SqlCommand("EGH.GetWaterNearTemp", dbcontext.connection)) { cmd.CommandType = CommandType.StoredProcedure; { SqlParameter parm = new SqlParameter("@Температура", SqlDbType.Float); parm.Value = temp; cmd.Parameters.Add(parm); } { SqlParameter parm = new SqlParameter("@exitrc", SqlDbType.Int); parm.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(parm); } try { cmd.ExecuteNonQuery(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { int code = (int)reader["КодПоказателяВоды"]; float temperature = (float)reader["Температура"]; float viscocity = (float)reader["Вязкость"]; float density = (float)reader["Плотность"]; float tension = (float)reader["КоэфПовНат"]; delta = (float)reader["delta"]; if (rc = (int)cmd.Parameters["@exitrc"].Value > 0) { waterproperties = new WaterProperties(code, (float)temperature, (float)viscocity, (float)density, (float)tension); } } reader.Close(); } catch (Exception e) { rc = false; }; } return(rc); }
public ActionResult WaterPropertiesCreate(WaterPropertiesView wpv) { RGEContext db = null; ViewBag.EGHLayout = "RGE.WaterProperties"; ActionResult view = View("Index"); string menuitem = this.HttpContext.Request.Params["menuitem"] ?? "Empty"; try { db = new RGEContext(); view = View("WaterProperties", db); if (menuitem.Equals("WaterProperties.Create.Create")) { int id = -1; if (EGH01DB.Primitives.WaterProperties.GetNextCode(db, out id)) { int water_code = wpv.water_code; string strtemperature = this.HttpContext.Request.Params["temperature"] ?? "Empty"; float temperature; Helper.FloatTryParse(strtemperature, out temperature); string strviscocity = this.HttpContext.Request.Params["viscocity"] ?? "Empty"; float viscocity; Helper.FloatTryParse(strviscocity, out viscocity); string strdensity = this.HttpContext.Request.Params["density"] ?? "Empty"; float density; Helper.FloatTryParse(strdensity, out density); string strtension = this.HttpContext.Request.Params["tension"] ?? "Empty"; float tension; Helper.FloatTryParse(strtension, out tension); WaterProperties wp = new EGH01DB.Primitives.WaterProperties((int)water_code, (float)temperature, (float)viscocity, (float)density, (float)tension); if (EGH01DB.Primitives.WaterProperties.Create(db, wp)) { view = View("WaterProperties", db); } else if (menuitem.Equals("WaterProperties.Create.Cancel")) { view = View("WaterProperties", db); } } } else if (menuitem.Equals("WaterProperties.Create.Cancel")) { view = View("WaterProperties", db); } } catch (RGEContext.Exception e) { ViewBag.msg = e.message; } catch (Exception e) { ViewBag.msg = e.Message; } return(view); }
public ActionResult WaterProperties() { RGEContext db = null; ActionResult view = View("Index"); ViewBag.EGHLayout = "RGE.WaterProperties"; string menuitem = this.HttpContext.Request.Params["menuitem"] ?? "Empty"; try { db = new RGEContext(); ViewBag.msg = "Соединение с базой данных установлено"; view = View("WaterProperties", db); if (menuitem.Equals("WaterProperties.Create")) { view = View("WaterPropertiesCreate"); } else if (menuitem.Equals("WaterProperties.Delete")) { string water_code = this.HttpContext.Request.Params["water_code"]; if (water_code != null) { int c = 0; if (int.TryParse(water_code, out c)) { EGH01DB.Primitives.WaterProperties wp = new EGH01DB.Primitives.WaterProperties(); if (EGH01DB.Primitives.WaterProperties.GetByCode(db, c, out wp)) { view = View("WaterPropertiesDelete", wp); } } } } else if (menuitem.Equals("WaterProperties.Update")) { string water_code = this.HttpContext.Request.Params["water_code"]; if (water_code != null) { int c = 0; if (int.TryParse(water_code, out c)) { WaterProperties wp = new WaterProperties(); if (EGH01DB.Primitives.WaterProperties.GetByCode(db, c, out wp)) { view = View("WaterPropertiesUpdate", wp); } } } } else if (menuitem.Equals("WaterProperties.Excel")) { EGH01DB.Primitives.WaterPropertiesList list = new EGH01DB.Primitives.WaterPropertiesList(db); XmlNode node = list.toXmlNode(); XmlDocument doc = new XmlDocument(); XmlNode nnode = doc.ImportNode(node, true); doc.AppendChild(nnode); doc.Save(Server.MapPath("~/App_Data/WaterProperties.xml")); view = View("Index"); view = File(Server.MapPath("~/App_Data/WaterProperties.xml"), "text/plain", "Свойства воды.xml"); } } catch (RGEContext.Exception e) { ViewBag.msg = e.message; } catch (Exception e) { ViewBag.msg = e.Message; } return(view); }