//Check to see if the two dates are equals-------------------------------------------------- public bool checkDates() { bool dtDiff = false; //Rquired Date Format String format = "dd/MM/yyyy"; //Get the current date var currentDate = DateTime.Now.ToString("dd/MM/yyyy"); var getCYear = DateTime.Now.Year.ToString(); //EndDate of the year var endDate = "31/12/" + getCYear; //currentDate = "01/10/2017"; DateTime dt1 = DateTime.ParseExact(currentDate.ToString(), format, System.Globalization.CultureInfo.InvariantCulture); DateTime dt2 = DateTime.ParseExact(endDate.ToString(), format, System.Globalization.CultureInfo.InvariantCulture); //find the difference if (dt1.Date < dt2.Date) { YearMaxBillNo yrbl = new YearMaxBillNo(); //yrbl.maxbillno= dtDiff = true; } return(dtDiff); }
//TODO: Add new Bill---------------------------------------------------------------- public void AddNewBill(AddNewBill bdv) { //hear we are going to get the max no form YearMaxBillNo., why we do that because that no will be used to form the finall bill no. int maxNo = 0; using (LundryDbContext db = new LundryDbContext()) { if (checkDates()) //if the current date is less than the end date which is the last day in the year e.g (31/12/2016) { //TODO: if result is true...get max from the current year; var getCYear = DateTime.Now.Year.ToString(); maxNo = getMaxBillNo(getCYear); //get the max bill no depending on the year from table yearmaxbillnoes AddBill(maxNo); //calling the method AddBill to add the new bill to the database //update the YearMaxBillNoes by adding the new max bill no to the year int getCount = db.yearmaxbillno.Where(x => x.year.Equals(getCYear)).Count(); if (getCount > 0) // check to see if we are not at the begining of the year { YearMaxBillNo yrbl = db.yearmaxbillno.Where(x => x.year.Equals(getCYear)).FirstOrDefault(); yrbl.maxbillno = (maxNo + 1); db.SaveChanges(); } else { YearMaxBillNo yrbl = new YearMaxBillNo(); yrbl.year = getCYear; yrbl.maxbillno = 1; db.yearmaxbillno.Add(yrbl); db.SaveChanges(); } } else { //TODO: if result is true...get max from the current year; var getCYear = DateTime.Now.Year.ToString(); maxNo = getMaxBillNo(getCYear); //get the max bill no depending on the year from table yearmaxbillnoes AddBill(maxNo); //calling the method AddBill to add the new bill to the database //update the YearMaxBillNoes by adding the new max bill no to the year YearMaxBillNo yrbl = db.yearmaxbillno.Where(x => x.year.Equals(getCYear)).FirstOrDefault(); if (string.IsNullOrEmpty(yrbl.year)) { yrbl.maxbillno = maxNo + 1; db.SaveChanges(); } else { yrbl.year = getCYear; yrbl.maxbillno = 1; db.SaveChanges(); } } } }