public List <TestSetupEntry> GetAllTestWithType() { SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT * FROM Tests ORDER BY TestName ASC"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); List <TestSetupEntry> tests = new List <TestSetupEntry>(); if (reader.HasRows) { while (reader.Read()) { TestSetupEntry test = new TestSetupEntry(); test.TestId = Convert.ToInt32(reader["TestId"].ToString()); test.TestName = reader["TestName"].ToString(); test.TestFee = Convert.ToDecimal(reader["TestFee"].ToString()); test.TestTypeId = Convert.ToInt32(reader["TestTypeId"].ToString()); tests.Add(test); } reader.Close(); } connection.Close(); return(tests); }
//public double GetFee(string id) //{ // SqlConnection connection = new SqlConnection(connectionString); // string query = "SELECT * FROM Tests WHERE TestId = '" + id + "'"; // SqlCommand command = new SqlCommand(query, connection); // connection.Open(); // SqlDataReader reader = command.ExecuteReader(); // double fee = 0; // while (reader.Read()) // { // fee = Convert.ToDouble(reader["Fee"].ToString()); // } // reader.Close(); // connection.Close(); // return fee; //} public TestSetupEntry GetTestByTestId(int testId) { SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT * FROM Tests WHERE TestId = '" + testId + "'"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); TestSetupEntry test = null; if (reader.HasRows) { while (reader.Read()) { test = new TestSetupEntry(); test.TestId = Convert.ToInt32(reader["TestId"].ToString()); test.TestName = reader["TestName"].ToString(); test.TestFee = Convert.ToDecimal(reader["TestFee"].ToString()); test.TestTypeId = Convert.ToInt32(reader["TestTypeId"].ToString()); } reader.Close(); } connection.Close(); return(test); }
public int SaveTest(TestSetupEntry test) { if (IsTestNameExists(test)) { throw new Exception("Test Name already exists"); } return(testSetupGateway.SaveTest(test)); }
public int SaveTest(TestSetupEntry test) { SqlConnection connection = new SqlConnection(connectionString); string query = "INSERT INTO Tests VALUES('" + test.TestName + "', " + test.TestFee + ", " + test.TestTypeId + ")"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); int rowAffected = command.ExecuteNonQuery(); connection.Close(); return(rowAffected); }
protected void selectTestDropDownList_SelectedIndexChanged(object sender, EventArgs e) { if (selectTestDropDownList.SelectedIndex == 0) { feeTextBox.Text = string.Empty; } else { int testId = Convert.ToInt32(selectTestDropDownList.SelectedValue.ToString()); ViewState["testId"] = testId; TestSetupEntry test = testSetupManager.GetAllTestById(testId); feeTextBox.Text = test.TestFee.ToString(); } }
public bool IsTestNameExist(TestSetupEntry test) { SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT * FROM Tests WHERE TestName='" + test.TestName + "'"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); bool isTestNameExist = false; if (reader.HasRows) { isTestNameExist = true; } reader.Close(); connection.Close(); return(isTestNameExist); }
protected void saveButton_Click(object sender, EventArgs e) { try { TestSetupEntry test = new TestSetupEntry(); test.TestName = testNameTextBox.Text; test.TestFee = Convert.ToDecimal(feeTextBox.Text); test.TestTypeId = Convert.ToInt32(testTypeDropDownList.SelectedValue); if (testSetupManager.SaveTest(test) > 0) { messageLable.Text = "Test Successfully Saved"; LoadAllTests(); ClearForm(); } } catch (Exception exception) { messageLable.Text = exception.Message; } }
public bool IsTestNameExists(TestSetupEntry test) { return(testSetupGateway.IsTestNameExist(test)); }