public void AddItem() { Object temp = new object(); foreach (Window window in Application.Current.Windows) { if (window.GetType() == typeof(MainWindow)) { temp = (window as MainWindow).listboxItems.ItemsSource; } } if (temp != null) { WindowAddEdit window = new WindowAddEdit(); if (window.ShowDialog() == true) { if (temp is IEnumerable <Phone> ) { Phones.Add((Phone) new Phone().ShopToItem(window.view.OtherElectronics)); } else if (temp is IEnumerable <Laptop> ) { Laptops.Add((Laptop) new Laptop().ShopToItem(window.view.OtherElectronics)); } else if (temp is IEnumerable <TV> ) { TVs.Add((TV) new TV().ShopToItem(window.view.OtherElectronics)); } SaveChanges(); } } }
public void DelItem() { Object temp = new object(); foreach (Window window in Application.Current.Windows) { if (window.GetType() == typeof(MainWindow)) { temp = (window as MainWindow).listboxItems.SelectedItem; } } if (temp != null) { if (temp is Phone) { Phones.Remove((Phone)temp); } else if (temp is Laptop) { Laptops.Remove((Laptop)temp); } else if (temp is TV) { TVs.Remove((TV)temp); } SaveChanges(); } }
public List <Product> ParseXMLDataToProduct(Laptops data) { List <Product> elements = new List <Product>(); foreach (ProductXML laptop in data.laptops.laptop) { Product element = new Product(); element.Id = laptop.@id; element.Producent = laptop.manufacturer; element.Matryca = laptop.screen.size; element.Rozdzielczosc = laptop.screen.resolution; element.TypMatrycy = laptop.screen.type; element.DotykowyEkran = laptop.screen.@touch; element.CPU = laptop.processor.name; element.IloscRdzeni = laptop.processor.physical_cores; element.MHZ = laptop.processor.clock_speed; element.RAM = laptop.ram; element.PojemnoscDysku = laptop.disc.storage; element.RodzajDysku = laptop.disc.@type; element.GPU = laptop.graphic_card.name; element.VRAM = laptop.graphic_card.memory; element.SystemOperacyjny = laptop.os; element.NapedOptyczny = laptop.disc_reader; elements.Add(element); } return(elements); }
//public ActionResult PlaceOrder(int id) //{ // Laptops model = new Laptops(); // var laptop = context.laptop.Where(s => s.serialNo == id).ToList(); // if (laptop.Count > 0) // model = laptop[0]; // List<Laptops> lstOlddata = SessionHelper.GetObjectFromJson<List<Laptops>>(HttpContext.Session, "OrderPlacement"); // if (lstOlddata == null) // lstOlddata = new List<Laptops>(); // if (laptop.Count > 0) // lstOlddata.Add(model); // SessionHelper.SetObjectAsJson(HttpContext.Session, "OrderPlacement", lstOlddata); // return View(lstOlddata); //} public ActionResult PlaceOrder(int id, string val) { List <Laptops> lstOlddata = null; if (val == "Add") { Laptops model = new Laptops(); var laptop = context.laptop.Where(s => s.serialNo == id).ToList(); if (laptop.Count > 0) { model = laptop[0]; } lstOlddata = SessionHelper.GetObjectFromJson <List <Laptops> >(HttpContext.Session, "OrderPlacement"); if (lstOlddata == null) { lstOlddata = new List <Laptops>(); } if (laptop.Count > 0) { lstOlddata.Add(model); } SessionHelper.SetObjectAsJson(HttpContext.Session, "OrderPlacement", lstOlddata); // return View(lstOlddata); } else if (val == "Remove") { Laptops model = new Laptops(); lstOlddata = SessionHelper.GetObjectFromJson <List <Laptops> >(HttpContext.Session, "OrderPlacement"); if (lstOlddata.Count > 0) { var lapmodellst = lstOlddata.Where(item => item.serialNo == id).ToList(); if (lapmodellst.Count > 0) { Laptops lapmodel = lapmodellst[0]; lstOlddata.Remove(lapmodel); } } SessionHelper.SetObjectAsJson(HttpContext.Session, "OrderPlacement", lstOlddata); } else { lstOlddata = SessionHelper.GetObjectFromJson <List <Laptops> >(HttpContext.Session, "OrderPlacement"); if (lstOlddata == null) { lstOlddata = new List <Laptops>(); } } return(View(lstOlddata)); }
public ActionResult Index(int id) { string user = HttpContext.Session.GetString("LoginUser"); if (string.IsNullOrEmpty(user)) { TempData["ItemID"] = id; return(RedirectToAction("Login")); } else { Laptops model = _context.laptop.First(s => s.serialNo == id); return(View(model)); } }
public void OnGet() { var chuildPhoneCategory = _categoryRepository.GetSome(x => x.IsDeleted == false && x.ParentId == 1); foreach (var item in chuildPhoneCategory) { var phone = _itemRepository.GetByCategory(item.Id); foreach (var _phone in phone) { Phones.Add(_phone); } } var chuildLaptopCategory = _categoryRepository.GetSome(x => x.IsDeleted == false && x.ParentId == 2); foreach (var item in chuildLaptopCategory) { var laptop = _itemRepository.GetByCategory(item.Id); foreach (var _laptop in laptop) { Laptops.Add(_laptop); } } var chuildTabletCategory = _categoryRepository.GetSome(x => x.IsDeleted == false && x.ParentId == 3); foreach (var item in chuildTabletCategory) { var tablet = _itemRepository.GetByCategory(item.Id); foreach (var _tablet in tablet) { Tablets.Add(_tablet); } } var chuildAccessorieCategory = _categoryRepository.GetSome(x => x.IsDeleted == false && x.ParentId == 4); foreach (var item in chuildAccessorieCategory) { var accessorie = _itemRepository.GetByCategory(item.Id); foreach (var _accessorie in accessorie) { Accessories.Add(_accessorie); } } var cus = _userManager.GetUserAsync(HttpContext.User).Result; }
public Laptops ParseProductToXMLData(Product[] data) { var elements = new List <ProductXML>(); foreach (Product element in data) { ProductXML laptop = new ProductXML(); laptop.screen = new Screen(); laptop.disc = new Disc(); laptop.graphic_card = new GraphicCard(); laptop.processor = new Processor(); laptop.@id = element.Id; laptop.manufacturer = element.Producent; laptop.screen.size = element.Matryca; laptop.screen.resolution = element.Rozdzielczosc; laptop.screen.type = element.TypMatrycy; laptop.screen.@touch = element.DotykowyEkran; laptop.processor.name = element.CPU; laptop.processor.physical_cores = element.IloscRdzeni; laptop.processor.clock_speed = element.MHZ; laptop.ram = element.RAM; laptop.disc.storage = element.PojemnoscDysku; laptop.disc.@type = element.RodzajDysku; laptop.graphic_card.name = element.GPU; laptop.graphic_card.memory = element.VRAM; laptop.os = element.SystemOperacyjny; laptop.disc_reader = element.NapedOptyczny; elements.Add(laptop); } Laptops XMLData = new Laptops(); XMLData.laptops = new Laptop(); XMLData.laptops.laptop = new List <ProductXML>(); XMLData.laptops.laptop = elements; return(XMLData); }
public ActionResult ProceedToBuy(int id) { string user = HttpContext.Session.GetString("LoginUser"); if (string.IsNullOrEmpty(user)) { TempData["ItemID"] = id; return(RedirectToAction("Login", "AddToCart")); } else { Laptops model = new Laptops(); var laptop = context.laptop.Where(s => s.serialNo == id).ToList(); if (laptop.Count > 0) { model = laptop[0]; } List <Laptops> lstOlddata = SessionHelper.GetObjectFromJson <List <Laptops> >(HttpContext.Session, "OrderPlacement"); if (lstOlddata == null) { lstOlddata = new List <Laptops>(); } if (laptop.Count > 0) { lstOlddata.Add(model); } SessionHelper.SetObjectAsJson(HttpContext.Session, "OrderPlacement", lstOlddata); return(RedirectToAction("Index", "Checkout")); } }
public ApplicationContext() : base("DefaultConnection") { Phones.Load(); Laptops.Load(); //TVS.Load(); }
public BaseShop() : base("DefaultConnection") { Phones.Load(); Laptops.Load(); TVs.Load(); }
public static void AddLaptops() { Console.WriteLine("Вы хотите добавить laptop? y/n "); var key = Console.ReadKey(); Console.Write(key.Key); switch (key.Key) { case ConsoleKey.Y: { Laptops lap = new Laptops(); MySqlConnection connection = new MySqlConnection(lap.ConnectString); connection.Open(); // // string queryCount = "Select count(Id) from laptop"; // MySqlCommand count = new MySqlCommand(queryCount,connection); // string countStringTable = count.ExecuteScalar().ToString(); // lap.Id = Convert.ToInt32(countStringTable); Console.WriteLine("Введите название laptop"); lap.Name = Console.ReadLine(); Console.WriteLine("Введите вес laptop"); lap.Weigth = Convert.ToDecimal(Console.ReadLine()); Console.WriteLine("Введите цвет laptop"); lap.Color = Console.ReadLine(); Console.WriteLine("Введите производителя laptop"); lap.Producer = Console.ReadLine(); Console.WriteLine("Введите диагональ laptop"); lap.Screen = Convert.ToDecimal(Console.ReadLine()); Console.WriteLine("laptop содержит ssd - 1/0"); var d3 = Console.ReadKey(); switch (d3.Key) { case ConsoleKey.D1: { lap.Ssd = true; break; } case ConsoleKey.D0: { lap.Ssd = false; break; } } Console.WriteLine("laptop содержит touchbar? 1/0"); var Db = Console.ReadKey(); switch (Db.Key) { case ConsoleKey.D1: { lap.TouchBar = true; break; } case ConsoleKey.D0: { lap.TouchBar = false; break; } } string sql = $"INSERT INTO shop.laptop (Id,Name, Weigth, Color,Producer,Screen) VALUES ({lap.Id},'{lap.Name}', {lap.Weigth}, '{lap.Color}','{lap.Producer}',{lap.Screen})"; MySqlCommand command = new MySqlCommand(sql, connection); command.ExecuteNonQuery(); //возвращает числом кол-во строк которые модифицированын connection.Close(); // return lap; break; } case ConsoleKey.N: { Console.WriteLine("Заврешаем работу приложения"); // return null; break; } } }
public HttpResponseMessage Post(int id, Product[] sendData) { int i = 1; if (id == 1 && sendData == null) { var xmlPath = @"E:\STUDIA_III_SEMESTR\IntegracjaSystemowLab\Lab2\ReadWriteAppBE\ReadWriteAppBE\Resources\katalog.xml"; if (!File.Exists(xmlPath)) { var file = File.Create(xmlPath); StreamWriter sw = new StreamWriter(file); sw.WriteLine(sampleXML); sw.Close(); file.Close(); } XmlDocument doc = new XmlDocument(); doc.Load(xmlPath); string json = JsonConvert.SerializeXmlNode(doc); Laptops laptops = JsonConvert.DeserializeObject <Laptops>(json); List <Product> products = ParseXMLDataToProduct(laptops); return(new HttpResponseMessage() { Content = new StringContent(JArray.FromObject(products).ToString(), Encoding.UTF8, "application/json") }); } else if (id == 1 && sendData != null) { Laptops objectToSerialize = ParseProductToXMLData(sendData); using (StreamWriter myWriter = new StreamWriter(@"E:\STUDIA_III_SEMESTR\IntegracjaSystemowLab\Lab2\ReadWriteAppBE\ReadWriteAppBE\Resources\zapisane-dane.xml", false)) { XmlSerializer mySerializer = new XmlSerializer(typeof(Laptop)); mySerializer.Serialize(myWriter, objectToSerialize.laptops); } return(new HttpResponseMessage() { Content = new StringContent(JArray.FromObject(sendData).ToString(), Encoding.UTF8, "application/json") }); } else if (id == 2 && sendData == null) { var filePath = @"E:\STUDIA_III_SEMESTR\IntegracjaSystemowLab\Lab2\ReadWriteAppBE\ReadWriteAppBE\Resources\katalog.txt"; if (!File.Exists(filePath)) { var file = File.Create(filePath); StreamWriter sw = new StreamWriter(file); sw.WriteLine(sampleTXT); sw.Close(); file.Close(); } string[] lines = File.ReadAllLines(filePath); List <Product> products = new List <Product>(); foreach (string line in lines) { var element = line.Split(';'); Product product = new Product(); product.Id = i++; product.Producent = element[0]; product.Matryca = element[1]; product.Rozdzielczosc = element[2]; product.TypMatrycy = element[3]; product.DotykowyEkran = element[4]; product.CPU = element[5]; product.IloscRdzeni = element[6]; product.MHZ = element[7]; product.RAM = element[8]; product.PojemnoscDysku = element[9]; product.RodzajDysku = element[10]; product.GPU = element[11]; product.VRAM = element[12]; product.SystemOperacyjny = element[12]; product.NapedOptyczny = element[12]; products.Add(product); } return(new HttpResponseMessage() { Content = new StringContent(JArray.FromObject(products).ToString(), Encoding.UTF8, "application/json") }); } else if (id == 2 && sendData != null) { StringBuilder sb = new StringBuilder(""); foreach (Product data in sendData) { var dataElement = data.Producent + ";" + data.Matryca + ";" + data.Rozdzielczosc + ";" + data.TypMatrycy + ";" + data.DotykowyEkran + ";" + data.CPU + ";" + data.IloscRdzeni + ";" + data.MHZ + ";" + data.RAM + ";" + data.PojemnoscDysku + ";" + data.RodzajDysku + ";" + data.GPU + ";" + data.VRAM + ";" + data.SystemOperacyjny + ";" + data.NapedOptyczny + "; \n"; sb.Append(dataElement); } if (sb.ToString().Length > 10) { StreamWriter sw = new StreamWriter(@"E:\STUDIA_III_SEMESTR\IntegracjaSystemowLab\Lab2\ReadWriteAppBE\ReadWriteAppBE\Resources\zapisane-dane.txt"); sw.WriteLine(sb.ToString()); sw.Close(); } return(new HttpResponseMessage() { Content = new StringContent(JArray.FromObject(sendData).ToString(), Encoding.UTF8, "application/json") }); } //zapis do bazy else if (id == 3 && sendData != null) { DataTable tvp = new DataTable(); tvp.Columns.Add(new DataColumn("producent", typeof(string))); tvp.Columns.Add(new DataColumn("matryca", typeof(string))); tvp.Columns.Add(new DataColumn("rozdzielczosc", typeof(string))); tvp.Columns.Add(new DataColumn("typ_matrycy", typeof(string))); tvp.Columns.Add(new DataColumn("dotykowy_ekran", typeof(string))); tvp.Columns.Add(new DataColumn("cpu", typeof(string))); tvp.Columns.Add(new DataColumn("ilosc_rdzeni", typeof(string))); tvp.Columns.Add(new DataColumn("mhz", typeof(string))); tvp.Columns.Add(new DataColumn("ram", typeof(string))); tvp.Columns.Add(new DataColumn("pojemnosc_dysku", typeof(string))); tvp.Columns.Add(new DataColumn("rodzaj_dysku", typeof(string))); tvp.Columns.Add(new DataColumn("gpu", typeof(string))); tvp.Columns.Add(new DataColumn("vram", typeof(string))); tvp.Columns.Add(new DataColumn("system_operacyjny", typeof(string))); tvp.Columns.Add(new DataColumn("naped_optyczny", typeof(string))); foreach (var data in sendData) { tvp.Rows.Add(data.Producent, data.Matryca, data.Rozdzielczosc, data.TypMatrycy, data.DotykowyEkran, data.CPU, data.IloscRdzeni, data.MHZ, data.RAM, data.PojemnoscDysku, data.RodzajDysku, data.GPU, data.VRAM, data.SystemOperacyjny, data.NapedOptyczny); } using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand cmd = new SqlCommand("dbo.zapiszLaptopy", connection); cmd.CommandType = CommandType.StoredProcedure; SqlParameter tvparam = cmd.Parameters.AddWithValue("@lista", tvp); // these next lines are important to map the C# DataTable object to the correct SQL User Defined Type tvparam.SqlDbType = SqlDbType.Structured; tvparam.TypeName = "dbo.laptop"; var result = cmd.ExecuteReader(); connection.Close(); } return(new HttpResponseMessage() { Content = new StringContent(JArray.FromObject(sendData).ToString(), Encoding.UTF8, "application/json") }); } //odczyt z bazy else if (id == 3 && sendData == null) { List <Product> products = new List <Product>(); using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand cmd = new SqlCommand("dbo.pobierzLaptopy", connection); cmd.CommandType = CommandType.StoredProcedure; var result = cmd.ExecuteReader(); while (result.Read()) { Product product = new Product(); product.Id = int.Parse(result["id"].ToString()); product.Producent = result["producent"].ToString(); product.Matryca = result["matryca"].ToString(); product.Rozdzielczosc = result["rozdzielczosc"].ToString(); product.TypMatrycy = result["typ_matrycy"].ToString(); product.DotykowyEkran = result["dotykowy_ekran"].ToString(); product.CPU = result["cpu"].ToString(); product.IloscRdzeni = result["ilosc_rdzeni"].ToString(); product.MHZ = result["mhz"].ToString(); product.RAM = result["ram"].ToString(); product.PojemnoscDysku = result["pojemnosc_dysku"].ToString(); product.RodzajDysku = result["rodzaj_dysku"].ToString(); product.GPU = result["gpu"].ToString(); product.VRAM = result["vram"].ToString(); product.SystemOperacyjny = result["system_operacyjny"].ToString(); product.NapedOptyczny = result["naped_optyczny"].ToString(); products.Add(product); } connection.Close(); } return(new HttpResponseMessage() { Content = new StringContent(JArray.FromObject(products).ToString(), Encoding.UTF8, "application/json") }); } return(new HttpResponseMessage() { Content = new StringContent(null, Encoding.UTF8, "application/json") }); }