static void Main() { Item sallingerBook = new Book("4adwlj4", "Catcher in the Rye", 20.00m, "J. D. Salinger", "fiction"); Item threeManBook = new Book("84djesd", "Three Men in a Boat", 39.99m, "Jerome K. Jerome", new List<string> { "comedy" }); Item acGame = new Game("9gkjdsa", "AC Revelations", 78.00m, "historical", AgeRestriction.Teen); Item bubbleSplashGame = new Game("r8743jf", "Bubble Splash", 7.80m, new List<string> { "child", "fun" }); Item godfatherMovie = new Movie("483252j", "The Godfather", 99.00m, 178, "crime"); Item dieHardMovie = new Movie("9853kfds", "Die Hard 4", 9.90m, 144, new List<string> { "action", "crime", "thriller" }); DateTime today = DateTime.Now; DateTime fiveYearsAgo = today.AddYears(-5); Sale dieHardSale = new Sale(dieHardMovie, fiveYearsAgo); Console.WriteLine(dieHardSale.DateOfPurchase); // 1/30/2015 2:31:55 PM (today) Sale acSale = new Sale(acGame); Console.WriteLine(acSale.DateOfPurchase); // 1/30/2010 2:31:55 PM DateTime afterOneWeek = today.AddDays(30); Rent bookRent = new Rent(sallingerBook, today, afterOneWeek); Console.WriteLine(bookRent.RentStatus); // Pending DateTime lastMonth = today.AddDays(-34); DateTime lastWeek = today.AddDays(-8); Rent movieRent = new Rent(godfatherMovie, lastMonth, lastWeek); Console.WriteLine(movieRent.RentStatus); // Overdue movieRent.ReturnItem(); Console.WriteLine(movieRent.RentStatus); // Returned Console.WriteLine(movieRent.ReturnDate); // 1/30/2015 2:41:53 PM Console.WriteLine(movieRent.CalculateRentFine()); // 7.9200 ShopEngine.Run(); }
private void GenerateSalesReport(DateTime date, ExcelRow row, int dbSupermarketId, int dbProductId) { var quantity = int.Parse(row.AllocatedCells[2].Value.ToString()); var unitPrice = decimal.Parse(row.AllocatedCells[3].Value.ToString()); var totalSum = decimal.Parse(row.AllocatedCells[4].Value.ToString()); var salesReport = new Sale { SupermarketId = dbSupermarketId, ProductId = dbProductId, Quantity = quantity, UnitPrice = unitPrice, TotalSum = totalSum, Date = date }; this.SalesReports.Add(salesReport); }
private IEnumerable<Sale> ReadSalesFromExcellSheet(string path) { var sales = new List<Sale>(); string connectionString = string.Format(ConnectionString, path); var excellCon = new OleDbConnection(connectionString); excellCon.Open(); using (excellCon) { var excelSchema = excellCon.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); var sheetName = excelSchema.Rows[0]["TABLE_NAME"].ToString(); var excelDbCommand = new OleDbCommand(@"SELECT * FROM [" + sheetName + "]", excellCon); var sale = new Sale(); using (var reader = excelDbCommand.ExecuteReader()) { while (reader.Read()) { sale.Id = int.Parse(reader["SaleId"].ToString()); sale.PartId = int.Parse(reader["ProductId"].ToString()); sale.Quantity = int.Parse(reader["Quantity"].ToString()); sale.UnitPrice = decimal.Parse(reader["UnitPrice"].ToString()); sale.Date = (DateTime)reader["Date"]; sale.VendorId = int.Parse(reader["VendorId"].ToString()); sales.Add(sale); sale = new Sale(); } } } return sales; }
private static IEnumerable<Sale> ExtractExcelData(string excelFilePath, string excelFileName, string date) { var connectionStringFormat = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}; Extended Properties=Excel 8.0"; var connectionString = string.Format(connectionStringFormat, excelFilePath); var conn = new OleDbConnection(connectionString); conn.Open(); var command = new OleDbCommand("Select * From [Sales$]", conn); var adapter = new OleDbDataAdapter(); adapter.SelectCommand = command; var dataSet = new DataSet(); adapter.Fill(dataSet, excelFileName); var table = dataSet.Tables[0]; Console.WriteLine(table.TableName); var sales = new List<Sale>(); foreach (DataRow data in table.Rows) { try { var sale = new Sale { BookId = int.Parse(data[0].ToString()), Quantity = int.Parse(data[1].ToString()), UnitPrice = decimal.Parse(data[2].ToString()), Sum = decimal.Parse(data[3].ToString()), Location = excelFileName, Date = DateTime.Parse(date) }; sales.Add(sale); } catch { } } conn.Close(); return sales; }
public static void AddSale(IItem itemSold, DateTime dateOfSale) { ISale sale = new Sale(itemSold, dateOfSale); Sales.Add(sale); }