public void SaveAllOrders(DateTime date, List <Orders> orders) { string FileName = "Orders_" + date.Month.ToString("d2") + date.Day.ToString("d2") + date.Year + ".txt"; using (StreamWriter streamWriter = new StreamWriter(FileName)) { streamWriter.WriteLine("OrderNumber,CustomerName,State,TaxRate,ProductType,Area,CostPerSquareFoot,LaborCostPerSquareFoot,MaterialCost,LaborCost,Tax,Total"); foreach (Orders custOrder in orders) { streamWriter.WriteLine(OrdersMapper.ToStringCSV(custOrder)); } } }
public List <Orders> LoadOrders(DateTime date)//question about edit and remove load cause it just create one if it doesn't exist { List <Orders> orders = new List <Orders>(); FileName = "Orders_" + date.Month.ToString("d2") + date.Day.ToString("d2") + date.Year + ".txt"; if (!File.Exists(FileName)) { File.Create(FileName).Close(); return(orders); } using (StreamReader streamReader = new StreamReader(FileName)) { string row = streamReader.ReadLine(); while ((row = streamReader.ReadLine()) != null) { Orders o = OrdersMapper.ToOrder(row); o.dateTime = date; orders.Add(o); } } return(orders); }