示例#1
0
        private void DeleteBudget()
        {
            string message;

            if (Budget.Transactions?.Count > 0)
            {
                message =
                    $"Wenn sie das Budget von {Budget.Year} löschen, werden alle zugehörigen Buchungen ({Budget.Transactions.Count}) ebenfalls gelöscht. " +
                    "Wollen sie das Budget trotzdem löschen?";
            }
            else
            {
                message = $"Wollen sie das Budget von {Budget.Year} wirklich löschen?";
            }

            if (MessageBox.Show(message, "Budget löschen?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                var deletedBudget       = Budget;
                var deletedTransactions = Budget.Transactions?.ToList() ?? new List <Transaction>();

                UnitOfWork.Transactions.RemoveRange(deletedTransactions);
                UnitOfWork.Budgets.Remove(deletedBudget);
                UnitOfWork.Complete();

                foreach (var t in deletedTransactions)
                {
                    TransactionList.Remove(t);
                }

                BudgetList.Remove(deletedBudget);
                Budget = BudgetList.Count > 0 ? BudgetList[0] : null;
            }
        }
        protected override void RefreshMainData()
        {
            PgMng.Grow(string.Empty, "Proforma");

            _selectedOid = ActiveOID;

            switch (DataType)
            {
            case EntityMngFormTypeData.Default:
                if (Library.Common.ModulePrincipal.GetUseActiveYear())
                {
                    List = BudgetList.GetList(false, Library.Common.ModulePrincipal.GetActiveYear().Year);
                }
                else
                {
                    List = BudgetList.GetList(false);
                }
                break;

            case EntityMngFormTypeData.ByParameter:
                _sorted_list = List.GetSortedList();
                break;
            }
            PgMng.Grow(string.Empty, "Lista de Proformas");
        }
        public async Task <IActionResult> delete(BudgetList budgetList)
        {
            try
            {
                List <Budget> list = budgetList.Budgets;

                for (int i = 0; i < list.Count; i++)
                {
                    var budget = _context.Budget.Where(x => x.StoreCode == list[i].StoreCode).First();
                    _context.Budget.Remove(budget);
                    _context.SaveChanges();
                }
                return(StatusCode(200, new
                {
                    status = "200",
                    delete = true,
                    message = "Deleted successfully!"
                }));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, new
                {
                    status = "500",
                    delete = false,
                    message = ex.ToString()
                }));
            }
        }
        public BudgetList SyncBudgets(BudgetList budgets)
        {
            try
            {
                var budgetsList = new BudgetList();
                var budgetIDs = budgets.Select(x => x.BudgetId).ToList();
                using (EntityContext context = new EntityContext())
                {
                    var query = (from i in context.Budget
                                 where budgetIDs.Contains(i.BudgetId)
                                 select i).ToList();

                    //investigate if there is a better way to convert the generic list to ObservableCollection
                    foreach (var item in query)
                    {
                        var tempItem = budgets.FirstOrDefault(x => x.BudgetId == item.BudgetId);
                        if (tempItem.ModifiedDate < item.ModifiedDate)
                            budgets.Remove(tempItem);
                    }
                }

                return SaveBudgets(budgets);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#5
0
        public BudgetSelectForm(Form parent, BudgetList lista)
            : base(true, parent, lista)
        {
            InitializeComponent();
            _view_mode = molView.Select;

            _action_result = DialogResult.Cancel;
        }
示例#6
0
        /// <summary>
        /// Retrieve a budget list from the repository.
        /// </summary>
        /// <returns>Reference to the budget list in the repository. Guaranteed to be not <c>null</c>.</returns>
        public BudgetList Find()
        {
            var list = this.readStore.RetrieveSingleton <BudgetList>();

            if (list == null)
            {
                list = new BudgetList();
                this.Save(list);
            }

            return(list);
        }
示例#7
0
        /// <summary>
        /// Get an initialized budget list
        /// </summary>
        /// <returns>initialized budget list</returns>
        private BudgetList GetBudgetList()
        {
            var budgetList = this.budgetListRepository.Find();

            if (budgetList == null)
            {
                budgetList = new BudgetList();
                this.budgetListRepository.Save(budgetList);
            }

            return(budgetList);
        }
        public override void UpdateList()
        {
            switch (_current_action)
            {
            case molAction.Add:
                if (_entity == null)
                {
                    return;
                }
                List.AddItem(_entity.GetInfo(false));
                if (FilterType == IFilterType.Filter)
                {
                    BudgetList listA = BudgetList.GetList(_filter_results);
                    listA.AddItem(_entity.GetInfo(false));
                    _filter_results = listA.GetSortedList();
                }
                break;

            case molAction.Edit:
            case molAction.Lock:
            case molAction.Unlock:
                if (_entity == null)
                {
                    return;
                }
                ActiveItem.CopyFrom(_entity);
                break;

            case molAction.Delete:
                if (ActiveItem == null)
                {
                    return;
                }
                List.RemoveItem(ActiveOID);
                if (FilterType == IFilterType.Filter)
                {
                    BudgetList listD = BudgetList.GetList(_filter_results);
                    listD.RemoveItem(ActiveOID);
                    _filter_results = listD.GetSortedList();
                }
                break;
            }

            RefreshSources();
            if (_entity != null)
            {
                Select(_entity.Oid);
            }
            _entity = null;
        }
示例#9
0
        private void NewBudget()
        {
            var budget = new Budget();
            var vm     = new EditBudgetViewModel(new UnitOfWorkFactory(), budget);

            vm.Init();
            var window = new EditBudgetView(vm);

            if (window.ShowDialog() ?? false)
            {
                BudgetList.Add(budget);
                Budget = budget;
            }
        }
示例#10
0
    protected void Page_PreRender(object sender, EventArgs e)
    {
        DataAbstract DA = new DataAbstract();

        if (Convert.ToInt32(Session["userID"]) != 0)
        {
            userID = Convert.ToInt32(Session["userID"]);
            DataSet accountData = DA.returnAccounts(userID);               //gets all accounts
            System.Data.DataTable accountsTable = accountData.Tables[0];   //table holding all account entries for the user
            object s = accountsTable.Rows[0].Field <object>("AcctNumber"); //sets the default account to the first of the user's accounts. LIKELY CHANGE LATER.
            if (Convert.ToInt64(Session["account"]) == 0)
            {
                Session["account"] = Convert.ToInt64(s);                    //saves the first account as the default account during the session
            }
            userID = Convert.ToInt16(Session["userID"]);                    //saves the Session userID to the variable on this page
        }
        else
        {
            Session["userID"]  = 1; //temporary solution for demo 3/19/2017
            Session["account"] = 211111110;
        }

        BudgetDS = DA.returnBoundedBudgets(Convert.ToInt64(Session["account"]), d1, d2);

        //Sets the source for the listview

        BudgetList.DataSource = BudgetDS;
        BudgetList.DataBind();
        //LoadSubjects();
        DataTable    accounts = DA.returnAccounts(userID).Tables[0];
        DropDownList DDL      = AccountList;

        DDL.Items.Insert(0, new ListItem("Select Account", "0"));
        DDL.DataSource     = accounts;
        DDL.DataTextField  = "AcctNumber";
        DDL.DataValueField = "AcctNumber";

        DDL.DataBind();

        DataTable    categories = DA.returnCategories(userID).Tables[0];
        DropDownList DDL2       = CategorySelect;

        DDL2.Items.Insert(0, new ListItem("Select Category", "0"));
        DDL2.DataSource     = categories;
        DDL2.DataTextField  = "Name";
        DDL2.DataValueField = "CategoryID";

        DDL2.DataBind();
    }
        public override void PrintList()
        {
            PgMng.Reset(3, 1, Face.Resources.Messages.LOADING_DATA, this);

            BudgetReportMng reportMng = new BudgetReportMng(AppContext.ActiveSchema, this.Text, this.FilterValues);

            PgMng.Grow(Face.Resources.Messages.BUILDING_REPORT);

            ReportClass report = reportMng.GetListReport(BudgetList.GetList(Datos.DataSource as IList <BudgetInfo>),
                                                         null,
                                                         SerieList.GetList(false));

            PgMng.FillUp();

            ShowReport(report);
        }
        public BudgetMngForm(bool isModal, Form parent, BudgetList list)
            : base(isModal, parent, list)
        {
            InitializeComponent();

            SetView(molView.Normal);

            // Parche para poder abrir el formulario en modo diseño y no perder la configuracion de columnas
            DatosLocal_BS    = Datos;
            Tabla.DataSource = DatosLocal_BS;

            SetMainDataGridView(Tabla);
            Datos.DataSource = BudgetList.NewList().GetSortedList();
            SortProperty     = Fecha.DataPropertyName;
            SortDirection    = ListSortDirection.Descending;
        }
示例#13
0
        public async Task <IActionResult> update(BudgetList budgetList)
        {
            try
            {
                List <Budget> list = budgetList.Budgets;

                for (int i = 0; i < list.Count; i++)
                {
                    bool discExist = false;
                    discExist = _context.Budget.Any(c => c.StoreCode == list[i].StoreCode);
                    if (discExist == true)
                    {
                        var budget = _context.Budget.Where(x => x.StoreCode == list[i].StoreCode).First();
                        budget.Amount          = list[i].Amount;
                        budget.TransactionDate = list[i].TransactionDate;
                        budget.JournalNumber   = list[i].JournalNumber;
                        _context.Budget.Update(budget);
                        _context.SaveChanges();
                    }
                    else
                    {
                        return(StatusCode(404, new
                        {
                            status = "404",
                            update = false,
                            message = "Discount code not found."
                        }));
                    }
                }

                return(StatusCode(200, new
                {
                    status = "200",
                    update = true,
                    message = "updated successfully!"
                }));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, new
                {
                    status = "500",
                    update = false,
                    message = ex.ToString()
                }));
            }
        }
