Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Multiselect      = false;
                openFileDialog.RestoreDirectory = true;
                openFileDialog.Title            = "Open File";
                // Set filter for file extension and default file extension
                openFileDialog.Filter = "Harris Dai|*.harrisDai";
                var result = openFileDialog.ShowDialog();
                if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(openFileDialog.FileName))
                {
                    string          contentBeforeDecrypt = File.ReadAllText(openFileDialog.FileName);
                    TypePasswordBox box = new TypePasswordBox("請輸入軟體的解密密碼");
                    result = box.ShowDialog();
                    if (result != DialogResult.OK || string.IsNullOrWhiteSpace(box.textBox1.Text))
                    {
                        return;
                    }

                    string contentAfterDecrypt = AES.aesDecryptBase64(contentBeforeDecrypt, box.textBox1.Text);
                    var    controller          = JsonConvert.DeserializeObject <ViewModelController>(contentAfterDecrypt);
                    if (controller == null)
                    {
                        throw new Exception("密碼錯誤");
                    }

                    box    = new TypePasswordBox("請輸入檔案的解密密碼");
                    result = box.ShowDialog();
                    if (result != DialogResult.OK || string.IsNullOrWhiteSpace(box.textBox1.Text))
                    {
                        return;
                    }

                    if (!controller.Password.Equals(box.textBox1.Text))
                    {
                        throw new Exception("密碼錯誤");
                    }

                    _controller = controller;
                    dataGridView1.DataSource = _controller.ViewModelList;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #2
0
 private void button2_Click(object sender, EventArgs e)
 {
     _controller = new ViewModelController();
     dataGridView1.DataSource = _controller.ViewModelList;
 }