protected override void CleanupCurrentTest() { if (TestIdReceived) { if (TorqueAngleChart != null && TorqueAngleChart.Series["series1"].Points.Count > 0) { TorqueTest completedTest = TestBench.Singleton.CompletedTests.LastOrDefault(); if (completedTest != null) { // add the new test to the grid. Session.CompletedTests.Add(completedTest); // show the start button and exit program buttons again. StartTestCommand.RaiseCanExecuteChanged(); ExitProgamCommand.RaiseCanExecuteChanged(); } } //clear out the data points (except the dummy point) ClearPointsFromChart(); // change it back. TestIdReceived = false; } }
/// <summary> /// Determines if the testId has already been used. /// </summary> /// <param name="testId"> /// A unique identifier for the test. /// </param> /// <returns> /// </returns> internal static bool InvalidTestId(string testId) { try { TorqueTest testInDb = GetTestById(testId); var oldTestFound = testInDb != null; if (oldTestFound) { return(true); } return(false); } catch (Exception) { throw; } }
internal static void SetTorqeTestParameters(SqlCommand cmd, TorqueTest torqueTest) { cmd.Parameters.Add(new SqlParameter { ParameterName = "@TestId", SqlDbType = SqlDbType.NVarChar, Value = torqueTest.TestId }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@TestTemplateId", SqlDbType = SqlDbType.Int, Value = torqueTest.TestTemplateId }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@EmployeeNumber", SqlDbType = SqlDbType.NVarChar, Value = torqueTest.Operator.ClockId }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@WorkId", SqlDbType = SqlDbType.NVarChar, Value = torqueTest.WorkOrder }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@TestDate", SqlDbType = SqlDbType.Date, Value = torqueTest.StartDate.Value.Date }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@StartTime", SqlDbType = SqlDbType.Time, Value = torqueTest.StartTime }); cmd.Parameters.Add(new SqlParameter { ParameterName = "@FinishTime", SqlDbType = SqlDbType.Time, Value = torqueTest.FinishTime }); // now see if it's a unidirectional test, so the direction must be know. var direction = "BD"; // both directions is default, see TestDirections table. UnidirectionalTorqueTest test = torqueTest as UnidirectionalTorqueTest; if (test != null) { if (test.Direction == TestDirection.Clockwise) { direction = "CW"; } else if (test.Direction == TestDirection.Counterclockwise) { direction = "CCW"; } } // now add the parameter cmd.Parameters.Add(new SqlParameter { ParameterName = "@Direction", SqlDbType = SqlDbType.NVarChar, Precision = 5, Value = direction }); }
internal static int SaveToDatabase(TorqueTest test) { SqlConnection conn = null; try { var rowsAffected = 0; var sel = "up_SaveTwisterTest"; conn = TwisterConnection(); SqlCommand cmd = CreateCommand(conn, sel); SetTorqeTestParameters(cmd, test); TransactionOptions options = new TransactionOptions(); /* It allow shared locks and read only committed data. That means * never read changed data that are in the middle of any transaction. */ options.IsolationLevel = IsolationLevel.ReadCommitted; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, options)) { // save the test. rowsAffected += cmd.ExecuteNonQuery(); var spDtPt = "up_SaveDataPoint"; cmd.Dispose(); cmd = CreateCommand(conn, spDtPt); // save each data point. foreach (Sample dataPoint in test.Data) { if (cmd.Parameters.Count == 0) { SetTestSampleParameters(cmd, dataPoint, test.TestId); } else { UpdateTestSampleParams(cmd, dataPoint); } // increment number of rows affected. rowsAffected += cmd.ExecuteNonQuery(); } scope.Complete(); } cmd.Dispose(); return(rowsAffected); } catch (Exception ex) { Debug.WriteLine(Msg.GeneralExceptionMessage(ex, "SaveToDatabase")); return(0); } finally { CloseConnection(conn); } }