Пример #1
0
        /* -------------------------- HOUSEWORK -------------------------- */

        public static List <Housework> HouseworkTableGetByID(int homeID)
        {
            string           sqlCMD     = $"SELECT * FROM Housework WHERE homeID='{homeID}'";
            DataTable        dataTable  = GetDataTable(sqlCMD);
            List <Housework> houseworks = new List <Housework>();
            List <Chore>     chores     = ChoreTableGetByID(homeID);

            foreach (DataRow row in dataTable.Rows)
            {
                List <String> answers = new List <String>();
                answers.Add(row.Field <String>("answer1"));
                answers.Add(row.Field <String>("answer2"));
                answers.Add(row.Field <String>("answer3"));
                int choreID = row.Field <int>("choreID");

                foreach (Chore chore in chores)
                {
                    if (chore.ID == choreID)
                    {
                        Housework housework = new Housework(answers, chore);
                        housework.IDh = row.Field <int>("ID");
                        houseworks.Add(housework);
                        break;
                    }
                }
            }

            return(houseworks);
        }
Пример #2
0
 private void button_DontDoIt_Click(object sender, EventArgs e)
 {
     if (dontDoItHousework != null)
     {
         Housework housework = (Housework)dontDoItHousework[0];
         housework.RemoveFromDatabase();
         mainScreen.home.Calendar.DeleteOccasion(dontDoItHousework);
         FillListBoxes();
         ClearShowBox();
         dontDoItHousework = null;
     }
 }
Пример #3
0
        public static bool OccasionTableUpdate(Housework housework)
        {
            string answer1 = "";
            string answer2 = "";
            string answer3 = "";

            if (housework.Answers.Count > 2)
            {
                answer1 = housework.Answers[0];
                answer2 = housework.Answers[1];
                answer3 = housework.Answers[2];
            }
            else if (housework.Answers.Count > 2)
            {
                answer1 = housework.Answers[0];
                answer2 = housework.Answers[1];
            }
            else if (housework.Answers.Count > 1)
            {
                answer3 = housework.Answers[0];
            }


            if (!ConnectToDatabase())
            {
                return(false);
            }
            string     sqlCMD  = "UPDATE Housework SET answer1=@answer1, answer2=@answer2, answer3=@answer3 WHERE ID = @ID";
            SqlCommand command = new SqlCommand(sqlCMD, connection);

            command.Parameters.AddWithValue("@answer1", answer1);
            command.Parameters.AddWithValue("@answer2", answer2);
            command.Parameters.AddWithValue("@answer3", answer3);

            command.ExecuteNonQuery();

            DisconnectFromDatabase();
            return(true);
        }
Пример #4
0
        public static int HouseworkTableAdd(Housework housework)
        {
            string answer1 = "";
            string answer2 = "";
            string answer3 = "";

            if (housework.Answers.Count > 2)
            {
                answer1 = housework.Answers[0];
                answer2 = housework.Answers[1];
                answer3 = housework.Answers[2];
            }
            else if (housework.Answers.Count > 1)
            {
                answer1 = housework.Answers[0];
                answer2 = housework.Answers[1];
            }
            else if (housework.Answers.Count > 0)
            {
                answer1 = housework.Answers[0];
            }



            if (!ConnectToDatabase())
            {
                return(0);
            }
            string sqlCMD = $"INSERT INTO Housework(choreID, answer1, answer2, answer3,homeID) OUTPUT INSERTED.ID " +
                            $"VALUES ({housework.ID}, '{answer1}', '{answer2}', '{answer3}', {housework.HomeID})";

            SqlCommand command      = new SqlCommand(sqlCMD, connection);
            int        houseworkKey = (int)command.ExecuteScalar();

            DisconnectFromDatabase();
            return(houseworkKey);
        }
