private void btnOk_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtFileName.Text.Trim())) { MessageBox.Show("File name is required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!CaculatorHelper.CheckFileNameValid(txtFileName.Text)) { MessageBox.Show("File name is invalid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (CheckNameExist(txtFileName.Text)) { MessageBox.Show("File name already existed in the system.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var fileName = txtFileName.Text; this.Close(); var id = _assessmentService.NewRecord(fileName); _frmMain.RefreshDataForGridFromAnotherForm(); var frmPcst = new FrmPcstForm(id, _frmMain); frmPcst.ShowDialog(); } }
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"); } } }