internal static List <FilterRule> getTableFilters(string name) { string[] ary = name.Split(','); string conn = ""; string tbName = name; if (ary.Length > 1) { conn = ary[0]; tbName = ary[1]; } DatabaseAdmin dba = DatabaseAdmin.getInstance(conn); TableDef tbDef = dba.getTableDef(tbName); List <FilterRule> ret = new List <FilterRule>(); foreach (FieldDef fldDef in tbDef.FieldDefs) { FilterRule fr = new FilterRule(); fr.field = fldDef.Name; ret.Add(fr); } return(ret); }
private void setQueryParameters(CommandSchema cmdSchema, DbCommand cmd) { DatabaseAdmin dbAdmin = DatabaseAdmin.getInstance(_schema.ConnectionName); foreach (ParameterSchema p in cmdSchema.QueryParams) { switch (p.Direction) { case ParameterDirection.Input: case ParameterDirection.InputOutput: string value = p.DefaultValue; if (Request.QueryString.AllKeys.Contains(p.Id)) { value = Request[p.Id]; } if (!string.IsNullOrEmpty(value) && value.StartsWith("(") && value.EndsWith(")")) { value = null; object obj = Umc.invoke(value, null).ToString(); if (obj != null) { value = obj.ToString(); } } break; } } }
public static DbCommand getSchemaCommand(DatabaseAdmin dba, CommandSchema schemaCommand) { Database db = dba.Database; if (schemaCommand == null || string.IsNullOrEmpty(schemaCommand.CommandText)) { throw new Exception(Lang.NotAssignedSQL); } CommandType cmdType = (CommandType)schemaCommand.CommandType; DbCommand cmd = null; switch (cmdType) { case CommandType.StoredProcedure: { cmd = db.GetStoredProcCommand(schemaCommand.CommandText); break; } default: { cmd = db.GetSqlStringCommand(schemaCommand.CommandText); break; } } return(cmd); }
internal static List <DataListColumn> getTableColumns(DatabaseAdmin dba, string tableName) { List <DataListColumn> ret = new List <DataListColumn>(); TableDef tableDef = dba.getTableDef(tableName); int i = 0; foreach (FieldDef field in tableDef.FieldDefs) { i++; if (i > DataSourceConst.MaxCol) { break; } DataListColumn col = new DataListColumn(); col.field = field.Name; col.title = field.Alias; if (string.IsNullOrEmpty(col.title)) { col.title = field.Name; } col.resizable = true; col.sortable = true; ret.Add(col); } return(ret); }
public bool updateUser(User user, string userId) { // if (!(Security.user.Id.Equals(user.Id) && Security.IsAdminRoleUser)) // throw new XUserException("无权操作"); if (existsUser(user.Id) && user.Id != userId) { throw new XUserException("用户" + user.Id + "已经存在,法将用户" + userId + "改为" + user.Id); } DatabaseAdmin dba = SecuritySettings.getDBA(); DbCommand cmd = dba.getSqlStringCommand(SecurityDataScripts.UpdateUserSql); dba.addInParameter(cmd, "@Id", DbType.String, user.Id); dba.addInParameter(cmd, "@DisplayName", DbType.String, user.DisplayName); dba.addInParameter(cmd, "@IsDisable", DbType.Boolean, user.IsDisable); dba.addInParameter(cmd, "@IsActive", DbType.Boolean, user.IsActive); dba.addInParameter(cmd, "@Email", DbType.AnsiString, user.Email); dba.addInParameter(cmd, "@Mobile", DbType.AnsiString, user.Mobile); dba.addInParameter(cmd, "@GroupId", DbType.AnsiString, user.GroupId); dba.addInParameter(cmd, "@oldId", DbType.AnsiString, userId); bool ret = dba.execNonQuery(cmd) != 0; if (!ret) { throw new XUserException(userId + "用户未发现"); } return(ret); }
public static DataSourceSchema BuildTableSchema(string connName, string tableName) { string defCon = ConnectionAdmin.getDefaultConnName(); if (!string.IsNullOrEmpty(connName) && connName.Equals(defCon, StringComparison.OrdinalIgnoreCase)) { connName = null; } DatabaseAdmin dba = DatabaseAdmin.getInstance(connName); DataSourceSchema ret = new DataSourceSchema(); ret.ConnectionName = connName; ret.TableName = tableName; ret.SelectCommand = new CommandSchema(); ret.SelectCommand.CommandText = tableName; ret.SelectCommand.CommandType = CommandType.TableDirect; BuildFields(ret); ret.PrimaryKeys = dba.GetPrimaryKeys(tableName); BuildSchemaCommand(ret); //string dsId = tableName; //if (!string.IsNullOrEmpty(connName)) // dsId = connName + "." + dsId; // DataSourceSchemaContainer.Instance().AddItem(dsId, ret); return(ret); }
private List <TreeNode> drillMembersComm(List <string> memberPath) { if (levels == null || levels.Count < 1) { throw new NoDefineLevelException(); } StringBuilder sbSql = new StringBuilder(); int memberPathCount; StringBuilder sbWhere = getDrillWhere(memberPath, out memberPathCount); if (memberPathCount > levels.Count - 1) { throw new OlapLevelOverException(); } string drillField = levels[memberPathCount].column; sbSql.Append(" Select "); sbSql.Append(drillField); sbSql.Append(" From "); sbSql.Append(table.name); if (sbWhere.Length > 0) { sbSql.Append(" Where "); sbSql.Append(sbWhere); } sbSql.Append(" Group By "); sbSql.Append(drillField); DatabaseAdmin dba = DatabaseAdmin.getInstance(_table.connection); DataTable tb = dba.executeTable(sbSql.ToString()); List <TreeNode> nodes = new List <TreeNode>(); foreach (DataRow row in tb.Rows) { TreeNode node = new TreeNode(); node.text = row[drillField].ToString(); node.attr.Add("memberField", drillField); if (memberPathCount + 1 < levels.Count) { List <string> subMembers = new List <string>(); if (memberPath != null && memberPath.Count > 0) { subMembers = new List <string>(memberPath); } subMembers.Add(node.text); node.children = drillMembers(subMembers); } nodes.Add(node); } return(nodes); }
public override bool Check(string value) { //XDatabaseFactory dbfact = XDatabaseFactory.Instance; DatabaseAdmin db = DatabaseAdmin.getInstance(connect); object o = null; try { o = db.Database.ExecuteScalar("if " + expression + " select 1 else select 0"); } catch (Exception e) { throw new XException("表达式校验器在执行[" + expression + "]时发生错误," + e.Message); } if (o is bool) { return((bool)o); } string s = o.ToString(); if (string.IsNullOrEmpty(s)) { return(false); } return(s != "0"); }
public bool updateRole(Role role, string roleId) { if (String.IsNullOrEmpty(roleId)) { throw new Exception("角色Id不能为空"); } if (existsRole(role.Id) && !roleId.Equals(role.Id, StringComparison.OrdinalIgnoreCase)) { throw new Exception("角色Id" + role.Id + "已经存在,不能将" + roleId + "修改成" + role.Id); } DatabaseAdmin dba = SecuritySettings.getDBA(); DbCommand cmd = dba.getSqlStringCommand(SecurityDataScripts.UpdateRoleSql); dba.addInParameter(cmd, "@Id", DbType.String, role.Id); dba.addInParameter(cmd, "@DisplayName", DbType.String, role.DisplayName); dba.addInParameter(cmd, "@Remark", DbType.String, role.Remark); dba.addInParameter(cmd, "@oldId", DbType.String, roleId); bool ret = dba.execNonQuery(cmd) != 0; if (!ret) { throw new XUserException("角色修改失败,角色" + roleId + "不存在"); } return(ret); }
public void refreshFields() { DatabaseAdmin dba = DatabaseAdmin.getInstance(_schema.ConnectionName); DataSet ds = getDataSet(); if (ds == null || ds.Tables.Count < 1) { return; } foreach (DataColumn col in ds.Tables[0].Columns) { FieldSchema fs = _schema.Fields.FindItem(col.ColumnName); if (fs == null) { fs = new FieldSchema(); fs.Id = col.ColumnName; fs.DataType = dba.getDbType(col.DataType); _schema.Fields.Add(fs); } } if (DataSourceSchemaContainer.Instance().Contains(_name)) { DataSourceSchemaContainer.Instance().UpdateItem(_name, _schema); } }
public adminDashboard() { InitializeComponent(); orderDB = new OrderRepo(); adminDB = new DatabaseAdmin(); dataGridView1.DataSource = adminDB.table(); }
public static EasyUiGridData createGrid(string connName, string tableName) { DatabaseAdmin dba = DatabaseAdmin.getInstance(connName); TableDef tableDef = dba.getTableDef(tableName); string title = string.IsNullOrEmpty(tableDef.Title)?tableName:tableDef.Title; return(EUGridUtils.getGrid(connName, title, tableDef.FieldDefs)); }
public bool deleteUser(string userId) { DatabaseAdmin dba = SecuritySettings.getDBA(); DbCommand cmd = dba.getSqlStringCommand(SecurityDataScripts.DeleteUserSQL); dba.addInParameter(cmd, "@user_id", DbType.String, userId); return(dba.execNonQuery(cmd) != 0); }
public static void deleteUserRole(string userId, string roleId) { DatabaseAdmin dba = SecuritySettings.getDBA(); DbCommand cmd = dba.getSqlStringCommand(SecurityDataScripts.deleteUserRoleSQL); dba.addInParameter(cmd, "@roleId", DbType.String, roleId); dba.addInParameter(cmd, "@userId", DbType.String, userId); dba.execNonQuery(cmd); }
public EasyUiGridData drillTableToGrid(List <string> parentMembers) { DatabaseAdmin dba = DatabaseAdmin.getInstance(table.connection); TableDef tbf = dba.getTableDef(table.name); string title = string.IsNullOrEmpty(tbf.Title) ? table.name : tbf.Title; EasyUiGridData ret = EUGridUtils.getGrid(table.connection, title, tbf.FieldDefs); return(ret); }
public override bool Check(string value) { //XDatabaseFactory dbfact = XDatabaseFactory.Instance; DatabaseAdmin dba = DatabaseAdmin.getInstance(connectString); object o = dba.Database.ExecuteScalar(""); return(o != null); // db.ExecuteTable() }
private static void BuildFields(DataSourceSchema schema) { DsAdapterCustomer dsa = new DsAdapterCustomer(schema); DataSet ds = dsa.getDataSet(); DataTable netTable = ds.Tables[0]; // schema.Fields.Clear(); SchemaList <FieldSchema> tmpFieldSchema = new SchemaList <FieldSchema>(); //da.FillSchema(netTable, SchemaType.Source); // schema.PrimaryKeys = new List<string>(); // foreach (DataColumn col in netTable.PrimaryKey) // { // schema.PrimaryKeys.Add(col.ColumnName); // } foreach (DataColumn col in netTable.Columns) { FieldSchema field = new FieldSchema(); field.Id = col.ColumnName; field.Title = col.Caption; if (col.ExtendedProperties.ContainsKey(DataSourceConst.ExProDescription)) { if (col.ExtendedProperties[DataSourceConst.ExProDescription] != null) { field.Description = col.ExtendedProperties[DataSourceConst.ExProDescription].ToString(); } } field.ReadOnly = col.ReadOnly; field.ReadOnly = col.AutoIncrement; if (netTable.PrimaryKey.Contains(col)) { field.IsKey = true; } if (col.ExtendedProperties.ContainsKey(DataSourceConst.ExProDbType)) { field.DataType = (DbType)col.ExtendedProperties[DataSourceConst.ExProDbType]; } else { field.DataType = DatabaseAdmin.getInstance().getDbType(col.DataType); } // schema.Fields.Add(field); if (schema.Fields.FindItem(field.Id) == null) { schema.Fields.Add(field); } if (tmpFieldSchema.FindItem(field.Id) == null) { tmpFieldSchema.Add(field); } } }
public bool existsUser(string userId) { DatabaseAdmin dba = SecuritySettings.getDBA(); DbCommand cmd = dba.getSqlStringCommand(SecurityDataScripts.CheckUserExistsSQL); dba.addInParameter(cmd, "@user_id", DbType.String, userId); object o = dba.executeScalar(cmd); return(o != null); }
public static string getPrimaryKey(string connName, string tableName) { if (string.IsNullOrEmpty(tableName)) { return(""); } DatabaseAdmin dba = DatabaseAdmin.getInstance(connName); TableDef tbDef = dba.getTableDef(tableName); return(tbDef.MainKeys[0].Name); }
public static List <string> getConstraintNames(string connName, string tableName) { DatabaseAdmin da = DatabaseAdmin.getInstance(connName); DataTable dt = da.getConstraintTable(tableName); List <string> ret = new List <string>(); foreach (DataRow row in dt.Rows) { ret.Add(row[0].ToString()); } return(ret); }
/// <summary> /// 设置角色的对象权限 /// </summary> /// <param name="roleId"></param> /// <param name="objectId"></param> /// <param name="permission"></param> public static void setPermission(string roleId, string objectId, PermissionTypes permission) { PermissionTypes oldPerm = getRoleObjectPermission(roleId, objectId); oldPerm = oldPerm | permission; DatabaseAdmin dba = SecuritySettings.getDBA(); DbCommand cmd = dba.getSqlStringCommand(SecurityDataScripts.SetRoleObjectPermissionSql); dba.addInParameter(cmd, "@roleId", DbType.String, roleId); dba.addInParameter(cmd, "@objectId", DbType.String, objectId); dba.addInParameter(cmd, "@permission", DbType.Int32, oldPerm); dba.execNonQuery(cmd); //for(PermissionTypes }
public void appendUserRole(string userId, string roleId) { DatabaseAdmin dba = SecuritySettings.getDBA(); DbCommand cmd = dba.getSqlStringCommand(SecurityDataScripts.CheckUserRolesSQl); dba.addInParameter(cmd, "@roleId", DbType.String, roleId); dba.addInParameter(cmd, "@userId", DbType.String, userId); object c = dba.executeScalar(cmd); if ((int)c < 1) { cmd = dba.getSqlStringCommand(SecurityDataScripts.AppendUserRolesSQl); dba.addInParameter(cmd, "@roleId", DbType.String, roleId); dba.addInParameter(cmd, "@userId", DbType.String, userId); } dba.execNonQuery(cmd); }
private List <ListDataRow> getSubTableRows(Dictionary <string, string> pks, SubTableSchema subSchema) { DatabaseAdmin dba = DatabaseAdmin.getInstance(); DataSource subDs = new DataSource(subSchema.Name); DataSourceSchema dss = subDs.getSchema(); if (dss.SelectCommand.CommandType != CommandType.TableDirect) { throw new XException(string.Format(Lang.SubTableSelCommandTypeOnlyIsTable, subSchema.Name)); } StringBuilder sb = new StringBuilder("select * from "); sb.Append(dss.SelectCommand.CommandText); sb.Append(" "); sb.Append(" where "); Hashtable ps = new Hashtable(); for (int i = 0; i < subSchema.Fks.Count; i++) { string fk = subSchema.Fks[i]; string pk = _schema.PrimaryKeys[i]; sb.Append(fk); sb.Append("=@"); sb.Append(pk); sb.Append(" and "); ps.Add("@" + pk, pks[pk].ToString()); } sb.Remove(sb.Length - 5, 5); DbCommand cmd = dba.getSqlStringCommand(sb.ToString()); foreach (string key in ps.Keys) { dba.addInParameter(cmd, key, DbType.String, ps[key]); } DataTable tb = dba.executeTable(cmd); List <ListDataRow> rows = new List <ListDataRow>(); foreach (DataRow row in tb.Rows) { rows.Add(DataSourceComm.readRow(tb, dss, row)); } return(rows); }
public static Dictionary <string, string> getTables(string connName) { Dictionary <string, string> ret = new Dictionary <string, string>(); DatabaseAdmin dba = DatabaseAdmin.getInstance(connName); List <string> tables = dba.getTableNames(); foreach (string table in tables) { string text = dba.getTableTitle(table); if (string.IsNullOrEmpty(text)) { text = table; } ret.Add(table, text); } return(ret); }
public bool repassword(string password1, string password2) { if (!Security.IsLogin) { throw new XUserException("请先登录"); } if (password1.Equals(password2)) { throw new XUserException("两次输入的密码不一致"); } DatabaseAdmin dba = SecuritySettings.getDBA(); DbCommand cmd = dba.getSqlStringCommand(SecurityDataScripts.InsertUserSql); dba.addInParameter(cmd, "@Id", DbType.String, Security.user.Id); return(dba.execNonQuery(cmd) != 0); }
public string GetInsertCommand() { string tableName = GetFrom(); string insertCmd = "INSERT INTO " + tableName + " ("; string values = ""; DatabaseAdmin db = DatabaseAdmin.getInstance(schema.ConnectionName); foreach (FieldSchema fldsch in schema.Fields) { if (!fldsch.ReadOnly && !db.isIdentityField(tableName, fldsch.Id) && !db.isRowGuidField(tableName, fldsch.Id)) { insertCmd += " [" + fldsch.Id + "]" + XTableSchemaConst.FieldSplitor; values += "@" + fldsch.Id + XTableSchemaConst.FieldSplitor; } } values = values.Remove(values.LastIndexOf(XTableSchemaConst.FieldSplitor)); insertCmd = insertCmd.Remove(insertCmd.Length - 1); insertCmd += ")"; insertCmd += " VALUES (" + values + ")"; if (schema.PrimaryKeys != null && schema.PrimaryKeys.Count > 0) { List <string> pks = schema.PrimaryKeys; string id = ""; foreach (string fieldName in pks) { if (db.isIdentityField(tableName, fieldName)) { id = fieldName; break; } } if (!string.IsNullOrEmpty(id)) { insertCmd += ";SELECT * FROM " + tableName + " WHERE [" + id + "]=SCOPE_IDENTITY()"; } } // db.Close(); return(insertCmd); }
public static PermissionTypes getRoleObjectPermission(string roleId, string objectId) { DatabaseAdmin dba = SecuritySettings.getDBA(); DbCommand cmd = dba.getSqlStringCommand(SecurityDataScripts.RoleObjectPermissionSql); dba.addInParameter(cmd, "@roleId", DbType.String, roleId); dba.addInParameter(cmd, "@objectId", DbType.String, objectId); object ret = dba.executeScalar(cmd); if (ret != null && ret is int) { return((PermissionTypes)ret); } else { return(PermissionTypes.None); } }
public bool addUser(User user) { if (String.IsNullOrEmpty(user.Id) || !(UserInfoExpress.isEmail(user.Id) || UserInfoExpress.isMobile(user.Id))) { throw new XUserException("新用户注册,必须填写手机号或电子邮件!"); } if (existsUser(user.Id)) { throw new XUserException("新用户注册,用户" + user.Id + "已经被别人使用!"); } user.Password = Crypto.Encrypt(user.Password); if (UserInfoExpress.isEmail(user.Id) && string.IsNullOrEmpty(user.Email)) { user.Email = user.Id; } if (UserInfoExpress.isMobile(user.Id) && string.IsNullOrEmpty(user.Mobile)) { user.Mobile = user.Id; } DatabaseAdmin dba = SecuritySettings.getDBA(); DbCommand cmd = dba.getSqlStringCommand(SecurityDataScripts.InsertUserSql); dba.addInParameter(cmd, "@Id", DbType.String, user.Id); dba.addInParameter(cmd, "@DisplayName", DbType.String, user.DisplayName); dba.addInParameter(cmd, "@Password", DbType.String, user.Password); dba.addInParameter(cmd, "@create_date", DbType.DateTime, DateTime.Now); dba.addInParameter(cmd, "@IsDisable", DbType.Boolean, user.IsDisable); dba.addInParameter(cmd, "@IsActive", DbType.Boolean, user.IsActive); dba.addInParameter(cmd, "@Email", DbType.AnsiString, user.Email); dba.addInParameter(cmd, "@Mobile", DbType.AnsiString, user.Mobile); dba.addInParameter(cmd, "@GroupId", DbType.AnsiString, user.GroupId); bool ret = dba.execNonQuery(cmd) != 0; if (!ret) { throw new XUserException("用户添加失败"); } return(ret); }
/// <summary> /// 用权限类型设置角色的对象权限 /// </summary> /// <param name="roleId">角色ID</param> /// <param name="objectId">对象ID</param> /// <param name="type">权限类型字符串:None/Read/Write/Execute/DoAll</param> /// <param name="enable"></param> public static void setPermission(string roleId, string objectId, string type, bool enable) { PermissionTypes permission = (PermissionTypes)Enum.Parse(typeof(PermissionTypes), type); PermissionTypes oldPerm = getRoleObjectPermission(roleId, objectId); oldPerm = oldPerm | permission; if (!enable) { oldPerm = oldPerm ^ permission; } DatabaseAdmin dba = SecuritySettings.getDBA(); DbCommand cmd = dba.getSqlStringCommand(SecurityDataScripts.SetRoleObjectPermissionSql); dba.addInParameter(cmd, "@roleId", DbType.String, roleId); dba.addInParameter(cmd, "@objectId", DbType.String, objectId); dba.addInParameter(cmd, "@permission", DbType.Int32, oldPerm); dba.execNonQuery(cmd); }
public static Dictionary <string, string> getFields(string connName, string tableName) { Dictionary <string, string> ret = new Dictionary <string, string>(); if (string.IsNullOrEmpty(tableName)) { return(ret); } DatabaseAdmin dba = DatabaseAdmin.getInstance(connName); TableDef tbDef = dba.getTableDef(tableName); ret.Add("", ""); foreach (FieldDef field in tbDef.FieldDefs) { string title = string.IsNullOrEmpty(field.Title) ? field.Name : field.Title; ret.Add(field.Name, title); } return(ret); }