Пример #1
0
        private void DeleteTrainingSessionButton_Click(object sender, EventArgs e)
        {
            DataRowView     rowView    = TrainingSessionComboBox.SelectedItem as DataRowView;
            TrainingSession newSession = new TrainingSession();

            if (rowView != null)
            {
                newSession.SessionId = (rowView[0].ToString());
                if (controller.DeleteObject(newSession) == true)
                {
                    SessionResponseTextBox.Text = "booking deleted";
                }
                else
                {
                    SessionResponseTextBox.Text = "cannot delete trainingsession that has bookings";
                }


                this.Populate();
            }
            else
            {
                SessionResponseTextBox.Text = "select session to delete";
            }
        }
Пример #2
0
        public Boolean DeleteBookingToDatabase(TrainingSession session, GymMember member)
        {
            SqlCommand myCommand = new SqlCommand();

            session.StartTime.AddMilliseconds(000);
            long   memberId    = Convert.ToInt64(member.MemberID);
            long   sessionId   = Convert.ToInt64(session.SessionId);
            string commandText = $"delete from Booking where mId= '{memberId}' and tId = '{sessionId}';";

            using (sqlCon = new SqlConnection(conString))
            {
                try
                {
                    sqlCon.Open();
                    myCommand.CommandText = commandText;
                    myCommand.Connection  = sqlCon;
                    int nbrOfRows = myCommand.ExecuteNonQuery();
                    if (nbrOfRows == 0)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
                catch (SqlException ex)
                {
                    return(false);
                }
            }
        }
 public Boolean DeleteBooking(TrainingSession session, GymMember member)
 {
     if (dal.DeleteBookingToDatabase(session, member) == true)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
        //tar in värden från interface & skapar en ny session m.h.a. AddObjectToDatabase i dal

        public TrainingSession CreateTrainingSession(string sessionId, string sessionInstructor, string sessionRoomNumber, string sessionType,

                                                     DateTime sessionStartTime, int sessionLength)
        {
            TrainingSession newSession = new TrainingSession();

            newSession.SessionId  = sessionId;
            newSession.Instructor = sessionInstructor;
            newSession.RoomNumber = sessionRoomNumber;
            newSession.Type       = sessionType;
            newSession.StartTime  = sessionStartTime;
            newSession.Length     = sessionLength;

            return(dal.AddObjectToDatabase(newSession) as TrainingSession);
        }
        public Boolean CreateBooking(TrainingSession session, GymMember member)
        {
            Booking booking = new Booking();

            booking.GymMember       = member;
            booking.TrainingSession = session;
            booking.BookingId       = CreateBookingId().ToString();
            if (dal.AddBookingToDatabase(booking.BookingId, session, member) == true)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #6
0
        private void CreateBooking_Click(object sender, EventArgs e)
        {
            DataRowView     memberRow  = BookGymMemberComboBox.SelectedItem as DataRowView;
            DataRowView     sessionRow = BookTrainingSessionCombobox.SelectedItem as DataRowView;
            GymMember       member     = new GymMember(memberRow[0].ToString());
            TrainingSession session    = new TrainingSession();

            session.SessionId = sessionRow[0].ToString();
            if (controller.CreateBooking(session, member) == true)
            {
                long memberId  = Convert.ToInt64(member.MemberID);
                long sessionId = Convert.ToInt64(session.SessionId);
                BookingMessageTextBox.Text      = $"booking for member = {memberId} added for Trainingsession = {sessionId}";
                BookTrainingGridView.DataSource = controller.DisplayBookingForObject(member);
            }
            else
            {
                BookingMessageTextBox.Text = "booking already exists";
            }
        }
Пример #7
0
        private void DeleteBooking_Click(object sender, EventArgs e)
        {
            DataRowView memberRow  = BookGymMemberComboBox.SelectedItem as DataRowView;
            DataRowView sessionRow = BookTrainingSessionCombobox.SelectedItem as DataRowView;
            GymMember   member     = new GymMember();

            member.MemberID = (memberRow[0].ToString());
            TrainingSession session = new TrainingSession();

            session.SessionId = sessionRow[0].ToString();
            if (controller.DeleteBooking(session, member) == true)
            {
                BookingMessageTextBox.Text      = $"booking for member = {member.MemberID} deleted for Trainingsession = {session.SessionId}";
                BookTrainingGridView.DataSource = controller.DisplayBookingForObject(member);
            }
            else
            {
                BookingMessageTextBox.Text = "booking doesnt exist";
            }
        }
Пример #8
0
 private void CreateTrainingSessionButton_Click(object sender, EventArgs e)
 {
     if (TrainingSessionComboBox.SelectedItem is null)
     {
         if (SessionInstructorComboBox.SelectedItem != null && SessionRoomNbrComboBox.SelectedItem != null && SessionTypeComboBox.SelectedItem != null && SessionRoomNbrComboBox.SelectedItem != null)
         {
             String   sessionInstructor = SessionInstructorComboBox.SelectedItem.ToString();
             String   sessionType       = SessionTypeComboBox.SelectedItem.ToString();
             DateTime sessionStartTime  = SessionDateTimePicker.Value;
             Console.WriteLine(sessionStartTime);
             string date = sessionStartTime.ToString("yyyy-MM-dd HH:mm:ss.fff");
             sessionStartTime = DateTime.ParseExact(date, "yyyy-MM-dd HH:mm:ss.fff", null);
             int             sessionLength     = 1;
             String          sessionRoomNumber = SessionRoomNbrComboBox.SelectedItem.ToString();
             int             sessionId         = controller.CreateTrainingSessionId();
             TrainingSession session           = controller.CreateTrainingSession(sessionId.ToString(), sessionInstructor, sessionRoomNumber, sessionType, sessionStartTime, sessionLength);
             if (session == null)
             {
                 SessionResponseTextBox.Text = "session already exists for this instructor at this time";
             }
             else
             {
                 SessionResponseTextBox.Text = "session added";
                 this.Populate();
             }
         }
         else
         {
             SessionResponseTextBox.Text = "Please make sure all fields have been filled in.";
         }
     }
     else
     {
         SessionResponseTextBox.Text = "please select --new trainingsession--";
         this.Populate();
     }
 }
Пример #9
0
        private void UpdateTrainingSessionButton_Click_1(object sender, EventArgs e)
        {
            Console.WriteLine("hej");
            DataRowView rowView = TrainingSessionComboBox.SelectedItem as DataRowView;

            if (TrainingSessionComboBox.SelectedItem is null)
            {
                SessionResponseTextBox.Text = "pick session to update";
            }
            else
            {
                if (SessionInstructorComboBox.SelectedItem != null && SessionRoomNbrComboBox.SelectedItem != null && SessionTypeComboBox.SelectedItem != null && SessionRoomNbrComboBox.SelectedItem != null)
                {
                    TrainingSession session = new TrainingSession();
                    session.Instructor = SessionInstructorComboBox.SelectedItem.ToString();
                    session.Type       = SessionTypeComboBox.SelectedItem.ToString();
                    session.StartTime  = SessionDateTimePicker.Value;
                    session.Length     = 1;
                    session.RoomNumber = SessionRoomNbrComboBox.SelectedItem.ToString();
                    session.SessionId  = rowView[0].ToString();
                    session            = controller.UpdateObject(session) as TrainingSession;
                    if (session == null)
                    {
                        SessionResponseTextBox.Text = "session already exists for this instructor at this time";
                    }
                    else
                    {
                        SessionResponseTextBox.Text = "session added";
                        this.Populate();
                    }
                }
                else
                {
                    SessionResponseTextBox.Text = "Please make sure all fields have been filled in.";
                }
            }
        }
Пример #10
0
        public Boolean AddBookingToDatabase(String bookingId, TrainingSession session, GymMember member)
        {
            SqlCommand myCommand    = new SqlCommand();
            long       memberId     = Convert.ToInt64(member.MemberID);
            long       sessionId    = Convert.ToInt64(session.SessionId);
            string     commandText1 = $"select * from Booking b where b.tId='{sessionId}' and b.mId='{memberId}';";
            string     commandText2 = $"insert into Booking (bookingId,tId,mId) values('{bookingId}','{session.SessionId}','{member.MemberID}');";

            using (sqlCon = new SqlConnection(conString))
            {
                try
                {
                    sqlCon.Open();
                    SqlDataReader dr;
                    myCommand.CommandText = commandText1;
                    myCommand.Connection  = sqlCon;
                    dr = myCommand.ExecuteReader();
                    if (!dr.HasRows)
                    {
                        dr.Close();
                        myCommand.CommandText = commandText2;
                        myCommand.Connection  = sqlCon;
                        int nbrOfRows = myCommand.ExecuteNonQuery();
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch (SqlException ex)
                {
                    return(false);
                }
            }
        }