Exemple #1
0
        private void ExportAssessment(int assessmentId)
        {
            string encyptKey = ConfigurationManager.AppSettings["EncyptKey"];

            if (string.IsNullOrEmpty(encyptKey))
            {
                throw new Exception("EncyptKey not found in App.config");
            }

            var assessment = _assessmentService.GetById(assessmentId);

            if (assessment != null)
            {
                var isShowExportForm = true;
                var listError        = new List <MessageErrorVo>();

                var dataJsonDiscloseData = new DisclosureFormVo();
                var dataJsonAssessment   = new AssessmentDataVo();

                if (string.IsNullOrEmpty(assessment.DisclosureFormData))
                {
                    isShowExportForm = false;
                    var errorMsg = "To export assessment, please input data fully to Disclosure Form.\n";
                    MessageBox.Show(errorMsg, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (!string.IsNullOrEmpty(assessment.DisclosureFormData))
                {
                    var decryptDiscloseData = EncryptHelper.Decrypt(assessment.DisclosureFormData, encyptKey);
                    dataJsonDiscloseData = JsonConvert.DeserializeObject <DisclosureFormVo>(decryptDiscloseData);

                    if (!string.IsNullOrEmpty(assessment.AssessmentData))
                    {
                        var decryptAssessment = EncryptHelper.Decrypt(assessment.AssessmentData, encyptKey);
                        dataJsonAssessment = JsonConvert.DeserializeObject <AssessmentDataVo>(decryptAssessment);
                    }

                    var listErrorDisclosureForm = _assessmentService.CheckInValidDisclosureForm(dataJsonDiscloseData);
                    listError = _assessmentService.CheckInValidBeforeExport(dataJsonDiscloseData, dataJsonAssessment);

                    if (listErrorDisclosureForm != null && listErrorDisclosureForm.Count > 0)
                    {
                        if (listError != null && listError.Count > 0)
                        {
                            listErrorDisclosureForm.AddRange(listError);
                        }
                        isShowExportForm = false;
                        var errorMsg = "To export assessment, please input data fully to Disclosure Form.\n" +
                                       "Following business rules are failed:\n";
                        foreach (var item in listErrorDisclosureForm)
                        {
                            errorMsg += " - " + item.MessageError.Replace("(Disclosure Form)", "") + "\n";
                        }
                        MessageBox.Show(errorMsg, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (listError != null && listError.Count > 0)
                    {
                        isShowExportForm = false;
                        var errorMsg = "Following business rules are failed:\n";
                        foreach (var item in listError)
                        {
                            errorMsg += " - " + item.MessageError.Replace("(Disclosure Form)", "") + "\n";
                        }
                        MessageBox.Show(errorMsg, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }

                if (isShowExportForm)
                {
                    var form = new FrmExport(assessment);
                    form.ShowDialog();
                }
            }
        }