示例#1
0
文件: Session.cs 项目: nfearnley/ADD
 public Session()
 {
     course = new Course();
     instructor = new Instructor();
     room = new Room();
 }
示例#2
0
        // Add Instructor, return InstructorID
        public static int AddInstructor(Instructor instructor)
        {
            int instructorID = -1;

            // Setup Connection
            using (DatabaseConnection db = new DatabaseConnection("dbo.AddInstructor"))
            {
                // Set Parameters
                AddParameters(instructor, db.comm);

                // Open Connection
                db.conn.Open();

                // Execute Command and Read Response
                instructorID = Convert.ToInt32(db.comm.ExecuteScalar());
            }

            return instructorID;
        }
示例#3
0
        // Update Instructor, return number of rows affected
        public static int UpdateInstructor(Instructor instructor, Instructor oldInstructor)
        {
            int rowsAffected = 0;

            // Setup Connection
            using (DatabaseConnection db = new DatabaseConnection("dbo.UpdateInstructor"))
            {
                // Set Parameters
                AddParameters(instructor, db.comm);
                AddOldParameters(oldInstructor, db.comm);

                // Open Connection
                db.conn.Open();

                // Execute Command and Read Response
                rowsAffected = db.comm.ExecuteNonQuery();
            }

            return rowsAffected;
        }
示例#4
0
 // Set Parameters
 private static void AddParameters(Instructor instructor, SqlCommand comm)
 {
     comm.Parameters.AddWithValue("AddressCity", instructor.InstructorAddressCity);
     comm.Parameters.AddWithValue("AddressCountry", instructor.InstructorAddressCountry);
     comm.Parameters.AddWithValue("AddressLine1", instructor.InstructorAddressLine1);
     comm.Parameters.AddWithValue("AddressLine2", instructor.InstructorAddressLine2 == null ? (object)DBNull.Value : instructor.InstructorAddressLine2); // Check for null
     comm.Parameters.AddWithValue("AddressPostalCode", instructor.InstructorAddressPostalCode);
     comm.Parameters.AddWithValue("AddressRegion", instructor.InstructorAddressRegion);
     comm.Parameters.AddWithValue("AltPhone", instructor.InstructorAltPhone == null ? (object)DBNull.Value : instructor.InstructorAltPhone); // Check for null
     comm.Parameters.AddWithValue("FirstName", instructor.InstructorFirstName);
     comm.Parameters.AddWithValue("HomePhone", instructor.InstructorHomePhone);
     comm.Parameters.AddWithValue("LastName", instructor.InstructorLastName);
 }
示例#5
0
 public static Instructor ReadInstructor(SqlDataReader reader)
 {
     Instructor instructor = new Instructor();
     instructor.InstructorID = (int)reader["InstructorID"];
     instructor.InstructorAddressCity = (string)reader["InstructorAddressCity"];
     instructor.InstructorAddressCountry = (string)reader["InstructorAddressCountry"];
     instructor.InstructorAddressLine1 = (string)reader["InstructorAddressLine1"];
     instructor.InstructorAddressLine2 = reader["InstructorAddressLine2"] as string; // Allow null
     instructor.InstructorAddressPostalCode = (string)reader["InstructorAddressPostalCode"];
     instructor.InstructorAddressRegion = (string)reader["InstructorAddressRegion"];
     instructor.InstructorAltPhone = reader["InstructorAltPhone"] as string; // Allow null
     instructor.InstructorFirstName = (string)reader["InstructorFirstName"];
     instructor.InstructorHomePhone = (string)reader["InstructorHomePhone"];
     instructor.InstructorLastName = (string)reader["InstructorLastName"];
     return instructor;
 }