Esempio n. 1
0
        /// <summary>
        /// 载入用水支出数据
        /// </summary>
        /// <param name="account">账户</param>
        /// <param name="years">年度列表</param>
        /// <param name="type">类型</param>
        /// <param name="showLabel">是否显示标签</param>
        private void LoadWaterData(ExpenseAccount account, int[] years, int type, bool showLabel)
        {
            for (int i = 0; i < years.Length; i++)
            {
                int    year  = years[i];
                string title = $"{year}年";

                var waterExpenses = BusinessFactory <WaterExpenseBusiness> .Instance.FindYearByAccount(account.Id, year).ToList();

                List <SeriesPoint> points = new List <SeriesPoint>();
                string             unit   = "";

                for (int j = 0; j < waterExpenses.Count; j++)
                {
                    string      month = $"{waterExpenses[j].BelongDate.Month}月";
                    SeriesPoint point = new SeriesPoint();
                    point.Argument = month;

                    if (type == 0)
                    {
                        point.Values = new double[] { Convert.ToDouble(waterExpenses[j].TotalQuantity) };
                        unit         = "吨";
                    }
                    else if (type == 1)
                    {
                        point.Values = new double[] { Convert.ToDouble(waterExpenses[j].TotalAmount) };
                        unit         = "元";
                    }
                    points.Add(point);
                }

                this.energyChart.AddSeries(title, points, unit, showLabel);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 设置关联账户
        /// </summary>
        /// <param name="account"></param>
        public void SetAccount(ExpenseAccount account)
        {
            this.currentAccount = account;
            this.waterExpRecGrid.Init();

            LoadReceipts();
        }
        /// <summary>
        /// 显示年度汇总
        /// </summary>
        /// <param name="account"></param>
        private async void DisplayYear(ExpenseAccount account)
        {
            var task1 = Task.Run(() =>
            {
                List <EnergyExpense> data = new List <EnergyExpense>();
                for (int i = startYear; i <= nowYear; i++)
                {
                    var yearData = BusinessFactory <ElectricExpenseBusiness> .Instance.FindYearByAccount(account.Id, i);
                    if (yearData.Count() == 0)
                    {
                        continue;
                    }

                    EnergyExpense energyExpense = new EnergyExpense();
                    energyExpense.BelongDate    = new DateTime(i, 1, 1);
                    energyExpense.Quantum       = yearData.Sum(r => r.TotalQuantity);
                    energyExpense.Amount        = yearData.Sum(r => r.TotalAmount);

                    data.Add(energyExpense);
                }

                return(data);
            });

            var result1 = await task1;

            this.electricYearChart.SetChartTitle(account.ShortName + "历年用电对比");
            this.electricYearChart.SetSeriesLengedText(0, "用电量(度)");
            this.electricYearChart.DataSource = result1;

            var task2 = Task.Run(() =>
            {
                List <EnergyExpense> data = new List <EnergyExpense>();
                for (int i = startYear; i <= nowYear; i++)
                {
                    var yearData = BusinessFactory <WaterExpenseBusiness> .Instance.FindYearByAccount(account.Id, i);
                    if (yearData.Count() == 0)
                    {
                        continue;
                    }

                    EnergyExpense energyExpense = new EnergyExpense();
                    energyExpense.BelongDate    = new DateTime(i, 1, 1);
                    energyExpense.Quantum       = yearData.Sum(r => r.TotalQuantity);
                    energyExpense.Amount        = yearData.Sum(r => r.TotalAmount);

                    data.Add(energyExpense);
                }
                return(data);
            });

            var result2 = await task2;

            this.waterYearChart.SetChartTitle(account.ShortName + "历年用水对比");
            this.waterYearChart.SetSeriesLengedText(0, "用水量(吨)");
            this.waterYearChart.DataSource = result2;

            this.electricYearGridMod.SetAccount(this.currentAccount, EnergyExpenseType.Electric);
            this.waterYearGridMod.SetAccount(this.currentAccount, EnergyExpenseType.Water);
        }
Esempio n. 4
0
        public IHttpActionResult PutExpenseAccount(int id, ExpenseAccount expenseAccount)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != expenseAccount.ExpenseAccountId)
            {
                return(BadRequest());
            }

            db.Entry(expenseAccount).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ExpenseAccountExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 5
0
        public IHttpActionResult PostExpenseAccount(ExpenseAccount expenseAccount)
        {
            if (!ModelState.IsValid || expenseAccount == null)
            {
                return(BadRequest(ModelState));
            }

            ExpenseAccount e     = db.ExpenseAccounts.OrderByDescending(ex => ex.ExpenseAccountId).FirstOrDefault();
            int            newId = (null == e ? 1000 : e.ExpenseAccountId) + 1;

            expenseAccount.ExpenseAccountId = newId;

            expenseAccount.WhenCreated = DateTime.Now;

            db.ExpenseAccounts.Add(expenseAccount);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (ExpenseAccountExists(expenseAccount.ExpenseAccountId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = expenseAccount.ExpenseAccountId }, expenseAccount));
        }
 public ActionResult Expenses([Bind(Include = "accountType,code,name,description,parentCode,isGroup,openingDebit,openingCredit, isActive")] ExpenseAccount exp)
 {
     if (ModelState.IsValid)
     {
         ExpenseAccount e = db.ExpenseAccounts.Find(exp.code);
         if (e == null)
         {
             exp.isActive = true;
             db.ExpenseAccounts.Add(exp);
         }
         else
         {
             var exDb = db.ExpenseAccounts.Single(x => x.code == exp.code);
             exDb.accountType   = exp.accountType;
             exDb.code          = exp.code;
             exDb.name          = exp.name;
             exDb.parentCode    = exp.parentCode;
             exDb.isGroup       = exp.isGroup;
             exDb.openingDebit  = exp.openingDebit;
             exDb.openingCredit = exp.openingCredit;
         }
         db.SaveChanges();
         return(RedirectToAction("Expenses"));
     }
     return(View(exp));
 }
        /// <summary>
        /// 设置关联账户
        /// </summary>
        /// <param name="account">账户对象</param>
        public void SetAccount(ExpenseAccount account)
        {
            this.txtName.Text      = account.Name;
            this.txtShortName.Text = account.ShortName;
            this.txtRemark.Text    = account.Remark;

            this.chkType1.Checked = this.chkType2.Checked = this.chkType3.Checked = this.chkType4.Checked = false;

            if (account.EnergyType.Contains(1))
            {
                this.chkType1.Checked = true;
            }
            if (account.EnergyType.Contains(2))
            {
                this.chkType2.Checked = true;
            }
            if (account.EnergyType.Contains(3))
            {
                this.chkType3.Checked = true;
            }
            if (account.EnergyType.Contains(4))
            {
                this.chkType4.Checked = true;
            }
        }
        /// <summary>
        /// 设置实体
        /// </summary>
        /// <param name="entity"></param>
        private void SetEntity(ExpenseAccount entity)
        {
            entity.Name      = this.txtName.Text;
            entity.ShortName = this.txtShortName.Text;
            entity.Remark    = this.txtRemark.Text;

            if (this.tluParent.EditValue != null)
            {
                entity.ParentId = this.tluParent.EditValue.ToString();
            }
            else
            {
                entity.ParentId = null;
            }

            entity.EnergyType = new List <int>();
            if (chkType1.Checked)
            {
                entity.EnergyType.Add(1);
            }
            if (chkType2.Checked)
            {
                entity.EnergyType.Add(2);
            }
            if (chkType3.Checked)
            {
                entity.EnergyType.Add(3);
            }
            if (chkType4.Checked)
            {
                entity.EnergyType.Add(4);
            }
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            var input = CheckInput();

            if (!input.Item1)
            {
                MessageUtil.ShowError(input.Item2);
                return;
            }

            ExpenseAccount entity = new ExpenseAccount();

            SetEntity(entity);

            try
            {
                BusinessFactory <ExpenseAccountBusiness> .Instance.Create(entity);

                MessageUtil.ShowInfo("保存成功");
                this.Close();
            }
            catch (PoseidonException pe)
            {
                MessageUtil.ShowError(string.Format("保存失败,错误消息:{0}", pe.Message));
            }
        }
