Ejemplo n.º 1
0
        public List <Stores> GetAllStoresWithTheSameCatAndFloor(long cat, int floor)
        {
            List <Stores> result = new List <Stores>();

            try
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    using (cmd.Connection = new SqlConnection(m_conn_string))
                    {
                        cmd.Connection.Open();

                        cmd.CommandType = System.Data.CommandType.Text;
                        cmd.CommandText = $"SELECT * FROM Stores WHERE Categories_ID={cat} AND Floor={floor};";

                        SqlDataReader reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            Stores s = new Stores()
                            {
                                ID            = (long)reader["ID"],
                                Name          = reader["Name"].ToString(),
                                Floor         = (int)reader["Floor"],
                                Categories_ID = (long)reader["Categories_ID"],
                            };
                            result.Add(s);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                my_logger.Error("Failed Function GetAllStoresWithTheSameCatAndFloor by query (SELECT * FROM Stores WHERE Categories_ID={cat} AND Floor={floor})");
                my_logger.Error($"Failed to read from data base. Error : {ex}");
            }

            return(result);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            my_logger.Info("...System coming up...");
            StoresDAO storesDAO = new StoresDAO("Data Source=.;Initial Catalog=TargilMeskamSSMS;Integrated Security=True;");
            Stores    s         = new Stores("Prada", 2, 1);
            //storesDAO.UpdateStore(s, 2);
            //storesDAO.AddStore(s);
            List <Stores> stores_list = storesDAO.GetAllStores();

            Console.WriteLine("GetAllStores`-");
            stores_list.ForEach(s1 => Console.WriteLine(s1));
            Stores store = storesDAO.GetStoreById(3);

            Console.WriteLine("getstorebyID");
            Console.WriteLine(store);
            List <Stores> stores_list2 = storesDAO.GetAllStoresWithTheSameCatAndFloor(1, 2);

            Console.WriteLine("GetAllStoresWithTheSameCatAndFloor");
            stores_list2.ForEach(s2 => Console.WriteLine(s2));
            Console.WriteLine("GetMaxStoresByCategory");
            Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(storesDAO.GetMaxStoresByCategory()));
            my_logger.Info("...System shutting down...");
        }
Ejemplo n.º 3
0
 public void AddStore(Stores s)
 {
     ExecuteNonQuery("INSERT INTO Stores(Name, Floor,Categories_ID)" +
                     $"VALUES('{s.Name}',{s.Floor},{s.Categories_ID});");
 }
Ejemplo n.º 4
0
 public void UpdateStore(Stores s, int id)
 {
     ExecuteNonQuery(
         $"UPDATE Stores SET Name='{s.Name}', Floor={s.Floor},Categories_ID={s.Categories_ID} WHERE ID={id}");
 }