Exemplo n.º 1
0
        public void GenerateDyeingOrdersAcc(int iserial)
        {
            using (var entities = new WorkFlowManagerDBEntities())
            {
                var planHeader = entities.TblDyeingPlanHeaderAccs.SingleOrDefault(x => x.Iserial == iserial);
                planHeader.PlanGenerated = true;

                var dyeingSummaryList = entities.TblDyeingSummaryAccs.Where(x => x.DyeingHeader == planHeader.Iserial).ToList();
                var vendorList        = dyeingSummaryList.Select(x => x.Vendor).Distinct().ToList();

                foreach (var item in vendorList)
                {
                    var dyeingHeaderRow = new TblDyeingOrdersHeaderAcc {
                        DocPlan = planHeader.DocNo, Vendor = item
                    };

                    entities.AddToTblDyeingOrdersHeaderAccs(dyeingHeaderRow);
                    entities.SaveChanges();

                    const int transId     = 1;
                    var       mainDetails = new TblDyeingOrdersMainDetailsACC
                    {
                        DyeingProductionOrder = dyeingHeaderRow.DyeingProductionOrder,
                        WareHouse             = planHeader.Location,
                        TransactionType       = 0,
                        TransId = transId,
                        Posted  = false
                    };
                    entities.AddToTblDyeingOrdersMainDetailsACCs(mainDetails);
                    entities.SaveChanges();

                    var summarylist = dyeingSummaryList.Where(x => x.Vendor == item).ToList();
                    var sub         = new ObservableCollection <TblDyeingOrdersDetailsAcc>();
                    foreach (var dyeingObject in summarylist)
                    {
                        sub.Add(new TblDyeingOrdersDetailsAcc
                        {
                            Size  = dyeingObject.Size,
                            Color = dyeingObject.Color,

                            DyedFabric            = dyeingObject.DyedFabric,
                            Unit                  = dyeingObject.Unit,
                            CalculatedTotalQty    = Convert.ToSingle(dyeingObject.CalculatedTotalQty),
                            FabricCode            = dyeingObject.FabricCode,
                            DyeingProductionOrder = dyeingHeaderRow.DyeingProductionOrder,
                            TransactionType       = mainDetails.TransactionType,
                            TransId               = mainDetails.TransId,
                        });
                    }

                    foreach (var orderDetails in sub)
                    {
                        entities.AddToTblDyeingOrdersDetailsAccs(orderDetails);
                        entities.SaveChanges();
                    }
                }
            }
        }
Exemplo n.º 2
0
        public List <TblDyeingOrdersMainDetailsACC> SaveDyeingOrderAcc(TblDyeingOrdersHeaderAcc header, List <TblDyeingOrdersMainDetailsACC> Maindetails)
        {
            using (var entities = new WorkFlowManagerDBEntities())
            {
                if (header.DyeingProductionOrder != 0)
                {
                    var h = entities.TblDyeingOrdersHeaderAccs.SingleOrDefault(x => x.DyeingProductionOrder == header.DyeingProductionOrder);

                    if (h != null)
                    {
                        h.DocPlan         = header.DocPlan;
                        h.TransactionDate = header.TransactionDate;
                        h.Vendor          = header.Vendor;
                    }
                }
                else
                {
                    entities.AddToTblDyeingOrdersHeaderAccs(header);
                }
                entities.SaveChanges();

                foreach (var item in Maindetails)
                {
                    if (item.DyeingProductionOrder == 0)
                    {
                        item.DyeingProductionOrder = header.DyeingProductionOrder;
                        entities.AddToTblDyeingOrdersMainDetailsACCs(item);
                    }
                    else
                    {
                        var mainDetailRow = (from d in entities.TblDyeingOrdersMainDetailsACCs
                                             where d.TransId == item.TransId && d.TransactionType == item.TransactionType &&
                                             d.DyeingProductionOrder == item.DyeingProductionOrder
                                             select d).SingleOrDefault();

                        if (mainDetailRow != null)
                        {
                            GenericUpdate(mainDetailRow, item, entities);
                        }
                        else
                        {
                            entities.AddToTblDyeingOrdersMainDetailsACCs(item);
                        }
                    }
                    entities.SaveChanges();

                    if (item.DyeingProductionOrder != 0)
                    {
                        foreach (var items in item.TblDyeingOrdersDetailsAccs.ToList())
                        {
                            var dyeingOrderDetails = (from d in entities.TblDyeingOrdersDetailsAccs
                                                      where d.Iserial == items.Iserial && d.TransactionType == item.TransactionType
                                                      select d).SingleOrDefault();
                            if (dyeingOrderDetails != null)
                            {
                                GenericUpdate(dyeingOrderDetails, items, entities);
                            }
                            else
                            {
                                items.TblDyeingOrdersMainDetailsACC = null;
                                entities.AddToTblDyeingOrdersDetailsAccs(items);
                            }
                            entities.SaveChanges();
                        }
                    }
                }
            }
            return(Maindetails);
        }