protected void FillGrid() { int bulk_letter_sending_queue_batch_id = IsValidFormBatchID() ? GetFormBatchID() : -1; DataTable dt = BulkLetterSendingQueueDB.GetDataTable(bulk_letter_sending_queue_batch_id); // send method hashtable DataTable sendMethodTbl = DBBase.GetGenericDataTable_WithWhereOrderClause(null, "LetterPrintHistorySendMethod", "", "", "letter_print_history_send_method_id", "descr"); Hashtable sendMethodHash = new Hashtable(); for (int i = 0; i < sendMethodTbl.Rows.Count; i++) { sendMethodHash[Convert.ToInt32(sendMethodTbl.Rows[i]["letter_print_history_send_method_id"])] = (string)sendMethodTbl.Rows[i]["descr"]; } // patient hashtable ArrayList ptIDs = new ArrayList(); for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i]["patient_id"] != DBNull.Value) { ptIDs.Add((int)dt.Rows[i]["patient_id"]); } } Hashtable patientHash = PatientDB.GetByIDsInHashtable((int[])ptIDs.ToArray(typeof(int))); // staff hashtable Hashtable staffHash = StaffDB.GetAllInHashtable(true, true, true, false); // referrersHash Hashtable referrersHash = ReferrerDB.GetHashtableByReferrer(); // letters hashtable Hashtable letterHash = LetterDB.GetHashTable(); // add from hashtable dt.Columns.Add("letter_print_history_send_method_descr", typeof(String)); dt.Columns.Add("added_by_name", typeof(String)); dt.Columns.Add("patient_name", typeof(String)); dt.Columns.Add("referrer_name", typeof(String)); dt.Columns.Add("letter_doc_name", typeof(String)); int SMSSent = 0; int SMSUnSent = 0; int EmailSent = 0; int EmailUnSent = 0; int PrintSent = 0; int PrintUnSent = 0; for (int i = 0; i < dt.Rows.Count; i++) { int letter_print_history_send_method_id = Convert.ToInt32(dt.Rows[i]["letter_print_history_send_method_id"]); bool sent = dt.Rows[i]["datetime_sent"] != DBNull.Value; dt.Rows[i]["letter_print_history_send_method_descr"] = (string)sendMethodHash[letter_print_history_send_method_id]; dt.Rows[i]["added_by_name"] = dt.Rows[i]["added_by"] == DBNull.Value ? "" : ((Staff)staffHash[Convert.ToInt32(dt.Rows[i]["added_by"])]).Person.FullnameWithoutMiddlename; dt.Rows[i]["patient_name"] = dt.Rows[i]["patient_id"] == DBNull.Value ? "" : ((Patient)patientHash[Convert.ToInt32(dt.Rows[i]["patient_id"])]).Person.FullnameWithoutMiddlename; dt.Rows[i]["referrer_name"] = dt.Rows[i]["referrer_id"] == DBNull.Value ? "" : ((Referrer)referrersHash[Convert.ToInt32(dt.Rows[i]["referrer_id"])]).Person.FullnameWithoutMiddlename; string source_template_path = dt.Rows[i]["email_letter_source_template_path"].ToString(); string letter_doc_name = source_template_path.Length == 0 ? "" : System.IO.Path.GetFileName(source_template_path); dt.Rows[i]["letter_doc_name"] = letter_doc_name; if (letter_print_history_send_method_id == 3 && sent) { SMSSent++; } if (letter_print_history_send_method_id == 3 && !sent) { SMSUnSent++; } if (letter_print_history_send_method_id == 2 && sent) { EmailSent++; } if (letter_print_history_send_method_id == 2 && !sent) { EmailUnSent++; } if (letter_print_history_send_method_id == 1 && sent) { PrintSent++; } if (letter_print_history_send_method_id == 1 && !sent) { PrintUnSent++; } } lblSMSSent.Text = SMSSent.ToString(); lblSMSUnSent.Text = SMSUnSent.ToString(); lblEmailSent.Text = EmailSent.ToString(); lblEmailUnSent.Text = EmailUnSent.ToString(); lblPrintSent.Text = PrintSent.ToString(); lblPrintUnSent.Text = PrintUnSent.ToString(); lblTotalSent.Text = (SMSSent + EmailSent + PrintSent).ToString(); lblTotalUnSent.Text = (SMSUnSent + EmailUnSent + PrintUnSent).ToString(); DataView dv = new DataView(dt); dv.Sort = "letter_print_history_send_method_id"; dt = dv.ToTable(); Session["lettersprintbatchstatus_data"] = dt; if (dt.Rows.Count > 0) { if (IsPostBack && Session["lettersprintbatchstatus_sortexpression"] != null && Session["lettersprintbatchstatus_sortexpression"].ToString().Length > 0) { DataView dataView = new DataView(dt); dataView.Sort = Session["lettersprintbatchstatus_sortexpression"].ToString(); GrdBulkLetterSendingQueue.DataSource = dataView; } else { GrdBulkLetterSendingQueue.DataSource = dt; } GrdBulkLetterSendingQueue.AllowPaging = false; try { GrdBulkLetterSendingQueue.DataBind(); GrdBulkLetterSendingQueue.PagerSettings.FirstPageText = "1"; GrdBulkLetterSendingQueue.PagerSettings.LastPageText = GrdBulkLetterSendingQueue.PageCount.ToString(); GrdBulkLetterSendingQueue.DataBind(); } catch (Exception ex) { HideTableAndSetErrorMessage("", ex.ToString()); } } else { dt.Rows.Add(dt.NewRow()); GrdBulkLetterSendingQueue.DataSource = dt; GrdBulkLetterSendingQueue.DataBind(); int TotalColumns = GrdBulkLetterSendingQueue.Rows[0].Cells.Count; GrdBulkLetterSendingQueue.Rows[0].Cells.Clear(); GrdBulkLetterSendingQueue.Rows[0].Cells.Add(new TableCell()); GrdBulkLetterSendingQueue.Rows[0].Cells[0].ColumnSpan = TotalColumns; GrdBulkLetterSendingQueue.Rows[0].Cells[0].Text = "No Record Found"; } }