コード例 #1
0
ファイル: DBQueryTests.cs プロジェクト: timnicolaisen/eule
        public void SelectVacationRequestTest_F5032_K_1()
        {
            ulong VacationRequestIDtmp = 0UL;
            DateTime VacationStartDatetmp = new DateTime(2000, 1, 1);
            DateTime VacationEndDatetmp = new DateTime(2000, 1, 1);
            DateTime SubmissionDatetmp = new DateTime(2000, 1, 1);
            string VacationProcessingStatetmp = "";
            string VacationTypetmp = "c";
            DateTime ModificationDatetmp = new DateTime(2000, 1, 1);
            Boolean VacationOverlapNotetmp = false;
            Boolean VacationLockPeriodNotetmp = false;
            string EmployeeIDtmp = "null";
            int NetVacationDays = 0;

            using (SqlConnection connection = new SqlConnection(sqlConnectionString))
            {
                string sqlStatement =
                    "SELECT * FROM dbo.VacationRequest WHERE VacationRequestID = " + 10 + "";
                using (SqlCommand cmd = new SqlCommand(sqlStatement, connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        // Check if the reader has any rows at all before starting to read.
                        if (reader.HasRows)
                        {
                            // Read advances to the next row.
                            while (reader.Read())
                            {
                                // Save DB-Returns into temp variables and insert them into the list

                                VacationRequestIDtmp = (ulong)reader.GetInt64(reader.GetOrdinal("VacationRequestID"));
                                VacationStartDatetmp = reader.GetDateTime(reader.GetOrdinal("VacationStartDate"));
                                VacationEndDatetmp = reader.GetDateTime(reader.GetOrdinal("VacationEndDate"));
                                SubmissionDatetmp = reader.GetDateTime(reader.GetOrdinal("SubmissionDate"));
                                VacationTypetmp = reader.GetString(reader.GetOrdinal("VacationType"));
                                VacationProcessingStatetmp = reader.GetString(reader.GetOrdinal("VacationProcessingState"));
                                ModificationDatetmp = reader.GetDateTime(reader.GetOrdinal("ModificationDate"));
                                VacationOverlapNotetmp = reader.GetBoolean(reader.GetOrdinal("VacationPeriodOverlapNote"));
                                VacationLockPeriodNotetmp = reader.GetBoolean(reader.GetOrdinal("VacationLockPeriodNote"));
                                EmployeeIDtmp = reader.GetString(reader.GetOrdinal("EmployeeID"));
                                NetVacationDays = reader.GetInt32(reader.GetOrdinal("NetVacationDays"));

                            }
                        }
                    }
                }
            }
            VacationRequest Vac = new VacationRequest(VacationRequestIDtmp, EmployeeIDtmp, VacationStartDatetmp,
                                    VacationEndDatetmp, SubmissionDatetmp, VacationTypetmp, VacationRequestProcessingState.submitted,
                                    ModificationDatetmp, VacationOverlapNotetmp, VacationLockPeriodNotetmp, NetVacationDays);
            VacationRequest Vacexpect = new VacationRequest(10,"1e04bd54-4fb8-4bb8-806c-8ad7b8c90c43", new DateTime(2015,02,01),new DateTime(2015,02,28),
                                    SubmissionDatetmp, "Erholungsurlaub", VacationRequestProcessingState.submitted, ModificationDatetmp,
                                    false,false,29);
            bool Result = false;
            if ((Vac.getVacationRequestID() == Vacexpect.getVacationRequestID())
                && (Vac.getEmployeeID() == Vacexpect.getEmployeeID())
                && (Vac.getVacationStartDate() == Vacexpect.getVacationStartDate())
                && (Vac.getVacationEndDate() == Vacexpect.getVacationEndDate())
                && (Vac.getSubmissionDate() == Vacexpect.getSubmissionDate())
                && (Vac.getVacationType() == Vacexpect.getVacationType())
                && (Vac.getVacationRequestProcessingState() == Vacexpect.getVacationRequestProcessingState())
                && (Vac.getModificationDate() == Vacexpect.getModificationDate())
                && (Vac.getVacationPeriodOverlapNote() == Vacexpect.getVacationPeriodOverlapNote())
                && (Vac.getVacationLockPeriodNote() == Vacexpect.getVacationLockPeriodNote())
                && (Vac.getNetVacationDays() == Vacexpect.getNetVacationDays()))
            {
                Result = true;
            }
            Assert.AreEqual(true, Result);
        }
コード例 #2
0
ファイル: DBQuery.cs プロジェクト: timnicolaisen/eule
        /// <summary>
        /// inserts a new VacationRequest into the DB
        /// </summary>
        /// <param name="VacationRequest">VacationRequest of Employee</param>
        /// <returns>true or false (successfull or not)</returns>
        public Boolean InsertNewVacationRequest(VacationRequest VacationRequest)
        {
            bool Result = false;
            using (SqlConnection connection = new SqlConnection(sqlConnectionString))
            {
                string sqlStatement =
                    "INSERT INTO [dbo].[VacationRequest] VALUES (@VacationRequestID, @VacationStartDate, @VacationEndDate, @SubmissionDate, @VacationType, @VacationProcessingState, @ModificationDate, @VacationPeriodOverlapNote, @VacationLockPeriodNote,@NetVacationDays, @EmployeeID)";
                using (SqlCommand cmd = new SqlCommand(sqlStatement, connection))
                {
                    cmd.Parameters.AddWithValue("VacationRequestID", (long)VacationRequest.getVacationRequestID());
                    cmd.Parameters.AddWithValue("VacationStartDate", VacationRequest.getVacationStartDate());
                    cmd.Parameters.AddWithValue("VacationEndDate", VacationRequest.getVacationEndDate());
                    cmd.Parameters.AddWithValue("SubmissionDate", VacationRequest.getSubmissionDate());
                    cmd.Parameters.AddWithValue("VacationType", VacationRequest.getVacationType());
                    cmd.Parameters.AddWithValue("VacationProcessingState",
                        ConvertVacationRequestProcessingStateToString(VacationRequest.getVacationRequestProcessingState()));
                    cmd.Parameters.AddWithValue("ModificationDate", VacationRequest.getModificationDate());
                    cmd.Parameters.AddWithValue("VacationPeriodOverlapNote",
                        VacationRequest.getVacationPeriodOverlapNote());
                    cmd.Parameters.AddWithValue("VacationLockPeriodNote", VacationRequest.getVacationLockPeriodNote());
                    cmd.Parameters.AddWithValue("EmployeeID", VacationRequest.getEmployeeID());
                    cmd.Parameters.AddWithValue("NetVacationDays", VacationRequest.getNetVacationDays());

                    try
                    {
                        connection.Open();
                        cmd.ExecuteNonQuery();//insert/delete/update is nonQuery
                        Result = true;
                    }
                    catch (SqlException e) //if Failure in Database then Result = false
                    {
                        {
                            Result = false;
                        }
                    }
                }
            }
            return Result;
        }