public void setUserAuth(UserAuth userAuth) { try { SqlParameter[] parameters = { new SqlParameter("@pageName",userAuth.pageName), new SqlParameter("@userIds",userAuth.userIds) }; string sql = ""; if (GetUserAuth(userAuth.pageName) == null) { sql = "INSERT INTO [USTA].[dbo].[usta_UserAuth]([pageName],[userIds]) VALUES (@pageName,@userIds)"; } else { sql = "UPDATE [USTA].[dbo].[usta_UserAuth] SET [userIds] = @userIds WHERE [pageName] = @pageName"; } SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql, parameters); } catch (Exception ex) { MongoDBLog.LogRecord(ex); CommonUtility.RedirectUrl(); } finally { conn.Close(); } }
public UserAuth GetUserAuth(string page) { UserAuth userAuth = null; try { string sql = "SELECT [id],[pageName],[userIds] FROM [USTA].[dbo].[usta_UserAuth] WHERE pageName = @page"; SqlParameter[] parameters = { new SqlParameter("@page",page) }; SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.Text, sql, parameters); if (dr.Read()) { userAuth = new UserAuth { id = Convert.ToInt32(dr["id"].ToString().Trim()), pageName = dr["pageName"].ToString().Trim(), userIds = dr["userIds"].ToString().Trim() }; } dr.Close(); } catch (Exception ex) { MongoDBLog.LogRecord(ex); CommonUtility.RedirectUrl(); } finally { conn.Close(); } return userAuth; }
protected void dlSearchTeacher_ItemCommand(object source, DataListCommandEventArgs e) { string teacherNowSelected = this.dlSearchTeacher.DataKeys[e.Item.ItemIndex].ToString(); //取选中行教师的编号 DalOperationAboutUserAuth dalua = new DalOperationAboutUserAuth(); UserAuth userAuth = dalua.GetUserAuth(pageName); if (e.CommandName == "addAuth") { if (userAuth == null) { userAuth = new UserAuth(); userAuth.pageName = pageName; userAuth.userIds = teacherNowSelected; } else { if (userAuth.userIds == null || userAuth.userIds.Equals("")) { userAuth.userIds = teacherNowSelected; } else { userAuth.userIds = userAuth.userIds + "," + teacherNowSelected; } } } else if (e.CommandName == "removeAuth") { if (userAuth == null) return; string[] ids = userAuth.userIds.Split(','); List<string> list = new List<string>(); for (int i = 0; i < ids.Length; i++) { if (!ids[i].Equals(teacherNowSelected)) { list.Add(ids[i]); } } userAuth.userIds = string.Join(",", list.ToArray()); } dalua.setUserAuth(userAuth); Javascript.JavaScriptLocationHref("ProjectManager.aspx?fragment=1&teacherName=" + this.txtKeyword.Text.Trim(), Page); }
/// <summary> /// /// </summary> /// <param name="page"></param> /// <returns></returns> public UserAuth GetUserAuth(string page) { UserAuth userAuth = null; string sql = "SELECT [id],[pageName],[userIds] FROM [USTA].[dbo].[usta_UserAuth] WHERE pageName = @page"; SqlParameter[] parameters = { new SqlParameter("@page",page) }; SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.Text, sql, parameters); if (dr.Read()) { userAuth = new UserAuth { id=Convert.ToInt32( dr["id"].ToString().Trim()), pageName=dr["pageName"].ToString().Trim(), userIds =dr["userIds"].ToString().Trim() }; } dr.Close(); return userAuth; }
protected void dlSearchTeacher_ItemCommand(object source, DataListCommandEventArgs e) { string teacherNoSelect = this.dlSearchTeacher.DataKeys[e.Item.ItemIndex].ToString();//取选中行教师编号 UserAuth userAuth = dalua.GetUserAuth(pageName); if (e.CommandName == "addAuth") { if (userAuth == null) { userAuth = new UserAuth(); userAuth.pageName = pageName; userAuth.userIds = teacherNoSelect; } else { if (userAuth.userIds == null || userAuth.userIds.Equals("")) { userAuth.userIds = teacherNoSelect; } else { userAuth.userIds = userAuth.userIds + "," + teacherNoSelect; } } } else if (e.CommandName == "removeAuth") { if (userAuth == null) return; string[] ids = userAuth.userIds.Split(','); List<string> list = new List<string>(); for (int i = 0; i < ids.Length; i++) { if (!ids[i].Equals(teacherNoSelect)) { list.Add(ids[i]); } } userAuth.userIds = string.Join(",", list.ToArray()); } dalua.setUserAuth(userAuth); Javascript.JavaScriptLocationHref("/Administrator/NormManager.aspx?page=" + pageIndex, Page); }