Пример #5
0
        public void FillListBoxes()
        {
            listBox_ChoreEvent.Items.Clear();
            listBox_Chores.Items.Clear();
            listBox_Today.Items.Clear();
            listBox_TodayEvent.Items.Clear();
            DateTime dateTime = DateTime.Now;

            foreach (Chore chore in chores)
            {
                bool isToday   = false;
                var  isNumeric = int.TryParse(chore.Frequency, out int n);
                if (chore.Frequency == "D")
                {
                    isToday = true;
                }
                else if (isNumeric && n == dateTime.Day)
                {
                    isToday = true;
                }
                else if (chore.Frequency.Contains(dateTime.DayOfWeek.ToString().Substring(0, 2)))
                {
                    isToday = true;
                }
                if (isToday)
                {
                    List <List <object> > todayList = mainScreen.home.Calendar.GetDaysOccasions(dateTime, typeof(Housework));
                    bool skip = false;
                    foreach (List <Object> occasion in todayList)
                    {
                        Housework housework = (Housework)occasion[0];
                        if (housework.Name == chore.Name)
                        {
                            var startTime = ((DateTime)occasion[1]).ToString("HH:mm");
                            var endDate   = ((DateTime)occasion[2]).ToString("HH:mm");
                            listBox_TodayEvent.Items.Add(chore.Name + " : (" + startTime + " > " + endDate + ")");
                            skip = true;
                            break;
                        }
                    }
                    if (!skip)
                    {
                        listBox_Today.Items.Add(chore.Name);
                    }
                }
            }


            for (int i = 1; i < 31; i++)
            {
                DateTime dateTime2 = dateTime.AddDays(i);
                foreach (Chore chore in chores)
                {
                    var  isNumeric2 = int.TryParse(chore.Frequency, out int n2);
                    bool isToday    = false;
                    if (chore.Frequency == "D")
                    {
                        isToday = true;
                    }
                    else if (isNumeric2 && n2 == dateTime2.Day)
                    {
                        isToday = true;
                    }
                    else if (chore.Frequency.Contains(dateTime2.DayOfWeek.ToString().Substring(0, 2)))
                    {
                        isToday = true;
                    }
                    if (isToday)
                    {
                        List <List <object> > todayList = mainScreen.home.Calendar.GetDaysOccasions(dateTime2, typeof(Housework));
                        bool skip = false;
                        foreach (List <Object> occasion in todayList)
                        {
                            Housework housework = (Housework)occasion[0];
                            if (housework.Name == chore.Name)
                            {
                                listBox_ChoreEvent.Items.Add(chore.Name + " : [" + dateTime2.DayOfWeek + " | " + dateTime2.ToShortDateString() + "]");
                                skip = true;
                                break;
                            }
                        }
                        if (!skip)
                        {
                            listBox_Chores.Items.Add(chore.Name + " : [" + dateTime2.DayOfWeek + " | " + dateTime2.ToShortDateString() + "]");
                        }
                    }
                }
            }
        }
