Beispiel #1
0
        private async Task UserReactionsReports(int Roleid)
        {
            try
            {
                var        mainVm = (App.Current.MainWindow as MainWindow).DataContext as MainVM;
                RestStatus status = await RestHub.UserReactionsReports(RoleId);

                if (status.HttpCode == System.Net.HttpStatusCode.OK)
                {
                    List <UserReportsDTO> userReportDto = (List <UserReportsDTO>)status.UserObject;
                    mainVm.UserReports    = new ObservableCollection <ViewModels.Extended.UserResportsVM>();
                    mainVm.AllUserReports = new ObservableCollection <ViewModels.Extended.UserResportsVM>();
                    foreach (var userReport in userReportDto.Where(ur => ur.SingleUser))
                    {
                        mainVm.UserReports.Add(new ViewModels.Extended.UserResportsVM {
                            Date = userReport.Date, ReactionsCount = userReport.ReactionsCount
                        });
                    }
                    mainVm.UserReports.Add(new ViewModels.Extended.UserResportsVM {
                        Date = DateTime.Now.AddDays(1).Date.ToString("dd-MM"), ReactionsCount = 0
                    });
                    foreach (var userReport in userReportDto.Where(ur => !ur.SingleUser))
                    {
                        mainVm.AllUserReports.Add(new ViewModels.Extended.UserResportsVM {
                            Date = userReport.Date, ReactionsCount = userReport.ReactionsCount
                        });
                    }
                    mainVm.AllUserReports.Add(new ViewModels.Extended.UserResportsVM {
                        Date = DateTime.Now.AddDays(1).Date.ToString("dd-MM"), ReactionsCount = 0
                    });
                }
                else
                {
                    AppErrorBox.ShowErrorMessage("User Report Can't Be Loaded", status.StatusMessage);
                }
            }
            catch (Exception ex)
            {
                Log.This(ex);
            }
        }
Beispiel #2
0
        private async void DoSaveQueryAsync(object obj)
        {
            Loading = true;
            if (FormQuery != null && FormQuery.TanId > 0 && !String.IsNullOrEmpty(FormQuery.TanNumber) && !String.IsNullOrEmpty(FormQuery.Title) && !String.IsNullOrEmpty(FormQuery.Comment) && U.RoleId != 4)
            {
                try
                {
                    QueryDTO dto = new QueryDTO()
                    {
                        Comment   = FormQuery.Comment,
                        Id        = FormQuery.Id,
                        Page      = FormQuery.Page,
                        QueryType = FormQuery.QueryType,
                        TanId     = FormQuery.TanId,
                        Title     = FormQuery.Title,
                    };
                    var result = await RestHub.SaveQuery(dto);

                    if (result.UserObject != null && (bool)result.UserObject)
                    {
                        MessageBox.Show(result.StatusMessage);
                        RefreshQueries.Execute(this);
                        ClearQuery.Execute(this);
                    }
                    else
                    {
                        MessageBox.Show("Can't Save Query . .");
                    }
                }
                catch (Exception ex)
                {
                    AppErrorBox.ShowErrorMessage("Error while saving Query . .", ex.ToString());
                }
            }
            else
            {
                AppInfoBox.ShowInfoMessage("Query can't be created without all required information . .");
            }
            Loading = false;
        }
Beispiel #3
0
        private async Task loginUser()
        {
            try
            {
                RestStatus status = await RestHub.LoginUser(userName, password);

                if (status.HttpCode == System.Net.HttpStatusCode.OK)
                {
                    Hide       = Visibility.Hidden;
                    U.UserName = userName;
                    U.RoleId   = RoleId;
                    U.UserRole = (from r in Roles
                                  where r.RoleId == RoleId
                                  select r.RoleName).FirstOrDefault();
                    await UserPermissionInfo(RoleId);
                    await UserReactionsReports(RoleId);

                    ((App.Current.MainWindow as MainWindow).DataContext as MainVM).UserName = (U.UserName + " \\ " + U.UserRole).ToUpper();
                    try
                    {
                        HubClient.InitHub();
                        HubClient.NotificationReceived += HubClient_NotificationReceived;
                        ((App.Current.MainWindow as MainWindow).DataContext as MainVM).SignalRId = HubClient.signalRId;
                    }
                    catch (Exception ex)
                    {
                        AppErrorBox.ShowErrorMessage("Error while conneciton to live server . .", ex.ToString());
                    };
                }
                else
                {
                    AppInfoBox.ShowInfoMessage(status.StatusMessage);
                    LoginEnable = true;
                }
            }
            catch (Exception ex)
            {
                Log.This(ex);
            }
        }
        private async void LoadTans()
        {
            if (BatchSummary != null)
            {
                TANs.Clear();
                WorkInProgress = true;
                try
                {
                    var result = await RestHub.TansOfDelivery(BatchSummary.Id, IsZeroRxns, IsQueried);

                    if (result.HttpCode == System.Net.HttpStatusCode.OK)
                    {
                        List <DeliveryTanDTO> dtos = (List <DeliveryTanDTO>)result.UserObject;
                        foreach (var dto in dtos)
                        {
                            TANs.Add(new DeliveryTanVM
                            {
                                Id                    = dto.Id,
                                TanNumber             = dto.TanNumber,
                                RXNCount              = dto.RXNCount,
                                IsQueried             = dto.IsQueried,
                                DeliveryRevertMessage = dto.DeliveryRevertMessage
                            });
                        }
                    }
                    else
                    {
                        AppErrorBox.ShowErrorMessage("Error While Batches . .", result.StatusMessage);
                    }
                }
                catch (Exception ex)
                {
                    AppErrorBox.ShowErrorMessage("Error While Batches . .", ex.ToString());
                }
                finally
                {
                    WorkInProgress = false;
                }
            }
        }
        private async void DoRefresh(object obj)
        {
            Loading   = true;
            Workflows = new ObservableCollection <QueryWorkflowVM>();
            Workflows.CollectionChanged += Workflows_CollectionChanged;
            try
            {
                var result = await RestHub.QueryWorkflows();

                if (result.UserObject != null)
                {
                    List <QueryWorkflowUserDTO> dto = result.UserObject as List <QueryWorkflowUserDTO>;
                    if (dto != null)
                    {
                        foreach (var username in Usernames)
                        {
                            var workflow = dto.Where(w => w.L1User == username).FirstOrDefault();
                            Workflows.Add(new QueryWorkflowVM
                            {
                                L1user = username,
                                L2user = workflow?.L2User,
                                L3user = workflow?.L3User,
                                L4user = workflow?.L4User,
                                L5user = workflow?.L5User,
                            });
                        }
                        Workflows.UpdateDisplayOrder();
                    }
                }
                else
                {
                    MessageBox.Show("Can't Load Users . .");
                }
            }
            catch (Exception ex)
            {
                AppErrorBox.ShowErrorMessage("Error While Loading Users . .", ex.ToString());
            }
            Loading = false;
        }
 private void VerifyXML(string fileName)
 {
     try
     {
         XSDResult = new ObservableCollection <ValidateXSDVM>();
         XmlReaderSettings settings = new XmlReaderSettings();
         settings.ValidationType   = ValidationType.Schema;
         settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation | XmlSchemaValidationFlags.ReportValidationWarnings;
         settings.Schemas.Add(null, XmlReader.Create(XSD_PATH));
         settings.ValidationEventHandler += new ValidationEventHandler(XmlErrorHandler);
         XmlReader reader = XmlReader.Create(fileName, settings);
         while (reader.Read())
         {
             ;
         }
     }
     catch (Exception ex)
     {
         AppErrorBox.ShowErrorMessage("Error While Verifying XML . .", ex.ToString());
         Log.This(ex);
     }
 }
