Example #1
0
            static public bool Delete(EGH01DB.IDBContext dbcontext, ECOForecast ecoforecast)
            {
                bool rc = false;

                using (SqlCommand cmd = new SqlCommand("EGH.DeleteReport", dbcontext.connection))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    {
                        SqlParameter parm = new SqlParameter("@IdОтчета", SqlDbType.Int);
                        parm.Value = ecoforecast.id;
                        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);
            }
Example #2
0
 public ECOForecast(ECOForecast forecast)
 {
     this.id         = forecast.id;
     this.date       = forecast.date;
     this.incident   = forecast.incident;
     this.groundblur = forecast.groundblur;
     this.waterblur  = forecast.waterblur;
     this.dateconcentrationinsoil = forecast.dateconcentrationinsoil;
     this.datewatercompletion     = forecast.datewatercompletion;
     this.datemaxwaterconc        = forecast.datemaxwaterconc;
     this.errormessage            = this.errormessage;
 }
Example #3
0
            public static bool GetById(EGH01DB.IDBContext dbcontext, int id, out ECOForecast ecoforecast, out string comment)
            {
                bool rc = false;

                ecoforecast = new ECOForecast();
                comment     = "";
                using (SqlCommand cmd = new SqlCommand("EGH.GetReportbyId", dbcontext.connection))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    {
                        SqlParameter parm = new SqlParameter("@IdОтчета", SqlDbType.Int);
                        parm.Value = id;
                        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())
                        {
                            DateTime date     = (DateTime)reader["ДатаОтчета"];
                            string   stage    = (string)reader["Стадия"];
                            int      predator = (int)reader["Родитель"];
                            comment = (string)reader["Комментарий"];
                            //
                            string      xmlContent = (string)reader["ТекстОтчета"];
                            XmlDocument doc        = new XmlDocument();
                            doc.LoadXml(xmlContent);
                            XmlNode newNode = doc.DocumentElement;
                            //

                            if (rc = (int)cmd.Parameters["@exitrc"].Value > 0)
                            {
                                ecoforecast = new ECOForecast(newNode);
                            }
                        }
                        reader.Close();
                    }
                    catch (Exception e)
                    {
                        rc = false;
                    };
                }
                return(rc);
            }
Example #4
0
            public static bool Create(IDBContext dbcontext, ECOForecast ecoforecast, 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))
                        {
                            ecoforecast.id = new_report_id;
                        }
                        parm.Value = ecoforecast.id;
                        cmd.Parameters.Add(parm);
                    }
                    {
                        SqlParameter parm = new SqlParameter("@ДатаОтчета", SqlDbType.DateTime);
                        parm.Value = ecoforecast.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      = ecoforecast.toXmlNode("EcoForeCast").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);
                }
            }