Пример #1
0
        public static List <ConsumptionInfo> DealWithSheet2(XSSFWorkbook wk)
        {
            try
            {
                var sheet         = wk.GetSheet("Sheet2");
                var rows          = sheet.GetRowEnumerator();
                var listOrderInfo = new List <ConsumptionInfo>();
                rows.MoveNext();
                while (rows.MoveNext())
                {
                    var row   = (IRow)rows.Current;
                    var order = new ConsumptionInfo();
                    order.MemberId = row.GetCell(0).ToString().Trim();
                    order.Subject  = row.GetCell(1).StringCellValue.Trim();
                    var yearMonth = row.GetCell(2).DateCellValue;
                    order.Year        = yearMonth.Year;
                    order.Month       = yearMonth.Month;
                    order.Day         = yearMonth.Day;
                    order.ConsumCount = (int)row.GetCell(3).NumericCellValue;
                    order.Count       = (int)row.GetCell(4).NumericCellValue;
                    //order.StudentName = row.GetCell(5).StringCellValue;
                    listOrderInfo.Add(order);
                }

                return(listOrderInfo);
            }catch (Exception ex)
            {
                MessageBox.Show("获取Sheet2数据出问题");
                return(new List <ConsumptionInfo>());
            }
        }
        private static bool EachOrderEachStudent(ConcurrentDictionary <string, int> studentConsumcount, ConsumptionInfo item, OrderInfo order)
        {
            var key = GetStudentConsumeKey(item.MemberId, order.OrderId);

            var count = studentConsumcount.GetOrAdd(key, 0);

            count += item.Count;
            var result = false;

            if (count >= order.Count)
            {
                order.FinishYearMonth = item.ComsumDate.ToString("yyyy-MM");
                count -= order.Count;
                result = true;
            }
            studentConsumcount.AddOrUpdate(key, count, (old, newvalue) => count);
            return(result);
        }