示例#1
0
        private void onResultsRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                MessageBox.Show(CommandErrors.GetErrorMessage(response.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                var resultslist = JsonConvert.DeserializeObject <List <ResultSheetItem> >(SequrityUtils.DecryptString(response.Data, connection.User.SecretKey));

                dataGridView.Rows.Clear();
                dataGridView.Columns.Clear();

                dataGridView.Columns.Add("Id", "Id");
                dataGridView.Columns.Add("NameSurname", "Имя/Фамилия учащегося");
                dataGridView.Columns.Add("Mark", "Оценка");
                dataGridView.Columns.Add("PassDate", "Дата выполнения");
                dataGridView.Columns.Add("PassingTime", "Время выполнения");
                dataGridView.Columns.Add("ExtendedResults", "Расширенные результаты");

                foreach (var item in resultslist)
                {
                    var row = new DataGridViewRow();
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.id.ToString()));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.NameSurname));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.Mark.ToString()));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.PassDate.ToString("dd.MM.yyyy")));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.PassingTime.ToString("hh:mm:ss")));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowButtonCell("Расширенные результаты"));
                    dataGridView.Rows.Add(row);
                }
            }
        }
示例#2
0
        private void onSubjectsRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                MessageBox.Show(CommandErrors.GetErrorMessage(response.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                subjects = JsonConvert.DeserializeObject <Dictionary <int, string> >(SequrityUtils.DecryptString(response.Data, connection.User.SecretKey));
                comboBoxSubject.Items.Clear();
                if (subjects.Count == 0)
                {
                    comboBoxSubject.SelectedIndex = -1;
                }
                else
                {
                    foreach (var keyValue in subjects)
                    {
                        comboBoxSubject.Items.Add(keyValue.Value);
                    }
                    comboBoxSubject.SelectedIndex = 0;
                }
            }
        }
示例#3
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (comboBoxSubject.SelectedIndex < 0)
            {
                MessageBox.Show("Необходимо выбрать предмет/дисциплину теста. Если в списке нет вашего предмета/дисциплины воспользуйтесь кнопкой \"Добавить предмет\"", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (textBoxTestName.Text == "")
            {
                MessageBox.Show("Поле \"Название теста\" должно быть заполнено!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            var saver = new ServerTestSaveProvider(connection);

            if (saver.Save(test, textBoxTestName.Text, subjects.FirstOrDefault(x => x.Value == (string)comboBoxSubject.SelectedItem).Key))
            {
                _testName    = textBoxTestName.Text;
                DialogResult = DialogResult.OK;
            }
            else
            {
                if (saver.Error != null)
                {
                    MessageBox.Show(CommandErrors.GetErrorMessage(saver.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
 protected CommandResult(bool isValid, Commands commandType, string extention = null, string feedbackMessage = null
                         , CommandErrors errorType = CommandErrors.Idle)
 {
     IsValid         = isValid;
     CommandType     = commandType;
     Extention       = extention;
     FeedbackMessage = feedbackMessage;
     ErrorType       = errorType;
 }
示例#5
0
        private void OnGetContext(IAsyncResult result)
        {
            try
            {
                HttpListener        listener = (HttpListener)result.AsyncState;
                HttpListenerContext context  = listener.EndGetContext(result);

                HttpListenerRequest request = context.Request;
                log.LogMessage("Запрос от " + request.RemoteEndPoint.Address.ToString());

                HttpListenerResponse response = context.Response;
                ResponseInfo         responseData;
                if (request.HttpMethod != "POST")
                {
                    log.LogError("Запрос использует недопустимый метод");
                    responseData = new ResponseInfo("BADMETHOD", null);
                }
                else
                {
                    CommandError error;
                    var          postData    = GetRequestPostData(request);
                    RequestInfo  requestData = null;
                    try
                    {
                        requestData  = RequestInfo.FromJson(postData);
                        responseData = new ResponseInfo(null, CommandFactory.GetCommand(requestData).Execute(out error));
                        if (error != CommandError.None)
                        {
                            log.LogError(CommandErrors.GetErrorCode(error));
                            responseData = new ResponseInfo(CommandErrors.GetErrorCode(error), null);
                        }
                    }
                    catch (Exception e)
                    {
                        log.LogError(e.ToString());
                        responseData = new ResponseInfo("BADJSON", null);
                    }
                }
                var    responseString = responseData.ToJson();
                byte[] buffer         = System.Text.Encoding.UTF8.GetBytes(responseString);
                response.ContentLength64 = buffer.Length;
                Stream output = response.OutputStream;
                output.Write(buffer, 0, buffer.Length);
                output.Close();
            }
            catch (HttpListenerException e)
            {
                if (e.ErrorCode != 995)
                {
                    throw e;
                }
            }
        }
示例#6
0
        private void onTestListRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                MessageBox.Show(CommandErrors.GetErrorMessage(response.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                var itemlist = JsonConvert.DeserializeObject <List <TestSheetItem> >(SequrityUtils.DecryptString(response.Data, connection.User.SecretKey));

                dataGridView.Rows.Clear();
                dataGridView.Columns.Clear();

                dataGridView.Columns.Add("Id", "Id");
                dataGridView.Columns.Add("Name", "Название");
                dataGridView.Columns.Add("Creator", "Создатель");
                dataGridView.Columns.Add("EditDate", "Дата изменения");
                dataGridView.Columns.Add("Subject", "Предмет/Дисциплина");
                dataGridView.Columns.Add("PassAvailable", "Доступен для прохождения");
                dataGridView.Columns.Add("ShowResults", "Просмотреть результат");
                if (comboBoxData.SelectedIndex == 1)
                {
                    dataGridView.Columns.Add("OpenClosePassing", "Разрешить/Запретить прохождение");
                    dataGridView.Columns.Add("Delete", "Удалить");
                }

                foreach (var item in itemlist)
                {
                    var row = new DataGridViewRow();
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.id.ToString()));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.Name));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.Creator));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.EditDate.ToString()));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(subjectsRoles[item.Subject]));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.PassAvailable ? "Да" : "Нет"));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowButtonCell("Просмотреть результаты"));
                    if (comboBoxData.SelectedIndex == 1)
                    {
                        row.Cells.Add(DataGridViewComponents.GetDataGridViewRowButtonCell("Разрешить/Запретить прохождение"));
                        row.Cells.Add(DataGridViewComponents.GetDataGridViewRowButtonCell("Удалить"));
                    }
                    dataGridView.Rows.Add(row);
                }
                if (checkBoxDate.Checked)
                {
                    dataGridView.Sort(dataGridView.Columns[3], ListSortDirection.Ascending);
                }
            }
        }
