public Stores GetByIdStores(int id) { Stores store = null; string query = $"SELECT * FROM Stores where Id={id}"; try { conn.Open(); SqlCommand cmd = new SqlCommand(query, conn); SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default); reader.Read(); store = new Stores { ID = Convert.ToInt32(reader["ID"]), StoresName = reader["StoresName"].ToString(), Store_Floor = Convert.ToInt32(reader["Store_Floor"]), category_ID = Convert.ToInt32(reader["category_ID"]) }; my_logger.Info($"get store with id= {id} "); } catch (Exception ex) { my_logger.Error($"Failed to get store. Error : {ex}"); my_logger.Error($"GetByIdStores: [{query}]"); } conn.Close(); return(store); }
static void Main(string[] args) { my_logger.Info("******************** System startup"); m_config = new SQL_SERVER_AppConfig(); Console.WriteLine($"-- Hello App {m_config.AppName}"); Categories category1 = new Categories { ID = 3, CategoryName = "computer" }; Categories category2 = new Categories { ID = 4, CategoryName = "cellular" }; Stores store1 = new Stores { ID = 10, StoresName = "bug", Store_Floor = 2, category_ID = 4 }; Stores store2 = new Stores { ID = 11, StoresName = "yosi cumputers", Store_Floor = 1, category_ID = 3 }; DAO dAO = new DAO(); dAO.AddCategories(category1.CategoryName); dAO.AddStores(store1); Console.WriteLine("GetAllCategories: "); dAO.GetAllCategories().ForEach(c => Console.WriteLine(c.ToString())); Console.WriteLine(); Console.WriteLine("GetAllStores: "); dAO.GetAllStores().ForEach(s => Console.WriteLine(s.ToString())); Console.WriteLine(); Console.WriteLine("GetAllStoresWithCategories: "); dAO.GetAllStoresWithCategories().ForEach(c => Console.WriteLine(JsonConvert.SerializeObject(c, Formatting.Indented).ToString())); Console.WriteLine(); Console.WriteLine("GetByIdCategories: "); Console.WriteLine(dAO.GetByIdCategories(1).ToString()); Console.WriteLine(); Console.WriteLine("GetByIdStores: "); Console.WriteLine(dAO.GetByIdStores(1).ToString()); Console.WriteLine(); Console.WriteLine("GetSoresFromFloorAndCategories: "); dAO.GetSoresFromFloorAndCategories(1, 1).ForEach(c => Console.WriteLine(c.ToString())); Console.WriteLine(); dAO.UpdateCategories(8, category2); dAO.UpdateStores(12, store2); Console.WriteLine("ShowCategoriesWithMaxStores: "); dAO.ShowCategoriesWithMaxStores(); Console.WriteLine(); Console.ReadLine(); dAO.DeleteCategories(7); dAO.DeleteStores(9); my_logger.Info("******************** System shutdown"); }