Exemple #1
0
        public NewProductPage()
        {
            InitializeComponent();

            Thread getTypes = new Thread(delegate()
            {
                MANAGEMENT_STORE_Entities db = new MANAGEMENT_STORE_Entities();
                var TypeProduct = new ObservableCollection <string>(db.Type_product.Select(x => x.Type_Product1));
                var Supplier    = new ObservableCollection <string>(db.Supplier.Select(x => x.Name_Sup));

                Dispatcher.Invoke(() =>
                {
                    ProductId.Text = manage.Create_NewIdproduct_Auto();
                    comboProductTypes.ItemsSource = TypeProduct;
                    comboboxSupplier.ItemsSource  = Supplier;
                    BitmapImage image             = new BitmapImage();
                    image.BeginInit();
                    image.UriSource = new Uri("pack://application:,,/Images/Image.png");
                    image.EndInit();
                    imgProduct.Source = image;
                    imgProduct.Tag    = null;
                });
            });

            getTypes.Start();
        }
Exemple #2
0
 public void refreshCombo(bool Data)
 {
     if (Data) // Nếu có chỉnh sửa danh sách loại sản phẩm thì refresh combo
     {
         int oldIndexType = comboProductTypes.SelectedIndex;
         int oldIndexSup  = comboboxSupplier.SelectedIndex;
         // Get và hiển thị danh sách loại sản phẩm
         Thread getPTypes = new Thread(delegate()
         {
             var db           = new MANAGEMENT_STORE_Entities();
             var productTypes = new ObservableCollection <string>(db.Type_product.Select(x => x.Type_Product1));
             var sup          = new ObservableCollection <string>(db.Supplier.Select(x => x.Name_Sup));
             Dispatcher.Invoke(() =>
             {
                 comboProductTypes.ItemsSource = productTypes; // Tác động lên UI
                 comboboxSupplier.ItemsSource  = sup;
                 if (oldIndexType > 0)
                 {
                     comboProductTypes.SelectedIndex = oldIndexType;
                 }
                 if (oldIndexSup > 0)
                 {
                     comboboxSupplier.SelectedIndex = oldIndexSup;
                 }
                 // Cập nhật tiếp trang ở trước
                 if (RefreshProductList != null)
                 {
                     RefreshProductList.Invoke(true);
                 }
             });
         });
         getPTypes.Start();
     }
 }
Exemple #3
0
        public void refresh(bool Data)
        {
            if (Data) // Nếu vừa sửa xong
            {
                // Lấy lại đối tượng mới
                var db = new MANAGEMENT_STORE_Entities();
                product = db.Detail_Product.SingleOrDefault(x => x.ID_Product == product.ID_Product);

                // Làm mới danh sách ở trang trước (delegate 2 cấp)
                if (RefreshProductList != null)
                {
                    RefreshProductList.Invoke(true);
                }
            }
            // Đưa thông tin lên UI
            txbProductName.Text   = product.NameProduct;
            txbProductId.Text     = product.ID_Product;
            txbOriginalPrice.Text = product.Original_Price.ToString();
            txbSupplier.Text      = manage.GetSupplier(product);
            txbDateImport.Text    = manage.GetDateImport(product).ToString();
            txbCurrAmount.Text    = product.Amount_Current.ToString() + "/" + manage.GetinitialAmount(product).ToString();
            // editProductType.Text = product.ProductType;
            if (product.Description_Pro != null)
            {
                txbDescri.Text = product.Description_Pro;
            }
            if (product.Image_Path != null)
            {
                BitmapImage source = new BitmapImage(new Uri(product.Image_Path));
                imgProduct.Source = source;
            }

            // Lấy tên loại sản phẩm và các hóa đơn liên quan
            Thread thread = new Thread(delegate()
            {
                try
                {
                    var db = new MANAGEMENT_STORE_Entities();
                    string productTypeName             = db.Type_product.Find(product.ID_TypeProduct).Type_Product1; // Lấy tên loại sản phẩm
                    ObservableCollection <Bills> bills = manage.Load_Bill(product.ID_Product);                       // Lấy danh sách hóa đơn

                    // Đưa lên UI
                    Dispatcher.Invoke(() => {
                        txbProductType.Text  = productTypeName;
                        listBill.ItemsSource = bills;
                        // Hiện thông báo nếu không có Bill nào
                        if (bills.Count == 0)
                        {
                            noBillAnnounce.Visibility = Visibility.Visible;
                        }
                    });
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString());
                }
            });

            thread.Start();
        }
