// Обработка #region /// <summary> /// Добавляем заказ в БД /// </summary> /// <param name="ord"></param> /// <param name="sqc"></param> /// <param name="flag"></param> protected void addOrdToDb(Order ord, QueryGenerator.SomeSqlCommand sqc, UpdateType flag) { using (var adapter = new SqlDataAdapter()) { string connectionString = ConfigurationManager.ConnectionStrings["tpDb"].ConnectionString; //инициируем таблицу-представление var ordTable = TableInit.OrderInit(); //генерация новой записи var newRow = TableInit.OrderAddRow(ordTable, ord); ordTable.Rows.Add(newRow); // Проверим, есть ли в таблице данный пользователь if (flag == UpdateType.Update) { if (custList.Where(c => c.Phone == ord.Customer.Phone).Count() == 0) { DataContext db = new DataContext(connectionString); db.GetTable <Customer>().InsertOnSubmit(ord.Customer); db.SubmitChanges(); } } //инициировать строку запроса adapter.InsertCommand = sqc(connectionString, flag); adapter.Update(ordTable); } }
/// <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(); }