///<summary>Converts a DataTable to a list of objects.</summary> public static List <JobPermission> TableToList(DataTable table) { List <JobPermission> retVal = new List <JobPermission>(); JobPermission jobPermission; foreach (DataRow row in table.Rows) { jobPermission = new JobPermission(); jobPermission.JobPermissionNum = PIn.Long(row["JobPermissionNum"].ToString()); jobPermission.UserNum = PIn.Long(row["UserNum"].ToString()); string jobPermType = row["JobPermType"].ToString(); if (jobPermType == "") { jobPermission.JobPermType = (OpenDentBusiness.JobPerm) 0; } else { try{ jobPermission.JobPermType = (OpenDentBusiness.JobPerm)Enum.Parse(typeof(OpenDentBusiness.JobPerm), jobPermType); } catch { jobPermission.JobPermType = (OpenDentBusiness.JobPerm) 0; } } retVal.Add(jobPermission); } return(retVal); }
///<summary>Updates one JobPermission in the database. Uses an old object to compare to, and only alters changed fields. This prevents collisions and concurrency problems in heavily used tables. Returns true if an update occurred.</summary> public static bool Update(JobPermission jobPermission, JobPermission oldJobPermission) { string command = ""; if (jobPermission.UserNum != oldJobPermission.UserNum) { if (command != "") { command += ","; } command += "UserNum = " + POut.Long(jobPermission.UserNum) + ""; } if (jobPermission.JobPermType != oldJobPermission.JobPermType) { if (command != "") { command += ","; } command += "JobPermType = '" + POut.String(jobPermission.JobPermType.ToString()) + "'"; } if (command == "") { return(false); } command = "UPDATE jobpermission SET " + command + " WHERE JobPermissionNum = " + POut.Long(jobPermission.JobPermissionNum); Db.NonQ(command); return(true); }
///<summary>Inserts one JobPermission into the database. Provides option to use the existing priKey. Doesn't use the cache.</summary> public static long InsertNoCache(JobPermission jobPermission, bool useExistingPK) { bool isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys); string command = "INSERT INTO jobpermission ("; if (!useExistingPK && isRandomKeys) { jobPermission.JobPermissionNum = ReplicationServers.GetKeyNoCache("jobpermission", "JobPermissionNum"); } if (isRandomKeys || useExistingPK) { command += "JobPermissionNum,"; } command += "UserNum,JobPermType) VALUES("; if (isRandomKeys || useExistingPK) { command += POut.Long(jobPermission.JobPermissionNum) + ","; } command += POut.Long(jobPermission.UserNum) + "," + "'" + POut.String(jobPermission.JobPermType.ToString()) + "')"; if (useExistingPK || isRandomKeys) { Db.NonQ(command); } else { jobPermission.JobPermissionNum = Db.NonQ(command, true, "JobPermissionNum", "jobPermission"); } return(jobPermission.JobPermissionNum); }
///<summary>Inserts one JobPermission into the database. Provides option to use the existing priKey.</summary> public static long Insert(JobPermission jobPermission, bool useExistingPK) { if (!useExistingPK && PrefC.RandomKeys) { jobPermission.JobPermissionNum = ReplicationServers.GetKey("jobpermission", "JobPermissionNum"); } string command = "INSERT INTO jobpermission ("; if (useExistingPK || PrefC.RandomKeys) { command += "JobPermissionNum,"; } command += "UserNum,JobPermType) VALUES("; if (useExistingPK || PrefC.RandomKeys) { command += POut.Long(jobPermission.JobPermissionNum) + ","; } command += POut.Long(jobPermission.UserNum) + "," + "'" + POut.String(jobPermission.JobPermType.ToString()) + "')"; if (useExistingPK || PrefC.RandomKeys) { Db.NonQ(command); } else { jobPermission.JobPermissionNum = Db.NonQ(command, true, "JobPermissionNum", "jobPermission"); } return(jobPermission.JobPermissionNum); }
///<summary>Inserts one JobPermission into the database. Returns the new priKey.</summary> public static long Insert(JobPermission jobPermission) { if (DataConnection.DBtype == DatabaseType.Oracle) { jobPermission.JobPermissionNum = DbHelper.GetNextOracleKey("jobpermission", "JobPermissionNum"); int loopcount = 0; while (loopcount < 100) { try { return(Insert(jobPermission, true)); } catch (Oracle.ManagedDataAccess.Client.OracleException ex) { if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")) { jobPermission.JobPermissionNum++; loopcount++; } else { throw ex; } } } throw new ApplicationException("Insert failed. Could not generate primary key."); } else { return(Insert(jobPermission, false)); } }
///<summary>Updates one JobPermission in the database.</summary> public static void Update(JobPermission jobPermission) { string command = "UPDATE jobpermission SET " + "UserNum = " + POut.Long(jobPermission.UserNum) + ", " + "JobPermType = '" + POut.String(jobPermission.JobPermType.ToString()) + "' " + "WHERE JobPermissionNum = " + POut.Long(jobPermission.JobPermissionNum); Db.NonQ(command); }
///<summary>Returns true if Update(JobPermission,JobPermission) would make changes to the database. ///Does not make any changes to the database and can be called before remoting role is checked.</summary> public static bool UpdateComparison(JobPermission jobPermission, JobPermission oldJobPermission) { if (jobPermission.UserNum != oldJobPermission.UserNum) { return(true); } if (jobPermission.JobPermType != oldJobPermission.JobPermType) { return(true); } return(false); }
///<summary>Inserts one JobPermission into the database. Returns the new priKey. Doesn't use the cache.</summary> public static long InsertNoCache(JobPermission jobPermission) { if (DataConnection.DBtype == DatabaseType.MySql) { return(InsertNoCache(jobPermission, false)); } else { if (DataConnection.DBtype == DatabaseType.Oracle) { jobPermission.JobPermissionNum = DbHelper.GetNextOracleKey("jobpermission", "JobPermissionNum"); //Cacheless method } return(InsertNoCache(jobPermission, true)); } }
private void butOK_Click(object sender, EventArgs e) { _jobPermissions.Clear(); JobPermission jobPermission; for (int i = 0; i < listAvailable.SelectedIndices.Count; i++) { jobPermission = new JobPermission(); jobPermission.UserNum = _userNum; jobPermission.JobPermType = (JobPerm)listAvailable.SelectedIndices[i]; _jobPermissions.Add(jobPermission); } JobPermissions.Sync(_jobPermissions, _userNum); DataValid.SetInvalid(InvalidType.JobPermission); DialogResult = DialogResult.OK; }
/// <summary> /// To create a new work history details /// </summary> /// <param name="jobSeekerWorkHistoryObj">WorkHistory object</param> public string Post(JobPermission jobSeekerWorkHistoryObj) { jobSeekerWorkHistoryObj.EmployerId = SkillsmartUser.GuidStr(HttpContext.Current.User); ServiceFactory.GetJobPermission().Create(jobSeekerWorkHistoryObj); return(jobSeekerWorkHistoryObj.Id.ToString()); }
/// <summary> /// Sets the permissions for a experiment. makes sure that only one permission per user exists. /// </summary> public void SetJobPermission(Guid jobId, Guid grantedByUserId, Guid grantedUserId, Permission permission) { using (var db = CreateContext()) { JobPermission jobPermission = db.JobPermissions.SingleOrDefault(x => x.JobId == jobId && x.GrantedUserId == grantedUserId); if (jobPermission != null) { if (permission == Permission.NotAllowed) { // not allowed, delete db.JobPermissions.DeleteOnSubmit(jobPermission); } else { // update jobPermission.Permission = permission; jobPermission.GrantedByUserId = grantedByUserId; // update grantedByUserId, always the last "granter" is stored } } else { // insert if (permission != Permission.NotAllowed) { jobPermission = new JobPermission() { JobId = jobId, GrantedByUserId = grantedByUserId, GrantedUserId = grantedUserId, Permission = permission }; db.JobPermissions.InsertOnSubmit(jobPermission); } } db.SubmitChanges(); } }
///<summary>Inserts one JobPermission into the database. Returns the new priKey. Doesn't use the cache.</summary> public static long InsertNoCache(JobPermission jobPermission) { return(InsertNoCache(jobPermission, false)); }