Esempio n. 1
0
 private void buttonOK_Click(object sender, EventArgs e)
 {
     _password = textBoxPassword.Text;
     if (!IsTeacherMode)
     {
         if (_resultUser == null)
         {
             MessageBox.Show("Для начала тестирования необходимо выбрать пользователя.",
                             "Выбор пользователя", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             return;
         }
         SetChildEnable(false);
         StaticServerProvider.Logout();
         LoginProvider loginProvider = LoginProvider.Login(_resultUser.Login, textBoxPassword.Text, LoginHelper.Server, LoginHelper.SEND_TIMEOUT, null,
                                                           new LoginProvider.LoginResultDelegate((hasPassword, errorMessage) =>
         {
             this.Invoke((Action)(() =>
             {
                 if (hasPassword)
                 {
                     if (String.IsNullOrEmpty(LoginHelper.Server))
                     {
                         string[] databases = StaticServerProvider.TestClient.GetDatabaseNamesList();
                         if (databases.Length > 0)
                         {
                             string dbPassword = StaticServerProvider.TestClient.GetDatabasePassword(databases[0]);
                             using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(String.Format(
                                                                                                                           "Data Source=(local);Initial Catalog={0};User ID=testingUser;Password={1}", databases[0], dbPassword)))
                             {
                                 System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("EXEC InitDbSettings;", conn);
                                 conn.Open();
                                 cmd.ExecuteNonQuery();
                                 conn.Close();
                                 Console.WriteLine(cmd.ExecuteScalar());
                             }
                         }
                     }
                     StartTestParams ncs = StaticServerProvider.TestClient.GetNotCommitedSessions(_resultUser.UserId, false);
                     TestorData testSettings = null;
                     if (ncs == null)
                     {
                         SelectSingleItemForm selectTest = new SelectSingleItemForm(_resultUser, TestingServerItemType.ActiveTestTree);
                         if (selectTest.ShowDialog() != DialogResult.OK)
                         {
                             textBoxPassword.Text = String.Empty;
                             StaticServerProvider.Logout();
                             LoginHelper.AnonymousLogin();
                             SetChildEnable(true);
                             return;
                         }
                         _selectedTest = selectTest.SelectedItem;
                         if (_selectedTest == null || _selectedTest.ItemType != TestorItemType.Test &&
                             _selectedTest.ItemType != TestorItemType.MasterTest)
                         {
                             MessageBox.Show("Для начала тестирования необходимо выбрать тест.",
                                             "Выбор теста", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                             _selectedTest = null;
                             StaticServerProvider.Logout();
                             LoginHelper.AnonymousLogin();
                             SetChildEnable(true);
                             return;
                         }
                         testSettings = selectTest.TestSettings;
                     }
                     else
                     {
                         testSettings = ncs.TestSettings;
                         TestorData.CoreTestsRow coreTest = testSettings.CoreTests[0];
                         _selectedTest = new TestorTreeItem(0, coreTest.TestId, coreTest.TestName,
                                                            coreTest.IsMasterTest ? TestorItemType.MasterTest : TestorItemType.Test, null);
                     }
                     RemoteTestingProvider provider = new RemoteTestingProvider(null, _selectedTest,
                                                                                testSettings, ncs, true);
                     TestForm testForm = new TestForm(provider);
                     testForm.ShowDialog();
                     comboBoxUserType_SelectedIndexChanged(sender, e);
                     StaticServerProvider.Logout();
                     LoginHelper.AnonymousLogin();
                     SetChildEnable(true);
                 }
                 else
                 {
                     SystemMessage.ShowServerErrorMessage(errorMessage);
                     textBoxPassword.Text = String.Empty;
                     StaticServerProvider.Logout();
                     LoginHelper.AnonymousLogin();
                     SetChildEnable(true);
                     return;
                 }
             }));
         }));
     }
     else
     {
         SetFormEnableMode(false);
         _userName = textBoxStudentName.Text;
         StaticServerProvider.Logout();
         LoginProvider loginProvider = LoginProvider.Login(_userName, _password, LoginHelper.Server, LoginHelper.SEND_TIMEOUT, null,
                                                           new LoginProvider.LoginResultDelegate((hasPassword, errorMessage) =>
         {
             this.Invoke((Action)(() =>
             {
                 SetFormEnableMode(true);
                 if (hasPassword)
                 {
                     StatisticsForm statistics = new StatisticsForm(false);
                     statistics.MdiParent = this.MdiParent;
                     statistics.Dock = DockStyle.Fill;
                     statistics.ControlBox = false;
                     statistics.Show();
                     comboBoxUserType.SelectedIndex = 0;
                     textBoxStudentName.Focus();
                     SetChildEnable(true);
                 }
                 else
                 {
                     SystemMessage.ShowServerErrorMessage(errorMessage);
                     StaticServerProvider.Logout();
                     LoginHelper.AnonymousLogin();
                     SetChildEnable(true);
                     return;
                 }
             }));
         }));
     }
 }