コード例 #1
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var    testName     = SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey);
            var    result       = DBConnection.PrepareExecProcedureCommand("CheckTestCreator", testName).ExecuteReader();
            string testFilename = null;
            int    testSubject;

            if (result.Read())
            {
                if (result.GetInt32(2) != client.UserId)
                {
                    error = CommandError.NoPermissions;
                    return(null);
                }
                testFilename = result.GetInt32(0) + ".test";
                testSubject  = result.GetInt32(1);
            }
            else
            {
                error = CommandError.TestNotFound;
                return(null);
            }
            result.Close();

            var test = FileProcessor.LoadTestFile(testFilename);

            error = CommandError.None;
            return(SequrityUtils.Encrypt(new NetSerializedTestInfo(test, testName, testSubject).ToJson(), client.SecretDFKey));
        }
コード例 #2
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            if (client.Role != UserRoles.Student)
            {
                error = CommandError.UserNotStudent;
                return(null);
            }

            if (client.CurrentPassTestId == null)
            {
                error = CommandError.NoCurrentTest;
                return(null);
            }

            var testResult = TestResult.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));

            var command = DBConnection.GetCommand();

            command.CommandText = "call AddTestResult(@param0, @param1, @param2, @param3, @param4)";
            command.Parameters.Add(new MySqlParameter("@param0", client.CurrentPassTestId));
            command.Parameters.Add(new MySqlParameter("@param1", client.UserId));
            command.Parameters.Add(new MySqlParameter("@param2", testResult.Mark));
            command.Parameters.Add(new MySqlParameter("@param3", testResult.PassingTime));
            command.Parameters.Add(new MySqlParameter("@param4", Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(testResult.Answers))));
            command.ExecuteNonQuery();

            error = CommandError.None;
            return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
        }
コード例 #3
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var config = ConfigContainer.GetConfig();

            if (client.Role == UserRoles.Teacher && !config.AllowSubjectsAdding)
            {
                error = CommandError.SubjectAddNotAllowed;
                return(null);
            }

            if (client.Role != UserRoles.Teacher && client.Role != UserRoles.Admin)
            {
                error = CommandError.NoPermissions;
                return(null);
            }

            var subjectName = SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey);

            var result = DBConnection.PrepareExecProcedureCommand("CheckSubject", subjectName).ExecuteReader();

            if (result.Read())
            {
                error = CommandError.SubjectExists;
                return(null);
            }
            result.Close();

            DBConnection.PrepareExecProcedureCommand("AddSubject", subjectName).ExecuteNonQuery();

            error = CommandError.None;
            return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
        }
コード例 #4
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var testName = SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey);
            var result   = DBConnection.PrepareExecProcedureCommand("CheckTestAvailability", testName).ExecuteReader();
            int?testId   = null;
            int testSubject;

            if (result.Read())
            {
                if (!result.GetBoolean(2))
                {
                    error = CommandError.TestNotAvailable;
                    return(null);
                }
                testId      = result.GetInt32(0);
                testSubject = result.GetInt32(1);
            }
            else
            {
                error = CommandError.TestNotFound;
                return(null);
            }
            result.Close();

            var test = FileProcessor.LoadTestFile(testId + ".test");

            client.CurrentPassTestId = testId;

            error = CommandError.None;
            return(SequrityUtils.Encrypt(new NetSerializedTestInfo(test, testName, testSubject).ToJson(), client.SecretDFKey));
        }