示例#14
0
        public ActionResult List(DateTime bDate, DateTime eDate, string SearchType = "", int codeID = 0, string code = "", int codeID2 = 0)
        {
            IEnumerable <programeventbudget> BudgetList;

            if (SearchType == "EventSearch")
            {
                BudgetList = ProgramEventBudgetRepository.GetEventBudgetByEventID(codeID);
            }
            else if (SearchType == "StatusSearch")
            {
                BudgetList = ProgramEventBudgetRepository.GetEventBudgetByStatus(code);
            }
            else
            {
                BudgetList = ProgramEventBudgetRepository.GetEventBudgetByDueDateRange(bDate, eDate);
            }

            ViewBag.RecordCount = BudgetList.Count();

            return(View(BudgetList));
        }
示例#15
0
        public async Task <IActionResult> create(BudgetList budgetList)
        {
            try
            {
                List <Budget> list = budgetList.Budgets;

                for (int i = 0; i < list.Count; i++)
                {
                    Budget budget = new Budget();
                    budget.StoreCode       = list[i].StoreCode;
                    budget.StoreId         = list[i].StoreId;
                    budget.StoreName       = list[i].StoreName;
                    budget.Amount          = list[i].Amount;
                    budget.JournalNumber   = list[i].JournalNumber;
                    budget.TransactionDate = list[i].TransactionDate;
                    _context.Add(budget);
                    _context.SaveChanges();
                }

                return(StatusCode(200, new
                {
                    status = "200",
                    create = true,
                    message = "Created successfully!"
                }));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, new
                {
                    status = "500",
                    create = false,
                    message = ex.ToString()
                }));
            }
        }
