示例#1
0
        public IResult <double> AVDiensteGesamt(PUser valUser)
        {
            const string query = @"SELECT Count(*) FROM [StuK_DB].[dbo].[Mitglieder.Dienste] 
                                   Where MitgliederID = @mid and ( Aufgabe = 10 or Aufgabe = 2 or Aufgabe = 15 or Aufgabe = 16)  ";

            var cmd = new SqlCommand(query, StaticSettings.SqlConn);

            cmd.Parameters.Add("@mid", SqlDbType.Int).Value = valUser.MemberID;

            var result = 1;

            try {
                StaticSettings.SqlConn.Open();
                var r = cmd.ExecuteReader();
                while (r.Read())
                {
                    result = (int)r[0];
                }

                r.Close();
            } catch (SqlException sqlException) {
                switch (sqlException.ErrorCode)
                {
                case -2:
                    return(new FailureResult <double>(ErrorType.DatabaseTimout).AddMessage("Timeout"));

                case -1:
                    return(new FailureResult <double>(ErrorType.DatabaseNoConnection).AddMessage("ConnectionError"));

                default:
                    return(new FailureResult <double>(ErrorType.Database).AddMessage(sqlException.Message));
                }
            } catch (InvalidOperationException e) {
                return(new FailureResult <double>(ErrorType.InvalidOperation).AddMessage(e.Message));
                ////} catch (ConfigurationErrorsException e) {
                //    return new FailureResult<double>(ErrorType.InternalError).AddMessage(e.Message);
            } finally {
                StaticSettings.SqlConn.Close();
            }


            return(new SuccessResult <double> {
                Value = result
            });
        }
示例#2
0
        public IResult <DateTime> LastAVDienst(PUser valUser)
        {
            const string query = @"SELECT Top (1) Datum FROM [StuK_DB].[dbo].[Dienste.DienstTag] 
                                   WHERE AV = @avID order by Datum DESC";

            var cmd = new SqlCommand(query, StaticSettings.SqlConn);

            cmd.Parameters.Add("@avID", SqlDbType.Int).Value = valUser.LoginID;

            var result = new DateTime(1090, 06, 20);


            try {
                StaticSettings.SqlConn.Open();
                var r = cmd.ExecuteReader();
                while (r.Read())
                {
                    result = r.GetDateTime(0);
                }

                r.Close();
            } catch (SqlException sqlException) {
                switch (sqlException.ErrorCode)
                {
                case -2:
                    return(new FailureResult <DateTime>(ErrorType.DatabaseTimout).AddMessage("Timeout"));

                case -1:
                    return(new FailureResult <DateTime>(ErrorType.DatabaseNoConnection).AddMessage("ConnectionError"));

                default:
                    return(new FailureResult <DateTime>(ErrorType.Database).AddMessage(sqlException.Message));
                }
            } catch (InvalidOperationException e) {
                return(new FailureResult <DateTime>(ErrorType.InvalidOperation).AddMessage(e.Message));
                //} catch (ConfigurationErrorsException e) {
                //    return new FailureResult<DateTime>(ErrorType.InternalError).AddMessage(e.Message);
            } finally {
                StaticSettings.SqlConn.Close();
            }
            return(new SuccessResult <DateTime> {
                Value = result
            });
        }
示例#3
0
        public IResult <bool> GroßesAVRecht(PUser valUser)
        {
            var result = new[] { false, false, false };

            const string query = @"SELECT AV, AvDi, AvDoFr FROM[StuK_DB].[dbo].[Mitglieder.Optionen] 
                                   WHERE MID = @mid";

            var cmd = new SqlCommand(query, StaticSettings.SqlConn);

            cmd.Parameters.Add("@mid", SqlDbType.Int).Value = valUser.MemberID;

            try {
                StaticSettings.SqlConn.Open();
                var r = cmd.ExecuteReader();
                while (r.Read())
                {
                    result[0] = (bool)r[0];
                    result[1] = (bool)r[1];
                    result[2] = (bool)r[2];
                }

                r.Close();
            } catch (SqlException sqlException) {
                switch (sqlException.ErrorCode)
                {
                case -2:
                    return(new FailureResult <bool>(ErrorType.DatabaseTimout).AddMessage("Timeout"));

                case -1:
                    return(new FailureResult <bool>(ErrorType.DatabaseNoConnection).AddMessage("ConnectionError"));

                default:
                    return(new FailureResult <bool>(ErrorType.Database).AddMessage(sqlException.Message));
                }
            } catch (InvalidOperationException e) {
                return(new FailureResult <bool>(ErrorType.InvalidOperation).AddMessage(e.Message));
                //} catch (ConfigurationErrorsException e) {
                //    return new FailureResult<bool>(ErrorType.InternalError).AddMessage(e.Message);
            } finally {
                StaticSettings.SqlConn.Close();
            }

            if (!result[0])
            {
                return new SuccessResult <bool> {
                           Status = ResultStatus.Empty
                }
            }
            ;

            if (result[0] && result[1])
            {
                return new SuccessResult <bool> {
                           Value = true
                }
            }
            ;

            return(new SuccessResult <bool> {
                Value = false
            });
        }
    }
}