Exemple #4
0
        public NewProductPage(Detail_Product product)
        {
            InitializeComponent();
            isEdit                  = true;
            imgProduct.Tag          = product.Image_Path;
            Title.Content           = "Edit product";
            ProductName.Text        = product.NameProduct;
            ProductId.Text          = product.ID_Product;
            ProductDescription.Text = product.Description_Pro;
            ProductPrice.Text       = product.Original_Price.ToString();
            ProductCapital.Text     = "0";
            var t = db.Input_Form.FirstOrDefault(x => x.ID_Product == product.ID_Product);

            ProductDate.Text          = t.Input_Date.ToString();
            ProductInitialAmount.Text = "0";
            if (product.Image_Path != null)
            {
                BitmapImage source = new BitmapImage(new Uri(product.Image_Path));
                imgProduct.Source = source;
            }
            Thread getTypes = new Thread(delegate()
            {
                MANAGEMENT_STORE_Entities db = new MANAGEMENT_STORE_Entities();
                var TypeProduct = new ObservableCollection <string>(db.Type_product.Select(x => x.Type_Product1));
                var Supplier    = new ObservableCollection <string>(db.Supplier.Select(x => x.Name_Sup));
                Dispatcher.Invoke(() =>
                {
                    comboProductTypes.ItemsSource = TypeProduct;
                    comboboxSupplier.ItemsSource  = Supplier;
                });
                Type_product target = db.Type_product.Find(product.ID_TypeProduct);
                for (int i = 0; i < TypeProduct.Count; i++)
                {
                    if (TypeProduct[i] == target.Type_Product1)
                    {
                        Dispatcher.Invoke(() =>
                        {
                            comboProductTypes.SelectedIndex = i;
                        });
                        break;
                    }
                }

                Supplier target1 = db.Supplier.Find(product.ID_Supplier);
                for (int i = 0; i < Supplier.Count; i++)
                {
                    if (Supplier[i] == target1.Name_Sup)
                    {
                        Dispatcher.Invoke(() =>
                        {
                            comboboxSupplier.SelectedIndex = i;
                        });
                        break;
                    }
                }
            });

            getTypes.Start();
        }
        private void BtnSeeProduct_Click(object sender, RoutedEventArgs e)
        {
            if (listBill.SelectedItem == null)
            {
                return;
            }
            Bill_Show bill_ = listBill.SelectedItem as Bill_Show;

            try
            {
                var db     = new MANAGEMENT_STORE_Entities();
                var target = db.Detail_Product.Find(bill_.ID_PRO);
                NavigationService.Navigate(new DetailProductPage(target));
            }
            catch
            {
            }
        }
        private void dispatcherTimer1_Tick(object sender, EventArgs e)
        {
            if (imgCameraCode.Source != null)
            {
                BarcodeReader        barcodeReader = new BarcodeReader();
                ImageSourceConverter c             = new ImageSourceConverter();

                ImageSource  ImaSrc     = imgCameraCode.Source;
                BitmapSource BmpSrc     = (BitmapSource)ImaSrc;
                Bitmap       bitmapCode = GetBitmap(BmpSrc);
                Result       result     = barcodeReader.Decode(bitmapCode);
                if (result != null)
                {
                    #region Navigation
                    MANAGEMENT_STORE_Entities db = new MANAGEMENT_STORE_Entities();
                    string         ProductNameID = result.Text;
                    Detail_Product detail        = db.Detail_Product.FirstOrDefault((x) => x.ID_Product == ProductNameID);
                    if (detail != null)
                    {
                        DetailProductPage detailPage = new DetailProductPage(detail);
                        this.ReFresh();
                        if (NavigationService.CanGoBack)
                        {
                            NavigationService.GoBack();
                        }
                        NavigationService.Navigate(detailPage);
                        dispatcherTimer.Stop();

                        Thread thread = new Thread(delegate()
                        {
                            if (captureDevice.IsRunning)
                            {
                                captureDevice.Stop();
                            }
                        });
                        thread.Start();
                    }
                    #endregion
                }
            }
        }
        public void Import(ObservableCollection <ImportProduct> Data)
        {
            MANAGEMENT_STORE_Entities db = new MANAGEMENT_STORE_Entities();

            if (Data != null)
            {
                for (int i = 0; i < Data.Count; i++)
                {
                    try
                    {
                        dbProduct.AddProduct(false, Data[i].ID, Data[i].Type, Data[i].Supplier, Data[i].input_time, Data[i].Name, Data[i].Orig_price, Data[i].Initial_amount, Data[i].Descrip, Data[i].Image_path);
                        // Tăng số sản phẩm của loại sản phẩm
                        Type_product type = db.Type_product.Find(Data[i].ID_Type);
                        type.Num_Of_Product++;
                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        continue; // Không xảy ra lỗi trùng mã vì đã xử lý trước
                    }
                }
                Refresh(true);
            }
        }
