コード例 #1
0
        /**
         * Uses and in-line SQL statement to change the status of the given appointment
         * to given status
         *
         * parameters: AppointmentClass appointment, char status
         * returns: Boolean
         */
        public static Boolean updateAppointmentStatus(AppointmentClass apt, char status)
        {
            Boolean blnWasApptUpdated       = false;
            int     intNumberOfRowsAffected = 0;

            if (status == 'A')
            {
                return(false);
            }

            using (SqlConnection connection = getConnection())
            {
                connection.Open();
                StringBuilder sb = new StringBuilder();
                sb.Append($"Update Appointments Set Status = '{status}' Where AppointmentDate = '{apt.m_dtDateTime}' AND CustomerName = '{apt.m_strPatientName}'");
                String sql = sb.ToString();
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    intNumberOfRowsAffected = command.ExecuteNonQuery();

                    if (intNumberOfRowsAffected > 0)
                    {
                        blnWasApptUpdated = true;
                    }
                }
                return(blnWasApptUpdated);
            }
        }
コード例 #2
0
        /**
         * Uses and in-line SQL statement to create an AppointmentClass object with a given
         * date of the appointment
         *
         * parameters: String Datetime of Appointment
         * returns: Appointment object
         */
        public static AppointmentClass QueryDatabaseForAppointmentWithDateTime(String strDateTimeOfAppointment)
        {
            AppointmentClass acAppointmentToReturn = null;

            using (SqlConnection connection = getConnection())
            {
                connection.Open();
                StringBuilder sb = new StringBuilder();
                sb.Append($"SELECT TOP 1 * FROM Appointments As A WHERE A.AppointmentDate = '{strDateTimeOfAppointment}' AND A.Status = 'A'");
                String sql = sb.ToString();

                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            acAppointmentToReturn = new AppointmentClass(reader.GetString(0),
                                                                         reader.GetString(1),
                                                                         reader.GetString(2),
                                                                         reader.GetString(3),
                                                                         reader.GetDateTime(4),
                                                                         reader.GetDateTime(5),
                                                                         reader.GetSqlChars(6));
                            return(acAppointmentToReturn);
                        }
                    }
                }
            }
            return(acAppointmentToReturn);
        }