Ejemplo n.º 1
0
        private void dlMenuItem_Click(object sender, EventArgs e) {
            DialogResult result = new UpdateCheck().ShowDialog();
            if (result == DialogResult.OK) {
                foreach (DataTable thisdt in dt) {
                    thisdt.Dispose();
                }
                dt.Clear();
                foreach (DataGridView thisdgv in dgv) {
                    thisdgv.Dispose();
                }
                dgv.Clear();

                if (File.Exists(databasefilename)) {
                    File.Delete(databasefilename);
                }
                dlWorker.RunWorkerAsync();
            }
        }
Ejemplo n.º 2
0
        private void DownloadBrickLinkDB() {
            StreamWriter swr = new StreamWriter(debugdbfilename);
            #region download bricklink files
            if ((!File.Exists(databasefilename)) || (!File.Exists(databasezipfilename))) {
                swr.Write("Downloading new Bricklink database" + Environment.NewLine);
                swr.Close();
                DownloadDB();
            } else if (File.GetLastWriteTime(databasezipfilename) < DateTime.Now.AddDays(-10)) {
                DialogResult result = new UpdateCheck().ShowDialog();
                if (result == DialogResult.OK) {
                    swr.Write("User chose to update out of date Bricklink database" + Environment.NewLine);
                    swr.Close();
                    DownloadDB();
                } else {
                    swr.Write("User chose NOT to update out of date Bricklink database" + Environment.NewLine);
                    swr.Close();
                }
            } else {
                swr.Write("Database up to date" + Environment.NewLine);
                swr.Close();
            }
            #endregion

            #region read bricklink files
            AddStatus("Loading...");

            db_colours.Clear();
            db_categories.Clear();
            db_blitems.Clear();
            db_typenames.Clear();
            db_blaltids.Clear();
            try {
                string conString = "Data Source=" + databasefilename;
                using (SqlCeConnection con = new SqlCeConnection(conString)) {
                    con.Open();
                    using (SqlCeCommand com = new SqlCeCommand("SELECT * FROM types", con)) {
                        SqlCeDataReader reader = com.ExecuteReader();
                        while (reader.Read()) {
                            db_typenames.Add(reader.GetString(0), reader.GetString(1));
                        }
                    }

                    using (SqlCeCommand com = new SqlCeCommand("SELECT * FROM categories", con)) {
                        SqlCeDataReader reader = com.ExecuteReader();
                        while (reader.Read()) {
                            db_categories.Add(reader.GetString(0), new DBCat() {
                                id = reader.GetString(0),
                                name = reader.GetString(1),
                                sets = Convert.ToInt32(reader.GetString(2)),
                                parts = Convert.ToInt32(reader.GetString(3)),
                                minifigures = Convert.ToInt32(reader.GetString(4)),
                                books = Convert.ToInt32(reader.GetString(5)),
                                gear = Convert.ToInt32(reader.GetString(6)),
                                catalogs = Convert.ToInt32(reader.GetString(7)),
                                instructions = Convert.ToInt32(reader.GetString(8)),
                                originalboxes = Convert.ToInt32(reader.GetString(9))
                            });
                        }
                    }

                    using (SqlCeCommand com = new SqlCeCommand("SELECT * FROM colours", con)) {
                        SqlCeDataReader reader = com.ExecuteReader();
                        while (reader.Read()) {
                            db_colours.Add(reader.GetString(0), new DBColour() {
                                id = reader.GetString(0),
                                name = reader.GetString(1),
                                rgb = reader.GetString(2),
                                type = reader.GetString(3)
                            });
                        }
                    }

                    using (SqlCeCommand com = new SqlCeCommand("SELECT * FROM items", con)) {
                        SqlCeDataReader reader = com.ExecuteReader();
                        while (reader.Read()) {
                            db_blitems.Add(reader.GetString(0), new DBBLItem() {
                                id = reader.GetString(0),
                                number = reader.GetString(1),
                                type = reader.GetString(2),
                                name = reader.GetString(3),
                                weight = reader.GetString(4),
                                dimensions = reader.GetString(5),
                                catid = reader.GetString(6),
                            });
                            string containraw = reader.GetString(8);
                            foreach (string line in containraw.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)) {
                                string[] part = line.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                if (!db_containers.ContainsKey(part[0])) {
                                    db_containers.Add(part[0], new List<DBItemContain>() {
                                    new DBItemContain(){ 
                                        item = part[1], qty = Convert.ToInt32(part[2]) 
                                    }
                                });
                                } else {
                                    db_containers[part[0]].Add(new DBItemContain() {
                                        item = part[1],
                                        qty = Convert.ToInt32(part[2])
                                    });
                                }
                            }
                        }
                    }

                    using (SqlCeCommand com = new SqlCeCommand("SELECT * FROM altid", con)) {
                        SqlCeDataReader reader = com.ExecuteReader();
                        while (reader.Read()) {
                            if (reader.GetString(0) == "3749") {
                                MessageBox.Show(reader.GetString(0) + " / " + reader.GetString(1));
                            }
                            db_blaltids.Add(reader.GetString(0), reader.GetString(1));
                        }
                    }

                }

            } catch (Exception exc) {
                swr.Write("ERROR Reading database" + Environment.NewLine + exc.Message);
                swr.Close();
                if (File.Exists(databasefilename)) {
                    File.Delete(databasefilename);
                }
                MessageBox.Show("The database could not be read:" + Environment.NewLine + exc.Message);
                Close();
            }
            swr.Close();
            #endregion

        }