//下拉框选择逻辑 private void cmbRole_SelectedIndexChanged(object sender, EventArgs e) { int roleId = cmbRole.SelectedIndex + 2; string roleName = cmbRole.Text; string oldName = string.Empty; DataGridViewCell cell = dgvAuth.CurrentCell; if (cell != null) { try { oldName = cell.Value.ToString(); cell.Value = roleName; int row = cell.RowIndex; dgvAuth.Rows[row].Cells[2].Value = roleId; Db.Authority auth = new Db.Authority(); auth.Id = Convert.ToInt32(dtAuth.Rows[row]["id"]); auth.Name = dtAuth.Rows[row]["name"].ToString(); Role role = new Role(roleId, roleName); auth.Role = role; if (auth.Update()) { LogMan.Log2Sqlite(new Log(LogLevel.Info, EventType.权限管理, "修改权限:" + dtAuth.Rows[row]["name"].ToString() + "(" + oldName + "->" + roleName + ")", DateTime.Now)); } } catch (Exception ex) { LogMan.Log2File(null, ex); } } }
/// <summary> /// Finds the specified Authority. /// </summary> /// <param name="where">The where.</param> /// <returns>Authority.</returns> public static Authority Find(string where) { Authority auth = new Authority(); Sqlite sqlite = new Sqlite(); string text = "SELECT A.id,A.name,R.id,R.name FROM auth A,role R WHERE A.roleid=R.id "; if (!string.IsNullOrEmpty(where)) { text = text + " AND A." + where; } SQLiteDataReader reader = sqlite.Query(text); while (reader.Read()) { auth.Id = reader.GetInt32(0); auth.Name = reader.GetString(1); Role role = new Role(); role.Id = reader.GetInt32(2); role.Name = reader.GetString(3); auth.Role = role; } sqlite.Close(); return(auth); }