Ejemplo n.º 1
0
        private void btn_AddChore_Click(object sender, EventArgs e)
        {
            lbl_AddChoreError.Visible = false;
            lbl_AddChoreError.Text    = "";
            label_FinishedNew.Hide();


            if (comboBox_Type.SelectedIndex == -1)
            {
                lbl_AddChoreError.Visible = true;
                lbl_AddChoreError.Text    = "Chore type can't be empty!";
                return;
            }
            if (textBox_Description.Text.Trim() == "")
            {
                lbl_AddChoreError.Visible = true;
                lbl_AddChoreError.Text    = "Chore description can't be empty!";
                return;
            }

            if (radioButton_Question1Disabled.Checked == false && textBox_Question1.Text.Trim() == "")
            {
                lbl_AddChoreError.Visible = true;
                lbl_AddChoreError.Text    = "Question 1 is empty! Either disable it or add a question.";
                return;
            }
            if (radioButton_Question2Disabled.Checked == false && textBox_Question2.Text.Trim() == "")
            {
                lbl_AddChoreError.Visible = true;
                lbl_AddChoreError.Text    = "Question 2 is empty! Either disable it or add a question.";
                return;
            }
            if (radioButton_Question3Disabled.Checked == false && textBox_Question3.Text.Trim() == "")
            {
                lbl_AddChoreError.Visible = true;
                lbl_AddChoreError.Text    = "Question 3 is empty! Either disable it or add a question.";
                return;
            }
            string name;
            string type = comboBox_Type.Text;

            if (textBox_Name.Text.Trim() != "")
            {
                if (IsTheNameUnique(textBox_Name.Text))
                {
                    name = textBox_Name.Text;
                }
                else
                {
                    lbl_AddChoreError.Visible = true;
                    lbl_AddChoreError.Text    = "The name already exists!";
                    return;
                }
            }
            else
            {
                name = FindAvailableChoreName(type, 0);
            }


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

            if (radioButton_Question1Optional.Checked)
            {
                questionList.Add("1" + textBox_Question1.Text);
            }
            else if (radioButton_Question1Required.Checked)
            {
                questionList.Add("0" + textBox_Question1.Text);
            }
            if (radioButton_Question2Optional.Checked)
            {
                questionList.Add("1" + textBox_Question2.Text);
            }
            else if (radioButton_Question2Required.Checked)
            {
                questionList.Add("0" + textBox_Question2.Text);
            }
            if (radioButton_Question3Optional.Checked)
            {
                questionList.Add("1" + textBox_Question3.Text);
            }
            else if (radioButton_Question3Required.Checked)
            {
                questionList.Add("0" + textBox_Question3.Text);
            }

            string frequency = "";

            if (radioButton_Daily.Checked)
            {
                frequency = "D";
            }
            else if (radioButton_Monthly.Checked)
            {
                frequency = numericUpDown_Monthly.Value.ToString();
            }
            else if (radioButton_Weekly.Checked)
            {
                if (checkBox_Monday.Checked)
                {
                    frequency += "Mo";
                }
                if (checkBox_Tuesday.Checked)
                {
                    frequency += "Tu";
                }
                if (checkBox_Wednesday.Checked)
                {
                    frequency += "We";
                }
                if (checkBox_Thursday.Checked)
                {
                    frequency += "Th";
                }
                if (checkBox_Friday.Checked)
                {
                    frequency += "Fr";
                }
                if (checkBox_Saturday.Checked)
                {
                    frequency += "Sa";
                }
                if (checkBox_Sunday.Checked)
                {
                    frequency += "Su";
                }
            }


            Chore chore = new Chore(name, type, textBox_Description.Text, frequency, questionList, mainScreen.home.ID);

            chore.AddToDatabase();

            chores.Add(chore);

            label_FinishedNew.Text = "Chore Added Succesfully!";
            label_FinishedNew.Show();

            listBox_Chores.Items.Add(chore.Name);

            ClearGroupBox(groupBox_NewChore);
        }