当前位置: 首页>>代码示例>>C#>>正文


C# Database.CreateQuery方法代码示例

本文整理汇总了C#中db.Database.CreateQuery方法的典型用法代码示例。如果您正苦于以下问题:C# Database.CreateQuery方法的具体用法?C# Database.CreateQuery怎么用?C# Database.CreateQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在db.Database的用法示例。


在下文中一共展示了Database.CreateQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleRequest

 protected override void HandleRequest()
 {
     using (var db = new Database())
     {
         if (Account == null) BadLogin();
         else
         {
             var cmd = db.CreateQuery();
             cmd.CommandText = "SELECT fame FROM stats WHERE [email protected];";
             cmd.Parameters.AddWithValue("@accId", Account.AccountId);
             if ((int)cmd.ExecuteScalar() < 5000) WriteErrorLine("Not enough fame");
             else
             {
                 cmd = db.CreateQuery();
                 cmd.CommandText = "UPDATE stats set fame = MIN(fame - 5000, 0) WHERE [email protected];";
                 cmd.Parameters.AddWithValue("@accId", Account.AccountId);
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     cmd = db.CreateQuery();
                     cmd.CommandText = "UPDATE accounts SET maxCharSlot = maxCharSlot + 1 WHERE [email protected];";
                     cmd.Parameters.AddWithValue("@accId", Account.AccountId);
                     if (cmd.ExecuteNonQuery() > 0) Success();
                     else WriteErrorLine("Internal Error");
                 }
                 else WriteErrorLine("Internal Error");
             }
         }
     }
 }
开发者ID:BlackRayquaza,项目名称:PhoenixRealms,代码行数:29,代码来源:purchaseCharSlot.cs

示例2: HandleRequest

 protected override void HandleRequest()
 {
     using (var db = new Database())
     {
         var acc = db.Verify(Query["guid"], Query["password"]);
         byte[] status;
         if (acc == null)
         {
             status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>");
         }
         else
         {
             var cmd = db.CreateQuery();
             object exescala;
             cmd.CommandText = "SELECT COUNT(name) FROM accounts WHERE [email protected];";
             cmd.Parameters.AddWithValue("@name", Query["name"]);
             exescala = cmd.ExecuteScalar();
             if (int.Parse(exescala.ToString()) > 0)
                 status = Encoding.UTF8.GetBytes("<Error>Duplicated name</Error>");
             else
             {
                 cmd = db.CreateQuery();
                 cmd.CommandText = "UPDATE accounts SET [email protected], namechosen=TRUE WHERE [email protected];";
                 cmd.Parameters.AddWithValue("@accId", acc.AccountId);
                 cmd.Parameters.AddWithValue("@name", Query["name"]);
                 if (cmd.ExecuteNonQuery() != 0)
                     status = Encoding.UTF8.GetBytes("<Success />");
                 else
                     status = Encoding.UTF8.GetBytes("<Error>Internal error</Error>");
             }
         }
         Context.Response.OutputStream.Write(status, 0, status.Length);
     }
 }
开发者ID:BlackRayquaza,项目名称:MMOE,代码行数:34,代码来源:setName.cs