Exemple #8
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Left = Owner.Left + Owner.Width / 2 - Width / 2;
            Top  = this.Owner.Top + Owner.Height / 2 - Height / 2;

            Thread thread = new Thread(delegate()
            {
                // Mở Excel và đọc
                Workbook workbook   = new Workbook(filename);
                Worksheet worksheet = workbook.Worksheets[0];
                var db = new MANAGEMENT_STORE_Entities();
                db.Configuration.ValidateOnSaveEnabled = false;
                // Nếu import loại sản phẩm
                if (worksheet.Name.Equals("Product Type"))
                {
                    productTypes = new ObservableCollection <Type_product>();

                    // Bắt đầu từ hàng thứ 2
                    int i = 2;
                    while (worksheet.Cells[$"B{i}"].Value != null)
                    {
                        // Nếu dữ liệu đã tồn tại thì thôi
                        if (db.Type_product.FirstOrDefault(x => x.ID == worksheet.Cells[$"B{i}"].Value.ToString()) != null)
                        {
                            i++;
                            continue;
                        }

                        // Kiểm tra tên, ngày có trống không
                        if (worksheet.Cells[$"A{i}"].Value == null ||
                            worksheet.Cells[$"C{i}"].Value == null)
                        {
                            i++;
                            continue;
                        }

                        // Tới đây được tức có dữ liệu đã đúng
                        Type_product type = new Type_product()
                        {
                            Type_Product1  = worksheet.Cells[$"A{i}"].Value.ToString(),
                            ID             = worksheet.Cells[$"B{i}"].Value.ToString(),
                            Num_Of_Product = Int32.Parse(worksheet.Cells[$"B{i}"].Value.ToString())
                        };
                        productTypes.Add(type);
                        i++;
                    }

                    // Cập nhật UI
                    Dispatcher.Invoke(() =>
                    {
                        listData.ItemsSource = productTypes;
                    });
                }
                // Nếu import sản phẩm
                else if (worksheet.Name.Equals("Product"))
                {
                    import = new ObservableCollection <ImportProduct>();

                    // Bắt đầu từ hàng thứ 2
                    int i = 2;
                    while (worksheet.Cells[$"B{i}"].Value != null)
                    {
                        // Nếu dữ liệu đã tồn tại thì thôi
                        string t = worksheet.Cells[$"B{i}"].Value.ToString();
                        if (db.Detail_Product.FirstOrDefault(x => x.ID_Product == t) != null)
                        {
                            i++;
                            continue;
                        }

                        // Nếu loại sản phẩm không tồn tại thì thôi
                        t = worksheet.Cells[$"J{i}"].Value.ToString();
                        if (db.Type_product.FirstOrDefault(x => x.ID == t) == null)
                        {
                            i++;
                            continue;
                        }

                        t = worksheet.Cells[$"I{i}"].Value.ToString();
                        if (db.Supplier.FirstOrDefault(x => x.ID_sup == t) == null)
                        {
                            i++;
                            continue;
                        }

                        // Kiểm tra các cột khác có trống không (trừ MÔ TẢ, LOẠI SP và ẢNH SP)
                        if (worksheet.Cells[$"A{i}"].Value == null ||
                            worksheet.Cells[$"C{i}"].Value == null ||
                            worksheet.Cells[$"D{i}"].Value == null ||
                            worksheet.Cells[$"E{i}"].Value == null ||
                            worksheet.Cells[$"F{i}"].Value == null ||
                            worksheet.Cells[$"G{i}"].Value == null ||
                            worksheet.Cells[$"K{i}"].Value == null)
                        {
                            i++;
                            continue;
                        }

                        // Kiểm tra ngày có đúng định dạng không
                        string date       = worksheet.Cells[$"D{i}"].Value.ToString();
                        DateTime dateTime = new DateTime();
                        try
                        {
                            dateTime = DateTime.Parse(date);
                        }
                        catch (Exception ex)
                        {
                            i++;
                            continue;
                        }

                        // Tới đây được tức có dữ liệu đã đúng
                        try
                        {
                            Detail_Product product = new Detail_Product()
                            {
                                NameProduct     = worksheet.Cells[$"A{i}"].Value.ToString(),
                                ID_Product      = worksheet.Cells[$"B{i}"].Value.ToString(),
                                Original_Price  = Int32.Parse(worksheet.Cells[$"C{i}"].Value.ToString()),
                                Amount_Current  = int.Parse(worksheet.Cells[$"F{i}"].Value.ToString()),
                                Description_Pro = worksheet.Cells[$"H{i}"].Value == null ? null : worksheet.Cells[$"H{i}"].Value.ToString(),
                                ID_TypeProduct  = worksheet.Cells[$"J{i}"].Value.ToString(),
                                Image_Path      = worksheet.Cells[$"K{i}"].Value == null ? null : worksheet.Cells[$"K{i}"].Value.ToString(),
                                ID_Supplier     = worksheet.Cells[$"I{i}"].Value.ToString()
                            };

                            DateTime time      = DateTime.Parse(worksheet.Cells[$"D{i}"].Value.ToString());
                            int Capital        = Int32.Parse(worksheet.Cells[$"G{i}"].Value.ToString());
                            int Amount_Initial = int.Parse(worksheet.Cells[$"F{i}"].Value.ToString());
                            ImportProduct a    = new ImportProduct()
                            {
                                Name           = product.NameProduct.ToString(),
                                ID             = product.ID_Product,
                                Curr_amount    = Int32.Parse(product.Amount_Current.ToString()),
                                Orig_price     = Int32.Parse(product.Original_Price.ToString()),
                                Supplier       = db.Supplier.Find(product.ID_Supplier).Name_Sup,
                                Type           = db.Type_product.Find(product.ID_TypeProduct).Type_Product1,
                                Descrip        = product.Description_Pro,
                                ID_Type        = product.ID_TypeProduct,
                                ID_Supp        = product.ID_Supplier,
                                Image_path     = product.Image_Path,
                                input_time     = time,
                                capital        = Capital,
                                Initial_amount = Amount_Initial
                            };
                            import.Add(a);
                        }
                        catch (Exception) { }
                        i++;
                        continue;
                    }

                    // Cập nhật UI
                    Dispatcher.Invoke(() =>
                    {
                        listData.ItemsSource = import;
                    });
                }

                // Nếu không có dữ liệu nào có thể import thì thông báo
                Dispatcher.Invoke(() =>
                {
                    if (listData.Items.Count == 0)
                    {
                        emptyAnnounce.Visibility = Visibility.Visible;
                    }
                    ProgressBar.IsEnabled  = false;
                    ProgressBar.Visibility = Visibility.Hidden;
                });
            });

            thread.Start();
        }