示例#1
0
        public async Task <TaxiAutorizations> TaxiFromPlateSqliteAll()
        {
            TaxiAutorizations ret = new TaxiAutorizations();

            using (var con = new SqliteConnection())
            {
                con.ConnectionString = "Data Source=taxis.sqlite3;";


                await con.OpenAsync();

                using (var cmd = con.CreateCommand())
                {
                    cmd.CommandText = "select * from bucuresti";
                    using (var rd = await cmd.ExecuteReaderAsync())
                    {
                        while (await rd.ReadAsync())
                        {
                            // just first record

                            Func <object, string> empty = (rec) =>
                            {
                                if (rec == null)
                                {
                                    return("");
                                }
                                if (rec == DBNull.Value)
                                {
                                    return("");
                                }
                                string value = rec.ToString();
                                if (string.IsNullOrWhiteSpace(value))
                                {
                                    return("");
                                }

                                return(value);
                            };
                            string line = "";
                            line += empty(rd["Nr. Aut. Taxi"]);
                            line += "|";
                            line += empty(rd["Stare Aut. Taxi"]);
                            line += "|";
                            line += empty(rd["Nume Transportator"]);
                            line += "|";
                            line += empty(rd["Marca Auto"]);
                            line += "|";
                            line += empty(rd["An Fabricatie Auto"]);
                            line += "|";
                            line += empty(rd["Nr. Inmatriculare Auto"]);
                            line += "|";
                            line += empty(rd["Expirare Valabilitate"]);
                            line += "|";
                            line += empty(rd["Observatii"]);
                            var bucarestCSV = new BucarestCSV(line);
                            var err         = bucarestCSV.Parse().FirstOrDefault();
                            if (err != null)
                            {
                                throw new ArgumentException($"line:{line} ex:{ err.ErrorMessage}");
                            }
                            ret.Add(FromBucarestCSV(bucarestCSV));
                        }
                    }
                }

                return(ret);
            }
        }
示例#2
0
        public async Task <TaxiAutorization> TaxiFromPlateSqlite(string plateNumber)
        {
            if (string.IsNullOrWhiteSpace(plateNumber))
            {
                return(null);
            }
            plateNumber = plateNumber.ToLower();
            using (var con = new SqliteConnection())
            {
                con.ConnectionString = "Data Source=taxis.sqlite3;";

                //con.ConnectionString = "taxis.sqlite3";
                await con.OpenAsync();

                BucarestCSV bucarestCSV = null;
                using (var cmd = con.CreateCommand())
                {
                    cmd.CommandText = "select * from bucuresti where lower([Nr. Inmatriculare Auto])=@plate";
                    cmd.Parameters.AddWithValue("@plate", plateNumber);
                    using (var rd = await cmd.ExecuteReaderAsync())
                    {
                        while (await rd.ReadAsync())
                        {
                            // just first record
                            if (bucarestCSV != null)
                            {
                                break;
                            }
                            Func <object, string> empty = (rec) =>
                            {
                                if (rec == null)
                                {
                                    return("");
                                }
                                if (rec == DBNull.Value)
                                {
                                    return("");
                                }
                                string value = rec.ToString();
                                if (string.IsNullOrWhiteSpace(value))
                                {
                                    return("");
                                }

                                return(value);
                            };
                            string line = "";
                            line       += empty(rd["Nr. Aut. Taxi"]);
                            line       += "|";
                            line       += empty(rd["Stare Aut. Taxi"]);
                            line       += "|";
                            line       += empty(rd["Nume Transportator"]);
                            line       += "|";
                            line       += empty(rd["Marca Auto"]);
                            line       += "|";
                            line       += empty(rd["An Fabricatie Auto"]);
                            line       += "|";
                            line       += empty(rd["Nr. Inmatriculare Auto"]);
                            line       += "|";
                            line       += empty(rd["Expirare Valabilitate"]);
                            line       += "|";
                            line       += empty(rd["Observatii"]);
                            bucarestCSV = new BucarestCSV(line);
                            var err = bucarestCSV.Parse().FirstOrDefault();
                            if (err != null)
                            {
                                throw new ArgumentException($"line:{line} ex:{ err.ErrorMessage}");
                            }
                        }
                    }
                }

                return(FromBucarestCSV(bucarestCSV));
            }
        }