Пример #6
0
        private void button_DoIt_Click(object sender, EventArgs e)
        {
            label_DoItError.Text    = "";
            label_DoItError.Visible = false;
            label_Finished.Hide();

            if (chosenChore == null)
            {
                label_DoItError.Visible = true;
                label_DoItError.Text    = "You have not chosen a chore!";
                return;
            }

            List <string> answers = new List <string>();

            if (label_Question1.Text.EndsWith("[Required]"))
            {
                if (textBox_Question1.Text.Trim() == "")
                {
                    label_DoItError.Visible = true;
                    label_DoItError.Text    = "The Answer can't be empty!";
                    return;
                }
                answers.Add(textBox_Question1.Text);
            }
            else if (label_Question1.Text.EndsWith("[Optional]"))
            {
                if (textBox_Question1.Text.Trim() == "")
                {
                    textBox_Question1.Text = "Not Answered";
                }
                answers.Add(textBox_Question1.Text);
            }
            if (label_Question2.Text.EndsWith("[Required]"))
            {
                if (textBox_Question2.Text.Trim() == "")
                {
                    label_DoItError.Visible = true;
                    label_DoItError.Text    = "The Answer can't be empty!";
                    return;
                }
                answers.Add(textBox_Question2.Text);
            }
            else if (label_Question2.Text.EndsWith("[Optional]"))
            {
                if (textBox_Question2.Text.Trim() == "")
                {
                    textBox_Question2.Text = "Not Answered";
                }
                answers.Add(textBox_Question2.Text);
            }
            if (label_Question3.Text.EndsWith("[Required]"))
            {
                if (textBox_Question3.Text.Trim() == "")
                {
                    label_DoItError.Visible = true;
                    label_DoItError.Text    = "The Answer can't be empty!";
                    return;
                }
                answers.Add(textBox_Question3.Text);
            }
            else if (label_Question3.Text.EndsWith("[Optional]"))
            {
                if (textBox_Question3.Text.Trim() == "")
                {
                    textBox_Question3.Text = "Not Answered";
                }
                answers.Add(textBox_Question3.Text);
            }

            if (dateTimePicker_Duration.Value.TimeOfDay.TotalMinutes == 0)
            {
                label_DoItError.Visible = true;
                label_DoItError.Text    = "The duration can't be zero!";
                return;
            }


            Housework housework = new Housework(answers, chosenChore);

            housework.AddToDatabase();
            mainScreen.home.Houseworks.Add(housework);
            label_Finished.Text = "Your housework has been added!";

            int startpos = chosenChoreName.IndexOf("|");

            if (startpos == -1)
            {
                chosenChoreListBox.Items.Remove(chosenChoreName);
                DateTime startDateTime = DateTime.Now.Date;
                startDateTime = startDateTime.AddMinutes(dateTimePicker_ChooseTime.Value.TimeOfDay.TotalMinutes);
                if (radioButton_Now.Checked)
                {
                    startDateTime = DateTime.Now;
                }
                DateTime endDateTime = startDateTime.AddMinutes(dateTimePicker_Duration.Value.TimeOfDay.TotalMinutes);
                mainScreen.home.Calendar.AddOccasions(housework, startDateTime, endDateTime, mainScreen.User);

                listBox_TodayEvent.Items.Add(housework.Name + " : (" + startDateTime.ToString("HH:mm") + " > " + endDateTime.ToString("HH:mm") + ")");
            }
            else
            {
                startpos++;
                chosenChoreListBox.Items.Remove(chosenChoreName);
                int      length        = chosenChoreName.IndexOf("]") - startpos;
                DateTime startDateTime = DateTime.Parse(chosenChoreName.Substring(startpos, length));
                startDateTime = startDateTime.AddMinutes(dateTimePicker_ChooseTime.Value.TimeOfDay.TotalMinutes);
                DateTime endDateTime = startDateTime.AddMinutes(dateTimePicker_Duration.Value.TimeOfDay.TotalMinutes);
                mainScreen.home.Calendar.AddOccasions(housework, startDateTime, endDateTime, mainScreen.User);

                listBox_ChoreEvent.Items.Add(housework.Name + " : [" + startDateTime.DayOfWeek + " | " + startDateTime.ToShortDateString() + "]");
            }

            ClearChosenChore();
        }
