Esempio n. 1
0
 public bool IsDifferentFrom(ReactionRSN otherRsn)
 {
     if (otherRsn == null)
     {
         return(true);
     }
     return(this.DisplayOrder != otherRsn.DisplayOrder || this.CVT != otherRsn.CVT || this.FreeText != otherRsn.FreeText);
 }
Esempio n. 2
0
        public static Tan GetTanFromViewModel(MainVM mainViewModel)
        {
            var tan = new Tan();

            try
            {
                var ReactionParticipants = new List <ReactionRSD>();
                var reactions            = new List <Reaction>();
                var Participants         = new List <ReactionRSD>();
                var RSNs = new List <ProductTracking.Models.Core.ReactionRSN>();
                tan.TanChemicals = mainViewModel.TanVM.TanChemicals;
                List <string> TanTempDefaultComments = new List <string>();
                #region Reactions
                foreach (var reaction in mainViewModel.TanVM.Reactions)
                {
                    var           reactionYield = mainViewModel.TanVM.ReactionParticipants.OfReactionOfType(reaction.Id, ParticipantType.Product).Select(rp => rp.ReactionYield).FirstOrDefault();
                    List <string> PORMComments  = new List <string>();
                    var           dbreaction    = new Reaction
                    {
                        Id                    = reaction.Id,
                        DisplayOrder          = reaction.DisplayOrder,
                        Name                  = reaction.Name,
                        TanId                 = reaction.TanVM.Id,
                        AnalogousFromId       = reaction.AnalogousVMId,
                        IsCurationCompleted   = reaction.IsCurationCompleted,
                        IsReviewCompleted     = reaction.IsReviewCompleted,
                        Yield                 = reactionYield,
                        Tan                   = tan,
                        CuratorCreatedDate    = reaction.CuratorCreatedDate,
                        LastUpdatedDate       = reaction.LastupdatedDate,
                        CuratorCompletedDate  = reaction.CuratorCompletedDate,
                        ReviewerCreatedDate   = reaction.ReviewerCreatedDate,
                        ReviewLastUpdatedDate = reaction.ReviewLastupdatedDate,
                        ReviewerCompletedDate = reaction.ReviewerCompletedDate,
                        QCLastUpdatedDate     = reaction.QCLastupdatedDate,
                        QCCompletedDate       = reaction.QcCompletedDate
                    };
                    var stages = new List <Stage>();
                    foreach (var stage in reaction.Stages)
                    {
                        var conditions = new List <ProductTracking.Models.Core.StageCondition>();
                        if (stage.Conditions != null)
                        {
                            foreach (var condition in stage.Conditions)
                            {
                                var dbcondition = new ProductTracking.Models.Core.StageCondition
                                {
                                    Id            = condition.Id,
                                    DisplayOrder  = condition.DisplayOrder,
                                    PH            = condition.PH,
                                    Pressure      = condition.Pressure,
                                    StageId       = stage.Id,
                                    Temperature   = condition.Temperature,
                                    Time          = condition.Time,
                                    TEMP_TYPE     = condition.TEMP_TYPE,
                                    TIME_TYPE     = condition.TIME_TYPE,
                                    PH_TYPE       = condition.PH_TYPE,
                                    PRESSURE_TYPE = condition.PRESSURE_TYPE
                                };
                                if (condition.TEMP_TYPE == TemperatureEnum.pluseDevminus.ToString())
                                {
                                    PORMComments.Add(" needs TP=" + condition.Temperature);
                                }
                                if (dbcondition.Id == Guid.Empty)
                                {
                                }
                                else
                                {
                                    conditions.Add(dbcondition);
                                }
                            }
                        }
                        var dbstage = new Stage
                        {
                            Id              = stage.Id,
                            DisplayOrder    = stage.DisplayOrder,
                            Name            = stage.Name,
                            ReactionId      = reaction.Id,
                            StageConditions = conditions
                        };
                        stages.Add(dbstage);
                    }
                    dbreaction.Stages = stages;
                    reactions.Add(dbreaction);
                    if (PORMComments.Count > 0)
                    {
                        TanTempDefaultComments.Add("NUM-SEQ " + reaction.KeyProductSeq + string.Join(", ", PORMComments));
                    }
                }
                tan.Reactions = reactions;

                #region TanDefaultComments
                List <ViewModels.Core.Comments> tempComments = mainViewModel.TanVM.TanComments.TanComments.Where(tc => tc.CommentType == CommentType.TEMPERATURE).ToList();
                foreach (var item in tempComments)
                {
                    mainViewModel.TanVM.TanComments.TanComments.Remove(item);
                }
                if (TanTempDefaultComments.Count > 0)
                {
                    mainViewModel.TanVM.TanComments.TanComments.Add(new ViewModels.Core.Comments
                    {
                        Comment      = string.Join(". ", TanTempDefaultComments),
                        TotalComment = string.Join(". ", TanTempDefaultComments),
                        CommentType  = CommentType.TEMPERATURE,
                        Id           = Guid.NewGuid()
                    });
                }
                List <ViewModels.Core.Comments> defaultComments = mainViewModel.TanVM.TanComments.TanComments.Where(tc => tc.CommentType == CommentType.DEFAULT).ToList();
                foreach (var item in defaultComments)
                {
                    mainViewModel.TanVM.TanComments.TanComments.Remove(item);
                }


                var _8500Series = mainViewModel.TanVM.ReactionParticipants.OfType(ParticipantType.Product, ParticipantType.Reactant).OfChemicalType(ChemicalType.S8500);
                var _8000Series = mainViewModel.TanVM.ReactionParticipants.OfType(ParticipantType.Product, ParticipantType.Reactant).OfChemicalType(ChemicalType.S8000);

                if (_8500Series.Where(p => p.ParticipantType == ParticipantType.Product).Count() > 0 && _8500Series.Where(p => p.ParticipantType == ParticipantType.Reactant).Count() > 0)
                {
                    mainViewModel.TanVM.TanComments.TanComments.Add(new ViewModels.Core.Comments {
                        Comment = "8500 used as product and reactant", TotalComment = "8500 used as product and reactant", CommentType = CommentType.DEFAULT, Id = Guid.NewGuid()
                    });
                }
                if (_8000Series.Where(p => p.ParticipantType == ParticipantType.Product).Count() > 0 && _8000Series.Where(p => p.ParticipantType == ParticipantType.Reactant).Count() > 0)
                {
                    mainViewModel.TanVM.TanComments.TanComments.Add(new ViewModels.Core.Comments {
                        Comment = "8000 used as product and reactant", TotalComment = "8000 used as product and reactant", CommentType = CommentType.DEFAULT, Id = Guid.NewGuid()
                    });
                }

                if (_8500Series.Where(p => p.ParticipantType == ParticipantType.Product).Count() > 0 && _8500Series.Where(p => p.ParticipantType == ParticipantType.Reactant).Count() == 0)
                {
                    mainViewModel.TanVM.TanComments.TanComments.Add(new ViewModels.Core.Comments {
                        Comment = "8500 used as product", TotalComment = "8500 used as product", CommentType = CommentType.DEFAULT, Id = Guid.NewGuid()
                    });
                }
                if (_8000Series.Where(p => p.ParticipantType == ParticipantType.Product).Count() > 0 && _8000Series.Where(p => p.ParticipantType == ParticipantType.Reactant).Count() == 0)
                {
                    mainViewModel.TanVM.TanComments.TanComments.Add(new ViewModels.Core.Comments {
                        Comment = "8000 used as product", TotalComment = "8000 used as product", CommentType = CommentType.DEFAULT, Id = Guid.NewGuid()
                    });
                }

                if (_8500Series.Where(p => p.ParticipantType == ParticipantType.Product).Count() == 0 && _8500Series.Where(p => p.ParticipantType == ParticipantType.Reactant).Count() > 0)
                {
                    mainViewModel.TanVM.TanComments.TanComments.Add(new ViewModels.Core.Comments {
                        Comment = "8500 used as reactant", TotalComment = "8500 used as reactant", CommentType = CommentType.DEFAULT, Id = Guid.NewGuid()
                    });
                }
                if (_8000Series.Where(p => p.ParticipantType == ParticipantType.Product).Count() == 0 && _8000Series.Where(p => p.ParticipantType == ParticipantType.Reactant).Count() > 0)
                {
                    mainViewModel.TanVM.TanComments.TanComments.Add(new ViewModels.Core.Comments {
                        Comment = "8000 used as reactant", TotalComment = "8000 used as reactant", CommentType = CommentType.DEFAULT, Id = Guid.NewGuid()
                    });
                }
                #endregion

                #endregion

                #region Participants
                if (mainViewModel.TanVM.ReactionParticipants != null)
                {
                    foreach (var participant in mainViewModel.TanVM.ReactionParticipants)
                    {
                        var dbParticipant = new ReactionRSD
                        {
                            Id              = participant.Id,
                            DisplayYield    = participant.Yield,
                            Yield           = participant.ProductYield,
                            DisplayOrder    = participant.DisplayOrder,
                            ParticipantId   = participant.TanChemicalId,
                            ParticipantType = participant.ParticipantType,
                            ReactionId      = participant.ReactionVM.Id,
                            StageId         = participant.StageVM?.Id,
                            TanId           = mainViewModel.TanVM.Id,
                            KeyProduct      = participant.KeyProduct,
                            KeyProductSeq   = participant.KeyProductSeqWithOutNum,
                            Name            = participant.Name
                        };
                        Participants.Add(dbParticipant);
                    }
                }
                tan.Participants = Participants;
                #endregion

                #region RSN
                foreach (var comment in mainViewModel.TanVM.Rsns)
                {
                    var dbcomment = new ProductTracking.Models.Core.ReactionRSN
                    {
                        CVT                   = comment.CvtText,
                        FreeText              = comment.FreeText,
                        ReactionId            = comment.Reaction.Id,
                        StageId               = comment.Stage != null ? comment.Stage?.Id : Guid.Empty,
                        TanId                 = mainViewModel.TanVM.Id,
                        Id                    = comment.Id,
                        DisplayOrder          = comment.DisplayOrder,
                        IsIgnorableInDelivery = comment.IsIgnorableInDelivery,
                        ReactionParticipantId = comment.ReactionParticipantId
                    };
                    RSNs.Add(dbcomment);
                }
                tan.RSNs = RSNs;
                #endregion

                tan.Id            = mainViewModel.TanVM.Id;
                tan.tanNumber     = mainViewModel.TanVM.TanNumber;
                tan.DocumentPath  = mainViewModel.TanVM.DocumentPath;
                tan.IsQCCompleted = mainViewModel.TanVM.IsQCCompleted;
                tan.CAN           = mainViewModel.TanVM.CanNumber;
                #region TanComments
                var tancomments = new List <ProductTracking.Models.Core.Comments>();
                foreach (var com in mainViewModel.TanVM.TanComments.TanComments)
                {
                    var comment = new ProductTracking.Models.Core.Comments
                    {
                        Comment      = com.Comment,
                        TotalComment = com.TotalComment,
                        CommentType  = com.CommentType,
                        Id           = com.Id,
                        Length       = com.TotalComment != null ? com.TotalComment.Length : 0,
                        Column       = com.Column,
                        Figure       = com.Figure,
                        FootNote     = com.FootNote,
                        Line         = com.Line,
                        Num          = com.Num,
                        Page         = com.Page,
                        Para         = com.Para,
                        Schemes      = com.Schemes,
                        Sheet        = com.Sheet,
                        Table        = com.Table,
                    };
                    tancomments.Add(comment);
                }
                if (tan.Reactions.Count == 0)
                {
                    if (tancomments.Where(tc => tc.Comment.ToLower() == "No Reactions in the Article".ToLower()).Count() == 0)
                    {
                        tancomments.Add(new ProductTracking.Models.Core.Comments {
                            Comment = "No reactions in the article", TotalComment = "No reactions in the article", CommentType = CommentType.DEFAULT, Id = Guid.NewGuid(), Length = "No reactions in the article".Length
                        });
                    }
                }
                else
                {
                    var comment = tancomments.Where(tc => tc.Comment.ToLower() == "No reactions in the article".ToLower()).FirstOrDefault();
                    tancomments.Remove(comment);
                }
                tan.TanComments = tancomments;
                #endregion
                tan.Batch = new ProductTracking.Models.Core.Batch
                {
                    Id            = mainViewModel.Batch.Id,
                    DateCreated   = mainViewModel.Batch.DateCreated,
                    DocumentsPath = mainViewModel.Batch.DocumentsPath,
                    GifImagesPath = mainViewModel.Batch.GifImagesPath,
                    Name          = mainViewModel.Batch.Name
                };
            }
            catch (Exception ex)
            {
                Log.This(ex);
                AppErrorBox.ShowErrorMessage("Can't Get TAN From View . .", ex.ToString());
            }
            return(tan);
        }