示例#7
0
        private void onExtendedResultsExcelInfoRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                MessageBox.Show(CommandErrors.GetErrorMessage(response.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                var results = JsonConvert.DeserializeObject <List <ExtendedResultSheetItem> >(SequrityUtils.DecryptString(response.Data, connection.User.SecretKey));
                var saver   = new ExcelTestResultsSaver();
                saver.Save(excelPath, TestName, results);
            }
        }
示例#8
0
        private void onUserListRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                MessageBox.Show(CommandErrors.GetErrorMessage(response.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                var userlist = JsonConvert.DeserializeObject <List <UserSheetItem> >(SequrityUtils.DecryptString(response.Data, connection.User.SecretKey));

                dataGridView.Rows.Clear();
                dataGridView.Columns.Clear();

                dataGridView.Columns.Add("Id", "Id");
                dataGridView.Columns.Add("Login", "Логин");
                dataGridView.Columns.Add("Name", "Имя");
                dataGridView.Columns.Add("Surname", "Фамилия");
                dataGridView.Columns.Add("Role", "Тип аккаунта");
                dataGridView.Columns.Add("Group", "Группа");
                if (connection.User.UserRole == UserRoles.Admin)
                {
                    dataGridView.Columns.Add("Edit", "Изменить");
                    dataGridView.Columns.Add("Delete", "Удалить");
                }

                foreach (var item in userlist)
                {
                    var row = new DataGridViewRow();
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.id.ToString()));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.Login));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.Name));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.Surname));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(subjectsRoles[item.Role]));
                    row.Cells.Add(DataGridViewComponents.GetDataGridViewRowTextBoxCell(item.Group));
                    if (connection.User.UserRole == UserRoles.Admin)
                    {
                        row.Cells.Add(DataGridViewComponents.GetDataGridViewRowButtonCell("Изменить"));
                        if (item.Role != (int)UserRoles.Admin + 1)
                        {
                            row.Cells.Add(DataGridViewComponents.GetDataGridViewRowButtonCell("Удалить"));
                        }
                    }
                    dataGridView.Rows.Add(row);
                }
            }
        }
示例#9
0
        private void onExtendedResultsRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                MessageBox.Show(CommandErrors.GetErrorMessage(response.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                var result = JsonConvert.DeserializeObject <List <AnswerListItem> >(SequrityUtils.DecryptString(response.Data, connection.User.SecretKey));
                using (var resultDialog = new AnswerListDialog(result))
                {
                    resultDialog.ShowDialog();
                }
            }
        }
示例#10
0
        private void onTestsRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                MessageBox.Show(CommandErrors.GetErrorMessage(response.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                var tests = JsonConvert.DeserializeObject <List <string> >(SequrityUtils.DecryptString(response.Data, connection.User.SecretKey));
                listBoxTests.Items.Clear();
                foreach (var testName in tests)
                {
                    listBoxTests.Items.Add(testName);
                }
            }
        }
示例#11
0
        private void onRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                if (response.Error != "USER_NOT_STUDENT")
                {
                    MessageBox.Show(CommandErrors.GetErrorMessage(response.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                if (SequrityUtils.DecryptString(response.Data, connection.User.SecretKey) != "OK")
                {
                    MessageBox.Show("Неизвестная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void onRecive(string data)
        {
            var response = ResponseInfo.FromJson(data);

            if (response.Error != null)
            {
                MessageBox.Show(CommandErrors.GetErrorMessage(response.Error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (SequrityUtils.DecryptString(response.Data, connection.User.SecretKey) == "OK")
                {
                    MessageBox.Show("Регистрация завершена успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("Непредвиденная ошибка регистрации", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#13
0
        private void вывестиВWordToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var saver = new TestWordSaver();

            using (var saveDialog = new SaveFileDialog())
            {
                saveDialog.Filter = "Microsoft Word (.docx)|*.docx";
                if (saveDialog.ShowDialog() == DialogResult.OK)
                {
                    var error = saver.Save(testForEdit, saveDialog.FileName);
                    if (error != null)
                    {
                        MessageBox.Show(CommandErrors.GetErrorMessage(error), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show("Успешно сохранено", "Вывод в Word", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
示例#14
0
 public static void SendCommandFailure(this WorkerConnection connection, long requestId, CommandErrors error)
 {
     connection.SendCommandFailure(requestId, error.ToString("D"));
 }
示例#15
0
 public static CommandResult CreateFromFailure(CommandErrors errorType, string feedbackMessage)
 {
     return(new CommandResult(false, Commands.Idle, feedbackMessage: feedbackMessage, errorType: errorType));
 }