示例#1
0
        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());
        }
        public void ReadCategories()
        {
            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 <categories> values = File.ReadAllLines(path)
                                           .Skip(1)
                                           .Select(v => categories.FromCsv(v))
                                           .ToList();


                DataAccess  dtc = new DataAccess();
                SQLCreation cre = new SQLCreation();
                dtc.SQLCommand(Properties.Settings.Default.DBName, cre.categories());
                dtc.CreateBulckCategories(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());
            }
        }