Esempio n. 10
0
 public ActionResult Add([Bind(Include = "productCode,categoryCode,categoryName,name,UOM,price,currentQuantity,lastPurchasePrice,averagePrice")] Product product, int?page)
 {
     if (ModelState.IsValid)
     {
         var            pr         = db.Products.SingleOrDefault(m => m.productCode == product.productCode);
         ExpenseAccount exSale     = new ExpenseAccount();
         ExpenseAccount exPurchase = new ExpenseAccount();
         if (pr == null)
         {
             var max = db.ExpenseAccounts.ToList().OrderByDescending(r => r.code).FirstOrDefault();
             exPurchase.code          = max == null ? 1 : (max.code) + 1;
             exPurchase.accountType   = "Expense";
             exPurchase.description   = "Purchase Account";
             exPurchase.isGroup       = false;
             exPurchase.isActive      = true;
             exPurchase.name          = product.name + " Purchase";
             exPurchase.openingCredit = 0;
             exPurchase.openingDebit  = 0;
             exPurchase.parentCode    = 3;
             db.ExpenseAccounts.Add(exPurchase);
             db.SaveChanges();
             var maxCode = db.ExpenseAccounts.ToList().OrderByDescending(r => r.code).FirstOrDefault();
             exSale.code          = maxCode == null ? 1 : (maxCode.code) + 1;
             exSale.accountType   = "Revenue";
             exSale.description   = "Sale Account";
             exSale.isGroup       = false;
             exSale.isActive      = true;
             exSale.name          = product.name + " Sale";
             exSale.openingCredit = 0;
             exSale.openingDebit  = 0;
             exSale.parentCode    = 2;
             db.ExpenseAccounts.Add(exSale);
             db.SaveChanges();
             product.chartOfAccCode = exPurchase.code;
             db.Products.Add(product);
         }
         else
         {
             var prDb  = db.Products.Single(m => m.productCode == pr.productCode);
             var exDBP = db.ExpenseAccounts.Single(m => m.code == pr.chartOfAccCode);
             prDb.productCode  = product.productCode;
             prDb.name         = product.name;
             prDb.UOM          = product.UOM;
             prDb.categoryCode = product.categoryCode;
             prDb.categoryName = product.categoryName;
             prDb.price        = product.price;
             exDBP.name        = product.name + " Purchase";
             var exDBS = db.ExpenseAccounts.SingleOrDefault(m => m.code == pr.chartOfAccCode + 1);
             exDBS.name = product.name + " Sale";
         }
         db.SaveChanges();
         return(RedirectToAction("Add"));
     }
     ViewBag.cat      = db.Categories.ToList();
     ViewBag.Products = (db.Products.ToList().ToPagedList(page ?? 1, 8));
     //ViewBag.Products = (db.Products.ToList().ToPagedList(page ?? 1, 8));
     //ViewBag.cat = new SelectList(db.Categories.ToList(), "categoryName", "categoryName");
     return(View(product));
 }
