Пример #1
0
 public bool didMemberAttendSingleMeeting(Meeting meeting, Member member)
 {
     string query = "SELECT COUNT(*) FROM attendance WHERE member_id = " + member.Id + " AND meeting_id = " + meeting.Id + "";
     int returnCount = 0;
     using (SqlCeConnection con = this.connectionManager.getConnection())
     {
         con.Open();
         using (SqlCeCommand command = new SqlCeCommand(query, con))
         {
             command.CommandType = CommandType.Text;
             returnCount = (Int32)command.ExecuteScalar();
         }
     }
     return returnCount > 0 ? true : false;
 }
Пример #2
0
 public bool deleteMeeting(Meeting meeting)
 {
     string query = "DELETE FROM meeting WHERE meeting_id = " + meeting.Id + "";
     try
     {
         using (SqlCeConnection con = connectionManager.getConnection())
         {
             con.Open();
             using (SqlCeCommand command = new SqlCeCommand(query, con))
             {
                 int affectedRows = command.ExecuteNonQuery();
                 return affectedRows == 1 ? true : false;
             }
         }
     }
     catch (SqlCeException)
     {
         return false;
     }
 }
Пример #3
0
        private List<Meeting> getMeetings(string query)
        {
            List<Meeting> meetings = new List<Meeting>();

            using (SqlCeConnection con = connectionManager.getConnection())
            {
                con.Open();
                using (SqlCeCommand command = new SqlCeCommand(query, con))
                {
                    SqlCeDataAdapter adapter = new SqlCeDataAdapter(command);
                    DataTable data = new DataTable();
                    adapter.Fill(data);

                    if (data.Rows.Count > 0)
                    {
                        foreach (DataRow row in data.Rows)
                        {
                            Meeting meeting = new Meeting();
                            meeting.Id = int.Parse(row.ItemArray[0].ToString());
                            meeting.Date = Convert.ToDateTime(row.ItemArray[1].ToString());
                            meeting.Venue = row.ItemArray[2].ToString();
                            meetings.Add(meeting);
                        }
                    }
                }
                con.Close();
            }
            return meetings;
        }
Пример #4
0
 public Meeting updateMeeting(Meeting meeting)
 {
     string query = "UPDATE meeting SET meeting_date = @date, meeting_venue = @venue WHERE (meeting_id = " + meeting.Id + ")";
     return insertOrUpdate(query, meeting, false);
 }
Пример #5
0
 public Meeting createMeeting(Meeting meeting)
 {
     string query = "INSERT INTO meeting (meeting_date, meeting_venue) VALUES (@date, @venue)";
     return insertOrUpdate(query, meeting, true);
 }
Пример #6
0
        private Meeting insertOrUpdate(string query, Meeting meeting, bool newRecord)
        {
            try
            {
                using (SqlCeConnection con = connectionManager.getConnection())
                {
                    con.Open();
                    using (SqlCeCommand command = new SqlCeCommand(query, con))
                    {
                        command.Parameters.AddWithValue("@date", meeting.Date);
                        command.Parameters.AddWithValue("@venue", meeting.Venue);
                        int affectedRows = command.ExecuteNonQuery();

                        if (newRecord)
                        {
                            command.CommandText = "SELECT @@IDENTITY";
                            meeting.Id = Convert.ToInt32(command.ExecuteScalar().ToString());
                        }
                        return affectedRows == 1 ? meeting : null;
                    }
                }
            }
            catch (SqlCeException)
            {
                return null;
            }
        }
Пример #7
0
 public Attendance(Member member, Meeting meeting)
 {
     this.Attendee = member;
     this.AttendedMeeting = meeting;
 }