コード例 #5
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            if (client.Role != UserRoles.Admin)
            {
                error = CommandError.NoPermissions;
                return(null);
            }

            var    editData       = EditUserData.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));
            string password       = "";
            bool   changePassword = false;

            if (editData.Password != null)
            {
                password       = SequrityUtils.GetHash(editData.Password);
                changePassword = true;
            }

            UserRoles role;
            var       DBReader = DBConnection.PrepareExecProcedureCommand("GetUserRole", editData.id.ToString()).ExecuteReader();

            if (DBReader.Read())
            {
                role = (UserRoles)DBReader.GetInt32(0) - 1;
            }
            else
            {
                error = CommandError.ClientNotFound;
                return(null);
            }
            DBReader.Close();

            int  studentGroup = -1;
            bool changeGroup  = false;

            if (role == UserRoles.Student)
            {
                changeGroup = true;
                DBReader    = DBConnection.PrepareExecProcedureCommand("GetStudentGroup", editData.Group).ExecuteReader();

                if (DBReader.Read())
                {
                    studentGroup = DBReader.GetInt32(0);
                    DBReader.Close();
                }
                else
                {
                    DBReader.Close();
                    error = CommandError.BadStudentGroup;
                    return(null);
                }
            }

            DBConnection.PrepareExecProcedureCommand("EditUser", editData.id.ToString(), editData.Firstname, editData.Lastname, password, studentGroup.ToString(), Convert.ToInt32(changePassword).ToString(), Convert.ToInt32(changeGroup).ToString()).ExecuteNonQuery();

            error = CommandError.None;
            return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
        }
コード例 #6
0
ファイル: LoginCommand.cs プロジェクト: 0leXis/OleXisTest2.0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var loginData    = LoginData.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));
            var passwordHash = SequrityUtils.GetHash(loginData.Password);
            var result       = DBConnection.PrepareExecProcedureCommand("CheckLoginInfo", loginData.Login, passwordHash).ExecuteReader();

            if (result.Read())
            {
                client.UserId = result.GetInt32(0);
                client.Role   = (UserRoles)(result.GetInt32(4) - 1);
                var info = new AccountInfo(client.UserId, result.GetString(1), result.GetString(2), client.Role.Value, result.IsDBNull(5) ? null : result.GetString(5));

                client.UpdateExpiredTime();

                result.Close();
                error = CommandError.None;
                return(SequrityUtils.Encrypt(info.ToJson(), client.SecretDFKey));
            }
            else
            {
                result.Close();
                error = CommandError.BadLoginOrPassword;
                return(null);
            }
        }
コード例 #7
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var testId = SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey);

            var result = DBConnection.PrepareExecProcedureCommand("GetExtendedResultSheet", testId).ExecuteReader();
            List <ExtendedResultSheetItem> extendedResults = new List <ExtendedResultSheetItem>();

            while (result.Read())
            {
                var tmpDateTime = result.GetString(3).Split(':');
                var passingTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, Convert.ToInt32(tmpDateTime[0]), Convert.ToInt32(tmpDateTime[1]), Convert.ToInt32(tmpDateTime[2]));
                extendedResults.Add(
                    new ExtendedResultSheetItem(
                        result.GetInt32(0),
                        result.GetString(1),
                        result.GetInt32(2),
                        passingTime,
                        result.GetDateTime(4),
                        JsonConvert.DeserializeObject <List <AnswerListItem> >(Encoding.UTF8.GetString((byte[])result.GetValue(5)))
                        ));
            }
            result.Close();

            error = CommandError.None;
            return(SequrityUtils.Encrypt(JsonConvert.SerializeObject(extendedResults), client.SecretDFKey));
        }
コード例 #8
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            if (client.Role != UserRoles.Teacher)
            {
                error = CommandError.NoPermissions;
                return(null);
            }

            var id = SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey);

            var result = DBConnection.PrepareExecProcedureCommand("CheckTestCreatorId", id).ExecuteReader();

            if (result.Read())
            {
                if (result.GetInt32(0) != client.UserId)
                {
                    error = CommandError.NoPermissions;
                    return(null);
                }
            }
            else
            {
                error = CommandError.TestNotFound;
                return(null);
            }
            result.Close();

            DBConnection.PrepareExecProcedureCommand("PassToggle", id).ExecuteNonQuery();

            error = CommandError.None;
            return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
        }
