//    catch (Exception ex)
        //    {
        //        notification.Type = Library.DTO.NotificationType.Error;
        //        notification.Message = ex.Message;
        //        if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
        //        {
        //            notification.DetailMessage.Add(ex.InnerException.Message);
        //        }
        //        return string.Empty;
        //    }
        //}



        public DTO.ReportPlcProducts.SupportDataContainer GetSupportData(out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DAL.Support.DataFactory factory = new Support.DataFactory();

            //try to get data
            try
            {
                DTO.ReportPlcProducts.SupportDataContainer dtoItem = new DTO.ReportPlcProducts.SupportDataContainer();

                dtoItem.Factories = factory.GetFactory().ToList();
                return(dtoItem);
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    notification.DetailMessage.Add(ex.InnerException.Message);
                }
                return(new DTO.ReportPlcProducts.SupportDataContainer());
            }
        }
Beispiel #2
0
 public DTO.DocumentMonitoringMng.SearchSupportList GetSearchSupportData()
 {
     DAL.Support.DataFactory factory = new Support.DataFactory();
     DTO.DocumentMonitoringMng.SearchSupportList dtoSupport = new DTO.DocumentMonitoringMng.SearchSupportList();
     dtoSupport.Seasons = factory.GetSeason().ToList();
     return(dtoSupport);
 }
Beispiel #3
0
 public DTO.ClientPaymentMng.EditSupportList GetEditSupportData()
 {
     DAL.Support.DataFactory factory = new Support.DataFactory();
     DTO.ClientPaymentMng.EditSupportList dtoSupport = new DTO.ClientPaymentMng.EditSupportList();
     dtoSupport.Users = factory.GetUser().ToList();
     return(dtoSupport);
 }
Beispiel #4
0
 public DTO.ClientPaymentMng.SearchSupportList GetSearchSupportData()
 {
     DAL.Support.DataFactory factory = new Support.DataFactory();
     DTO.ClientPaymentMng.SearchSupportList dtoSupport = new DTO.ClientPaymentMng.SearchSupportList();
     dtoSupport.Seasons = factory.GetSeason().ToList();
     dtoSupport.Salers  = factory.GetSaler().ToList();
     return(dtoSupport);
 }
 public DTO.BackSaleOrderMng.SearchFilterData GetSearchFilter()
 {
     DTO.BackSaleOrderMng.SearchFilterData filterData = new DTO.BackSaleOrderMng.SearchFilterData();
     Support.DataFactory support_factory = new Support.DataFactory();
     filterData.Seasons = support_factory.GetSeason().ToList();
     filterData.Salers  = support_factory.GetSaler().ToList();
     return(filterData);
 }
Beispiel #6
0
        public DTO.WarehouseTransportMng.EditSupportList GetEditSupportData()
        {
            DAL.Support.DataFactory factory = new Support.DataFactory();
            DTO.WarehouseTransportMng.EditSupportList dtoSupport = new DTO.WarehouseTransportMng.EditSupportList();
            dtoSupport.Users = factory.GetUser().ToList();
            dtoSupport.FromWarehouseAreas = GetPhysicalStockByWarehouseArea();
            dtoSupport.ToWarehouseAreas   = factory.GetAllWarehouseArea().ToList();
            dtoSupport.Seasons            = factory.GetSeason().ToList();

            return(dtoSupport);
        }
Beispiel #7
0
 public DTO.DocumentMonitoringMng.EditSupportList GetEditSupportData()
 {
     DAL.Support.DataFactory support_factory = new Support.DataFactory();
     DTO.DocumentMonitoringMng.EditSupportList dtoSupport = new DTO.DocumentMonitoringMng.EditSupportList();
     using (DocumentMonitoringMngEntities context = CreateContext())
     {
         dtoSupport.DefaultRemarks = converter.DB2DTO_DefaultRemark(context.List_DocumentMonitoringRemark_View.ToList());
         dtoSupport.Users          = support_factory.GetUser().ToList();
     }
     return(dtoSupport);
 }
