/// <summary> /// save the new change record /// </summary> internal void PostToDB(Changes change) { string itemQry = ""; try { List <string> qryList = new List <string>(); //insert to master data string qry = dBservices.BuildInsertChanges(change); qryList.Add(qry); for (int i = 0; i < change.ObjectsList.Count; i++) { qry = dBservices.BuildInsertObjectsAffected(change.ObjectsList[i], change.Id); qryList.Add(qry); } for (int i = 0; i < change.TestsList.Count; i++) { qry = dBservices.BuildInsertObjectsAffected(change.TestsList[i], change.Id); qryList.Add(qry); } foreach (var item in qryList) { dBservices.insert(item); itemQry = item; } } catch (Exception ex) { LogWaveClass.LogWave("שגיאת הכנסה לדטהבייס " + itemQry + " " + ex.Message); } }
/// <summary> /// check user authentication /// </summary> public void IsValidUser() { try { List <UserPrincipal> ListUserPrincipal = new List <UserPrincipal>(); ListUsersNames = new List <string>(); string Domain = System.DirectoryServices.ActiveDirectory.Domain.GetComputerDomain().ToString(); using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, Domain)) { // validate the credentials IsValid = pc.ValidateCredentials(UserName, Password); var usr = UserPrincipal.FindByIdentity(pc, UserName); if (usr != null) { FullName = usr.DisplayName; } Password = ""; //get all names from active directory using (var searcher = new PrincipalSearcher(new UserPrincipal(pc))) { ListUserPrincipal = searcher.FindAll().Select(u => (UserPrincipal)u).ToList(); ListUsersNames = ListUserPrincipal.Select(x => x.DisplayName).Distinct().ToList(); } } } catch (Exception ex) { LogWaveClass.LogWave("IsValidUser -" + ex.Message); } }
/// <summary> /// check if current user can approve the change /// </summary> internal bool CheckifCanApprove(string fullNameUser, string userName, string typeApprove, string idChange) { bool check = false; Id = int.Parse(idChange); try { string qry = ""; switch (typeApprove)//which type of button was clicked { case "Initated": qry = $@"SELECT * FROM ChangessS400 WHERE NameInitated='{fullNameUser}' and Id={Id}"; break; case "It": qry = $@"SELECT * FROM ChangesPremission WHERE UserName='******' and It = 'TRUE'"; break; case "Finance": qry = $@"SELECT * FROM ChangesPremission WHERE UserName='******' and Finance = 'TRUE'"; break; } DataTable dataTable = new DataTable(); dataTable = dBservices.GetDataTable(qry); if (dataTable.Rows.Count >= 1)//can sign { //update approve field to true qry = $@"SELECT * FROM ChangessS400 WHERE Id={Id}"; dataTable = dBservices.GetDataTable(qry); dataTable.Rows[0][typeApprove] = true; dBservices.update(dataTable); check = true; } else { check = false; } } catch (Exception ex) { LogWaveClass.LogWave(ex.Message); } return(check); }