private void cleanStorage() { using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { string path = "Shared\\Media\\Pictures"; if (isolatedStorage.DirectoryExists(path)) { var fileNames = isolatedStorage.GetFileNames(string.Format("{0}\\*.jpg", path)).ToList(); foreach (var fileName in fileNames) { Debug.WriteLine(fileName); int indexPoint = fileName.IndexOf("."); string id = fileName.Remove(indexPoint); Debug.WriteLine(id); using (var ctx = new DiscountDataContext()) { var product = from c in ctx.Products where c.productID == id select c; if (product.Count() == 0) { Debug.WriteLine("deletion"); isolatedStorage.DeleteFile(string.Format("{0}\\{1}.jpg", path, id)); } } } } } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); string productID_; NavigationContext.QueryString.TryGetValue("id", out productID_); if (!string.IsNullOrEmpty(productID_)) { productID = productID_; tbID.Text = productID; DiscountDataContext db = new DiscountDataContext(); var lProduct = from c in db.Products where c.productID == productID select c; foreach (var prod_i in lProduct) { product = prod_i; } storeName = product.storeName; tbStoreName.Text = storeName; nameFile = product.productID; InitializeSettings(); tbProductName.Text += product.productName; tbOldPrice.Text = product.oldPrice + " р."; tbNewPrice.Text = product.newPrice + " р."; tbDiscount.Text = product.discount.ToString() + "%"; tbStartDate.Text = product.startDate; tbEndDate.Text = product.endDate; //lbProduct.ItemsSource = product; } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); string productID_; NavigationContext.QueryString.TryGetValue("id", out productID_); if (!string.IsNullOrEmpty(productID_) ) { productID = productID_; tbID.Text = productID; DiscountDataContext db = new DiscountDataContext(); var lProduct = from c in db.Products where c.productID == productID select c; foreach (var prod_i in lProduct) { product = prod_i; } storeName = product.storeName; tbStoreName.Text = storeName; nameFile = product.productID; InitializeSettings(); tbProductName.Text += product.productName; tbOldPrice.Text = product.oldPrice + " р."; tbNewPrice.Text = product.newPrice + " р."; tbDiscount.Text = product.discount.ToString() + "%"; tbStartDate.Text = product.startDate; tbEndDate.Text = product.endDate; //lbProduct.ItemsSource = product; } }
public SearchPage() { InitializeComponent(); using (var ctx = new DiscountDataContext()) { products = ctx.Products.ToList(); } }
public void LoadData() { using (var db = new DiscountDataContext()) { if (db.DatabaseExists() == false) { db.CreateDatabase(); } } var settings = IsolatedStorageSettings.ApplicationSettings; if (!settings.Contains("hash")) { settings.Add("hash", "0"); settings.Save(); } hash = settings["hash"].ToString(); if (!settings.Contains("isStoresDownloaded")) { settings.Add("isStoresDownloaded", false); settings.Save(); } wcfService.getHashCompleted += wcfService_GetHashCompleted; wcfService.getDiscountListCompleted += wcfService_GetDiscountListCompleted; wcfService.getStoreListCompleted += wcfService_GetStoreListCompleted; if (NetworkInterface.GetIsNetworkAvailable()) { if ((bool)settings["isStoresDownloaded"]) { loadStoreListFromDB(); wcfService.getHashAsync(); } else { wcfService.getStoreListAsync(); } } else if ((bool)settings["isStoresDownloaded"]) { loadStoreListFromDB(); bindingStoreData(); progress.Visibility = System.Windows.Visibility.Collapsed; } else { MessageBox.Show("Необходимо интернет-соединение!", "Выход", MessageBoxButton.OK); throw new ExitException(); } }
private void clearBuys() { using (var db = new DiscountDataContext()) { var res = from c in db.Buys select c; foreach (var r in res) { db.Buys.DeleteOnSubmit(r); } db.SubmitChanges(); InitializeSettings(); } }
private void loadStoreListFromDB() { DiscountDataContext db = new DiscountDataContext(); var lStores = from c in db.Stores select new CStore { storeID = c.storeID, storeName = c.storeName }; stores = lStores.ToList(); }
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) { using (var db = new DiscountDataContext()) { var lProducts = from c in db.Products where c.storeID == storeID orderby c.productTypeID select c; products = lProducts.ToList(); bindingProductData(); } }
private void delProduct_Click(object sender, RoutedEventArgs e) { using (var db = new DiscountDataContext()) { var res = from c in db.Buys where c.productID == productID select c; BuysTable buy = res.First(); //Debug.WriteLine(productID); db.Buys.DeleteOnSubmit(buy); db.SubmitChanges(); InitializeSettings(); } }
public void LoadData() { using (var db = new DiscountDataContext()) { if (db.DatabaseExists() == false) db.CreateDatabase(); } var settings = IsolatedStorageSettings.ApplicationSettings; if (!settings.Contains("hash")) { settings.Add("hash", "0"); settings.Save(); } hash = settings["hash"].ToString(); if (!settings.Contains("isStoresDownloaded")) { settings.Add("isStoresDownloaded", false); settings.Save(); } wcfService.getHashCompleted += wcfService_GetHashCompleted; wcfService.getDiscountListCompleted += wcfService_GetDiscountListCompleted; wcfService.getStoreListCompleted += wcfService_GetStoreListCompleted; if (NetworkInterface.GetIsNetworkAvailable()) { if ((bool)settings["isStoresDownloaded"]) { loadStoreListFromDB(); wcfService.getHashAsync(); } else wcfService.getStoreListAsync(); } else if ((bool)settings["isStoresDownloaded"]) { loadStoreListFromDB(); bindingStoreData(); progress.Visibility = System.Windows.Visibility.Collapsed; } else { MessageBox.Show("Необходимо интернет-соединение!", "Выход", MessageBoxButton.OK); throw new ExitException(); } }
private void addProduct_Click(object sender, RoutedEventArgs e) { using (var db = new DiscountDataContext()) { var res = from c in db.Buys where c.productID == productID select c; if (res.Count() == 0) { BuysTable buy = new BuysTable(); buy.productID = productID; db.Buys.InsertOnSubmit(buy); db.SubmitChanges(); } } }
private void InitializeSettings() { progress.Visibility = System.Windows.Visibility.Visible; using (var db = new DiscountDataContext()) { buys.Clear(); List <BuysTable> b = db.Buys.ToList(); foreach (var buy in b) { var product = from c in db.Products where c.productID == buy.productID select c; buys.Add(product.First()); } } lbBuys.ItemsSource = null; lbBuys.ItemsSource = buys; progress.Visibility = System.Windows.Visibility.Collapsed; }
private void saveDBStoresLocally() { DiscountDataContext db = new DiscountDataContext(); var lStores = from c in db.Stores select c; foreach (var i in lStores) { db.Stores.DeleteOnSubmit(i); } db.SubmitChanges(); foreach (CStore store_i in stores) { var store = new StoresTable(); store.storeID = store_i.storeID; store.storeName = store_i.storeName; db.Stores.InsertOnSubmit(store); } db.SubmitChanges(); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); string storeID_; NavigationContext.QueryString.TryGetValue("id", out storeID_); using (DiscountDataContext db = new DiscountDataContext()) { if (!string.IsNullOrEmpty(storeID_)) { storeID = Convert.ToInt32(storeID_); var storeName_ = from c in db.Stores where c.storeID == storeID select c; storeName = storeName_.First().storeName; tbStoreName.Text = storeName; } else { MessageBox.Show("Ошибка перехода на страницу: " + storeTitle.Text); storeTitle.Text = "ошибка"; } var settings = IsolatedStorageSettings.ApplicationSettings; } }
private void saveBuy() { using (var db = new DiscountDataContext()) { var res = from c in db.Buys where c.productID == productID select c; if (res.Count() == 0) { BuysTable buy = new BuysTable(); buy.productID = productID; db.Buys.InsertOnSubmit(buy); db.SubmitChanges(); popupMsgText.Text = "Добавлено"; showPopup(); } else { popupMsgText.Text = "Уже есть в списке покупок"; showPopup(); } } }
private void saveDBProductsLocally() { using (DiscountDataContext db = new DiscountDataContext()) { var lProducts = from c in db.Products select c; foreach (var i in lProducts) { db.Products.DeleteOnSubmit(i); } db.SubmitChanges(); foreach (CProduct prod_i in products) { var product = new ProductsTable(); product.productID = prod_i.productID; product.productName = prod_i.productName; product.storeID = prod_i.storeID; product.storeName = prod_i.storeName; product.productTypeID = prod_i.productsTypeID; product.productType = prod_i.productsType; product.discount = prod_i.discount; product.oldPrice = prod_i.oldPrice; product.newPrice = prod_i.newPrice; product.startDate = prod_i.startDate; product.endDate = prod_i.endDate; product.imageURL = prod_i.imageURL; db.Products.InsertOnSubmit(product); } db.SubmitChanges(); } cleanStorage(); }
private void cleanStorage() { using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { string path = "Shared\\Media\\Pictures"; if (isolatedStorage.DirectoryExists(path)) { var fileNames = isolatedStorage.GetFileNames(string.Format("{0}\\*.jpg",path)).ToList(); foreach (var fileName in fileNames) { Debug.WriteLine(fileName); int indexPoint = fileName.IndexOf("."); string id = fileName.Remove(indexPoint); Debug.WriteLine(id); using (var ctx = new DiscountDataContext()) { var product = from c in ctx.Products where c.productID == id select c; if (product.Count() == 0) { Debug.WriteLine("deletion"); isolatedStorage.DeleteFile(string.Format("{0}\\{1}.jpg", path, id)); } } } } } }
private void InitializeSettings() { progress.Visibility = System.Windows.Visibility.Visible; using (var db = new DiscountDataContext()) { buys.Clear(); List<BuysTable> b = db.Buys.ToList(); foreach (var buy in b) { var product = from c in db.Products where c.productID == buy.productID select c; buys.Add(product.First()); } } lbBuys.ItemsSource = null; lbBuys.ItemsSource = buys; progress.Visibility = System.Windows.Visibility.Collapsed; }