示例3: ParseContents

        private bool ParseContents(Account acc, string json)
        {
            try
            {
                using (var db = new Database())
                {
                    var code = GiftCode.FromJson(json);
                    if (code == null) return false;
                    var cmd = db.CreateQuery();

                    if (code.Gifts.Count > 0)
                    {
                        List<int> gifts = acc.Gifts;
                        foreach (var i in code.Gifts)
                            gifts.Add(i);

                        cmd = db.CreateQuery();
                        cmd.CommandText =
                            "UPDATE accounts SET [email protected] WHERE [email protected] AND password=SHA1(@password);";
                        cmd.Parameters.AddWithValue("@gifts", Utils.GetCommaSepString<int>(gifts.ToArray()));
                        cmd.Parameters.AddWithValue("@uuid", Query["guid"]);
                        cmd.Parameters.AddWithValue("@password", Query["password"]);
                        cmd.ExecuteNonQuery();
                    }

                    if (code.CharSlots > 0)
                    {
                        cmd = db.CreateQuery();
                        cmd.CommandText =
                            "UPDATE accounts SET maxCharSlot=maxCharSlot + @amount WHERE [email protected] AND password=SHA1(@password);";
                        cmd.Parameters.AddWithValue("@amount", code.CharSlots);
                        cmd.Parameters.AddWithValue("@uuid", Query["guid"]);
                        cmd.Parameters.AddWithValue("@password", Query["password"]);
                        cmd.ExecuteNonQuery();
                    }

                    if (code.VaultChests > 0)
                        for (int j = 0; j < code.VaultChests; j++)
                            db.CreateChest(acc);

                    if (code.Gold > 0)
                        db.UpdateCredit(acc, code.Gold);

                    if (code.Fame > 0)
                        db.UpdateFame(acc, code.Fame);
                }
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
开发者ID:SirAnuse,项目名称:fabiano-swagger-of-doom,代码行数:53,代码来源:redeemGiftCode.cs

示例4: IsUserInLegends

        public bool IsUserInLegends()
        {
            //Week
            using (var db = new Database())
            {
                var cmd = db.CreateQuery();
                cmd.CommandText = "SELECT * FROM death WHERE (time >= DATE_SUB(NOW(), INTERVAL 1 WEEK)) ORDER BY totalFame DESC LIMIT 10;";
                using (var rdr = cmd.ExecuteReader())
                    while (rdr.Read())
                        if (rdr.GetString("accId") == AccountId) return true;
            }

            //Month
            using (var db = new Database())
            {
                var cmd = db.CreateQuery();
                cmd.CommandText = "SELECT * FROM death WHERE (time >= DATE_SUB(NOW(), INTERVAL 1 MONTH)) ORDER BY totalFame DESC LIMIT 10;";
                using (var rdr = cmd.ExecuteReader())
                    while (rdr.Read())
                        if (rdr.GetString("accId") == AccountId) return true;
            }
            //All Time
            using (var db = new Database())
            {
                var cmd = db.CreateQuery();
                cmd.CommandText = "SELECT * FROM death WHERE TRUE ORDER BY totalFame DESC LIMIT 10;";
                using (var rdr = cmd.ExecuteReader())
                    while (rdr.Read())
                        if (rdr.GetString("accId") == AccountId) return true;
            }

            return false;
        }
开发者ID:SirAnuse,项目名称:fabiano-swagger-of-doom,代码行数:33,代码来源:Player.List.cs

示例5: HandleRequest

        public void HandleRequest(HttpListenerContext context)
        {
            NameValueCollection query;
            using (StreamReader rdr = new StreamReader(context.Request.InputStream))
                query = HttpUtility.ParseQueryString(rdr.ReadToEnd());

            using (var db = new Database())
            {
                var acc = db.Verify(query["guid"], query["password"]);
                byte[] status;
                if (acc == null)
                {
                    status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>");
                }
                else
                {
                    var cmd = db.CreateQuery();
                    cmd.CommandText = "UPDATE accounts SET password=SHA1(@password) WHERE [email protected];";
                    cmd.Parameters.AddWithValue("@accId", acc.AccountId);
                    cmd.Parameters.AddWithValue("@password", query["newPassword"]);
                    if (cmd.ExecuteNonQuery() > 0)
                        status = Encoding.UTF8.GetBytes("<Success />");
                    else
                        status = Encoding.UTF8.GetBytes("<Error>Internal error</Error>");
                }
                context.Response.OutputStream.Write(status, 0, status.Length);
            }
        }
开发者ID:rotmgkillroyx,项目名称:rotmg_svr_OLD,代码行数:28,代码来源:changePassword.cs

示例6: HandleRequest

        protected override void HandleRequest()
        {
            using (Database db = new Database())
            {
                string authKey = Database.GenerateRandomString(128);
                var cmd = db.CreateQuery();
                cmd.CommandText = "UPDATE accounts SET [email protected] WHERE [email protected];";
                cmd.Parameters.AddWithValue("@authToken", authKey);
                cmd.Parameters.AddWithValue("@email", Query["guid"]);
                if (cmd.ExecuteNonQuery() == 1)
                {
                    MailMessage message = new MailMessage();
                    message.To.Add(Query["guid"]);
                    message.Subject = "Forgot Password";
                    message.From = new MailAddress(Program.Settings.GetValue<string>("serverEmail", ""), "Forgot Passowrd");
                    message.Body = emailBody.
                        Replace("{RPLINK}", String.Format("{0}/{1}{2}", Program.Settings.GetValue<string>("serverDomain", "localhost"), "account/resetPassword?authToken=", authKey)).
                        Replace("{SUPPORTLINK}", String.Format("{0}", Program.Settings.GetValue<string>("supportLink", "localhost"))).
                        Replace("{SERVERDOMAIN}", Program.Settings.GetValue<string>("serverDomain", "localhost"));

                    Program.SendEmail(message, true);
                }
                else
                    using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream))
                        wtr.Write("<Error>Error.accountNotFound</Error>");
            }
        }