Beispiel #7
0
        async private void DoGenerateXML(object obj)
        {
            try
            {
                WorkInProgress = true;
                if (DeliveryBatch != null)
                {
                    DeliveryInProgress = Visibility.Visible;
                    var result = await RestHub.GenerateXML(DeliveryBatch.Id);

                    if (result.HttpCode == System.Net.HttpStatusCode.OK)
                    {
                        var dto = result.UserObject as GenerateXMLDTO;
                        if (dto.IsSuccess)
                        {
                            GenerateXMLSuccessBox.ShowStatus(dto.OutXmlPath);
                        }
                    }
                    else
                    {
                        AppErrorBox.ShowErrorMessage(result.StatusMessage, result.HttpResponse);
                    }
                    DeliveryInProgress = Visibility.Hidden;
                }
                else
                {
                    MessageBox.Show("From Batch, From Category, Delivery Batch Number Is Required . . .");
                }
            }
            catch (Exception ex)
            {
                Log.This(ex);
                AppErrorBox.ShowErrorMessage("Can't Generate XML", ex.ToString());
            }
            finally
            {
                WorkInProgress = false;
            }
        }
Beispiel #8
0
        private async Task UserPermissionInfo(int RoleId)
        {
            try
            {
                RestStatus status = await RestHub.UserPermissionsInfo(RoleId);

                if (status.HttpCode == System.Net.HttpStatusCode.OK)
                {
                    UserInfoDTO userInfoDTO = (UserInfoDTO)status.UserObject;
                    U.CanApprove = userInfoDTO.canApprove;
                    U.CanReject  = userInfoDTO.canReject;
                    U.CanSubmit  = userInfoDTO.canSubmit;
                }
                else
                {
                    AppErrorBox.ShowErrorMessage("Unable to load user permission", status.StatusMessage);
                }
            }
            catch (Exception ex)
            {
                Log.This(ex);
            }
        }
Beispiel #9
0
        private async void LoadDeliveryBatches()
        {
            DeliveryBatches = new ObservableCollection <DeliveryBatchVM>();
            var deliveryResult = await RestHub.DeleveryBatches();

            if (deliveryResult.HttpCode == System.Net.HttpStatusCode.OK)
            {
                List <DeliveryBatchDTO> deliveryBatches = (List <DeliveryBatchDTO>)deliveryResult.UserObject;
                foreach (var batchDto in deliveryBatches)
                {
                    DeliveryBatches.Add(new DeliveryBatchVM
                    {
                        Id          = batchDto.Id,
                        BatchNumber = batchDto.BatchNumber
                    });
                }
                DeliveryBatch = DeliveryBatches.FirstOrDefault();
            }
            else
            {
                AppErrorBox.ShowErrorMessage("Can't Load Delivery Batches . .", deliveryResult.StatusMessage);
            }
        }
Beispiel #10
0
        public static void This(Exception ex)
        {
            if (ex != null)
            {
                try
                {
                    if (mongoDB == null)
                    {
                        Init();
                    }

                    List <string> sources    = new List <string>();
                    StackTrace    stackTrace = new StackTrace(ex, true);
                    if (stackTrace != null && stackTrace.GetFrames() != null)
                    {
                        sources = stackTrace.GetFrames().Select(f => f.GetFileName() + " - " + f.GetFileLineNumber()).ToList();
                    }
                    var logEntries = mongoDB.GetCollection <MongoLogEntry>(LOG_ENTRIES);
                    logEntries.InsertOne(new MongoLogEntry
                    {
                        StackTrace      = ex.ToString(),
                        System          = Environment.MachineName,
                        User            = Environment.UserName,
                        Message         = ex.Message,
                        Version         = version,
                        TanId           = T.TanId,
                        Source          = String.Join(";", sources),
                        InnerStackTrace = ex.InnerException?.ToString(),
                        Timestamp       = DateTime.Now,
                    });
                }
                catch (Exception e)
                {
                    AppErrorBox.ShowErrorMessage("Unable To Log Error, Please Report To IT Team", ex.ToString() + Environment.NewLine + e.ToString());
                }
            }
        }