コード例 #9
0
 private void GetTestsList(bool isCreatorTests)
 {
     if (isCreatorTests && connection.User.UserRole != UserRoles.Teacher)
     {
         MessageBox.Show("Вы должны иметь права Преподавателя для просмотра данного списка", "Права доступа", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         comboBoxData.SelectedIndex = 0;
     }
     else
     {
         connection.SendCommand(
             new RequestInfo(
                 "GetTestsSheet",
                 SequrityUtils.Encrypt(
                     new TestSheetGetParams(
                         isCreatorTests,
                         textBoxTestNameSurname.Text,
                         subjectsRoles.FirstOrDefault(
                             x => x.Value == (string)comboBoxSubjectRole.SelectedItem)
                         .Key)
                     .ToJson(),
                     connection.User.SecretKey),
                 connection.User.UserToken),
             onTestListRecive);
     }
 }
コード例 #10
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            client.UpdateExpiredTime();
            error = CommandError.None;
            return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
        }
コード例 #11
0
ファイル: AddSubject.cs プロジェクト: 0leXis/OleXisTest2.0
 private void buttonAdd_Click(object sender, EventArgs e)
 {
     if (textBoxSubjectName.Text == "")
     {
         MessageBox.Show("Поле \"Название предмета\" должно быть заполнено!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     connection.SendCommand(new RequestInfo("AddSubject", SequrityUtils.Encrypt(textBoxSubjectName.Text, connection.User.SecretKey), connection.User.UserToken), onRecive);
 }
コード例 #12
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var sheetParams = TestSheetGetParams.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));

            if (client.Role != UserRoles.Teacher && sheetParams.isCreatorTests)
            {
                error = CommandError.NoPermissions;
                return(null);
            }
            bool   useNameFilter    = false;
            bool   useSubjectFilter = false;
            int    subject          = -1;
            string name             = "";

            if (sheetParams.Name != null && sheetParams.Name != "")
            {
                name          = sheetParams.Name;
                useNameFilter = true;
            }
            if (sheetParams.Subject != null && sheetParams.Subject > 0)
            {
                subject          = sheetParams.Subject.Value;
                useSubjectFilter = true;
            }

            MySqlDataReader result;

            if (sheetParams.isCreatorTests)
            {
                result = DBConnection.PrepareExecProcedureCommand("GetTestsCreatorSheet", client.UserId.ToString(), name, subject.ToString(), Convert.ToInt32(useNameFilter).ToString(), Convert.ToInt32(useSubjectFilter).ToString()).ExecuteReader();
            }
            else
            {
                result = DBConnection.PrepareExecProcedureCommand("GetTestsSheet", name, subject.ToString(), Convert.ToInt32(useNameFilter).ToString(), Convert.ToInt32(useSubjectFilter).ToString()).ExecuteReader();
            }

            var testList = new List <TestSheetItem>();

            while (result.Read())
            {
                testList.Add(
                    new TestSheetItem(
                        result.GetInt32(0),
                        result.GetString(1),
                        result.GetString(2),
                        result.GetDateTime(3),
                        result.GetInt32(4),
                        result.GetBoolean(5)
                        ));
            }
            result.Close();

            error = CommandError.None;
            return(SequrityUtils.Encrypt(JsonConvert.SerializeObject(testList), client.SecretDFKey));
        }
コード例 #13
0
ファイル: DBTestResults.cs プロジェクト: 0leXis/OleXisTest2.0
 private void GetExtendedResults(int resultId)
 {
     connection.SendCommand(
         new RequestInfo(
             "GetExtendedResult",
             SequrityUtils.Encrypt(
                 resultId.ToString(),
                 connection.User.SecretKey),
             connection.User.UserToken),
         onExtendedResultsRecive);
 }
コード例 #14
0
 private void PassToggleTest(int id)
 {
     connection.SendCommand(
         new RequestInfo(
             "PassToggleTest",
             SequrityUtils.Encrypt(
                 id.ToString(),
                 connection.User.SecretKey),
             connection.User.UserToken),
         onDeletePassToggleRecive);
 }
コード例 #15
0
ファイル: DBTestResults.cs プロジェクト: 0leXis/OleXisTest2.0
 private void GetExtendedResultsExcelInfo()
 {
     connection.SendCommand(
         new RequestInfo(
             "GetExtendedResultSheet",
             SequrityUtils.Encrypt(
                 TestId.ToString(),
                 connection.User.SecretKey),
             connection.User.UserToken),
         onExtendedResultsExcelInfoRecive);
 }