Пример #7
0
        private void ShowHouseworkDescription(object sender, EventArgs e)
        {
            ClearShowBox();
            if (((ListBox)sender).SelectedIndex == -1)
            {
                return;
            }
            ListBox listbox = (ListBox)sender;
            int     index   = listbox.SelectedIndex;

            if (listBox_Today != listbox)
            {
                listBox_Today.SelectedIndex = -1;
            }
            if (listBox_TodayEvent != listbox)
            {
                listBox_TodayEvent.SelectedIndex = -1;
            }
            if (listBox_ChoreEvent != listbox)
            {
                listBox_ChoreEvent.SelectedIndex = -1;
            }
            if (listBox_Chores != listbox)
            {
                listBox_Chores.SelectedIndex = -1;
            }
            if (listbox == null || listbox.SelectedIndex == -1)
            {
                return;
            }

            string listBoxName = listbox.SelectedItem.ToString();

            if (listBoxName.IndexOf(':') != -1)
            {
                listBoxName = listBoxName.Substring(0, (listBoxName.IndexOf(':') - 1));
            }

            foreach (Chore chore in chores)
            {
                if (chore.Name == listBoxName)
                {
                    showChore        = chore;
                    showChoreName    = listbox.SelectedItem.ToString();
                    showChoreListBox = (ListBox)sender;

                    label_ShowName.Text        = "Name: " + chore.Name;
                    label_ShowDescription.Text = "Description: " + chore.Description;
                    if (chore.Questions.Count > 0)
                    {
                        label_ShowQuestion1.Text = "Question 1: " + chore.Questions[0].Substring(1);
                    }
                    if (chore.Questions.Count > 1)
                    {
                        label_ShowQuestion2.Text = "Question 2: " + chore.Questions[1].Substring(1);
                    }
                    if (chore.Questions.Count > 2)
                    {
                        label_ShowQuestion3.Text = "Question 3: " + chore.Questions[2].Substring(1);
                    }
                    label_ShowType.Text = "Type: " + chore.Type;


                    string frequency = "";
                    var    isNumeric = int.TryParse(chore.Frequency, out int n);
                    if (chore.Frequency == "D")
                    {
                        frequency = "Daily";
                    }
                    else if (isNumeric)
                    {
                        frequency = "Every " + n + ". day of the month";
                    }
                    else
                    {
                        frequency = "Every";
                        if (chore.Frequency.Contains("Mo"))
                        {
                            frequency += " Monday,";
                        }
                        if (chore.Frequency.Contains("Tu"))
                        {
                            frequency += " Tuesday,";
                        }
                        if (chore.Frequency.Contains("We"))
                        {
                            frequency += " Wednesday,";
                        }
                        if (chore.Frequency.Contains("Th"))
                        {
                            frequency += " Thursday,";
                        }
                        if (chore.Frequency.Contains("Fr"))
                        {
                            frequency += " Friday,";
                        }
                        if (chore.Frequency.Contains("Sa"))
                        {
                            frequency += " Saturday,";
                        }
                        if (chore.Frequency.Contains("Su"))
                        {
                            frequency += " Sunday,";
                        }
                    }
                    label_ShowFrequency.Text = "Frequency: " + frequency;

                    button_ChooseChore.Enabled = true;
                    button_DontDoIt.Enabled    = false;
                    dontDoItHousework          = null;
                }
            }

            if (listbox == listBox_ChoreEvent || listbox == listBox_TodayEvent)
            {
                button_ChooseChore.Enabled = false;
                int      startpos;
                int      length;
                DateTime dateTime;
                if (listbox == listBox_ChoreEvent)
                {
                    startpos = showChoreName.IndexOf("|") + 1;
                    length   = showChoreName.IndexOf("]") - startpos;
                    dateTime = DateTime.Parse(showChoreName.Substring(startpos, length));
                }
                else
                {
                    dateTime = DateTime.Now;
                }

                List <List <object> > list = mainScreen.home.Calendar.GetDaysOccasions(dateTime, typeof(Housework));
                foreach (List <Object> occasion in list)
                {
                    Housework housework = (Housework)occasion[0];
                    if (housework.Name == listBoxName)
                    {
                        label_ShowDateTime.Text = "Date" + ((DateTime)occasion[1]).ToString(" dddd, d/MM/yy \n HH:mm - ") + ((DateTime)occasion[2]).ToString(" HH:mm");
                        var nickname = ((Person)occasion[3]).Nickname;
                        label_ShowPerson.Text = "Person: " + nickname;
                        if (nickname == mainScreen.User.Nickname)
                        {
                            label_ShowPerson.Text     += " (You)";
                            button_ChooseChore.Enabled = true;
                            button_DontDoIt.Enabled    = true;
                            dontDoItHousework          = occasion;
                        }
                        if (housework.Answers.Count > 0)
                        {
                            label_ShowAnswer1.Text = housework.Answers[0];
                        }
                        if (housework.Answers.Count > 1)
                        {
                            label_ShowAnswer2.Text = housework.Answers[1];
                        }
                        if (housework.Answers.Count > 2)
                        {
                            label_ShowAnswer3.Text = housework.Answers[2];
                        }
                    }
                }
            }
        }
