示例#1
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            string encyptKey = ConfigurationManager.AppSettings["EncyptKey"];

            if (string.IsNullOrEmpty(encyptKey))
            {
                MessageBox.Show("EncyptKey not found in App.config.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (string.IsNullOrEmpty(txtFilePathImport.Text.Trim()))
            {
                MessageBox.Show("File path is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (!File.Exists(txtFilePathImport.Text))
            {
                MessageBox.Show("File path can not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (string.IsNullOrEmpty(txtFileName.Text.Trim()))
            {
                MessageBox.Show("File name is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (CheckNameExist(txtFileName.Text.Trim()))
            {
                MessageBox.Show("File name already existed in the system.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                string text = File.ReadAllText(txtFilePathImport.Text);

                var dataDecrypt = EncryptHelper.Decrypt(text, encyptKey);
                AssessmentService assessmentService = new AssessmentService();
                var id = assessmentService.ImportData(txtFileName.Text, dataDecrypt);
                if (id > 0)
                {
                    MessageBox.Show("Import successfully!", "Information");
                    this.Close();
                    _frmMain.RefreshDataForGridFromAnotherForm();
                }
                else
                {
                    MessageBox.Show("Import failed!", "Error");
                }
            }
        }