public void ReadVehicles() { try { string path = ""; OpenFileDialog filedialog = new OpenFileDialog(); filedialog.Filter = "CSV Files (*.csv)|*.csv"; filedialog.FilterIndex = 1; filedialog.Multiselect = false; if (filedialog.ShowDialog() == DialogResult.OK) { path = filedialog.FileName; } else { return; } List <vehicles> values = File.ReadAllLines(path) .Skip(1) .Select(v => vehicles.FromCsv(v)) .ToList(); DataAccess dtc = new DataAccess(); SQLCreation cre = new SQLCreation(); dtc.SQLCommand(Properties.Settings.Default.DBName, cre.vehicles()); dtc.CreateBulckVehicles(Properties.Settings.Default.DBName, path); } catch (Exception e) { MessageBox.Show(@"There was an error. Probably you tried to read a wrong csv file." + Environment.NewLine + Environment.NewLine + "Error: " + e.ToString()); } }
private void Button_Click_RecreateDB(object sender, RoutedEventArgs e) { SQLCreation sql = new SQLCreation(); DataAccess dts = new DataAccess(); //string command = sql.CreateDB() + sql.User() + sql.CarProduct() + sql.categories() + sql.vehicles(); dts.SQLCommand(Properties.Settings.Default.DBName, sql.CreateDB()); dts.SQLCommand(Properties.Settings.Default.DBName, sql.User()); dts.SQLCommand(Properties.Settings.Default.DBName, sql.CreateFirstUser()); dts.SQLCommand(Properties.Settings.Default.DBName, sql.categories()); dts.SQLCommand(Properties.Settings.Default.DBName, sql.vehicles()); dts.SQLCommand(Properties.Settings.Default.DBName, sql.CarProduct()); }
private bool CheckUnique(string Username) { SQLCreation sql = new SQLCreation(); int author = Int32.Parse(dts.LoginAuth(Properties.Settings.Default.DBName, sql.AuthUserName(Username))); if (author > 0) { return(true); } else { return(false); } }
private void OK_Click(object sender, EventArgs e) { DataAccess dts = new DataAccess(); SQLCreation sql = new SQLCreation(); int author = Int32.Parse(dts.LoginAuth(Properties.Settings.Default.DBName, sql.AuthUser(textBoxUserName.Text, textBoxPassword.Text))); if (author > 0) { caching.LoginFlag = author; this.Close(); } else { //textBoxUserName.Text = ""; textBoxPassword.Text = ""; textBoxPassword.Focus(); MessageBox.Show("Λάθος κωδικός ή όνομα χρήστη. "); } }
private void Button_Click_CreateDummy(object sender, RoutedEventArgs e) { DataAccess dt = new DataAccess(); SQLCreation sq = new SQLCreation(); dt.SQLCommand(Properties.Settings.Default.DBName, sq.CarProduct()); List <CarProduct> cars = new List <CarProduct>(); string temp = caching.CategoriesCached.Where(c => c.id == "1908").ToList()[0].name; for (int i = 1; i <= NumberOfObjects.Value / 10; i++) { DataAccess dts = new DataAccess(); String ran = ""; bool flag = true; while (flag) { Random generator = new Random(); ran = generator.Next(0, 9999).ToString("D4"); flag = dts.CheckIfCarProductExists(Properties.Settings.Default.DBName, ran); } cars.Add(new CarProduct { unique_id = ran, title = i.ToString(), description = i.ToString(), category_id = "1908", category_name = caching.CategoriesCached.Where(c => c.id == "1908").ToList()[0].name, price = i, photo = "http://antallaktika-smart.com/wp-content/uploads/Car_gr/SM-F2-3-001.JPG", conditions = "Μεταχειρισμένο", update_interval = i, make = "57", make_name = caching.VehiclesCached.Where(c => c.make_id == "57").ToList()[0].make_name, model = "1183", model_name = caching.VehiclesCached.Where(c => c.model_id == "1183").ToList()[0].model_name, yearfrom = 1980, yearto = 2018, amount = i, isParent = "ΝΑΙ", manufacturer_number = "none", aftermarket_number = "none", color = "none" } ); for (int j = 0; j < 10; j++) { cars.Add(new CarProduct { unique_id = ran + "-" + j.ToString(), title = i.ToString(), description = i.ToString(), category_id = "1908", category_name = caching.CategoriesCached.Where(c => c.id == "1908").ToList()[0].name, price = i, photo = "http://antallaktika-smart.com/wp-content/uploads/Car_gr/SM-F2-3-" + j + ".JPG", conditions = "Μεταχειρισμένο", update_interval = i, make = "57", make_name = caching.VehiclesCached.Where(c => c.make_id == "57").ToList()[0].make_name, model = "1183", model_name = caching.VehiclesCached.Where(c => c.model_id == "1183").ToList()[0].model_name, yearfrom = 1980, yearto = 2018, amount = i, isParent = "ΟΧΙ", manufacturer_number = "none", aftermarket_number = "none", color = caching.colors[i % 22] } ); } } dt.CreateCarProduct(Properties.Settings.Default.DBName, cars); }