public static void WriteOutput(string menuSelection, OrderedDictionary dataMap, Dictionary <string, string> options, ProgressPage progressPage) { // Get template and save as output file var excelPkg = new ExcelPackage(new FileInfo(options["TemplatePath"])); excelPkg.SaveAs(new FileInfo(options["OutputFolder"] + "\\" + options["OutputFileName"])); var(startRow, startCol) = ExcelUtils.GetRowCol(options["StartInCell"]); // Write Raw Data tab if (options["SamplesOut"] == "columns") { excelPkg = MapToExcel.WriteSamplesInColumns(dataMap, excelPkg, "Raw Data", options); } else { // TODO - fix this. Method was separated/changed //MapToExcel.WriteSamplesInRows(dataMap, excelPkg, "Raw Data", options); //MapToExcel.WriteCompoundsInColumns // Write to template if selected progressPage.ProgressTextBox.AppendText("Writing data into template\n"); } excelPkg = MapToExcel.WriteIntoTemplate(dataMap, excelPkg, options, options["TemplateTabName"]); // QC - Copy data tab, remove non-QC, calculate CV progressPage.ProgressTextBox.AppendText("Calculating QC CV\n"); excelPkg = QualityControl.WriteQCTab(excelPkg, options); // Absolute Quant Calc progressPage.ProgressTextBox.AppendText("Absolute Quantitation\n"); var compoundLoc = int.TryParse(options["CompoundLoc"], out var compoundLocNum) ? compoundLocNum : ExcelUtils.ColumnNameToNumber(options["CompoundLoc"]); excelPkg = MapToExcel.WriteIntoTemplate(dataMap, excelPkg, options, options["AbsoluteQuantTabName"], false, 2, 3, 1, compoundLoc); excelPkg = AbsoluteQuant.Sciex6500Template(excelPkg, options, compoundLoc); progressPage.ProgressTextBox.AppendText("Finished writing Absolute Quant Tab\n"); switch (menuSelection) { case "Sciex6500": break; case "Lipidyzer": break; default: break; } }
private void ShowProgressWindow() { ProgressPage progressPage = new ProgressPage(); navigationService.Navigate(progressPage); var progressTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(2500) }; progressTimer.Start(); progressTimer.Tick += (_sender, args) => { navigationService.Navigate(this); progressTimer.Stop(); progressTimer = null; CreateReceiptPDF(); }; }
private void StartTransfering(string transferToAcc, double amount) { ProgressPage progressPage = new ProgressPage(); _navigationService.Navigate(progressPage); var progressTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(2000) }; progressTimer.Start(); progressTimer.Tick += (_sender, args) => { DBHelper dBHelper = new DBHelper(); bool transferToAccIsValid = dBHelper.CheckAccountNo(transferToAcc); if (transferToAccIsValid) { User user = dBHelper.GetUser(ATMSession.AccountNo); transaction = new Transaction(user.User_Id, ATMSession.AccountNo, DateTime.Now, amount, transferToAcc); ReturnResult transactionResult = dBHelper.Transfer(transaction); if (transactionResult == ReturnResult.Success) { ATMSession.RestartSessionTimer(); if (_canPrintReceipt) { CreateReceiptPDF(); } TransactionSuccessMsg(); } else if (transactionResult == ReturnResult.IsEmpty) { var result = WpfMessageBox.Show("Warning", "Your account balance is Rs. 0.00", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Warning, WpfMessageBox.MessageBoxType.Warning); if (result.Equals(MessageBoxResult.OK)) { ATMSession.RestartSessionTimer(); TransferAmountTextBox.SelectAll(); TransferAmountTextBox.Focus(); } } else if (transactionResult == ReturnResult.AmountIsGreater) { var result = WpfMessageBox.Show("Warning", "Entered amount is greater than your account balance.", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Warning, WpfMessageBox.MessageBoxType.Warning); if (result.Equals(MessageBoxResult.OK)) { ATMSession.RestartSessionTimer(); TransferAmountTextBox.SelectAll(); TransferAmountTextBox.Focus(); } } else { var result = WpfMessageBox.Show("Error", "Transfer Error. Please contact your bank.", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Error, WpfMessageBox.MessageBoxType.Error); if (result.Equals(MessageBoxResult.OK)) { ATMSession.RestartSessionTimer(); TransferAmountTextBox.SelectAll(); TransferAmountTextBox.Focus(); } } _navigationService.GoBack(); progressTimer.Stop(); progressTimer = null; } else { var result = WpfMessageBox.Show("Error", "Transfer to account is not a valid account.", MessageBoxButton.OK, WpfMessageBox.MessageBoxImage.Error, WpfMessageBox.MessageBoxType.Error); if (result.Equals(MessageBoxResult.OK)) { ATMSession.RestartSessionTimer(); TransferAccountTextBox.SelectAll(); TransferAccountTextBox.Focus(); } _navigationService.GoBack(); progressTimer.Stop(); progressTimer = null; } }; }
public static OrderedDictionary ReadMultiQuantText( List <string> filePaths, Dictionary <string, string> options, ProgressPage progressPage) { // <compound, <sample name, data>> var dataMap = new OrderedDictionary(); /* Since text files can only be read row by row, first write the * data to an excel sheet and then read it into the data map. * This cross references the sample ID and compound name when storing the data. */ // Create "Import" tab in data template ExcelPackage.LicenseContext = LicenseContext.NonCommercial; // EPPlus license var templateFile = new FileInfo(options["TemplatePath"]); var excelPkg = new ExcelPackage(templateFile); var worksheet = excelPkg.Workbook.Worksheets.Add("Import"); int row = 1, col = 1, namesRow = 1; // One file at a time. Descending order makes POS before NEG // Keep ascending so samples are in order for multiple files? foreach (var filePath in filePaths) //.OrderByDescending(i => i)) { progressPage.ProgressTextBox.AppendText($"Reading file {Path.GetFileName(filePath)}\n"); // Read data from txt file to worksheet string[] lines = File.ReadAllLines(filePath); /* If samples in columns (MultiQuant export "Transposed" checked), * first line contains sample names with POS or NEG. */ /* If samples in rows (MultiQuant export "Transposed" not checked), * first line contains compound names. */ string[] names = lines[0].Split("\t"); foreach (var name in names) { // Write name to column // If samples in columns, name is sample name, remove POS or NEG worksheet.Cells[namesRow, col++].Value = options["SamplesIn"] == "columns" ? Regex.Replace(name, "^POS_|_POS$|^NEG_|_NEG$", "", RegexOptions.IgnoreCase) : name; } // Done with first line, increment row and reset column ++row; col = 1; // Write remaining lines for (var i = 1; i < lines.Length; ++i) { var line = lines[i]; string[] words = line.Split("\t"); //// If samples in rows, first word is sample name, remove POS or NEG if (options["SamplesIn"] == "rows") { words[0] = Regex.Replace(words[0], "^POS_|_POS$|^NEG_|_NEG$", "", RegexOptions.IgnoreCase); } // Write to cell, increment column after writing foreach (var word in words) { worksheet.Cells[row, col++].Value = word; } // Done with line, increment row and reset column ++row; col = 1; } var curMap = new OrderedDictionary(); // Read data into current map <compound, <sample name, data> curMap = options["SamplesIn"] == "rows" ? ExcelToMap.SamplesInRowsToMap(namesRow, 1, excelPkg, "Import") : ExcelToMap.SamplesInColumnsToMap(namesRow, 1, excelPkg, "Import"); // Remove "Sample Type" if that option was used. It is not a compound. try { curMap.Remove("Sample Type"); } catch { } // Merge current map with dataMap dataMap = Merge.MergeMaps(dataMap, curMap); /* At the end of each file, the next file's name row is the next row. * This is important to make sure the dataMap and curMap aren't * affected by mismatched sample order between the two files. */ namesRow = row; } excelPkg.SaveAs(new FileInfo(options["OutputFolder"] + "\\" + "import_" + options["OutputFileName"])); progressPage.ProgressTextBox.AppendText("All input files have been read.\n"); return(dataMap); }
public static OrderedDictionary ReadInputs(string menuSelection, List <string> filePathList, Dictionary <string, string> options, ProgressPage progressPage) { var dataMap = new OrderedDictionary(); switch (menuSelection) { case "Sciex6500": dataMap = options["InputType"] == "text" ? ReadMultiQuantTextInput.ReadMultiQuantText(filePathList, options, progressPage) : ExcelToMap.ReadAllFiles(filePathList, options); break; case "Lipidyzer": // Read one book at a time, write into template break; default: break; } return(dataMap); }
public static void Run(string menuSelection, List <string> filePathList, Dictionary <string, string> options, ProgressPage progressPage, InputOutputPage io) { // Read input - All data formats are read into one dataMap format for further processing progressPage.ProgressTextBox.AppendText("Processing inputs\n"); if (menuSelection == "Lipidyzer") { Lipidyzer(filePathList, options); return; } var dataMap = ReadInputs(menuSelection, filePathList, options, progressPage); // Perform data options // Write output progressPage.ProgressTextBox.AppendText("Writing output file\n"); WriteOutput(menuSelection, dataMap, options, progressPage); }