Beispiel #1
0
        public Form1()
        {
            InitializeComponent();
            pictureBox1.Capture      = true;
            mouseSelectedRect.Parent = pictureBox1;

            //ディレクトリが存在するかチェックし、なかったら作成
            if (!Directory.Exists(cacheDir))
            {
                Directory.CreateDirectory(cacheDir);
            }

            //データベースが存在するかチェックし、なかったら作成
            if (!File.Exists(cacheDB))
            {
                Object[,] column =
                {
                    { ColumnExtended.ToString(Column.URL),      DataTypeExtended.ToString(DataType.TEXT), DataTypeExtended.ToString(DataType.PRIMARYKEY) },
                    { ColumnExtended.ToString(Column.FILENAME), DataTypeExtended.ToString(DataType.TEXT), DataTypeExtended.ToString(DataType.NOTNULL)    }
                };

                //テーブルを作成する
                if (CreateTable(TABLENAME, column))
                {
                    MessageBox.Show("テーブルの作成が正常に終了しました。", "初回処理", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("テーブルの作成に異常が発生しました。", "初回処理", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    cacheMode = false;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// テーブルの特定列のデータを取得する
        /// </summary>
        /// <param name="tableName">テーブル名</param>
        /// <param name="column">取得する列</param>
        /// <param name="data">プライマリキーに相当するデータが入った変数。e.g. "https://www.AAA/cat.jpg"</param>
        /// <returns>取得されたデータを返す</returns>
        private String Select(String tableName, Column column, String data)
        {
            //テーブル名が空白ではないかチェック かつ
            //文字列が1以上あるかチェックし、問題なければそのまま処理を続行
            if (!tableName.Equals("") && data.Length < 1)
            {
                return(null);
            }

            try
            {
                var sqlConnectionSb = new SQLiteConnectionStringBuilder {
                    DataSource = cacheDB
                };
                SQLiteConnection con = null;
                SQLiteCommand    cmd = null;

                try
                {
                    con = new SQLiteConnection(sqlConnectionSb.ToString());
                    con.Open();

                    //データ挿入処理
                    cmd = new SQLiteCommand("SELECT " + ColumnExtended.ToString(column) + " FROM " + tableName +
                                            " WHERE " + ColumnExtended.ToString(Column.URL) + " = ?", con);
                    //Parameterを追加するとき、追加するデータはObject型に変換しないと正しく追加されない模様
                    cmd.Parameters.Add(new SQLiteParameter(DbType.String, (Object)data));
                    SQLiteDataReader reader = cmd.ExecuteReader();
                    reader.Read();

                    String readStr = (String)reader[0];
                    return(readStr);
                }
                catch (Exception e)
                {
                    Console.WriteLine("---------------------------> ERROR:" + e.Message);
                    return(null);
                }
                finally
                {
                    if (con != null)
                    {
                        con.Dispose();
                    }

                    if (cmd != null)
                    {
                        cmd.Dispose();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("---------------------------> ERROR:" + e.Message);
                return(null);
            }
        }