void InitializeDataSources() { projectId = (long)HttpContext.Current.Items["ProjectId"]; project = Project.Find(projectId); //Note - Since we are not using weak references yet, records are cached in memory. //a call to refresh ensures we are getting the latest from the DB. project.Refresh(); UsersDataGrid.DataSource = project.Users; UsersDataGrid.DataBind(); ProjectName.Text = project.Title; }
protected void ApplyUsersFilter_Click(object sender, EventArgs e) { try { int userTypeId = Convert.ToInt32(UsersFilterTable_TypeDropDownList.SelectedValue); int userRoleId = Convert.ToInt32(UsersFilterTable_RoleDropDownList.SelectedValue); int selectedDealerId = Convert.ToInt32(UsersFilterTable_DealerDropDownList.SelectedValue); string connectionString = ConfigurationSettings.AppSettings["fleetnetbaseConnectionString"]; DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]); int orgId = Convert.ToInt32(Session["CURRENT_ORG_ID"]); List <int> usersIds = new List <int>(); dataBlock.OpenConnection(); if (userTypeId != -1) { usersIds.AddRange(dataBlock.usersTable.Get_AllUsersId(orgId, userTypeId)); } else { usersIds.AddRange(dataBlock.usersTable.Get_AllUsersId(orgId, dataBlock.usersTable.DriverUserTypeId)); usersIds.AddRange(dataBlock.usersTable.Get_AllUsersId(orgId, dataBlock.usersTable.AdministratorUserTypeId)); usersIds.AddRange(dataBlock.usersTable.Get_AllUsersId(orgId, dataBlock.usersTable.ManagerUserTypeId)); } Session["UsersTab_UserControl_UsersIds"] = usersIds; DataTable dt = new DataTable(); DataRow dr; dt.Columns.Add(new DataColumn("DEALER", typeof(string))); dt.Columns.Add(new DataColumn("SURNAME", typeof(string))); dt.Columns.Add(new DataColumn("NAME", typeof(string))); dt.Columns.Add(new DataColumn("PAtronimic", typeof(string))); dt.Columns.Add(new DataColumn("LOGIN", typeof(string))); dt.Columns.Add(new DataColumn("REG_DATE", typeof(string))); dt.Columns.Add(new DataColumn("ROLE", typeof(string))); dt.Columns.Add(new DataColumn("USER_TYPE", typeof(string))); dt.Columns.Add(new DataColumn("STATE", typeof(string))); int userInfoId = 0; //int dealerId; string dealerName = ""; DateTime date = new DateTime(); int dealerId; foreach (int userId in usersIds) { if (userRoleId != -1) { if (dataBlock.usersTable.GetUserRoleId(userId) != userRoleId) { continue; } } /*if (userTypeId != -1) * if (dataBlock.usersTable.Get_UserTypeId(userId) != userTypeId) * continue;*/ if (selectedDealerId != -1) { userInfoId = dataBlock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_DealerId); if (int.TryParse(dataBlock.usersTable.GetUserInfoValue(userId, userInfoId), out dealerId)) { if (selectedDealerId != dealerId) { continue; } else { dealerName = dataBlock.organizationTable.GetOrganizationName(dealerId); } } else { continue; } } else { userInfoId = dataBlock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_DealerId); if (int.TryParse(dataBlock.usersTable.GetUserInfoValue(userId, userInfoId), out dealerId)) { dealerName = dataBlock.organizationTable.GetOrganizationName(dealerId); } else { dealerName = "???"; } if (dealerName.Trim() == "") { dealerName = "???"; } } dr = dt.NewRow(); //DEALER dr["DEALER"] = dealerName; //SURNAME userInfoId = dataBlock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_Surname); dr["SURNAME"] = dataBlock.usersTable.GetUserInfoValue(userId, userInfoId); //NAME userInfoId = dataBlock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_Name); dr["NAME"] = dataBlock.usersTable.GetUserInfoValue(userId, userInfoId); //Patronimic userInfoId = dataBlock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_Patronimic); dr["PAtronimic"] = dataBlock.usersTable.GetUserInfoValue(userId, userInfoId); //LOGIN dr["LOGIN"] = dataBlock.usersTable.Get_UserName(userId); //REG_DATE if (DateTime.TryParse(dataBlock.usersTable.GetUserInfoValue(userId, DataBaseReference.UserInfo_RegDate), out date)) { dr["REG_DATE"] = date.ToLongDateString() + " " + date.ToShortTimeString(); } //ROLE dr["ROLE"] = dataBlock.usersTable.Get_UserRoleName(userId); //USER_TYPE dr["USER_TYPE"] = dataBlock.usersTable.Get_UserTypeStr(userId); //STATE date = dataBlock.usersTable.Get_TimeConnect(userId); if (date == (new DateTime())) { dr["STATE"] = "Вход не производился"; } else { dr["STATE"] = "Последний вход " + date.ToLongDateString() + " " + date.ToShortTimeString(); } // dt.Rows.Add(dr); } dataBlock.CloseConnection(); UsersDataGrid.DataSource = dt; UsersDataGrid.DataBind(); UsersDataGridUpdatePanel.Update(); } catch (Exception ex) { RaiseException(ex); } }
public void LoadUsersTable() { string connectionString = ConfigurationSettings.AppSettings["fleetnetbaseConnectionString"]; DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]); int orgId = Convert.ToInt32(Session["CURRENT_ORG_ID"]); List <int> usersIds = new List <int>(); List <UserFromTable> userFromTableList = new List <UserFromTable>(); dataBlock.OpenConnection(); usersIds.AddRange(dataBlock.usersTable.Get_AllUsersId(orgId, dataBlock.usersTable.DriverUserTypeId)); usersIds.AddRange(dataBlock.usersTable.Get_AllUsersId(orgId, dataBlock.usersTable.AdministratorUserTypeId)); usersIds.AddRange(dataBlock.usersTable.Get_AllUsersId(orgId, dataBlock.usersTable.ManagerUserTypeId)); usersIds.AddRange(dataBlock.usersTable.Get_AllUsersId(orgId, dataBlock.usersTable.DealerUserTypeId)); foreach (int id in usersIds) { userFromTableList.Add(new UserFromTable().FillWithInfo(id, dataBlock.usersTable)); } Session["UsersTab_UserControl_UsersIds"] = usersIds; DataTable dt = new DataTable(); DataRow dr; dt.Columns.Add(new DataColumn("DEALER", typeof(string))); dt.Columns.Add(new DataColumn("SURNAME", typeof(string))); dt.Columns.Add(new DataColumn("NAME", typeof(string))); dt.Columns.Add(new DataColumn("PAtronimic", typeof(string))); dt.Columns.Add(new DataColumn("LOGIN", typeof(string))); dt.Columns.Add(new DataColumn("REG_DATE", typeof(string))); dt.Columns.Add(new DataColumn("ROLE", typeof(string))); dt.Columns.Add(new DataColumn("USER_TYPE", typeof(string))); dt.Columns.Add(new DataColumn("STATE", typeof(string))); int userInfoId = 0; int dealerId; string dealerName = ""; DateTime date = new DateTime(); foreach (UserFromTable users in userFromTableList) { dr = dt.NewRow(); //DEALER userInfoId = dataBlock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_DealerId); if (int.TryParse(dataBlock.usersTable.GetUserInfoValue(users.id, userInfoId), out dealerId)) { dealerName = dataBlock.organizationTable.GetOrganizationName(dealerId); } else { dealerName = "???"; } if (dealerName.Trim() == "") { dealerName = "???"; } dr["DEALER"] = dealerName; //SURNAME userInfoId = dataBlock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_Surname); dr["SURNAME"] = dataBlock.usersTable.GetUserInfoValue(users.id, userInfoId); //NAME userInfoId = dataBlock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_Name); dr["NAME"] = dataBlock.usersTable.GetUserInfoValue(users.id, userInfoId); //Patronimic userInfoId = dataBlock.usersTable.GetUserInfoNameId(DataBaseReference.UserInfo_Patronimic); dr["PAtronimic"] = dataBlock.usersTable.GetUserInfoValue(users.id, userInfoId); //LOGIN dr["LOGIN"] = users.name; //REG_DATE if (DateTime.TryParse(dataBlock.usersTable.GetUserInfoValue(users.id, DataBaseReference.UserInfo_RegDate), out date)) { dr["REG_DATE"] = date.ToLongDateString() + " " + date.ToShortTimeString(); } //ROLE dr["ROLE"] = users.userRole; //USER_TYPE dr["USER_TYPE"] = users.userType; //STATE if (users.timeConnection == (new DateTime())) { dr["STATE"] = "Вход не производился"; } else { dr["STATE"] = "Последний вход " + users.timeConnection.ToLongDateString() + " " + users.timeConnection.ToShortTimeString(); } // dt.Rows.Add(dr); } dataBlock.CloseConnection(); UsersDataGrid.DataSource = dt; UsersDataGrid.DataBind(); }