Esempio n. 1
0
        public static bool ChangeDataBase(string ChooseString, Student student)
        {
            SQLiteCommand cmdUpdate = new SQLiteCommand();

            //数据库连接字符串
            string ConnectionString  = "Data Source=" + Environment.CurrentDirectory + "\\DATABASE.db;Version=3;UseUTF16Encoding=True;".Replace("DATABASE.db", DataBaseName);
            string CommandTextUpdate = "";

            if (ChooseString == "Grade")
            {
                CommandTextUpdate = UpdateGradeCommand.Replace("'", "\"").Replace("idid", student.id).Replace("gradegrade", student.grade).Replace("cnocno", student.course);
            }
            else if (ChooseString == "Information")
            {
                CommandTextUpdate = UpateInformationCommand.Replace("'", "\"").Replace("sexsex", student.sex).Replace("idid", student.id).Replace("namename", student.name).Replace("yearyear", student.year).Replace("monthmonth", student.month).Replace("dayday", student.day).Replace("classclass", student.class0).Replace("collegecollege", student.college).Replace("professionalprofessional", student.professional);
            }
            else if (ChooseString == "DeleteInformation")
            {
                CommandTextUpdate = DeleteInformationCommand.Replace("'", "\"").Replace("idid", student.id).Replace("namename", student.name);
            }
            else
            {
                MessageBox.Show("参数传递错误", "错误");
                return(false);
            }

            SQLiteConnection con = null;

            try
            {
                con = new SQLiteConnection(ConnectionString);
                con.Open();
            }
            catch
            {
                MessageBox.Show("数据库修改时时,连接失败");
                return(false);
            }
            SQLiteCommand cmd = new SQLiteCommand();

            cmd.Connection  = con;
            cmd.CommandText = CommandTextUpdate;

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch
            {
                MessageBox.Show("数据库修改时发生错误,错误提示:\n" + cmd.CommandText);
                return(false);
            }
            finally
            {
                con.Close();
            }
            return(true);
        }
        public void ShouldContainNoErrors()
        {
            // Arrange
            var id      = Guid.NewGuid();
            var version = 0;

            var command = new DeleteInformationCommand(id, version);

            // Act
            var validationResult = _validator.Validate(command);
            var exists           = validationResult.Errors.Count > 0;

            // Assert
            exists.Should().BeFalse();
        }
        public void ShouldHaveInformationNotFoundCustomFailureWhenIdIsGuidEmpty()
        {
            // Arrange
            var id      = Guid.Empty;
            var version = 0;

            var command = new DeleteInformationCommand(id, version);

            // Act
            var validationResult = _validator.Validate(command);
            var exists           =
                validationResult.Errors.Any(
                    a => a.PropertyName.Equals("Id") && a.ErrorMessage.Contains(CustomFailures.InformationNotFound));

            // Assert
            exists.Should().BeTrue();
        }