コード例 #1
0
        /*
         * Setting up parameters and inserting values into the car_class if a new rate needs to be added
         * to the car class table
         */
        public void addCar_Rate(Car_Rate_Entity_Class rate_Class)
        {
            /*
              * Creating a connection  to connect to the database calling Orc class that returns the connection string
              */
            OracleConnection connection = new OracleConnection(OrcConnection.connection());

            OracleCommand cmd = new OracleCommand();

            try
            {
                connection.Open();
                OracleTransaction transaction = connection.BeginTransaction();
                cmd.Transaction = transaction;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "INSERT INTO Car_Class VALUES(car_rate_seq.NEXTVAL,:description,:car_rate)";

                var description = new OracleParameter(":description", OracleType.VarChar);
                description.Value = rate_Class.Description;
                cmd.Parameters.Add(description);

                var car_rate = new OracleParameter(":car_rate", OracleType.Number);
                car_rate.Value = rate_Class.Car_rate;
                cmd.Parameters.Add(car_rate);

                cmd.Connection = connection;
                cmd.ExecuteNonQuery();
                transaction.Commit();
                connection.Close();

                MessageBox.Show("Insert complete successfully");
            }
            catch (Exception)
            {
                MessageBox.Show("Insert Did not complete successfully");
            }
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Car_Rate_Entity_Class rate_Class = new Car_Rate_Entity_Class();
            Enter_Car_Access rate = new Enter_Car_Access();

            //This checks if a value is entered into the  textbox
            if(string.IsNullOrEmpty(txt_Desc.Text))
            {
                errorProvider1.SetError(txt_Desc , "Please choose a Description");
            }

            // this means any character that IS NOT a-z OR A-Z will not be accepted
            else if (System.Text.RegularExpressions.Regex.IsMatch(txt_Desc.Text , "[^a-zA-Z]"))
                 {
                     MessageBox.Show("Please enter only Sting Characters\n into the Description Field");
                 }

                // this means only digits and dot will  be accepted
                  else if (System.Text.RegularExpressions.Regex.IsMatch(txt_Rate.Text , "[^0-9 \\.]"))
                        {
                             MessageBox.Show("Please enter only numbers\n into the Car_Rate Field");
                        }

                        //This checks if a value is entered into the  textbox
                           else if (string.IsNullOrEmpty(txt_Rate.Text))
                               {
                                   errorProvider2.SetError(txt_Rate , "You must Supply a Car Rate");
                               }

                                else
                                    {
                                        rate_Class.Description = txt_Desc.Text;
                                        rate_Class.Car_rate = double.Parse(txt_Rate.Text);
                                        rate.addCar_Rate(rate_Class);
                                    }
        }