// Method gets a list of customers by the customer ID public List <Customer> GetCustomerByCustomerId(Guid customerId) { BusinessObjects _businessObjects = new BusinessObjects(); List <Customer> customerList = Translators.Customer.ToBusinessObject(_dataAccessObjects.GetCustomerByCustomerId(customerId)); List <Customer> customers = PopulateCustomers(customerList); return(customers); }
// Method gets a list of customers by the customer email address public List <Customer> GetCustomerByEmail(string email) { BusinessObjects _businessObjects = new BusinessObjects(); List <Customer> customerList = Translators.Customer.ToBusinessObject(_dataAccessObjects.GetCustomerByPersonEmail(email)); List <Customer> customers = PopulateCustomers(customerList); return(customers); }
// Method gets a list of customers by the last name public List <Customer> GetCustomerByLastName(string personLastName) { BusinessObjects _businessObjects = new BusinessObjects(); List <Customer> customerList = Translators.Customer.ToBusinessObject(_dataAccessObjects.GetCustomerByPersonLastName(personLastName)); List <Customer> customers = PopulateCustomers(customerList); return(customers); }
// Method gets a list of customers by the phone number public List <Customer> GetCustomerByPhoneNumber(string phoneNumber) { BusinessObjects _businessObjects = new BusinessObjects(); List <Customer> customerList = Translators.Customer.ToBusinessObject(_dataAccessObjects.GetCustomerByPersonPhone(phoneNumber)); List <Customer> customers = PopulateCustomers(customerList); return(customers); }
public static void SendWorkCompleteNotification() { //Assemble BusinessObjects _businessObjects = new BusinessObjects(); BusinessLayer.Order order = _businessObjects.GetOrder(new Guid("7F70F68B-E942-4D20-AC40-E017B0CF4892")); //Act order.OrderStatus = OrderStatus.WorkComplete; int returnValue = _businessObjects.UpdateOrder(order); //Assert if (returnValue == 1) { throw new CustomException("SendWorkCompleteNotification() failed to set order status to Work Complete and insert new notification."); } }
// USER RELATED METHODS public static UserAccount AuthenticateUser(string userName, string password) { /// Accepts login input and sets the appropriate UserAccount object and permissions token BusinessObjects _businessObjects = new BusinessObjects(); UserAccount userAccount = _businessObjects.GetUserAccountByUserName(userName); if(userAccount == null) { userAccount = new UserAccount("invalid", "invalid", true); } if(!userAccount.MatchPassword(password)) { userAccount.ClearPermissionSet(); } return userAccount; }
public static void AuthenticateUser(string userName, string password) { //Assemble //This unit test assumes that there is at least one record in the dbo.UserAccount table // with inputted userName and password. //Assumptions of this type are not good. //TODO: either check for records before running or find another way to ensure records exist. BusinessObjects _businessObjects = new BusinessObjects(); //Act UserAccount userAccount = ApplicationObjects.AuthenticateUser(userName, password); //Assert if (userAccount.PermissionSet.Token == 0) { throw new CustomException("AuthenticateUser() failed to authenticate inputted username and password."); } }
public static void GetUserAccountByUserName(string userName) { //Assemble //This unit test assumes that there is at least one record in the dbo.UserAccount table // with inputted userName. //Assumptions of this type are not good. //TODO: either check for records before running or find another way to ensure records exist. BusinessObjects _businessObjects = new BusinessObjects(); //Act UserAccount userAccount = _businessObjects.GetUserAccountByUserName(userName); //Assert if (userAccount.UserName != userName) { throw new CustomException("GetUserAccountByUserName() failed to retrieve the correct UserAccess record."); } }
public static void ChangePassword(string userName, string newPassword) { //Assemble //This unit test assumes that there is at least one record in the dbo.UserAccount table // with inputted userName and password. //Assumptions of this type are not good. //TODO: either check for records before running or find another way to ensure records exist. BusinessObjects _businessObjects = new BusinessObjects(); UserAccount userAccount = _businessObjects.GetUserAccountByUserName(userName); //Act userAccount.PasswordHash = newPassword; int _returnValue = ApplicationObjects.ChangePassword(userAccount); //Assert if (_returnValue == 1) { throw new CustomException("ChangePassword() failed to update the database with new password."); } }
// MARK AS SOLD submit button click event private void btn_SubmitRequest_Click(object sender, EventArgs e) { int updateReturnValue; int notificationReturnValue; BusinessObjects _businessObjects = new BusinessObjects(); // Verify that user enterd an order Id, and that they had an inventory item selected in the search result combobox if ((tbx_OrderSold.Text == null) || (cbx_ResultsList.SelectedItem == null)) { MessageBox.Show("Invalid input. Please make sure you have selected an inventory item & entered an Order ID and try again", "Invalid Stock Request", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } // Verify that the item that has been selected is not already marked as SOLD else if (inventoryItems[cbx_ResultsList.SelectedIndex].InventoryItemStatus != InventoryItemStatus.Stock) { MessageBox.Show("You have selected an inventory item that is not in stock. Please try again", "Invalid Item Status", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } // If user input appears to be valid, continue else { try { // Try to convert user input to a Guid Order order = _businessObjects.GetOrder(new Guid(tbx_OrderSold.Text.ToString())); // Verify that an Order was found if (order == null) { MessageBox.Show("We were unable to find an order with the ID that you entered. Please try again", "No Order Found", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } // Add order ID to inventory item InventoryItem inventoryItem = inventoryItems[cbx_ResultsList.SelectedIndex]; inventoryItem.OrderId = order.OrderId; // Change inventory item status to SOLD inventoryItem.InventoryItemStatus = InventoryItemStatus.Sold; //Update inventory and populate result value variable updateReturnValue = _businessObjects.UpdateInventoryItem(inventoryItem); // Display message based on success or failue of database update if (updateReturnValue == 0) { BusinessObjects _notificationBusinessObject = new BusinessObjects(); // Populate notification fields manually Notification notification = new Notification(); notification.OrderId = order.OrderId; notification.NotificationId = Guid.NewGuid(); notification.NotificationMessage = ("Please pull inventory item : " + inventoryItem.InventoryItemId.ToString()); notification.NotificationType = NotificationType.MediaPull; notification.IsRead = false; notification.PermissionScope = Permission.StockClerk; // Insert notification into database table notificationReturnValue = _notificationBusinessObject.InsertNotification(notification); // Database insert success message MessageBox.Show("Your inventory update request was successful.", "Inventory Update", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { // Database insert failure message MessageBox.Show("Your inventory update request has failed, Please try again.", "Inventory Update", MessageBoxButtons.OK, MessageBoxIcon.Hand); } // After transaction is complete, re-run original search and refresh search results. btn_SearchSubmit.PerformClick(); tbx_OrderSold.Text = ""; } // Show error if user didn't enter an INT catch (Exception) { MessageBox.Show("You entered an invalid order ID. Please try again", "Invalid Number", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } } }
// INVENTORY SEARCH submit button click event private void btn_SearchSubmit_Click(object sender, EventArgs e) { BusinessObjects _businessObjects = new BusinessObjects(); // Element reset to be performed each time, before a search is ran lbl_ResultsFound.Text = null; // Clear contents of search result label cbx_ResultsList.Items.Clear(); // Clear old search results from results combo box cbx_ResultsList.Text = ""; // Clear text from visible combobox area rbox_clerkSearchDisplay.Clear(); // Clear search results each time a new search is submitted inventoryItems = null; // Verify that a query type was selected by the user if ((cbx_QueryType.SelectedItem == null) || (cbx_InventoryStatus.SelectedItem == null) || (tbx_QueryInput.Text =="")) { MessageBox.Show("Please make sure all search criteria is filled out and try again", "Invalid Query Input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // SEARCH BY MANUFACTURER NAME - Chech to see if user entered a Manufacturer Name else if (cbx_QueryType.SelectedItem.ToString() == "Manufacturer") { // Generate a list of Inventory Items that match the Manufacturer Name entered by the user inventoryItems = _businessObjects.GetInventoryItemByItemManufacturer(tbx_QueryInput.Text, cbx_InventoryStatus.SelectedIndex); } // SEARCH BY ITEM NAME - Check to see if user entered an Item Name else if (cbx_QueryType.SelectedItem.ToString() == "Item Name") { // Generate a list of Inventory Items that match the Item Name entered by the user inventoryItems = _businessObjects.GetInventoryItemByItemName(tbx_QueryInput.Text, cbx_InventoryStatus.SelectedIndex); } // SEARCH BY ITEM GUID - Check to see if user entered an ID Number else if (cbx_QueryType.SelectedItem.ToString() == "Inventory ID") { try { // Generate a list of Inventory Items that match the Item ID entered by the user inventoryItems = ApplicationObjects.GetInventoryItemByInventoryItemIdAndInventoryItemStatusId(new Guid(tbx_QueryInput.Text), cbx_InventoryStatus.SelectedIndex); } catch (Exception) { // Catch if a non-Guid was entered MessageBox.Show("Search failed! You may have entered an invalid ID. Please check your item ID and try again", "Search Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); rbox_clerkSearchDisplay.AppendText("Input error - please try again"); return; } } // SEARCH BY CATALOG NUMBER - Check to see if user entered an Item Name else if (cbx_QueryType.SelectedItem.ToString() == "Catalog Number") { try { // Generate a list of Inventory Items that match the Item Name entered by the user inventoryItems = _businessObjects.GetInventoryItemByCatalogItemIdAndInventoryItemStatusId(new Guid(tbx_QueryInput.Text), cbx_InventoryStatus.SelectedIndex); } catch (Exception) { // Catch if a non-integer was entered MessageBox.Show("Search failed! You may have entered an invalid ID. Please check your catalog ID and try again", "Search Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); rbox_clerkSearchDisplay.AppendText("Input error - please try again"); return; } } // If nothing is populated into the searchDisplay box, we can assume that there were no search results else { lbl_ResultsFound.Text = "No matches found - please try again"; } // Populate label that displays how many results were found lbl_ResultsFound.Text = (inventoryItems.Count.ToString() + " result(s) found!"); // This string list holds the results of an InventoryItem's ToItemDescription method, which actually // returns a list of individual line items, which each hold the item's attributes that will be // displayed on seperate lines of the text box try { List<string> itemDescriptions = inventoryItems.FirstOrDefault().ToItemDescription(); foreach (string lineItem in itemDescriptions) { // Add each description line item to the text box rbox_clerkSearchDisplay.AppendText(lineItem + Environment.NewLine); } // Populate the search result combobox with the catalog numbers of the search results foreach (InventoryItem inventoryItem in inventoryItems) { cbx_ResultsList.Items.Add(inventoryItem.InventoryItemId.ToString()); } // Set the combobox to show the catalog number of the first search record cbx_ResultsList.SelectedIndex = 0; } catch (Exception) { rbox_clerkSearchDisplay.AppendText("No matches found - please try again"); return; } }
// INVENTORY REQUEST submit button click event private void btn_InventoryRequest_Click(object sender, EventArgs e) { // Verify all fields are NOT null if ((tbx_CatalogId.Text != null) && (tbx_Quantity.Text != null)) { try { DateTime time = DateTime.Now; // Variable to be included in notification message int quantity = Convert.ToInt32(tbx_Quantity.Text); // validate INT input from user int notificationReturnValue; // Variable to hold return value from database insert BusinessObjects _businessObject = new BusinessObjects(); // Get the catalog information for the item that needs to be ordered. Some of the catalog item info // will be populated into the notification message string CatalogItem catalogItem = _businessObject.GetCatalogItemByCatalogItemId(new Guid(tbx_CatalogId.Text)); // Populate notification fields manually Notification notification = new Notification(); notification.OrderId = new Guid(tbx_OrderId.Text); notification.NotificationId = Guid.NewGuid(); notification.NotificationMessage = ("Please order inventory item --> Item Name: " + catalogItem.ItemName.ToString() + ", Manufacturer Name: " + catalogItem.Manufacturer.ToString() + ", Date: " + time.ToString() + ", Quantity: " + quantity.ToString()) + ", Catalog ID: " + catalogItem.CatalogItemId.ToString(); notification.NotificationType = NotificationType.RestockItem; notification.IsRead = false; notification.PermissionScope = Permission.StockClerk; // Insert notification into database table notificationReturnValue = _businessObject.InsertNotification(notification); if (notificationReturnValue == 0) { // Database insert success message MessageBox.Show("Your stock request was sent successfully.", "Stock Request", MessageBoxButtons.OK, MessageBoxIcon.Information); tbx_OrderId.Clear(); tbx_CatalogId.Clear(); tbx_Quantity.Clear(); } else { // Database insert failure message MessageBox.Show("Your stock request failed. Please try again", "Stock Request", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } } catch (Exception) { // Failure message MessageBox.Show("Your stock request failed. Please make sure that you filled out all request fields with appropriate information", "Stock Request", MessageBoxButtons.OK, MessageBoxIcon.Hand); } } else { // Error message due to empty fields in stock request form MessageBox.Show("Your stock request is not complete. Please fill out all fields try again", "Stock Request", MessageBoxButtons.OK, MessageBoxIcon.Hand); } }
public static List<Notification> CheckAllNotifications(UserAccount user) { BusinessObjects _businessObjects = new BusinessObjects(); List<Notification> notificationList = _businessObjects.CheckAllNotifications(user); return notificationList; }
// NOTIFICATION METHODS public static List<Notification> CheckNewNotifications(UserAccount user, bool isRead = false) { BusinessObjects _businessObjects = new BusinessObjects(); List<Notification> notificationList = _businessObjects.CheckNewNotifications(user, isRead); return notificationList; }
// Method gets a list of customers by the phone number public List<Customer> GetCustomerByPhoneNumber(string phoneNumber) { BusinessObjects _businessObjects = new BusinessObjects(); List<Customer> customerList = Translators.Customer.ToBusinessObject(_dataAccessObjects.GetCustomerByPersonPhone(phoneNumber)); List<Customer> customers = PopulateCustomers(customerList); return customers; }
// Method gets a list of customers by the customer email address public List<Customer> GetCustomerByEmail(string email) { BusinessObjects _businessObjects = new BusinessObjects(); List<Customer> customerList = Translators.Customer.ToBusinessObject(_dataAccessObjects.GetCustomerByPersonEmail(email)); List<Customer> customers = PopulateCustomers(customerList); return customers; }
// CUSTOMER METHODS public static int UpdateCustomer(Customer customer) { // Transaction to perform 4 inter-related data inserts on multiple database tables using (TransactionScope scope = new TransactionScope()) { int returnValue = 1; // Write PERSON record to database BusinessObjects _personBusinessObject = new BusinessObjects(); returnValue = _personBusinessObject.UpdatePersonFromCustomer(customer); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return 1; } // Write MAILING ADDRESS record to database BusinessObjects _mailingAddressBusinessObject = new BusinessObjects(); returnValue = _mailingAddressBusinessObject.UpdateAddress(customer.MailingAddress); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return 1; } // Write BILLING ADDRESS record to database BusinessObjects _billingAddressBusinessObject = new BusinessObjects(); returnValue = _billingAddressBusinessObject.UpdateAddress(customer.BillingAddress); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return 1; } // Committ data transaction & display success message scope.Complete(); ApplicationObjects.DisplayDataStatus(returnValue); return 0; }// End transaction }
private void btnRemoveUser_Click(object sender, EventArgs e) { if(lstUsers.SelectedIndices.Count == 0) { MessageBox.Show("You must select a user to delete.", "No user selected", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DialogResult result = MessageBox.Show("Are you sure that you would like to remove this user?", "Confirm - DROP USER" , MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result == DialogResult.No || result == DialogResult.Cancel) return; BusinessObjects _businessObjects = new BusinessObjects(); int returnValue = _businessObjects.DeleteUserAccount(lstUsers.SelectedItems[0].Text); if(returnValue == 0) MessageBox.Show("User deleted successfully.", "Result" , MessageBoxButtons.OK, MessageBoxIcon.Information); RefreshUserList(); }
private void RefreshUserList() { BusinessObjects _businessObjects = new BusinessObjects(); List<UserAccount> users = _businessObjects.GetAllUserAccounts(); lstUsers.Items.Clear(); if (users != null) { foreach (UserAccount user in users) { ListViewItem item = new ListViewItem( new string[] { user.UserName, user.HighestPermission.ToString() } ); this.lstUsers.Items.Add(item); } } }
private void btn_clerknotifysubmit_Click(object sender, EventArgs e) { //Validate order id. Guid orderId; if (!ApplicationObjects.TryParseGuid(tbox_clerknotifyid.Text)) { MessageBox.Show("Invalid order ID format. No update occurred.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else { orderId = new Guid(tbox_clerknotifyid.Text); } Order order = ApplicationObjects.GetOrder(orderId); if (order == null) { MessageBox.Show("Order ID does not exist. No update occurred.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } //Validate that at least one of the radio button is selected. if (!rbtn_NotifyEnRoute.Checked && !rbtn_NotifyDelivered.Checked) { MessageBox.Show("Either the \"En Route\" or the \"Delivered\" radio button must be selected. No update occurred.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } //Prevent decrementing if status was already maked as delivered. if ((order.OrderStatus != OrderStatus.Delivered) && (rbtn_NotifyDelivered.Checked)) { string message = "Marking this order as \"Delivered\" will set the status for all items in the order " + "and decrement the available number in stock. Are you sure you'd like to mark this order \"Delivered\"?"; DialogResult result = MessageBox.Show(message, "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.Cancel) return; //Update order status and submit notifications order.OrderStatus = OrderStatus.Delivered; ApplicationObjects.UpdateOrderStatusWithNotification(order, (Permission)userAccount.PermissionSet.GetHighestPermission()); /*************************************/ //TODO: Re-think this location for the deletes. Should the stock clerk mark delivered to the customer or //just to the engraver. If to the engraver, then should the engraver handle the inventory decrementation? /*************************************/ //Delete from inventory because the material has been delivered. //ApplicationObjects.RemoveOrderItemsFromInventory(order); } //Do nothing if En Route was already set. else if ((order.OrderStatus != OrderStatus.EnRoute) && (rbtn_NotifyEnRoute.Checked)) { //Validate order id. if (!ApplicationObjects.TryParseGuid(tbox_clerknotifyid.Text)) { MessageBox.Show("Invalid order ID format. No update occurred.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else { //Update order status and submit notifications order.OrderStatus = OrderStatus.EnRoute; ApplicationObjects.UpdateOrderStatusWithNotification(order, (Permission)userAccount.PermissionSet.GetHighestPermission()); BusinessObjects _notificationBusinessObject = new BusinessObjects(); int notificationReturnValue; Notification notification = new Notification(); notification.OrderId = new Guid(tbox_clerknotifyid.Text); notification.NotificationId = Guid.NewGuid(); notification.NotificationMessage = ("Inventory item has been ordered and is en route : " + inventoryItems[cbx_ResultsList.SelectedIndex].InventoryItemId.ToString()); notification.NotificationType = NotificationType.EnRoute; notification.IsRead = false; notification.PermissionScope = Permission.WorkSpecialist; // INSERT notification to database notificationReturnValue = _notificationBusinessObject.InsertNotification(notification); if (notificationReturnValue == 0) { /* Database (inventory update) & (notification insert) success message. This message displays if the inventory database update was successful, and the notificaiton insert was successfull*/ MessageBox.Show("Your inventory update request was successful. A notification has been sent to the Work Specialist", "Inventory Update", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { /* Database (inventory update SUCCESS) but (notification insert FAILURE) message. This message displays if the inventory database update was successful, but the notification failed for some reason*/ MessageBox.Show("Your inventory update request was successful. However, an error prevented a" + "notification from being sent to the Work Specialist", "Inventory Update", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
public static int DeleteNotification(Guid notificationId) { BusinessObjects _businessObjects = new BusinessObjects(); return _businessObjects.DeleteNotification(notificationId); }
public static int CreateOrder(Order order) { BusinessObjects _businessObjects = new BusinessObjects(); return _businessObjects.InsertOrder(order); }
public static int CreateCustomer(Customer customer) { BusinessObjects _businessObjects = new BusinessObjects(); return _businessObjects.InsertPersonFromCustomer(customer); }
public static void RemoveInventoryItemFromInventory(InventoryItem item) { BusinessObjects _businessObjects = new BusinessObjects(); int returnValue; returnValue = _businessObjects.DeleteInventoryItem(item); DisplayDataStatus(returnValue); if (returnValue == 0) { int notificationReturnValue; BusinessObjects _notificationBusinessObject = new BusinessObjects(); Notification notification = new Notification(); notification.OrderId = item.OrderId; notification.NotificationId = Guid.NewGuid(); notification.NotificationMessage = ("Inventory item is en route : " + item.InventoryItemId.ToString()); notification.NotificationType = BusinessLayer.Enumerations.NotificationType.EnRoute; notification.IsRead = false; notification.PermissionScope = BusinessLayer.Enumerations.Permission.WorkSpecialist; // INSERT notification to database notificationReturnValue = _notificationBusinessObject.InsertNotification(notification); if(notificationReturnValue == 0) { MessageBox.Show("A notification has been sent to the Work specialist", "Item Sent to Work Specialist", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if(notificationReturnValue == 1) { MessageBox.Show("There was a problem sending a notification to the Work Specialist - please notify them manually that the item is on the way", "Item Sent to Work Specialist", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
// Method gets a list of customers by the customer ID public List<Customer> GetCustomerByCustomerId(Guid customerId) { BusinessObjects _businessObjects = new BusinessObjects(); List<Customer> customerList = Translators.Customer.ToBusinessObject(_dataAccessObjects.GetCustomerByCustomerId(customerId)); List<Customer> customers = PopulateCustomers(customerList); return customers; }
public static int NewUser(UserAccount user) { BusinessObjects _businessObjects = new BusinessObjects(); int returnValue = _businessObjects.NewUserAccount(user); return returnValue; }
// Method gets a list of customers by the last name public List<Customer> GetCustomerByLastName(string personLastName) { BusinessObjects _businessObjects = new BusinessObjects(); List<Customer> customerList = Translators.Customer.ToBusinessObject(_dataAccessObjects.GetCustomerByPersonLastName(personLastName)); List<Customer> customers = PopulateCustomers(customerList); return customers; }
private void btn_SearchSubmit_Click(object sender, EventArgs e) { BusinessObjects _businessObjects = new BusinessObjects(); // Element reset to be performed each time, before a search is ran lbl_CatalogResultsFound.Text = null; // Clear contents of search result label cbx_CatalogResultsList.Items.Clear(); // Clear old search results from results combo box cbx_CatalogResultsList.Text = ""; // Clear text from visible combobox area rbx_CatalogSearchResults.Clear(); // Clear search results each time a new search is submitted catalogItemCollection = null; // Clear inventory items from list // Verify that a query type was selected by the user if (cbx_CatalogQueryType.SelectedItem == null) { MessageBox.Show("You forgot to select a query type. Please try again", "Invalid Query", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } // SEARCH BY MANUFACTURER NAME - Chech to see if user entered a Manufacturer Name else if (cbx_CatalogQueryType.SelectedItem.ToString() == "Manufacturer") { // Generate a list of Inventory Items that match the Manufacturer Name entered by the user catalogItemCollection = _businessObjects.GetCatalogItemByManufacturer(tbx_CatalogQueryInput.Text); } // SEARCH BY ITEM NAME - Check to see if user entered an Item Name else if (cbx_CatalogQueryType.SelectedItem.ToString() == "Item Name") { // Generate a list of Catalog Items that match the Item Name entered by the user catalogItemCollection = (catalogItemCollection == null) ? new List<CatalogItem>() : catalogItemCollection; catalogItemCollection.Add(_businessObjects.GetCatalogItemByItemName(tbx_CatalogQueryInput.Text)); } // SEARCH BY ITEM GUID - Check to see if user entered an ID Number else if (cbx_CatalogQueryType.SelectedItem.ToString() == "Catalog ID") { try { // Generate a list of Catalog Items that match the Item ID entered by the user catalogItemCollection = (catalogItemCollection == null) ? new List<CatalogItem>() : catalogItemCollection; catalogItemCollection.Add(ApplicationObjects.GetCatalogItemByCatalogItemId(new Guid(tbx_CatalogQueryInput.Text))); } catch (Exception) { // Catch if a non-Guid was entered MessageBox.Show("You entered an invalid ID. Please make sure that the ID contains 32 characters and 4 hyphens", "Invalid GUID", MessageBoxButtons.OK, MessageBoxIcon.Hand); rbx_CatalogSearchResults.AppendText("Input error - please try again"); return; } } // If nothing is populated into the searchDisplay box, we can assume that there were no search results else { lbl_CatalogResultsFound.Text = "No results found"; } // Populate label that displays how many results were found lbl_CatalogResultsFound.Text = (catalogItemCollection.Count.ToString() + " result(s) found!"); // This string list holds the results of an CatalogItem's ToItemDescription method, which actually // returns a list of individual line items, which each hold the item's attributes that will be // displayed on seperate lines of the text box List<string> itemDescriptions = (catalogItemCollection.Count > 0) ? catalogItemCollection.FirstOrDefault().ToItemDescription() : new List<string>(); foreach (string lineItem in itemDescriptions) { // Add each description line item to the text box rbx_CatalogSearchResults.AppendText(lineItem + Environment.NewLine); } // Populate the search result combobox with the Catalog Id numbers of the search results foreach (CatalogItem catalogItem in catalogItemCollection) { cbx_CatalogResultsList.Items.Add(catalogItem.CatalogItemId.ToString()); } // Set the combobox to show the catalog number of the first search record if(cbx_CatalogResultsList.Items.Count > 0) cbx_CatalogResultsList.SelectedIndex = 0; }
public static int ChangePassword(UserAccount userWithNewPassword) { BusinessObjects _businessObjects = new BusinessObjects(); return _businessObjects.UpdateUserAccountByUserId(userWithNewPassword); }
// ORDER METHODS public static int UpdateOrderStatusWithNotification(Order order, Enumeration.Permission senderPermissionScope) { int returnValue = 1; BusinessObjects _businessObjects = new BusinessObjects(); returnValue = _businessObjects.UpdateOrder(order); if (returnValue == 1) return returnValue; Notification notification = new Notification { NotificationId = Guid.NewGuid(), IsRead = false, OrderId = order.OrderId }; string message = ""; switch (order.OrderStatus) { case Enumeration.OrderStatus.WorkComplete: message = "Order ID: " + order.OrderId.ToString() + " - STATUS CHANGE = Work Complete"; notification.NotificationMessage = message; notification.NotificationType = Enumeration.NotificationType.WorkComplete; notification.PermissionScope = Enumeration.Permission.OperationsManager; returnValue = _businessObjects.InsertNotification(notification); break; case Enumeration.OrderStatus.EnRoute: message = "Order ID: " + order.OrderId.ToString() + " - STATUS CHANGE = En Route"; notification.NotificationMessage = message; notification.NotificationType = Enumeration.NotificationType.EnRoute; notification.PermissionScope = Enumeration.Permission.WorkSpecialist; returnValue = _businessObjects.InsertNotification(notification); break; case Enumeration.OrderStatus.Delivered: if (senderPermissionScope == Enumeration.Permission.SalesPerson) { message = "Order ID: " + order.OrderId.ToString() + " - STATUS CHANGE = Delivered"; notification.NotificationMessage = message; notification.NotificationType = Enumeration.NotificationType.Delivered; notification.PermissionScope = Enumeration.Permission.OperationsManager; returnValue = _businessObjects.InsertNotification(notification); } else if (senderPermissionScope == Enumeration.Permission.StockClerk) { message = "Order ID: " + order.OrderId.ToString() + " - STATUS CHANGE = Delivered"; notification.NotificationMessage = message; notification.NotificationType = Enumeration.NotificationType.Delivered; notification.PermissionScope = Enumeration.Permission.WorkSpecialist; returnValue = _businessObjects.InsertNotification(notification); } break; case Enumeration.OrderStatus.Complete: message = "Order ID: " + order.OrderId.ToString() + " - STATUS CHANGE = Order Complete"; notification.NotificationMessage = message; notification.NotificationType = Enumeration.NotificationType.OrderComplete; notification.PermissionScope = Enumeration.Permission.SalesPerson; returnValue = _businessObjects.InsertNotification(notification); break; case Enumeration.OrderStatus.FailedValidation: message = "Order ID: " + order.OrderId.ToString() + " - STATUS CHANGE = Failed Validation"; notification.NotificationMessage = message; notification.NotificationType = Enumeration.NotificationType.FailedQualityControl; notification.PermissionScope = Enumeration.Permission.WorkSpecialist; returnValue = _businessObjects.InsertNotification(notification); break; } return returnValue; }
public static void RemoveOrderItemsFromInventory(Order order) { BusinessObjects _businessObjects = new BusinessObjects(); using (TransactionScope scope = new TransactionScope()) { int returnValue = 1; foreach (OrderItem orderItem in order.ItemList) { //Get list of items in the inventory that match the catalog id and are on hold by this order List<InventoryItem> inventoryList = (List<InventoryItem>)ApplicationObjects.GetInventoryItemByCatalogItemId(orderItem.CatalogItem ).Where(o => o.OrderId == order.OrderId); returnValue = _businessObjects.DeleteInventoryItems(inventoryList); if (returnValue == 1) { scope.Dispose(); //kick transactionscope thus rolling back transaction. break; } } if (returnValue == 0) scope.Complete(); //commit transaction } }
// Begin CREATE CUSTOMER button click event private void btnCreateCustomer_Click(object sender, EventArgs e) { // BEGIN USER INPUT DATA VALIDATION..... // Verify that PERSONAL information was not left blank if ((tbx_FirstName.Text == "") || (tbx_LastName.Text == "") || (tbx_PhoneNumber.Text == "") || (tbx_EMail.Text == "")) { // If any personal information was blank, display error and break code ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the personal fields and try again."); return; } // Verify that MAILING address information was not left blank if ((tbx_MailingStreetNumber.Text == "") || (tbx_MailingStreetName.Text == "") || (tbx_MailingCity.Text == "") || (tbx_MailingState.Text == "") || (tbx_MailingZipCode.Text == "")) { // If any mailing address information was blank, display error and break code ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the mailing address fields and try again."); return; } // Verify that BILLING address information was not left blank if ((tbx_BillingStreetNumber.Text == "") || (tbx_BillingStreetName.Text == "") || (tbx_BillingCity.Text == "") || (tbx_BillingState.Text == "") || (tbx_BillingZipCode.Text == "")) { // If any billing address information was blank, display error and break code ApplicationObjects.DisplayInvalidInput("Please make sure that you have filled out all of the billing address fields and try again."); return; } // Variable used in TryParse functions long number; // Validate numeric input for phone number if ((!long.TryParse((tbx_PhoneNumber.Text), out number)) || (tbx_PhoneNumber.Text.Length != 10)) { // If phone number input was not numeric, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid phone number entered. Please enter 10 digits (no dashes) & try again."); return; } // validate email address format if (!ApplicationObjects.EmailIsValid(tbx_EMail.Text)) { // If email address was not in specified format, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid e-mail address entered. Please try again."); return; } // Validate numeric input for street numbers if ((!long.TryParse((tbx_MailingStreetNumber.Text), out number)) || (!long.TryParse((tbx_BillingStreetNumber.Text), out number))) { // If street number input was not numeric, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid street number entered. Please enter only numeric values & try again."); return; } // Verify that the state is only 2 characters if ((tbx_MailingState.Text.Length != 2) || (tbx_BillingState.Text.Length != 2)) { // If state input does not have only 2 characters, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid state entered. Please enter a 2-letter state abbreviation & try again."); return; } // Validate numeric input for zip codes if ((!long.TryParse((tbx_MailingZipCode.Text), out number)) || (!long.TryParse((tbx_BillingZipCode.Text), out number))) { // If zip code input was not numeric, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid zip code entered. Please enter only numeric values & try again."); return; } // If zip is numeric, validate only 5 digits else if ((tbx_MailingZipCode.Text.Length != 5) || (tbx_BillingZipCode.Text.Length != 5)) { // If zip code does not have only 5 characters, display error and break code ApplicationObjects.DisplayInvalidInput("Invalid zip code entered. Please enter only 5 digits & try again."); return; } // .....END USER INPUT DATA VALIDATION // Populate customer object with user input Customer customer = new Customer(); customer.FirstName = tbx_FirstName.Text; customer.LastName = tbx_LastName.Text; customer.PhoneNumber = tbx_PhoneNumber.Text; customer.EmailAddress = tbx_EMail.Text; // Populate mailing address object with user input Address mailingAddress = new Address(); mailingAddress.PersonId = customer.PersonId; mailingAddress.StreetNumber = int.Parse(tbx_MailingStreetNumber.Text); mailingAddress.StreetName = tbx_MailingStreetName.Text; mailingAddress.AddressCity = tbx_MailingCity.Text; mailingAddress.AddressState = tbx_MailingState.Text; mailingAddress.AddressZip = tbx_MailingZipCode.Text; mailingAddress.AddressType = AddressType.Mailing; // Populate billing address object with user input Address billingAddress = new Address(); billingAddress.PersonId = customer.PersonId; billingAddress.StreetNumber = int.Parse(tbx_BillingStreetNumber.Text); billingAddress.StreetName = tbx_BillingStreetName.Text; billingAddress.AddressCity = tbx_BillingCity.Text; billingAddress.AddressState = tbx_BillingState.Text; billingAddress.AddressZip = tbx_BillingZipCode.Text; billingAddress.AddressType = AddressType.Billing; // Transaction to perform 4 inter-related data inserts on multiple database tables using (TransactionScope scope = new TransactionScope()) { int returnValue = 1; // Write PERSON record to database BusinessObjects _personBusinessObject = new BusinessObjects(); returnValue = _personBusinessObject.InsertPersonFromCustomer(customer); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return; } // Write CUSTOMER record to database BusinessObjects _customerBusinessObject = new BusinessObjects(); returnValue = _customerBusinessObject.InsertCustomer(customer); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return; } // Write MAILING ADDRESS record to database BusinessObjects _mailingAddressBusinessObject = new BusinessObjects(); returnValue = _mailingAddressBusinessObject.InsertAddress(mailingAddress); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return; } // Write BILLING ADDRESS record to database BusinessObjects _billingAddressBusinessObject = new BusinessObjects(); returnValue = _billingAddressBusinessObject.InsertAddress(billingAddress); if (returnValue == 1) { // If insert fails, rollback transaction & display error message scope.Dispose(); ApplicationObjects.DisplayDataStatus(returnValue); return; } // Committ data transaction & display success message scope.Complete(); ApplicationObjects.DisplayDataStatus(returnValue); }// End transaction _loginForm.ShowCustomerInfoForm(userAccount, _loginForm); this.Close(); }
// NOTIFICATION COMBO BOX selected index changed event private void cbx_Notifications_SelectedIndexChanged(object sender, EventArgs e) { BusinessObjects _businessObjects = new BusinessObjects(); // Clear Notification detail display box rbox_ClerkNotifications.Clear(); // Get description of selected notification List<string> notificationDescription = notifications[cbx_Notifications.SelectedIndex].ToNotificationDescription(); // Write description to notification diplay box foreach (string lineItem in notificationDescription) { rbox_ClerkNotifications.AppendText(lineItem + Environment.NewLine); } // Mark notification as READ notifications[cbx_Notifications.SelectedIndex].IsRead = true; // Update database to show notification is READ _businessObjects.UpdateNotification(notifications[cbx_Notifications.SelectedIndex]); }
public static int UpdateInventoryItem(InventoryItem item) { BusinessObjects _businessObjects = new BusinessObjects(); return _businessObjects.UpdateInventoryItem(item); }