/// <summary> /// Submits the wire guage modification to the database /// </summary> private void submit() { informationText = ""; if (wireGaugesFound.Count <= 0) { informationText = "No wire guages selected to update."; } else if (checkComplete()) { try { informationText = "Submitting wire gauge modifications..."; //Create a new modification for each wire gauge in the list //Should only be one foreach (WireGauge gauge in wireGaugesFound) { EngineeredModification modifiedGauge = new EngineeredModification() { RequestDate = DateTime.Now, ReviewedDate = new DateTime(1900, 1, 1), Description = string.IsNullOrWhiteSpace(description) ? "no description entered" : description, State = 0, Sender = string.Format("{0} {1}", _navigationService.user.FirstName, _navigationService.user.LastName), Reviewer = "", IsNew = false, ComponentName = "", EnclosureSize = "", EnclosureType = "", NewTime = 0, OldTime = 0, Gauge = gauge.Gauge, NewTimePercentage = (decimal)newTimePercentage, OldTimePercentage = gauge.TimePercentage }; _serviceProxy.addEngineeredModificationRequest(modifiedGauge); } //Clear input boxes _wireGauge = null; RaisePropertyChanged("wireGauge"); wireGaugesFound = new ObservableCollection <WireGauge>(); newTimePercentage = null; description = ""; informationText = "Wire gauge modification has been submitted. Waiting for manager approval."; } catch (Exception e) { informationText = "There was a problem accessing the database"; Console.WriteLine(e); } } }
/// <summary> /// Submits the checked modifications to the database and creates or modifies the /// information as needed /// Calls updateModification /// </summary> private void submitChecked() { informationText = "Submitting changes..."; int numApproved = 0; int numDenied = 0; int numError = 0; string errorText = ""; //Go through each table //check for state to equal 3 (checked to approve) or 4 (checked to decline) foreach (EngineeredModification mod in newComponents) { //If modification is checked to approve if (mod.State == 3) { mod.ComponentName = mod.ComponentName.ToUpper(); mod.EnclosureSize = mod.EnclosureSize.ToUpper(); try { //Ensure information is still valid if (string.IsNullOrWhiteSpace(mod.ComponentName)) { errorText += string.Format("Error adding component {0}. Invalid component.\n", mod.ComponentName); numError++; } else if (_serviceProxy.getComponent(mod.ComponentName, mod.EnclosureSize) != null) { errorText += string.Format("Error adding component {0} - {1}. Component already exists.\n", mod.ComponentName, mod.EnclosureSize); numError++; } else if (string.IsNullOrWhiteSpace(mod.EnclosureSize) || !(_serviceProxy.getEnclosureSizes().Contains(mod.EnclosureSize))) { errorText += string.Format("Error adding component {0} - {1}. Invalid Enclosure Size.\n", mod.ComponentName, mod.EnclosureSize); numError++; } else if (mod.NewTime < 0) { errorText += string.Format("Error adding component {0}. Invalid Time: {1}.\n.", mod.ComponentName, mod.NewTime); numError++; } else { Component component = new Component() { ComponentName = mod.ComponentName, EnclosureSize = mod.EnclosureSize, Time = mod.NewTime }; _serviceProxy.addComponent(component); numApproved++; updateModification(mod); } } catch (Exception e) { errorText += string.Format("Error adding component {0}. Problem accessing the database\n", mod.ComponentName); numError++; Console.WriteLine(e.Message); } } //If modification is checked to deny //Update the modification in the database to save the state to denied else if (mod.State == 4) { try { updateModification(mod); numDenied++; } catch (Exception e) { informationText = "There was a problem accessing the database."; Console.WriteLine(e.Message); } } } foreach (EngineeredModification mod in modifiedComponents) { //If modification is checked to approve if (mod.State == 3) { try { //Ensure information is still valid if (mod.NewTime < 0) { errorText += string.Format("Error modifying component {0}. Invalid Time: {1}.\n", mod.ComponentName, mod.NewTime); numError++; } else { _serviceProxy.updateComponent(mod.ComponentName, mod.EnclosureSize, mod.NewTime); numApproved++; updateModification(mod); } } catch (Exception e) { errorText += string.Format("Error modifying component {0}.\n", mod.ComponentName); numError++; informationText = "There was a problem accessing the database."; Console.WriteLine(e.Message); } } //If checked to deny else if (mod.State == 4) { try { updateModification(mod); numDenied++; } catch (Exception e) { informationText = "There was a problem accessing the database."; Console.WriteLine(e.Message); } } } foreach (EngineeredModification mod in modifiedEnclosures) { //If checked to approve if (mod.State == 3) { try { //Ensure information is still valid if (mod.NewTime < 0) { errorText += string.Format("Error modifying enclosure {0} - {1}. Invalid Time: {2}.\n", mod.EnclosureType, mod.EnclosureSize, mod.NewTime); numError++; } else { _serviceProxy.updateEnclosure(mod.EnclosureType, mod.EnclosureSize, mod.NewTime); numApproved++; updateModification(mod); } } catch (Exception e) { errorText += string.Format("Error modifying enclosure {0} - {1}.\n", mod.EnclosureType, mod.EnclosureSize); numError++; informationText = "There was a problem accessing the database."; Console.WriteLine(e.Message); } } //If checked to deny else if (mod.State == 4) { try { updateModification(mod); numDenied++; } catch (Exception e) { informationText = "There was a problem accessing the database."; Console.WriteLine(e.Message); } } } foreach (EngineeredModification mod in wireGaugeMods) { //Check if the wire gauge modification is adding a new wire gauge or modifying an old wire gauge if (mod.IsNew) { //If checked to approve if (mod.State == 3) { mod.Gauge = mod.Gauge.ToUpper(); try { //Ensure information is still valid if (string.IsNullOrWhiteSpace(mod.Gauge)) { errorText += string.Format("Error adding wire gauge {0}. Invalid gauge.\n", mod.Gauge); numError++; } else if (_serviceProxy.getWireGauge(mod.Gauge) != null) { errorText += string.Format("Error adding wire gauge {0}. Gauge already exists.\n", mod.Gauge); numError++; } else if (mod.NewTimePercentage <= 0) { errorText += string.Format("Error adding wire gauge {0}. Invalid Time: {1}.\n", mod.Gauge, mod.NewTimePercentage); numError++; } else { WireGauge wireGauge = new WireGauge() { Gauge = mod.Gauge, TimePercentage = mod.NewTimePercentage }; _serviceProxy.addWireGauge(wireGauge); numApproved++; updateModification(mod); } } catch (Exception e) { errorText += string.Format("Error adding wire gauge {0}. Problem accessing the database\n", mod.Gauge); numError++; Console.WriteLine(e.Message); } } //If checked to deny else if (mod.State == 4) { try { updateModification(mod); numDenied++; } catch (Exception e) { informationText = "There was a problem accessing the database."; Console.WriteLine(e.Message); } } } //If the modification is for modyfing a wire gauge else { //If checked to approve if (mod.State == 3) { try { //Ensure information is still valid if (string.IsNullOrWhiteSpace(mod.Gauge)) { errorText += string.Format("Error modifying wire gauge {0}. Invalid gauge.\n", mod.Gauge); numError++; } else if (_serviceProxy.getWireGauge(mod.Gauge) == null) { errorText += string.Format("Error modifying wire gauge {0}. Gauge does not exist.\n", mod.Gauge); numError++; } else if (mod.NewTimePercentage <= 0) { errorText += string.Format("Error modifying wire gauge {0}. Invalid Time: {1}.\n", mod.Gauge, mod.NewTimePercentage); numError++; } else { _serviceProxy.updateWireGauge(mod.Gauge, mod.NewTimePercentage); numApproved++; updateModification(mod); } } catch (Exception e) { errorText += string.Format("Error modifying wire gauge {0}.\n", mod.Gauge); numError++; informationText = "There was a problem accessing the database."; Console.WriteLine(e.Message); } } //If checked to deny else if (mod.State == 4) { try { updateModification(mod); numDenied++; } catch (Exception e) { informationText = "There was a problem accessing the database."; Console.WriteLine(e.Message); } } } } //Display a summary message if (numError > 0) { MessageBox.Show(string.Format("Approved: {0}\n" + "Denied: {1}\n" + "Errors: {2}\n" + "{3}", numApproved, numDenied, numError, errorText)); } else { MessageBox.Show(string.Format("Approved: {0}\n" + "Denied: {1}", numApproved, numDenied)); } informationText = ""; }