コード例 #1
0
        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);
        }
コード例 #2
0
        //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);
        }
コード例 #3
0
 public int SaveTest(TestSetupEntry test)
 {
     if (IsTestNameExists(test))
     {
         throw new Exception("Test Name already exists");
     }
     return(testSetupGateway.SaveTest(test));
 }
コード例 #4
0
        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();
            }
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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;
            }
        }
コード例 #8
0
 public bool IsTestNameExists(TestSetupEntry test)
 {
     return(testSetupGateway.IsTestNameExist(test));
 }