Beispiel #8
0
        public DTO.WarehouseCIMng.DataContainer GetDataContainer(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DAL.Support.DataFactory factory = new Support.DataFactory();
            //try to get data
            try
            {
                using (WarehouseCIMngEntities context = CreateContext())
                {
                    DTO.WarehouseCIMng.DataContainer dtoItem = new DTO.WarehouseCIMng.DataContainer();

                    if (id > 0)
                    {
                        WarehouseCIMng_WarehouseCI_View dbItem;
                        dbItem = context.WarehouseCIMng_WarehouseCI_View
                                 .Include("WarehouseCIMng_WarehouseCIDetail_View")
                                 .Include("WarehouseCIMng_WarehouseCIExtDetail_View")
                                 .FirstOrDefault(o => o.WarehouseCIID == id);
                        DTO.WarehouseCIMng.WarehouseCI WarehouseCIDTO = converter.DB2DTO_WarehouseCI(dbItem);
                        dtoItem.WarehouseCIData = WarehouseCIDTO;
                    }
                    else
                    {
                        dtoItem.WarehouseCIData = new DTO.WarehouseCIMng.WarehouseCI();
                        dtoItem.WarehouseCIData.WarehouseCIDetails    = new List <DTO.WarehouseCIMng.WarehouseCIDetail>();
                        dtoItem.WarehouseCIData.WarehouseCIExtDetails = new List <DTO.WarehouseCIMng.WarehouseCIExtDetail>();
                    }

                    dtoItem.Clients    = factory.GetClient().ToList();
                    dtoItem.Currency   = factory.GetCurrency().ToList();
                    dtoItem.WareHouses = factory.GetWareHouse().ToList();
                    //dtoItem.TurnOverLedgerAccount = factory.T
                    return(dtoItem);
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Warning
                };
                return(new DTO.WarehouseCIMng.DataContainer());
            }
        }
        public override DTO.ShowroomReceiptMng.EditFormData GetData(int id, out Library.DTO.Notification notification)
        {
            DTO.ShowroomReceiptMng.EditFormData editFormData = new DTO.ShowroomReceiptMng.EditFormData();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (ShowroomReceiptMngEntities context = CreateContext())
                {
                    if (id > 0)
                    {
                        ShowroomReceiptMng_ShowroomReceipt_View dbItem;
                        dbItem = context.ShowroomReceiptMng_ShowroomReceipt_View
                                 .Include("ShowroomReceiptMng_ShowroomReceiptDetail_View")
                                 .FirstOrDefault(o => o.ShowroomReceiptID == id);

                        editFormData.Data = converter.DB2DTO_ShowroomReceipt(dbItem);
                    }
                    else
                    {
                        editFormData.Data = new DTO.ShowroomReceiptMng.ShowroomReceipt();
                        editFormData.Data.ShowroomReceiptDetails = new List <DTO.ShowroomReceiptMng.ShowroomReceiptDetail>();
                        editFormData.Data.Season      = DALBase.Helper.GetCurrentSeason();
                        editFormData.Data.ReceiptDate = DateTime.Now.ToString("dd/MM/yyyy");;
                    }
                    //get support list
                    DAL.Support.DataFactory support_factory = new Support.DataFactory();
                    editFormData.Users     = support_factory.GetUser().ToList();
                    editFormData.Showrooms = support_factory.GetShowroom();
                    editFormData.Seasons   = support_factory.GetSeason().ToList();
                    return(editFormData);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    notification.DetailMessage.Add(ex.InnerException.Message);
                }
                return(editFormData);
            }
        }
