private void LoadCases() { try { if (File.Exists(txtTSVFileLocation.Text.Trim())) { List <Dictionary <string, string> > parsedTable = BatchBL.ParseXSVFile(txtTSVFileLocation.Text); dgCases.Rows.Clear(); foreach (var tableRow in parsedTable) { //Read each row of data DataGridViewRow dr = new DataGridViewRow(); dr.Height = 30; dr.CreateCells(dgCases); dr.Cells[0].Value = tableRow["id"].ToString(); if (tableRow.ContainsKey("template")) { dr.Cells[1].Value = tableRow["template"].ToString(); } if (tableRow.ContainsKey("case_number")) { dr.Cells[2].Value = tableRow["case_number"].ToString(); } if (tableRow.ContainsKey("jurisdiction")) { dr.Cells[3].Value = tableRow["jurisdiction"].ToString(); } dr.Cells[6].Value = "Preview"; dgCases.Rows.Add(dr); } dgCases.Refresh(); } } catch (Exception) { throw; } }
private void dgCases_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex == -1) { return; } int selectedIndex = dgCases.CurrentCell.RowIndex; int selectedCol = dgCases.CurrentCell.ColumnIndex; var id = dgCases.Rows[selectedIndex].Cells[0].Value; string templatepath = Path.Combine(txtJsonTemplateLocation.Text, AppConstants.LoginState); List <Dictionary <string, string> > parsedTable = BatchBL.ParseXSVFile(txtTSVFileLocation.Text); Dictionary <string, string> templates = BatchBL.InitiTemplates(templatepath); foreach (var tableRow in parsedTable) { //Read each row of data if (id.Equals(tableRow["id"])) { tableRow.Add("batch_id", BatchId); var line = string.Join(AppConstants.XSV_SEPERATOR, tableRow.Values); String payload = null; string template = null; if (tableRow.ContainsKey("template")) { template = tableRow["template"]; } if (template != null && template.Trim().Length > 0) { if (templates.ContainsKey(template)) { payload = templates[template]; } } else { if (!tableRow.ContainsKey("case_number") || tableRow["case_number"].ToString().Trim().Length == 0) { template = "NEW"; } else { template = "EXISTING"; } if (templates.ContainsKey(template)) { payload = templates[template]; } } if (payload == null) { MessageBox.Show("Template: " + template + " Not Found"); } else { foreach (KeyValuePair <string, string> entry in tableRow) { var value = entry.Value; if (entry.Value.EndsWith(AppConstants.PDF_PATTERN)) { value = Path.GetFileName(value); } payload = payload.Replace("${" + entry.Key + "}", value); } frmPayload frmPayload = new frmPayload(); frmPayload.Payload = payload; frmPayload.ShowDialog(); } } } } catch (Exception ex) { LogManager.LogError(ex); } }
private void BGBatchProcess_DoWork(object sender, DoWorkEventArgs e) { try { string templatepath = Path.Combine(txtJsonTemplateLocation.Text, AppConstants.LoginState); List <Dictionary <string, string> > parsedTable = BatchBL.ParseXSVFile(txtTSVFileLocation.Text); Dictionary <string, string> templates = BatchBL.InitiTemplates(templatepath); var results = new List <dynamic>(); int counter = 0; int TotalRecord = parsedTable.Count; LogManager.Trace(String.Format("Add to batch process started for batch {0}.", BatchId)); foreach (var tableRow in parsedTable) { if (BGBatchProcess.CancellationPending) { LogManager.Trace(String.Format("Add to batch process stopped by user for batch {0}.", BatchId)); e.Cancel = true; break; } //Read each row of data tableRow.Add("batch_id", BatchId); var line = string.Join(AppConstants.XSV_SEPERATOR, tableRow.Values); String payload = null; string template = null; if (tableRow.ContainsKey("template")) { template = tableRow["template"]; } if (template != null && template.Trim().Length > 0) { if (templates.ContainsKey(template)) { payload = templates[template]; } } else { if (tableRow["case_number"].ToString().Trim().Length == 0) { template = "NEW"; } else { template = "EXISTING"; } if (templates.ContainsKey(template)) { payload = templates[template]; } } //-------------------------------------------------------------------------------- var filepaths = new List <string>(); if (payload != null) { foreach (KeyValuePair <string, string> entry in tableRow) { var value = entry.Value; if (entry.Value.EndsWith(AppConstants.PDF_PATTERN)) { filepaths.Add(value); value = Path.GetFileName(value); } payload = payload.Replace("${" + entry.Key + "}", value); } } var id = tableRow["id"]; int progress = (counter * 100) / TotalRecord; BGBatchProcess.ReportProgress(progress, id + "-Started-" + "efile process started."); try { if (payload == null) { throw new Exception("Template not found: " + template); } LogManager.Trace(String.Format("eFile for batch- {0} and id {1} started ", BatchId, id)); dynamic response = AppConstants.ApiCaller.Efile(id, payload, filepaths); //It is important that you update your database immidiately here with response before doing other things results.Add(response); LogManager.Trace(String.Format("eFile for batch- {0} and id {1} completed ", BatchId, id)); BGBatchProcess.ReportProgress(progress, id + "-Completed-" + "eFile process completed"); } catch (Exception ex) { BGBatchProcess.ReportProgress(progress, id + "-Failed-" + ex.Message); } counter++; } e.Result = results; } catch (Exception ex) { LogManager.LogError(ex); } }