コード例 #1
0
ファイル: MongoDBHelper_Star.cs プロジェクト: GSazheniuk/HOO
        public DBCommandResult SaveStar(Star s)
        {
            DBCommandResult res = new DBCommandResult();
            try
            {
                var stars = db.GetCollection<Star>("Stars");
                if (s.IsLoaded)
                    res.Tag = stars.ReplaceOne(new BsonDocument("_id", s._id), s, new UpdateOptions { IsUpsert = true });
                else
                {
                    stars.InsertOne(s, new InsertOneOptions { BypassDocumentValidation = false });
                    res.Tag = s;
                }

                s.IsLoaded = s.IsSaved = true;

                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex)
            {
                res.ResultCode = -2;
                res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
コード例 #2
0
        public DBCommandResult AddNewPlayer(string userName, string password, string email, Player p)
        {
            DBCommandResult res = new DBCommandResult ();

            MySqlCommand com = new MySqlCommand ("ADM_AddPlayer", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;
            MySqlParameter spUsername = new MySqlParameter("pUserName", userName);
            MySqlParameter spEmail = new MySqlParameter("pEmail", email);
            MySqlParameter spPassword = new MySqlParameter("pPassword", password);
            MySqlParameter spLeaderName = new MySqlParameter("pLeaderName", p.LeaderName);
            MySqlParameter spRace = new MySqlParameter("pRace", p.Race);
            MySqlParameter spMotto = new MySqlParameter("pMotto", p.Motto);
            MySqlParameter spColor = new MySqlParameter("pColor", p.Color);
            com.Parameters.AddRange(new MySqlParameter[] {spUsername, spEmail, spPassword, spLeaderName, spRace, spMotto, spColor});

            try
            {
                DataSet ds = _dg.GetDataSet(com);
                DataRow dr = ds.Tables[0].Rows[0];
                p.OBID = Convert.ToInt32(dr["OBID"]);
                p.LeaderName = Convert.ToString(dr["LeaderName"]);
                p.Race = Convert.ToString(dr["Race"]);
                p.Motto = Convert.ToString(dr["Motto"]);
                p.Color = Convert.ToString(dr["Color"]);

                res = SaveAttributes(p);
            }
            catch (Exception ex) {
                res.ResultCode = -2;
                res.ResultMsg = String.Format ("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
コード例 #3
0
        public DBCommandResult AddNewPlayer(Player p)
        {
            DBCommandResult res = new DBCommandResult();

            try
            {
                var players = db.GetCollection<Player>("Players");

                p._id = players.Count(new BsonDocument());

                players.InsertOne(p, new InsertOneOptions { BypassDocumentValidation = false });

                p.IsLoaded = p.IsSaved = true;

                res.Tag = p;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex)
            {
                res.ResultCode = -2;
                res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
コード例 #4
0
        public DBCommandResult GetAllGalaxies(int uId)
        {
            DBCommandResult res = new DBCommandResult ();

            MySqlCommand com = new MySqlCommand ("ADM_GetAllGalaxies", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;
            MySqlParameter spUID = new MySqlParameter("pUId", uId);
            com.Parameters.Add(spUID);

            try
            {
                DataSet ds = _dg.GetDataSet(com);
                List<Galaxy> gals = new List<Galaxy>();
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    Galaxy g = new Galaxy();
                    g.OBID = Convert.ToInt32(dr["OBID"]);
                    g.Name = Convert.ToString(dr["Name"]);
                    g.DimensionX = Convert.ToInt32(dr["DimX"]);
                    g.DimensionY = Convert.ToInt32(dr["DimY"]);
                    g.DimensionZ = Convert.ToInt32(dr["DimZ"]);

                    gals.Add(g);
                }
                res.Tag = gals;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex) {
                res.ResultCode = -2;
                res.ResultMsg = String.Format ("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
コード例 #5
0
        public DBCommandResult SaveAttributes(BaseObject bo)
        {
            DBCommandResult res = new DBCommandResult ();

            try {
                //Save Attributes
            //            OAttribute[] list = bo.Attributes;//.ChangedAttributes ();
                //for (int i = 0; i<list.Length; i++) {
                //	OAttribute key = list [i];
                //	//throw new Exception (String.Format("{0}. {1}, {2}, {3}", bo.ObjectType, bo.OBID, key, bo.Attributes [key]));
                //	MySqlCommand com = new MySqlCommand ("GM_SaveAttribute", _dg.Connection);
                //	com.CommandType = CommandType.StoredProcedure;
                //	MySqlParameter spAId = new MySqlParameter ("pAID", key._id);
                //	MySqlParameter spAttrId = new MySqlParameter ("pAttrId", key.AttributeID);
                //	MySqlParameter spObjectType = new MySqlParameter ("pAttrType", key.AttributeType);
                //	MySqlParameter spObjectId = new MySqlParameter ("pObjectId", bo.OBID);
                //	MySqlParameter spValue = new MySqlParameter ("pValue", key.Value);

                //	com.Parameters.AddRange (new MySqlParameter[] { spAId, spAttrId, spObjectType, spObjectId, spValue });
                //	_dg.ExecuteCommand (com);
                //}

                //bo.Attributes.SaveAll();
                res.Tag = bo;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            } catch (Exception ex) {
                res.ResultCode = -2;
                res.ResultMsg = String.Format ("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
コード例 #6
0
        public DBCommandResult LoadOrbitalBody(StarOrbitalBody sob)
        {
            DBCommandResult res = new DBCommandResult ();

            MySqlCommand com = new MySqlCommand ("ADM_GetOrbitalBodyById", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;
            MySqlParameter spSOBID = new MySqlParameter("pSOBId", sob.OBID);
            com.Parameters.Add(spSOBID);
            try
            {
                DataSet ds = _dg.GetDataSet(com);
                DataRow dr = ds.Tables[0].Rows[0];
                sob.OBID = Convert.ToInt32(dr["OBID"]);
                sob.OrbitNo = Convert.ToInt32(dr["OrbitNo"]);

                sob.Attributes = new List<OAttribute>();
                //sob.Attributes.ParentObject = sob;
                //sob.Attributes.Load(LoadAttributes(ds.Tables[1]));

                res.Tag = sob;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex) {
                res.ResultCode = -2;
                res.ResultMsg = String.Format ("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
コード例 #7
0
        public DBCommandResult LoadGalaxy(long galaxyId)
        {
            DBCommandResult res = new DBCommandResult();

            try
            {
                var rg = db.GetCollection<Galaxy>("Galaxies").Find(new BsonDocument("_id", galaxyId)).ToList();
                Galaxy g = (rg.Count > 0) ? rg[0] : new Galaxy();

                DBCommandResult rs = GetAllStars(galaxyId);

                if (rs.ResultCode == 0)
                    g.Stars = (List<Star>)rs.Tag;

                g.IsLoaded = g.IsSaved = true;
                res.Tag = g;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex)
            {
                res.Tag = new Galaxy();
                res.ResultCode = -2;
                res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }

            return res;
        }
コード例 #8
0
ファイル: MongoDBHelper_SOB.cs プロジェクト: GSazheniuk/HOO
        public DBCommandResult GetStarOrbitalBodies(long starId)
        {
            DBCommandResult res = new DBCommandResult();

            try
            {
                var rs = db.GetCollection<Star>("Stars").Find(new BsonDocument("_id", starId)).ToList();
                Star s = (rs.Count > 0) ? rs[0] : new Star();

                DBCommandResult ro = GetAllOrbitalBodies(starId);

                if (ro.ResultCode == 0)
                    s.OrbitalBodies = (List<StarOrbitalBody>)ro.Tag;

                s.IsLoaded = s.IsSaved = true;
                res.Tag = s;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex)
            {
                res.Tag = new Star();
                res.ResultCode = -2;
                res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }

            return res;
        }
コード例 #9
0
        public DBCommandResult LoadUniverse(Universe u)
        {
            DBCommandResult res = new DBCommandResult();

            try
            {
                var resu = db.GetCollection<Universe>("Universe").Find(new BsonDocument("_id", u._id)).ToList();
                Universe ru = (resu.Count > 0) ? resu[0] : new Universe();

                DBCommandResult rg = GetAllGalaxies(ru._id);

                if (rg.ResultCode == 0)
                    ru.Galaxies = (List<Galaxy>)rg.Tag;

                ru.IsLoaded = ru.IsSaved = true;
                res.Tag = ru;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex)
            {
                res.Tag = new Universe();
                res.ResultCode = -2;
                res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
コード例 #10
0
ファイル: MongoDBHelper_Star.cs プロジェクト: GSazheniuk/HOO
 public DBCommandResult GetStarNames()
 {
     DBCommandResult res = new DBCommandResult();
     var snames = db.GetCollection<StarName>("StarDictionary").Find(new BsonDocument()).ToList();
     res.Tag = snames;
     res.ResultCode = 0;
     res.ResultMsg = "Ok";
     return res;
 }
コード例 #11
0
        public DBCommandResult LoadGalaxy(Galaxy g)
        {
            DBCommandResult res = new DBCommandResult ();

            MySqlCommand com = new MySqlCommand ("ADM_GetGalaxyById", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;
            MySqlParameter spGalID = new MySqlParameter("pGalId", g.OBID);
            com.Parameters.Add(spGalID);

            try
            {
                DataSet ds = _dg.GetDataSet(com);
                DataRow dr = ds.Tables[0].Rows[0];
                g.OBID = Convert.ToInt32(dr["OBID"]);
                g.Name = Convert.ToString(dr["Name"]);
                g.DimensionX = Convert.ToInt32(dr["DimX"]);
                g.DimensionY = Convert.ToInt32(dr["DimY"]);
                g.DimensionZ = Convert.ToInt32(dr["DimZ"]);

                g.Attributes = new List<OAttribute>();
                //g.Attributes.ParentObject = g;
                //g.Attributes.Load(LoadAttributes(ds.Tables[1]));

                foreach (DataRow sRow in ds.Tables[2].Rows)
                {
                    Star s = new Star();
                    s.GalaxyId = g._id;
                    s.OBID = Convert.ToInt32(sRow["OBID"]);
                    s.Coordinates= new HOO.Core.Model.Configuration.Point3D();
                    s.Class = ((StarClass)Convert.ToInt32(sRow["Class"]));
                    s.TemperatureLevel = Convert.ToInt32(sRow["TempLvl"]);
                    s.Size = ((StarSize)Convert.ToInt32(sRow["Size"]));
                    s.StarSystemName = Convert.ToString(sRow["SystemName"]);
                    s.Coordinates.X = Convert.ToInt32(sRow["X"]);
                    s.Coordinates.Y = Convert.ToInt32(sRow["Y"]);
                    s.Coordinates.Z = Convert.ToInt32(sRow["Z"]);

                    g.Stars.Add(s);
                }

                res.Tag = g;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex) {
                res.ResultCode = -2;
                res.ResultMsg = String.Format ("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
コード例 #12
0
        public void LoadOrbitalBody()
        {
            DBCommandResult res = new DBCommandResult ();
            res = _dh.LoadOrbitalBody (OrbitalBody);

            if (res.ResultCode == 0) {
                OrbitalBody.IsLoaded = OrbitalBody.IsSaved = true;

                if (this.OrbitalBody.Attributes.Count == 0) {
                    InitDefaultParameters ();
                }
            } else {
                throw new Exception (res.ResultMsg);
            }
        }
コード例 #13
0
 public DBCommandResult AllUniverses()
 {
     DBCommandResult res = new DBCommandResult();
     try
     {
         res.Tag = db.GetCollection<Universe>("Universe").Find(new BsonDocument()).ToList();
         res.ResultCode = 0;
         res.ResultMsg = "Ok";
     }
     catch (Exception ex)
     {
         res.ResultCode = -2;
         res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
     }
     return res;
 }
コード例 #14
0
 public DBCommandResult SaveUniverse(Universe u)
 {
     DBCommandResult res = new DBCommandResult();
     try
     {
         var us = db.GetCollection<Universe>("Universe");
         res.Tag = us.ReplaceOne(new BsonDocument("_id", u._id), u, new UpdateOptions { IsUpsert = true });
         res.ResultCode = 0;
         res.ResultMsg = "Ok";
     }
     catch (Exception ex)
     {
         res.ResultCode = -2;
         res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
     }
     return res;
 }
コード例 #15
0
ファイル: MongoDBHelper_Star.cs プロジェクト: GSazheniuk/HOO
        public DBCommandResult GetAllStars(long galaxyId)
        {
            DBCommandResult res = new DBCommandResult();

            try
            {
                res.Tag = db.GetCollection<Star>("Stars").Find(new BsonDocument("GalaxyId", galaxyId)).ToList();
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex)
            {
                res.Tag = new List<Star>();
                res.ResultCode = -2;
                res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }

            return res;
        }
コード例 #16
0
        public DBCommandResult AddStarName(string pName)
        {
            DBCommandResult res = new DBCommandResult ();

            MySqlCommand com = new MySqlCommand ("ADM_AddStarName", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;
            MySqlParameter spName = new MySqlParameter("pName", pName);
            com.Parameters.Add(spName);

            try
            {
                _dg.ExecuteCommand(com);
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex) {
                res.ResultCode = -2;
                res.ResultMsg = String.Format ("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
コード例 #17
0
        public DBCommandResult AuthPlayer(string userName, string password)
        {
            DBCommandResult res = new DBCommandResult();

            try
            {
                var players = db.GetCollection<Player>("Players").Find(x => x.Username == userName && x.Password == password).ToList();
                Player p = (players.Count > 0) ? players[0] : new Player();

                p.IsLoaded = p.IsSaved = (players.Count > 0);

                res.Tag = p;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex)
            {
                res.ResultCode = -2;
                res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
コード例 #18
0
        public DBCommandResult EndTurn(int uId)
        {
            DBCommandResult res = new DBCommandResult ();

            MySqlCommand com = new MySqlCommand ("GM_TickUniverse", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;
            MySqlParameter spUniverseId = new MySqlParameter("pUniverseId", uId);
            com.Parameters.Add(spUniverseId);

            try
            {
                _dg.ExecuteCommand(com);
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
                //res.Tag = s;
            }
            catch (Exception ex) {
                res.ResultCode = -2;
                res.ResultMsg = String.Format ("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
コード例 #19
0
ファイル: MySqlDBHelper.cs プロジェクト: GSazheniuk/HOO
        public DBCommandResult AddGalaxy(Galaxy gal)
        {
            DBCommandResult res = new DBCommandResult();

            MySqlCommand com = new MySqlCommand("ADM_AddGalaxy", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;

            MySqlParameter spUniverseId = new MySqlParameter("pUniverseId", gal.UniverseId);
            MySqlParameter spName = new MySqlParameter("pName", gal.Name);
            MySqlParameter spDimX = new MySqlParameter("pDimX", gal.DimensionX);
            MySqlParameter spDimY = new MySqlParameter("pDimY", gal.DimensionY);
            MySqlParameter spDimZ = new MySqlParameter("pDimZ", gal.DimensionZ);

            com.Parameters.AddRange(new MySqlParameter[] { spUniverseId, spName, spDimX, spDimY, spDimZ});

            try
            {
                DataSet ds = _dg.GetDataSet(com);
                DataRow dr = ds.Tables[0].Rows[0];
                Galaxy rg = new Galaxy();
                rg.OBID = Convert.ToInt32(dr["OBID"]);
                rg.UniverseId = gal.UniverseId;
                rg.Name = Convert.ToString(dr["Name"]);
                rg.DimensionX = Convert.ToInt32(dr["DimX"]);
                rg.DimensionY = Convert.ToInt32(dr["DimY"]);
                rg.DimensionZ = Convert.ToInt32(dr["DimZ"]);
                res.Tag = rg;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex)
            {
                res.ResultCode = -2;
                res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null)?ex.InnerException.Message:"");
            }

            return res;
        }
コード例 #20
0
        public DBCommandResult SaveGalaxy(Galaxy g)
        {
            DBCommandResult res = new DBCommandResult();
            try
            {
                var us = db.GetCollection<Galaxy>("Galaxies");
                if (g.IsLoaded)
                    res.Tag = us.ReplaceOne(new BsonDocument("_id", g._id), g, new UpdateOptions { IsUpsert = true });
                else
                {
                    us.InsertOne(g, new InsertOneOptions { BypassDocumentValidation = false });
                    res.Tag = g;
                }

                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex)
            {
                res.ResultCode = -2;
                res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
コード例 #21
0
        public DBCommandResult AuthPlayer(string userName, string password)
        {
            DBCommandResult res = new DBCommandResult ();

            MySqlCommand com = new MySqlCommand ("GM_AuthPlayer", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;
            MySqlParameter spUsername = new MySqlParameter("pUserName", userName);
            MySqlParameter spPassword = new MySqlParameter("pPassword", password);

            com.Parameters.AddRange(new MySqlParameter[] {spUsername, spPassword});

            try
            {
                DataSet ds = _dg.GetDataSet(com);
                DataRow dr = ds.Tables[0].Rows[0];
                Player p = new Player();
                p.OBID = Convert.ToInt32(dr["OBID"]);
                p.LeaderName = Convert.ToString(dr["LeaderName"]);
                p.Race = Convert.ToString(dr["Race"]);
                p.Motto = Convert.ToString(dr["Motto"]);
                p.Color = Convert.ToString(dr["Color"]);

                p.Attributes = new List<OAttribute>();
                //p.Attributes.ParentObject = p;
                //p.Attributes.Load(LoadAttributes(ds.Tables[1]));

                res.Tag = p;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex) {
                res.ResultCode = -2;
                res.ResultMsg = String.Format ("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
コード例 #22
0
        public DBCommandResult SaveUniverse(Universe u)
        {
            DBCommandResult res = new DBCommandResult ();
            MySqlCommand com = new MySqlCommand ("GM_SaveUniverse",_dg.Connection);
            com.CommandType = CommandType.StoredProcedure;

            MySqlParameter spUniverseId = new MySqlParameter("pUID", u.OBID);
            MySqlParameter spTick = new MySqlParameter("pTick", u.CurrentTick);
            MySqlParameter spTurn = new MySqlParameter("pTurn", u.CurrentTurn);
            MySqlParameter spPeriod = new MySqlParameter("pPeriod", u.CurrentPeriod);

            com.Parameters.AddRange (new MySqlParameter[] {spUniverseId, spTick, spTurn, spPeriod});

            try
            {
                _dg.ExecuteCommand(com);
                res = SaveAttributes(u);
                res.Tag = u;
            }
            catch (Exception ex) {
                res.ResultCode = -2;
                res.ResultMsg = String.Format ("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
コード例 #23
0
ファイル: DBHelper.cs プロジェクト: GSazheniuk/HOO
        public DBCommandResult AddStar(Star s)
        {
            DBCommandResult res = new DBCommandResult();

            SqlCommand com = new SqlCommand("ADM.AddStar", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;

            SqlParameter spGalaxyId = new SqlParameter("@GalaxyId", s.GalaxyId);
            SqlParameter spSystemName = new SqlParameter("@SystemName", s.StarSystemName);
            SqlParameter spX = new SqlParameter("@X", s.Coordinates.X);
            SqlParameter spY = new SqlParameter("@Y", s.Coordinates.Y);
            SqlParameter spZ = new SqlParameter("@Z", s.Coordinates.Z);
            SqlParameter spClass = new SqlParameter("@Class", s.Class);
            SqlParameter spSize = new SqlParameter("@Size", s.Size);
            SqlParameter spTempLvl = new SqlParameter("@TempLvl", s.TemperatureLevel);

            com.Parameters.AddRange(new SqlParameter[] { spClass, spGalaxyId, spSize, spSystemName, spTempLvl, spX, spY, spZ });

            try
            {
                DataSet ds = _dg.GetDataSet(com);
                DataRow dr = ds.Tables[0].Rows[0];
                Star rs = new Star();
                rs.OBID = Convert.ToInt32(dr["OBID"]);
                rs.GalaxyId = s.GalaxyId;
                rs.StarSystemName = Convert.ToString(dr["SystemName"]);
                rs.Coordinates = new Core.Model.Configuration.Point3D();
                rs.Coordinates.X = Convert.ToInt32(dr["X"]);
                rs.Coordinates.Y = Convert.ToInt32(dr["Y"]);
                rs.Coordinates.Z = Convert.ToInt32(dr["Z"]);
                rs.Class = (StarClass)Convert.ToInt32(dr["Class"]);
                rs.Size = (StarSize)Convert.ToInt32(dr["Size"]);
                rs.TemperatureLevel = Convert.ToInt32(dr["TempLvl"]);
                res.Tag = rs;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex)
            {
                res.ResultCode = -2;
                res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, ex.InnerException.Message);
            }

            return res;
        }
コード例 #24
0
ファイル: MySqlDBHelper.cs プロジェクト: GSazheniuk/HOO
        public DBCommandResult AddStar(Star s)
        {
            DBCommandResult res = new DBCommandResult();
            string pref = "";
            string suff = "";

            switch (MrRandom.rnd.Next (4)) {
            case 0:
                pref = "";
                suff = "";
                break;
            case 1:
                pref = prefixes[MrRandom.rnd.Next(prefixes.Length)];
                suff = "";
                break;
            case 2:
                pref = "";
                suff = suffixes[MrRandom.rnd.Next(suffixes.Length)];
                break;
            case 3:
                pref = prefixes[MrRandom.rnd.Next(prefixes.Length)];
                suff = suffixes[MrRandom.rnd.Next(suffixes.Length)];
                break;
            }

            if (pref != "") {
            int x = MrRandom.rnd.Next (10);
                switch (x) {
                    case 0:
                    case 1:
                    case 2:
                    case 3:
                    pref = pref + "-" + (x + 1).ToString ();
                    break;
                }
                pref += " ";
            }

            if (suff != "")
                suff = " " + suff;

            MySqlCommand com = new MySqlCommand("ADM_AddStar", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;

            MySqlParameter spGalaxyId = new MySqlParameter("pGalaxyId", s.GalaxyId);
            MySqlParameter spX = new MySqlParameter("pX", s.Coordinates.X);
            MySqlParameter spY = new MySqlParameter("pY", s.Coordinates.Y);
            MySqlParameter spZ = new MySqlParameter("pZ", s.Coordinates.Z);
            MySqlParameter spClass = new MySqlParameter("pClass", s.Class);
            MySqlParameter spSize = new MySqlParameter("pSize", s.Size);
            MySqlParameter spTempLvl = new MySqlParameter("pTempLvl", s.TemperatureLevel);

            MySqlParameter spPrefix = new MySqlParameter("pPrefix", pref);
            MySqlParameter spSuffix = new MySqlParameter("pSuffix", suff);

            com.Parameters.AddRange(new MySqlParameter[] { spClass, spGalaxyId, spSize, spTempLvl, spX, spY, spZ,spPrefix, spSuffix });

            try
            {
                DataSet ds = _dg.GetDataSet(com);
                DataRow dr = ds.Tables[0].Rows[0];
                Star rs = new Star();
                rs.OBID = Convert.ToInt32(dr["OBID"]);
                rs.GalaxyId = s.GalaxyId;
                rs.StarSystemName = Convert.ToString(dr["SystemName"]);
                rs.Coordinates = new Core.Model.Configuration.Point3D();
                rs.Coordinates.X = Convert.ToInt32(dr["X"]);
                rs.Coordinates.Y = Convert.ToInt32(dr["Y"]);
                rs.Coordinates.Z = Convert.ToInt32(dr["Z"]);
                rs.Class = (StarClass)Convert.ToInt32(dr["Class"]);
                rs.Size = (StarSize)Convert.ToInt32(dr["Size"]);
                rs.TemperatureLevel = Convert.ToInt32(dr["TempLvl"]);
                res.Tag = rs;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex)
            {
                res.ResultCode = -2;
                res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null)?ex.InnerException.Message:"");
            }

            return res;
        }
コード例 #25
0
ファイル: MySqlDBHelper.cs プロジェクト: GSazheniuk/HOO
        public DBCommandResult AddUniverse(Universe u)
        {
            DBCommandResult res = new DBCommandResult();

            MySqlCommand com = new MySqlCommand("ADM_AddUniverse", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;
            MySqlParameter spName = new MySqlParameter("pName", u.Name);
            MySqlParameter spDescrip = new MySqlParameter("pDescrip", u.Descrip);
            com.Parameters.Add(spName);
            com.Parameters.Add(spDescrip);
            try
            {
                DataSet ds = _dg.GetDataSet(com);
                DataRow dr = ds.Tables[0].Rows[0];
                Universe resU = new Universe();
                resU.OBID = Convert.ToInt32(dr["OBID"]);
                resU.Name = Convert.ToString(dr["Name"]);
                resU.Descrip = Convert.ToString(dr["Description"]);
                res.Tag = resU;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex)
            {
                res.ResultCode = -2;
                res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null)?ex.InnerException.Message:"");
            }
            return res;
        }
コード例 #26
0
ファイル: MySqlDBHelper.cs プロジェクト: GSazheniuk/HOO
        public DBCommandResult AddOrbitalBody(StarOrbitalBody sob)
        {
            DBCommandResult res = new DBCommandResult();

            if (sob is Planet)
            {
                Planet p = (Planet)sob;
                MySqlCommand com = new MySqlCommand("ADM_AddStarOrbitalBody", _dg.Connection);
                com.CommandType = CommandType.StoredProcedure;

                MySqlParameter spStarId = new MySqlParameter("pStarId", p.StarId);
                MySqlParameter spOrbitNo = new MySqlParameter("pOrbitNo", p.OrbitNo);
                MySqlParameter spBodyType = new MySqlParameter("pBodyType", 1);
                MySqlParameter spSize = new MySqlParameter("pSize", p.Size);
                MySqlParameter spType = new MySqlParameter("pClass", p.Type);

                com.Parameters.AddRange(new MySqlParameter[] { spStarId, spSize, spOrbitNo, spType, spBodyType });

                try
                {
                    DataSet ds = _dg.GetDataSet(com);
                    DataRow dr = ds.Tables[0].Rows[0];
                    Planet rp = new Planet(sob.StarId);
                    rp.OBID = Convert.ToInt32(dr["OBID"]);
                    rp.OrbitNo = Convert.ToInt32(dr["OrbitNo"]);
                    rp.Size = (PlanetSize)Convert.ToInt32(dr["Size"]);
                    rp.Type = (PlanetType)Convert.ToInt32(dr["Class"]);
                    res.Tag = rp;
                    res.ResultCode = 0;
                    res.ResultMsg = "Ok";
                }
                catch (Exception ex)
                {
                    res.ResultCode = -2;
                    res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null)?ex.InnerException.Message:"");
                }
                return res;
            }

            if (sob is GasGiant)
            {
                GasGiant p = (GasGiant)sob;
                MySqlCommand com = new MySqlCommand("ADM_AddStarOrbitalBody", _dg.Connection);
                com.CommandType = CommandType.StoredProcedure;

                MySqlParameter spStarId = new MySqlParameter("pStarId", p.StarId);
                MySqlParameter spOrbitNo = new MySqlParameter("pOrbitNo", p.OrbitNo);
                MySqlParameter spBodyType = new MySqlParameter("pBodyType", 2);
                MySqlParameter spSize = new MySqlParameter("pSize", p.Size);
                MySqlParameter spType = new MySqlParameter("pClass", p.Class);

                com.Parameters.AddRange(new MySqlParameter[] { spStarId, spSize, spOrbitNo, spType, spBodyType });

                try
                {
                    DataSet ds = _dg.GetDataSet(com);
                    DataRow dr = ds.Tables[0].Rows[0];
                    GasGiant rg = new GasGiant(sob.StarId);
                    rg.OBID = Convert.ToInt32(dr["OBID"]);
                    rg.OrbitNo = Convert.ToInt32(dr["OrbitNo"]);
                    rg.Class = (GasGiantClass)Convert.ToInt32(dr["Class"]);
                    rg.Size = (GasGiantSize)Convert.ToInt32(dr["Size"]);
                    res.Tag = rg;
                    res.ResultCode = 0;
                    res.ResultMsg = "Ok";
                }
                catch (Exception ex)
                {
                    res.ResultCode = -2;
                    res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null)?ex.InnerException.Message:"");
                }
                return res;
            }

            if (sob is AsteroidBelt)
            {
                AsteroidBelt p = (AsteroidBelt)sob;
                MySqlCommand com = new MySqlCommand("ADM_AddStarOrbitalBody", _dg.Connection);
                com.CommandType = CommandType.StoredProcedure;

                MySqlParameter spStarId = new MySqlParameter("pStarId", p.StarId);
                MySqlParameter spOrbitNo = new MySqlParameter("pOrbitNo", p.OrbitNo);
                MySqlParameter spBodyType = new MySqlParameter("pBodyType", 3);
                MySqlParameter spSize = new MySqlParameter("pSize", p.Density);
                MySqlParameter spType = new MySqlParameter("pClass", p.Type);

                com.Parameters.AddRange(new MySqlParameter[] { spStarId, spSize, spOrbitNo, spType, spBodyType });

                try
                {
                    DataSet ds = _dg.GetDataSet(com);
                    DataRow dr = ds.Tables[0].Rows[0];
                    AsteroidBelt ra = new AsteroidBelt(sob.StarId);
                    ra.OBID = Convert.ToInt32(dr["OBID"]);
                    ra.OrbitNo = Convert.ToInt32(dr["OrbitNo"]);
                    ra.Density = (AsteroidDensity)Convert.ToInt32(dr["Size"]);
                    ra.Type = (AsteroidType)Convert.ToInt32(dr["Class"]);

                    res.Tag = ra;
                    res.ResultCode = 0;
                    res.ResultMsg = "Ok";
                }
                catch (Exception ex)
                {
                    res.ResultCode = -2;
                    res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null)?ex.InnerException.Message:"");
                }
                return res;
            }
            return res;
        }
コード例 #27
0
        public DBCommandResult GetAllUniverses()
        {
            DBCommandResult res = new DBCommandResult ();

            MySqlCommand com = new MySqlCommand ("ADM_GetAllUniverses", _dg.Connection);

            try
            {
                DataSet ds = _dg.GetDataSet(com);
                List<Universe> unis = new List<Universe>();
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    Universe u = new Universe();
                    u.OBID = Convert.ToInt32(dr["OBID"]);
                    u.Descrip = Convert.ToString(dr["Description"]);
                    u.Name = Convert.ToString(dr["Name"]);
                    unis.Add(u);
                }
                res.Tag = unis;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex) {
                res.ResultCode = -2;
                res.ResultMsg = String.Format ("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
コード例 #28
0
        public DBCommandResult GetStarOrbitalBodies(Star s)
        {
            DBCommandResult res = new DBCommandResult ();

            MySqlCommand com = new MySqlCommand ("ADM_GetStarOrbitalBodies", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;
            MySqlParameter spStarId = new MySqlParameter("pStarId", s.OBID);
            com.Parameters.Add(spStarId);

            try
            {
                DataSet ds = _dg.GetDataSet(com);
                s.OrbitalBodies = new List<StarOrbitalBody>();

                foreach(DataRow dr in ds.Tables[0].Rows)
                {
                    switch (Convert.ToInt32(dr["BodyType"]))
                    {
                    case 1:
                        Planet p = new Planet(s._id);
                        p.OrbitNo = Convert.ToInt32(dr["OrbitNo"]);
                        p.Size = (PlanetSize)Convert.ToInt32(dr["Size"]);
                        p.Type = (PlanetType)Convert.ToInt32(dr["Class"]);
                        p.OBID = Convert.ToInt32(dr["OBID"]);
                        s.OrbitalBodies.Add(p);
                        break;
                    case 2:
                        GasGiant g = new GasGiant(s._id);
                        g.OrbitNo = Convert.ToInt32(dr["OrbitNo"]);
                        g.Size = (GasGiantSize)Convert.ToInt32(dr["Size"]);
                        g.Class = (GasGiantClass)Convert.ToInt32(dr["Class"]);
                        g.OBID = Convert.ToInt32(dr["OBID"]);
                        s.OrbitalBodies.Add(g);
                        break;
                    case 3:
                        AsteroidBelt a = new AsteroidBelt(s._id);
                        a.OrbitNo = Convert.ToInt32(dr["OrbitNo"]);
                        a.Density = (AsteroidDensity)Convert.ToInt32(dr["Size"]);
                        a.Type = (AsteroidType)Convert.ToInt32(dr["Class"]);
                        a.OBID = Convert.ToInt32(dr["OBID"]);
                        s.OrbitalBodies.Add(a);
                        break;
                    }
                }

                res.ResultCode = 0;
                res.ResultMsg = "Ok";
                res.Tag = s;
            }
            catch (Exception ex) {
                res.ResultCode = -2;
                res.ResultMsg = String.Format ("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
コード例 #29
0
        public DBCommandResult LoadUniverse(Universe u)
        {
            DBCommandResult res = new DBCommandResult();

            MySqlCommand com = new MySqlCommand("ADM_GetUniverseById", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;
            MySqlParameter spUID = new MySqlParameter("pId", u.OBID);
            com.Parameters.Add(spUID);
            try
            {
                DataSet ds = _dg.GetDataSet(com);
                DataRow dr = ds.Tables[0].Rows[0];
                Universe resU = new Universe();
                resU.OBID = Convert.ToInt32(dr["OBID"]);
                resU.Name = Convert.ToString(dr["Name"]);
                resU.Descrip = Convert.ToString(dr["Description"]);
                resU.CurrentTick = Convert.ToInt32(dr["CurrentTick"]);
                resU.CurrentTurn = Convert.ToInt32(dr["CurrentTurn"]);
                resU.CurrentPeriod = Convert.ToInt32(dr["CurrentPeriod"]);

                resU.Attributes = new List<OAttribute>();
                //resU.Attributes.ParentObject = resU;
                //resU.Attributes.Load(LoadAttributes(ds.Tables[1]));

                foreach (DataRow gRow in ds.Tables[2].Rows)
                {
                    Galaxy g = new Galaxy();
                    g.UniverseId = resU._id;
                    g.OBID = Convert.ToInt32(gRow["OBID"]);
                    g.Name = Convert.ToString(gRow["Name"]);
                    g.DimensionX = Convert.ToInt32(gRow["DimX"]);
                    g.DimensionY = Convert.ToInt32(gRow["DimY"]);
                    g.DimensionZ = Convert.ToInt32(gRow["DimZ"]);
                    resU.Galaxies.Add(g);
                }

                res.Tag = resU;
                res.ResultCode = 0;
                res.ResultMsg = "Ok";
            }
            catch (Exception ex)
            {
                res.ResultCode = -2;
                res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null)?ex.InnerException.Message:"");
            }
            return res;
        }