Exemplo n.º 1
0
        private void button_AddBill_Click(object sender, EventArgs e)
        {
            label_Error.Text = "";
            label_Error.Hide();
            label_Finished.Hide();

            if (textBox_Name.Text == "")
            {
                label_Error.Text = "Name can't be empty";
                label_Error.Show();
                return;
            }
            else if (textBox_Currency.Text == "")
            {
                label_Error.Text = "Currency can't be empty";
                label_Error.Show();
                return;
            }
            else if (comboBox_Type.SelectedIndex == -1)
            {
                label_Error.Text = "Type can't be empty";
                label_Error.Show();
                return;
            }
            int frequency = 0;

            if (checkBox_Yearly.Checked)
            {
                frequency = 1;
            }


            string   name       = textBox_Name.Text;
            string   type       = comboBox_Type.SelectedItem.ToString();
            int      cost       = (int)numericUpDown_Cost.Value;
            string   currency   = textBox_Currency.Text;
            DateTime paymentDue = dateTimePicker_PaymentDue.Value;

            if (this.bill == null)
            {
                Bill bill = new Bill(name, type, cost, currency, paymentDue, frequency, mainScreen.home.ID);
                mainScreen.home.Bills.Add(bill);
                label_Finished.Text = "Bill Created Successfully!";
            }
            else
            {
                bill.Name       = textBox_Name.Text;
                bill.Currency   = textBox_Currency.Text;
                bill.Cost       = (int)numericUpDown_Cost.Value;
                bill.Type       = comboBox_Type.SelectedItem.ToString();
                bill.PaymentDue = dateTimePicker_PaymentDue.Value;

                Database.BillTableUpdate(bill);
                this.Parent.Controls.Remove(this);
                viewList.DrawObjects();
                label_Finished.Text = "Bill Updated Successfully!";
            }

            label_Finished.Show();
        }
Exemplo n.º 2
0
        private void button_CreateBusyTime_Click(object sender, EventArgs e)
        {
            label_Error.Text = "";
            label_Error.Hide();
            label_Finished.Hide();

            if (textBox_Name.Text == "" || textBox_Name.Text == null)
            {
                label_Error.Text = "Name can't be empty";
                label_Error.Show();
                return;
            }
            if (textBox_Description.Text == "" || textBox_Description.Text == null)
            {
                label_Error.Text = "Description can't be empty";
                label_Error.Show();
                return;
            }
            if (comboBox_Type.SelectedIndex == -1)
            {
                label_Error.Text = "Type can't be empty";
                label_Error.Show();
                return;
            }
            if (checkedListBox_Frequency.CheckedItems.Count == 0)
            {
                label_Error.Text = "Frequency can't be empty";
                label_Error.Show();
                return;
            }
            if ((dateTimePicker_EndingTime.Value.TimeOfDay - dateTimePicker_StartingTime.Value.TimeOfDay).TotalMinutes <= 0)
            {
                label_Error.Text = "Ending time can't be earlier than Starting time!";
                label_Error.Show();
                return;
            }


            string   name          = textBox_Name.Text;
            string   description   = textBox_Description.Text;
            string   type          = comboBox_Type.SelectedItem.ToString();
            TimeSpan startDateTime = dateTimePicker_StartingTime.Value.TimeOfDay;
            TimeSpan endDateTime   = dateTimePicker_EndingTime.Value.TimeOfDay;
            string   frequency     = "";

            foreach (object item in checkedListBox_Frequency.CheckedItems)
            {
                frequency += item.ToString().Substring(0, 2);
            }

            if (busyTime == null)
            {
                BusyTime busyTime = new BusyTime(name, type, description, frequency, mainScreen.User.ID, startDateTime, endDateTime);
                mainScreen.User.BusyTimes.Add(busyTime);
                if (mainScreen.home != null)
                {
                    mainScreen.home.BusyTimes.Add(busyTime);
                }
                ClearBoxes();
                label_Finished.Text = "Busy Time Created Successfully!";
            }
            else
            {
                busyTime.Name        = name;
                busyTime.Description = description;
                busyTime.Frequency   = frequency;
                busyTime.Type        = comboBox_Type.SelectedItem.ToString();
                busyTime.StartTime   = startDateTime;
                busyTime.EndTime     = endDateTime;


                Database.BusyTimeTableUpdate(busyTime);
                this.Parent.Controls.Remove(this);
                viewList.DrawObjects();

                label_Finished.Text = "Busy Time Updated Successfully!";
            }
            label_Finished.Show();
        }