开发者ID:OryxAwakening,项目名称:Fabiano_Swagger_of_Doom,代码行数:27,代码来源:forgotPassword.cs

示例7: HandleRequest

        protected override void HandleRequest()
        {
            using (Database db = new Database())
            {
                Account acc = db.GetAccount(Query["accountId"], Program.GameData);
                Char chr = db.LoadCharacter(acc, int.Parse(Query["charId"]));

                MySqlCommand cmd = db.CreateQuery();
                cmd.CommandText = @"SELECT time, killer, firstBorn FROM death WHERE [email protected] AND [email protected];";
                cmd.Parameters.AddWithValue("@accId", Query["accountId"]);
                cmd.Parameters.AddWithValue("@charId", Query["charId"]);
                int time;
                string killer;
                bool firstBorn;
                using (MySqlDataReader rdr = cmd.ExecuteReader())
                {
                    rdr.Read();
                    time = Database.DateTimeToUnixTimestamp(rdr.GetDateTime("time"));
                    killer = rdr.GetString("killer");
                    firstBorn = rdr.GetBoolean("firstBorn");
                }

                using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream))
                    wtr.Write(chr.FameStats.Serialize(Program.GameData, acc, chr, time, killer, firstBorn));
            }
        }
开发者ID:SirAnuse,项目名称:fabiano-swagger-of-doom,代码行数:26,代码来源:fame.cs

示例8: HandleRequest

        public void HandleRequest(HttpListenerContext context)
        {
            NameValueCollection query;
            using (StreamReader rdr = new StreamReader(context.Request.InputStream))
                query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
            using (var db = new Database())
            {
                var acc = db.GetAccount(int.Parse(query["accountId"]));
                var chr = db.LoadCharacter(acc, int.Parse(query["charId"]));

                var cmd = db.CreateQuery();
                cmd.CommandText = @"SELECT time, killer, firstBorn FROM death WHERE [email protected] AND [email protected];";
                cmd.Parameters.AddWithValue("@accId", query["accountId"]);
                cmd.Parameters.AddWithValue("@charId", query["charId"]);
                int time;
                string killer;
                bool firstBorn;
                using (var rdr = cmd.ExecuteReader())
                {
                    rdr.Read();
                    time = Database.DateTimeToUnixTimestamp(rdr.GetDateTime("time"));
                    killer = rdr.GetString("killer");
                    firstBorn = rdr.GetBoolean("firstBorn");
                }

                using (StreamWriter wtr = new StreamWriter(context.Response.OutputStream))
                    wtr.Write(chr.FameStats.Serialize(acc, chr, time, killer, firstBorn));
            }
        }
开发者ID:lcnvdl,项目名称:rotmg-server,代码行数:29,代码来源:fame.cs

示例9: GetGlobalNews

        private List<globalNews_struct> GetGlobalNews(Database db)
        {
            List<globalNews_struct> ret = new List<globalNews_struct>();
            var cmd = db.CreateQuery();
            cmd.CommandText = "SELECT * FROM globalNews WHERE endTime >= now();";
            using (var rdr = cmd.ExecuteReader())
            {
                while (rdr.Read())
                {
                    ret.Add(new globalNews_struct
                    {
                        slot = rdr.GetInt32("slot"),
                        linkType = rdr.GetInt32("linkType"),
                        title = rdr.GetString("title"),
                        image = rdr.GetString("image"),
                        priority = rdr.GetInt32("priority"),
                        linkDetail = rdr.GetString("linkDetail"),
                        platform = rdr.GetString("platform"),
                        startTime = long.Parse(Database.DateTimeToUnixTimestamp(rdr.GetDateTime("startTime")).ToString() + "000"),
                        endTime = long.Parse(Database.DateTimeToUnixTimestamp(rdr.GetDateTime("endTime")).ToString() + "000")
                    });
                }
            }

            return ret;
        }
