Ejemplo n.º 1
0
        static public bool Delete(EGH01DB.IDBContext dbcontext, PetrochemicalType petrochemical_type)
        {
            bool rc = false;

            using (SqlCommand cmd = new SqlCommand("EGH.DeletePetrochemicalType", dbcontext.connection))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                {
                    SqlParameter parm = new SqlParameter("@КодТипаНефтепродукта", SqlDbType.Int);
                    parm.Value = petrochemical_type.code_type;
                    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);
        }
Ejemplo n.º 2
0
        static public bool GetByCode(EGH01DB.IDBContext dbcontext, int type_code, ref PetrochemicalType petrochemical_type)
        {
            bool rc = false;

            petrochemical_type = new PetrochemicalType(type_code);
            using (SqlCommand cmd = new SqlCommand("EGH.GetPetrochemicalTypeByCode", dbcontext.connection))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                {
                    SqlParameter parm = new SqlParameter("@КодТипаНефтепродукта", SqlDbType.Int);
                    parm.Value = type_code;
                    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())
                    {
                        string name                        = (string)reader["НаименованиеТипаНефтепродукта"];
                        float  boilingtemp                 = (float)reader["ТемператураКипения"];
                        float  density                     = (float)reader["Плотность"];
                        float  viscosity                   = (float)reader["КинематическаяВязкость"];
                        float  solubility                  = (float)reader["Растворимость"];
                        float  tension                     = (float)reader["КоэфНатяжения"];
                        float  dynamicviscosity            = (float)reader["ДинамическаяВязкость"];
                        float  diffusion                   = (float)reader["КоэфДиффузии"];
                        int    petrochemicalcategories     = (int)reader["КодКатегорииНефтепродукта"];
                        string petrochemicalcategoriesname = (string)reader["НаименованиеКатегорииНефтепродукта"];
                        PetrochemicalCategories petro_cat  = new PetrochemicalCategories(petrochemicalcategories, petrochemicalcategoriesname);
                        if (rc = (int)cmd.Parameters["@exitrc"].Value > 0)
                        {
                            petrochemical_type = new PetrochemicalType(type_code, name,
                                                                       (float)boilingtemp,
                                                                       (float)density,
                                                                       (float)viscosity,
                                                                       (float)solubility,
                                                                       (float)tension,
                                                                       (float)dynamicviscosity,
                                                                       (float)diffusion,
                                                                       petro_cat);
                        }
                    }
                    reader.Close();
                }
                catch (Exception e)
                {
                    rc = false;
                };
            }
            return(rc);
        }
Ejemplo n.º 3
0
        static public bool Update(EGH01DB.IDBContext dbcontext, PetrochemicalType petrochemical_type)
        {
            bool rc = false;

            using (SqlCommand cmd = new SqlCommand("EGH.UpdatePetrochemicalType", dbcontext.connection))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                {
                    SqlParameter parm = new SqlParameter("@КодТипаНефтепродукта", SqlDbType.Int);
                    parm.Value = petrochemical_type.code_type;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@НаименованиеТипаНефтепродукта", SqlDbType.VarChar);
                    parm.Value = petrochemical_type.name;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@ТемператураКипения", SqlDbType.Real);
                    parm.Value = petrochemical_type.boilingtemp;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@Плотность", SqlDbType.Real);
                    parm.Value = petrochemical_type.density;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@КинематическаяВязкость", SqlDbType.Real);
                    parm.Value = petrochemical_type.viscosity;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@Растворимость", SqlDbType.Real);
                    parm.Value = petrochemical_type.solubility;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@КоэфНатяжения", SqlDbType.Real);
                    parm.Value = petrochemical_type.tension;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@ДинамическаяВязкость", SqlDbType.Real);
                    parm.Value = petrochemical_type.dynamicviscosity;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@КоэфДиффузии", SqlDbType.Real);
                    parm.Value = petrochemical_type.diffusion;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@КодКатегорииНефтепродукта", SqlDbType.Int);
                    parm.Value = petrochemical_type.petrochemicalcategories.type_code;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@exitrc", SqlDbType.Real);
                    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);
        }
Ejemplo n.º 4
0
        public ActionResult PetrochemicalType()
        {
            CCOContext db = null;

            ViewBag.EGHLayout = "CCO";
            ActionResult view     = View("Index");
            string       menuitem = this.HttpContext.Request.Params["menuitem"] ?? "Empty";

            try
            {
                db          = new CCOContext();
                ViewBag.msg = "Соединение с базой данных установлено";
                view        = View("PetrochemicalType", db);


                if (menuitem.Equals("PetrochemicalType.Create"))
                {
                    view = View("PetrochemicalTypeCreate");
                }
                else if (menuitem.Equals("PetrochemicalType.Delete"))
                {
                    string type_code_item = this.HttpContext.Request.Params["type_code"];
                    if (type_code_item != null)
                    {
                        int c = 0;
                        if (int.TryParse(type_code_item, out c))
                        {
                            PetrochemicalType pt = new PetrochemicalType();
                            if (EGH01DB.Types.PetrochemicalType.GetByCode(db, c, ref pt))
                            {
                                view = View("PetrochemicalTypeDelete", pt);
                            }
                        }
                    }
                }
                else if (menuitem.Equals("PetrochemicalType.Update"))
                {
                    string type_code_item = this.HttpContext.Request.Params["type_code"];

                    if (type_code_item != null)
                    {
                        int c = 0;
                        if (int.TryParse(type_code_item, out c))
                        {
                            EGH01DB.Types.PetrochemicalType pt = new EGH01DB.Types.PetrochemicalType();
                            if (EGH01DB.Types.PetrochemicalType.GetByCode(db, c, ref pt))
                            {
                                view = View("PetrochemicalTypeUpdate", pt);
                            }
                        }
                    }
                }
                else if (menuitem.Equals("PetrochemicalType.Excel"))
                {
                    EGH01DB.Types.PetrochemicalTypeList list = new PetrochemicalTypeList(db);
                    XmlNode     node  = list.toXmlNode();
                    XmlDocument doc   = new XmlDocument();
                    XmlNode     nnode = doc.ImportNode(node, true);
                    doc.AppendChild(nnode);
                    doc.Save(Server.MapPath("~/App_Data/PetrochemicalType.xml"));
                    view = View("Index");

                    view = File(Server.MapPath("~/App_Data/PetrochemicalType.xml"), "text/plain", "Химический состав нефтей.xml");
                }
            }
            catch (RGEContext.Exception e)
            {
                ViewBag.msg = e.message;
            }
            catch (Exception e)
            {
                ViewBag.msg = e.Message;
            }

            return(view);
        }