Example #1
0
            public static ECOEvalution GetById(IDBContext db, int id)
            {
                ECOEvalution rc = null;

                using (SqlCommand cmd = new SqlCommand("EGH.GetECOEvalutionById", db.connection))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    {
                        SqlParameter parm = new SqlParameter("@IdОтчета", SqlDbType.Int);
                        parm.Value = id;
                        cmd.Parameters.Add(parm);
                    }
                    try
                    {
                        SqlDataReader reader = cmd.ExecuteReader();
                        if (reader.Read())
                        {
                            string xmlContent = (string)reader["ТекстОтчета"];
                            if (!xmlContent.Trim().Equals(""))
                            {
                                XmlDocument doc = new XmlDocument();
                                doc.LoadXml(xmlContent);
                                rc = new CEQContext.ECOEvalution(doc.DocumentElement);
                            }
                        }
                        reader.Close();
                    }
                    catch (Exception e) { rc = null; };
                }
                return(rc);
            }
Example #2
0
            public static bool Create(IDBContext dbcontext, ECOEvalution ecoevalution, string comment = "")
            {
                bool rc = false;

                using (SqlCommand cmd = new SqlCommand("EGH.CreateReport", dbcontext.connection))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    {
                        SqlParameter parm          = new SqlParameter("@IdОтчета", SqlDbType.Int);
                        int          new_report_id = 0;
                        if (GetNextId(dbcontext, out new_report_id))
                        {
                            ecoevalution.id = new_report_id;
                        }
                        parm.Value = ecoevalution.id;
                        cmd.Parameters.Add(parm);
                    }
                    {
                        SqlParameter parm = new SqlParameter("@ДатаОтчета", SqlDbType.DateTime);
                        parm.Value = ecoevalution.date;
                        cmd.Parameters.Add(parm);
                    }
                    {
                        SqlParameter parm = new SqlParameter("@Стадия", SqlDbType.NChar);
                        parm.Value = "Р";
                        cmd.Parameters.Add(parm);
                    }
                    {
                        SqlParameter parm = new SqlParameter("@Родитель", SqlDbType.Int);
                        parm.IsNullable = true;
                        parm.Value      = 0;
                        cmd.Parameters.Add(parm);
                    }
                    {
                        SqlParameter parm = new SqlParameter("@ТекстОтчета", SqlDbType.Xml);
                        parm.IsNullable = true;
                        parm.Value      = ecoevalution.toXmlNode("Отладка").OuterXml;
                        cmd.Parameters.Add(parm);
                    }
                    {
                        SqlParameter parm = new SqlParameter("@Комментарий", SqlDbType.NVarChar);
                        parm.IsNullable = true;
                        parm.Value      = comment;
                        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);
                }
            }