protected void Sort(string sortExpression, params string[] sortExpr) { DataTable dataTable = Session["userlogin_data"] as DataTable; if (dataTable != null) { if (Session["userlogin_sortexpression"] == null) { Session["userlogin_sortexpression"] = ""; } DataView dataView = new DataView(dataTable); string[] sortData = Session["userlogin_sortexpression"].ToString().Trim().Split(' '); string newSortExpr = (sortExpr.Length == 0) ? (sortExpression == sortData[0] && sortData[1] == "ASC") ? "DESC" : "ASC" : sortExpr[0]; dataView.Sort = sortExpression + " " + newSortExpr; Session["userlogin_sortexpression"] = sortExpression + " " + newSortExpr; GrdUserLogin.DataSource = dataView; GrdUserLogin.DataBind(); } }
public void FilterPPRId(string name) { if (!string.IsNullOrEmpty(name)) { DataTable dt = (DataTable)ViewState["DataList"]; DataView dataView = dt.DefaultView; dataView.RowFilter = "N_Name like '%" + name + "%'"; GrdUserLogin.DataSource = dataView; GrdUserLogin.DataBind(); } }
public void GetUserLogin() { try { obj = new AcknowledgementBL(); DataTable dt = obj.GetUserLoginDetailsBL(); if (dt.Rows.Count > 0) { GrdUserLogin.DataSource = dt; GrdUserLogin.DataBind(); ViewState["DataList"] = dt; } else { GrdUserLogin.DataSource = dt; GrdUserLogin.DataBind(); } } catch (Exception ex) { LogError(ex); } }
protected void FillGrid() { if (GetFormIncStaffLogins() && GetFormIncPatientLogins()) { ddlDisplayUserType.SelectedValue = "All"; } else if (!GetFormIncStaffLogins() && GetFormIncPatientLogins()) { ddlDisplayUserType.SelectedValue = "Patients Only"; } else if (GetFormIncStaffLogins() && !GetFormIncPatientLogins()) { ddlDisplayUserType.SelectedValue = "Staff Only"; } DateTime fromDate = IsValidDate(txtStartDate.Text) ? GetDate(txtStartDate.Text) : DateTime.Now.Date.AddDays(-7); DateTime toDate = IsValidDate(txtEndDate.Text) ? GetDate(txtEndDate.Text).AddDays(1) : DateTime.Now.Date.AddDays(1); UserView userView = UserView.GetInstance(); int numCurrentlyLoggedIn = 0; Hashtable distinctLoggedInToday = new Hashtable(); DataTable dt = UserLoginDB.GetDataTable(userView.IsStakeholder, fromDate, toDate, GetFormIncStaffLogins(), GetFormIncPatientLogins(), IsValidFormStaffID() ? GetFormStaffID() : -1); dt.Columns.Add("user_to_display", typeof(string)); dt.Columns.Add("user_type", typeof(string)); for (int i = 0; i < dt.Rows.Count; i++) { UserLogin userLogin = UserLoginDB.LoadAll(dt.Rows[i]); if (userLogin.Staff == null && userLogin.Patient == null) { dt.Rows[i]["user_to_display"] = userLogin.Username; dt.Rows[i]["user_type"] = ""; } else if (userLogin.Staff != null) { dt.Rows[i]["user_to_display"] = userLogin.Staff.Person.FullnameWithoutMiddlename; dt.Rows[i]["user_type"] = "Staff"; } else if (userLogin.Patient != null) { dt.Rows[i]["user_to_display"] = userLogin.Patient.Person.FullnameWithoutMiddlename; dt.Rows[i]["user_type"] = "Patient"; } if (userLogin.Staff != null && userLogin.Staff.StaffID > 0 && !userLogin.IsLoggedOff) { numCurrentlyLoggedIn++; } if (userLogin.Staff != null && userLogin.Staff.StaffID > 0 && userLogin.LastAccessTime >= DateTime.Today) { distinctLoggedInToday[userLogin.Staff.StaffID] = 1; } } Session["userlogin_data"] = dt; lblNumCurrentlyLoggedIn.Text = "(current: " + numCurrentlyLoggedIn + ") " + "<font color=\"#A0A0A0\">(distinct today: " + distinctLoggedInToday.Keys.Count + ") </font>"; if (!userView.IsStakeholder) { img_log_user_off_icon.Visible = false; foreach (DataControlField col in GrdUserLogin.Columns) { if (col.HeaderText.ToLower().Trim() == "log off") { col.Visible = false; } } } if (dt.Rows.Count > 0) { if (IsPostBack && Session["userlogin_sortexpression"] != null && Session["userlogin_sortexpression"].ToString().Length > 0) { DataView dataView = new DataView(dt); dataView.Sort = Session["userlogin_sortexpression"].ToString(); GrdUserLogin.DataSource = dataView; } else { GrdUserLogin.DataSource = dt; } try { GrdUserLogin.DataBind(); GrdUserLogin.PagerSettings.FirstPageText = "1"; GrdUserLogin.PagerSettings.LastPageText = GrdUserLogin.PageCount.ToString(); GrdUserLogin.DataBind(); FillCountries(); } catch (Exception ex) { SetErrorMessage(ex.ToString()); } } else { dt.Rows.Add(dt.NewRow()); GrdUserLogin.DataSource = dt; GrdUserLogin.DataBind(); int TotalColumns = GrdUserLogin.Rows[0].Cells.Count; GrdUserLogin.Rows[0].Cells.Clear(); GrdUserLogin.Rows[0].Cells.Add(new TableCell()); GrdUserLogin.Rows[0].Cells[0].ColumnSpan = TotalColumns; GrdUserLogin.Rows[0].Cells[0].Text = "No Record Found"; } }