public static IEnumerable <Models.AppFunction> GetAllParentList() { List <Models.AppFunction> rList; DataTable dt = null; try { rList = new List <Models.AppFunction>() { new Models.AppFunction() { AppFunctionId = 0, UniqueName = "system", DisplayName = "System", AppFuncLevelId = 0, ParentId = 0, SequentialNum = 0, IsDisabled = false, IsNavItem = false } }; string sql = "SELECT * FROM AppFunctions WHERE AppFuncLevelId<3 ORDER BY AppFuncLevelId,SequentialNum,DisplayName,UniqueName"; dt = DbHandler.IsMssqlConnected ? DbHandler.MSSQL.SelectDataTable(sql) : DbHandler.SQLite.SelectDataTable(sql); if ((dt?.Rows.Count ?? 0) > 0) { foreach (DataRow dr in dt.Rows) { Models.AppFunction o = Mapping(dr); if (o != null) { rList.Add(o); } } } return(rList); } finally { DbHandler.DisposeDataTable(ref dt); } }
public static Models.User LoginAuthentication(string loginname, string password) { if (string.IsNullOrWhiteSpace(loginname)) { return(null); } string hash = BAL.CommonHelper.ComputeHashFromString(password ?? ""); string sql = "SELECT * FROM Users WHERE LoginName=@LoginName AND (Hash=@Hash OR (NOT(Password IS NULL OR Password='') AND Password=@Password))"; List <Models.User> list = DbHandler.IsMssqlConnected ? GetListBySqlFromMssql(sql, new SqlParameter("@LoginName", SqlDbType.VarChar) { Value = loginname }, new SqlParameter("@Hash", SqlDbType.VarChar) { Value = hash }, new SqlParameter("@Password", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(password) }): GetListBySqlFromSQLite(sql, new System.Data.SQLite.SQLiteParameter("@LoginName", DbType.AnsiString) { Value = loginname }, new System.Data.SQLite.SQLiteParameter("@Hash", DbType.AnsiString) { Value = hash }, new System.Data.SQLite.SQLiteParameter("@Password", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(password) } ); return(list?.FirstOrDefault()); }
public static Models.AppFuncLevel GetUnit(int id) { DataTable dt = null; try { string sql = "SELECT * FROM AppFuncLevels WHERE AppFuncLevelId=@AppFuncLevelId"; dt = DbHandler.IsMssqlConnected ? DbHandler.MSSQL.SelectDataTable(sql, new SqlParameter("@AppFuncLevelId", SqlDbType.Int) { Value = id }): DbHandler.SQLite.SelectDataTable(sql, new System.Data.SQLite.SQLiteParameter("@AppFuncLevelId", System.Data.DbType.Int32) { Value = id }); if ((dt?.Rows.Count ?? 0) > 0) { return(null); } return(Mapping(dt.Rows[0])); } finally { DbHandler.DisposeDataTable(ref dt); } }
/// Return value = number of records affected. public static int UpdateRecord(Student std) { if (std == null) { return(-1); } string sql = "UPDATE Students SET StudentName=@StudentName,Age=@Age,Email=@Email WHERE StudentId=@StudentId"; SqlParameter[] array1 = new SqlParameter[] { new SqlParameter("@StudentId", SqlDbType.Int) { Value = std.StudentId }, new SqlParameter("@StudentName", SqlDbType.VarChar) { Value = std.StudentName }, new SqlParameter("@Age", SqlDbType.Int) { Value = std.Age }, new SqlParameter("@Email", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(std.Email) } }; return(DbHandler.IsMssqlConnected ? DbHandler.MSSQL.ExecuteNonQuery(sql, new SqlParameter("@StudentId", SqlDbType.Int) { Value = std.StudentId }, new SqlParameter("@StudentName", SqlDbType.VarChar) { Value = std.StudentName }, new SqlParameter("@Age", SqlDbType.Int) { Value = std.Age }, new SqlParameter("@Email", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(std.Email) }): DbHandler.SQLite.ExecuteNonQuery(sql, new System.Data.SQLite.SQLiteParameter("@StudentId", DbType.Int32) { Value = std.StudentId }, new System.Data.SQLite.SQLiteParameter("@StudentName", DbType.AnsiString) { Value = std.StudentName }, new System.Data.SQLite.SQLiteParameter("@Age", DbType.Int32) { Value = std.Age }, new System.Data.SQLite.SQLiteParameter("@Email", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(std.Email) })); }
/// Return value = the number of records affected. public static int UpdateUnit(Models.Role o) { if (o == null) { return(-1); } string sql = "UPDATE Roles SET UniqueName=@UniqueName,DisplayName=@DisplayName" + ",IsDisabled=@IsDisabled,UpdatedDt=@UpdateDt,UpdatedBy=@UpdatedBy,Description=@Description" + " WHERE RoleId=@RoleId"; return(DbHandler.IsMssqlConnected ? DbHandler.MSSQL.ExecuteNonQuery(sql, new SqlParameter("@RoleId", SqlDbType.Int) { Value = o.RoleId }, new SqlParameter("@UniqueName", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.UniqueName) }, new SqlParameter("@DisplayName", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.DisplayName) }, new SqlParameter("@IsDisabled", SqlDbType.Bit) { Value = o.IsDisabled }, new SqlParameter("@UpdateDt", SqlDbType.DateTime) { Value = o.UpdatedDt }, new SqlParameter("@UpdatedBy", SqlDbType.Int) { Value = o.UpdatedBy }, new SqlParameter("@Description", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.Description) }): DbHandler.SQLite.ExecuteNonQuery(sql, new System.Data.SQLite.SQLiteParameter("@RoleId", DbType.Int32) { Value = o.RoleId }, new System.Data.SQLite.SQLiteParameter("@UniqueName", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.UniqueName) }, new System.Data.SQLite.SQLiteParameter("@DisplayName", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.DisplayName) }, new System.Data.SQLite.SQLiteParameter("@IsDisabled", DbType.Boolean) { Value = o.IsDisabled }, new System.Data.SQLite.SQLiteParameter("@UpdateDt", DbType.DateTime) { Value = o.UpdatedDt }, new System.Data.SQLite.SQLiteParameter("@UpdatedBy", DbType.Int32) { Value = o.UpdatedBy }, new System.Data.SQLite.SQLiteParameter("@Description", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.Description) })); }
/// Return value = number of records affected. public static int UpdateUnit(Models.User o) { if (o == null) { return(-1); } string sql = "UPDATE Users SET LoginName=@LoginName,DisplayName=@DisplayName,IsDisabled=@IsDisabled,UpdatedDt=@UpdatedDt,UpdatedBy=@UpdatedBy,Description=@Description" + (o.IsUpdateHash ? ",Hash=@Hash,Password=@Password" : "") + " WHERE UserId=@UserId"; List <SqlParameter> list = null; List <System.Data.SQLite.SQLiteParameter> list2 = null; try { if (DbHandler.IsMssqlConnected) { list = new List <SqlParameter>() { new SqlParameter("@UserId", SqlDbType.Int) { Value = o.UserId }, new SqlParameter("@LoginName", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.LoginName) }, new SqlParameter("@DisplayName", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.DisplayName) }, new SqlParameter("@IsDisabled", SqlDbType.Bit) { Value = o.IsDisabled }, new SqlParameter("@UpdatedDt", SqlDbType.DateTime) { Value = o.UpdatedDt }, new SqlParameter("@UpdatedBy", SqlDbType.Int) { Value = o.UpdatedBy }, new SqlParameter("@Description", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.Description) } }; if (o.IsUpdateHash) { list.Add(new SqlParameter("@Hash", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.Hash) }); list.Add(new SqlParameter("@Password", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.Password) }); } return(DbHandler.MSSQL.ExecuteNonQuery(sql, list.ToArray())); } else { list2 = new List <System.Data.SQLite.SQLiteParameter>() { new System.Data.SQLite.SQLiteParameter("@UserId", DbType.Int32) { Value = o.UserId }, new System.Data.SQLite.SQLiteParameter("@LoginName", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.LoginName) }, new System.Data.SQLite.SQLiteParameter("@DisplayName", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.DisplayName) }, new System.Data.SQLite.SQLiteParameter("@IsDisabled", DbType.Boolean) { Value = o.IsDisabled }, new System.Data.SQLite.SQLiteParameter("@UpdatedDt", DbType.DateTime) { Value = o.UpdatedDt }, new System.Data.SQLite.SQLiteParameter("@UpdatedBy", DbType.Int32) { Value = o.UpdatedBy }, new System.Data.SQLite.SQLiteParameter("@Description", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.Description) } }; if (o.IsUpdateHash) { list2.Add(new System.Data.SQLite.SQLiteParameter("@Hash", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.Hash) }); list2.Add(new System.Data.SQLite.SQLiteParameter("@Password", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.Password) }); } return(DbHandler.SQLite.ExecuteNonQuery(sql, list2.ToArray())); } } finally { if (list != null) { list.Clear(); list = null; } if (list2 != null) { list2.Clear(); list2 = null; } } }
public static int InsertUnit(Models.User o) { if (o == null) { return(-1); } string sql = "INSERT INTO Users (LoginName,DisplayName,Hash,Password,IsDisabled,CreatedDt,CreatedBy,UpdatedDt,UpdatedBy,Description) VALUES (@LoginName,@DisplayName,@Hash,@Password,@IsDisabled,@UpdatedDt,@UpdatedBy,@UpdatedDt,@UpdatedBy,@Description)"; return(DbHandler.IsMssqlConnected ? DbHandler.MSSQL.ExecuteNonQuery(sql, new SqlParameter("@LoginName", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.LoginName) }, new SqlParameter("@DisplayName", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.DisplayName) }, new SqlParameter("@Hash", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.Hash) }, new SqlParameter("@Password", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.Password) }, new SqlParameter("@IsDisabled", SqlDbType.Bit) { Value = o.IsDisabled }, new SqlParameter("@UpdatedDt", SqlDbType.DateTime) { Value = o.UpdatedDt }, new SqlParameter("@UpdatedBy", SqlDbType.Int) { Value = o.UpdatedBy }, new SqlParameter("@Description", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.Description) }): DbHandler.SQLite.ExecuteNonQuery(sql, new System.Data.SQLite.SQLiteParameter("@LoginName", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.LoginName) }, new System.Data.SQLite.SQLiteParameter("@DisplayName", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.DisplayName) }, new System.Data.SQLite.SQLiteParameter("@Hash", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.Hash) }, new System.Data.SQLite.SQLiteParameter("@Password", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.Password) }, new System.Data.SQLite.SQLiteParameter("@IsDisabled", DbType.Boolean) { Value = o.IsDisabled }, new System.Data.SQLite.SQLiteParameter("@UpdatedDt", DbType.DateTime) { Value = o.UpdatedDt }, new System.Data.SQLite.SQLiteParameter("@UpdatedBy", DbType.Int32) { Value = o.UpdatedBy }, new System.Data.SQLite.SQLiteParameter("@Description", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.Description) })); }
public static List <Models.AppFunction> GetList(int AppFuncLevelId, int ParentId, bool?IsNavItem, bool isShort) { if (AppFuncLevelId > 3 || AppFuncLevelId < 0) { return(null); } DataTable dt = null; List <SqlParameter> listOfPara = null; List <System.Data.SQLite.SQLiteParameter> listOfPara2 = null; try { string sql; if (isShort) { sql = "SELECT AppFunctionId,UniqueName,DisplayName,ActionName,ControllerName,ParentId,AppFuncLevelId FROM AppFunctions WHERE AppFuncLevelId=@AppFuncLevelId AND ParentId=@ParentId" + (IsNavItem.HasValue ? " AND IsNavItem=@IsNavItem" : "") + " ORDER BY SequentialNum,DisplayName,UniqueName"; } else { sql = "SELECT * FROM AppFunctions WHERE AppFuncLevelId=@AppFuncLevelId AND ParentId=@ParentId" + (IsNavItem.HasValue ? " AND IsNavItem=@IsNavItem" : "") + " ORDER BY SequentialNum,DisplayName,UniqueName"; } if (DbHandler.IsMssqlConnected) { listOfPara = new List <SqlParameter>() { new SqlParameter("@AppFuncLevelId", SqlDbType.Int) { Value = AppFuncLevelId }, new SqlParameter("@ParentId", SqlDbType.Int) { Value = ParentId } }; if (IsNavItem.HasValue) { listOfPara.Add(new SqlParameter("@IsNavItem", SqlDbType.Bit) { Value = IsNavItem.GetValueOrDefault() }); } dt = DbHandler.MSSQL.SelectDataTable(sql, listOfPara.ToArray()); } else { listOfPara2 = new List <System.Data.SQLite.SQLiteParameter>() { new System.Data.SQLite.SQLiteParameter("@AppFuncLevelId", DbType.Int32) { Value = AppFuncLevelId }, new System.Data.SQLite.SQLiteParameter("@ParentId", DbType.Int32) { Value = ParentId } }; if (IsNavItem.HasValue) { listOfPara2.Add(new System.Data.SQLite.SQLiteParameter("@IsNavItem", DbType.Boolean) { Value = IsNavItem.GetValueOrDefault() }); } dt = DbHandler.SQLite.SelectDataTable(sql, listOfPara2.ToArray()); } if ((dt?.Rows.Count ?? 0) < 1) { return(null); } List <Models.AppFunction> rList = new List <Models.AppFunction>(); foreach (DataRow dr in dt.Rows) { Models.AppFunction o = Mapping(dr); if (o != null) { //o.ParentId = ParentId; //o.AppFuncLevelId = AppFuncLevelId; o.ChildList = GetList(AppFuncLevelId + 1, o.AppFunctionId, IsNavItem, isShort); rList.Add(o); } } return(rList); } finally { DbHandler.DisposeDataTable(ref dt); if (listOfPara != null) { listOfPara.Clear(); listOfPara = null; } if (listOfPara2 != null) { listOfPara2.Clear(); listOfPara2 = null; } } }
/// Return value = number of records affected. public static int UpdateUnit(Models.AppFunction o) { //if (o == null) return -1; string sql = "UPDATE AppFunctions SET UniqueName=@UniqueName,DisplayName=@DisplayName" + ",ControllerName=@ControllerName,ActionName=@ActionName,AppFuncLevelId=@AppFuncLevelId,ParentId=@ParentId,SequentialNum=@SequentialNum,IsNavItem=@IsNavItem" + ",IsDisabled=@IsDisabled,UpdatedDt=GETDATE(),UpdatedBy=@UpdatedBy,Description=@Description" + " WHERE AppFunctionId=@AppFunctionId"; return(o == null ? -1 : ( DbHandler.IsMssqlConnected ? DbHandler.MSSQL.ExecuteNonQuery(sql, new SqlParameter("@AppFunctionId", SqlDbType.Int) { Value = o.AppFunctionId }, new SqlParameter("@UniqueName", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.UniqueName) }, new SqlParameter("@DisplayName", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.DisplayName) }, new SqlParameter("@ControllerName", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.ControllerName) }, new SqlParameter("@ActionName", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.ActionName) }, new SqlParameter("@AppFuncLevelId", SqlDbType.Int) { Value = o.AppFuncLevelId }, new SqlParameter("@ParentId", SqlDbType.Int) { Value = o.ParentId }, new SqlParameter("@SequentialNum", SqlDbType.Int) { Value = o.SequentialNum }, new SqlParameter("@IsDisabled", SqlDbType.Bit) { Value = o.IsDisabled }, new SqlParameter("@IsNavItem", SqlDbType.Bit) { Value = o.IsNavItem }, new SqlParameter("@UpdatedBy", SqlDbType.Int) { Value = o.UpdatedBy }, new SqlParameter("@Description", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.Description) } ): DbHandler.SQLite.ExecuteNonQuery(sql, new System.Data.SQLite.SQLiteParameter("@AppFunctionId", DbType.Int32) { Value = o.AppFunctionId }, new System.Data.SQLite.SQLiteParameter("@UniqueName", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.UniqueName) }, new System.Data.SQLite.SQLiteParameter("@DisplayName", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.DisplayName) }, new System.Data.SQLite.SQLiteParameter("@ControllerName", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.ControllerName) }, new System.Data.SQLite.SQLiteParameter("@ActionName", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.ActionName) }, new System.Data.SQLite.SQLiteParameter("@AppFuncLevelId", DbType.Int32) { Value = o.AppFuncLevelId }, new System.Data.SQLite.SQLiteParameter("@ParentId", DbType.Int32) { Value = o.ParentId }, new System.Data.SQLite.SQLiteParameter("@SequentialNum", DbType.Int32) { Value = o.SequentialNum }, new System.Data.SQLite.SQLiteParameter("@IsDisabled", DbType.Boolean) { Value = o.IsDisabled }, new System.Data.SQLite.SQLiteParameter("@IsNavItem", DbType.Boolean) { Value = o.IsNavItem }, new System.Data.SQLite.SQLiteParameter("@UpdatedBy", DbType.Int32) { Value = o.UpdatedBy }, new System.Data.SQLite.SQLiteParameter("@Description", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.Description) } ))); }
/// Insert the record. public static int InsertUnit(Models.AppFunction o) { string sql = "INSERT INTO AppFunctions (UniqueName,DisplayName,ControllerName,ActionName,AppFuncLevelId,ParentId,SequentialNum,IsDisabled,IsNavItem,CreatedDt,CreatedBy,UpdatedDt,UpdatedBy,Description) VALUES (@UniqueName,@DisplayName,@ControllerName,@ActionName,@AppFuncLevelId,@ParentId,@SequentialNum,@IsDisabled,@IsNavItem,GETDATE(),@CreatedBy,GETDATE(),@UpdatedBy,@Description)"; return(o == null ? -1 : ( DbHandler.IsMssqlConnected ? DbHandler.MSSQL.ExecuteNonQuery(sql, new SqlParameter("@UniqueName", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.UniqueName) }, new SqlParameter("@DisplayName", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.DisplayName) }, new SqlParameter("@ControllerName", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.ControllerName) }, new SqlParameter("@ActionName", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.ActionName) }, new SqlParameter("@AppFuncLevelId", SqlDbType.Int) { Value = o.AppFuncLevelId }, new SqlParameter("@ParentId", SqlDbType.Int) { Value = o.ParentId }, new SqlParameter("@SequentialNum", SqlDbType.Int) { Value = o.SequentialNum }, new SqlParameter("@IsDisabled", SqlDbType.Bit) { Value = o.IsDisabled }, new SqlParameter("@IsNavItem", SqlDbType.Bit) { Value = o.IsNavItem }, //new SqlParameter("@CreatedDt", SqlDbType.DateTime) { Value = o.CreatedDt }, new SqlParameter("@CreatedBy", SqlDbType.Int) { Value = o.CreatedBy }, //new SqlParameter("@CreatedByDisplayName", SqlDbType.VarChar) { Value = o.CreatedByDisplayName }, //new SqlParameter("@UpdatedDt", SqlDbType.DateTime) { Value = o.UpdatedDt }, new SqlParameter("@UpdatedBy", SqlDbType.Int) { Value = o.UpdatedBy }, //new SqlParameter("@UpdatedByDisplayName", SqlDbType.VarChar) { Value = o.UpdatedByDisplayName }, new SqlParameter("@Description", SqlDbType.VarChar) { Value = DbHandler.GetObjectToDb(o.Description) } ): DbHandler.SQLite.ExecuteNonQuery(sql, new System.Data.SQLite.SQLiteParameter("@UniqueName", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.UniqueName) }, new System.Data.SQLite.SQLiteParameter("@DisplayName", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.DisplayName) }, new System.Data.SQLite.SQLiteParameter("@ControllerName", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.ControllerName) }, new System.Data.SQLite.SQLiteParameter("@ActionName", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.ActionName) }, new System.Data.SQLite.SQLiteParameter("@AppFuncLevelId", DbType.Int32) { Value = DbHandler.GetObjectToDb(o.AppFuncLevelId) }, new System.Data.SQLite.SQLiteParameter("@ParentId", DbType.Int32) { Value = DbHandler.GetObjectToDb(o.ParentId) }, new System.Data.SQLite.SQLiteParameter("@SequentialNum", DbType.Int32) { Value = DbHandler.GetObjectToDb(o.SequentialNum) }, new System.Data.SQLite.SQLiteParameter("@IsDisabled", DbType.Boolean) { Value = DbHandler.GetObjectToDb(o.IsDisabled) }, new System.Data.SQLite.SQLiteParameter("@IsNavItem", DbType.Boolean) { Value = DbHandler.GetObjectToDb(o.IsNavItem) }, //new System.Data.SQLite.SQLiteParameter("@CreatedDt", DbType.DateTime) { Value = DbHandler.GetObjectToDb(o.CreatedDt) }, new System.Data.SQLite.SQLiteParameter("@CreatedBy", DbType.Int32) { Value = DbHandler.GetObjectToDb(o.CreatedBy) }, //new System.Data.SQLite.SQLiteParameter("@UpdatedDt", DbType.DateTime) { Value = DbHandler.GetObjectToDb(o.UpdatedDt) }, new System.Data.SQLite.SQLiteParameter("@UpdatedBy", DbType.Int32) { Value = DbHandler.GetObjectToDb(o.UpdatedBy) }, new System.Data.SQLite.SQLiteParameter("@Description", DbType.AnsiString) { Value = DbHandler.GetObjectToDb(o.Description) } ))); }