示例#1
0
        public void TestGetDiveType()
        {
            var diveType = new DiveType(1, "100a", 1.0f);
            var testType = DbHandler.GetDiveType("1");

            Assert.AreEqual(diveType.Difficulty, testType.Difficulty);
            Assert.AreEqual(diveType.Code, testType.Code);
            Assert.AreEqual(diveType.Id, testType.Id);
            Assert.AreNotEqual("200c", testType.Code);
        }
示例#2
0
文件: Dive.cs 项目: ozzieem/UniCpp
 public Dive(int id, DiveType diveType, float totalPoints, int order, int diverId)
     : base(id)
 {
     Assessments = new List<Assessment>();
     DiverId = diverId;
     Type = diveType;
     TotalPoints = new Score(totalPoints);
     Order = order;
     //_name = Name; //Skall anropa en funktion som genererar namnet på hoppet från koden.
 }
示例#3
0
        public static List<DiveType> GetDiveTypes()
        {
            Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}");
            const string sql = "SELECT * FROM divetype";

            using (var sqlConnection = ConnectToDatabase())
            {
                var tDiveTypes = new List<DiveType>();
                using (var sqlQuery = new MySqlCommand(sql, sqlConnection))
                {
                    Logger.Info("Running Query: \"{0}\"", sql);

                    var tableReader = sqlQuery.ExecuteReader();
                    while (tableReader.Read())
                    {
                        var tDiveType = new DiveType(
                            tableReader.GetInt32("Id"),
                            tableReader.GetString("Code"),
                            tableReader.GetFloat("Difficulty"));
                        tDiveTypes.Add(tDiveType);
                    }
                }
                Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}");
                return tDiveTypes;
            }
        }
示例#4
0
        public static DiveType GetDiveType(string data)
        {
            Logger.Trace($"Entering method {MethodBase.GetCurrentMethod().Name}");

            int id;
            int.TryParse(data, out id);
            var sql = id > 0
                ? $"SELECT * FROM divetype WHERE ID = {id}"
                : $"SELECT * FROM divetype WHERE Code = '{data}'";

            using (var sqlConnection = ConnectToDatabase())
            {
                var diveType = new DiveType();
                using (var sqlQuery = new MySqlCommand(sql, sqlConnection))
                {
                    Logger.Info("Running Query: \"{0}\"", sql);

                    var tableReader = sqlQuery.ExecuteReader();
                    while (tableReader.Read())
                    {
                        var tDiveType = new DiveType(
                            tableReader.GetInt32("Id"),
                            tableReader.GetString("Code"),
                            tableReader.GetFloat("Difficulty"));
                        diveType = tDiveType;
                    }
                }
                Logger.Trace($"Leaving method {MethodBase.GetCurrentMethod().Name}");
                return diveType;
            }
        }