コード例 #1
0
ファイル: ExpenseChild.cs プロジェクト: JustJal/SaveX
        /// <summary>
        /// This event validates the data before triggering the Edit or Add method
        /// 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.ActualExpenseChildState)
            {
            case 0:     //Add Expense State
            {
                if (DescriptionTBox.Text == "Ex: Electricity" ||
                    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 (MyAmount > UserCache.Account.Amount)
                {
                    MessageBox.Show("You don't have enough money to afford this expense.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                DialogResult DR = MessageBox.Show("Are you sure to add this Expense?", "Verfication", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (DR == DialogResult.Yes)
                {
                    Expense.CreateAndAdd(MyID, ExpenseDatePicker.Value.Date, DescriptionTBox.Text, MyAmount, UserCache.Account);
                    MessageBox.Show("Go to Home Window and return to see changes");
                }
                break;
            }

            case 1:     // Edit Expense 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 (MyAmount > UserCache.Account.Amount)
                {
                    MessageBox.Show("You don't have enough money to afford this expense.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                DialogResult DR = MessageBox.Show("Are you sure to edit this Expense?", "Verfication", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (DR == DialogResult.Yes)
                {
                    Expense.Edit(Expense.Expenses[UserCache.CurrentExpense.ID - 1], MyAmount, DescriptionTBox.Text, ExpenseDatePicker.Value.Date, UserCache.Account);
                    MessageBox.Show("Go to Home window and return to see changes");
                }
                break;
            }
            }
            this.Close();
        }