Beispiel #10
0
 public override DTO.BackSaleOrderMng.EditFormData GetData(int id, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification {
         Type = Library.DTO.NotificationType.Success, Message = "Get success"
     };
     try
     {
         using (BackSaleOrderMngEntities context = CreateContext())
         {
             DTO.BackSaleOrderMng.EditFormData data = new DTO.BackSaleOrderMng.EditFormData();
             if (id > 0)
             {
                 data.Data = converter.DB2DTO_BackOrder(context.BackSaleOrderMng_BackOrder_View.Include("BackSaleOrderMng_BackOrderDetail_View").Where(o => o.BackOrderID == id).FirstOrDefault());
             }
             else
             {
                 data.Data = new DTO.BackSaleOrderMng.BackOrder();
             }
             DAL.Support.DataFactory support_factory = new Support.DataFactory();
             data.Seasons        = support_factory.GetSeason().ToList();
             data.Salers         = support_factory.GetSaler().ToList();
             data.PaymentTerms   = support_factory.GetPaymentTerm().ToList();
             data.DeliveryTerms  = support_factory.GetDeliveryTerm().ToList();
             data.VATPercent     = support_factory.GetVATPercent();
             data.Currency       = support_factory.GetCurrency().ToList();
             data.SaleOrderTypes = support_factory.GetSaleOrderType();
             return(data);
         }
     }
     catch (Exception ex)
     {
         notification.Type    = Library.DTO.NotificationType.Error;
         notification.Message = ex.Message;
         notification.DetailMessage.Add(ex.Message);
         if (ex.GetBaseException() != null)
         {
             notification.DetailMessage.Add(ex.GetBaseException().Message);
         }
         return(new DTO.BackSaleOrderMng.EditFormData());
     }
 }
Beispiel #11
0
 public IEnumerable <DTO.Support.Season> GetSeasons(out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification()
     {
         Type = Library.DTO.NotificationType.Success
     };
     DAL.Support.DataFactory support_factory = new Support.DataFactory();
     try
     {
         return(support_factory.GetSeason().ToList());;
     }
     catch (Exception ex)
     {
         notification.Type    = Library.DTO.NotificationType.Error;
         notification.Message = ex.Message;
         if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
         {
             notification.DetailMessage.Add(ex.InnerException.Message);
         }
         return(new List <DTO.Support.Season>());
     }
 }