Beispiel #11
0
        public static async Task GetStaticData()
        {
            try
            {
                regularExpressions.Clear();
                solventBoilingPoints.Clear();
                NamePriorities.Clear();

                RestStatus status = await RestHub.GetStaticData();

                if (status.UserObject != null)
                {
                    AppStaticDTO dto = (AppStaticDTO)status.UserObject;
                    regularExpressions.AddRange(dto.RegulerExpressions);
                    solventBoilingPoints.AddRange(dto.SolventBoilingPoints.OrderBy(sbp => sbp.Name).ToList());

                    commentDictionary.FreeText.Clear();
                    commentDictionary.CVT.Clear();

                    commentDictionary.FreeText = new List <FreeText>();
                    commentDictionary.FreeText = dto.CommentDictionary.Freetexts;

                    commentDictionary.CVT = new List <CVT>();
                    commentDictionary.CVT = dto.CommentDictionary.CVTs;
                    NamePriorities.AddRange(dto.NamePriorities);
                }
                else
                {
                    AppErrorBox.ShowErrorMessage("Unable to fetch initial data . .", status.StatusMessage);
                }
            }
            catch (Exception ex)
            {
                Log.This(ex);
            }
        }
        private async void DoSearch(object obj)
        {
            WorkInProgress = true;
            BatchSummaries.Clear();
            TANs = new ObservableCollection <DeliveryTanVM>();
            try
            {
                var result = await RestHub.DeliveryBatchSummary();

                if (result.HttpCode == System.Net.HttpStatusCode.OK)
                {
                    List <DeliveryBatchDTO> dtos = (List <DeliveryBatchDTO>)result.UserObject;
                    foreach (var dto in dtos)
                    {
                        BatchSummaries.Add(new BatchSummaryVM
                        {
                            Id          = dto.Id,
                            BatchNumber = dto.BatchNumber,
                            TansCount   = dto.TansCount
                        });
                    }
                }
                else
                {
                    AppErrorBox.ShowErrorMessage("Error While Batches . .", result.StatusMessage);
                }
            }
            catch (Exception ex)
            {
                AppErrorBox.ShowErrorMessage("Error While Batches . .", ex.ToString());
            }
            finally
            {
                WorkInProgress = false;
            }
        }
        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);
        }
        private async void DoAssignTans(object obj)
        {
            try
            {
                WorkInProgress = true;
                var list          = BatchTansView;
                var filteredItems = BatchTansView.Cast <BatchTanVM>();
                BatchTans = new ObservableCollection <BatchTanVM>();
                if (SelectedCurator != null)
                {
                    if (!string.IsNullOrEmpty(CommentText))
                    {
                        if (SelectedTans != null && SelectedTans.Count > 0)
                        {
                            var      invalidTans     = new List <object>();
                            TanState?tanstateToCheck = null;
                            if (SelectedCurator.Role == Role.Curator)
                            {
                                tanstateToCheck = TanState.Not_Assigned;
                            }
                            else if (SelectedCurator.Role == Role.Reviewer)
                            {
                                tanstateToCheck = TanState.Curation_Submitted;
                            }
                            else if (SelectedCurator.Role == Role.QC)
                            {
                                tanstateToCheck = TanState.Review_Accepted;
                            }
                            if (tanstateToCheck != null)
                            {
                                invalidTans = SelectedTans.Where(st => ((st as BatchTanVM).CurrentRole != 0 && (st as BatchTanVM).CurrentRole != SelectedCurator.Role) ||
                                                                 ((st as BatchTanVM).CurrentRole == 0 && (st as BatchTanVM).TanState != tanstateToCheck)).ToList();
                                if (!invalidTans.Any())
                                {
                                    var result = await RestHub.AssignTans(SelectedTans.Select(tan => (tan as BatchTanVM).Id).ToList(), SelectedCurator.UserId, U.RoleId, CommentText, SelectedRole.Equals("Curator")?Role.Curator : SelectedRole.Equals("Reviewer")?Role.Reviewer : Role.QC);

                                    if (result.UserObject != null)
                                    {
                                        AppInfoBox.ShowInfoMessage($"Tans Assigned to {SelectedRole} Successfully");
                                        SearchTans.Execute(null);
                                    }
                                    else
                                    {
                                        AppErrorBox.ShowErrorMessage("Can't Assign TANs . .", result.StatusMessage);
                                    }
                                }
                                else
                                {
                                    AppInfoBox.ShowInfoMessage($"In selected tans {string.Join(",", invalidTans.Select(tan => (tan as BatchTanVM).TanNumber + " - " + (tan as BatchTanVM).CurrentRole).ToList())} are allocated to other roles");
                                }
                            }
                            else
                            {
                                AppInfoBox.ShowInfoMessage("Please select Role");
                            }
                        }
                        else
                        {
                            AppInfoBox.ShowInfoMessage("Please select atleast One TAN From the below list to Assign TANs");
                        }
                    }
                    else
                    {
                        AppInfoBox.ShowInfoMessage("Please enter comment to Assign Selected TANs");
                    }
                }
                else
                {
                    AppInfoBox.ShowInfoMessage("Please Select User to assign TANs");
                }
            }
            catch (Exception ex)
            {
                Log.This(ex);
            }
            WorkInProgress = false;
        }
        public static ViewAnalogousVM GenerateNewAnalogousReactions(
            ReactionVM SelectedReaction,
            bool IsReactantsSelected,
            bool IsSolventsSelected,
            bool IsAgentsSelected,
            bool IsCatalystSelected,
            bool IspHSelected,
            bool IsTempSelected,
            bool IsTimeSelected,
            bool IsPressureSelected,
            bool IsRSNSelected,
            int ReactionsCountToCopy, int IndexToAdd
            )
        {
            ViewAnalogousVM vm            = new ViewAnalogousVM();
            var             mainViewModel = ((MainWindow)(App.Current.MainWindow)).DataContext as MainVM;

            mainViewModel.ProgressText = "Creating Analogous Reacions . .";
            try
            {
                vm.SelectedMasterReaction = SelectedReaction;
                List <ReactionParticipantVM> allParticipants = new List <ReactionParticipantVM>();
                List <RsnVM>      tanRsns      = new List <RsnVM>();
                List <ReactionVM> tanReactions = new List <ReactionVM>();
                var tanParticipants            = new List <ReactionParticipantVM>();
                if (IsReactantsSelected)
                {
                    var reactants = mainViewModel.TanVM.ReactionParticipants.OfType(ParticipantType.Reactant);
                    allParticipants.AddRange(reactants);
                }
                if (IsSolventsSelected)
                {
                    var solvents = mainViewModel.TanVM.ReactionParticipants.OfType(ParticipantType.Solvent);
                    allParticipants.AddRange(solvents);
                }

                if (IsAgentsSelected)
                {
                    var agents = mainViewModel.TanVM.ReactionParticipants.OfType(ParticipantType.Agent);
                    allParticipants.AddRange(agents);
                }

                if (IsCatalystSelected)
                {
                    var catalysts = mainViewModel.TanVM.ReactionParticipants.OfType(ParticipantType.Catalyst);
                    allParticipants.AddRange(catalysts);
                }
                for (int i = 0; i < ReactionsCountToCopy; i++)
                {
                    var reaction = new ReactionVM
                    {
                        DisplayOrder  = ++IndexToAdd,
                        Id            = Guid.NewGuid(),
                        TanVM         = SelectedReaction.TanVM,
                        AnalogousVMId = SelectedReaction.Id
                    };
                    #region Stages
                    var stages = new List <StageVM>();
                    foreach (var masterStage in SelectedReaction.Stages)
                    {
                        bool ValidStage     = true;
                        var  analogousStage = new StageVM {
                            Id = Guid.NewGuid(), ReactionVm = reaction
                        };
                        var Conditions = new List <StageConditionVM>();
                        if (masterStage.Conditions != null)
                        {
                            foreach (var selectedCondition in masterStage.Conditions)
                            {
                                var condition = new StageConditionVM
                                {
                                    DisplayOrder  = selectedCondition.DisplayOrder,
                                    Id            = Guid.NewGuid(),
                                    PH            = IspHSelected ? selectedCondition.PH : "",
                                    Pressure      = IsPressureSelected ? selectedCondition.Pressure : "",
                                    StageId       = analogousStage.Id,
                                    Temperature   = IsTempSelected ? selectedCondition.Temperature : "",
                                    Time          = IsTimeSelected ? selectedCondition.Time : "",
                                    TIME_TYPE     = IsTimeSelected ? selectedCondition.TIME_TYPE : "",
                                    PRESSURE_TYPE = IsPressureSelected ? selectedCondition.PRESSURE_TYPE : "",
                                    TEMP_TYPE     = IsTempSelected ? selectedCondition.TEMP_TYPE : "",
                                    PH_TYPE       = IspHSelected ? selectedCondition.PH_TYPE : "",
                                };
                                if ((IspHSelected && !string.IsNullOrEmpty(selectedCondition.PH)) || (IsPressureSelected && !string.IsNullOrEmpty(selectedCondition.Pressure)) ||
                                    (IsTempSelected && !string.IsNullOrEmpty(selectedCondition.Temperature)) || (IsTimeSelected && !string.IsNullOrEmpty(selectedCondition.Time)))
                                {
                                    Conditions.Add(condition);
                                }
                            }
                            analogousStage.SetConditions(Conditions);
                        }
                        var stageParticipants = (from sp in allParticipants where sp.StageVM.Id == masterStage.Id select sp).ToList();
                        foreach (var stageParticipant in stageParticipants)
                        {
                            var newParticipant = new ReactionParticipantVM
                            {
                                ChemicalType    = stageParticipant.ChemicalType,
                                DisplayOrder    = stageParticipant.DisplayOrder,
                                Name            = stageParticipant.Name,
                                Num             = stageParticipant.Num,
                                ParticipantType = stageParticipant.ParticipantType,
                                ReactionVM      = reaction,
                                Reg             = stageParticipant.Reg,
                                StageVM         = analogousStage,
                                TanChemicalId   = stageParticipant.TanChemicalId,
                                Yield           = stageParticipant.Yield,
                                Id = Guid.NewGuid()
                            };
                            tanParticipants.Add(newParticipant);
                        }
                        if (IsRSNSelected)
                        {
                            var stagersnList = (from rsn in mainViewModel.TanVM.Rsns where rsn.Reaction.Id == SelectedReaction.Id && rsn.Stage != null && rsn.Stage.Id == masterStage.Id select rsn).ToList();
                            foreach (var rsn in stagersnList)
                            {
                                var newRsn = new RsnVM
                                {
                                    CvtText  = rsn.CvtText,
                                    Reaction = reaction,
                                    IsRXN    = rsn.IsRXN,
                                    Stage    = analogousStage,
                                    FreeText = rsn.FreeText,
                                    Id       = Guid.NewGuid(),
                                    IsIgnorableInDelivery = rsn.IsIgnorableInDelivery,
                                    DisplayOrder          = rsn.DisplayOrder,
                                    ReactionParticipantId = rsn.ReactionParticipantId,
                                    SelectedChemical      = rsn.SelectedChemical
                                };
                                tanRsns.Add(newRsn);
                            }
                        }
                        if ((analogousStage.Conditions == null || !analogousStage.Conditions.Any()) &&
                            (tanParticipants == null || !tanParticipants.Where(tp => tp.StageVM != null && tp.StageVM.Id == analogousStage.Id).Any()) &&
                            (tanRsns == null || !tanRsns.Where(tp => tp.Stage != null && tp.Stage.Id == analogousStage.Id).Any()) && !mainViewModel.TanVM.ReactionParticipants.OfReactionAndStage(SelectedReaction.Id, masterStage.Id).OfType(ParticipantType.Reactant).Any())
                        {
                            ValidStage = false;
                        }
                        if (ValidStage)
                        {
                            stages.Add(analogousStage);
                        }
                    }
                    #endregion
                    reaction.SetStages(stages, 0, false, true);
                    tanReactions.Add(reaction);
                    var reactionParticipants = (from sp in allParticipants where sp.ReactionVM.Id == SelectedReaction.Id && sp.StageVM == null select sp).ToList();
                    foreach (var participant in reactionParticipants)
                    {
                        var newParticipant = new ReactionParticipantVM
                        {
                            ChemicalType    = participant.ChemicalType,
                            DisplayOrder    = participant.DisplayOrder,
                            Name            = participant.Name,
                            Num             = participant.Num,
                            ParticipantType = participant.ParticipantType,
                            ReactionVM      = reaction,
                            Reg             = participant.Reg,
                            StageVM         = null,
                            TanChemicalId   = participant.TanChemicalId,
                            Yield           = participant.Yield,
                            Id = Guid.NewGuid()
                        };
                        tanParticipants.Add(newParticipant);
                    }

                    if (IsRSNSelected)
                    {
                        var reationrsnList = (from rsn in mainViewModel.TanVM.Rsns where rsn.Reaction.Id == SelectedReaction.Id && rsn.Stage == null select rsn).ToList();
                        foreach (var rsn in reationrsnList)
                        {
                            var newRsn = new RsnVM
                            {
                                CvtText               = rsn.CvtText,
                                Reaction              = reaction,
                                FreeText              = rsn.FreeText,
                                IsRXN                 = rsn.IsRXN,
                                Stage                 = null,
                                Id                    = Guid.NewGuid(),
                                SelectedChemical      = rsn.SelectedChemical,
                                ReactionParticipantId = rsn.ReactionParticipantId,
                                DisplayOrder          = rsn.DisplayOrder,
                                IsIgnorableInDelivery = rsn.IsIgnorableInDelivery
                            };
                            tanRsns.Add(newRsn);
                        }
                    }
                }
                foreach (var participant in tanParticipants)
                {
                    vm.AllParticipants.Add(participant);
                    vm.ReactionParticipants.Add(participant);
                }
                vm.Rsns.Clear();
                foreach (var rsn in tanRsns)
                {
                    vm.Rsns.Add(rsn);
                }
                foreach (var reaction in tanReactions)
                {
                    vm.AnalogousReactions.Add(reaction);
                }
            }
            catch (Exception ex)
            {
                AppErrorBox.ShowErrorMessage("Can't Create Analogous Reactions", ex.Message);
            }
            return(vm);
        }
