コード例 #1
0
        public int InsertMap(Map map)
        {
            int id = 0;
            using (SqlConnection con = DBConnection.GetConnection())
            {
                SqlCommand cmd = new SqlCommand("InsertMap", con);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@longitude", map.Longitude));
                cmd.Parameters.Add(new SqlParameter("@latitude", map.Latitude));
                cmd.Parameters.Add(new SqlParameter("@field_id_fk", map.FieldId));

                con.Open();
                //cmd.ExecuteNonQuery();
                SqlDataAdapter ad = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                ad.Fill(ds);
                DataTable result = ds.Tables[0];
                foreach (DataRow row in result.Rows)
                {
                    id = Int16.Parse(row[0].ToString());
                }
                con.Close();
            }
            return id;
        }
コード例 #2
0
        public Map SelectMapById(int map_id)
        {
            Map map = new Map();
            try
            {
                using (SqlConnection con = DBConnection.GetConnection())
                {
                    SqlCommand cmd = new SqlCommand("SelectMapById", con);
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@map_id", map_id));
                    con.Open();

                    SqlDataAdapter ad = new SqlDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    ad.Fill(ds);
                    DataTable maps = ds.Tables[0];
                    if (maps == null)
                    {
                        return null;
                    }
                    else
                    {
                        foreach (DataRow row in maps.Rows)
                        {
                            map.MapId = Int16.Parse(row[0].ToString());
                            map.Longitude = Double.Parse(row[1].ToString());
                            map.Latitude = Double.Parse(row[2].ToString());
                            if(row[3] != DBNull.Value)
                                map.FieldId = Int16.Parse(row[3].ToString());
                        }
                    }
                    con.Close();
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }

            return map;
        }
コード例 #3
0
        public List<Map> SelectMaps()
        {
            List<Map> maps = new List<Map>();
            using (SqlConnection con = DBConnection.GetConnection())
            {
                SqlCommand cmd = new SqlCommand("SelectMaps", con);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                con.Open();

                SqlDataAdapter ad = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                ad.Fill(ds);
                DataTable mapsTable = ds.Tables[0];

                if (mapsTable == null)
                {
                    return null;
                }
                else
                {
                    foreach (DataRow row in mapsTable.Rows)
                    {
                        Map map = new Map();
                        map.MapId = Int16.Parse(row[0].ToString());
                        map.Longitude = Double.Parse(row[1].ToString());
                        map.Latitude = Double.Parse(row[2].ToString());
                        map.FieldId = Int16.Parse(row[3].ToString());
                        maps.Add(map);
                    }
                }
                con.Close();
            }

            return maps;
        }