Example #1
0
        static void Main(string[] args)
        {
            FileStream readLogs;
            using (readLogs = new FileStream(OUTPUT_FILE, FileMode.OpenOrCreate)) { };
            int readCount = File.ReadLines(OUTPUT_FILE).Count();
            using (readLogs = new FileStream(OUTPUT_FILE, FileMode.Append))
            using (StreamWriter writer = new StreamWriter(readLogs))
            {
                IEnumerable<string> lines = File.ReadLines(INPUT_FILE).Skip(readCount);
                List<ReceiptItem> receiptItems = new List<ReceiptItem>();
                int newReceiptId = 0;

                foreach (string line in lines)
                {
                    //Search for business rule pattern
                    var dateMatch = Regex.Match(line, DATE_PATTERN, RegexOptions.IgnoreCase);
                    var purchaseItemMatch = Regex.Match(line, PURCHASE_ITEM_PATTERN, RegexOptions.IgnoreCase);

                    //if line contains a date and time (regex)
                    if (dateMatch.Success)
                    {
                        Console.WriteLine(dateMatch.Value);

                        // create a Receipt object
                        DateTime d = default(DateTime);
                        DateTime.TryParse(dateMatch.Value,out d);
                        if (d != DateTime.MinValue)
                        {
                            newReceiptId = ReceiptBLL.UpdateReceipt(new Receipt() { Date = d });
                            receiptItems = new List<ReceiptItem>();
                        }
                        else
                        {
                            continue; //something weird might have happened
                        }
                    }

                    // start processing line items (regex)
                    if (purchaseItemMatch.Success)
                    {
                        Console.WriteLine("{0}:{1}", purchaseItemMatch.Groups[1].Value, purchaseItemMatch.Groups[2].Value);

                        // create a list<ReceiptItem>
                        ReceiptItem item = new ReceiptItem();
                        item.Name = purchaseItemMatch.Groups[1].Value;
                        decimal cost = 0M;
                        decimal.TryParse(purchaseItemMatch.Groups[2].Value, out cost);
                        item.Cost = cost;
                        item.ProductName = ReceiptBLL.UpdateReceiptItem(newReceiptId, item);
                        receiptItems.Add(item);
                    }

                    //process as line read.
                    writer.WriteLine(line);
                }
            }
        }
Example #2
0
File: DAL.cs Project: rodchar/csgen
        private static List<ReceiptItem> GetGenericReceiptItemList(DataTable dt)
        {
            List<ReceiptItem> list = new List<ReceiptItem>();

            foreach (DataRow dr in dt.Rows)
            {
                ReceiptItem item = new ReceiptItem();
                item.Id = Convert.ToInt32(dr["Id"]);
                item.Name = dr["Name"].ToString();

                list.Add(item);
            }

            return list;
        }
Example #3
0
File: DAL.cs Project: rodchar/csgen
 //Save receipt item
 public static string UpdateReceiptItem(int receiptId, ReceiptItem item)
 {
     string productName = string.Empty;
     if (receiptId > 0)
     {
         productName = daReceiptItems.InsertQuery(receiptId, item.Name).ToString();
     }
     return productName;
 }