Ejemplo n.º 1
0
        private void OpenImportProductwindow(HomeWindow para)
        {
            this.HomeWindow = para;
            ImportProductWindow window = new ImportProductWindow();

            this.imageFileName = null;
            try
            {
                string query = "SELECT MAX(ID) FROM Product " +
                               "UNION " +
                               "SELECT MAX(ID) FROM StockReceipt";

                List <Int32> temp = DataProvider.Instance.DB.Database.SqlQuery <Int32>(query).ToList();

                window.txtID.Text             = (temp[0] + 1).ToString();
                window.txtStockReceiptID.Text = (temp[1] + 1).ToString();
            }
            catch
            {
                window.txtID.Text             = "1";
                window.txtStockReceiptID.Text = "1";
            }
            finally
            {
                window.ShowDialog();
            }
        }
Ejemplo n.º 2
0
        private void ImportProduct(ProductControlUC para)
        {
            Product product   = new Product();
            int     productID = int.Parse(para.txbID.Text);
            int     stockReceiptID;

            product = DataProvider.Instance.DB.Products.Where(x => x.ID == productID).First();

            try
            {
                stockReceiptID = DataProvider.Instance.DB.StockReceipts.Max(p => p.ID) + 1;
            }
            catch
            {
                stockReceiptID = 1;
            }

            ImageBrush imageBrush = new ImageBrush();

            imageBrush.ImageSource = Converter.Instance.ConvertByteToBitmapImage(product.Image);

            ImportProductWindow window = new ImportProductWindow();

            window.txtID.Text             = product.ID.ToString();
            window.txtStockReceiptID.Text = stockReceiptID.ToString();

            window.txtProductName.Text           = product.Name;
            window.txtProductName.SelectionStart = window.txtProductName.Text.Length;

            window.txtUnit.Text           = product.Unit;
            window.txtUnit.SelectionStart = window.txtUnit.Text.Length;

            window.txtImportPrice.Text           = ConvertToString(product.ImportPrice);
            window.txtImportPrice.SelectionStart = window.txtImportPrice.Text.Length;

            window.txtAmount.Text           = ConvertToString(product.Count);
            window.txtAmount.SelectionStart = window.txtAmount.Text.Length;

            window.grdImage.Background = imageBrush;
            if (window.grdImage.Children.Count != 0)
            {
                window.grdImage.Children.Remove(window.grdImage.Children[0]);
                window.grdImage.Children.Remove(window.grdImage.Children[0]);
            }

            window.Title = "Import exits product";
            window.ShowDialog();
        }
Ejemplo n.º 3
0
 private void CloseImportWindow(ImportProductWindow para)
 {
     para.Close();
 }
Ejemplo n.º 4
0
        private void Import_SaveProduct(ImportProductWindow para)
        {
            if (string.IsNullOrEmpty(para.txtProductName.Text))
            {
                para.txtProductName.Focus();
                return;
            }
            if (string.IsNullOrEmpty(para.txtUnit.Text))
            {
                para.txtUnit.Focus();
                return;
            }
            if (string.IsNullOrEmpty(para.txtImportPrice.Text))
            {
                para.txtImportPrice.Focus();
                return;
            }
            if (string.IsNullOrEmpty(para.txtAmount.Text))
            {
                para.txtAmount.Focus();
                return;
            }

            StreamReader sr    = new StreamReader("../../cache.txt");
            string       cache = sr.ReadToEnd();

            sr.Close();

            string[] rulesSetting = cache.Split(' ');

            var results = DataProvider.Instance.DB.Products.Where(x => x.IsDelete == false).Select(x => x.Unit).Distinct().ToList();

            if (para.Title == "Thêm sản phẩm" && DataProvider.Instance.DB.Products.Where(x => x.IsDelete == false).ToList().Count >= int.Parse(rulesSetting[2]))
            {
                MessageBox.Show("Exceed the number of product limit");
                return;
            }

            if (DataProvider.Instance.DB.Products.Where(x => x.IsDelete == false).Where(x => x.Unit == para.txtUnit.Text).ToList().Count < 1)
            {
                if (results.Count >= int.Parse(rulesSetting[3]))
                {
                    MessageBox.Show("Exceed the number of unit limit");
                    return;
                }
            }

            string id          = para.txtID.Text;
            string name        = para.txtProductName.Text;
            string unit        = para.txtUnit.Text;
            long   importPrice = ConvertToNumber(para.txtImportPrice.Text);
            long   exportPrice = ConvertToNumber(para.txtStockReceiptID.Text);
            int    amount      = (int)ConvertToNumber(para.txtAmount.Text);

            try
            {
                int    productID      = int.Parse(para.txtID.Text);
                int    stockReceiptID = int.Parse(para.txtStockReceiptID.Text);
                string productName    = para.txtProductName.Text;
                string units          = para.txtUnit.Text;
                importPrice = ConvertToNumber(para.txtImportPrice.Text);
                amount      = (int)ConvertToNumber(para.txtAmount.Text);
                byte[] imgByteArr;

                if (imageFileName == null)
                {
                    imgByteArr = Converter.Instance.ConvertImageToBytes(@"..\..\Resources\Images\default.jpg");
                }
                else
                {
                    imgByteArr = Converter.Instance.ConvertImageToBytes(imageFileName);
                }

                Product product;
                //exits product
                if (para.Title == "Import exits product")
                {
                    product             = DataProvider.Instance.DB.Products.Where(p => p.ID == productID).First();
                    product.ID          = productID;
                    product.Name        = productName;
                    product.Unit        = units;
                    product.ImportPrice = importPrice;
                    product.Count       = amount;
                    product.Image       = imgByteArr;
                    product.IsDelete    = false;
                }
                //import new product
                else
                {
                    product             = new Product();
                    product.ID          = productID;
                    product.Name        = productName;
                    product.Unit        = units;
                    product.ImportPrice = importPrice;
                    product.ExportPrice = 0;
                    product.Count       = amount;
                    product.Image       = imgByteArr;
                    product.IsDelete    = false;
                }

                StockReceiptInfo stockReceiptInfo = new StockReceiptInfo();
                stockReceiptInfo.StockReceiptID = stockReceiptID;
                stockReceiptInfo.ProductID      = productID;
                stockReceiptInfo.Amount         = amount;
                stockReceiptInfo.Price          = importPrice;

                StockReceipt stockReceipt = new StockReceipt();
                stockReceipt.ID      = stockReceiptID;
                stockReceipt.CheckIn = DateTime.Now;
                stockReceipt.Total   = product.Count * product.ImportPrice;

                DataProvider.Instance.DB.Products.AddOrUpdate(product);
                DataProvider.Instance.DB.StockReceipts.AddOrUpdate(stockReceipt);
                DataProvider.Instance.DB.StockReceiptInfoes.AddOrUpdate(stockReceiptInfo);
                DataProvider.Instance.DB.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                this.LoadProduct(this.HomeWindow);
                para.Close();
            }
        }