Ejemplo n.º 1
0
        private void btnProcess_Click(object sender, EventArgs e)
        {
            Log.Info("====================================================================== ");
            Log.Info("Start to import ATFfile ... ");
            btnProcess.Enabled = false;
            SIMSDllResolution.AddSIMSDllResolution();

            if (LoginHelper.SIMSlogin(AppSetting.Server,
                                      AppSetting.Database,
                                      AppSetting.User,
                                      AppSetting.Password))
            {
                var atf = XmlHelper.ConvertToObject <ATfile>(txtInfo.Text, out var errorMessages);
                if (atf == null)
                {
                    MessageBoxHelper.ShowError(@"Xml content is not valid");
                    txtInfo.Text = errorMessages;
                    Log.Info(@"Xml content is not valid" + errorMessages);
                    return;
                }

                if (!ValidationATFile(atf, out var validationMessages))
                {
                    MessageBoxHelper.ShowError(@"ATFile validation error");
                    txtInfo.Text = validationMessages;
                    Log.Info(@"ATFile validation error : " + validationMessages);
                    return;
                }

                Log.Info("XML content file : ");
                Log.Info(txtInfo.Text);

                Log.Info("Serialized content data :");
                Log.Info(atf.ATFpupilData);

                var results = Applicant.CreateApplicants(atf.ATFpupilData, atf.Header);

                if (results.Any(x => x.SimsResult.Status == Status.Failed))
                {
                    var strError = new StringBuilder();
                    foreach (var result in results)
                    {
                        string validationError = string.Empty;

                        if (result.SimsResult.Errors != null)
                        {
                            validationError = string.Join(", ", result.SimsResult.Errors.Cast <ValidationError>().ToList().Select(x => x.Message).ToList());
                        }
                        strError.AppendLine(result.EntityName + " : " + result.SimsResult.Status + " - " + validationError);
                    }

                    strError.AppendLine(string.Empty);
                    foreach (var message in Applicant.CacheMessages.Where(x => !string.IsNullOrEmpty(x.Messages)))
                    {
                        strError.AppendLine(message.Type + " : " + message.Messages);
                    }

                    txtInfo.Text = strError.ToString();

                    Log.Info("Importing applicant failed : ");
                    Log.Info(strError.ToString());
                    MessageBoxHelper.ShowInfo(@"Import applicant failed ...");
                }
                else
                {
                    Log.Info("Importing successfully. ");
                    var strMsg = new StringBuilder();
                    foreach (var result in results)
                    {
                        strMsg.AppendLine(result.Type + " >> " + result.EntityName + " : " + result.SimsResult.Status);
                    }
                    txtInfo.Text = strMsg.ToString();
                    Log.Info(strMsg.ToString());
                    MessageBoxHelper.ShowInfo(@"Import applicant successfully !");
                }
            }
            else
            {
                Log.Info("Login to SIMS.net failed ... ");
                MessageBoxHelper.ShowError(LoginHelper.ErrorMessage);
            }
        }