开发者ID:OryxAwakening,项目名称:Fabiano_Swagger_of_Doom,代码行数:26,代码来源:globalNews.cs

示例10: HandleRequest

        protected override void HandleRequest()
        {
            StreamWriter wtr = new StreamWriter(Context.Response.OutputStream);
            if (Query.AllKeys.Length > 0)
            {
                using (Database db = new Database())
                {
                    Account acc = db.Verify(Query["guid"], Query["password"], Program.GameData);

                    if (CheckAccount(acc, db, false))
                    {
                        foreach (ItemCostItem item in Prices)
                        {
                            if (item.Type == Query["skinType"] && item.Puchasable == 1)
                            {
                                if (!acc.OwnedSkins.Contains(int.Parse(Query["skinType"])))
                                {
                                    acc.OwnedSkins.Add(int.Parse(Query["skinType"]));
                                    db.UpdateCredit(acc, -item.Price);
                                    MySqlCommand cmd = db.CreateQuery();
                                    cmd.CommandText =
                                        "UPDATE accounts SET [email protected] WHERE [email protected] AND password=SHA1(@password)";
                                    cmd.Parameters.AddWithValue("@ownedSkins",
                                        Utils.GetCommaSepString(acc.OwnedSkins.ToArray()));
                                    cmd.Parameters.AddWithValue("@uuid", Query["guid"]);
                                    cmd.Parameters.AddWithValue("@password", Query["password"]);
                                    if (cmd.ExecuteNonQuery() == 0)
                                        wtr.WriteLine("<Error>Unable to purchase</Error>");
                                }
                            }
                        }
                    }
                }
            }
        }
开发者ID:SirAnuse,项目名称:fabiano-swagger-of-doom,代码行数:35,代码来源:purchaseSkin.cs

示例11: HandleRequest

        protected override void HandleRequest()
        {
            using (Database db = new Database())
            {
                Account acc = db.Verify(Query["guid"], Query["password"], Program.GameData);

                if (CheckAccount(acc, db))
                {
                    if (acc.VerifiedEmail || !Program.Settings.GetValue<bool>("verifyEmail")) return;
                    string authKey = Database.GenerateRandomString(128);
                    var cmd = db.CreateQuery();
                    cmd.CommandText = "UPDATE accounts SET [email protected], [email protected] WHERE [email protected];";
                    cmd.Parameters.AddWithValue("@newGuid", Query["newGuid"]);
                    cmd.Parameters.AddWithValue("@newAuthToken", authKey);
                    cmd.Parameters.AddWithValue("@oldGuid", Query["guid"]);
                    cmd.Parameters.AddWithValue("@password", Query["password"]);
                    cmd.ExecuteNonQuery();

                    MailMessage message = new MailMessage();
                    message.To.Add(Query["newGuid"]);
                    message.IsBodyHtml = true;
                    message.Subject = "Please verify your account.";
                    message.From = new MailAddress(Program.Settings.GetValue<string>("serverEmail", ""));
                    message.Body = "<center>Please verify your email via this <a href=\"" + Program.Settings.GetValue<string>("serverDomain", "localhost") + "/account/validateEmail?authToken=" + authKey + "\" target=\"_blank\">link</a>.</center>";
                    Program.SendEmail(message, true);
                }
            }
        }
开发者ID:OryxAwakening,项目名称:Fabiano_Swagger_of_Doom,代码行数:28,代码来源:changeEmail.cs

示例12: HandleRequest

        public override void HandleRequest(HttpListenerContext context)
        {
            NameValueCollection query;
            using (var rdr = new StreamReader(context.Request.InputStream))
                query = HttpUtility.ParseQueryString(rdr.ReadToEnd());

            using (var db = new Database(Program.Settings.GetValue("conn")))
            {
                Account acc = db.Verify(query["guid"], query["password"]);
                byte[] status;
                if (acc == null)
                    status = Encoding.UTF8.GetBytes("<Error>Account credentials not valid</Error>");
                else
                {
                    MySqlCommand cmd = db.CreateQuery();
                    cmd.CommandText = @"DELETE FROM characters WHERE accId = @accId AND charId = @charId;";
                    cmd.Parameters.AddWithValue("@accId", acc.AccountId);
                    cmd.Parameters.AddWithValue("@charId", query["charId"]);
                    if (cmd.ExecuteNonQuery() > 0)
                        status = Encoding.UTF8.GetBytes("<Success />");
                    else
                        status = Encoding.UTF8.GetBytes("<Error>Internal Error</Error>");
                }
                context.Response.OutputStream.Write(status, 0, status.Length);
            }
        }
