Ejemplo n.º 1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtUserName.Text))
            {
                MessageBoxHelper.ShowError("Please enter the username ...");
                return;
            }

            if (string.IsNullOrEmpty(txtPassword.Text))
            {
                MessageBoxHelper.ShowError("Please enter the password ...");
                return;
            }

            btnLogin.Enabled = false;
            var serializer  = new JsonSerializer();
            var errorLogger = new ErrorLogger();
            var loginClient = new AdmissionLoginClient(serializer, errorLogger);
            var user        = loginClient.LogIn(txtUserName.Text, txtPassword.Text);

            if (user.status == "success")
            {
                MisCache.UserToken           = user.user_token;
                MisCache.UserEmail           = user.user_email;
                MisCache.IsImportClasses     = true;
                MisCache.IsImportExamResults = true;

                SIMSDllResolution.AddSIMSDllResolution();
                if (!LoginHelper.SIMSlogin(AppSetting.Server,
                                           AppSetting.Database,
                                           AppSetting.User,
                                           AppSetting.Password))
                {
                    MessageBoxHelper.ShowError("Could not access to SIMS. Please check the SIMS user / password.");
                    Application.Exit();
                    return;
                }
                var frmHome = new FrmHome();
                frmHome.Show();
                this.Hide();
            }
            else
            {
                MisCache.UserToken = null;
                MisCache.UserEmail = null;
                MessageBoxHelper.ShowError(user.message ?? "Invalid user name or password.");
                btnLogin.Enabled = true;
            }
        }
Ejemplo n.º 2
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);
            }
        }