Ejemplo n.º 1
0
 private void DeleteTblSampleRVCMatches(tblSampleDetail detail)
 {
     foreach(var match in detail.tblSampleRVCMatches.ToList())
     {
         OldContext.tblSampleRVCMatches.DeleteObject(match);
     }
 }
Ejemplo n.º 2
0
 private void DeleteTblSampleCustSpecs(tblSampleDetail detail)
 {
     foreach(var spec in detail.tblSampleCustSpecs.ToList())
     {
         OldContext.tblSampleCustSpecs.DeleteObject(spec);
     }
 }
Ejemplo n.º 3
0
        private void DeleteTblSampleDetail(tblSampleDetail detail)
        {
            DeleteTblSampleCustSpecs(detail);
            DeleteTblSampleRVCMatches(detail);

            foreach(var match in detail.tblSampleCusMatches.ToList())
            {
                OldContext.tblSampleCusMatches.DeleteObject(match);
            }

            foreach(var ingredient in detail.tblSampleRVCIngredients.ToList())
            {
                OldContext.tblSampleRVCIngredients.DeleteObject(ingredient);
            }

            OldContext.tblSampleDetails.DeleteObject(detail);
        }
Ejemplo n.º 4
0
        private void SetTblSampleDetails(tblSample tblSample, SampleOrder sampleOrder, ref bool commitNewContext)
        {
            var existingDetails = tblSample.tblSampleDetails.ToDictionary(n => n.SampleDetailID);
            var sampleDetailId = OldContext.tblSampleDetails.Select(n => n.SampleDetailID).DefaultIfEmpty(DateTime.Now.RoundMillisecondsForSQL()).Max();
            var custSpecId = OldContext.tblSampleCustSpecs.Select(n => n.CustSpecID).DefaultIfEmpty(DateTime.Now.RoundMillisecondsForSQL()).Max();
            var rvcMatchId = OldContext.tblSampleRVCMatches.Select(n => n.RVCMatchID).DefaultIfEmpty(DateTime.Now.RoundMillisecondsForSQL()).Max();
            foreach(var item in sampleOrder.Items)
            {
                tblSampleDetail detail = null;
                if(item.SampleDetailID != null && existingDetails.TryGetValue(item.SampleDetailID.Value, out detail))
                {
                    existingDetails.Remove(detail.SampleDetailID);
                }

                if(detail == null)
                {
                    commitNewContext = true;
                    sampleDetailId = sampleDetailId.AddSeconds(1);
                    detail = new tblSampleDetail
                        {
                            SampleDetailID = sampleDetailId,
                            SampleID = tblSample.SampleID,
                            s_GUID = Guid.NewGuid()
                        };
                    OldContext.tblSampleDetails.AddObject(detail);
                    item.SampleDetailID = detail.SampleDetailID;
                }

                detail.ProdID = item.Product == null ? (int?) null : int.Parse(item.Product.ProductCode);
                detail.Lot = item.Lot == null ? (int?) null : LotNumberParser.BuildLotNumber(item.Lot);
                detail.Qty = item.Quantity;
                detail.Desc = item.Description;
                detail.SampleMatch = item.CustomerProductName;

                if(item.Spec == null)
                {
                    DeleteTblSampleCustSpecs(detail);
                }
                else
                {
                    var spec = detail.tblSampleCustSpecs.FirstOrDefault(s => s.CustSpecID == item.Spec.CustSpecID);
                    if(spec == null)
                    {
                        commitNewContext = true;
                        custSpecId = custSpecId.AddSeconds(1);
                        spec = new tblSampleCustSpec
                            {
                                CustSpecID = custSpecId,
                                SampleDetailID = detail.SampleDetailID
                            };
                        OldContext.tblSampleCustSpecs.AddObject(spec);
                        item.Spec.CustSpecID = spec.CustSpecID;
                    }

                    SetSpec(spec, item.Spec);
                }

                if(item.Match == null)
                {
                    DeleteTblSampleRVCMatches(detail);
                }
                else
                {
                    var match = detail.tblSampleRVCMatches.FirstOrDefault(s => s.RVCMatchID == item.Match.RVCMatchID);
                    if(match == null)
                    {
                        commitNewContext = true;
                        rvcMatchId = rvcMatchId.AddSeconds(1);
                        match = new tblSampleRVCMatch
                            {
                                RVCMatchID = rvcMatchId,
                                SampleDetailID = detail.SampleDetailID
                            };
                        OldContext.tblSampleRVCMatches.AddObject(match);
                        item.Match.RVCMatchID = match.RVCMatchID;
                    }

                    SetMatch(match, item.Match);
                }
            }

            foreach(var detail in existingDetails)
            {
                DeleteTblSampleDetail(detail.Value);
            }
        }