Пример #8
0
        public CalendarInformationPopUp(List <object> occasion)
        {
            InitializeComponent();
            this.occasion = occasion;

            var      activity         = occasion[0];
            DateTime startingDateTime = (DateTime)occasion[1];
            DateTime endingDateTime   = (DateTime)occasion[2];
            Person   person           = (Person)occasion[3];



            label_Info2.Text = person.Nickname;
            label_Info3.Text = startingDateTime.ToString("HH:mm dd/MM/yyyy");
            label_Info4.Text = endingDateTime.ToString("HH:mm dd/MM/yyyy");

            label_Title2.Text = "Creator:";
            label_Title3.Text = "Starting Date:";
            label_Title4.Text = "Ending Date:";

            pictureBox1.Parent = this;
            this.Controls.SetChildIndex(pictureBox1, 0);

            Type type = activity.GetType();

            label_Activity.Text = type.Name;
            if (type == typeof(BusyTime))
            {
                BusyTime busyTime = (BusyTime)activity;

                label_Info1.Text = busyTime.Name;
                label_Info5.Text = busyTime.Type;

                pictureBox1.Image = imageList1.Images[0];

                label_Title1.Text = "Name:";
                label_Title5.Text = "Type:";
            }
            else if (type == typeof(Event))
            {
                Event @event = (Event)activity;

                label_Info1.Text = @event.Name;
                label_Info5.Text = @event.Type;

                pictureBox1.Image = imageList1.Images[1];

                label_Title1.Text = "Name:";
                label_Title5.Text = "Type:";
            }
            else if (type == typeof(Request))
            {
                Request request = (Request)activity;

                label_Info1.Text = request.Name;
                label_Info5.Text = request.AccepterName;
                label_Info6.Text = request.Description;

                pictureBox1.Image = imageList1.Images[3];

                label_Title1.Text = "Name:";
                label_Title5.Text = "Accepter:";
                label_Title6.Text = "Description:";
            }
            else if (type == typeof(Housework))
            {
                Housework housework = (Housework)activity;

                label_Info1.Text = housework.Name;
                label_Info5.Text = housework.Type;
                label_Info6.Text = housework.Description;

                pictureBox1.Image = imageList1.Images[2];

                label_Title1.Text = "Name:";
                label_Title5.Text = "Type:";
                label_Title6.Text = "Description:";

                string[] questions = { "", "", "" };
                string[] answers   = { "", "", "" };
                for (int i = 0; i < housework.Answers.Count; i++)
                {
                    answers[i] = housework.Answers[i];
                }
                for (int i = 0; i < housework.Questions.Count; i++)
                {
                    questions[i] = housework.Questions[i];
                }



                label_Info7.Text = answers[0];
                label_Info8.Text = answers[1];
                label_Info9.Text = answers[2];

                label_Title7.Text = questions[0];
                label_Title8.Text = questions[1];
                label_Title9.Text = questions[2];
            }

            GiveAllChildsDrag(this);
            Coloring();
        }
Пример #9
0
        public static bool HouseworkTableRemove(Housework housework)
        {
            string sqlCMD = $"DELETE FROM housework WHERE ID={housework.IDh}";

            return(RemoveRow(sqlCMD));
        }