public bool ValidEmployeeNumber(string clockNumber, out string message) { if (string.IsNullOrWhiteSpace(clockNumber)) { message = Messages.ClockNumberCannotBeNullOrEmpty(); return(false); } try { var employeeFound = false; BenchOperator bo = BenchOperatorDb.GetEmployeeById(clockNumber); if (bo == null) { message = Messages.BenchOperatorNotFound(clockNumber); employeeFound = false; } else { message = null; employeeFound = true; } return(employeeFound); } catch (Exception ex) { Messages.GeneralExceptionMessage(ex, "DataValidator.ValidEmployeeNumber()"); message = ""; return(false); } }
public static void LoadOperatorInfo(BenchOperator benchOperator) { try { // load xml file XmlDocument dom = new XmlDocument(); dom.Load(EMPLOYEE_PATH); // find node by employee number XmlNode node = dom.DocumentElement.SelectSingleNode("//employee[@clockId='104']"); if (node == null) { benchOperator = null; } else { // add first and last name properties to the bench operator. XmlNode firstNameNode = node.Attributes.GetNamedItem("firstName"); if (firstNameNode != null) { benchOperator.FirstName = firstNameNode.Value; } XmlNode lastNameNode = node.Attributes.GetNamedItem("lastName"); if (lastNameNode != null) { benchOperator.LastName = lastNameNode.Value; } } } catch (Exception ex) { Messages.GeneralExceptionMessage(ex, "DataValidator.LoadOperatorInfo()"); } }
/// <summary> /// For a given testId, this method will get you a TorqueTest from /// the Twister database. /// </summary> /// <param name="testId"> /// The TestId for the test performed. /// </param> /// <returns> /// A TorqueTest with properties populated from the database. If /// the record is not found in the database, return null. /// </returns> private static TorqueTest GetTestById(string testId) { SqlConnection conn = null; FullyReversedTorqueTest existingTest = null; var sel = "up_GetTestById"; try { conn = TwisterConnection(); SqlCommand cmd = CreateCommand(conn, sel); cmd.Parameters.AddWithValue("@testId", testId); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { existingTest = new FullyReversedTorqueTest(); existingTest.TestId = dr["TestId"] as string; existingTest.TestTemplateId = (int)dr["TestTemplateId"]; // get the employee than ran the test, the class loads the rest. BenchOperator employee = new BenchOperator(dr["EmployeeNumber"] as string); existingTest.WorkOrder = dr["WorkId"] as string; if (dr["TestDate"] == DBNull.Value) { existingTest.StartDate = null; } else { existingTest.StartDate = (DateTime)dr["TestDate"]; } if (dr["StartTime"] != DBNull.Value) { existingTest.StartTime = (TimeSpan)dr["StartTime"]; } if (dr["FinishTime"] != DBNull.Value) { existingTest.FinishTime = (TimeSpan)dr["FinishTime"]; } } } cmd.Dispose(); return(existingTest); } catch (Exception) { throw; } finally { CloseConnection(conn); } }
private void ConfirmTestInfo() { try { if (PassedValidation()) { // finish up initializing the TestSession BenchOperator currentOperator = new BenchOperator(ClockNumber); currentOperator.GetName(); MainWindow_VM.Instance.TestSession.BenchOperator = currentOperator; MainWindow_VM.Instance.TestSession.WorkId = WorkOrder; if (MainWindow_VM.Instance.TestSession.TestTemplate.Id == (int)TestType.TorsionTestToFailure) { MainWindow_VM.Instance.CurrentViewModel = MainWindow_VM.Instance.UnidirectionalToFailureTestVm; var vm = (UnidirectionalTorqueTest_VM)MainWindow_VM.Instance.CurrentViewModel; // starts up the test monitoring. vm.PrepareToTest(MainWindow_VM.Instance.TestSession); } else if (MainWindow_VM.Instance.TestSession.TestTemplate.Id == (int)TestType.SteeringShaftTest_4000_inlbs) { // if this is a brand new part number with no calibration information, this shaft will need to be calibrated. WorkOrderInfo woInfo = new WorkOrderInfo(WorkOrder); woInfo.Load(); if (HasBeenCalibrated(woInfo.PartNumber, woInfo.Revision)) { MainWindow_VM.Instance.CurrentViewModel = MainWindow_VM.Instance.SteeringShaftTestVm; var vm = (FullyReversedTorqueTest_VM)MainWindow_VM.Instance.CurrentViewModel; // starts up the test monitoring. vm.PrepareToTest(MainWindow_VM.Instance.TestSession); } else { MainWindow_VM.Instance.CalibrationVm.PartNumber = woInfo.PartNumber; MainWindow_VM.Instance.CalibrationVm.Revision = woInfo.Revision; MainWindow_VM.Instance.CurrentViewModel = MainWindow_VM.Instance.CalibrationVm; } } else { throw new Exception("Invalid test type, must select a valid test type to continue."); } } } catch (Exception ex) { _log.Error(ex.ToString()); ErrorMessage = ex.Message; } }
internal static BenchOperator GetEmployeeById(string employeeId) { SqlConnection connection = null; try { var sp = "up_GetBenchOperatorByClockId"; connection = TwisterConnection(); SqlCommand command = CreateCommand(connection, sp); command.Parameters.Add(new SqlParameter("@ClockId", employeeId)); BenchOperator employee = null; using (SqlDataReader dr = command.ExecuteReader()) { while (dr.Read()) { employee = new BenchOperator(employeeId) { FirstName = dr["FirstName"] as string, LastName = dr["LastName"] as string }; // only one employee possible break; } } command.Dispose(); return(employee); } catch (Exception ex) { Debug.WriteLine(Messages.GeneralExceptionMessage(ex, "BenchOperatorDb.GetEmployeeById")); return(null); } finally { CloseConnection(connection); } }