private async void btnAddProducImgs_Click(object sender, RoutedEventArgs e) { FileOpenPicker openPicker = new FileOpenPicker(); openPicker.SuggestedStartLocation = PickerLocationId.Desktop; openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".png"); //FileData var openFile = await openPicker.PickMultipleFilesAsync(); if (openFile != null) { foreach (var item in openFile) { var Product_Images = new Product_Images() { Name = item.Path }; Product.Product_Images.Add(Product_Images); test.Add(Product_Images); } this.DataContext = Product; lvManyImg.ItemsSource = null; lvManyImg.ItemsSource = test; } }
public UpdateUserControl(Product product) { this.InitializeComponent(); Product = product; try { //Load Product_Images List <Product_Images> img = new List <Product_Images>(); DataTable images = QueryForSQLServer.GetProducts_Image(Product.Id); foreach (DataRow item in images.Rows) { var Product_Images = new Product_Images() { id = (int)item.ItemArray[0], ProductId = (int)item.ItemArray[1], Name = (string)item.ItemArray[2] }; img.Add(Product_Images); } Product.Product_Images = img; lvManyImg.ItemsSource = img; } catch (Exception ex) { Debug.WriteLine("ex: " + ex.Message); } this.DataContext = Product; var categoriesList = PageHome.GetCategoriesFromDb(); cbbListType.ItemsSource = categoriesList; cbbListType.SelectedIndex = (int)product.CatId - 1; //back SystemNavigationManager manager = SystemNavigationManager.GetForCurrentView(); manager.BackRequested += DetailPage_BackRequested; manager.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; }
public static int InsertProduct_Image(Product_Images product_Images) { const string Query = "insert into Product_Images(Id,ProductId,Name) values(@Id,@ProductId,@Name)"; Provider p = new Provider(); int id = -1; try { DataTable dt; p.Connect(); p.ExcecuteQuery(CommandType.Text, Query, new SqlParameter { ParameterName = "@Id", Value = product_Images.id }, new SqlParameter { ParameterName = "@ProductId", Value = product_Images.ProductId }, new SqlParameter { ParameterName = "@Name", Value = product_Images.Name } ); dt = p.ExcecuteQuery(CommandType.Text, "select @@IDENTITY"); //id = (int)dt.Rows[0].ItemArray[0]; return(id); } catch (Exception eSql) { Debug.WriteLine("Exception: " + eSql.Message); } finally { p.DisConnect(); } return(0); }
public DetailsUserControl(Product product) { if (product != null) { this.InitializeComponent(); this.DataContext = product; pageInfo.DataContext = "1"; objProduct = product; List <Product_Images> img = new List <Product_Images>(); DataTable images = QueryForSQLServer.GetProducts_Image(product.Id); foreach (DataRow item in images.Rows) { var Product_Images = new Product_Images() { id = (int)item.ItemArray[0], ProductId = (int)item.ItemArray[1], Name = (string)item.ItemArray[2] }; img.Add(Product_Images); } lvManyImg.ItemsSource = img; //back SystemNavigationManager manager = SystemNavigationManager.GetForCurrentView(); manager.BackRequested += DetailPage_BackRequested; manager.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; } else { this.Visibility = Visibility.Collapsed; } }
private async void Import_Detail_Images_Click(object sender, RoutedEventArgs e) { ExcelEngine excelEngine = new ExcelEngine(); IApplication application = excelEngine.Excel; //Instantiates the File Picker. try { FileOpenPicker openPicker = new FileOpenPicker(); openPicker.SuggestedStartLocation = PickerLocationId.Desktop; openPicker.FileTypeFilter.Add(".xlsx"); openPicker.FileTypeFilter.Add(".xls"); StorageFile openFile = await openPicker.PickSingleFileAsync(); //Opens the workbook. IWorkbook workbook = await application.Workbooks.OpenAsync(openFile); //Access first worksheet from the workbook. var tabs = workbook.Worksheets; //Sets workbook version. workbook.Version = ExcelVersion.Excel2016; //Initializes FileSavePicker. FileSavePicker savePicker = new FileSavePicker(); List <Product_Images> list = new List <Product_Images>(); foreach (var tab in tabs) { Debug.WriteLine(tab.Name); var row = 3; var product = new Product() { Name = tab.Name }; tab.UsedRangeIncludesFormatting = false; var cell = tab.Range[$"C3"]; while (cell.Value != null && !cell.IsBlank) { var image = tab.Range[$"B{row}"].Text; var name = tab.Range[$"C{row}"].Text; var ImageId = (int)QueryForSQLServer.GetProductsByImage(image).Rows[0].ItemArray[0]; var product_image = new Product_Images() { ProductId = ImageId, Name = name }; Debug.WriteLine($"{image}{name}"); list.Add(product_image); // Đi qua dòng kế row++; cell = tab.Range[$"C{row}"]; } } workbook.Close(); excelEngine.Dispose(); var messageDialog = new MessageDialog("Import", "Confirm"); messageDialog.Commands.Add(new UICommand("Yes") { Id = 0 }); messageDialog.Commands.Add(new UICommand("No") { Id = 1 }); messageDialog.DefaultCommandIndex = 0; messageDialog.CancelCommandIndex = 1; var result = await messageDialog.ShowAsync(); if ((int)result.Id == 0) { var i = QueryForSQLServer.GetProducts_ImageMaxId(list[0].ProductId) + 1; var preProduct = list[0].ProductId; foreach (var img in list) { if (img.ProductId != preProduct) { i = QueryForSQLServer.GetProducts_ImageMaxId(img.ProductId) + 1; } img.id = i; preProduct = img.ProductId; QueryForSQLServer.InsertProduct_Image(img); Debug.WriteLine(img.id + img.Name + img.ProductId); i++; } var messageDialog2 = await new MessageDialog("Success", "Confirm").ShowAsync(); } else { } } catch (Exception ex) { Debug.WriteLine("Exception: " + ex.Message); } }