/// <summary> /// Заполняем списки разными способами /// </summary> /// <param name="take"></param> /// <param name="skip"></param> private void fillLists(int take, int skip) { void littleFiller <cl>(TableInit.Init a, TableInit.GetRow <cl> b, List <cl> lst, string c, SqlDataAdapter adapter, string connectionString1) { var Table = a(); adapter.SelectCommand = QueryGenerator.GenerateSelectQuery(c, connectionString1); adapter.Fill(Table); foreach (DataRow row in Table.Rows) { lst.Add(b(row)); } } var connectionString = ConfigurationManager.ConnectionStrings["tpDb"].ConnectionString; using (var adapter = new SqlDataAdapter()) { //Используя специальную функцию littleFiller(TableInit.CustomerInit, TableInit.CustomerGetRow, custList, "Customer", adapter, connectionString); //Испольхуя встроенные методы driverList = Driver.GetDrivers(connectionString, adapter); adList = Address.GetAddresses(connectionString, adapter); carList = Car.GetCars(connectionString, adapter); d2aList = D2A.GetD2As(connectionString, adapter, carList, driverList); //Ещё 1 метод var Table = TableInit.OrderInit(); adapter.SelectCommand = QueryGenerator.GenerateSelectQuery("Orders", connectionString); adapter.Fill(Table); foreach (DataRow row in Table.Rows) { ordList.Add(TableInit.OrderGetRow(row, d2aList, adList, custList)); } Table = TableInit.WayInit(); adapter.SelectCommand = QueryGenerator.GenerateSelectQuery("Metrics", connectionString); adapter.Fill(Table); foreach (DataRow row in Table.Rows) { wayList.Add(TableInit.WayGetRow(row, adList)); } //Сортировка switch (sortType.Value) { case "2": ordList = ordList.OrderBy(o => o.Customer.Name).ToList(); break; case "3": ordList = ordList.OrderBy(o => o.d2a.Auto.Mark).ToList(); break; case "4": ordList = ordList.OrderBy(o => o.d2a.Driver.Name).ToList(); break; case "5": ordList = ordList.OrderBy(o => o.Way.From.street).ToList(); break; case "6": ordList = ordList.OrderBy(o => o.d2a.Date).ToList(); break; case "7": ordList = ordList.OrderBy(o => o.Price).ToList(); break; default: break; } ordList = ordList .Skip(skip) .Take(take) .ToList(); } //Используя LINQ-To-SQL DataContext db = new DataContext(connectionString); rsList = db.GetTable <RadioStation>().ToList(); }
private void fillLists() { using (var adapter = new SqlDataAdapter()) (d2aList, carList, driverList) = D2A.GetD2As(ConfigurationManager.ConnectionStrings["tpDb"].ConnectionString, adapter); d2aList = d2aList.OrderByDescending(x => x.Date).ToList(); }