Esempio n. 1
0
        /// <summary>
        /// This methods validates the data before Adding or editing, depending on the state.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SumbitbBtn_Click(object sender, EventArgs e)
        {
            decimal MyAmount;
            int     MyID;

            switch (UserCache.ActualDebtChildState)
            {
            case 0:     //Add Debt State
            {
                if (DescriptionTBox.Text == "Ex: Pay to Joe" ||
                    AmountTBox.Text == "Ex: 1000")
                {
                    MessageBox.Show("Fill the fields with your data.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (string.IsNullOrWhiteSpace(IDTBox.Text) ||
                    string.IsNullOrWhiteSpace(DescriptionTBox.Text) ||
                    string.IsNullOrWhiteSpace(AmountTBox.Text))
                {
                    MessageBox.Show("Some fields may be empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (!Int32.TryParse(IDTBox.Text, out MyID) ||
                    !decimal.TryParse(AmountTBox.Text, out MyAmount) ||
                    MyID <= 0 ||
                    MyAmount <= 0)
                {
                    MessageBox.Show("Some numeric fields may be invalid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (DateTime.Compare(DateTime.Now, DeadLinePicker.Value) > 0)
                {
                    MessageBox.Show("DeadLine is before today.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                DialogResult DR = MessageBox.Show("Are you sure to add this Debt?", "Verfication", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (DR == DialogResult.Yes)
                {
                    Debt.CreateAndAdd(MyID, DeadLinePicker.Value.Date, DescriptionTBox.Text, MyAmount);
                    MessageBox.Show("Go to Home window and return to see changes");
                }
                break;
            }

            case 1:     // Edit Debt State (Under Development)
            {
                if (string.IsNullOrWhiteSpace(IDTBox.Text) ||
                    string.IsNullOrWhiteSpace(DescriptionTBox.Text) ||
                    string.IsNullOrWhiteSpace(AmountTBox.Text))
                {
                    MessageBox.Show("Some fields may be empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (!Int32.TryParse(IDTBox.Text, out MyID) ||
                    !decimal.TryParse(AmountTBox.Text, out MyAmount) ||
                    MyID <= 0 ||
                    MyAmount <= 0)
                {
                    MessageBox.Show("Some numeric fields may be invalid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (DateTime.Compare(DateTime.Now, DeadLinePicker.Value) > 0)
                {
                    MessageBox.Show("DeadLine is before today.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                DialogResult DR = MessageBox.Show("Are you sure to edit this Debt?", "Verfication", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (DR == DialogResult.Yes)
                {
                    Debt.Edit(Debt.Debts[UserCache.CurrentDebt.ID - 1], MyAmount, DescriptionTBox.Text, DeadLinePicker.Value.Date);
                    MessageBox.Show("Go to Home window and return to see changes");
                }
                break;
            }
            }
            this.Close();
        }