Esempio n. 1
0
        public bool SaveWareHouse(List <WareHouse> saveData)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq = WareHouseDAO.GetWareHouseSEQ();
                    foreach (WareHouse data in saveData)
                    {
                        switch (data.Status)
                        {
                        // Add new
                        case ModifyMode.Insert:
                            seq++;
                            data.WarehouseID = GenerateID.WareHouseID(seq);
                            this.WareHouseDAO.InsertWareHouse(data);
                            break;

                        // Update
                        case ModifyMode.Update:
                            this.WareHouseDAO.UpdateWareHouse(data);
                            break;

                        // Delete
                        case ModifyMode.Delete:
                            this.WareHouseDAO.DeleteWareHouse(data);
                            break;
                        }
                    }

                    transaction.Commit();

                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }
 public WareHouseController()
 {
     this.WareHouseDAO   = new WareHouseDAO(this.Context);
     this.WareHouseLogic = new WareHouseLogic(this.Context);
 }
Esempio n. 3
0
        public bool SaveWareHouseFull(WareHouse data, List <WareHouseDetail> detailData)
        {
            using (DbContextTransaction transaction = Context.Database.BeginTransaction())
            {
                try
                {
                    long seq       = WareHouseDAO.GetWareHouseSEQ();
                    long seqdetail = WareHouseDetailDAO.GetWareHouseDetailSEQ();
                    switch (data.Status)
                    {
                    // Thêm warehouse mới thì sẽ thực hiện thêm Detail mới nếu ListDetail có giá trị
                    case ModifyMode.Insert:
                        seq++;
                        data.WarehouseID = GenerateID.WareHouseID(seq);
                        this.WareHouseDAO.InsertWareHouse(data);
                        if (detailData.Count > 0)
                        {
                            //thêm warehouseDetail
                            #region insert warehouseDetail
                            foreach (WareHouseDetail wareHouseDetail in detailData)
                            {
                                if (wareHouseDetail.Status == ModifyMode.Insert)
                                {
                                    seqdetail++;
                                    wareHouseDetail.WareHouseDetailID = GenerateID.WareHouseDetailID(seqdetail);
                                    wareHouseDetail.WarehouseID       = data.WarehouseID;
                                    wareHouseDetail.VouchersID        = data.VouchersID;
                                    wareHouseDetail.CompanyID         = data.CompanyID;
                                    this.WareHouseDetailDAO.InsertWareHouseDetail(wareHouseDetail);
                                    //update Du Tonan Cong Trinh
                                    if (CommonInfo.DTCTDataSelected.Count > 0)
                                    {
                                        DUTOANCONGTRINHmodel itemDTCT = CommonInfo.DTCTDataSelected.Where(o => o.VouchersID == data.VouchersID &&
                                                                                                          o.ItemID == wareHouseDetail.ItemID).FirstOrDefault();
                                        if (itemDTCT != null)
                                        {
                                            itemDTCT.WareHouseDetailID = wareHouseDetail.WareHouseDetailID;
                                            //update DTCT
                                            DUTOANCONGTRINHDAO.UpdateDUTOANCONGTRINH(itemDTCT);
                                        }
                                    }
                                }
                            }
                            #endregion insert warehouseDetail
                        }
                        break;

                    //Khi update Warehouse thì sẽ thực hiện update WarehouseDetail, Thêm mới hoặc Warehouse Detail
                    case ModifyMode.Update:
                        this.WareHouseDAO.UpdateWareHouse(data);
                        if (detailData.Count > 0)
                        {
                            foreach (WareHouseDetail wareHouseDetail in detailData)
                            {
                                //thực hiện nhiệm vụ update với các chi tiết Warehouse đã thuộc warehouse
                                if (wareHouseDetail.Status == ModifyMode.Update)
                                {
                                    #region Update dataDetail
                                    if (!string.IsNullOrEmpty(wareHouseDetail.WareHouseDetailID))
                                    {
                                        this.WareHouseDetailDAO.UpdateWareHouseDetail(wareHouseDetail);
                                        DUTOANCONGTRINHmodel itemDTCT = new DUTOANCONGTRINHmodel
                                        {
                                            WareHouseDetailID = wareHouseDetail.WareHouseDetailID,
                                            VouchersID        = data.VouchersID,
                                            SoLuongXuat       = wareHouseDetail.Quantity,
                                            DonGiaXuat        = wareHouseDetail.Price,
                                            ThanhTienXuat     = wareHouseDetail.Amount,
                                            ItemID            = wareHouseDetail.ItemID,
                                            ItemUnitID        = wareHouseDetail.ItemUnitID,
                                        };
                                        //update DTCT
                                        DUTOANCONGTRINHDAO.EditDUTOANCONGTRINH(itemDTCT);
                                    }
                                    #endregion Update dataDetail
                                }
                                else if (wareHouseDetail.Status == ModifyMode.Insert)
                                {
                                    //thêm mới warehouseDetail vào warehouse
                                    #region insert warehouseDetail khi thêm detail mới cho warehouse đã có sẵn
                                    seqdetail++;
                                    wareHouseDetail.WareHouseDetailID = GenerateID.WareHouseDetailID(seqdetail);
                                    wareHouseDetail.WarehouseID       = data.WarehouseID;
                                    wareHouseDetail.VouchersID        = data.VouchersID;
                                    wareHouseDetail.CompanyID         = data.CompanyID;
                                    this.WareHouseDetailDAO.InsertWareHouseDetail(wareHouseDetail);
                                    #endregion insert warehouseDetail khi thêm detail mới cho warehouse đã có sẵn
                                }
                            }
                        }
                        break;

                    // Delete
                    case ModifyMode.Delete:
                        this.WareHouseDAO.DeleteWareHouse(data);
                        //Khi delete warehouse thì DB sẽ tự delete warehouse
                        break;

                    default:
                        //Khi warehouse không thực thêm, xóa, sửa thì có thể sẽ có thay đổi giá trị warehouseDetail
                        if (detailData.Count > 0)
                        {
                            foreach (WareHouseDetail wareHouseDetail in detailData)
                            {
                                //thực hiện nhiệm vụ update với các chi tiết warehouse đã thuộc warehouse
                                if (wareHouseDetail.Status == ModifyMode.Update)
                                {
                                    #region Update dataDetail
                                    if (!string.IsNullOrEmpty(wareHouseDetail.WareHouseDetailID))
                                    {
                                        this.WareHouseDetailDAO.UpdateWareHouseDetail(wareHouseDetail);
                                    }
                                    #endregion Update dataDetail
                                }
                                else if (wareHouseDetail.Status == ModifyMode.Insert)
                                {
                                    //thêm mới warehouseDetail vào warehouse
                                    #region insert warehouseDetail khi thêm detail mới cho warehouse đã có sẵn
                                    seqdetail++;
                                    wareHouseDetail.WareHouseDetailID = GenerateID.WareHouseDetailID(seqdetail);
                                    wareHouseDetail.WarehouseID       = data.WarehouseID;
                                    wareHouseDetail.VouchersID        = data.VouchersID;
                                    wareHouseDetail.CompanyID         = data.CompanyID;
                                    this.WareHouseDetailDAO.InsertWareHouseDetail(wareHouseDetail);
                                    #endregion insert warehouseDetail khi thêm detail mới cho warehouse đã có sẵn
                                }
                            }
                        }
                        break;
                    }
                    transaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    BSLog.Logger.Error(ex.Message);
                    return(false);
                }
            }
        }