开发者ID:Club559,项目名称:Travs-Domain-Server,代码行数:26,代码来源:delete.cs

示例13: HandleRequest

 protected override void HandleRequest()
 {
     using (var db = new Database())
     {
         if (!IsUsername(Query["newGUID"])) WriteErrorLine("Invalid Username");
         else
         {
             if (db.HasUuid(Query["guid"]) && db.Verify(Query["guid"], "") != null)
             {
                 if (db.HasUuid(Query["newGUID"])) WriteErrorLine("Username is already taken");
                 else
                 {
                     var cmd = db.CreateQuery();
                     cmd.CommandText = "UPDATE accounts SET [email protected], [email protected], password=SHA1(@password), guest=FALSE WHERE [email protected], [email protected];";
                     cmd.Parameters.AddWithValue("@uuid", Query["guid"]);
                     cmd.Parameters.AddWithValue("@newUuid", Query["newGUID"]);
                     cmd.Parameters.AddWithValue("@password", Query["newPassword"]);
                     if (cmd.ExecuteNonQuery() > 0) Success();
                     else WriteErrorLine("Internal Error");
                 }
             }
             else
             {
                 if (db.Register(Query["newGUID"], Query["newPassword"], false) != null) Success();
                 else WriteErrorLine("Internal Error");
             }
         }
     }
 }
开发者ID:BlackRayquaza,项目名称:PhoenixRealms,代码行数:29,代码来源:register.cs

示例14: HandleRequest

        protected override void HandleRequest()
        {
            using (Database db = new Database())
            {
                try
                {
                    Account acc = db.Verify(Query["guid"], Query["password"], Program.GameData);

                    string classType = Program.GameData.ObjectTypeToId[ushort.Parse(Query["classType"])];

                    if (CheckAccount(acc, db))
                    {
                        int price = Program.GameData.ObjectDescs[ushort.Parse(Query["classType"])].UnlockCost;
                        if (acc.Credits < price) return;
                        db.UpdateCredit(acc, -price);
                        MySqlCommand cmd = db.CreateQuery();
                        cmd.CommandText =
                            "UPDATE unlockedclasses SET available='unrestricted' WHERE [email protected] AND [email protected];";
                        cmd.Parameters.AddWithValue("@accId", acc.AccountId);
                        cmd.Parameters.AddWithValue("@class", classType);
                        cmd.ExecuteNonQuery();
                    }
                }
                catch (Exception e)
                {
                    using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream))
                    {
                        wtr.WriteLine("<Error>Invalid classType");
                        wtr.Flush();
                        wtr.WriteLine(e);
                    }
                }
            }
        }
开发者ID:SirAnuse,项目名称:fabiano-swagger-of-doom,代码行数:34,代码来源:purchaseClassUnlock.cs

示例15: HandleRequest

        public override void HandleRequest(HttpListenerContext context)
        {
            NameValueCollection query;
            using (var rdr = new StreamReader(context.Request.InputStream))
                query = HttpUtility.ParseQueryString(rdr.ReadToEnd());

            using (var db = new Database(Program.Settings.GetValue("conn")))
            {
                Account acc = db.Verify(query["guid"], query["password"]);
                byte[] status;
                if (acc == null)
                {
                    status = Encoding.UTF8.GetBytes("<Error>Account credentials not valid</Error>");
                }
                else
                {
                    MySqlCommand cmd = db.CreateQuery();
                    cmd.CommandText = "SELECT beginnerPackageTimeLeft FROM accounts WHERE [email protected]";
                    cmd.Parameters.AddWithValue("@uuid", query["guid"]);
                    object result = cmd.ExecuteScalar();

                    status = Encoding.UTF8.GetBytes("<BeginnerPackageTimeLeft>" + result + "</BeginnerPackageTimeLeft>");
                }
                context.Response.OutputStream.Write(status, 0, status.Length);
            }
        }
开发者ID:Club559,项目名称:Travs-Domain-Server,代码行数:26,代码来源:getBeginnerPackageTimeLeft.cs


注:本文中的db.Database.CreateQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。