Esempio n. 1
0
        void ShowMain()
        {
            ManageDataSession Data = ManageDataSession.Get(this);

            if (IsPostBack)
            {
                MainRadioButton SelBtn = GetMainRadioButton(Data);

                foreach (var Btn in Data.MainRadioButtons)
                {
                    Btn.Checked = false;
                }

                if (SelBtn != null)
                {
                    SelBtn.Checked = true;
                }
            }
            else
            {
                Data.MainRadioButtons.Clear();
                Data.MainRadioButtons.Add(new MainRadioButton("Add Single", ManageDataState.AddSingle)
                {
                    Checked = true
                });
                Data.MainRadioButtons.Add(new MainRadioButton("Add Multiple", ManageDataState.AddMultiple)
                {
                    Enabled = true
                });
                Data.MainRadioButtons.Add(new MainRadioButton("Add Repeating", ManageDataState.AddRepeating)
                {
                    Enabled = false
                });
                Data.MainRadioButtons.Add(new MainRadioButton("Add MaestroPlus", ManageDataState.AddMaestroPlus)
                {
                    Enabled = true
                });
                Data.MainRadioButtons.Add(new MainRadioButton("Manage MaestroPlus", ManageDataState.ManageMaestroPlus)
                {
                    Enabled = false
                });

                foreach (var Btn in Data.MainRadioButtons)
                {
                    if (Btn.Checked)
                    {
                        mainRadioResult.Value = Btn.InputID;
                    }
                }
            }

            btnBack.Visible         = false;
            divRadioOptions.Visible = true;
            rptOptions.DataSource   = Data.MainRadioButtons;
            rptOptions.DataBind();
        }
Esempio n. 2
0
        void HandleStateConfirm(ManageDataSession Data, BudgetSession S)
        {
            switch (Data.State)
            {
            case ManageDataState.Main: {
                MainRadioButton Next = GetMainRadioButton(Data);
                HandleShowState(Data, Next.NewState, true);
                return;
            }

            case ManageDataState.AddSingle: {
                if (!float.TryParse(inCurAmt.Value, out float Amt))
                {
                    throw new DisplayException("Could not parse currency amount");
                }

                if (!DateTime.TryParse(dateBegin.Value, out DateTime Date))
                {
                    throw new DisplayException("Could not parse date");
                }

                DAL         DbDAL = new DAL();
                Transaction T     = new Transaction(S.CurrentUser, Date, Amt);
                T.Description = inComment.Value.Trim();

                DbDAL.Insert(T);
                break;
            }

            case ManageDataState.AddMultiple: {
                if (!float.TryParse(inCurAmt.Value, out float Amt))
                {
                    throw new DisplayException("Could not parse currency amount");
                }

                if (!DateTime.TryParse(dateBegin.Value, out DateTime From))
                {
                    throw new DisplayException("Could not parse From date");
                }

                if (!DateTime.TryParse(dateEnd.Value, out DateTime To))
                {
                    throw new DisplayException("Could not parse To date");
                }
                else
                {
                    To = To.AddDays(1);
                }

                DAL DbDAL = new DAL();

                while (From < To)
                {
                    Transaction T = new Transaction(S.CurrentUser, From, Amt);
                    T.Description = inComment.Value.Trim();

                    DbDAL.Insert(T);
                    From = From.AddMonths(1);
                }

                break;
            }

            case ManageDataState.AddRepeating:
                break;

            case ManageDataState.AddMaestroPlus: {
                DAL DbDAL = new DAL();
                MaestroPlusCalculator MaestroCalc = new MaestroPlusCalculator(DbDAL);

                int      MonthCount = int.Parse(inMonthCount.Value);
                float    Amt        = float.Parse(inCurAmt.Value);
                DateTime From       = DateTime.Parse(dateBegin.Value);
                string   Comment    = inComment.Value.Trim();

                MaestroCalc.Calculate(MonthCount, Amt, out float OneTime, out float Monthly);

                MaestroEntry MaestroEntry = new MaestroEntry();
                MaestroEntry.Description = Comment;
                DbDAL.Insert(MaestroEntry);

                Transaction TOneTime = new Transaction(S.CurrentUser, From, -OneTime);
                TOneTime.Description = "Maestro OneTime " + Comment;
                TOneTime.Maestro     = MaestroEntry.ID;
                DbDAL.Insert(TOneTime);

                Transaction MaestroPayment = new Transaction(S.CurrentUser, From, Amt);
                MaestroPayment.Description = Comment;
                MaestroPayment.Maestro     = MaestroEntry.ID;
                DbDAL.Insert(MaestroPayment);

                From = From.AddMonths(1);

                for (int i = 0; i < MonthCount; i++)
                {
                    Transaction MaestroMonthly = new Transaction(S.CurrentUser, From, -Monthly);
                    MaestroMonthly.Description = Comment;
                    MaestroMonthly.Maestro     = MaestroEntry.ID;
                    DbDAL.Insert(MaestroMonthly);

                    From = From.AddMonths(1);
                }

                break;
            }

            case ManageDataState.ManageMaestroPlus:
                break;

            default:
                throw new Exception("Invalid state " + Data.State);
            }
        }