コード例 #16
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var newPassword  = SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey);
            var passwordHash = SequrityUtils.GetHash(newPassword);

            DBConnection.PrepareExecProcedureCommand("ChangePassword", client.UserId.ToString(), passwordHash).ExecuteNonQuery();

            error = CommandError.None;
            return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
        }
コード例 #17
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var config = ConfigContainer.GetConfig();

            if (client.Role == null && !config.AllowRegistrationRequests)
            {
                error = CommandError.SelfRegistrationNotAllowed;
                return(null);
            }
            if (client.Role == UserRoles.Teacher && !config.AllowStudentsRegistration)
            {
                error = CommandError.StudentRegistrationNotAllowed;
                return(null);
            }

            var registerData = RegisterData.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));
            var passwordHash = SequrityUtils.GetHash(registerData.Password);

            var DBReader = DBConnection.PrepareExecProcedureCommand("GetStudentGroup", registerData.Group).ExecuteReader();

            if (DBReader.Read())
            {
                var studentGroup = DBReader.GetInt32(0);
                DBReader.Close();

                DBReader = DBConnection.PrepareExecProcedureCommand("CheckUserLogin", registerData.Login).ExecuteReader();
                if (DBReader.Read())
                {
                    if (DBReader.GetInt32(0) > 0)
                    {
                        DBReader.Close();
                        error = CommandError.LoginExists;
                        return(null);
                    }
                }
                DBReader.Close();
                DBConnection.PrepareExecProcedureCommand("RegisterStudent", registerData.Firstname, registerData.Lastname, registerData.Login, passwordHash, studentGroup.ToString()).ExecuteNonQuery();

                error = CommandError.None;
                return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
            }
            else
            {
                DBReader.Close();
                error = CommandError.BadStudentGroup;
                return(null);
            }
        }
