public static void ListFile() { var listItems = new ExcelQueryFactory(Path) { DatabaseEngine = LinqToExcel.Domain.DatabaseEngine.Ace, TrimSpaces = LinqToExcel.Query.TrimSpacesType.Both, UsePersistentConnection = true, ReadOnly = true }; var pointsList = from a in listItems.Worksheet <PointItem>("Sheet1") select a; using (var db = new PointDbEntities()) { foreach (PointItem pointItem in pointsList) { if (pointItem.Adress != null) { PointListItems item = new PointListItems() { Id = Guid.NewGuid(), Adress = pointItem.Adress, GLN = pointItem.Gln }; db.PointListItems.Add(item); db.SaveChanges(); Count++; } } } }
static List <string> GetAllPoints() { var result = new List <string>(); try { using (var db = new PointDbEntities()) { result.AddRange(db.PointListItems.Select(x => x.GLN)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(result); }
static List <string> GetExistingPoints() { var result = new List <string>(); try { using (var db = new PointDbEntities()) { result.AddRange(db.CurrentPoints.Where(p => p.Customer == "Фудком(36)").Select(x => x.GLN)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(result); }
private static void ProcessList(string customerUrl, string customerName) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Start Porcessing Points. Customer: {0}", customerName); Console.ResetColor(); PointDbEntities db = new PointDbEntities(); var currentPointsList = new List <CurrentPoints>(); try { Driver.Navigate().GoToUrl(customerUrl); var table = Driver.FindElementByXPath("//table"); var rows = table.FindElements(By.TagName("td")); int i = 0; for (int z = 0; z < rows.Count;) { CurrentPoints cPoint = new CurrentPoints(); for (int a = 0; a < 4; a++) { if (a == 0) { cPoint.Adress = rows[z].Text.ToString(); } else if (a == 1) { cPoint.GLN = rows[z].Text.ToString(); } else if (a == 3) { cPoint.Id = Guid.NewGuid(); cPoint.Customer = customerName; currentPointsList.Add(cPoint); Console.WriteLine("{0} Add point: adress {1}, Gln {2}, Customer {3}", i, cPoint.Adress, cPoint.GLN, cPoint.Customer); TotalPointCounter++; } z++; } i++; } db.CurrentPoints.AddRange(currentPointsList); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error!!! {0}", ex.Message); Console.WriteLine(ex.StackTrace); Console.ResetColor(); } try { db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } }