private void commitAction(string userID, string password) { if (pageMode == PageFunctions.LogIn && SSOCheckBox.IsChecked == true && LoginFunctions.SingleSignon(userID)) { pageSuccess = true; } else if (!LoginFunctions.CheckPassword(userID, password)) { MessageFunctions.InvalidMessage("Incorrect existing username or password. Please check and try again.", "Incorrect Login"); } else if (pageMode == PageFunctions.LogIn) { LoginFunctions.AttemptLogin(userID, password); pageSuccess = true; } else if (pageMode == PageFunctions.PassChange) { bool success = LoginFunctions.ChangeLoginDetails(Globals.MyStaffID, userID, NewPassword.Password, ConfirmPassword.Password); if (success) { MessageFunctions.SuccessAlert("Your password has been changed successfully.", "Password Changed"); pageSuccess = true; } } }
// ---------------------- // // -- Data Management --- // // ---------------------- // // Shared functions // private void createNewContact() { int newID = 0; try { newID = ClientFunctions.NewContact(FirstName.Text, Surname.Text, JobTitle.Text, PhoneNumber.Text, Email.Text, (bool)ActiveCheckBox.IsChecked); } catch (Exception generalException) { MessageFunctions.Error("Error creating new contact record", generalException); } if (newID > 0) { MessageFunctions.SuccessAlert("New contact '" + FirstName.Text + " " + Surname.Text + "' saved successfully.", "Contact Created"); selectedContactID = newID; goBack(); } }
private void CommitButton_Click(object sender, RoutedEventArgs e) { if (editMode) { if (selectedProduct != null) { bool success = ProductFunctions.AmendProduct(selectedProduct.ID, ProductName.Text, Description.Text, Version.Text); if (success) { MessageFunctions.SuccessAlert("Your changes have been saved successfully.", "Product Amended"); refreshProductGrid(); amendmentSetup(); } } else { int newID = ProductFunctions.NewProduct(ProductName.Text, Description.Text, Version.Text); if (newID > 0) { additionMade = true; refreshProductGrid(); if (pageMode == PageFunctions.Amend) { MessageFunctions.SuccessAlert("New product '" + ProductName.Text + "' saved successfully.", "Product Created"); amendmentSetup(); ProductGrid.SelectedValue = gridList.First(s => s.ID == newID); ProductGrid.ScrollIntoView(ProductGrid.SelectedItem); } else { MessageFunctions.SuccessAlert("New product '" + ProductName.Text + "' saved successfully. You can create further products using the 'Add Another' button.", "Product Created"); ProductName.IsEnabled = Description.IsEnabled = Version.IsEnabled = false; editMode = false; CommitButton.IsEnabled = false; AddButton.Visibility = Visibility.Visible; AddButton.IsEnabled = true; AddImage.Visibility = Visibility.Visible; ReturnImage2.Visibility = Visibility.Collapsed; } AddButtonText.Text = "Add Another"; } } } else { MessageFunctions.Error("Saving should not be possible.", null); } }
private void CommitButton_Click(object sender, RoutedEventArgs e) { bool confirm = MessageFunctions.ConfirmOKCancel("Are you sure you wish to save your amendments?", "Save changes?"); if (!confirm) { return; } bool success = (editMode == ByProject) ? ProjectFunctions.SaveProjectProductChanges(Globals.SelectedProjectProxy.ProjectID) : ProjectFunctions.SaveProductProjectChanges(selectedProductID); if (success) { MessageFunctions.SuccessAlert("Your changes have been saved successfully. You can make further changes, go back to the previous screen, or close the current page.", "Changes Saved"); CommitButton.IsEnabled = false; } }
private void CommitButton_Click(object sender, RoutedEventArgs e) { try { //string roleDescription = ""; string roleCode = ""; //string defaultEntityName = ""; int defaultEntityID = 0; bool active = (ActiveCheckBox.IsChecked == true); string passwd = NewPassword.Password; if (RoleCombo.SelectedItem != null) { StaffRoles role = (StaffRoles)RoleCombo.SelectedItem; roleCode = role.RoleCode; } if (EntityCombo.SelectedItem != null) { Entities defaultEntity = (Entities)EntityCombo.SelectedItem; defaultEntityID = defaultEntity.ID; } if (passwd != "" && passwd != ConfirmPassword.Password) { MessageFunctions.InvalidMessage("New password does not match confirmation. Please check both fields and try again.", "Password Mismatch"); return; } int returnID = StaffFunctions.SaveStaffDetails(selectedStaffID, FirstName.Text, Surname.Text, roleCode, StartDate.SelectedDate, LeaveDate.SelectedDate, UserID.Text, passwd, active, defaultEntityID, (SSOCheckBox.IsChecked == true), DomainUser.Text); if (returnID > 0) { if (selectedStaffID == 0) { MessageFunctions.SuccessAlert("New staff member created successfully.", "Staff details saved"); selectedStaffID = returnID; } else { MessageFunctions.SuccessAlert("Changes saved successfully.", "Staff member amended"); } StaffFunctions.ReturnToStaffPage(selectedStaffID); } } catch (Exception generalException) { MessageFunctions.Error("Error saving details", generalException); } }
private void saveContactAmend() { bool success = false; try { success = ClientFunctions.AmendContact(selectedContactID, FirstName.Text, Surname.Text, JobTitle.Text, PhoneNumber.Text, Email.Text, (bool)ActiveCheckBox.IsChecked); } catch (Exception generalException) { MessageFunctions.Error("Error saving amendments to contact", generalException); } try { if (success) { MessageFunctions.SuccessAlert("Your changes have been saved successfully.", "Contact Amended"); goBack(); } } catch (Exception generalException) { MessageFunctions.Error("Error updating page for saved contact amendments", generalException); } }
private void saveClientAmend(string accountManagerName) { bool success = false; try { success = ClientFunctions.AmendClient(editRecordID, ClientCode.Text, ClientName.Text, accountManagerName, (bool)ActiveCheckBox.IsChecked); } catch (Exception generalException) { MessageFunctions.Error("Error saving amendments to client", generalException); } try { if (success) { MessageFunctions.SuccessAlert("Your changes have been saved successfully.", "Client Amended"); resetAmendPage(accountManagerName); // This is not necessarily done for us by the Account Managers list refreshClientGrid(); } } catch (Exception generalException) { MessageFunctions.Error("Error updating page for saved client amendments", generalException); } }
private void createNewClient(string accountManagerName) { int newID = 0; bool inCurrentEntity = (selectedEntityID == Globals.CurrentEntityID); string savedInEntity = ""; string contactsCopied = ""; try { newID = ClientFunctions.NewClient(ClientCode.Text, ClientName.Text, accountManagerName, (bool)ActiveCheckBox.IsChecked, selectedEntityID); } catch (Exception generalException) { MessageFunctions.Error("Error creating new client record", generalException); } if (newID > 0) { try { if (!inCurrentEntity) { if (CopyContactsCheckBox.IsChecked == true) { bool success = ClientFunctions.CopyContacts(selectedRecord.ID, newID); contactsCopied = success ? ", and all active linked contacts have been copied to it" : " but contacts could not be copied"; } savedInEntity = " in Entity '" + EntityFunctions.GetEntityName(selectedEntityID) + "'" + contactsCopied + ". Switch to that Entity if you need to work with the new record"; } MessageFunctions.SuccessAlert("New client '" + ClientName.Text + "' saved successfully" + savedInEntity + ".", "Client Created"); if (pageMode == PageFunctions.Amend) { resetAmendPage(accountManagerName); if (inCurrentEntity) { refreshClientGrid(); // This is not necessarily done for us by the Account Managers list ClientDataGrid.SelectedValue = gridList.First(c => c.ID == newID); ClientDataGrid.ScrollIntoView(ClientDataGrid.SelectedItem); } AddButtonText.Text = "Add Another"; } else { ClientFunctions.ReturnToTilesPage(); } } catch (Exception generalException) { MessageFunctions.Error("Error updating page for new client record", generalException); } } }
public static void SwitchEntity(ref Entities selectedEntity, bool makeDefault = false) { if (selectedEntity == null) { MessageFunctions.InvalidMessage("Please select an Entity from the drop-down list.", "No Entity Selected"); return; } try { UpdateCurrentEntity(ref selectedEntity); if (makeDefault) { SetDefaultEntity(ref selectedEntity); MessageFunctions.SuccessAlert("Your default Entity has now been set to '" + selectedEntity.EntityName + "'.", "Default Entity Changed"); } PageFunctions.ShowTilesPage(); } catch (Exception generalException) { MessageFunctions.Error("Error changing current Entity", generalException); } }
public static void ChangeDefaultEntity(ref Entities selectedEntity, string displayName) { if (selectedEntity != null) { try { SetDefaultEntity(ref selectedEntity); string notCurrent = ""; if (displayName != CurrentEntityName) { notCurrent = " Note that you are still currently connected to '" + CurrentEntityName + "'."; } MessageFunctions.SuccessAlert("Your default Entity has now been set to '" + displayName + "'." + notCurrent, "Default Entity Changed"); PageFunctions.UpdateDetailsBlock(); PageFunctions.ShowTilesPage(); } catch (Exception generalException) { MessageFunctions.Error("Error changing entity", generalException); } } else { MessageFunctions.InvalidMessage("Please select an Entity from the drop-down list.", "No Entity Selected"); } }
public static void AmendEntity(ref Entities selectedEntity, string entityName, string entityDescription) { int intSelectedEntityID; if (selectedEntity == null) { MessageFunctions.InvalidMessage("Please select an Entity to amend from the drop-down list.", "No Entity Selected"); return; } if (!PageFunctions.SqlInputOK(entityName, true, "Entity name")) { return; } else if (!PageFunctions.SqlInputOK(entityDescription, true, "Entity description")) { return; } try { ProjectTileSqlDatabase existingPtDb = SqlServerConnection.ExistingPtDbConnection(); using (existingPtDb) { intSelectedEntityID = selectedEntity.ID; Entities checkNewName = existingPtDb.Entities.FirstOrDefault(ent => ent.EntityName == entityName && ent.ID != intSelectedEntityID); if (checkNewName != null) { MessageFunctions.InvalidMessage("Could not amend Entity. Another Entity with name '" + entityName + "' already exists.", "Duplicate Name"); return; } Entities checkNewDescription = existingPtDb.Entities.FirstOrDefault(ent => ent.EntityDescription == entityDescription && ent.ID != intSelectedEntityID); if (checkNewDescription != null) { MessageFunctions.InvalidMessage("Could not amend Entity. Another Entity with description '" + entityDescription + "' already exists.", "Duplicate Description"); return; } try { try { string nameChange = ""; string originalName = selectedEntity.EntityName; if (originalName != entityName) { nameChange = " to '" + entityName + "'"; } ; Entities changeDbEntity = existingPtDb.Entities.Find(intSelectedEntityID); changeDbEntity.EntityName = entityName; changeDbEntity.EntityDescription = entityDescription; existingPtDb.SaveChanges(); MessageFunctions.SuccessAlert("Entity '" + originalName + "' has been amended" + nameChange + ".", "Entity Amended"); if (changeDbEntity.ID == CurrentEntityID) { UpdateCurrentEntity(ref changeDbEntity); } if (changeDbEntity.ID == MyDefaultEntityID) { UpdateMyDefaultEntity(ref changeDbEntity); } PageFunctions.ShowTilesPage(); } catch (Exception generalException) { MessageFunctions.Error("Error amending database record", generalException); return; } } catch (Exception generalException) { MessageFunctions.Error("Error creating new database", generalException); } } } catch (Exception generalException) { MessageFunctions.Error("Error checking new database details", generalException); } }
public static void NewEntity(string entityName, string entityDescription, bool switchTo, bool makeDefault) { int newEntityID; Entities newEntity; if (!PageFunctions.SqlInputOK(entityName, true, "Entity name")) { return; } else if (!PageFunctions.SqlInputOK(entityDescription, true, "Entity description")) { return; } try { ProjectTileSqlDatabase existingPtDb = SqlServerConnection.ExistingPtDbConnection(); using (existingPtDb) { Entities checkNewName = existingPtDb.Entities.FirstOrDefault(ent => ent.EntityName == entityName); if (checkNewName != null) { MessageFunctions.InvalidMessage("Could not create new Entity. An Entity with name '" + entityName + "' already exists.", "Duplicate Name"); return; } Entities checkNewDescription = existingPtDb.Entities.FirstOrDefault(ent => ent.EntityDescription == entityDescription); if (checkNewDescription != null) { MessageFunctions.InvalidMessage("Could not create new Entity. An Entity with description '" + entityDescription + "' already exists.", "Duplicate Description"); return; } try { try { newEntity = new Entities(); newEntity.EntityName = entityName; newEntity.EntityDescription = entityDescription; try { existingPtDb.Entities.Add(newEntity); existingPtDb.SaveChanges(); newEntityID = newEntity.ID; } catch (Exception generalException) { MessageFunctions.Error("Problem creating entity ID", generalException); return; } } catch (Exception generalException) { MessageFunctions.Error("Error creating database record", generalException); return; } try { Staff currentUser = MyStaffRecord; AllowEntity(newEntityID, currentUser.ID); } catch (Exception generalException) { MessageFunctions.Error("Error providing access to the new database", generalException); return; } try { existingPtDb.SaveChanges(); string switched = ". Use the 'Change Current Entity' function to log into it if you wish to work in this Entity."; if (switchTo) { UpdateCurrentEntity(ref newEntity); switched = " and you are now logged into it."; } if (makeDefault) { SetDefaultEntity(ref newEntity); } MessageFunctions.SuccessAlert("Entity '" + entityName + "' has been created" + switched, "New Entity Created"); PageFunctions.ShowTilesPage(); } catch (SqlException sqlException) { MessageFunctions.Error("SQL error saving changes to the database", sqlException); return; } catch (Exception generalException) { MessageFunctions.Error("Error saving changes to the database", generalException); return; } } catch (Exception generalException) { MessageFunctions.Error("Error creating new database", generalException); } } } catch (Exception generalException) { MessageFunctions.Error("Error checking new database details", generalException); } }