// Метод получения данных, вызываемый в отдельном потоке private void _getData(object fileName) { bool result = false; try { var file = new FileInfo((string)fileName); using (var stream = new FileStream((string)fileName, FileMode.Open, FileAccess.Read)) { IExcelDataReader reader = null; if (file.Extension == ".xls") { reader = ExcelReaderFactory.CreateBinaryReader(stream); } else if (file.Extension == ".xlsx") { reader = ExcelReaderFactory.CreateOpenXmlReader(stream); } if (reader != null) { int sheet = 0; do { sheets.Add(new List <object>() { "Sheet" + sheet.ToString() }); while (reader.Read()) { object[] tmp = new object[reader.FieldCount]; for (int i = 0; i < reader.FieldCount; i++) { tmp[i] = reader.GetValue(i); } tmp = tmp.Where(item => item != null).ToArray(); if (tmp.Length > 0) { sheets.Add(tmp.ToList()); if (!result) { result = true; } } } sheet++; }while (reader.NextResult()); reader.Dispose(); reader = null; stream.Dispose(); } } } catch (Exception e) { Console.WriteLine(e); } resultListener?.Invoke(result); }
private void _Parse(object obj) { CallBackResult result = new CallBackResult(); try { List <List <object> > data = (List <List <object> >)obj; result.StartPeriodDate = GetStartPeriodDate(data); lBase.Transaction(); int i = 0; while (i < data.Count) { if (((string)data[i][0]).Equals(Stop_Sheet_Tag)) { break; } if (data[i].Find(cell => Convert.ToString(cell).Contains(Subscriber_Start_Tag)) != null) { Subscriber subscriber = new Subscriber() { Number = GetSubscriberNumber(data[i]) }; if (!String.IsNullOrEmpty(subscriber.Number)) { subscriber.Id = lBase.GetSubscriberIdByNumber(subscriber.Number); if (subscriber.Id == 0) { subscriber.Id = lBase.AddSubscriber(subscriber); } if (subscriber.Id == 0) { continue; } i++; while (i < data.Count) { if (data[i].Find(cell => Convert.ToString(cell).Contains(Subscriber_End_Tag)) != null) { break; } if (data[i].Find(cell => Convert.ToString(cell).Contains(Internet_Tag)) != null) { i++; while (i < data.Count) { if (FindHeadder(data[i], Internet_Headder) == true) { break; } i++; } i++; while (i < data.Count) { if (data[i].Find(cell => Convert.ToString(cell).Contains(End_Unit_Tag)) != null) { break; } Connection connection = GetConnection(data[i], DataType.Intertet); if (connection != null) { lBase.AddConnection(subscriber.Id, connection); } i++; } } if (data[i].Find(cell => Convert.ToString(cell).Contains(SMS_Tag)) != null) { i++; while (i < data.Count) { if (FindHeadder(data[i], SMS_Headder) == true) { break; } i++; } i++; while (i < data.Count) { if (data[i].Find(cell => Convert.ToString(cell).Contains(End_Unit_Tag)) != null) { break; } Connection connection = GetConnection(data[i], DataType.SMS); if (connection != null) { lBase.AddConnection(subscriber.Id, connection); } i++; } } if (data[i].Find(cell => Convert.ToString(cell).Contains(MMS_Tag)) != null) { i++; while (i < data.Count) { if (FindHeadder(data[i], MMS_Headder) == true) { break; } i++; } i++; while (i < data.Count) { if (data[i].Find(cell => Convert.ToString(cell).Contains(End_Unit_Tag)) != null) { break; } Connection connection = GetConnection(data[i], DataType.MMS); if (connection != null) { lBase.AddConnection(subscriber.Id, connection); } i++; } } if (data[i].Find(cell => Convert.ToString(cell).Contains(Phone_Tag)) != null) { i++; while (i < data.Count) { if (FindHeadder(data[i], Phone_Headder) == true) { break; } i++; } i++; while (i < data.Count) { if (data[i].Find(cell => Convert.ToString(cell).Contains(End_Unit_Tag)) != null) { break; } Connection connection = GetConnection(data[i], DataType.Phone); if (connection != null) { lBase.AddConnection(subscriber.Id, connection); } i++; } } i++; } } } i++; } result.Result = true; } catch (Exception e) { Console.WriteLine(e); } lBase.Commit(); resultListener?.Invoke(result); }