Beispiel #12
0
        public DTO.ReportStockList.SearchFormData GetStockListSearch(Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            DTO.ReportStockList.SearchFormData searchFormData = new DTO.ReportStockList.SearchFormData();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            totalRows = 0;

            try
            {
                string  productStatusIDs    = null;
                bool?   isMatchedImage      = null;
                bool?   isHaveImage         = null;
                string  articleCode         = null;
                string  description         = null;
                int?    qnt40HC             = null;
                int?    physicalQnt         = null;
                decimal?physicalQntIn40HC   = null;
                string  wareHouseAreaIDs    = null;
                string  qntPerWarehouseArea = null;
                int?    onSeaQnt            = null;
                int?    tobeShippedQnt      = null;
                int?    reservationQnt      = null;
                int?    ftsQnt                = null;
                bool?   isActiveFreeToSale    = null;
                string  eanCode               = null;
                string  freeToSaleCategoryIDs = null;

                using (ReportStockListEntities context = CreateContext())
                {
                    if (filters.ContainsKey("productStatusIDs") && !string.IsNullOrEmpty(filters["productStatusIDs"].ToString()))
                    {
                        productStatusIDs = filters["productStatusIDs"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("isMatchedImage") && filters["isMatchedImage"] != null && !string.IsNullOrEmpty(filters["isMatchedImage"].ToString()))
                    {
                        switch (filters["isMatchedImage"].ToString().ToLower())
                        {
                        case "true":
                            isMatchedImage = true;
                            break;

                        case "false":
                            isMatchedImage = false;
                            break;

                        default:
                            isMatchedImage = null;
                            break;
                        }
                    }
                    if (filters.ContainsKey("isHaveImage") && filters["isHaveImage"] != null && !string.IsNullOrEmpty(filters["isHaveImage"].ToString()))
                    {
                        switch (filters["isHaveImage"].ToString().ToLower())
                        {
                        case "true":
                            isHaveImage = true;
                            break;

                        case "false":
                            isHaveImage = false;
                            break;

                        default:
                            isHaveImage = null;
                            break;
                        }
                    }
                    if (filters.ContainsKey("articleCode") && !string.IsNullOrEmpty(filters["articleCode"].ToString()))
                    {
                        articleCode = filters["articleCode"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("description") && !string.IsNullOrEmpty(filters["description"].ToString()))
                    {
                        description = filters["description"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("qnt40HC") && filters["qnt40HC"] != null && !string.IsNullOrEmpty(filters["qnt40HC"].ToString()))
                    {
                        qnt40HC = Convert.ToInt32(filters["qnt40HC"].ToString());
                    }
                    if (filters.ContainsKey("physicalQnt") && filters["physicalQnt"] != null && !string.IsNullOrEmpty(filters["physicalQnt"].ToString()))
                    {
                        physicalQnt = Convert.ToInt32(filters["physicalQnt"].ToString());
                    }
                    if (filters.ContainsKey("physicalQntIn40HC") && filters["physicalQntIn40HC"] != null && !string.IsNullOrEmpty(filters["physicalQntIn40HC"].ToString()))
                    {
                        physicalQntIn40HC = Convert.ToDecimal(filters["physicalQntIn40HC"].ToString());
                    }
                    if (filters.ContainsKey("wareHouseAreaIDs") && !string.IsNullOrEmpty(filters["wareHouseAreaIDs"].ToString()))
                    {
                        wareHouseAreaIDs = filters["wareHouseAreaIDs"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("qntPerWarehouseArea") && !string.IsNullOrEmpty(filters["qntPerWarehouseArea"].ToString()))
                    {
                        qntPerWarehouseArea = filters["qntPerWarehouseArea"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("onSeaQnt") && filters["onSeaQnt"] != null && !string.IsNullOrEmpty(filters["onSeaQnt"].ToString()))
                    {
                        onSeaQnt = Convert.ToInt32(filters["onSeaQnt"].ToString());
                    }
                    if (filters.ContainsKey("tobeShippedQnt") && filters["tobeShippedQnt"] != null && !string.IsNullOrEmpty(filters["tobeShippedQnt"].ToString()))
                    {
                        tobeShippedQnt = Convert.ToInt32(filters["tobeShippedQnt"].ToString());
                    }
                    if (filters.ContainsKey("reservationQnt") && filters["reservationQnt"] != null && !string.IsNullOrEmpty(filters["reservationQnt"].ToString()))
                    {
                        reservationQnt = Convert.ToInt32(filters["reservationQnt"].ToString());
                    }
                    if (filters.ContainsKey("ftsQnt") && filters["ftsQnt"] != null && !string.IsNullOrEmpty(filters["ftsQnt"].ToString()))
                    {
                        ftsQnt = Convert.ToInt32(filters["ftsQnt"].ToString());
                    }
                    if (filters.ContainsKey("isActiveFreeToSale") && filters["isActiveFreeToSale"] != null && !string.IsNullOrEmpty(filters["isActiveFreeToSale"].ToString()))
                    {
                        switch (filters["isActiveFreeToSale"].ToString().ToLower())
                        {
                        case "true":
                            isActiveFreeToSale = true;
                            break;

                        case "false":
                            isActiveFreeToSale = false;
                            break;

                        default:
                            isActiveFreeToSale = null;
                            break;
                        }
                    }

                    if (filters.ContainsKey("eanCode") && !string.IsNullOrEmpty(filters["eanCode"].ToString()))
                    {
                        eanCode = filters["eanCode"].ToString().Replace("'", "''");
                    }

                    if (filters.ContainsKey("freeToSaleCategoryIDs") && !string.IsNullOrEmpty(filters["freeToSaleCategoryIDs"].ToString()))
                    {
                        freeToSaleCategoryIDs = filters["freeToSaleCategoryIDs"].ToString().Replace("'", "''");
                    }

                    //cal grand total
                    var s = context.ReportMng_StockList_View.ToList();
                    searchFormData.TotalPhysicalQnt       = s.Sum(o => (o.PhysicalQnt.HasValue ? o.PhysicalQnt.Value : 0));
                    searchFormData.TotalPhysicalQntIn40HC = s.Sum(o => (o.PhysicalQntIn40HC.HasValue ? o.PhysicalQntIn40HC.Value : 0));
                    searchFormData.TotalOnSeaQnt          = s.Sum(o => (o.OnSeaQnt.HasValue ? o.OnSeaQnt.Value : 0));
                    searchFormData.TotalTobeShippedQnt    = s.Sum(o => (o.TobeShippedQnt.HasValue ? o.TobeShippedQnt.Value : 0));
                    searchFormData.TotalReservationQnt    = s.Sum(o => (o.ReservationQnt.HasValue ? o.ReservationQnt.Value : 0));
                    searchFormData.TotalFTSQnt            = s.Sum(o => (o.FTSQnt.HasValue ? o.FTSQnt.Value : 0));

                    //cal sub total
                    var x = context.ReportMng_action_GetSearchStockList(orderBy, orderDirection
                                                                        , productStatusIDs
                                                                        , isMatchedImage
                                                                        , isHaveImage
                                                                        , articleCode
                                                                        , description
                                                                        , qnt40HC
                                                                        , physicalQnt
                                                                        , physicalQntIn40HC
                                                                        , wareHouseAreaIDs
                                                                        , qntPerWarehouseArea
                                                                        , onSeaQnt
                                                                        , tobeShippedQnt
                                                                        , reservationQnt
                                                                        , ftsQnt
                                                                        , isActiveFreeToSale
                                                                        , eanCode
                                                                        , freeToSaleCategoryIDs).ToList();

                    searchFormData.SubTotalPhysicalQnt       = x.Sum(o => (o.PhysicalQnt.HasValue ? o.PhysicalQnt.Value : 0));
                    searchFormData.SubTotalPhysicalQntIn40HC = x.Sum(o => (o.PhysicalQntIn40HC.HasValue ? o.PhysicalQntIn40HC.Value : 0));
                    searchFormData.SubTotalOnSeaQnt          = x.Sum(o => (o.OnSeaQnt.HasValue ? o.OnSeaQnt.Value : 0));
                    searchFormData.SubTotalTobeShippedQnt    = x.Sum(o => (o.TobeShippedQnt.HasValue ? o.TobeShippedQnt.Value : 0));
                    searchFormData.SubTotalReservationQnt    = x.Sum(o => (o.ReservationQnt.HasValue ? o.ReservationQnt.Value : 0));
                    searchFormData.SubTotalFTSQnt            = x.Sum(o => (o.FTSQnt.HasValue ? o.FTSQnt.Value : 0));

                    //cal total row
                    totalRows = x.Count();
                    //search result
                    var result = context.ReportMng_action_GetSearchStockList(orderBy, orderDirection
                                                                             , productStatusIDs
                                                                             , isMatchedImage
                                                                             , isHaveImage
                                                                             , articleCode
                                                                             , description
                                                                             , qnt40HC
                                                                             , physicalQnt
                                                                             , physicalQntIn40HC
                                                                             , wareHouseAreaIDs
                                                                             , qntPerWarehouseArea
                                                                             , onSeaQnt
                                                                             , tobeShippedQnt
                                                                             , reservationQnt
                                                                             , ftsQnt
                                                                             , isActiveFreeToSale
                                                                             , eanCode
                                                                             , freeToSaleCategoryIDs);

                    searchFormData.Data = converter.DB2DTO_StockListSearch(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());

                    //get list eancode
                    List <int?> productIDs = searchFormData.Data.Where(o => o.ProductType == "PRODUCT").Select(o => o.GoodsID).ToList();
                    searchFormData.ProductSetEANCodes = converter.DB2DTO_ProductSetEANCode(context.ReportMng_StockList_ProductSetEANCode_View.Where(o => productIDs.Contains(o.ProductID)).ToList());

                    //assign location for every product
                    List <string> keyIDs        = searchFormData.Data.Select(o => o.KeyID).ToList();
                    var           stockLocation = context.ReportMng_StockList_PhysicalStockByWarehouseArea_View.Where(o => keyIDs.Contains(o.KeyID)).ToList();

                    foreach (var item in searchFormData.Data)
                    {
                        item.WarehouseAreaUD     = "";
                        item.QntPerWarehouseArea = "";
                        foreach (var sItem in stockLocation.Where(o => o.KeyID == item.KeyID))
                        {
                            item.WarehouseAreaUD     += sItem.WarehouseAreaUD + " / ";
                            item.QntPerWarehouseArea += sItem.PhysicalQnt.ToString() + " / ";
                        }
                        if (item.WarehouseAreaUD.Length > 2)
                        {
                            item.WarehouseAreaUD = item.WarehouseAreaUD.Substring(0, item.WarehouseAreaUD.Length - 2);
                        }
                        if (item.QntPerWarehouseArea.Length > 2)
                        {
                            item.QntPerWarehouseArea = item.QntPerWarehouseArea.Substring(0, item.QntPerWarehouseArea.Length - 2);
                        }
                    }
                }

                //get support list
                DAL.Support.DataFactory support_factory = new Support.DataFactory();
                searchFormData.FreeToSaleCategories = support_factory.GetFreeToSaleCategory();
                searchFormData.ProductStatuses      = support_factory.GetProductStatus().ToList();
                searchFormData.WarehouseAreas       = support_factory.GetAllWarehouseArea().ToList();;
                return(searchFormData);
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(searchFormData);
            }
        }
Beispiel #13
0
        public override bool UpdateData(int id, ref DTO.ShowroomReceiptMng.ShowroomReceipt dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (ShowroomReceiptMngEntities context = CreateContext())
                {
                    ShowroomReceipt dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new ShowroomReceipt();
                        context.ShowroomReceipt.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.ShowroomReceipt.FirstOrDefault(o => o.ShowroomReceiptID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "data not found!";
                        return(false);
                    }
                    else
                    {
                        // check concurrency
                        //if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoItem.ConcurrencyFlag_String)))
                        //{
                        //    throw new Exception(DALBase.Helper.TEXT_CONCURRENCY_CONFLICT);
                        //}

                        if (dtoItem.ReceiptTypeID == 2) // 2: EXPORT
                        {
                            DAL.Support.DataFactory support_factory = new Support.DataFactory();
                            Hashtable support_filters = new Hashtable();
                            foreach (var item in dtoItem.ShowroomReceiptDetails)
                            {
                                if (item.ShowroomReceiptDetailID > 0)
                                {
                                    foreach (var area in item.ShowroomReceiptAreaDetails)
                                    {
                                        if (area.ShowroomReceiptAreaDetailID > 0)
                                        {
                                            var physicalByArea = support_factory.QuickSearchShowroomAreaByPhysicalQnt(support_filters, out notification).Where(o => o.ShowroomItemID == item.ShowroomItemID && o.ShowroomAreaID == area.ShowroomAreaID).FirstOrDefault();
                                            var currentArea    = context.ShowroomReceiptAreaDetail.Where(o => o.ShowroomReceiptAreaDetailID == area.ShowroomReceiptAreaDetailID).FirstOrDefault();
                                            if (physicalByArea == null)
                                            {
                                                throw new Exception("Could not find this product in area. You should select another area");
                                            }
                                            else if (area.Quantity - currentArea.Quantity > physicalByArea.Quantity)
                                            {
                                                throw new Exception("Quantity must be less than current physical quantity");
                                            }
                                        }
                                        else
                                        {
                                            var physicalByArea = support_factory.QuickSearchShowroomAreaByPhysicalQnt(support_filters, out notification).Where(o => o.ShowroomItemID == item.ShowroomItemID && o.ShowroomAreaID == area.ShowroomAreaID).FirstOrDefault();
                                            if (physicalByArea == null)
                                            {
                                                throw new Exception("Could not find this product in area. You should select another area");
                                            }
                                            else if (area.Quantity > physicalByArea.Quantity)
                                            {
                                                throw new Exception("Quantity must be less than current physical quantity");
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    foreach (var area in item.ShowroomReceiptAreaDetails)
                                    {
                                        var physicalByArea = support_factory.QuickSearchShowroomAreaByPhysicalQnt(support_filters, out notification).Where(o => o.ShowroomItemID == item.ShowroomItemID && o.ShowroomAreaID == area.ShowroomAreaID).FirstOrDefault();
                                        if (physicalByArea == null)
                                        {
                                            throw new Exception("Could not find this product in area. You should select another area");
                                        }
                                        else if (area.Quantity > physicalByArea.Quantity)
                                        {
                                            throw new Exception("Quantity must be less than current physical quantity");
                                        }
                                    }
                                }
                            }
                        }

                        //convert dto to db
                        converter.DTO2DB_ShowroomReceipt(dtoItem, ref dbItem);
                        //reove orphan
                        context.ShowroomReceiptAreaDetail.Local.Where(o => o.ShowroomReceiptDetail == null).ToList().ForEach(o => context.ShowroomReceiptAreaDetail.Remove(o));
                        context.ShowroomReceiptDetail.Local.Where(o => o.ShowroomReceipt == null).ToList().ForEach(o => context.ShowroomReceiptDetail.Remove(o));
                        //save data
                        context.SaveChanges();
                        //update receipt no
                        context.ShowroomReceiptMng_function_GenerateReceipNo(dbItem.ShowroomReceiptID, dbItem.Season, dbItem.ReceiptTypeID);
                        //get return data
                        dtoItem = GetData(dbItem.ShowroomReceiptID, out notification).Data;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(false);
            }
        }
Beispiel #14
0
        public bool TransferMultiItem(List <DTO.TransferShowroomAreaMng.TransferShowroomAreaSearch> dtoItem, out List <DTO.TransferShowroomAreaMng.TransferShowroomAreaSearch> errorItems, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success, Message = "Transfer success"
            };
            errorItems = new List <DTO.TransferShowroomAreaMng.TransferShowroomAreaSearch>();
            try
            {
                TransferShowroomArea    dbTransfer;
                Hashtable               filter          = new Hashtable();
                DAL.Support.DataFactory support_factory = new Support.DataFactory();

                var dtoItemGroup = from p in dtoItem group p by new { p.ShowroomItemID, p.FromShowroomAreaID } into g select new { g.Key.ShowroomItemID, g.Key.FromShowroomAreaID, TotalTransferQnt = g.Sum(x => x.Quantity) };
                foreach (var item in dtoItemGroup)
                {
                    var physicalByArea = new DAL.Support.DataFactory().QuickSearchShowroomAreaByPhysicalQnt(filter, out notification).Where(o => o.ShowroomItemID == item.ShowroomItemID && o.ShowroomAreaID == item.FromShowroomAreaID).FirstOrDefault();
                    if (physicalByArea == null)
                    {
                        DTO.TransferShowroomAreaMng.TransferShowroomAreaSearch errorItem = new DTO.TransferShowroomAreaMng.TransferShowroomAreaSearch();
                        errorItem.ShowroomItemID   = item.ShowroomItemID;
                        errorItem.ToShowroomAreaID = item.FromShowroomAreaID;
                        errorItems.Add(errorItem);
                        throw new Exception("Could not find this product in area. You should select another area");
                    }
                    else if (item.TotalTransferQnt > physicalByArea.Quantity)
                    {
                        DTO.TransferShowroomAreaMng.TransferShowroomAreaSearch errorItem = new DTO.TransferShowroomAreaMng.TransferShowroomAreaSearch();
                        errorItem.ShowroomItemID   = item.ShowroomItemID;
                        errorItem.ToShowroomAreaID = item.FromShowroomAreaID;
                        errorItems.Add(errorItem);
                        throw new Exception("Quantity must be less than current physical quantity");
                    }
                }

                foreach (var item in dtoItem)
                {
                    if (!item.ToShowroomAreaID.HasValue)
                    {
                        throw new Exception("Can not transfer. You have to select To Area");
                    }

                    if (item.FromShowroomAreaID == item.ToShowroomAreaID)
                    {
                        throw new Exception("Can not transfer. From Area have to difference with To Area");
                    }
                }

                using (TransferShowroomAreaMngEntities context = CreateContext())
                {
                    foreach (var item in dtoItem)
                    {
                        dbTransfer = new TransferShowroomArea();
                        converter.DTO2DB_TransferArea(item, ref dbTransfer);
                        context.TransferShowroomArea.Add(dbTransfer);
                    }
                    context.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(false);
            }
        }