Exemplo n.º 1
0
        public void AddProgram(string path)
        {
            if (!Programs.Any(item => item.Path == path))
            {
                string friendlyName;
                string name = Path.GetFileName(path);
                if (File.Exists(path))
                {
                    FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(path);
                    friendlyName = fvi.FileDescription;
                    if (friendlyName == null)
                    {
                        friendlyName = name;
                    }
                }
                else
                {
                    friendlyName = name;
                }
                using (SQLiteCommand cmd = new SQLiteCommand("insert into programs (name, friendlyName, path, timeAdded) VALUES (@name, @friendlyName, @path, @timeAdded);", dbConnection))
                {
                    cmd.Parameters.AddWithValue("@name", name);
                    cmd.Parameters.AddWithValue("@friendlyName", friendlyName);
                    cmd.Parameters.AddWithValue("@path", path);
                    cmd.Parameters.AddWithValue("@timeAdded", DateTime.Now);
                    cmd.ExecuteNonQuery();
                }

                TrackedProgram p = new TrackedProgram(path, name, friendlyName, 0);
                Programs.Add(p);
                updateProgramList();
            }
            else
            {
                MessageBox.Show(path + " is already in list.");
            }
        }
Exemplo n.º 2
0
        private void loadDb()
        {
            if (dbConnected)
            {
                using (SQLiteCommand cmd = new SQLiteCommand("select * from programs", dbConnection))
                {
                    using (SQLiteDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            TrackedProgram tp = new TrackedProgram();
                            tp.Path         = reader["path"].ToString();
                            tp.Name         = reader["name"].ToString();
                            tp.friendlyName = reader["friendlyName"].ToString();
                            if (tp.friendlyName == "")
                            {
                                tp.friendlyName = tp.Name;
                            }
                            tp.runtime       = (int)reader["runtime"];
                            tp.activeRuntime = (int)reader["activeRuntime"];
                            tp.lastTimeRun   = reader["lastTimeRun"] as DateTime? ?? default(DateTime);
                            tp.timeAdded     = (DateTime)reader["timeAdded"];
                            Programs.Add(tp);
                        }
                    }
                }
                updateProgramList();

                using (SQLiteCommand cmd = new SQLiteCommand("SELECT settingstate FROM config WHERE settingkey='showPaths'", dbConnection))
                {
                    if (Convert.ToInt32(cmd.ExecuteScalar()) == 0)
                    {
                        changeSetting("showPaths", false);
                    }
                    else
                    {
                        changeSetting("showPaths", true);
                    }

                    cmd.CommandText = "SELECT settingstate FROM config WHERE settingkey='minimizeToTray'";
                    if (Convert.ToInt32(cmd.ExecuteScalar()) == 0)
                    {
                        minimizeToTray = false;
                    }
                    else
                    {
                        minimizeToTray = true;
                    }

                    cmd.CommandText = "SELECT settingvalue FROM config WHERE settingkey='column0Width';";
                    dataGridView1.Columns[0].Width = Convert.ToInt32(cmd.ExecuteScalar());
                    cmd.CommandText = "SELECT settingvalue FROM config WHERE settingkey='column1Width';";
                    dataGridView1.Columns[1].Width = Convert.ToInt32(cmd.ExecuteScalar());
                    cmd.CommandText = "SELECT settingvalue FROM config WHERE settingkey='column2Width';";
                    dataGridView1.Columns[2].Width = Convert.ToInt32(cmd.ExecuteScalar());
                    cmd.CommandText = "SELECT settingvalue FROM config WHERE settingkey='column3Width';";
                    dataGridView1.Columns[3].Width = Convert.ToInt32(cmd.ExecuteScalar());
                    cmd.CommandText = "SELECT settingvalue FROM config WHERE settingkey='column4Width';";
                    dataGridView1.Columns[4].Width = Convert.ToInt32(cmd.ExecuteScalar());
                    cmd.CommandText = "SELECT settingvalue FROM config WHERE settingkey='column5Width';";
                    dataGridView1.Columns[5].Width = Convert.ToInt32(cmd.ExecuteScalar());
                    cmd.CommandText = "SELECT settingvalue FROM config WHERE settingkey='column6Width';";
                    dataGridView1.Columns[6].Width = Convert.ToInt32(cmd.ExecuteScalar());
                    cmd.CommandText = "SELECT settingvalue FROM config WHERE settingkey='formWidth';";
                    int width = Convert.ToInt32(cmd.ExecuteScalar());
                    cmd.CommandText = "SELECT settingvalue FROM config WHERE settingkey='formHeight';";
                    int height = Convert.ToInt32(cmd.ExecuteScalar());

                    this.Size = new Size(width, height);
                }
            }
            else
            {
                MessageBox.Show("Can't load programs: not connected to a database.");
            }
        }