예제 #1
0
파일: Address.cs 프로젝트: andru196/Taxi
        /// <summary>
        /// Генерирует список адрессов в соответствии с базой данных
        /// </summary>
        /// <param name="connectionString">Строка подключений</param>
        /// <param name="adapter">SqlDataAdapter  для заполнения DataSet</param>
        /// <returns></returns>
        public static List <Address> GetAddresses(string connectionString, SqlDataAdapter adapter)
        {
            List <Address> la    = new List <Address>();
            DataTable      Table = TableInit.AddressInit();

            adapter.SelectCommand = QueryGenerator.GenerateSelectQuery("Address order by street", connectionString);
            adapter.Fill(Table);
            foreach (DataRow row in Table.Rows)
            {
                la.Add(TableInit.AddressGetRow(row));
            }
            return(la);
        }
예제 #2
0
파일: Car.cs 프로젝트: andru196/Taxi
        /// <summary>
        /// Возвращает список автомобилей из БД
        /// </summary>
        /// <param name="connectionString">Строка соединения</param>
        /// <param name="adapter">SqlDataAdapter</param>
        /// <returns></returns>
        public static List <Car> GetCars(string connectionString, SqlDataAdapter adapter)
        {
            List <Car> lc    = new List <Car>();
            DataTable  Table = TableInit.AutoInit();

            adapter.SelectCommand = QueryGenerator.GenerateSelectQuery("auto", connectionString);
            adapter.Fill(Table);
            foreach (DataRow row in Table.Rows)
            {
                lc.Add(TableInit.CarGetRow(row));
            }
            return(lc);
        }
예제 #3
0
        public static List <D2A> GetD2As(string connectionString, SqlDataAdapter adapter, List <Car> carList, List <Driver> driverList)
        {
            List <D2A> d2al  = new List <D2A>();
            DataTable  Table = TableInit.D2AInit();

            adapter.SelectCommand = QueryGenerator.GenerateSelectQuery("Drivers2Auto", connectionString);
            adapter.Fill(Table);
            foreach (DataRow row in Table.Rows)
            {
                d2al.Add(TableInit.D2AGetRow(row, carList, driverList));
            }
            return(d2al);
        }
예제 #4
0
파일: Driver.cs 프로젝트: andru196/Taxi
        public static List <Driver> GetDrivers(string connectionString, SqlDataAdapter adapter)
        {
            List <Driver> ld    = new List <Driver>();
            DataTable     Table = TableInit.DriversInit();

            adapter.SelectCommand = QueryGenerator.GenerateSelectQuery("drivers", connectionString);
            adapter.Fill(Table);
            foreach (DataRow row in Table.Rows)
            {
                ld.Add(TableInit.DriverGetRow(row));
            }

            return(ld);
        }
예제 #5
0
        /// <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();
        }