コード例 #1
0
        public String UpdateAlteration(int id, FundsAlteration newAlteration)
        {
            using (var context = new SystemDbContext())
            {
                String msg = "";
                if (!IsValid(newAlteration, UPDATE, out msg))
                {
                    return(msg);
                }

                var fundsAlterations = context.Set <FundsAlteration>();
                var fundsAlteration  = fundsAlterations.Where(x => x.Id == id).FirstOrDefault();
                fundsAlteration.Amount   = newAlteration.Amount;
                fundsAlteration.Comment  = newAlteration.Comment;
                fundsAlteration.Date     = newAlteration.Date;
                fundsAlteration.Type     = newAlteration.Type;
                fundsAlteration.Periodic = newAlteration.Periodic;

                if (!IsValid(fundsAlteration, UPDATE, out msg))
                {
                    return(msg);
                }

                context.SaveChanges();
                return(msg);
            }
        }
コード例 #2
0
 public EditingForm(FundsAlteration fundsAlteration)
 {
     InitializeComponent();
     this.fundsAlteration             = fundsAlteration;
     this.numericUpDownEdit.Value     = (decimal)fundsAlteration.Amount;
     this.radioButtonRepeated.Checked = fundsAlteration.Periodic;
     this.dateTimePickerEdit.Value    = (DateTime)fundsAlteration.Date;
 }
コード例 #3
0
 public void DeleteAlteration(int id)
 {
     using (var context = new SystemDbContext())
     {
         var             fundsAlterations = context.Set <FundsAlteration>();
         FundsAlteration fundsAlteration  = fundsAlterations
                                            .Where(x => x.Id == id)
                                            .FirstOrDefault();
         if (fundsAlteration != null)
         {
             fundsAlterations.Remove(fundsAlteration);
         }
     }
 }
コード例 #4
0
        public UpdateForm(Form parent, FundsAlteration fundsAlteration)
        {
            InitializeComponent();

            this.parent = parent;

            this.fundsAlteration    = fundsAlteration;
            this.Amount             = (decimal)fundsAlteration.Amount;
            this.Repeated           = fundsAlteration.Periodic;
            this.Date               = fundsAlteration.Date.Value;
            this.ConfirmButton.Text = "Редактирай";

            this.ConfirmButton.Click += ButtonUpdate_Click;
            this.BackButton.Click    += ButtonBack_Click;
        }
コード例 #5
0
        public String AddAlteration(double amount, String type, bool isPeriodic, DateTime?dateTime, String comment = null)
        {
            using (var context = new SystemDbContext())
            {
                var      fundsAlterations = context.Set <FundsAlteration>();
                DateTime?dt = (dateTime != null ? dateTime : DateTime.Now);

                String          msg = "";
                FundsAlteration fa  = new FundsAlteration(amount, type, dt, isPeriodic);
                if (IsValid(fa, CREATE, out msg))
                {
                    fundsAlterations.Add(fa);
                    context.SaveChanges();
                }
                return(msg);
            }
        }
コード例 #6
0
 public String DeleteAlteration(int id)
 {
     using (var context = new SystemDbContext())
     {
         String          msg = "";
         var             fundsAlterations = context.Set <FundsAlteration>();
         FundsAlteration fundsAlteration  = fundsAlterations
                                            .Where(x => x.Id == id)
                                            .FirstOrDefault();
         if (fundsAlteration != null && IsValid(fundsAlteration, DELETE, out msg))
         {
             fundsAlterations.Remove(fundsAlteration);
         }
         context.SaveChanges();
         return(msg);
     }
 }
コード例 #7
0
        private bool IsValid(FundsAlteration fundsAlteration, String type, out String msg)
        {
            if (fundsAlteration.Amount <= 0 ||
                (!fundsAlteration.Type.Equals(FundsAlterationTypes.INCOME) && !fundsAlteration.Type.Equals(FundsAlterationTypes.EXPENSE)))
            {
                msg = INVALID_DATA;
                return(false);
            }

            //if (fundsAlteration.Periodic)
            //{
            //    msg = GENERIC_ERROR; //to be implemented
            //    return false;
            //}

            if (fundsAlteration.Type.Equals(FundsAlterationTypes.EXPENSE))
            {
                double balance = this.CalcBalance();
                if (fundsAlteration.Amount > balance)
                {
                    msg = INSUFFICIENT_FUNDS;
                    return(false);
                }
            }

            switch (type)
            {
            case "create": msg = ROW_ADDED_SUCCESSFULLY; return(true);

            case "update": msg = ROW_UPDATED_SUCCESSFULLY; return(true);

            case "delete": msg = ROW_DELETED_SUCCESSFULLY; return(true);

            default: msg = "null";  return(true);
            }

            // msg = ROW_ADDED_SUCCESSFULLY;
            // return true;
        }