public List <TestTypeEntry> GetAllTestTypes() { SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT * FROM TestType ORDER BY TestTypeName ASC"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); List <TestTypeEntry> testTypes = new List <TestTypeEntry>(); if (reader.HasRows) { while (reader.Read()) { TestTypeEntry testType = new TestTypeEntry(); testType.TestTypeId = Convert.ToInt32(reader["TestTypeId"].ToString()); testType.TestTypeName = reader["TestTypeName"].ToString(); testTypes.Add(testType); } reader.Close(); } connection.Close(); return(testTypes); }
public int SaveTestType(TestTypeEntry testType) { if (IsTypeNameExists(testType)) { throw new Exception("Type Name Already Exists."); } return(testTypeGateway.SaveTestType(testType)); }
public int SaveTestType(TestTypeEntry testType) { SqlConnection connection = new SqlConnection(connectionString); string query = "INSERT INTO TestType VALUES('" + testType.TestTypeName + "')"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); int rowAffected = command.ExecuteNonQuery(); connection.Close(); return(rowAffected); }
public bool IsTypeNameExists(TestTypeEntry testType) { return(testTypeGateway.IsTypeNameExist(testType)); //TestTypeEntry existingTestType = testTypeGateway.IsTypeNameExist(testType); //if (existingTestType != null) //{ // return true; //} //else //{ // return false; //} }
public bool IsTypeNameExist(TestTypeEntry testType) { SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT * FROM TestType WHERE TestTypeName='" + testType.TestTypeName + "'"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); bool isTypeNameExist = false; if (reader.HasRows) { isTypeNameExist = true; } reader.Close(); connection.Close(); return(isTypeNameExist); }
protected void saveTestTypeButton_Click(object sender, EventArgs e) { try { TestTypeEntry testType = new TestTypeEntry(); testType.TestTypeName = testTypeTextbox.Text; if (testTypeManager.SaveTestType(testType) > 0) { messageLable.Text = "Test Type Successfully Saved"; LoadAllTestType(); testTypeTextbox.Text = ""; } else { messageLable.Text = "Save Failed"; } } catch (Exception exception) { messageLable.Text = exception.Message; } }