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

            using (SqlCommand cmd = new SqlCommand("EGH.DeleteEcoObject", dbcontext.connection))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                {
                    SqlParameter parm = new SqlParameter("@IdПриродоохранногоОбъекта", SqlDbType.Int);
                    parm.Value = ecoobject.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
        static public bool GetByMap(EGH01DB.IDBContext dbcontext, Coordinates coordinates, out EcoObject ecoobject)
        {
            bool rc = false;

            ecoobject = new EcoObject();
            using (SqlCommand cmd = new SqlCommand("MAP.InEcoObjectMap", dbcontext.connection))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                {
                    SqlParameter parm = new SqlParameter("@point", SqlDbType.VarChar);
                    parm.Value = coordinates.GetMapPoint();
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@exitrc", SqlDbType.Int);
                    parm.Direction = ParameterDirection.ReturnValue;
                    cmd.Parameters.Add(parm);
                }
                try
                {
                    SqlDataReader reader = cmd.ExecuteReader();
                    if (rc = reader.Read())
                    {
                        int           id              = (int)reader["Obj_Id"];
                        string        name            = (string)reader["name"];
                        string        type            = (string)reader["type"];
                        EcoObjectType eco_object_type = new EcoObjectType(type);
                        CadastreType  cadastre_type   = new CadastreType("не определено на карте");

                        ecoobject = new EcoObject(name, eco_object_type, cadastre_type);
                    }
                    reader.Close();
                }
                catch (Exception e)
                {
                    rc = false;
                };
            }
            return(rc);
        }
Example #3
0
        static public bool CreateNear(EGH01DB.IDBContext dbcontext, EcoObject ecoobject, float angle, float distance, out EcoObject eco_object)
        {
            bool rc = false;
            int  id = -1;

            eco_object = new EcoObject();
            using (SqlCommand cmd = new SqlCommand("EGH.GetCoordinatesByAngle", dbcontext.connection))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                {
                    SqlParameter parm = new SqlParameter("@lat1", SqlDbType.Real);
                    parm.Value = ecoobject.coordinates.latitude;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@lng1", SqlDbType.Real);
                    parm.Value = ecoobject.coordinates.lngitude;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@angle", SqlDbType.Real);
                    parm.Value = angle;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@distance", SqlDbType.Real);
                    parm.Value = distance;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@lat2", SqlDbType.Real);
                    parm.Direction = ParameterDirection.Output;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@lng2", SqlDbType.Real);
                    parm.Direction = ParameterDirection.Output;
                    cmd.Parameters.Add(parm);
                }
                try
                {
                    cmd.ExecuteNonQuery();

                    float       x           = (float)cmd.Parameters["@lat2"].Value;
                    float       y           = (float)cmd.Parameters["@lng2"].Value;
                    Coordinates coordinates = new Coordinates((float)x, (float)y);

                    int        new_ground_type_code = ecoobject.groundtype.type_code;
                    float      new_waterdeep        = ecoobject.waterdeep;
                    float      new_height           = ecoobject.height;
                    GroundType new_ground_type      = new GroundType(new_ground_type_code);
                    Point      point = new Point(coordinates, new_ground_type, new_waterdeep, new_height);

                    int           new_cadastre_type_code = ecoobject.cadastretype.type_code;
                    bool          iswaterobject          = ecoobject.iswaterobject;
                    string        name = ecoobject.name;
                    int           ecoobjecttype_code = ecoobject.ecoobjecttype.type_code;
                    EcoObjectType ecoobjecttype      = new EcoObjectType(ecoobjecttype_code);
                    CadastreType  cadastretype       = new CadastreType(new_cadastre_type_code);

                    eco_object = new EcoObject(id, point, ecoobjecttype, cadastretype, name, iswaterobject);
                    if (EcoObject.Create(dbcontext, eco_object))
                    {
                        rc = true;
                    }
                }
                catch (Exception e)
                {
                    rc = false;
                };
                return(rc);
            }
        }