Esempio n. 11
0
        /// <summary>
        /// 设置关联支出账户
        /// </summary>
        /// <param name="account">支出账户</param>
        /// <param name="energyType">能源支出类型</param>
        public void SetAccount(ExpenseAccount account, EnergyExpenseType energyType)
        {
            this.currentAccount = account;
            this.energyType     = energyType;
            this.nowYear        = DateTime.Now.Year;

            InitControls();
        }
        /// <summary>
        /// 显示对比
        /// </summary>
        /// <param name="account"></param>
        private void DisplayCompare(ExpenseAccount account)
        {
            this.electricCompareGridMod.SetAccount(account, EnergyExpenseType.Electric);
            this.electricCompareChartMod.SetAccount(account, EnergyExpenseType.Electric);

            this.waterCompareGridMod.SetAccount(account, EnergyExpenseType.Water);
            this.waterCompareChartMod.SetAccount(account, EnergyExpenseType.Water);
        }
Esempio n. 13
0
        /// <summary>
        /// 设置关联支出账户
        /// </summary>
        /// <param name="account">支出账户</param>
        /// <param name="energyType">能源支出类型</param>
        public void SetAccount(ExpenseAccount account, EnergyExpenseType energyType)
        {
            this.currentAccount = account;
            this.energyType     = energyType;

            InitControls();
            InitCompareData();
        }
        // GET: /Expense/Expenses
        public ActionResult Expenses(int?page)
        {
            ExpenseAccount ex    = new ExpenseAccount();
            var            maxId = db.ExpenseAccounts.ToList().OrderByDescending(r => r.code).FirstOrDefault();

            ex.code           = maxId == null ? 1 : (maxId.code) + 1;
            ViewBag.parentAcc = db.ExpenseAccounts.Where(r => r.isGroup == true).ToList();
            ViewBag.expenses  = (db.ExpenseAccounts.Where(r => r.isActive == true).ToList().ToPagedList(page ?? 1, 8));
            return(View(ex));
        }
        public void CreateInstance_ReadDataOK()
        {
            var sut = new ExpenseAccount();

            Assert.NotNull(sut);
            Assert.False(string.IsNullOrWhiteSpace(sut.PathToDailyData));

            sut.Expenses = DailyDataUtilities.ReadIntsFromFile("Day01Data.txt");
            Assert.Equal(200, sut.Expenses.Count);
            Assert.Equal(1769, sut.Expenses[199]);
        }
