public async Task <int> Update_Report_Count()
        {
            ReportCount reportCount = new ReportCount();
            int         id          = 1;

            var Model = await _context.ReportCount.SingleOrDefaultAsync(m => m.Id == id);

            // get the row count of ReportCount table


            // increment by one
            Model.Count = 0;


            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(reportCount);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                }
            }
            return(reportCount.Count);
        }
        public async Task <int> Update_Report_Count()
        {
            ReportCount reportCount = new ReportCount();

            // var Model = await _context.ReportCount.SingleOrDefaultAsync(m => m.Id == id);

            // get the row count of ReportCount table


            // increment by one
            reportCount.Count = 0;


            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(reportCount);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReportCountExists(reportCount.Id))
                    {
                        // return NotFound();
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(reportCount.Count);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Count")] ReportCount reportCount)
        {
            if (id != reportCount.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(reportCount);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReportCountExists(reportCount.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(reportCount));
        }
        public async Task <IActionResult> Create([Bind("Id,Count")] ReportCount reportCount)
        {
            if (ModelState.IsValid)
            {
                _context.Add(reportCount);
                await _context.SaveChangesAsync();

                // return RedirectToAction(nameof(Index));
            }
            return(View(reportCount));
        }
        public void CreateReportCount(int month, int year)
        {
            List <Book>           listBook           = BookDAO.Instance.GetListBook();
            List <ImportBookInfo> listImportBookInfo = ImportBookInfoDAO.Instance.GetListImportBookInfoByTime(month, year); // trong thang xu ly
            List <BillInfo>       listBillInfo       = BillInfoDAO.Instance.GetListBillInfoByTime(month, year);             // trong thang xu ly

            foreach (Book book in listBook)
            {
                int firstCount      = 0;
                int lastCount       = 0;
                int addCount        = 0;
                int countBookInBill = 0;

                foreach (BillInfo item in listBillInfo)
                {
                    if (item.IdBook == book.ID)
                    {
                        countBookInBill += item.Count;
                    }
                }
                foreach (ImportBookInfo item in listImportBookInfo)
                {
                    if (item.IDBook == book.ID)
                    {
                        addCount += item.Count;
                    }
                }

                DateTime date = (new DateTime(year, month, 1)).AddMonths(-1); // thang truoc
                if (ReportCountDAO.Instance.CheckReportCount(date.Month, date.Year))
                {
                    ReportCount rp = ReportCountDAO.Instance.GetReportCountInfoByTimeAndBookID(date.Month, date.Year, book.ID);
                    if (rp != null)
                    {
                        firstCount = rp.LastCount;
                    }
                    else
                    {
                        firstCount = 0;
                    }
                }
                else
                {
                    firstCount = 0;
                }
                lastCount = firstCount + addCount - countBookInBill;

                if (!ReportCountDAO.Instance.InsertReportCount(month, year, book.ID, firstCount, addCount, lastCount))
                {
                    MessageBox.Show("Có lỗi khi tạo báo cáo tháng!", "Thông báo");
                    return;
                }
            }
        }