Beispiel #16
0
        private async Task LoadTasks(int RoleID, bool pullTasks)
        {
            try
            {
                ProgressBarVisibility = Visibility.Visible;
                ButtonEnable          = false;
                ClearTaskSheet();
                if (pullTasks)
                {
                    RestStatus pullTaskResult = await RestHub.PullTask(RoleID, pullTasks);

                    PullTask   pullTask   = pullTaskResult.UserObject != null ? (PullTask)pullTaskResult.UserObject : null;
                    PullTaskVM pullTaskVm = new PullTaskVM();
                    if (pullTask != null)
                    {
                        pullTaskVm.TanNumber = pullTask.TanNumber;
                        if (pullTask.UserRanks != null)
                        {
                            pullTaskVm.UserRank = pullTask.UserRanks.Find(ur => ur.Key == U.UserName)?.Rank;
                        }
                        if (pullTask.TanRanks != null && pullTask.TanNumber != null)
                        {
                            pullTaskVm.AllottedTanRank = pullTask.TanRanks.Find(ur => ur.Key == pullTask.TanNumber)?.Rank;
                        }
                        List <RankVM> rankVM = new List <RankVM>();
                        int           count  = 1;
                        foreach (var r in pullTask.TanRanks)
                        {
                            rankVM.Add(new RankVM {
                                DisplayOrder = count++, Key = r.Key, Rank = r.Rank, Score = r.Score.ToString()
                            });
                        }
                        pullTaskVm.TanRanks = new ObservableCollection <RankVM>(rankVM);
                        rankVM = new List <RankVM>();
                        count  = 1;
                        foreach (var r in pullTask.UserRanks)
                        {
                            rankVM.Add(new RankVM {
                                DisplayOrder = count++, Key = r.Key, Rank = r.Rank, Score = r.Score.ToString()
                            });
                        }
                        pullTaskVm.UserRanks = new ObservableCollection <Core.RankVM>(rankVM);
                        PullTaskDetails.ShowWindow(pullTaskVm);
                    }
                }
                RestStatus status = await RestHub.MyTans(RoleID, pullTasks);

                if (status.HttpCode == System.Net.HttpStatusCode.OK)
                {
                    List <TaskDTO> tans = status.UserObject as List <TaskDTO>;
                    if (tans != null && tans.Count > 0)
                    {
                        foreach (TaskDTO tan in tans)
                        {
                            Tasks.Add(new TaskDeatilsVM
                            {
                                TanId             = tan.Id,
                                TanName           = tan.TanName,
                                Status            = tan.Status,
                                Analyst           = tan.Analyst,
                                BatchNo           = tan.BatchNo,
                                NUMsCount         = tan.NUMsCount,
                                QC                = tan.QC,
                                Reviewer          = tan.Reviewer,
                                RXNsCount         = tan.RXNsCount,
                                Version           = tan.Version,
                                TanCompletionDate = tan.TanCompletionDate,
                                ProcessingNote    = tan.ProcessingNote,
                                NearToTargetDate  = tan.NearToTargetDate
                            });
                        }
                        Tasks.UpdateDisplayOrder();
                        UserTasks = new ListCollectionView(Tasks);
                    }
                    else
                    {
                        AppInfoBox.ShowInfoMessage("No Tasks Found. Try GetTasks After Some Time.");
                    }
                }
                else
                {
                    AppErrorBox.ShowErrorMessage("Some error occured in Getting Tans.", status.StatusMessage);
                }
                ButtonEnable = true;
            }
            catch (Exception ex)
            {
                Log.This(ex);
            }
            finally
            {
                ProgressBarVisibility = Visibility.Hidden;
            }
        }
