Пример #1
0
        public BlockInDetail Add(BlockInDetail data)
        {
            var pk = new BlockInDetailPK {BlockId = 1};
            var maxId = BlockInDetailDAO.SelectSpecificType(null, Projections.Max("BlockInDetailPK.BlockDetailId"));

            pk.BlockDetailId = maxId == null ? "1" : (Int64.Parse(maxId.ToString()) + 1).ToString();

            data.BlockInDetailPK = pk;

            var maxProduct = ProductDAO.SelectSpecificType(null, Projections.Max("ProductId"));
            Int64 maxProductId = 1;
            if (maxProduct != null)
            {
                maxProductId = (Int64)maxProduct + 1;
            }

            var maxStockInId = StockInDAO.SelectSpecificType(null, Projections.Max("StockInId"));
            if (maxStockInId == null)
            {
                maxStockInId = (long) 1;
            }
            else
            {
                maxStockInId = (long)maxStockInId + 1;
            }

            var stockIn = new StockIn {StockInDate = data.ImportDate};
            data.StockInId = (long)maxStockInId;

            BlockInDetailDAO.Add(data);
            StockInDAO.Add(stockIn);

            foreach (Product product in data.Products)
            {
                // TODO product.ProductId = maxProductId++;
                product.BlockInDetail = data;
                ProductDAO.Add(product);

                var stockInDetail = new StockInDetail
                                        {
                                            Product = product,
                                            ProductId = product.ProductId,
                                            StockIn = stockIn,
                                            Quantity = product.Quantity,
                                            Price = product.Price,
                                            StockInType = (Int64)StockInDetail.StockInStatus.IMPORTED,
                                            StockInDetailPK =
                                                new StockInDetailPK
                                                    {StockInId = stockIn.StockInId, ProductId = product.ProductId}
                                        };
                StockInDetailDAO.Add(stockInDetail);
            }

            return data;
        }
Пример #2
0
 private void GoodsInput_Load(object sender, EventArgs e)
 {
     if (supplierList == null)
     {
         supplierList = SupplierLogic.FindAll(null);
         cbbSupplier.DisplayMember = "SupplierName";
         cbbSupplier.DataSource = supplierList;
     }
     if (sizeList == null)
     {
         sizeList = SizeLogic.FindAll(null);
     }
     if (colorList == null)
     {
         colorList = ColorLogic.FindAll(null);
     }
     if (typeList == null)
     {
         typeList = TypeLogic.FindAll(null);
     }
     if (BlockInDetail != null)
     {
         txtBlockId.Text = BlockInDetail.BlockInDetailPK.BlockDetailId + "";
         txtDexcription.Text = BlockInDetail.DetailValue;
         for (int i = 0; i < supplierList.Count; i++ )
         {
             if (((Supplier)supplierList[i]).SupplierId == BlockInDetail.SupplierId)
             {
                 cbbSupplier.SelectedItem = supplierList[i];
                 break;
             }
         }
         dtpImportDate.Value = BlockInDetail.BlockIn.ImportDate;
         PopulateDataGrid();
     }
     else
     {
         BlockInDetail = new BlockInDetail();
     }
 }
Пример #3
0
        public void Update(BlockInDetail data)
        {
            // Update block
            BlockInDetailDAO.Update(data);

            // Update Stock In
            StockIn stockIn = null;
            if (data.StockInId != 0)
            {
                stockIn = StockInDAO.FindById(data.StockInId);
                if (stockIn != null)
                {
                    stockIn.StockInDate = data.ImportDate;
                    StockInDAO.Update(stockIn);
                }
            }

            // Get the max id of product
            var maxProduct = ProductDAO.SelectSpecificType(null, Projections.Max("ProductId"));
            Int64 maxProductId = 1;
            if (maxProduct != null)
            {
                maxProductId = ((Int64)maxProduct) + 1;
            }

            foreach (Product product in data.Products)
            {
                // Add new Product
                if (string.IsNullOrEmpty(product.ProductId))
                {
                    // TODO product.ProductId = maxProductId++;
                    ProductDAO.Add(product);
                    if (stockIn != null)
                    {
                        var stockInDetail = new StockInDetail
                        {
                            Product = product,
                            ProductId = product.ProductId,
                            StockIn = stockIn,
                            Quantity = product.Quantity,
                            Price = product.Price,
                            StockInDetailPK =
                                new StockInDetailPK { StockInId = stockIn.StockInId, ProductId = product.ProductId }
                        };
                        StockInDetailDAO.Add(stockInDetail);
                    }
                }
                // Update Product
                else {
                    ProductDAO.Update(product);
                    if (stockIn != null)
                    {
                        var stockInDetail = new StockInDetail
                        {
                            Product = product,
                            ProductId = product.ProductId,
                            StockIn = stockIn,
                            Quantity = product.Quantity,
                            Price = product.Price,
                            StockInDetailPK =
                                new StockInDetailPK { StockInId = stockIn.StockInId, ProductId = product.ProductId }
                        };
                        StockInDetailDAO.Update(stockInDetail);
                    }
                }
            }
        }
Пример #4
0
 public void Delete(BlockInDetail data)
 {
     BlockInDetailDAO.Delete(data);
 }
Пример #5
0
 /// <summary>
 /// Delete BlockInDetail from database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public void Delete(BlockInDetail data)
 {
     HibernateTemplate.Delete(data);
 }
Пример #6
0
 /// <summary>
 /// Add BlockInDetail to database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public BlockInDetail Add(BlockInDetail data)
 {
     HibernateTemplate.Save(data);
     return data;
 }
Пример #7
0
 /// <summary>
 /// Update BlockInDetail to database.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public void Update(BlockInDetail data)
 {
     HibernateTemplate.Update(data);
 }
Пример #8
0
 private object[] AddBlockToDataGrid(BlockInDetail blockInDetail)
 {
     var obj = new object[6];
     obj[0] = blockInDetail.BlockInDetailPK.BlockDetailId;
     obj[1] = blockInDetail.ImportDate.ToString("dd/MM/yyyy HH:mm:ss");
     obj[2] = blockInDetail.DetailValue;
     Int64 sumOfProduct = 0;
     Int64 sumOfPrice = 0;
     foreach (Product product in blockInDetail.Products)
     {
         sumOfProduct += product.Quantity;
         sumOfPrice += (product.Quantity * product.Price);
     }
     obj[3] = sumOfProduct;
     obj[4] = sumOfPrice;
     if (blockInDetail.DelFlg == 1)
     {
         obj[5] = "Đã xóa";
     }
     return obj;
 }