示例#16
0
        public static BudgetList GetBudgets()
        {
            // Retrieve the Budget records from the data store
            List<BudgetDetails> details = SiteProvider.Accounts.GetBudgets();
            BudgetList list = new BudgetList();

            // Copy from the Budget records to the Budget objects
            foreach (BudgetDetails bd in details)
            {
                if (bd != null)
                {
                    // Create the new Budget object from the Budget Details retrieved
                    // from the database.
                    Budget b = new Budget(bd);

                    // Retrieve the list of Budget Items for the specified Budget.
                    List<BudgetItemDetails> itemDetails = SiteProvider.Accounts.GetBudgetItems(bd.ID);
                    BudgetItemList items = new BudgetItemList();
                    foreach (BudgetItemDetails bid in itemDetails)
                    {
                        if (bid != null)
                        {
                            BudgetItem bi = new BudgetItem(bid);
                            bi.Budget = b;
                            if (bid.TagID != -1)
                                bi.Tag = KapitalManager.Instance.Tags.FindByID(bid.TagID);

                            // Add the Budget Item to the list of BudgetItems.
                            items.Add(bi);
                        }
                    }

                    // Attach the list of items to the current Budget
                    b.BudgetItems = items;
                    list.Add(b);
                }
            }

            return list;
        }
        public BudgetList SaveBudgets(BudgetList budgets)
        {
            try
            {
                bool updateFound = false;

                using (EntityContext context = new EntityContext())
                {
                    foreach (var item in budgets)
                    {
                        if (item.BudgetId > 0) //Update
                        {
                            var original = context.Budget.Where(t => 
                                                                t.BudgetId == item.BudgetId &&
                                                                t.ModifiedDate < item.ModifiedDate &&
                                                                !t.IsDeleted).FirstOrDefault();

                            //update database only if the transaction in DB is older
                            if (original != null)
                            {
                                item.HasChanges = false;

                                original.CreatedUser = context.User.Where(k => !k.IsDeleted).Single(p => p.UserId == item.CreatedUser.UserId);
                                original.ModifiedUser = context.User.Where(k => !k.IsDeleted).Single(p => p.UserId == item.ModifiedUser.UserId);

                                item.FromDate = new DateTime(item.FromDate.Year, item.FromDate.Month, item.FromDate.Day, 0, 0, 0);
                                item.ToDate = new DateTime(item.ToDate.Year, item.ToDate.Month, item.ToDate.Day, 0, 0, 0);

                                context.Entry(original).CurrentValues.SetValues(item);

                                updateFound = true;
                            }
                        }
                        else //Insert
                        {
                            item.CreatedUser = context.User.Where(k => !k.IsDeleted).Single(p => p.UserId == item.CreatedUser.UserId);
                            item.ModifiedUser = context.User.Where(k => !k.IsDeleted).Single(p => p.UserId == item.ModifiedUser.UserId);

                            item.FromDate = new DateTime(item.FromDate.Year, item.FromDate.Month, item.FromDate.Day, 0, 0, 0);
                            item.ToDate = new DateTime(item.ToDate.Year, item.ToDate.Month, item.ToDate.Day, 0, 0, 0);

                            context.Budget.Add(item);

                            updateFound = true;
                        }
                    }

                    if (updateFound)
                        context.SaveChanges();
                }

                GetTransactionsForBudgets(budgets);
                budgets.PrepareForServiceSerialization();

                return budgets;
            }
            catch (DbEntityValidationException e)
            {
                StringBuilder s = new StringBuilder();
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                            ve.PropertyName, ve.ErrorMessage);
                        s.Append(string.Format("{0} - {1}", ve.PropertyName, ve.ErrorMessage));
                    }
                }

                throw new DbEntityValidationException(s.ToString());
            }
            catch (Exception)
            {

                throw;
            }
        }
        private void GetTransactionsForBudgets(BudgetList budgetList)
        {
            try
            {
                using (EntityContext context = new EntityContext())
                {
                    foreach (var item in budgetList)
                    {
                        var inQuery = from t in context.Transaction
                                      .Include(t => t.TransactionType).Where(k => !k.IsDeleted)
                                      where t.TransactionDate >= item.FromDate && t.TransactionDate <= item.ToDate
                                      && !t.IsDeleted && t.ModifiedUser.UserId == item.ModifiedUser.UserId
                                      select t;

                        TransactionList tl = new TransactionList();

                        foreach (var inItem in inQuery.ToList())
                            tl.Add(inItem);

                        item.Transactions = tl;

                        ////Apply the rule to create a new budget if the expired one is set to Repeat
                        //if (item.Repeat && item.ToDate < DateTime.Now)
                        //{
                        //    var dataSpanRange = item.ToDate - item.FromDate;
                        //    var dataSpanToday = DateTime.Now - item.ToDate;
                        //    var dateDif = dataSpanRange.Days;
                        //    var diff = dataSpanToday.Days % dataSpanRange.Days;
                        //    var newFromDate = DateTime.Now.AddDays(-diff + 1);
                        //    var newToDate = newFromDate.AddDays(dataSpanRange.Days);

                        //    var test = newToDate - newFromDate;

                        //    var newBudget = item.Clone();
                        //    newBudget.FromDate = newFromDate;
                        //    newBudget.ToDate = newToDate;

                        //    item.Repeat = false;
                        //    context.Budget.Add(newBudget);

                        //    //context.SaveChanges();
                        //}
                    }
                    //return budgetList;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public BudgetList GetAllBudgets(int userId)
        {
            try
            {
                BudgetList budgetList = new BudgetList();
                using (EntityContext context = new EntityContext())
                {
                    var query = (from i in context.Budget
                                .Include(i => i.CreatedUser)
                                .Include(i => i.ModifiedUser)
                                where !i.IsDeleted && i.ModifiedUser.UserId == userId
                                select i).ToList();

                    //investigate if there is a better way to convert the generic list to ObservableCollection
                    foreach (var item in query)
                        budgetList.Add(item);

                    GetTransactionsForBudgets(budgetList);

                    budgetList.PrepareForServiceSerialization();

                    return budgetList;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#20
0
 /// <summary>
 /// Save the budget list, or add it to the repository. Beware: replaces existing budget list in repository.
 /// </summary>
 /// <param name="budgetList">Budget list to save</param>
 internal void Save(BudgetList budgetList)
 {
     this.readStore.StoreSingleton(budgetList);
 }
 public ServiceData()
 {
     TransactionList = new TransactionList();
     TransactionImageList = new TransactionImageList();
     BudgetList = new BudgetList();
 }
            private async void LoadCachedBudgets(Action<BudgetList, Exception> callback)
            {
                var retVal = new BudgetList();
                try
                {
                    foreach (var item in await StorageUtility.ListItems(BUDGETS_FOLDER, App.Instance.User.UserName))
                    {
                        var budget = await StorageUtility.RestoreItem<Budget>(BUDGETS_FOLDER, item, App.Instance.User.UserName);
                        BudgetList.Add(budget);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                    //callback(null, ex);
                }

                //SetupBudgetList(retVal, false);
                //BudgetList = retVal;

                callback(BudgetList, null);
            }