Beispiel #17
0
        public static bool ValidateAndAddRsn(string FreeText, string CVT, List <RsnVM> Rsns, List <CvtVM> CVTData, ReactionVM ReactionVM, StageVM StageVM, RsnLevel RsnLevel, Regex regex, RSNWindowVM RSNWindowVM, RsnVM EditingRsn = null)
        {
            try
            {
                if (!string.IsNullOrEmpty(FreeText.Trim()) || !string.IsNullOrEmpty(CVT))
                {
                    string freetextREstring = S.RegularExpressions.Where(re => re.RegulerExpressionFor == ProductTracking.Models.Core.RegulerExpressionFor.FreeText).Select(re => re.Expression).FirstOrDefault();
                    Regex  FreetextRE       = new Regex(freetextREstring);
                    var    SPLList          = new List <string> {
                        "==", "%%", ",,", "((", "))", "{{", "}}", "++", "//", "\\", "::", ";;", "--", "..", "  ", "''", "<<", ">>", "**", "@@", "[[", "]]", ", ,", ").", ".,", " ."
                    };
                    if (!string.IsNullOrEmpty(FreeText) && SPLList.Where(spl => FreeText.Contains(spl)).FirstOrDefault() != null)
                    {
                        AppInfoBox.ShowInfoMessage($"Freetext contains invalid repetation of special Characters <SPL Char Start>{SPLList.Where(spl => FreeText.Contains(spl)).FirstOrDefault()}</SPL Char End>.");
                        //MessageBox.Show($"Freetext contains invalid repetation of special Characters {SPLList.Where(spl => FreeText.Contains(spl)).FirstOrDefault()}.", "Reactions", MessageBoxButton.OK, MessageBoxImage.Information);
                        return(false);
                    }
                    if (!string.IsNullOrEmpty(FreeText) && FreeText.Contains("), ") && StageVM != null && RsnLevel == RsnLevel.STAGE)
                    {
                        string[] list = FreeText.Split(new string[] { "), " }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var freetext in list)
                        {
                            string newText = !freetext.EndsWith(")") ? $"{freetext})" : freetext;
                            if (regex.IsMatch(newText))
                            {
                                List <int> data = PressureValidations.GetStageDisplayOrdersFromFreetexts(new List <RsnVM> {
                                    new ViewModels.RsnVM {
                                        Reaction = ReactionVM, Stage = StageVM, FreeText = newText
                                    }
                                }, ReactionVM, FreeTextWithOutStageInfo(newText));
                                if (!data.Contains(StageVM.DisplayOrder) && RsnLevel == RsnLevel.STAGE)
                                {
                                    AppInfoBox.ShowInfoMessage("Comma and space allowed only after stage information");
                                    return(false);
                                }
                            }
                            else
                            {
                                AppInfoBox.ShowInfoMessage($"Invalid freetext '{newText}'");
                                return(false);
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(FreeText) && FreeText.Contains(","))
                    {
                        string[] list = FreeText.Split(',');
                        for (int i = 1; i < list.Length; i++)
                        {
                            if (!Regex.IsMatch(list[i], @"^\s|\d"))
                            {
                                AppInfoBox.ShowInfoMessage("invalid freetext. It contains extra characters");
                                return(false);
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(FreeText) && FreeText.Contains(", ") && FreeText.ToLower().Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).GroupBy(s => FreeTextWithOutStageInfo(s)).SelectMany(grp => grp.Skip(1)).Count() > 0)
                    {
                        AppInfoBox.ShowInfoMessage("FreeText Contains duplicates.");
                        return(false);
                    }

                    if (!string.IsNullOrEmpty(FreeText) && FreeText.Contains(", ") && FreeText.ToLower().Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Where(s => s.EndsWith(".")).Count() > 0)
                    {
                        AppInfoBox.ShowInfoMessage("FreeText Contains .(Period)");
                        return(false);
                    }

                    if (RsnLevel == RsnLevel.STAGE && StageVM == null)
                    {
                        AppInfoBox.ShowInfoMessage("Please Select Stage to Add Stage RSN");
                        return(false);
                    }

                    if (RsnLevel == RsnLevel.REACTION && !String.IsNullOrEmpty(FreeText) && FreeText.Contains("(stage"))
                    {
                        AppInfoBox.ShowInfoMessage("Reaction Level stage information Not allowed");
                        return(false);
                    }

                    if (!string.IsNullOrEmpty(FreeText) && !FreetextRE.IsMatch(FreeText))
                    {
                        AppInfoBox.ShowInfoMessage("FreeText Contains special characters.");
                        return(false);
                    }
                    if (EditingRsn != null)
                    {
                        bool OnlyOneFreeTextInReactionLevel = (CVT == String.Empty && RsnLevel == RsnLevel.REACTION && Rsns.Any(r => r.Reaction != null && r.Reaction.Id == ReactionVM.Id && (EditingRsn != null ? r.Id != EditingRsn.Id : true) && r.Stage == null && r.CvtText == String.Empty)) ? false : true;
                        if (OnlyOneFreeTextInReactionLevel)
                        {
                            bool OnlyOneFreeTextInStageLevel = (CVT == String.Empty && RsnLevel == RsnLevel.STAGE && Rsns.Any(r => r.Reaction != null && (EditingRsn != null ? r.Id != EditingRsn.Id : true) && r.Reaction.Id == ReactionVM.Id && r.Stage != null && r.Stage.Id == StageVM.Id && r.CvtText == String.Empty)) ? false : true;
                            if (OnlyOneFreeTextInStageLevel)
                            {
                                if (!String.IsNullOrEmpty(CVT) && Rsns.Where(r => r.Reaction.Id == ReactionVM.Id && (EditingRsn != null ? r.Id != EditingRsn.Id : true) && r.CvtText != string.Empty && r.CvtText == CVT).Count() > 0)
                                {
                                    var SelectedRSNTerm = Rsns.Where(r => r.Reaction.Id == ReactionVM.Id && (EditingRsn != null ? r.Id != EditingRsn.Id : true) && r.CvtText == CVT).FirstOrDefault();
                                    AppInfoBox.ShowInfoMessage("Selected CVT " + (!String.IsNullOrEmpty(CVT) ? CVT : FreeText) + " Already used in " + (SelectedRSNTerm?.Stage != null ? SelectedRSNTerm?.Stage.Name : SelectedRSNTerm.Reaction.Name));
                                    return(false);
                                }
                                if (!string.IsNullOrEmpty(FreeText))
                                {
                                    var splittedFreetexts = FreeText.Split(new String[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Select(c => FreeTextWithOutStageInfo(c));
                                    foreach (var item in splittedFreetexts)
                                    {
                                        if (CVTData.Where(cvt => item.Trim().SafeEqualsLower(cvt.Text.Trim()) && !cvt.Text.Trim().SafeEqualsLower(CVT.Trim())).Count() > 0)
                                        {
                                            AppInfoBox.ShowInfoMessage($"Selected FreeText contains CVT \"{item}\"");
                                            return(false);
                                        }
                                        if (!string.IsNullOrEmpty(item) && Rsns.Where(r => r.Reaction.Id == ReactionVM.Id && (EditingRsn != null ? r.Id != EditingRsn.Id : true) && ((!String.IsNullOrEmpty(r.FreeText) && r.FreeText.Split(new String[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Where(c => FreeTextWithOutStageInfo(c).Trim().SafeEqualsLower(item.Trim())).Count() > 0) || (!string.IsNullOrEmpty(r.CvtText) && item.Trim().SafeContainsLower(r.CvtText.Trim())))).Count() > 0)
                                        {
                                            var SelectedRSNTerm = Rsns.Where(r => r.Reaction.Id == ReactionVM.Id && (EditingRsn != null ? r.Id != EditingRsn.Id : true) && ((!String.IsNullOrEmpty(r.FreeText) && r.FreeText.Split(new String[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Where(c => FreeTextWithOutStageInfo(c).Trim().SafeEqualsLower(item.Trim())).Count() > 0) || (!string.IsNullOrEmpty(r.CvtText) && item.Trim().SafeContainsLower(r.CvtText.Trim())))).FirstOrDefault();
                                            AppInfoBox.ShowInfoMessage("Selected FreeText " + FreeText + " Already used in " + (SelectedRSNTerm?.Stage != null ? SelectedRSNTerm?.Stage.Name : SelectedRSNTerm.Reaction.Name));
                                            return(false);
                                        }
                                    }
                                }

                                if (RsnLevel == RsnLevel.STAGE)
                                {
                                    if (!string.IsNullOrEmpty(CVT) && string.IsNullOrEmpty(FreeText))
                                    {
                                        AppInfoBox.ShowInfoMessage("Stage Level CVT Used, Then Freetext is mandatory..");
                                        return(false);
                                    }
                                    else if (!string.IsNullOrEmpty(FreeText) && regex.IsMatch(FreeText))
                                    {
                                        string outMsg = string.Empty;
                                        if (!ValidateRsnEditArea(FreeText, regex, ReactionVM, StageVM, out outMsg))
                                        {
                                            AppInfoBox.ShowInfoMessage(outMsg);
                                            return(false);
                                        }
                                        return(true);
                                    }
                                    else
                                    {
                                        AppInfoBox.ShowInfoMessage("Stage Level Information missed in Freetext Term... / Ends with some Special characters");
                                        return(false);
                                    }
                                }
                                return(true);
                            }
                            else
                            {
                                AppInfoBox.ShowInfoMessage("Only One Stage Level Free Text Is Allowed With out CVT . .");
                                return(false);
                            }
                        }
                        else
                        {
                            AppInfoBox.ShowInfoMessage("Only One Reaction Level Free Text Is Allowed With out CVT . .");
                            return(false);
                        }
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(CVT) || !String.IsNullOrEmpty(FreeText))
                        {
                            bool OnlyOneFreeTextInReactionLevel = (CVT == String.Empty && RsnLevel == RsnLevel.REACTION && Rsns.Any(r => r.Reaction != null && r.Reaction.Id == ReactionVM.Id && r.Stage == null && string.IsNullOrEmpty(r.CvtText))) ? false : true;
                            if (OnlyOneFreeTextInReactionLevel)
                            {
                                bool OnlyOneFreeTextInStageLevel = (CVT == String.Empty && RsnLevel == RsnLevel.STAGE && Rsns.Any(r => r.Reaction != null && r.Reaction.Id == ReactionVM.Id && r.Stage != null && r.Stage.Id == StageVM.Id && string.IsNullOrEmpty(r.CvtText))) ? false : true;
                                if (OnlyOneFreeTextInStageLevel)
                                {
                                    if (!String.IsNullOrEmpty(CVT) && Rsns.Where(r => r.Reaction.Id == ReactionVM.Id && r.CvtText.SafeEqualsLower(CVT)).Count() > 0)
                                    {
                                        var SelectedRSNTerm = Rsns.Where(r => r.Reaction.Id == ReactionVM.Id && r.CvtText.SafeEqualsLower(CVT)).FirstOrDefault();
                                        AppInfoBox.ShowInfoMessage("Selected CVT " + (!String.IsNullOrEmpty(CVT) ? CVT : FreeText) + " Already used in " + (SelectedRSNTerm?.Stage != null ? SelectedRSNTerm?.Stage.Name : SelectedRSNTerm.Reaction.Name));
                                        return(false);
                                    }

                                    if (!string.IsNullOrEmpty(FreeText))
                                    {
                                        var splittedFreetexts = FreeText.Split(new String[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Select(c => FreeTextWithOutStageInfo(c));
                                        foreach (var item in splittedFreetexts)
                                        {
                                            if (CVTData.Where(cvt => item.Trim().SafeEqualsLower(cvt.Text.Trim()) && !cvt.Text.Trim().SafeEqualsLower(CVT.Trim())).Count() > 0)
                                            {
                                                AppInfoBox.ShowInfoMessage($"Selected FreeText contains CVT \"{item}\"");
                                                return(false);
                                            }
                                            if (!string.IsNullOrEmpty(item) && Rsns.Where(r => r.Reaction.Id == ReactionVM.Id && ((!String.IsNullOrEmpty(r.FreeText) && r.FreeText.Split(new String[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Where(c => FreeTextWithOutStageInfo(c).Trim().SafeEqualsLower(item.Trim())).Count() > 0) || (!string.IsNullOrEmpty(r.CvtText) && item.Trim().SafeContainsLower(r.CvtText.Trim())))).Count() > 0)
                                            {
                                                var SelectedRSNTerm = Rsns.Where(r => r.Reaction.Id == ReactionVM.Id && ((!String.IsNullOrEmpty(r.FreeText) && r.FreeText.Split(new String[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Where(c => FreeTextWithOutStageInfo(c).Trim().SafeEqualsLower(item.Trim())).Count() > 0) || (!string.IsNullOrEmpty(r.CvtText) && item.Trim().SafeContainsLower(r.CvtText.Trim())))).FirstOrDefault();
                                                AppInfoBox.ShowInfoMessage($"Selected FreeText '{FreeText}' Already used in {(SelectedRSNTerm?.Stage != null ? SelectedRSNTerm?.Stage.Name : SelectedRSNTerm.Reaction.Name)}");
                                                return(false);
                                            }
                                        }
                                    }
                                    if (RsnLevel == RsnLevel.STAGE)
                                    {
                                        if (!string.IsNullOrEmpty(CVT) && string.IsNullOrEmpty(FreeText))
                                        {
                                            AppInfoBox.ShowInfoMessage("Stage Level CVT Used, Then Freetext is mandatory..");
                                            return(false);
                                        }
                                        else if (!string.IsNullOrEmpty(FreeText) && regex.IsMatch(FreeText))
                                        {
                                            string OutMsg = string.Empty;
                                            if (!ValidateRsnEditArea(FreeText, regex, ReactionVM, StageVM, out OutMsg))
                                            {
                                                AppErrorBox.ShowErrorMessage(OutMsg, String.Empty);
                                                return(false);
                                            }
                                            return(true);
                                        }
                                        else
                                        {
                                            AppInfoBox.ShowInfoMessage("Stage Level Information missed in Freetext Term...");
                                            return(false);
                                        }
                                    }
                                    return(true);
                                }
                                else
                                {
                                    AppInfoBox.ShowInfoMessage("Only One Stage Level Free Text Is Allowed With out CVT . .");
                                    return(false);
                                }
                            }
                            else
                            {
                                AppInfoBox.ShowInfoMessage("Only One Reaction Level Free Text Is Allowed With out CVT . .");
                                return(false);
                            }
                        }
                        return(false);
                    }
                    if (Rsns.Where(rsn => rsn.CvtText.SafeEqualsLower(S.ENZYMIC_CVT)).Count() > 0 && Rsns.Where(rsn => rsn.CvtText.SafeEqualsLower(S.BIOTRANSFORMATION_CVT)).Count() == 0)
                    {
                        var    enzymicRSN    = Rsns.Where(rsn => rsn.CvtText.SafeEqualsLower(S.ENZYMIC_CVT)).FirstOrDefault();
                        string freeTextToAdd = !string.IsNullOrEmpty(enzymicRSN.FreeText) ? StageInfoWithOutFreeText(enzymicRSN.FreeText, regex) : string.Empty;
                        Rsns.Add(new RsnVM
                        {
                            CvtText     = S.BIOTRANSFORMATION_CVT,
                            FreeText    = $"{S.BIOTRANSFORMATION_FREETEXT} {freeTextToAdd}",
                            IsRXN       = true,
                            Stage       = enzymicRSN.Stage != null ? enzymicRSN.Stage : null,
                            Reaction    = ReactionVM,
                            RSNWindowVM = RSNWindowVM,
                            Id          = Guid.NewGuid()
                        });
                    }
                    //ClearEditForm.Execute(this);
                }
                else
                {
                    AppInfoBox.ShowInfoMessage("Either CVT or FreeText mandatory to save RSN");
                }
                return(true);
            }
            catch (Exception ex)
            {
                Log.This(ex);
                AppErrorBox.ShowErrorMessage(ex.Message, ex.ToString());
                return(false);
            }
        }
Beispiel #18
0
        private void DoSaveForm(object obj)
        {
            try
            {
                string outMsg = string.Empty;
                if (!string.IsNullOrEmpty(FreeText.Trim()) || !string.IsNullOrEmpty(CVT))
                {
                    if (!RV.ValidateRsnFreetext(FreeText, ReactionVM, StageVM, RsnLevel, out outMsg))
                    {
                        AppInfoBox.ShowInfoMessage(outMsg);
                        return;
                    }

                    if (RV.ValidateRsnReactionLevel(ReactionVM, StageVM, RsnLevel, CVT, FreeText, Rsns.ToList(), out outMsg, EditingRsn))
                    {
                        if (EditingRsn != null)
                        {
                            EditingRsn.CvtText = CVT;
                            EditingRsn.IsIgnorableInDelivery = IsIgnorableInDelivery;
                            EditingRsn.FreeText = FreeText.Trim().TrimEnd('.');
                            EditingRsn.Stage    = RsnLevel == RsnLevel.STAGE ? StageVM : null;
                            UpdateRsnLengths();
                        }
                        else
                        {
                            var rsn = new RsnVM {
                            };
                            rsn.CvtText = CVT;
                            rsn.IsIgnorableInDelivery = IsIgnorableInDelivery;
                            rsn.FreeText    = FreeText.Trim().TrimEnd('.');
                            rsn.Reaction    = ReactionVM;
                            rsn.Id          = Guid.NewGuid();
                            rsn.Stage       = RsnLevel == RsnLevel.STAGE ? StageVM : null;
                            rsn.RSNWindowVM = this;
                            Rsns.Add(rsn);
                        }
                    }
                    else
                    {
                        AppInfoBox.ShowInfoMessage(outMsg);
                        return;
                    }
                    if (Rsns.Where(rsn => rsn.CvtText.SafeEqualsLower(S.ENZYMIC_CVT)).Count() > 0 && Rsns.Where(rsn => rsn.CvtText.SafeEqualsLower(S.BIOTRANSFORMATION_CVT)).Count() == 0)
                    {
                        var    enzymicRSN    = Rsns.Where(rsn => rsn.CvtText.SafeEqualsLower(S.ENZYMIC_CVT)).FirstOrDefault();
                        string freeTextToAdd = !string.IsNullOrEmpty(enzymicRSN.FreeText) ? RV.GetStageInfoWithOutFreeText(enzymicRSN.FreeText) : string.Empty;
                        Rsns.Add(new RsnVM
                        {
                            CvtText     = S.BIOTRANSFORMATION_CVT,
                            FreeText    = RsnLevel == RsnLevel.STAGE ? $"{S.BIOTRANSFORMATION_FREETEXT} {freeTextToAdd}" : string.Empty,
                            IsRXN       = true,
                            Stage       = enzymicRSN.Stage != null ? enzymicRSN.Stage : null,
                            Reaction    = ReactionVM,
                            RSNWindowVM = this,
                            Id          = Guid.NewGuid()
                        });
                    }
                    ClearEditForm.Execute(this);
                }
                else
                {
                    AppInfoBox.ShowInfoMessage("Either CVT or FreeText mandatory to save RSN");
                }
            }
            catch (Exception ex)
            {
                Log.This(ex);
                AppErrorBox.ShowErrorMessage(ex.Message, ex.ToString());
            }
        }
Beispiel #19
0
        public static void LoadSeriesData()
        {
            try
            {
                allSeriesNames.Clear();
                Dictionary <string, string>        DictNamePrioroty = NamePriorities.GroupBy(n => n.RegNumber).ToDictionary(n => n.Key, n => n.FirstOrDefault().Name);
                Dictionary <string, TanChemicalVM> registerNumWiseChemicalNameDict = new Dictionary <string, TanChemicalVM>();

                #region Series 8500
                if (File.Exists(C.FilePath8500))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(C.NetworkFilePath8500);
                    XmlNode series8500Node = doc.DocumentElement.SelectSingleNode("/Series8500");
                    foreach (XmlNode tableNode in series8500Node.ChildNodes)
                    {
                        TanChemicalVM vm = new TanChemicalVM();
                        vm.InChiKey     = tableNode.SelectSingleNode("INCHI_KEY")?.InnerText;
                        vm.RegNumber    = tableNode.SelectSingleNode("REG_NO")?.InnerText;
                        vm.Name         = tableNode.SelectSingleNode("ORGREF_NAME")?.InnerText;
                        vm.SearchName   = vm.Name;
                        vm.ChemicalType = ChemicalType.S8500;
                        allSeriesNames.Add(vm);
                    }
                }
                else
                {
                    AppErrorBox.ShowErrorMessage("8500 Series File is not found !", String.Empty);
                }
                #endregion

                #region Series 9000
                if (File.Exists(C.FilePath9000))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(C.NetworkFilePath9000);
                    XmlNode series9000Node = doc.DocumentElement.SelectSingleNode("/Series9000");
                    foreach (XmlNode tableNode in series9000Node.ChildNodes)
                    {
                        TanChemicalVM vm      = new TanChemicalVM();
                        var           numText = tableNode.SelectSingleNode("NUM")?.InnerText;
                        int           num;
                        Int32.TryParse(numText, out num);
                        vm.NUM          = num;
                        vm.InChiKey     = tableNode.SelectSingleNode("INCHI_KEY")?.InnerText;
                        vm.RegNumber    = tableNode.SelectSingleNode("REG_NO")?.InnerText;
                        vm.Name         = tableNode.SelectSingleNode("ORGREF_NAME")?.InnerText;
                        vm.SearchName   = vm.Name;
                        vm.ChemicalType = ChemicalType.S9000;
                        allSeriesNames.Add(vm);
                    }
                }
                else
                {
                    AppErrorBox.ShowErrorMessage("9000 Series File is not found !", String.Empty);
                }
                #endregion

                //Make synonyms from chemical names having same register numbers.
                foreach (TanChemicalVM c in allSeriesNames)
                {
                    c.Name = DictNamePrioroty.ContainsKey(c.RegNumber) ? DictNamePrioroty[c.RegNumber] : c.Name;
                    if (registerNumWiseChemicalNameDict.ContainsKey(c.RegNumber))
                    {
                        TanChemicalVM existingChemicalName = registerNumWiseChemicalNameDict[c.RegNumber];
                        existingChemicalName.SearchName = String.Join("; ", existingChemicalName.SearchName, c.SearchName);
                    }
                    else
                    {
                        registerNumWiseChemicalNameDict[c.RegNumber] = c;
                    }
                }

                AppChemicalDict.Clear();
                foreach (var entry in registerNumWiseChemicalNameDict)
                {
                    AppChemicalDict[entry.Key] = entry.Value;
                }
            }
            catch (Exception ex)
            {
                Log.This(ex);
            }
        }
Beispiel #20
0
        public async void LoadData()
        {
            try
            {
                #region Batches
                FromBatches     = new ObservableCollection <BatchVM>();
                ToBatches       = new ObservableCollection <BatchVM>();
                DeliveryBatches = new ObservableCollection <DeliveryBatchVM>();

                #region Shipment Batches
                var result = await RestHub.Batches();

                if (result.HttpCode == System.Net.HttpStatusCode.OK)
                {
                    List <BatchDTO> batches = (List <BatchDTO>)result.UserObject;
                    batches = batches.OrderByDescending(b => b.Name).ToList();
                    foreach (var batchDto in batches)
                    {
                        FromBatches.Add(new BatchVM
                        {
                            Id            = batchDto.Id,
                            DateCreated   = batchDto.DateCreated,
                            Name          = batchDto.Name,
                            DocumentsPath = batchDto.DocumentsPath
                        });
                    }
                    FromBatch = FromBatches.FirstOrDefault();
                    foreach (var batchDto in batches)
                    {
                        ToBatches.Add(new BatchVM
                        {
                            Id            = batchDto.Id,
                            DateCreated   = batchDto.DateCreated,
                            Name          = batchDto.Name,
                            DocumentsPath = batchDto.DocumentsPath
                        });
                    }
                    ToBatch = ToBatches.FirstOrDefault();
                    UpdateSummary(BatchTans);
                }
                else
                {
                    AppErrorBox.ShowErrorMessage("Can't Load Batches . .", result.StatusMessage);
                }
                #endregion

                #region Delivery Batches
                LoadDeliveryBatches();
                #endregion
                #endregion

                #region Categories
                FromCategories = new ObservableCollection <TanCategoryVM>();
                ToCategories   = new ObservableCollection <TanCategoryVM>();

                foreach (TanCategory tanCategory in Enum.GetValues(typeof(TanCategory)))
                {
                    FromCategories.Add(new TanCategoryVM {
                        Value = (int)tanCategory, Description = tanCategory.DescriptionAttribute()
                    });
                }
                FromCategory = new TanCategoryVM {
                    Value = (int)TanCategory.Progress, Description = TanCategory.Progress.DescriptionAttribute()
                };

                ToCategories.Add(new TanCategoryVM {
                    Value = (int)TanCategory.Patents, Description = TanCategory.Patents.DescriptionAttribute()
                });
                ToCategories.Add(new TanCategoryVM {
                    Value = (int)TanCategory.Journals, Description = TanCategory.Journals.DescriptionAttribute()
                });
                ToCategory = null;
                #endregion
            }
            catch (Exception ex)
            {
                Log.This(ex);
            }
        }
Beispiel #21
0
        private async void DoExtractRsns(object obj)
        {
            try
            {
                LoadingRSNs    = true;
                ExtractRsnView = null;
                if (FromBatch != null && FromCategory != null)
                {
                    var result = await RestHub.ExtractRsn(SelectedDeliveryBatch.Id, FromCategory.Value);

                    if (result.HttpCode == System.Net.HttpStatusCode.OK)
                    {
                        List <ExtractRSNDto> dtos = (List <ExtractRSNDto>)result.UserObject;
                        ExtractedRsns = new ObservableCollection <ExtractRsnVM>();
                        int count = 1;
                        Dictionary <string, Dictionary <int, int> > tanWiseRxnIdWiseTotalLengths = new Dictionary <string, Dictionary <int, int> >();
                        var tanNumbers = dtos.Select(dto => dto.TanNumber).Distinct();
                        foreach (var tan in tanNumbers)
                        {
                            tanWiseRxnIdWiseTotalLengths[tan] = dtos
                                                                .Where(d => d.TanNumber == tan)
                                                                .GroupBy(d => d.RXNSno)
                                                                .ToDictionary(d => d.Key, d => d.Select(dto => dto.CVT.SafeLength() + dto.FreeText.SafeLength()).Sum());
                        }
                        foreach (var dto in dtos)
                        {
                            var          rxnIdWiseTotalLengths = tanWiseRxnIdWiseTotalLengths[dto.TanNumber];
                            ExtractRsnVM vm = new ExtractRsnVM
                            {
                                TanNumber     = dto.TanNumber,
                                RXNSno        = dto.RXNSno,
                                ProductNumber = dto.ProductNumber,
                                RxnSeq        = dto.RxnSeq,
                                Stage         = dto.Stage,
                                CVT           = dto.CVT,
                                FreeText      = dto.FreeText,
                                Level         = dto.RSNType,
                                Id            = dto.Id,
                                DisplayOrder  = count++
                            };
                            if (rxnIdWiseTotalLengths != null && rxnIdWiseTotalLengths.ContainsKey(dto.RXNSno))
                            {
                                vm.TotalLength = rxnIdWiseTotalLengths[dto.RXNSno];
                                vm.Comment     = $"Reaction {dto.RXNSno} Info.";
                            }
                            ExtractedRsns.Add(vm);
                        }
                        ExtractRsnView = new ListCollectionView(ExtractedRsns);
                        ExtractRsnView.SortDescriptions.Add(new SortDescription("DisplayOrder", ListSortDirection.Ascending));
                        ExtractRsnView.SortDescriptions.Add(new SortDescription("TanNumber", ListSortDirection.Ascending));
                        ExtractRsnView.SortDescriptions.Add(new SortDescription("Sno", ListSortDirection.Ascending));
                        ExtractRsnView.SortDescriptions.Add(new SortDescription("RxnSeq", ListSortDirection.Ascending));
                        ExtractRsnView.SortDescriptions.Add(new SortDescription("Stage", ListSortDirection.Ascending));
                    }
                    else
                    {
                        AppErrorBox.ShowErrorMessage("Can't Update RSN", result.StatusMessage);
                    }
                }
                else
                {
                    AppInfoBox.ShowInfoMessage("From Batch and Category Are Required");
                }
            }
            catch (Exception ex)
            {
                Log.This(ex);
                AppErrorBox.ShowErrorMessage("Error while Extract RSNs", ex.ToString());
            }
            finally
            {
                LoadingRSNs = false;
            }
        }