コード例 #18
0
        public bool Save(ITest test, string testName, int subject)
        {
            if (testName == null)
            {
                throw new ArgumentNullException("Значение testName не может быть null");
            }
            FileProcessor.ClearTmpDir(tmpDir);

            for (var i = 0; i < test.Questions.Count; i++)
            {
                var serialized_question = test.Questions[i].Serialize();
                using (FileStream file = new FileStream(tmpDir + @"\" + i + ".dat", FileMode.OpenOrCreate))
                {
                    serialized_question.WriteTo(file);
                }
            }

            var formatter = new BinaryFormatter();

            using (FileStream file = new FileStream(tmpDir + @"\main.dat", FileMode.OpenOrCreate))
            {
                formatter.Serialize(file, test);
            }

            var stream = new MemoryStream();

            FileProcessor.CompressFile(tmpDir, stream);
            var testInfo = new NetSerializedTestInfo(stream.ToArray(), testName, subject);

            _error = null;
            connection.SendCommand(
                new RequestInfo(
                    "SaveTest",
                    SequrityUtils.Encrypt(
                        testInfo.ToJson(),
                        connection.User.SecretKey),
                    connection.User.UserToken),
                onSaveRecive
                );

            FileProcessor.ClearTmpDir(tmpDir);
            if (_error == null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #19
0
 private void DeleteTest(int id)
 {
     if (MessageBox.Show("Вы уверены?", "Удаление пользователя", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         connection.SendCommand(
             new RequestInfo(
                 "DeleteTest",
                 SequrityUtils.Encrypt(
                     id.ToString(),
                     connection.User.SecretKey),
                 connection.User.UserToken),
             onDeletePassToggleRecive);
     }
 }
コード例 #20
0
        public ITest LoadForEdit(string testName)
        {
            _error = null;
            connection.SendCommand(
                new RequestInfo(
                    "LoadTestForEdit",
                    SequrityUtils.Encrypt(
                        testName,
                        connection.User.SecretKey),
                    connection.User.UserToken),
                onLoadRecive
                );

            return(loadedTest);
        }
コード例 #21
0
ファイル: DBTestResults.cs プロジェクト: 0leXis/OleXisTest2.0
 private void UpdateData()
 {
     connection.SendCommand(
         new RequestInfo(
             "GetTestResults",
             SequrityUtils.Encrypt(
                 new ServerTestResultGetParams(
                     TestId,
                     textBoxTestNameSurname.Text,
                     checkBoxUseData.Checked ? (DateTime?)dateTimePicker1.Value : null)
                 .ToJson(),
                 connection.User.SecretKey),
             connection.User.UserToken),
         onResultsRecive);
 }
コード例 #22
0
 private void GetUsersList()
 {
     connection.SendCommand(
         new RequestInfo(
             "GetUsersSheet",
             SequrityUtils.Encrypt(
                 new UserSheetGetParams(
                     textBoxTestNameSurname.Text,
                     subjectsRoles.FirstOrDefault(
                         x => x.Value == (string)comboBoxSubjectRole.SelectedItem)
                     .Key)
                 .ToJson(),
                 connection.User.SecretKey),
             connection.User.UserToken),
         onUserListRecive);
 }
コード例 #23
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var result    = DBConnection.PrepareExecProcedureCommand("GetAvailableTests").ExecuteReader();
            var testsList = new List <string>();

            while (result.Read())
            {
                testsList.Add(result.GetString(0));
            }
            result.Close();

            error = CommandError.None;
            return(SequrityUtils.Encrypt(JsonConvert.SerializeObject(testsList), client.SecretDFKey));
        }
コード例 #24
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var result      = DBConnection.PrepareExecProcedureCommand("GetSubjectList").ExecuteReader();
            var subjectList = new Dictionary <int, string>();

            while (result.Read())
            {
                subjectList.Add(result.GetInt32(0), result.GetString(1));
            }
            result.Close();

            error = CommandError.None;
            return(SequrityUtils.Encrypt(JsonConvert.SerializeObject(subjectList), client.SecretDFKey));
        }
コード例 #25
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     if (textBoxSurname.Text == "")
     {
         MessageBox.Show("Поле \"Фамилия\" должно быть заполнено!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if (textBoxFirstname.Text == "")
     {
         MessageBox.Show("Поле \"Имя\" должно быть заполнено!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if (checkBoxChangePassword.Checked)
     {
         if (textBoxPassword.Text == "")
         {
             MessageBox.Show("Поле \"Пароль\" должно быть заполнено!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         if (textBoxPassConfirm.Text != textBoxPassword.Text)
         {
             MessageBox.Show("Пароли не совпадают!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
     }
     if (textBoxGroup.Visible)
     {
         if (textBoxGroup.Text == "")
         {
             MessageBox.Show("Поле \"Группа\" должно быть заполнено!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
     }
     connection.SendCommand(
         new RequestInfo(
             "EditUser",
             SequrityUtils.Encrypt(
                 new EditUserData(
                     userId,
                     checkBoxChangePassword.Checked ? textBoxPassword.Text : null,
                     textBoxFirstname.Text,
                     textBoxSurname.Text,
                     textBoxGroup.Text).ToJson(),
                 connection.User.SecretKey),
             connection.User.UserToken),
         onRecive);
 }
コード例 #26
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            if (client.Role != UserRoles.Admin)
            {
                error = CommandError.NoPermissions;
                return(null);
            }

            var id = SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey);

            DBConnection.PrepareExecProcedureCommand("DeleteUser", id).ExecuteNonQuery();

            error = CommandError.None;
            return(SequrityUtils.Encrypt("OK", client.SecretDFKey));
        }
コード例 #27
0
ファイル: NetConnection.cs プロジェクト: 0leXis/OleXisTest2.0
 public void Register(RegisterData registerData, Action <string> onRegister)
 {
     Connect((error) =>
     {
         if (error == null)
         {
             try
             {
                 var netSender = new NetDataSender(
                     new RequestInfo("RegisterStudent", SequrityUtils.Encrypt(registerData.ToJson(), _User.SecretKey), _User.UserToken),
                     (responseData) =>
                 {
                     var responseInfo = ResponseInfo.FromJson(responseData);
                     if (responseInfo.Error != null)
                     {
                         Disconnect();
                         onRegister(responseInfo.Error);
                     }
                     else
                     {
                         if (SequrityUtils.DecryptString(responseInfo.Data, _User.SecretKey) == "OK")
                         {
                             Disconnect();
                             onRegister(null);
                         }
                         else
                         {
                             Disconnect();
                             onRegister(responseInfo.Error);
                         }
                     }
                 },
                     Address);
             }
             catch (Exception e)
             {
                 onRegister("Ошибка авторизации: " + e.Message);
             }
         }
         else
         {
             onRegister(error);
         }
     });
 }
コード例 #28
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var resultParams = ServerTestResultGetParams.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));


            bool     useSurnameFilter = false;
            bool     useDateFilter    = false;
            DateTime date             = DateTime.Now;
            string   surname          = "";

            if (resultParams.StudentSurname != null && resultParams.StudentSurname != "")
            {
                surname          = resultParams.StudentSurname;
                useSurnameFilter = true;
            }
            if (resultParams.PassDate != null)
            {
                date          = resultParams.PassDate.Value;
                useDateFilter = true;
            }

            var result = DBConnection.PrepareExecProcedureCommand("GetTestResultSheet", surname, date.ToString("yyyy-MM-dd"), Convert.ToInt32(useSurnameFilter).ToString(), Convert.ToInt32(useDateFilter).ToString()).ExecuteReader();

            var resultList = new List <ResultSheetItem>();

            while (result.Read())
            {
                var tmpDateTime = result.GetString(3).Split(':');
                var passingTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, Convert.ToInt32(tmpDateTime[0]), Convert.ToInt32(tmpDateTime[1]), Convert.ToInt32(tmpDateTime[2]));
                resultList.Add(
                    new ResultSheetItem(
                        result.GetInt32(0),
                        result.GetString(1),
                        result.GetInt32(2),
                        passingTime,
                        result.GetDateTime(4)
                        ));
            }
            result.Close();

            error = CommandError.None;
            return(SequrityUtils.Encrypt(JsonConvert.SerializeObject(resultList), client.SecretDFKey));
        }
コード例 #29
0
ファイル: SetDFCommand.cs プロジェクト: 0leXis/OleXisTest2.0
        public byte[] Execute(out CommandError error)
        {
            if (requestData.UserToken == null)
            {
                error = CommandError.NullToken;
                return(null);
            }
            var client = ClientManager.GetClient(requestData.UserToken);

            if (client == null)
            {
                error = CommandError.ClientNotFound;
                return(null);
            }
            client.SecretDFKey = SequrityUtils.DiffieHellmanGetSecretKey(Encoding.UTF8.GetString(requestData.Data), client.GeneratedDFKey);
            error = CommandError.None;
            return(SequrityUtils.Encrypt("CONNECTION_STARTED", client.SecretDFKey));
        }
コード例 #30
0
        public byte[] Execute(out CommandError error)
        {
            var client = ClientManager.GetClient(requestData.UserToken);

            var    sheetParams      = UserSheetGetParams.FromJson(SequrityUtils.DecryptString(requestData.Data, client.SecretDFKey));
            bool   useSurnameFilter = false;
            bool   useRoleFilter    = false;
            int    role             = -1;
            string surname          = "";

            if (sheetParams.Surname != null && sheetParams.Surname != "")
            {
                surname          = sheetParams.Surname;
                useSurnameFilter = true;
            }
            if (sheetParams.Role != null && sheetParams.Role > 0)
            {
                role          = sheetParams.Role.Value;
                useRoleFilter = true;
            }

            var result   = DBConnection.PrepareExecProcedureCommand("GetUsersSheet", surname, role.ToString(), Convert.ToInt32(useSurnameFilter).ToString(), Convert.ToInt32(useRoleFilter).ToString()).ExecuteReader();
            var userList = new List <UserSheetItem>();

            while (result.Read())
            {
                userList.Add(
                    new UserSheetItem(
                        result.GetInt32(0),
                        result.GetString(1),
                        result.GetString(2),
                        result.GetString(3),
                        result.GetInt32(4),
                        result.IsDBNull(5) ? null : result.GetString(5)
                        ));
            }
            result.Close();

            error = CommandError.None;
            return(SequrityUtils.Encrypt(JsonConvert.SerializeObject(userList), client.SecretDFKey));
        }