예제 #1
0
        public static Tbl_ReservationMainDetails MaptoViewModel(TblReservationMainDetailsViewModel resRow)
        {
            var detailsList = new ObservableCollection <Tbl_ReservationDetails>();

            foreach (var row in resRow.ReservationDetailsViewModelList)
            {
                var newDetail = new Tbl_ReservationDetails();
                GenericMapper.InjectFromObCollection(newDetail.Tbl_ReservationRec, row.ReservationListRec);
                newDetail.InjectFrom(row);
                detailsList.Add(newDetail);
            }

            var newRow = new Tbl_ReservationMainDetails();

            newRow.InjectFrom(resRow);
            newRow.Tbl_ReservationDetails = detailsList;

            return(newRow);
        }
예제 #2
0
        public void GenerateReservationFromPlan(Tbl_ReservationHeader header)
        {
            if (header.Iserial == 0)
            {
                using (var context = new WorkFlowManagerDBEntities())
                {
                    using (var scope = new TransactionScope())
                    {
                        header.IsPosted = false;
                        header.DocNo    = "TEST";
                        context.AddObject("Tbl_ReservationHeader", header);
                        context.SaveChanges();

                        var valuesObjects = new Dictionary <string, object>();
                        var filter        = "it.PURCHID ==(@PURCHID0)";
                        valuesObjects.Add("PURCHID0", header.TransOrder);
                        filter = filter + " and it.DATAAREAID ==(@DATAAREAID0)";
                        valuesObjects.Add("DATAAREAID0", "ccm");
                        var parameterCollection = ConvertToParamters(valuesObjects);
                        var querytemp           = context.PurchlineInventDims.Where(filter, parameterCollection.ToArray());
                        foreach (var p in querytemp)
                        {
                            var newrow = new Tbl_ReservationMainDetails
                            {
                                Fabric                = p.ITEMID,
                                FabricUnit            = p.PURCHUNIT,
                                FabricColor           = p.CONFIGID,
                                Batchno               = p.INVENTBATCHID,
                                Qty                   = (float)p.PURCHQTY,
                                Inspected             = false,
                                LineNum               = p.LINENUM,
                                Location              = p.WMSLOCATIONID,
                                Warehouse             = p.INVENTLOCATIONID,
                                Site                  = p.INVENTSITEID,
                                Tbl_ReservationHeader = header.Iserial,
                            };

                            var purchaseOrderDetails = from x in context.TblPurchaseOrderDetails.Include(
                                "TblPurchaseOrderDetailBreakDowns.BOM1.TblSalesOrder1")
                                                       let purid = ("p" + x.TblPurchaseOrderHeader1.TblGeneratePurchaseHeader1.Code + "_" +
                                                                    x.TblPurchaseOrderHeader1.Vendor).ToLower()
                                                                   where x.ItemId == p.ITEMID && x.TblColor.Code == p.CONFIGID &&
                                                                   p.PURCHID == (purid)
                                                                   select x
                            ;
                            //var purchaseOrderDetails =
                            //    context.TblPurchaseOrderDetails.Include(
                            //        "TblPurchaseOrderDetailBreakDowns.BOM1.TblSalesOrder1")
                            //        .Where(
                            //            x =>
                            //                x.ItemId == p.ITEMID && x.TblColor.Code == p.CONFIGID &&
                            //                'P' + x.TblPurchaseOrderHeader1.TblGeneratePurchaseHeader1.Code + '_' +
                            //                x.TblPurchaseOrderHeader1.Vendor == p.PURCHID).ToList();
                            var reservationDetailList = new EntityCollection <Tbl_ReservationDetails>();

                            foreach (var purchaseLine in purchaseOrderDetails.ToList())
                            {
                                foreach (var row in purchaseLine.TblPurchaseOrderDetailBreakDowns)
                                {
                                    var percentage = row.Qty / purchaseLine.Qty;

                                    float salesorderQty = (float)(percentage * newrow.Qty);

                                    var newdetailrow = new Tbl_ReservationDetails
                                    {
                                        FinalQty              = salesorderQty,
                                        IntialQty             = salesorderQty,
                                        Markered              = false,
                                        AxPicklingListJournal = "",
                                        SalesOrderColor       = p.CONFIGID,
                                        SalesOrder            = row.BOM1.TblSalesOrder1.SalesOrderCode,
                                    };
                                    reservationDetailList.Add(newdetailrow);
                                }
                            }
                            newrow.Tbl_ReservationDetails = reservationDetailList;

                            context.Tbl_ReservationMainDetails.AddObject(newrow);
                        }
                        context.SaveChanges();
                        scope.Complete();
                    }
                }
            }
        }