public void Post()
        {
            if (this.Status == ProdRouteListStatus.Waiting)
            {
                if (this.FromProdRoute != null)
                {
                    ProdRouteList fromProdRouteList = new ProdRouteList(Session);
                    fromProdRouteList.Date = this.Date;
                    fromProdRouteList.ProdRoute = this.FromProdRoute;
                    fromProdRouteList.Qty = this.Qty * -1;
                    fromProdRouteList.ScrapQty = this.ScrapQty;
                    fromProdRouteList.Save();
                    FromProdRoute.UpdateTotalIOQty(); // ToProdRoute.WorkCenter.Type ==
                }

                if (this.ToProdRoute != null)
                {
                    ProdRouteList toProdRouteList = new ProdRouteList(Session);

                    toProdRouteList.Date = this.Date;
                    toProdRouteList.ProdRoute = this.ToProdRoute;
                    toProdRouteList.Qty = this.Qty;
                    toProdRouteList.ScrapQty = this.ScrapQty;
                    toProdRouteList.Save();
                    ToProdRoute.UpdateTotalIOQty();
                }

                _Status = ProdRouteListStatus.Complete;
                OnChanged("Status");

                _PostDate = ServerHelper.GetCurrentDateTime();
                OnChanged("PostDate");

                _PostBy = base.CurrentUser;
                OnChanged("PostBy");

                ProdOrder.UpdateWipQty();
                ProdOrder.UpdateKitQty();
                ProdOrder.Save();
            }
        }
        private void GenerateProdRouteListActivity(ProdRouteList prListOriginal, UnitOfWork uow)
        {
            ProdRoute pRoute = prListOriginal.ProdRoute;
            SortingCollection sortProps;
            sortProps = new SortingCollection(null);
            sortProps.Add(new SortProperty("CreatedDate", SortingDirection.Ascending));
            pRoute.ProdRouteLists.Sorting = sortProps;

            Dictionary<ProdRouteList, float> dictListIn = new Dictionary<ProdRouteList, float>();
            TimeSpan timeDiff;

            System.Collections.ArrayList arrayOut = new System.Collections.ArrayList();
            System.Collections.ArrayList arrayIn = new System.Collections.ArrayList();

            foreach (ProdRouteList prList in pRoute.ProdRouteLists)
            {
                if (prList.Qty > 0)
                    arrayOut.Add(prList);
                else
                {
                    arrayIn.Add(prList);
                    dictListIn.Add(prList, 0);
                }
            }

            foreach (ProdRouteList prListOut in arrayOut)
            {
                float outQty = prListOut.Qty;
                ProdRouteListActivity prlActivity;

                foreach (ProdRouteList prListIn in arrayIn)
                {
                    float inQty = dictListIn[prListIn];

                    float inBal = Math.Abs(prListIn.Qty) - inQty;

                    if (inBal > 0)
                    {
                        if (outQty > inBal)
                        {
                            if (prListIn == prListOriginal)
                            {
                                prlActivity = new ProdRouteListActivity(uow);
                                prlActivity.StartDate = prListOut.Date;
                                prlActivity.EndDate = prListIn.Date;
                                prlActivity.ProdRoute = pRoute;
                                prlActivity.Qty = inBal;
                                timeDiff = prlActivity.EndDate.Subtract(prlActivity.StartDate);
                                prlActivity.WorkDay = (int)timeDiff.TotalDays;
                                if (pRoute.Item.ColorCode != null)
                                {
                                    if (prlActivity.WorkDay > pRoute.ProdOrder.Item.ColorCode.DefaultSampleLT)
                                        prlActivity.Status = ProdRouteListActivity.ActivityStatus.Fail;
                                }
                                prlActivity.Save();
                            }
                            outQty = outQty - inBal;
                            dictListIn[prListIn] = Math.Abs(prListIn.Qty);
                        }
                        else
                        {
                            if (prListIn == prListOriginal)
                            {
                                prlActivity = new ProdRouteListActivity(uow);
                                prlActivity.StartDate = prListOut.Date;
                                prlActivity.EndDate = prListIn.Date;
                                prlActivity.ProdRoute = pRoute;
                                prlActivity.Qty = outQty;
                                timeDiff = prlActivity.EndDate.Subtract(prlActivity.StartDate);
                                prlActivity.WorkDay = (int)timeDiff.TotalDays;
                                if (pRoute.Item.ColorCode != null)
                                {
                                    if (prlActivity.WorkDay > pRoute.ProdOrder.Item.ColorCode.DefaultSampleLT)
                                        prlActivity.Status = ProdRouteListActivity.ActivityStatus.Fail;
                                }
                                prlActivity.Save();
                            }

                            dictListIn[prListIn] = dictListIn[prListIn] + outQty;
                            outQty = 0;
                            break;
                        }
                    }
                }
            }
        }