/// <summary> /// Import Orders /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnImport_Click(object sender, EventArgs e) { var fileSelector = new FolderBrowserDialog(); var defaultPath = ExportFile.GetDefaultPath("dircPath"); if (defaultPath != "") { fileSelector.SelectedPath = defaultPath; } if (fileSelector.ShowDialog() == DialogResult.OK) { ExportFile.SetFolderPath("dircPath", fileSelector.SelectedPath); lbFolder.Text = string.Format(" Selected Directory: {0}", fileSelector.SelectedPath); var files = Directory.GetFiles(fileSelector.SelectedPath).Where(name => name.EndsWith(".txt")); prbImport.Maximum = files.ToList().Count; prbImport.Step = 1; prbImport.Value = 0; foreach (var file in files.ToList()) { var objOrder = FormatParsing.ParsePathToFileName(file); objOrder = FormatParsing.ParseContentIntoOrder(file, objOrder); objOrders.Add(objOrder); } objOrders.Sort(); if (bkgWorkForImporting.IsBusy != true) { bkgWorkForImporting.RunWorkerAsync(); } btnImportRecords.Enabled = false; } }
/// <summary> /// Import the transaction records /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnImportTransaction_Click(object sender, EventArgs e) { FileDialog fileSelector = new OpenFileDialog(); fileSelector.Filter = "Text files (*.xls)|*.xls"; var defaultPath = ExportFile.GetDefaultPath("dircPath"); if (defaultPath != "") { fileSelector.InitialDirectory = defaultPath; } if (fileSelector.ShowDialog() == DialogResult.OK) { var pos = fileSelector.FileName.LastIndexOf(@"\", StringComparison.Ordinal); var path = fileSelector.FileName.Substring(0, pos); ExportFile.SetFolderPath("dircPath", path); lbFolder.Text = string.Format(" Selected Directory: {0}", path); prbImport.Step = 1; prbImport.Value = 0; objTransactions = FormatParsing.ParseContentIntoTransaction(fileSelector.FileName, objTransactions); prbImport.Maximum = objTransactions.Count; if (bkgWorkForTransaction.IsBusy != true) { bkgWorkForTransaction.RunWorkerAsync(); } btnImportTransaction.Enabled = false; } }