Esempio n. 16
0
        public IHttpActionResult GetExpenseAccount(int id)
        {
            ExpenseAccount expenseAccount = db.ExpenseAccounts.Find(id);

            if (expenseAccount == null)
            {
                return(NotFound());
            }

            return(Ok(expenseAccount));
        }
        /// <summary>
        /// 账户选择
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lbAccount_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.lbAccount.SelectedItem == null)
            {
                return;
            }

            this.currentAccount          = this.lbAccount.SelectedItem as ExpenseAccount;
            this.electricGrid.DataSource = this.currentAccount.ElectricMeters;
            this.waterGrid.DataSource    = this.currentAccount.WaterMeters;
            this.txtName.Text            = this.currentAccount.Name;
        }
        /// <summary>
        /// 设置账户
        /// </summary>
        /// <param name="id">支出账户ID</param>
        public void SetAccount(string id)
        {
            this.currentAccount = BusinessFactory <ExpenseAccountBusiness> .Instance.FindById(id);

            this.nowYear = DateTime.Now.Year;

            ClearDisplay();
            DisplaySummary(this.currentAccount);
            DisplayReceipt(this.currentAccount);
            DisplayCompare(this.currentAccount);
            DisplayYear(this.currentAccount);
        }
        public void FindSumOfTripleIs2020_Part1()
        {
            var sut = new ExpenseAccount();

            sut.Expenses = DailyDataUtilities.ReadIntsFromFile("Day01Data.txt");
            Assert.Equal(200, sut.Expenses.Count);
            Assert.Equal(1769, sut.Expenses[199]);

            var result = sut.FindTripleWithSum(2020);

            Assert.Equal(65656536, result);
        }
        public JsonResult DeleteConfirmed(int?id)
        {
            bool           result = false;
            ExpenseAccount exp    = db.ExpenseAccounts.SingleOrDefault(m => m.code == id);

            if (exp != null)
            {
                db.ExpenseAccounts.Remove(exp);
                db.SaveChanges();
                result = true;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 21
0
        public IHttpActionResult DeleteExpenseAccount(int id)
        {
            ExpenseAccount expenseAccount = db.ExpenseAccounts.Find(id);

            if (expenseAccount == null)
            {
                return(NotFound());
            }

            db.ExpenseAccounts.Remove(expenseAccount);
            db.SaveChanges();

            return(Ok(expenseAccount));
        }
        /// <summary>
        /// 账户选择
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void groupTree_OrganizationSelected(object sender, EventArgs e)
        {
            string id = this.groupTree.GetCurrentSelectId();

            if (id == null)
            {
                this.currentAccount = null;
            }
            else
            {
                this.currentAccount = BusinessFactory <ExpenseAccountBusiness> .Instance.FindById(id);

                InitAccountInfo();
            }
        }
        public ActionResult Edit(int?id, int?page)
        {
            ViewBag.expenses  = (db.ExpenseAccounts.ToList().ToPagedList(page ?? 1, 8));
            ViewBag.parentAcc = db.ExpenseAccounts.Where(r => r.isGroup == true).ToList();
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ExpenseAccount exp = db.ExpenseAccounts.Find(id);

            if (exp == null)
            {
                return(HttpNotFound());
            }
            return(View("Expenses", exp));
        }
        public void FindSumOfPairIs2020()
        {
            var sut = new ExpenseAccount();

            sut.Expenses = new List <int>()
            {
                1721,
                979,
                366,
                299,
                675,
                1456
            };

            var result = sut.FindPairWithSum(2020);

            Assert.Equal(514579, result);
        }
        public void FindSumOfTripleIs2020()
        {
            var sut = new ExpenseAccount();

            sut.Expenses = new List <int>()
            {
                1721,
                979,
                366,
                299,
                675,
                1456
            };

            var result = sut.FindTripleWithSum(2020);

            Assert.Equal(241861950, result);
        }
Esempio n. 26
0
        /// <summary>
        /// 载入数据
        /// </summary>
        /// <param name="account">支出账户</param>
        /// <param name="year">年度</param>
        /// <param name="energyType">能源类型</param>
        private async void LoadAccountData(ExpenseAccount account, int year, EnergyExpenseType energyType)
        {
            switch (energyType)
            {
            case EnergyExpenseType.Electric:
                var data1 = await LoadElectric(account, year);

                this.expenseGrid.DataSource    = data1;
                this.expenseGrid.ShowUnitPrice = false;
                this.expenseGrid.ShowAddition("功率因数奖(元)");
                break;

            case EnergyExpenseType.Water:
                var data2 = await LoadWater(account, year);

                this.expenseGrid.DataSource    = data2;
                this.expenseGrid.ShowUnitPrice = true;
                break;
            }
        }
 public ActionResult Customers([Bind(Include = "customerCode,name,contact,address,creditLimit,chartOfAccCode,openingDebit")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         Customer       c  = db.Customers.Find(customer.customerCode);
         ExpenseAccount ex = new ExpenseAccount();
         if (c == null)
         {
             var maxCode = db.ExpenseAccounts.ToList().OrderByDescending(r => r.code).FirstOrDefault();
             ex.code          = maxCode == null ? 1 : (maxCode.code) + 1;
             ex.accountType   = "Assets";
             ex.description   = "Customers Accounts";
             ex.isGroup       = false;
             ex.isActive      = true;
             ex.name          = customer.name + " Receivables";
             ex.parentCode    = 4; // This is Manual entry
             ex.openingCredit = 0;
             ex.openingDebit  = customer.openingDebit;
             db.ExpenseAccounts.Add(ex);
             db.SaveChanges();
             customer.chartOfAccCode = ex.code;
             db.Customers.Add(customer);
         }
         else
         {
             var cDB = db.Customers.SingleOrDefault(m => m.customerCode == customer.customerCode);
             var eDB = db.ExpenseAccounts.SingleOrDefault(m => m.code == customer.chartOfAccCode);
             cDB.customerCode = customer.customerCode;
             cDB.name         = customer.name;
             cDB.contact      = customer.contact;
             cDB.address      = customer.address;
             cDB.creditLimit  = customer.creditLimit;
             eDB.name         = customer.name;
             eDB.openingDebit = customer.openingDebit;
         }
         db.SaveChanges();
         return(RedirectToAction("Customers"));
     }
     return(View(customer));
 }
Esempio n. 28
0
 public ActionResult Vendors([Bind(Include = "vendorCode,name,contact,address,debitLimit,chartOfAccCode, openingCredit")] Vendor vendor)
 {
     if (ModelState.IsValid)
     {
         Vendor         v  = db.Vendors.Find(vendor.vendorCode);
         ExpenseAccount ex = new ExpenseAccount();
         if (v == null)
         {
             var maxCode = db.ExpenseAccounts.ToList().OrderByDescending(r => r.code).FirstOrDefault();
             ex.code          = maxCode == null ? 1 : (maxCode.code) + 1;
             ex.accountType   = "Liability";
             ex.description   = "Vendors Accounts";
             ex.name          = vendor.name + " Payables";
             ex.parentCode    = 5;
             ex.isGroup       = false;
             ex.isActive      = true;
             ex.openingDebit  = 0;
             ex.openingCredit = vendor.openingCredit;
             db.ExpenseAccounts.Add(ex);
             db.SaveChanges();
             vendor.chartOfAccCode = ex.code;
             db.Vendors.Add(vendor);
         }
         else
         {
             var vDb = db.Vendors.SingleOrDefault(m => m.vendorCode == vendor.vendorCode);
             var eDb = db.ExpenseAccounts.SingleOrDefault(m => m.code == vendor.chartOfAccCode);
             vDb.vendorCode    = vendor.vendorCode;
             vDb.name          = vendor.name;
             vDb.contact       = vendor.contact;
             vDb.address       = vendor.address;
             vDb.debitLimit    = vendor.debitLimit;
             eDb.name          = vendor.name;
             eDb.openingCredit = vendor.openingCredit;
         }
         db.SaveChanges();
         return(RedirectToAction("Vendors"));
     }
     return(View(vendor));
 }
Esempio n. 29
0
        /// <summary>
        /// 载入电费支出
        /// </summary>
        /// <param name="account"></param>
        /// <param name="year"></param>
        /// <returns></returns>
        private async Task <List <EnergyExpense> > LoadElectric(ExpenseAccount account, int year)
        {
            var task = Task.Run(() =>
            {
                List <EnergyExpense> electricData = new List <EnergyExpense>();
                var electricExpense = BusinessFactory <ElectricExpenseBusiness> .Instance.FindYearByAccount(account.Id, year);

                foreach (var exp in electricExpense)
                {
                    var model          = new EnergyExpense();
                    model.BelongDate   = exp.BelongDate;
                    model.Quantum      = exp.TotalQuantity;
                    model.Amount       = exp.TotalAmount;
                    model.AdditionData = exp.TotalPrize;

                    electricData.Add(model);
                }
                return(electricData);
            });

            return(await task);
        }
Esempio n. 30
0
        /// <summary>
        /// 载入水费支出
        /// </summary>
        /// <param name="account"></param>
        /// <param name="year"></param>
        /// <returns></returns>
        private async Task <List <EnergyExpense> > LoadWater(ExpenseAccount account, int year)
        {
            var task = Task.Run(() =>
            {
                List <EnergyExpense> expenseData = new List <EnergyExpense>();
                var waterExpense = BusinessFactory <WaterExpenseBusiness> .Instance.FindYearByAccount(account.Id, year);

                foreach (var exp in waterExpense)
                {
                    var model        = new EnergyExpense();
                    model.BelongDate = exp.BelongDate;
                    model.Quantum    = exp.TotalQuantity;
                    model.Amount     = exp.TotalAmount;
                    model.UnitPrice  = exp.TotalAmount / exp.TotalQuantity;

                    expenseData.Add(model);
                }
                return(expenseData);
            });

            return(await task);
        }