/// <summary> /// Va chercher les users et leurs workcenter en db /// </summary> private void GetUser() { List <UserWorkCenter> UserWorkCenters = new List <UserWorkCenter>(); List <ADR_WorkCenterUser> WorkCenterUsers; using (WorkCenterUserRepository WorkCenterUserRepository = new WorkCenterUserRepository()) { WorkCenterUsers = WorkCenterUserRepository.Get().Where((u) => !u.IsDisabled).OrderBy((u) => u.UserId).ToList(); } foreach (ADR_WorkCenterUser item in WorkCenterUsers) { ADR_WorkCenter WorkCenter; using (WorkCenterRepository WorkCenterRepository = new WorkCenterRepository()) { WorkCenter = WorkCenterRepository.Get(item.WorkCenterId); } UserWorkCenters.Add(new UserWorkCenter() { UserId = item.Id, WorkCenterId = item.WorkCenterId, User = item.UserId, WorkCenter = WorkCenter.WorkCenter }); } olvUser.SetObjects(UserWorkCenters); }
/// <summary> /// Supprime un utilisateur de la db /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRemove_Click(object sender, System.EventArgs e) { bool IsDeleted; UserWorkCenter UserWK = (UserWorkCenter)olvUser.SelectedObject; ADR_WorkCenterUser WorkCenterUser; using (WorkCenterUserRepository WorkCenterUserRepository = new WorkCenterUserRepository()) { WorkCenterUser = WorkCenterUserRepository.GetByUserId(UserWK.User); IsDeleted = WorkCenterUserRepository.Delete(WorkCenterUser); } if (!IsDeleted) { GenerateMessage("Erreur lors de la suppression de l'utilisateur"); } else { cbWorkCenter.SelectedIndex = cbWorkCenter.FindStringExact(""); txtMessage.Text = string.Empty; txtMessage2.Text = string.Empty; btnModify.Enabled = false; btnRemove.Enabled = false; GetUser(); GenerateHistorique.CreateHistorique(FormUser.UserID, "Suppression de l'utilisateur", UserWK.WorkCenter); } }
/// <summary> /// Attribue les noms aux controlleurs depuis les fichiers ressources. /// </summary> private bool LoadControllerName() { using (WorkCenterUserRepository WorkCenterUserRepository = new WorkCenterUserRepository()) { ADRWorkCenterUser = WorkCenterUserRepository.GetByUserId(FormUser.UserID); } if (ADRWorkCenterUser != null) { if (!ADRWorkCenterUser.IsDisabled) { using (WorkCenterRepository WorkCenterRepository = new WorkCenterRepository()) { ADRWorkCenter = WorkCenterRepository.Get(ADRWorkCenterUser.WorkCenterId); } } else { return(false); } } string WorkCenter = ADRWorkCenter != null ? ADRWorkCenter.WorkCenter : "Pas de section"; tssUser.Text = $"{SynapseForm.FormUser.ToString()} / {WorkCenter}"; tssRole.Text = string.Empty; tssBlank.Text = " "; return(true); }
/// <summary> /// Sauvegarde le choix de la section /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, System.EventArgs e) { ADR_WorkCenter WorkCenter = (ADR_WorkCenter)cbWorkCenter.SelectedItem; bool IsInserted = false; bool IsUpdated = false; if (WorkCenterUser == null) { WorkCenterUser = new ADR_WorkCenterUser() { UserId = FormUser.UserID.ToUpper(), WorkCenterId = WorkCenter.Id }; using (WorkCenterUserRepository WorkCenterUserRepository = new WorkCenterUserRepository()) { IsInserted = WorkCenterUserRepository.Insert(WorkCenterUser); } GenerateHistorique.CreateHistorique(FormUser.UserID, "Choix du WorkCenter (Création de l'utilisateur)", WorkCenter.WorkCenter); } else { string Origine; using (WorkCenterRepository WorkCenterRepository = new WorkCenterRepository()) { Origine = WorkCenterRepository.Get(WorkCenter.Id).WorkCenter; } WorkCenterUser.WorkCenterId = WorkCenter.Id; using (WorkCenterUserRepository WorkCenterUserRepository = new WorkCenterUserRepository()) { IsUpdated = WorkCenterUserRepository.Update(WorkCenterUser); } if (IsUpdated) { GenerateHistorique.CreateHistorique(FormUser.UserID, "Choix du WorkCenter", Origine, WorkCenter.WorkCenter); } } ADR.tssUser.Text = $"{SynapseForm.FormUser.ToString()} / {WorkCenter.WorkCenter}"; ADR.ADRWorkCenter = WorkCenter; ADR.ADRWorkCenterUser = WorkCenterUser; if (IsInserted || IsUpdated) { this.Dispose(); } }
/// <summary> /// Modifie en db le nouveau workcenter de l'utilisateur /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnModify_Click(object sender, System.EventArgs e) { UserWorkCenter UserWK = (UserWorkCenter)olvUser.SelectedObject; ADR_WorkCenter WorkCenter = (ADR_WorkCenter)cbWorkCenter.SelectedItem; ADR_WorkCenterUser UserDb; bool IsUpdated; string Origine; string Destination; using (WorkCenterUserRepository WorkCenterUserRepository = new WorkCenterUserRepository()) { UserDb = WorkCenterUserRepository.GetByUserId(UserWK.User); Origine = UserWK.WorkCenter; Destination = WorkCenter.WorkCenter; UserDb.WorkCenterId = WorkCenter.Id; IsUpdated = WorkCenterUserRepository.Update(UserDb); } if (!IsUpdated) { GenerateMessage("Erreur lors du changement de section"); } else { cbWorkCenter.SelectedIndex = cbWorkCenter.FindStringExact(""); txtMessage.Text = string.Empty; txtMessage2.Text = string.Empty; btnModify.Enabled = false; btnRemove.Enabled = false; GetUser(); ADR.tssUser.Text = $"{SynapseForm.FormUser.ToString()} / {WorkCenter.WorkCenter}"; ADR.ADRWorkCenter = WorkCenter; ADR.ADRWorkCenterUser = UserDb; GenerateHistorique.CreateHistorique(FormUser.UserID, "Changement de WorkCenter", Origine, Destination); } }