コード例 #1
0
        private async void btnDone_Click(object sender, RoutedEventArgs e)
        {
            var messageDialog = new MessageDialog("Save your change ???");

            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)
            {
                Product.Price    = Decimal.Parse(addGia.Text);
                Product.Quantity = int.Parse(addSoLuong.Text);
                QueryForSQLServer.UpdateProduct(Product);

                //delete then insert
                QueryForSQLServer.DeleteProduct_Image(Product.Id);
                int id = 1;
                foreach (var item in Product.Product_Images)
                {
                    item.id        = id;
                    item.ProductId = Product.Id;
                    QueryForSQLServer.InsertProduct_Image(item);
                    id++;
                }
                Handler?.Invoke(Product);
                //e.Handled = true;
                //SystemNavigationManager manager = SystemNavigationManager.GetForCurrentView();
                //manager.BackRequested -= DetailPage_BackRequested;
                //manager.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
                this.Visibility = Visibility.Collapsed;
            }
            else
            {
                //this.Visibility = Visibility.Collapsed;
            }
        }
コード例 #2
0
ファイル: PageAdd.xaml.cs プロジェクト: Raizohaza/DoAn1
        private async void btnDone_Click(object sender, RoutedEventArgs e)
        {
            var messageDialog = new MessageDialog("Add new produt", "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)
            {
                Product.Price    = Decimal.Parse(addGia.Text);
                Product.Quantity = int.Parse(addSoLuong.Text);
                var productid = QueryForSQLServer.InsertProduct(Product);
                int id        = 1;
                foreach (var item in Product.Product_Images)
                {
                    item.id        = id;
                    item.ProductId = productid;
                    QueryForSQLServer.InsertProduct_Image(item);
                    id++;
                }
                Frame.GoBack();
            }
            else
            {
                Frame.GoBack();
            }
        }
コード例 #3
0
ファイル: PageAdd.xaml.cs プロジェクト: Raizohaza/DoAn1
        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);
            }
        }