Пример #8
0
        private void CheckMeetingAttendance(Meeting meeting)
        {
            if (meeting != null)
            {
                this.dateMeetingDate.Value = meeting.Date;
                this.txtAddress.Text = meeting.Venue;
                List<Attendance> attendances = this.attendanceImpl.getAttendanceByMeetingId(meeting.Id);
                List<Member> attendees = new List<Member>();

                for (int i = 0; i < allAvailableMembers.Count; i++)
                {
                    this.clbxAttendees.SetItemChecked(i, false);
                }

                if (attendances.Count > 0)
                {
                    foreach (Attendance att in attendances)
                    {
                        attendees.Add(att.Attendee);
                    }
                    foreach (Member attendee in attendees)
                    {
                        for (int i = 0; i < allAvailableMembers.Count; i++)
                        {
                            if (allAvailableMembers[i].Id == attendee.Id)
                            {
                                this.clbxAttendees.SetItemChecked(i, true);
                                break;
                            }
                        }
                    }
                }
                this.lblMeetingDate.Text = meeting.Date.ToLongDateString();
                this.lblPresenceCount.Text = attendances.Count.ToString() + " members.";
            }
            else
            {
                this.dateMeetingDate.Value = DateTime.Today;
                this.txtAddress.Text = "";
                foreach (int i in this.clbxAttendees.CheckedIndices)
                {
                    this.clbxAttendees.SetItemCheckState(i, CheckState.Unchecked);
                }
                this.lblMeetingDate.Text = this.dateMeetingDate.Value.ToLongDateString();
                this.lblPresenceCount.Text = "0 members";
            }
        }
Пример #9
0
        private void btnSaveMeeting_Click(object sender, EventArgs e)
        {
            if (this.lstMeetings.SelectedIndices.Count != 0)
            {
                Meeting meeting;
                //Checks whether the selected meeting is fresh new or updatable.==>This is updatable
                if (this.lstMeetings.Items[this.lstMeetings.SelectedIndices[0]].BackColor != Color.OrangeRed)
                {
                    meeting = allAvailableMeetings[this.lstMeetings.SelectedIndices[0]];
                    meeting.Date = this.dateMeetingDate.Value;
                    meeting.Venue = this.txtAddress.Text;
                    if (this.meetingImpl.updateMeeting(meeting) != null)
                    {
                        List<Attendance> oldAttendances = this.attendanceImpl.getAttendanceByMeetingId(meeting.Id);
                        if (oldAttendances.Count > 0)
                        {
                            foreach (Attendance att in oldAttendances)
                            {
                                this.attendanceImpl.deleteAttendance(att);
                            }
                        }
                        if (this.clbxAttendees.CheckedItems.Count > 0)
                        {
                            for (int i = 0; i < this.clbxAttendees.CheckedItems.Count; i++)
                            {
                                Member member = allAvailableMembers[this.clbxAttendees.CheckedIndices[i]];
                                Attendance attendance = attendanceImpl.createAttendance(new Attendance(member, meeting));
                            }
                        }
                        this.lblStatus.ForeColor = Color.PaleGreen;
                        this.lblStatus.Text = "Mise à jour réussie...";
                    }
                    else
                    {
                        this.lblStatus.ForeColor = Color.OrangeRed;
                        this.lblStatus.Text = "Mise à jour échouée...";
                    }
                }
                //==>This is brand new!
                else
                {
                    meeting = new Meeting();
                    meeting.Date = this.dateMeetingDate.Value.Date;
                    meeting.Venue = this.txtAddress.Text;
                    Meeting createdMeeting = this.meetingImpl.createMeeting(meeting);
                    if (createdMeeting != null)
                    {
                        if (this.clbxAttendees.CheckedItems.Count > 0)
                        {
                            for (int i = 0; i < this.clbxAttendees.CheckedItems.Count; i++)
                            {
                                Member member = allAvailableMembers[this.clbxAttendees.CheckedIndices[i]];
                                Attendance attendance = attendanceImpl.createAttendance(new Attendance(member, createdMeeting));
                            }
                        }

                        this.lstMeetings.Items[0].BackColor = Color.Empty;
                        this.lblStatus.ForeColor = Color.PaleGreen;
                        this.lblStatus.Text = "Réunion créée...";
                    }
                    else
                    {
                        this.lblStatus.ForeColor = Color.OrangeRed;
                        this.lblStatus.Text = "Création de la réunion échouée...";
                    }
                }
                //To refresh the form
                this.MeetingsListPopulator(meetingImpl.getAllMeetings());
                this.AttendeesListPopulator(memberImpl.getAllMembers());
                this.CheckMeetingAttendance(meeting);
            }
            else
            {
                this.lblStatus.ForeColor = Color.OrangeRed;
                this.lblStatus.Text = "No selection made...";
            }
        }