private void FillMessageDataGrid() { try { ServiceAccess serviceLoader = ServiceAccess.GetInstance(); RegistrationService.LoginInfo regInfo = (RegistrationService.LoginInfo)Session["loginInfo"]; MessageService messageService = serviceLoader.GetMessage(); int userId; if (IsAgentRole) { userId = regInfo.UserId; } else { userId = Convert.ToInt32(ListOfAgentsWebUserControl1.SelectedValue); } MessageInfo[] dataSource = messageService.GetCustomMessageList(userId); if (dataSource.Length == 0) { NoRecordsTable.Visible = true; } else { NoRecordsTable.Visible = false; MessageDataGrid.DataSource = dataSource; ViewState["dataSource"] = MessageDataGrid.DataSource; MessageDataGrid.DataBind(); } } catch (Exception ex) { ErrorMessageLabel.Text = "Unable to load the message list."; ErrorMessageLabel.Visible = true; log.Error("Unknown Error", ex); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Session["SelectedMessage"] = null; ServiceAccess serviceLoader = ServiceAccess.GetInstance(); RegistrationService.LoginInfo regInfo = (RegistrationService.LoginInfo)Session["loginInfo"]; if (regInfo.Role != RegistrationService.UserRole.Agent) { AgentsPanel.Visible = true; AgentRFValidator.ControlToValidate = "ListOfAgentsWebUserControl1"; AgentRFValidator.Enabled = true; try { ListOfAgentsWebUserControl1.AutoPostBack = false; ListOfAgentsWebUserControl1.FillDropDown(); } catch (Exception ex) { ErrorMessageLabel.Text = "Unable to load the agents list"; ErrorMessageLabel.Visible = true; log.Error("Unknown error", ex); } } MessageService messageService = serviceLoader.GetMessage(); bool isAgent = (regInfo.Role == RegistrationService.UserRole.Agent); try { DesignService designService = ServiceAccess.GetInstance().GetDesign(); MessageInfo[] dataSource = null; string gender = string.Empty; string onDesignName = string.Empty; if (isAgent) { DesignInfo[] designs = designService.GetList(regInfo.UserId); if (designs != null) { foreach (DesignInfo designInfo in designs) { if (designInfo != null && designInfo.DesignId > 0 && designInfo.Status.Name.ToLower() == "approved") { DesignInfo allDesignInfo = designService.Get(designInfo.DesignId); if (allDesignInfo.Gender != string.Empty && allDesignInfo.OnDesignName != string.Empty) { gender = allDesignInfo.Gender; onDesignName = allDesignInfo.OnDesignName; break; } } } } } dataSource = messageService.GetStandardMessageList(isAgent, gender, onDesignName); if (dataSource == null || dataSource.Length == 0) { NoRecordsTable.Visible = true; } else { NoRecordsTable.Visible = false; MessageDataGrid.DataSource = dataSource; ViewState["dataSource"] = MessageDataGrid.DataSource; MessageDataGrid.DataBind(); } } catch (Exception ex) { ErrorMessageLabel.Text = "Unable to load the messages"; ErrorMessageLabel.Visible = true; log.Error("Unknown error", ex); } if (!IsAgentRole) { MessageDataGrid.Columns[0].Visible = true; AgentRFValidator.Enabled = true; AddStdMessagePanel.Visible = true; } else { MessageDataGrid.Columns[0].Visible = false; } } }
protected void MessageDataGrid_PageIndexChanged(object source, DataGridPageChangedEventArgs e) { MessageDataGrid.CurrentPageIndex = e.NewPageIndex; MessageDataGrid.DataSource = (MessageInfo[])ViewState["dataSource"]; MessageDataGrid.DataBind(); }