public static void OpenDocument(string DocumentPath) { try { if (thisWindow == null) { thisWindow = new ExportedPDF(); } if (File.Exists(DocumentPath)) { AxFoxitPDFSDK foxit = thisWindow.PdfHost.Child as AxFoxitPDFSDK; AxFoxitPDFSDK foxitSplitted = thisWindow.PdfHostSplitted.Child as AxFoxitPDFSDK; OpenPdf(foxit, DocumentPath); OpenPdf(foxitSplitted, DocumentPath); thisWindow.Show(); } else { AppInfoBox.ShowInfoMessage("PDF File not Found. Please Try after some time."); } } catch (Exception ex) { Log.This(ex); } }
private async void DoGenerateNextBatchNumber(object obj) { try { WorkInProgress = true; var status = await RestHub.GenerateNextBatchNumber(NextBatch); if (status.HttpCode == System.Net.HttpStatusCode.OK) { AppInfoBox.ShowInfoMessage(status.StatusMessage); LoadDeliveryBatches(); } else { AppErrorBox.ShowErrorMessage("Can't Generate New Batch Number. .", status.HttpResponse); } } catch (Exception ex) { AppErrorBox.ShowErrorMessage("Can't Generate New Batch Number . .", ex.ToString()); } finally { WorkInProgress = false; } }
public void DeleteRsn(RsnVM rsnVM) { try { if (Rsns != null) { var mainVM = (App.Current.MainWindow as MainWindow).DataContext as MainVM; if (rsnVM.IsIgnorableInDelivery && rsnVM.ReactionParticipantId != null && rsnVM.ReactionParticipantId.Count > 0 && mainVM.TanVM.ReactionParticipants.OfReaction(ReactionVM.Id).Where(rp => rsnVM.ReactionParticipantId.Contains(rp.Id)).FirstOrDefault() != null) { var RP = mainVM.TanVM.ReactionParticipants.OfReaction(ReactionVM.Id).Where(rp => rsnVM.ReactionParticipantId.Contains(rp.Id)).FirstOrDefault(); StringBuilder sb = new StringBuilder(); sb.Append("Special CVT has assoiciated Participant : "); sb.Append(RP.Reg); sb.AppendLine(); sb.AppendLine("RXN : " + RP.ReactionVM.Name); sb.AppendLine("Stage : " + RP.StageVM?.Name); sb.AppendLine("Category : " + RP.ParticipantType); sb.AppendLine("NUM : " + RP.Num); sb.AppendLine("Series : " + RP.ChemicalType); sb.AppendLine("Please remove participant from Reaction to delete Selected RSN"); AppInfoBox.ShowInfoMessage(sb.ToString()); } else { Rsns.Remove(rsnVM); } } } catch (Exception ex) { Log.This(ex); } }
private async void DoMarkAsDelivered(object obj) { if (DeliveryBatch != null) { try { WorkInProgress = true; var status = await RestHub.UpdateDeliveryStatus(DeliveryBatch.Id); if (status.HttpCode == System.Net.HttpStatusCode.OK) { AppInfoBox.ShowInfoMessage(status.StatusMessage); } else { AppErrorBox.ShowErrorMessage("Can't Update delivery status . .", status.HttpResponse); } } catch (Exception ex) { AppErrorBox.ShowErrorMessage("Can't Update delivery status . .", ex.ToString()); } finally { WorkInProgress = false; } } else { AppInfoBox.ShowInfoMessage("Please select atleast one batch to update delivery status"); } }
private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { this.Dispatcher.BeginInvoke((System.Action) delegate() { Hide(); AppInfoBox.ShowInfoMessage("Please Restart The Tool . ."); Environment.Exit(0); }); }
private async void DoAllowReview(object obj) { if (SelectedBatches.Any()) { var result = await RestHub.AllowForReview(SelectedBatches.Select(b => b.Name).ToList()); if (result.UserObject != null) { AppInfoBox.ShowInfoMessage("Status updated Succeesfully"); } } }
async private void DoGenerateMail(object obj) { try { WorkInProgress = true; if (DeliveryBatch != null) { var result = await RestHub.GenerateEmail(DeliveryBatch.Id); if (result.HttpCode == System.Net.HttpStatusCode.OK) { try { Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.MailItem mailItem = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); mailItem.To = "*****@*****.**"; mailItem.CC = "[email protected];[email protected]"; mailItem.Subject = "Reactions Mail"; mailItem.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML; mailItem.HTMLBody = result.UserObject.ToString(); mailItem.Display(false); } catch (Exception ex) { var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), $"{DeliveryBatch.BatchNumber}.html"); File.WriteAllText(path, result.UserObject.ToString()); AppInfoBox.ShowInfoMessage($"Unfortunately Outlook is not accessible. The prepared report will open in web browser, you may copy and paste in email manually."); Process.Start(path); } } else { AppErrorBox.ShowErrorMessage("Error While Generating Email . .", Environment.NewLine + result.HttpResponse); } DeliveryInProgress = Visibility.Hidden; } else { MessageBox.Show("From Batch, From Category, Delivery Batch Number Is Required . . ."); } WorkInProgress = false; } catch (Exception ex) { AppErrorBox.ShowErrorMessage("Can't generate mail report . .", ex.ToString()); } finally { WorkInProgress = false; } }
private async void DoMoveToDelivery(object obj) { try { WorkInProgress = true; if (BatchTans != null && SelectedTans != null && SelectedTans.Count() > 0) { var InValidTans = SelectedTans.Where(t => (((BatchTanVM)t).TanState.HasValue && S.UnDelivarableTanStates.Contains(((BatchTanVM)t).TanState.Value)) || ((BatchTanVM)t).IsDoubtRaised.ToLower().Equals("true")).ToList(); if (InValidTans.Any()) { AppInfoBox.ShowInfoMessage("Selected Tan Contains NotAssigned/Curation In progress/Doubt Raised tans."); return; } if (DeliveryBatch != null) { var moveTansDto = new MoveTansDTO(); moveTansDto.TanIds = SelectedTans.Select(t => ((BatchTanVM)t).Id).ToList(); moveTansDto.TargetCategory = DeliveryBatch.Id; var status = await RestHub.MoveToDelivery(moveTansDto); if (status.HttpCode == System.Net.HttpStatusCode.OK) { SearchTans.Execute(this); var result = MessageBox.Show(status.StatusMessage, "Status", MessageBoxButton.OKCancel); } else { AppErrorBox.ShowErrorMessage("Can't Move TANs To Delivery . .", status.HttpResponse); } } else { AppInfoBox.ShowInfoMessage("Delivery Batch Not Selected."); } } else { AppInfoBox.ShowInfoMessage("Please Load and Select TANs To Proceed . ."); } WorkInProgress = false; } catch (Exception ex) { Log.This(ex); AppErrorBox.ShowErrorMessage("Can't Move TANs To Delivery . .", ex.ToString()); } finally { WorkInProgress = false; } }
public void DisplayDuplicateString(string RegNumber) { StringBuilder sb = new StringBuilder(); sb.Append("Chemical with Reg Number "); sb.Append(RegNumber); sb.AppendLine(" Already added."); sb.AppendLine($"RXN : {this.ReactionVM.DisplayOrder} [{this.ReactionVM.KeyProductSeq}]"); sb.AppendLine("Stage : " + this.StageVM?.Name); sb.AppendLine("Category : " + this.ParticipantType); sb.AppendLine("NUM : " + this.Num); sb.AppendLine("Series : " + this.ChemicalType); AppInfoBox.ShowInfoMessage(sb.ToString()); }
private void CollectAnnotations() { PdfAnnotationsVM vm = thisInstance.DataContext as PdfAnnotationsVM; vm.Clear(); AxFoxitPDFSDK Foxit = (PdfHost.Child as AxFoxitPDFSDK); (PdfHost.Child as AxFoxitPDFSDK).UnLockActiveX(C.LICENCE_ID, C.UNLOCK_CODE); if (!String.IsNullOrEmpty(FilePath) && File.Exists(FilePath) && Foxit != null) { try { if (Foxit.OpenFile(FilePath, null)) { vm.FileName = System.IO.Path.GetFileName(FilePath); Foxit.ForceRefresh(); for (int page = 0; page < Foxit.PageCount; page++) { PDFPageAnnots annotations = Foxit.GetPageAnnots(page); int count = annotations.GetAnnotsCount(); for (int index = 0; index < count; index++) { PDFAnnot annot = annotations.GetAnnot(index); vm.Results.Add(new PdfAnnotationResultVM { Text = annot.GetContents(), PageNum = page + 1, Author = annot.Author, Type = annot.GetSubType() }); } } vm.Results.UpdateDisplayOrder(); vm.TotalCount = vm.Results.Count.ToString(); Foxit.CloseFile(); } else { AppErrorBox.ShowErrorMessage("Pdf can't be opened to collect annotations", $"{FilePath} Can't be opened"); } } catch (Exception ex) { AppErrorBox.ShowErrorMessage("Can't collect annotations . . ", ex.ToString()); Log.This(ex); } } else { AppInfoBox.ShowInfoMessage("Pdf file not avaialble"); } }
private void DoGenerateBatch(object obj) { if (NextBatch != 0) { var existingBatches = DeliveryBatches.OrderBy(d => d.BatchNumber).Select(t => t.BatchNumber); if (existingBatches.Any() && existingBatches.ToList().Contains(NextBatch)) { AppInfoBox.ShowInfoMessage("Selected batch Already exist"); return; } DoGenerateNextBatchNumber(null); } else { AppInfoBox.ShowInfoMessage("Enter Batch number to Generate new delivery batch"); } }
async private void DoGetVersions(object obj) { try { FromHistory = new ObservableCollection <TanHistoryVM>(); ToHistory = new ObservableCollection <TanHistoryVM>(); if (!String.IsNullOrEmpty(TanNumber)) { Loading = true; var result = await RestHub.Versions(TanNumber); if (result.HttpCode == System.Net.HttpStatusCode.OK) { List <TanHistoryDTO> dtos = (List <TanHistoryDTO>)result.UserObject; foreach (var dto in dtos) { FromHistory.Add(new Core.TanHistoryVM { Id = dto.Id, Text = dto.Text }); ToHistory.Add(new Core.TanHistoryVM { Id = dto.Id, Text = dto.Text }); } } else { AppInfoBox.ShowInfoMessage("Error While Versions . ." + Environment.NewLine + result.HttpResponse); } Loading = false; } else { AppInfoBox.ShowInfoMessage("Please Enter TAN Number . ."); } } catch (Exception ex) { Log.This(ex); } }
private async void DoMoveToCategory(object obj) { try { WorkInProgress = true; if (BatchTans != null && SelectedTans != null && SelectedTans.Count() > 0) { if (FromBatch != null && ToCategory != null) { var moveTansDto = new MoveTansDTO(); moveTansDto.TanIds = SelectedTans.Select(t => ((BatchTanVM)t).Id).ToList(); moveTansDto.TargetCategory = ToCategory.Value; var status = await RestHub.MoveToCategory(moveTansDto); if (status.HttpCode == System.Net.HttpStatusCode.OK) { SearchTans.Execute(this); var result = MessageBox.Show(status.StatusMessage, "Status", MessageBoxButton.OKCancel); } else { AppErrorBox.ShowErrorMessage("Can't Move TANs To Category . .", status.HttpResponse); } } else { AppInfoBox.ShowInfoMessage("From Batch, To Category Should Be Selected, And Must Be Different To Proceed. ."); } } else { AppInfoBox.ShowInfoMessage("Please Load and Select TANs To Proceed . ."); } } catch (Exception ex) { Log.This(ex); AppErrorBox.ShowErrorMessage("Can't Move TANs To Category . .", ex.ToString()); } finally { WorkInProgress = false; } }
private async void DoRevert(object obj) { if (String.IsNullOrEmpty(DeliveryMessage)) { AppInfoBox.ShowInfoMessage("Delivery message is mandatory . ."); return; } if (System.Windows.MessageBox.Show("Confirm Revert Action . .", "Confirm", MessageBoxButton.OKCancel) != MessageBoxResult.OK) { return; } if (Role != null && TAN != null) { WorkInProgress = true; try { var result = await RestHub.RevertDeliveryTAN(TAN.Id, Role.Role, DeliveryMessage); if (result.HttpCode == System.Net.HttpStatusCode.OK) { AppInfoBox.ShowInfoMessage(result.StatusMessage); Search.Execute(this); } else { AppErrorBox.ShowErrorMessage("Error While Reverting TAN . .", result.StatusMessage); } } catch (Exception ex) { AppErrorBox.ShowErrorMessage("Error While Reverting TAN . .", ex.ToString()); } finally { WorkInProgress = false; } } else { System.Windows.MessageBox.Show("Select Role and TAN"); } }
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 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; }
private void DoFind(object obj) { if (TanFreeTextsView != null && !string.IsNullOrEmpty(TargetText)) { TanFreeTextsView.Filter = (c) => { if (c != null) { var freetextProperty = c as FreetextPropertiesVM; if (freetextProperty != null) { return(String.IsNullOrEmpty(TargetText) ? true : !string.IsNullOrEmpty(freetextProperty.FreeText) && freetextProperty.FreeText.Contains(TargetText)); } } return(false); }; } else { AppInfoBox.ShowInfoMessage("Data must be required to find"); } }
private void DoReplace(object obj) { StringBuilder result = new StringBuilder(); if (IsEditAreaValid(out result)) { if (obj != null) { var but = (System.Windows.Controls.Button)obj; List <Guid> SelectedIds = TanFreetexts.Where(t => t.Selected).Select(t => t.RsnId).ToList(); if (but.Name == "ReplaceSelected" && (SelectedIds == null || !SelectedIds.Any())) { AppInfoBox.ShowInfoMessage("Please select items from the grid to replace freetext"); return; } if (MessageBox.Show($"Are you sure you want to Replace Freetexts in {(but.Name == "ReplaceSelected" ? "Selected RSNs" : "All Rsns")}", "Rsn Replace Window", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if ((App.Current.MainWindow) as MainWindow != null && ((App.Current.MainWindow) as MainWindow).DataContext as MainVM != null && (((App.Current.MainWindow) as MainWindow).DataContext as MainVM).TanVM != null) { var mainVM = ((App.Current.MainWindow) as MainWindow).DataContext as MainVM; string ResponceText = string.Empty; if (ReplaceFreeTexts(TargetText, ReplaceText, mainVM, out ResponceText, but.Name == "ReplaceSelected" ? SelectedIds : null)) { PrepareData(); } else { AppInfoBox.ShowInfoMessage(ResponceText); } } } } } else { AppInfoBox.ShowInfoMessage(result.ToString()); } }
public void AddParticipant(object participant) { try { var StartTime = DateTime.Now; Debug.WriteLine($"Add Participant Started at {StartTime.DMYHMT()}"); var mainViewModel = (App.Current.MainWindow as MainWindow).DataContext as MainVM; if (SelectedTanChemicalVM != null && mainViewModel.TanVM != null && mainViewModel.IsParticipatTypeSelected) { if (S.AllowedDuplicateChemicals.Where(c => SelectedTanChemicalVM.SearchName.Contains(c)).Count() > 0) { var ListOfNames = SelectedTanChemicalVM.SearchName.Split(new string[] { "; " }, StringSplitOptions.RemoveEmptyEntries); DuplicateNamesList dnList = new Views.DuplicateNamesList(); (dnList.DataContext as DuplicateNamesVM).DuplicateNamesView = new ObservableCollection <Names>(ListOfNames.Select(s => new Names { Name = s })); dnList.ShowDialog(); if ((dnList.DataContext as DuplicateNamesVM).DialogStatus) { SelectedTanChemicalVM.Name = (dnList.DataContext as DuplicateNamesVM).SelectedName.Name; } else { return; } } if (SelectedTanChemicalVM.RegNumber == "5137553") { AppInfoBox.ShowInfoMessage("You can't add Aliquat 336. If still you want please Add RSN as 'Aliquat 336 Used'"); return; } if (SelectedTanChemicalVM.RegNumber == "69849452") { AppInfoBox.ShowInfoMessage("Davis reagent (REGNUM: 69849452) cannot be used in RSD, please capture in RSN"); return; } //this is required only for 8500 series. All other series will have Num values. if (SelectedTanChemicalVM != null && SelectedTanChemicalVM.NUM == 0) { var numChemical = TanChemicalVMList.Where(cn => cn.ChemicalType == ChemicalType.NUM && cn.RegNumber == SelectedTanChemicalVM.RegNumber).FirstOrDefault(); if (numChemical != null) { StringBuilder sb = new StringBuilder(); sb.Append($"Selected chemical already Present in NUMS section with num {numChemical.NUM}"); AppInfoBox.ShowInfoMessage(sb.ToString()); return; } SelectedTanChemicalVM.Id = Guid.NewGuid(); var maxNum = TanChemicalVMList. Where(rp => rp.ChemicalType == ChemicalType.S8500). Select(rp => rp.NUM). Max(); if (maxNum > 0) { SelectedTanChemicalVM.NUM = maxNum + 1; } else { SelectedTanChemicalVM.NUM = 8501; } TanChemical tanchemical = (from p in mainViewModel.TanVM.TanChemicals where p.RegNumber == SelectedTanChemicalVM.RegNumber select p).FirstOrDefault(); if (tanchemical == null) { TanChemicalsCrud.AddTanChemicalToList(mainViewModel.TanVM.TanChemicals, SelectedTanChemicalVM, mainViewModel.TanVM.Id); } if (!AddAsParticipant) { mainViewModel.TanVM.PerformAutoSave("8500 Chemical Added"); } } var chemical = TanChemicalVMList.Where(cn => cn.ChemicalType == ChemicalType.NUM && cn.RegNumber == SelectedTanChemicalVM.RegNumber && SelectedTanChemicalVM.ChemicalType != ChemicalType.NUM).FirstOrDefault(); if (chemical != null) { SelectedTanChemicalVM = chemical; } if (SelectedTanChemicalVM.RegNumber == "30525894" && SelectedTanChemicalVM.ChemicalType == ChemicalType.NUM) { SelectedTanChemicalVM = TanChemicalVMList.Where(cn => cn.ChemicalType == ChemicalType.S9000 && cn.RegNumber == "50000").FirstOrDefault(); SelectedTanChemicalVM.Name = S.PARA_FORM; } Debug.WriteLine($"Before adding Participant to Json {System.DateTime.Now}"); if (SelectedTanChemicalVM != null && AddAsParticipant) { (App.Current.MainWindow as MainWindow).ChemicalNameAdded(SelectedTanChemicalVM); } ReactionValidations.AddJonesReAgentRSN(mainViewModel.TanVM); Debug.WriteLine($"After adding Participant to Json {System.DateTime.Now}"); Debug.WriteLine($"Add Participant Done in {(DateTime.Now - StartTime).TotalSeconds} seconds"); } } catch (Exception ex) { Log.This(ex); } }
private void CopySelectedStages(object obj) { if (SelectedStages.Count > 0) { var mainViewModel = ((MainWindow)(App.Current.MainWindow)).DataContext as MainVM; if (SelectedStageOption != CopyStageOptions.APPEND && (mainViewModel.TanVM.SelectedReaction == null || mainViewModel.TanVM.SelectedReaction.SelectedStage == null)) { AppInfoBox.ShowInfoMessage("Please select stage to Add stages before/after in curation window."); return; } List <ReactionParticipantVM> allParticipants = new List <ReactionParticipantVM>(); List <StageVM> reactionStages = new List <StageVM>(); var tanParticipants = new List <ReactionParticipantVM>(); if (IsReactantsSelected) { var reactants = (from p in mainViewModel.TanVM.ReactionParticipants where p.ReactionVM.Id == mainViewModel.TanVM.SelectedReaction.Id && p.ParticipantType == ParticipantType.Reactant select p).ToList(); allParticipants.AddRange(reactants); } if (IsSolventsSelected || IsAgentsSelected || IsCatalystSelected) { if (IsSolventsSelected) { var solvents = (from p in mainViewModel.TanVM.ReactionParticipants where p.ReactionVM.Id == mainViewModel.TanVM.SelectedReaction.Id && p.ParticipantType == ParticipantType.Solvent select p).ToList(); allParticipants.AddRange(solvents); } if (IsAgentsSelected) { var agents = (from p in mainViewModel.TanVM.ReactionParticipants where p.ReactionVM.Id == mainViewModel.TanVM.SelectedReaction.Id && p.ParticipantType == ParticipantType.Agent select p).ToList(); allParticipants.AddRange(agents); } if (IsCatalystSelected) { var catalysts = (from p in mainViewModel.TanVM.ReactionParticipants where p.ReactionVM.Id == mainViewModel.TanVM.SelectedReaction.Id && p.ParticipantType == ParticipantType.Catalyst select p).ToList(); allParticipants.AddRange(catalysts); } } else { AppInfoBox.ShowInfoMessage("Please select Atleast one type of Participants to Copy."); return; } var selectedreaction = mainViewModel.TanVM.SelectedReaction; List <RsnVM> tanRsns = new List <RsnVM>(); var stages = new List <StageVM>(); for (int i = 0; i < StagesCountToCopy; i++) { foreach (var selectedstage in SelectedStages) { var newStageToAdd = new StageVM { Id = Guid.NewGuid(), ReactionVm = selectedreaction }; if (IsConditionsSelected) { var Conditions = new List <StageConditionVM>(); foreach (var selectedCondition in selectedstage.Conditions) { var condition = new StageConditionVM { DisplayOrder = selectedCondition.DisplayOrder, Id = Guid.NewGuid(), PH = selectedCondition.PH, PH_TYPE = selectedCondition.PH_TYPE, Pressure = selectedCondition.Pressure, PRESSURE_TYPE = selectedCondition.PRESSURE_TYPE, StageId = newStageToAdd.Id, Temperature = selectedCondition.Temperature, TEMP_TYPE = selectedCondition.TEMP_TYPE, Time = selectedCondition.Time, TIME_TYPE = selectedCondition.TIME_TYPE }; Conditions.Add(condition); } newStageToAdd.SetConditions(Conditions); } else { newStageToAdd.Conditions = new ObservableCollection <StageConditionVM>(); } var stageParticipants = (from sp in allParticipants where sp.StageVM.Id == selectedstage.Id select sp).ToList(); foreach (var participant in stageParticipants) { var newParticipant = new ReactionParticipantVM { ChemicalType = participant.ChemicalType, DisplayOrder = participant.DisplayOrder, Name = participant.Name, Num = participant.Num, ParticipantType = participant.ParticipantType, ReactionVM = selectedreaction, Reg = participant.Reg, StageVM = newStageToAdd, TanChemicalId = participant.TanChemicalId, Yield = participant.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 == selectedstage.Id select rsn).ToList(); foreach (var rsn in stagersnList) { var newRsn = new RsnVM { CvtText = rsn.CvtText, Reaction = selectedreaction, IsRXN = false, Stage = newStageToAdd, FreeText = rsn.FreeText, Id = Guid.NewGuid(), DisplayOrder = rsn.DisplayOrder, IsIgnorableInDelivery = rsn.IsIgnorableInDelivery, ReactionParticipantId = rsn.ReactionParticipantId, SelectedChemical = rsn.SelectedChemical }; tanRsns.Add(newRsn); } } stages.Add(newStageToAdd); } } mainViewModel.TanVM.EnablePreview = false; foreach (var participant in tanParticipants) { mainViewModel.TanVM.ReactionParticipants.Add(participant); } foreach (var rsn in tanRsns) { mainViewModel.TanVM.Rsns.Add(rsn); } mainViewModel.TanVM.EnablePreview = true; if (SelectedStageOption != CopyStageOptions.APPEND && mainViewModel.TanVM.SelectedReaction != null && mainViewModel.TanVM.SelectedReaction.SelectedStage != null) { var stagesList = mainViewModel.TanVM.SelectedReaction.Stages.ToList(); var index = stagesList.Count() >= 1 ? stagesList.FindIndex(x => x.Id == mainViewModel.TanVM.SelectedReaction.SelectedStage.Id) : 0; if (SelectedStageOption == CopyStageOptions.AFTER) { selectedreaction.SetStages(stages, index + 1, true); } else if (SelectedStageOption == CopyStageOptions.BEFORE) { selectedreaction.SetStages(stages, index, true); } } else { selectedreaction.SetStages(stages); } mainViewModel.TanVM.PerformAutoSave("Stage Added"); Visible = System.Windows.Visibility.Hidden; AppInfoBox.ShowInfoMessage("Please Update the Stage Freetext Stage Information for newly created stages."); } else { AppInfoBox.ShowInfoMessage("Please Select AtLeast One stage"); } }
private async void DoSearchTans(object obj) { try { if (obj != null) { var conrol = (Telerik.Windows.Controls.RadGridView)obj; foreach (Telerik.Windows.Controls.GridViewColumn column in conrol.Columns) { column.ClearFilters(); } } WorkInProgress = true; BatchTans = new ObservableCollection <BatchTanVM>(); if (SelectedBatches.Any()) { var result = await RestHub.TansFromBatches(SelectedBatches.Select(b => b.Name).ToList(), 100); if (result.UserObject != null) { var tans = (List <BatchTanDto>)result.UserObject; foreach (var tan in tans) { BatchTans.Add(new BatchTanVM { Id = tan.Id, BatchNum = tan.BatchNumber, TanNumber = tan.TanNumber, TanCategory = new TanCategoryVM { Value = (int)tan.TanCategory, Description = tan.TanCategory.DescriptionAttribute() }, TanType = tan.TanType, Nums = tan.Nums, Rxns = tan.Rxns, Curator = tan.Curator, Reviewer = tan.Reviewer, QC = tan.QC, TanState = tan.TanState, CurrentRole = tan.CurrentRole, Version = tan.Version, Stages = tan.Stages, NearToTargetDate = tan.NearToTargetDate, IsDoubtRaised = tan.IsDoubtRaised.ToString(), TargetedDate = tan.TargetDate, ProcessingNote = tan.ProcessingNote }); } BatchTans.UpdateDisplayOrder(); BatchTansView = new ListCollectionView(BatchTans); } else { AppInfoBox.ShowInfoMessage("Can't Load TANs . ."); } } else { AppInfoBox.ShowInfoMessage("From Batch, To Batch, Category Are Required . ."); } UpdateSummary(BatchTans); } catch (Exception ex) { Log.This(ex); } WorkInProgress = false; }
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; } }
public static void ShowMessages(string msg) { AppInfoBox.ShowInfoMessage(msg); }
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); } }
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()); } }
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; } }
private void PopupViewModel_TANLoaded(object sender, Tan tan) { try { var mainViewModel = (App.Current.MainWindow as MainWindow).DataContext as MainVM; var startTime = DateTime.Now; var list = new List <TanChemicalVM>(); T.ResetTanChemicalDict(); foreach (var tanChemical in tan.TanChemicals) { string imagePath = null; if (tanChemical.Substancepaths != null && tanChemical.Substancepaths.Count > 0) { imagePath = tanChemical.Substancepaths.First().ImagePath; } var chemical = new TanChemicalVM { ChemicalType = tanChemical.ChemicalType, Id = tanChemical.Id, ImagePath = imagePath, Name = tanChemical.Name, NUM = tanChemical.NUM, RegNumber = tanChemical.RegNumber, SearchName = tanChemical.Name, CompoundNo = tanChemical.CompoundNo, GenericName = tanChemical.GenericName, StructureType = StructureType.MOL, MolString = tanChemical.MolString, MolFormula = tanChemical.Formula, AllImagePaths = tanChemical.Substancepaths.Select(s => s.ImagePath).Distinct().ToList(), ChemicalmataData = tanChemical.MetaData != null ? new List <TanChemicalMetaData>(tanChemical.MetaData) : null, InChiKey = tanChemical.InchiKey }; list.Add(chemical); } var regNumbersOfTanChemicals = tan.TanChemicals.Where(c => c.ChemicalType != ChemicalType.NUM).Select(c => c.RegNumber).ToList(); var chemicalDict = S.ChemicalDict; var dictOfchemicalsExceptTanNums = from storeChmical in chemicalDict where !regNumbersOfTanChemicals.Contains(storeChmical.Key) select storeChmical; var S8500ChemicalsFrom = dictOfchemicalsExceptTanNums.Select(s => s.Value).Where(tc => tc.ChemicalType == ChemicalType.S8500 && tc.NUM > 0); if (S8500ChemicalsFrom.Any()) { AppInfoBox.ShowInfoMessage("Static store chemical has updated"); } var participants = tan.TanChemicals.Where(p => p.ChemicalType == ChemicalType.S8000 && tan.Participants.Select(rp => rp.ParticipantId).ToList().Contains(p.Id)).Select(p => p.Id).ToList(); foreach (var chemical in list) { if (chemical.ChemicalType != ChemicalType.S8000) { var OrgRefChemical = S.Find(chemical.RegNumber); if (!string.IsNullOrEmpty(chemical.RegNumber) && OrgRefChemical != null && chemical.ChemicalType != ChemicalType.NUM) { chemical.SearchName = OrgRefChemical.SearchName; } } } foreach (var entry in dictOfchemicalsExceptTanNums) { var tanChemicalVM = new TanChemicalVM { AllImagePaths = entry.Value.AllImagePaths, ChemicalmataData = entry.Value.ChemicalmataData, ChemicalType = entry.Value.ChemicalType, CompoundNo = entry.Value.CompoundNo, GenericName = entry.Value.GenericName, Id = entry.Value.Id, ImagePath = entry.Value.ImagePath, Images = entry.Value.Images, InChiKey = entry.Value.InChiKey, MolString = entry.Value.MolString, Name = entry.Value.Name, NUM = entry.Value.NUM, RegNumber = entry.Value.RegNumber, SearchName = entry.Value.SearchName, StructureType = entry.Value.StructureType, MolFormula = entry.Value.MolFormula }; list.Add(tanChemicalVM); } TanChemicalVMList = new ObservableCollection <TanChemicalVM>(list); UpdateChemicalsView(); mainViewModel.S8000Chemicals = new ObservableCollection <Models.TanChemicalVM>(list.Where(chem => chem.ChemicalType == ChemicalType.S8000 && participants.Contains(chem.Id)).ToList()); } catch (Exception ex) { Log.This(ex); } }
private void Add8000SeriesChemical(object s) { try { if (!string.IsNullOrEmpty(MolString)) { if (S8000Metas != null && S8000Metas.Count > 0 && S8000Metas.Where(meta => !meta.ValidClass()).Count() == 0 && (!string.IsNullOrEmpty(SubstanceName) || !string.IsNullOrEmpty(CompoundNum) || !string.IsNullOrEmpty(GenericName))) { if ((EditingChemicalId == Guid.Empty && !string.IsNullOrEmpty(SubstanceName) && (from cn in TanChemicalVMList where cn.Name.SafeEqualsLower(SubstanceName) select cn).Any())) { AppInfoBox.ShowInfoMessage("Substance name Already exist in Chemical Names List"); return; } if ((EditingChemicalId == Guid.Empty && !string.IsNullOrEmpty(GenericName) && (from cn in TanChemicalVMList where cn.GenericName.SafeEqualsLower(GenericName) select cn).Any())) { AppInfoBox.ShowInfoMessage("GenericName Already exist in Chemical Names List"); return; } if ((EditingChemicalId == Guid.Empty && !string.IsNullOrEmpty(CompoundNum) && (from cn in TanChemicalVMList where cn.GenericName.SafeEqualsLower(CompoundNum) select cn).Any())) { AppInfoBox.ShowInfoMessage("CompoundNum Already exist in Chemical Names List"); return; } var inchiKey = MolToInchi.Mol2Inchi(MolString); if (!String.IsNullOrEmpty(inchiKey)) { var chemical = T.FindByInchiKey(inchiKey); if (chemical != null) { AppInfoBox.ShowInfoMessage(chemical.GetDuplicateChemicalString(inchiKey)); return; } chemical = TanChemicalVMList.Where(cn => cn.InChiKey != null && cn.InChiKey == inchiKey).FirstOrDefault(); if (chemical != null && EditingChemicalId == Guid.Empty) { AppInfoBox.ShowInfoMessage(chemical.GetDuplicateChemicalString(inchiKey)); return; } } var mainViewModel = (App.Current.MainWindow as MainWindow).DataContext as MainVM; var MetaDataList = new List <TanChemicalMetaData>(); foreach (var item in S8000Metas) { var tanChemicalMeta = new TanChemicalMetaData { Id = Guid.NewGuid(), ColumnNo = item.Column, Figure = item.Figure, FootNote = item.FootNote, LineNo = item.Line, OtherNotes = item.Other, PageNo = item.Page, ParaNo = item.Para, Scheme = item.Scheme, Sheet = item.Sheet, TableNo = item.Table }; MetaDataList.Add(tanChemicalMeta); } if (EditingChemicalId != Guid.Empty) { var EditedChemical = TanChemicalVMList.Where(i => i.Id == EditingChemicalId).FirstOrDefault(); if (EditedChemical != null) { EditedChemical.Name = SubstanceName; EditedChemical.SearchName = string.IsNullOrEmpty(SubstanceName) ? (string.IsNullOrEmpty(GenericName) ? CompoundNum : GenericName) : SubstanceName; EditedChemical.ChemicalType = ChemicalType.S8000; EditedChemical.CompoundNo = CompoundNum; EditedChemical.GenericName = GenericName; EditedChemical.StructureType = StructureType.CGM; EditedChemical.ChemicalmataData = MetaDataList; EditedChemical.MolString = MolString; EditedChemical.MolFormula = MolFormula; EditedChemical.InChiKey = inchiKey; } UpdateChemicalName(EditedChemical); SelectedTanChemicalVM = null; SelectedTanChemicalVM = EditedChemical; mainViewModel.TanVM.UpdateUnusedNUMs(); mainViewModel.TanVM.UpdateNumsView(); Clear8000EditArea(); SelectedTabIndex = 0; } else { var newChemical = new TanChemicalVM { Id = Guid.NewGuid(), Name = SubstanceName, SearchName = SubstanceName, ChemicalType = ChemicalType.S8000, CompoundNo = CompoundNum, GenericName = GenericName, StructureType = StructureType.CGM, ChemicalmataData = MetaDataList, MolString = MolString, MolFormula = MolFormula, InChiKey = inchiKey }; foreach (var item in MetaDataList) { item.TanChemicalId = newChemical.Id; } Add8000Chemical(newChemical); } EditingChemicalId = Guid.Empty; } else { AppInfoBox.ShowInfoMessage("New Chemical data missed. To save new chemical SubstanceName/CompoundNum/GenericName and PageNo are mandatory."); } } else { AppInfoBox.ShowInfoMessage("Please draw structure to add"); } } catch (Exception ex) { Log.This(ex); } }
private void EditTanChemical(object s) { try { var mainViewModel = (App.Current.MainWindow as MainWindow).DataContext as MainVM; if (SelectedTanChemicalVM != null) { if (SelectedTanChemicalVM.ChemicalType == ChemicalType.S8000) { EditingChemicalId = SelectedTanChemicalVM.Id; SubstanceName = SelectedTanChemicalVM.Name; CompoundNum = SelectedTanChemicalVM.CompoundNo; GenericName = SelectedTanChemicalVM.GenericName; MolString = SelectedTanChemicalVM.MolString; List <S8000MetaVM> MetaList = new List <S8000MetaVM>(); foreach (var item in SelectedTanChemicalVM.ChemicalmataData) { var metavm = new S8000MetaVM { Column = item.ColumnNo, Figure = item.Figure, FootNote = item.FootNote, Id = item.Id, Line = item.LineNo, Other = item.OtherNotes, Page = item.PageNo, Para = item.ParaNo, Scheme = item.Scheme, Sheet = item.Sheet, Table = item.TableNo }; MetaList.Add(metavm); } S8000Metas = new ObservableCollection <ViewModels.S8000MetaVM>(MetaList); SelectedTabIndex = 1; } else if (SelectedTanChemicalVM.ChemicalType == ChemicalType.S8500) { if (SelectedTanChemicalVM.NUM > 8500) { var s8500Chemicals = new List <TanChemicalVM>(); var chemicalName = new TanChemicalVM(SelectedTanChemicalVM); foreach (var e in TanChemicalVMList.Where(c => c.ChemicalType == ChemicalType.S8500 && c.NUM == 0)) { s8500Chemicals.Add(new TanChemicalVM(e)); } EditS8500Chemical.Invoke(this, new EditChemicalName { ChemicalNameVM = chemicalName, ChoosableChemicalVMs = s8500Chemicals }); var AllNumsList = TanChemicalVMList.Where(tc => tc.NUM > 0).Select(tc => tc.NUM); var duplicateNumsList = AllNumsList.GroupBy(num => num); if (AllNumsList.Count() != duplicateNumsList.Count()) { Log.This(new Exception("Duplicate Nums were generated")); } } else { AppInfoBox.ShowInfoMessage("NUM Not Generated For This Chemical . ."); } } else { AppInfoBox.ShowInfoMessage("Only 8500 And 8000 NUMs Are Editable . ."); } } } catch (Exception ex) { Log.This(ex); } }
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; }