Ejemplo n.º 1
0
        protected void Back_Click(object sender, EventArgs e)
        {
            ManageDataSession Data = ManageDataSession.Get(this);

            HandleShowState(Data, ManageDataState.Main, true);
            Server.TransferRequest(Request.Url.AbsolutePath, false);
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
0
        MainRadioButton GetMainRadioButton(ManageDataSession Data)
        {
            string ID = mainRadioResult.Value;

            foreach (var Btn in Data.MainRadioButtons)
            {
                if (Btn.InputID == ID)
                {
                    return(Btn);
                }
            }

            return(null);
        }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ManageDataSession Data = ManageDataSession.Get(this);

            Data.State = ManageDataState.Main;

            BudgetSession S = BudgetSession.Get(this);

            if (S.Authenticated())
            {
                S.LogOut();
            }

            Response.Redirect("Login.aspx");
        }
Ejemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            BudgetSession S = BudgetSession.Get(this);

            if (!S.Authenticated())
            {
                Response.Redirect("Login.aspx");
                return;
            }

            ManageDataSession Data = ManageDataSession.Get(this);

            if (Data.SelectedCurrency == null)
            {
                DAL DbDAL = new DAL();
                Data.SelectedCurrency = DbDAL.Select <Currency>().Where(C => C.Code == "HRK").First();
            }

            HandleShowState(Data, Data.State);
        }
Ejemplo n.º 6
0
        protected void Confirm_Click(object sender, EventArgs e)
        {
            ManageDataSession Data = ManageDataSession.Get(this);
            BudgetSession     S    = BudgetSession.Get(this);

            try {
                HandleStateConfirm(Data, S);
            } catch (DisplayException E) {
                labelError.Visible   = true;
                labelError.InnerText = E.Message;
                return;
            } catch (Exception E) when(!Debugger.IsAttached)
            {
                labelError.Visible   = true;
                labelError.InnerText = "Internal exception occured in HandleStateConfirm";
                return;
            }

            Server.TransferRequest(Request.Url.AbsolutePath, false);
        }
Ejemplo n.º 7
0
        void HandleShowState(ManageDataSession Data, ManageDataState State, bool ChangeState = false)
        {
            divRadioOptions.Visible = false;
            divDateFrom.Visible     = false;
            divDateTo.Visible       = false;
            divCurAmt.Visible       = false;
            divMonthCount.Visible   = false;

            btnBack.Visible = true;

            btnCurSel.InnerText = Data.SelectedCurrency.Code;

            switch (State)
            {
            case ManageDataState.Main:
                ShowMain();
                break;

            case ManageDataState.AddSingle:
                ShowSingleTransaction();
                break;

            case ManageDataState.AddMultiple:
                ShowMultipleTransaction();
                break;

            case ManageDataState.AddMaestroPlus:
                ShowAddMaestro();
                break;

            default:
                throw new NotImplementedException();
            }

            if (ChangeState)
            {
                Data.State = State;
            }
        }
Ejemplo n.º 8
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);
            }
        }