Beispiel #1
0
        //建立SQL Cipher資料庫
        void btnCipher_TouchUpInside(object sender, EventArgs e)
        {
            // 建立資料庫
            var documents      = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            var pathToDatabase = Path.Combine(documents, "cipher.db");

            Mono.Data.Sqlcipher.SqliteConnection.CreateFile(pathToDatabase);

            var msg = "資料庫名稱為: " + pathToDatabase;

            //建立Table
            var connectionString = String.Format("Data Source={0};Version=3;", pathToDatabase);

            using (var conn = new Mono.Data.Sqlcipher.SqliteConnection(connectionString))
            {
                conn.SetPassword("test");
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "CREATE TABLE People (PersonID INTEGER PRIMARY KEY AUTOINCREMENT , FirstName ntext, LastName ntext)";
                    cmd.CommandType = CommandType.Text;
                    cmd.ExecuteNonQuery();
                }
            }

            //新增資料
            using (var conn = new Mono.Data.Sqlcipher.SqliteConnection(connectionString))
            {
                conn.SetPassword("test");
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText  = "Insert into People(FirstName,LastName) Values('Terry','Lin') ;";
                    cmd.CommandText += "Insert into People(FirstName,LastName) Values('Ben','Lu') ";
                    cmd.CommandType  = CommandType.Text;
                    cmd.ExecuteNonQuery();
                }
            }

            // 訊息輸出並停用Button
            lblmsg.Text            = msg;
            this.btnCipher.Enabled = false;
        }
Beispiel #2
0
        //�إ�SQL Cipher��Ʈw
        void btnCipher_TouchUpInside(object sender, EventArgs e)
        {
            // �إ߸�Ʈw
            var documents = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            var pathToDatabase = Path.Combine(documents, "cipher.db");
            Mono.Data.Sqlcipher.SqliteConnection.CreateFile(pathToDatabase);

            var msg = "��Ʈw�W�٬�: " + pathToDatabase;

            //�إ�Table
            var connectionString = String.Format("Data Source={0};Version=3;", pathToDatabase);

            using (var conn = new Mono.Data.Sqlcipher.SqliteConnection(connectionString))
            {
                conn.SetPassword("test");
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "CREATE TABLE People (PersonID INTEGER PRIMARY KEY AUTOINCREMENT , FirstName ntext, LastName ntext)";
                    cmd.CommandType = CommandType.Text;
                    cmd.ExecuteNonQuery();
                }
            }

            //�s�W���
            using (var conn = new Mono.Data.Sqlcipher.SqliteConnection(connectionString))
            {
                conn.SetPassword("test");
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "Insert into People(FirstName,LastName) Values('Terry','Lin') ;";
                    cmd.CommandText += "Insert into People(FirstName,LastName) Values('Ben','Lu') ";
                    cmd.CommandType = CommandType.Text;
                    cmd.ExecuteNonQuery();
                }
            }

            // �T����X��Button
            lblmsg.Text = msg;
            this.btnCipher.Enabled = false;
        }
Beispiel #3
0
        //讀取加密資料庫
        void _btnRead_TouchUpInside(object sender, EventArgs e)
        {
            var documents        = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            var pathToDatabase   = Path.Combine(documents, "cipher.db");
            var connectionString = String.Format("Data Source={0};Version=3;", pathToDatabase);

            using (var conn = new Mono.Data.Sqlcipher.SqliteConnection(connectionString))
            {
                conn.SetPassword("test");
                conn.Open();
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "Select * from People";
                    cmd.CommandType = CommandType.Text;
                    var reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        this._txtView.Text += string.Format("First Name:{0} Last Name:{1}\r\n", reader[1].ToString(), reader[2].ToString());
                    }
                    reader.Close();
                }
            }
        }
Beispiel #4
0
 //Ū���[�K��Ʈw���
 void btnRead_TouchUpInside(object sender, EventArgs e)
 {
     var documents = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
     var pathToDatabase = Path.Combine(documents, "cipher.db");
     var connectionString = String.Format("Data Source={0};Version=3;", pathToDatabase);
     this.lblmsg.Text = "";
     using (var conn = new Mono.Data.Sqlcipher.SqliteConnection(connectionString))
     {
         conn.SetPassword("test");
         conn.Open();
         using (var cmd = conn.CreateCommand())
         {
             cmd.CommandText = "Select * from People";
             cmd.CommandType = CommandType.Text;
             var reader = cmd.ExecuteReader();
             while (reader.Read())
             {
                 this.lblmsg.Text += string.Format("First Name:{0} Last Name:{1}\r\n", reader[1].ToString(), reader[2].ToString());
             }
             reader.Close();
         }
     }
 }