private HtmlGenericControl generateDevice(Device device, DatabaseEntities db) { var brandQuery = db.Brands.Where(b => b.brand_id == device.brand_id); var brand = brandQuery.FirstOrDefault<Brand>(); var operatingSystemQuery = db.OperatingSystems.Where(b => b.operating_system_id == device.operating_system_id); var operatingSystem = operatingSystemQuery.FirstOrDefault<OperatingSystem>(); var displayQuery = db.Displays.Where(b => b.display_id == device.display_id); var display = displayQuery.FirstOrDefault<Display>(); HtmlGenericControl deviceDiv = new HtmlGenericControl("DIV"); deviceDiv.Attributes["class"] = "device"; //HtmlGenericControl anchorFirst = new HtmlGenericControl("a"); HtmlAnchor anchorFirst = new HtmlAnchor(); anchorFirst.HRef = String.Format("~/device.aspx?id={0}", device.device_id); HtmlImage img = new HtmlImage(); img.Src = String.Format("~/images/{0}/{1} {2} .jpg", brand.name, brand.name, device.device_name); anchorFirst.Controls.Add(img); HtmlGenericControl h2 = new HtmlGenericControl("h2"); //HtmlGenericControl anchorSecond = new HtmlGenericControl("a"); HtmlAnchor anchorSecond = new HtmlAnchor(); anchorSecond.HRef = String.Format("~/device.aspx?id={0}", device.device_id); anchorSecond.InnerText = String.Format("{0} {1}", brand.name, device.device_name); h2.Controls.Add(anchorSecond); HtmlGenericControl p = new HtmlGenericControl("p"); p.InnerText = String.Format("{0}, экран {1}, {2} ( {3} ), ОЗУ {4}, аккумулятор {5}", operatingSystem.name, device.screen_size, display.type, device.screen_resolution, device.ram, device.battery_capacity); HtmlGenericControl clrDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV"); clrDiv.Attributes["class"] = "clr"; HtmlGenericControl priceDiv = new HtmlGenericControl("DIV"); priceDiv.Attributes["class"] = "price"; priceDiv.InnerText = String.Format("{0}", device.price); deviceDiv.Controls.Add(anchorFirst); deviceDiv.Controls.Add(h2); deviceDiv.Controls.Add(p); deviceDiv.Controls.Add(clrDiv); deviceDiv.Controls.Add(priceDiv); return deviceDiv; }
protected void Page_Load(object sender, EventArgs e) { this.requestedDevice = Request.QueryString["id"]; if (this.requestedDevice != null) { device_id = Int16.Parse(requestedDevice); DatabaseEntities db = new DatabaseEntities(); var deviceQuery = db.Devices.Where(b => b.device_id == this.device_id); var device = deviceQuery.FirstOrDefault<Device>(); content.Controls.Add(generateDevice(device, db)); loadSideBar(device, db); loadDevicePath(device, db); } }
private HtmlGenericControl generateDevice(Device device, DatabaseEntities db) { var brandQuery = db.Brands.Where(b => b.brand_id == device.brand_id); var brand = brandQuery.FirstOrDefault<Brand>(); var batteryQuery = db.Batteries.Where(b => b.battery_id == device.battery_id); var battery = batteryQuery.FirstOrDefault<Battery>(); var displayQuery = db.Displays.Where(b => b.display_id == device.display_id); var display = displayQuery.FirstOrDefault<Display>(); var operatingSystemQuery = db.OperatingSystems.Where(b => b.operating_system_id == device.operating_system_id); var operatingSystem = operatingSystemQuery.FirstOrDefault<OperatingSystem>(); var processorQuery = db.Processors.Where(b => b.processor_id == device.processor_id); var processor = processorQuery.FirstOrDefault<Processor>(); var flashToDeviceQuery = db.FlashToDevices.Where(b => b.device_id == device.device_id); List<FlashToDevice> flashToDeviceList = flashToDeviceQuery.ToList<FlashToDevice>(); string flashTypes = ""; foreach (FlashToDevice type in flashToDeviceList) { var flashQuery = db.Flashes.Where(b => b.flash_id == type.flash_id); var flash = flashQuery.FirstOrDefault<Flash>(); flashTypes += flash.type + " "; } if (flashTypes.Trim() == "") flashTypes = "Отсутсвует"; HtmlGenericControl result = new HtmlGenericControl("div"); HtmlGenericControl descriptionDiv = new HtmlGenericControl("div"); descriptionDiv.Attributes["class"] = "device"; HtmlImage img = new HtmlImage(); img.Src = String.Format("~/images/{0}/{1} {2} .jpg", brand.name, brand.name, device.device_name); HtmlGenericControl h2 = new HtmlGenericControl("h2"); h2.InnerText = "Описание"; HtmlGenericControl pAboutBrand = new HtmlGenericControl("p"); pAboutBrand.InnerText = String.Format("{0}", brand.information); //HtmlGenericControl pShortInformation = new HtmlGenericControl("p"); //pShortInformation.InnerText = String.Format("{0}, экран {1}, {2} ( {3} ), ОЗУ {4}, аккумулятор {5}", // operatingSystem.name, device.screen_size, display.type, device.screen_resolution, device.ram, device.battery_capacity); HtmlGenericControl clrDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV"); clrDiv.Attributes["class"] = "clr"; HtmlGenericControl priceDiv = new HtmlGenericControl("DIV"); priceDiv.Attributes["class"] = "price"; priceDiv.InnerText = String.Format("{0}", device.price); descriptionDiv.Controls.Add(img); descriptionDiv.Controls.Add(h2); descriptionDiv.Controls.Add(pAboutBrand); //descriptionDiv.Controls.Add(pShortInformation); descriptionDiv.Controls.Add(clrDiv); descriptionDiv.Controls.Add(priceDiv); HtmlGenericControl h2Descr = new HtmlGenericControl("h2"); h2Descr.InnerText = "Характеристики"; result.Controls.Add(descriptionDiv); result.Controls.Add(h2Descr); HtmlGenericControl tableGeneral = new HtmlGenericControl("table"); string[] keysGeneral = { "Производитель", "Операционная система", "Год выпуска"}; string[] valuesGeneral = { brand.name, operatingSystem.name, device.release_year }; tableGeneral = createTable("Общее", keysGeneral, valuesGeneral); result.Controls.Add(tableGeneral); HtmlGenericControl tableDisplay = new HtmlGenericControl("table"); string[] keysDisplay = { "Тип дисплея", "Размер экрана", "Разрешение экрана", "Информация о техологии дисплея"}; string[] valuesDisplay = { display.type, device.screen_size, device.screen_resolution, display.information }; tableDisplay = createTable("Дисплей", keysDisplay, valuesDisplay); result.Controls.Add(tableDisplay); HtmlGenericControl tableProcessor = new HtmlGenericControl("table"); string[] keysProcessor = { "Тип процессора" }; string[] valuesProcessor = new string[1]; if (processor == null) valuesProcessor[0] = "Неизвестно"; else valuesProcessor[0] = processor.name; tableProcessor = createTable("Процессор", keysProcessor, valuesProcessor); result.Controls.Add(tableProcessor); HtmlGenericControl tableMemory = new HtmlGenericControl("table"); string[] keysMemory = { "Оперативная память", "Встроенная память", "Поддержка карт памяти" }; string[] valuesMemory = { device.ram, device.internal_memory, flashTypes}; tableMemory = createTable("Память", keysMemory, valuesMemory); result.Controls.Add(tableMemory); HtmlGenericControl tableBattery = new HtmlGenericControl("table"); string[] keysBattery = { "Тип батареи", "Eмкость батареи", "Информация о технологии батареи" }; string[] valuesBatery = { battery.type, device.battery_capacity, battery.information }; tableBattery = createTable("Батарея", keysBattery, valuesBatery); result.Controls.Add(tableBattery); return result; }
private void loadSideBar(Device device, DatabaseEntities db) { var brandQuery = db.Brands.Where(b => b.brand_id == device.brand_id); var brand = brandQuery.FirstOrDefault<Brand>(); HtmlGenericControl title = new HtmlGenericControl("div"); //HtmlGenericControl a = new HtmlGenericControl("a"); HtmlAnchor a = new HtmlAnchor(); a.HRef = String.Format("~/?brand={0}", brand.name); a.InnerText = brand.name; title.Attributes["class"] = "title"; title.Controls.Add(a); HtmlGenericControl ul = new HtmlGenericControl("ul"); List<Device> devicesList = db.Devices.Where(b => b.brand_id == device.brand_id).ToList<Device>(); foreach (Device item in devicesList) { HtmlGenericControl li = new HtmlGenericControl("li"); //HtmlGenericControl anchor = new HtmlGenericControl("a"); HtmlAnchor anchor = new HtmlAnchor(); anchor.HRef = String.Format("~/Device.aspx?id={0}", item.device_id); anchor.InnerText = String.Format("{0}", item.device_name); li.Controls.Add(anchor); ul.Controls.Add(li); } sidebar.Controls.Add(title); sidebar.Controls.Add(ul); }
private void loadDevicePath(Device device, DatabaseEntities db) { var brandQuery = db.Brands.Where(b => b.brand_id == device.brand_id); var brand = brandQuery.FirstOrDefault<Brand>(); HtmlImage firstArrow = new HtmlImage(); firstArrow.Src = "~/images/directory_arrow.png"; HtmlGenericControl brandDiv = new HtmlGenericControl("div"); brandDiv.Attributes["class"] = "directory_path"; //HtmlGenericControl brandAnchor = new HtmlGenericControl("a"); HtmlAnchor brandAnchor = new HtmlAnchor(); brandAnchor.HRef = "~/?brand=" + brand.name; brandAnchor.Attributes["id"] = "firstDirectory"; brandAnchor.InnerText = brand.name; brandDiv.Controls.Add(brandAnchor); HtmlImage secondArrow = new HtmlImage(); secondArrow.Src = "~/images/directory_arrow.png"; HtmlGenericControl deviceDiv = new HtmlGenericControl("div"); deviceDiv.Attributes["class"] = "directory_path"; //HtmlGenericControl deviceAnchor = new HtmlGenericControl("a"); HtmlAnchor deviceAnchor = new HtmlAnchor(); deviceAnchor.HRef = "~/Device.aspx?id=" + device.device_id; deviceAnchor.Attributes["id"] = "secondDirectory"; deviceAnchor.InnerText = device.device_name; deviceDiv.Controls.Add(deviceAnchor); path.Controls.Add(firstArrow); path.Controls.Add(brandDiv); path.Controls.Add(secondArrow); path.Controls.Add(deviceDiv); }
private void loadContent() { this.requestedPage = Request.QueryString["page"]; this.requestedBrand = Request.QueryString["brand"]; int lastPage = 1; if (requestedPage == null) pageIndex = 1; else pageIndex = Int16.Parse(Request.QueryString["page"]); pageIndex -= 1; if (requestedBrand == null) { DatabaseEntities db = new DatabaseEntities(); var deviceQuery = db.Devices; List<Device> list = deviceQuery.ToList<Device>(); for (int deviceIndex = pageIndex * devicePerPage; deviceIndex < pageIndex * devicePerPage + devicePerPage; deviceIndex++) { if (deviceIndex > list.Count - 1) break; if (list[deviceIndex] != null) content.Controls.Add(this.generateDevice(list[deviceIndex], db)); } if (list.Count / devicePerPage > 1) { if (list.Count % devicePerPage != 0) lastPage = list.Count / devicePerPage + 1; else lastPage = list.Count / devicePerPage; } loadPageButtons(lastPage); } else { DatabaseEntities db = new DatabaseEntities(); var brandQuery = db.Brands.Where(b => b.name == requestedBrand); var brand = brandQuery.FirstOrDefault<Brand>(); var deviceQuery = db.Devices.Where(b => b.brand_id == brand.brand_id); List<Device> list = deviceQuery.ToList<Device>(); for (int deviceIndex = pageIndex * devicePerPage; deviceIndex < pageIndex * devicePerPage + devicePerPage; deviceIndex++) { if (deviceIndex > list.Count - 1) break; if (list[deviceIndex] != null) content.Controls.Add(this.generateDevice(list[deviceIndex], db)); } if (list.Count / devicePerPage > 1) { if (list.Count % devicePerPage != 0) lastPage = list.Count / devicePerPage + 1; else lastPage = list.Count / devicePerPage; } loadDevicePath(brand, db); loadPageButtons(lastPage); } }
private void loadSideBar() { DatabaseEntities db = new DatabaseEntities(); foreach(Brand brand in db.Brands) { HtmlGenericControl li = new HtmlGenericControl("li"); //HtmlGenericControl anchor = new HtmlGenericControl("a"); HtmlAnchor anchor = new HtmlAnchor(); anchor.HRef = String.Format("~/?brand={0}", brand.name); anchor.InnerText = String.Format("{0}", brand.name); li.Controls.Add(anchor); brandList.Controls.Add(li); } }
private void loadDevicePath(Brand brand, DatabaseEntities db) { HtmlImage firstArrow = new HtmlImage(); firstArrow.Src = "~/images/directory_arrow.png"; HtmlGenericControl brandDiv = new HtmlGenericControl("div"); brandDiv.Attributes["class"] = "directory_path"; //HtmlGenericControl brandAnchor = new HtmlGenericControl("a"); HtmlAnchor brandAnchor = new HtmlAnchor(); brandAnchor.HRef = "~/?brand=" + brand.name; brandAnchor.Attributes["id"] = "firstDirectory"; brandAnchor.InnerText = brand.name; brandDiv.Controls.Add(brandAnchor); path.Controls.Add(firstArrow); path.Controls.Add(brandDiv); }
protected void submitButton_Click(object sender, EventArgs e) { if (Page.IsValid) { string[] requestKeys = { "brandOption", "releaseYear", "priceFrom", "priceTill", "displayOption", "displaySizeFrom", "displaySizeTill", "screenSizesOption", "ramFrom", "ramTill", "memoryFrom", "memoryTill", "flashTypeOption", "batteryTypeOption", "batteryFrom", "batteryTill" }; searchOptions = new Dictionary<string, string>(); foreach (string key in requestKeys) { string requestValue = Request.Form[key]; if (requestValue == null || requestValue == "" || requestValue == "Любой" || requestValue == "Любое" || requestValue == "Все") continue; searchOptions.Add(key, requestValue); } DatabaseEntities db = new DatabaseEntities(); List<Device> deviceList = db.Devices.ToList<Device>(); Brand brand = null; Display display = null; Flash flash = null; Battery battery = null; string value = null; if (searchOptions.ContainsKey("brandOption")) { value = searchOptions["brandOption"]; brand = db.Brands.Where(b => b.name == value).FirstOrDefault<Brand>(); } if (searchOptions.ContainsKey("displayOption")) { value = searchOptions["displayOption"]; display = db.Displays.Where(b => b.type == value).FirstOrDefault<Display>(); } if (searchOptions.ContainsKey("flashTypeOption")) { value = searchOptions["flashTypeOption"]; flash = db.Flashes.Where(b => b.type == value).FirstOrDefault<Flash>(); } if (searchOptions.ContainsKey("batteryTypeOption")) { value = searchOptions["batteryTypeOption"]; battery = db.Batteries.Where(b => b.type == value).FirstOrDefault<Battery>(); } if (flash != null && deviceList.Count > 0) { List<FlashToDevice> flashToDeviceList = db.FlashToDevices.Where(b => b.flash_id == flash.flash_id).ToList<FlashToDevice>(); //deviceList = flashToDeviceList.Where(b => b.flash_id == flash.flash_id).ToList<Device>(); deviceList.Clear(); foreach (FlashToDevice device in flashToDeviceList) { var data = db.Devices.Where(b => b.device_id == device.device_id).FirstOrDefault<Device>(); deviceList.Add(data); } } if (brand != null && deviceList.Count > 0) deviceList = deviceList.Where(b => b.brand_id == brand.brand_id).ToList<Device>(); if (display != null && deviceList.Count > 0) deviceList = deviceList.Where(b => b.display_id == display.display_id).ToList<Device>(); if (battery != null && deviceList.Count > 0) deviceList = deviceList.Where(b => b.battery_id == battery.battery_id).ToList<Device>(); if (searchOptions.ContainsKey("releaseYear")) { value = searchOptions["releaseYear"]; List<Device> buff = new List<Device>(); foreach (Device device in deviceList) { string releaseYear = device.release_year; releaseYear = releaseYear.Replace("г.", string.Empty); releaseYear = Regex.Replace(releaseYear, @"\s+", ""); if (Int32.Parse(releaseYear) == Int32.Parse(value)) buff.Add(device); } deviceList.Clear(); deviceList = buff; } if (searchOptions.ContainsKey("priceFrom")) { value = searchOptions["priceFrom"]; List<Device> buff = new List<Device>(); foreach (Device device in deviceList) { string price = device.price; price = price.Replace("руб.", string.Empty); price = Regex.Replace(price, @"\s+", ""); if (Int32.Parse(price) >= Int32.Parse(value)) buff.Add(device); } deviceList.Clear(); deviceList = buff; } if (searchOptions.ContainsKey("priceTill")) { value = searchOptions["priceTill"]; List<Device> buff = new List<Device>(); foreach (Device device in deviceList) { string price = device.price; price = price.Replace("руб.", string.Empty); price = Regex.Replace(price, @"\s+", ""); if (Int32.Parse(price) <= Int32.Parse(value)) buff.Add(device); } deviceList.Clear(); deviceList = buff; } if (searchOptions.ContainsKey("displaySizeFrom")) { value = searchOptions["displaySizeFrom"]; List<Device> buff = new List<Device>(); foreach (Device device in deviceList) { string screen_size = device.screen_size; screen_size = screen_size.Replace("\"", string.Empty); if (Double.Parse(screen_size) >= Double.Parse(value)) buff.Add(device); } deviceList.Clear(); deviceList = buff; } if (searchOptions.ContainsKey("displaySizeTill")) { value = searchOptions["displaySizeTill"]; List<Device> buff = new List<Device>(); foreach (Device device in deviceList) { string screen_size = device.screen_size; screen_size = screen_size.Replace("\"", string.Empty); if (Double.Parse(screen_size) <= Double.Parse(value)) buff.Add(device); } deviceList.Clear(); deviceList = buff; } if (searchOptions.ContainsKey("screenSizesOption")) { value = searchOptions["screenSizesOption"]; deviceList = deviceList.Where(b => b.screen_resolution == value).ToList<Device>(); } if (searchOptions.ContainsKey("ramFrom")) { value = searchOptions["ramFrom"]; List<Device> buff = new List<Device>(); foreach (Device device in deviceList) { string ram = device.ram; ram = ram.Replace("ГБ", string.Empty); ram = Regex.Replace(ram, @"\s+", ""); if (Double.Parse(ram) >= Double.Parse(value)) buff.Add(device); } deviceList.Clear(); deviceList = buff; } if (searchOptions.ContainsKey("ramTill")) { value = searchOptions["ramTill"]; List<Device> buff = new List<Device>(); foreach (Device device in deviceList) { string ram = device.ram; ram = ram.Replace("ГБ", string.Empty); ram = Regex.Replace(ram, @"\s+", ""); if (Double.Parse(ram) <= Double.Parse(value)) buff.Add(device); } deviceList.Clear(); deviceList = buff; } if (searchOptions.ContainsKey("memoryFrom")) { value = searchOptions["memoryFrom"]; List<Device> buff = new List<Device>(); foreach (Device device in deviceList) { string memory = device.internal_memory; memory = memory.Replace("ГБ", string.Empty); memory = Regex.Replace(memory, @"\s+", ""); if (Double.Parse(memory) >= Double.Parse(value)) buff.Add(device); } deviceList.Clear(); deviceList = buff; } if (searchOptions.ContainsKey("memoryTill")) { value = searchOptions["memoryTill"]; List<Device> buff = new List<Device>(); foreach (Device device in deviceList) { string memory = device.internal_memory; memory = memory.Replace("ГБ", string.Empty); memory = Regex.Replace(memory, @"\s+", ""); if (Double.Parse(memory) <= Double.Parse(value)) buff.Add(device); } deviceList.Clear(); deviceList = buff; } if (searchOptions.ContainsKey("batteryFrom")) { value = searchOptions["batteryFrom"]; List<Device> buff = new List<Device>(); foreach (Device device in deviceList) { string batteryCapacity = device.battery_capacity; batteryCapacity = batteryCapacity.Replace("мА·ч", string.Empty); batteryCapacity = Regex.Replace(batteryCapacity, @"\s+", ""); if (Double.Parse(batteryCapacity) >= Double.Parse(value)) buff.Add(device); } deviceList.Clear(); deviceList = buff; } if (searchOptions.ContainsKey("batteryTill")) { value = searchOptions["batteryTill"]; List<Device> buff = new List<Device>(); foreach (Device device in deviceList) { string batteryCapacity = device.battery_capacity; batteryCapacity = batteryCapacity.Replace("мА·ч", string.Empty); batteryCapacity = Regex.Replace(batteryCapacity, @"\s+", ""); if (Double.Parse(batteryCapacity) <= Double.Parse(value)) buff.Add(device); } deviceList.Clear(); deviceList = buff; } if (deviceList.Count == 0) { HtmlGenericControl noResultsFound = new HtmlGenericControl("div"); noResultsFound.Attributes["class"] = "noResult"; noResultsFound.InnerText = "Ничего не найдено"; content.Controls.Add(noResultsFound); } else foreach (Device device in deviceList) { content.Controls.Add(generateDevice(device, db)); } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DatabaseEntities db = new DatabaseEntities(); loadOptions(db); } }
private void loadOptions(DatabaseEntities db) { List<Brand> brandList = db.Brands.ToList<Brand>(); List<Display> displayList = db.Displays.ToList<Display>(); List<Battery> batteryTypeList = db.Batteries.ToList<Battery>(); List<Flash> flashTypeList = db.Flashes.ToList<Flash>(); List<Device> deviceList = db.Devices.ToList<Device>(); brandOption.Items.Add("Все"); foreach(Brand brand in brandList) brandOption.Items.Add(brand.name); displayOption.Items.Add("Любой"); foreach (Display display in displayList) displayOption.Items.Add(display.type); flashTypeOption.Items.Add("Любой"); foreach (Flash flash in flashTypeList) flashTypeOption.Items.Add(flash.type); batteryTypeOption.Items.Add("Любой"); foreach (Battery battery in batteryTypeList) batteryTypeOption.Items.Add(battery.type); releaseYear.Items.Add("Любой"); for (int year = 2015; year > 2009; year--) releaseYear.Items.Add(year.ToString()); List<string> typesList = new List<string>(); typesList.Add("Любое"); bool toSkip = false; foreach (Device device in deviceList) { foreach (string data in typesList) { if (data == device.screen_resolution) { toSkip = true; break; } } if (toSkip) { toSkip = false; continue; } else { typesList.Add(device.screen_resolution); } } HtmlGenericControl li = new HtmlGenericControl("li"); CheckBox checkbox = new CheckBox(); foreach (string data in typesList) { screenSizesOption.Items.Add(data); } }