Example #4
0
        static public bool GetById(EGH01DB.IDBContext dbcontext, int id, ref EcoObject ecoobject)
        {
            bool rc = false;

            using (SqlCommand cmd = new SqlCommand("EGH.GetEcoObjectByID", 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())
                    {
                        float       x           = (float)reader["ШиротаГрад"];
                        float       y           = (float)reader["ДолготаГрад"];
                        Coordinates coordinates = new Coordinates((float)x, (float)y);

                        string ground_type_name = (string)reader["НаименованиеТипаГрунта"];
                        float  porosity         = (float)reader["КоэфПористости"];
                        float  holdmigration    = (float)reader["КоэфЗадержкиМиграции"];
                        float  waterfilter      = (float)reader["КоэфФильтрацииВоды"];
                        float  diffusion        = (float)reader["КоэфДиффузии"];
                        float  distribution     = (float)reader["КоэфРаспределения"];
                        float  sorption         = (float)reader["КоэфСорбции"];
                        float  watercapacity    = (float)reader["КоэфКапВлагоемкости"];
                        float  soilmoisture     = (float)reader["ВлажностьГрунта"];
                        float  аveryanovfactor  = (float)reader["КоэфАверьянова"];
                        float  permeability     = (float)reader["Водопроницаемость"];
                        float  density          = (float)reader["СредняяПлотностьГрунта"];

                        GroundType ground_type = new GroundType((int)reader["ТипГрунта"],
                                                                (string)ground_type_name,
                                                                (float)porosity,
                                                                (float)holdmigration,
                                                                (float)waterfilter,
                                                                (float)diffusion,
                                                                (float)distribution,
                                                                (float)sorption,
                                                                (float)watercapacity,
                                                                (float)soilmoisture,
                                                                (float)аveryanovfactor,
                                                                (float)permeability,
                                                                (float)density);

                        float  waterdeep           = (float)reader["ГлубинаГрунтовыхВод"];
                        float  height              = (float)reader["ВысотаУровнемМоря"];
                        Point  point               = new Point(coordinates, ground_type, (float)waterdeep, (float)height);
                        int    ecoobject_type_code = (int)reader["КодТипаПриродоохранногоОбъекта"];
                        string ecoobject_type_name = (string)reader["НаименованиеТипаПриродоохранногоОбъекта"];

                        int  cat_water_name = (int)reader["КатегорияВодоохрТер"];
                        bool iswaterobject;
                        if (cat_water_name != 0)
                        {
                            iswaterobject = true;
                        }
                        else
                        {
                            iswaterobject = false;
                        }
                        WaterProtectionArea water_protection_area = new WaterProtectionArea(cat_water_name);
                        EcoObjectType       ecoobjecttype         = new EcoObjectType(ecoobject_type_code, ecoobject_type_name, water_protection_area);

                        int    cadastre_type_code = (int)reader["КодТипаНазначенияЗемель"];
                        string cadastre_type_name = (string)reader["НаименованиеНазначенияЗемель"];
                        float  pdk             = (float)reader["ПДК"];
                        float  water_pdk_coef  = (float)reader["ПДКводы"];
                        string ground_doc_name = (string)reader["НормДокументЗемля"];
                        string water_doc_name  = (string)reader["НормДокументВода"];

                        CadastreType cadastre_type = new CadastreType(cadastre_type_code, (string)cadastre_type_name,
                                                                      pdk, water_pdk_coef,
                                                                      ground_doc_name, water_doc_name);
                        string ecoobject_name = (string)reader["НаименованиеПриродоохранногоОбъекта"];


                        ecoobject = new EcoObject(id, point, ecoobjecttype, cadastre_type, ecoobject_name, iswaterobject);
                    }
                    reader.Close();
                    rc = (int)cmd.Parameters["@exitrc"].Value > 0;
                }
                catch (Exception e)
                {
                    rc = false;
                };

                return(rc);
            }
        }
Example #5
0
        static public bool Update(EGH01DB.IDBContext dbcontext, EcoObject ecoobject)
        {
            bool rc = false;

            using (SqlCommand cmd = new SqlCommand("EGH.UpdateEcoObject", dbcontext.connection))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                {
                    SqlParameter parm = new SqlParameter("@IdПриродоохранногоОбъекта", SqlDbType.Int);
                    parm.Value = ecoobject.id;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@КодТипаПриродоохранногоОбъекта", SqlDbType.Int);
                    parm.Value = ecoobject.ecoobjecttype.type_code;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@КодТипаНазначенияЗемель", SqlDbType.Int);
                    parm.Value = ecoobject.cadastretype.type_code;
                    cmd.Parameters.Add(parm);
                }

                {
                    SqlParameter parm = new SqlParameter("@НаименованиеПриродоохранногоОбъекта", SqlDbType.NVarChar);
                    parm.Value = ecoobject.name;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@ШиротаГрад", SqlDbType.Real);
                    parm.Value = ecoobject.coordinates.latitude;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@ДолготаГрад", SqlDbType.Real);
                    parm.Value = ecoobject.coordinates.lngitude;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@ТипГрунта", SqlDbType.Int);
                    parm.Value = ecoobject.groundtype.type_code;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@ГлубинаГрунтовыхВод", SqlDbType.Real);
                    parm.Value = ecoobject.waterdeep;
                    cmd.Parameters.Add(parm);
                }
                {
                    SqlParameter parm = new SqlParameter("@ВысотаУровнемМоря", SqlDbType.Real);
                    parm.Value = ecoobject.height;
                    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);
        }