コード例 #1
0
        private Dictionary <string, int> _QueryEachDayChargeYB(DBManager dbMgr, string fromDate, string toDate, string userid, int zoneid)
        {
            Dictionary <string, int> result;

            if (dbMgr == null || string.IsNullOrEmpty(fromDate) || string.IsNullOrEmpty(toDate) || string.IsNullOrEmpty(userid))
            {
                result = null;
            }
            else
            {
                Dictionary <string, int> eachDayChargeYB = new Dictionary <string, int>();
                MySQLConnection          conn            = null;
                try
                {
                    string cmdText = string.Format("SELECT SUM(amount) as total,DATE_FORMAT(inputtime,'%Y-%m-%d') as inputdate FROM t_inputlog WHERE u='{0}' AND inputtime >='{1}' AND inputtime <= '{2}' AND zoneid={3} AND result='success' GROUP BY inputdate UNION ALL  SELECT SUM(amount) as total,DATE_FORMAT(inputtime,'%Y-%m-%d') as inputdate FROM t_inputlog2 WHERE u='{0}' AND inputtime >='{1}' AND inputtime <= '{2}' AND zoneid={3} AND result='success' GROUP BY inputdate", new object[]
                    {
                        userid,
                        fromDate,
                        toDate,
                        zoneid
                    });
                    GameDBManager.SystemServerSQLEvents.AddEvent(string.Format("+SQL: {0}", cmdText), EventLevels.Important);
                    conn = dbMgr.DBConns.PopDBConnection();
                    MySQLCommand cmd = new MySQLCommand(cmdText, conn);
                    try
                    {
                        MySQLDataReader reader = cmd.ExecuteReaderEx();
                        while (reader.Read())
                        {
                            string inputDate  = reader["inputdate"].ToString();
                            int    inputMoney = Convert.ToInt32(reader["total"].ToString());
                            if (!eachDayChargeYB.ContainsKey(inputDate))
                            {
                                eachDayChargeYB.Add(inputDate, inputMoney);
                            }
                            else
                            {
                                Dictionary <string, int> dictionary;
                                string key;
                                (dictionary = eachDayChargeYB)[key = inputDate] = dictionary[key] + inputMoney;
                            }
                        }
                    }
                    catch (MySQLException)
                    {
                        LogManager.WriteLog(LogTypes.Error, string.Format("读取数据库失败: {0}", cmdText), null, true);
                    }
                    cmd.Dispose();
                    cmd = null;
                }
                finally
                {
                    if (null != conn)
                    {
                        dbMgr.DBConns.PushDBConnection(conn);
                    }
                }
                result = eachDayChargeYB;
            }
            return(result);
        }
コード例 #2
0
 private void Read(ref List<string[]> result)
 {
     oraRD = cmd.ExecuteReaderEx();
     int n = oraRD.FieldCount;
     while (oraRD.Read())
     {
         string[] oneResult = new string[n];
         for (int i = 0; i < n; i++)
         {
             oneResult[i] = oraRD[i].ToString();
         }
         result.Add(oneResult);
     }
     oraRD.Close();
 }
コード例 #3
0
ファイル: Default.aspx.cs プロジェクト: cupid0426/MyProject
        protected void Page_Load(object sender, EventArgs e)
        {
            string strCategory = Request.QueryString["Category"].ToString();

            MySQLConnection conn = new MySQLConnection(new MySQLConnectionString("192.168.1.250", "discuz_bbs", "cupid", "qweqwe123").AsString);

            //Response.Write("Connecting to database");
            try
            {
                conn.Open();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
                return;
            }

            MySQLCommand cmd = new MySQLCommand("set names gb2312", conn);

            cmd.ExecuteNonQuery();

            if (strCategory == "1")
            {
                cmd = new MySQLCommand("SELECT fid,tid,author,subject,views FROM `cdb_threads` WHERE fid = 8 ORDER BY dateline DESC LIMIT 0,5", conn);
                //cmd = new MySQLCommand("SELECT fid,tid,author,subject,views FROM `pre_forum_thread` WHERE fid = 8 ORDER BY dateline DESC LIMIT 0,7", conn);
                MySQLDataReader reader = cmd.ExecuteReaderEx();
                while (reader.Read())
                {
                    //Response.Write(string.Format("{0}---{1}---{2}---{3}<br>", reader["tid"], reader["author"], reader["subject"].ToString().Replace("??", "--"), reader["views"]));
                    sb.Append(string.Format("<a target=\"_blank\" title=\"{1}\" href=\"http://192.168.1.250/viewthread.php?tid={0}&extra=page%3D1\">{2}{1}</a>\r\n", reader["tid"], reader["subject"].ToString().Replace("??", "--"), ShowFidName(reader["fid"])));
                    //sb.Append(string.Format("<a target=\"_blank\" title=\"{1}\" href=\"http://192.168.1.250/forum.php?mod=viewthread&tid={0}&extra=page%3D1\">{2}{1}</a>\r\n", reader["tid"], reader["subject"].ToString().Replace("??", "--"), ShowFidName(reader["fid"])));
                }
                strContent = sb.ToString();
                reader.Close();
                cmd.Dispose();
                conn.Close();
            }

            if (strCategory == "11")
            {
                cmd = new MySQLCommand("SELECT fid,tid,author,subject,views FROM `cdb_threads` WHERE fid = 8 ORDER BY dateline DESC LIMIT 5,5", conn);
                //cmd = new MySQLCommand("SELECT fid,tid,author,subject,views FROM `pre_forum_thread` WHERE fid = 8 ORDER BY dateline DESC LIMIT 7,7", conn);
                MySQLDataReader reader = cmd.ExecuteReaderEx();
                while (reader.Read())
                {
                    //Response.Write(string.Format("{0}---{1}---{2}---{3}<br>", reader["tid"], reader["author"], reader["subject"].ToString().Replace("??", "--"), reader["views"]));
                    sb.Append(string.Format("<a target=\"_blank\" title=\"{1}\" href=\"http://192.168.1.250/viewthread.php?tid={0}&extra=page%3D1\">{2}{1}</a>\r\n", reader["tid"], reader["subject"].ToString().Replace("??", "--"), ShowFidName(reader["fid"])));
                }
                strContent = sb.ToString();
                reader.Close();
                cmd.Dispose();
                conn.Close();
            }

            if (strCategory == "2")
            {
                cmd = new MySQLCommand("SELECT fid,tid,author,subject,views FROM `cdb_threads` WHERE fid not in (8,16,18) ORDER BY dateline DESC LIMIT 0,7", conn);
                //cmd = new MySQLCommand("SELECT fid,tid,author,subject,views FROM `pre_forum_thread` WHERE fid not in (8,16,18) ORDER BY dateline DESC LIMIT 0,7", conn);
                MySQLDataReader reader = cmd.ExecuteReaderEx();
                while (reader.Read())
                {
                    //Response.Write(string.Format("{0}---{1}---{2}---{3}<br>", reader["tid"], reader["author"], reader["subject"].ToString().Replace("??", "--"), reader["views"]));
                    sb.Append(string.Format("<a target=\"_blank\" title=\"{1}\" href=\"http://192.168.1.250/viewthread.php?tid={0}&extra=page%3D1\">{2}{1}</a>\r\n", reader["tid"], reader["subject"].ToString().Replace("??", "--"), ShowFidName(reader["fid"])));
                }
                strContent = sb.ToString();
                reader.Close();
                cmd.Dispose();
                conn.Close();
            }

            if (strCategory == "3")
            {
                cmd = new MySQLCommand("SELECT fid,tid,author,subject,views FROM `cdb_threads` WHERE fid not in (8,16,18) ORDER BY dateline DESC LIMIT 7,7", conn);
                //cmd = new MySQLCommand("SELECT fid,tid,author,subject,views FROM `pre_forum_thread` WHERE fid not in (8,16,18) ORDER BY dateline DESC LIMIT 7,7", conn);
                MySQLDataReader reader = cmd.ExecuteReaderEx();
                while (reader.Read())
                {
                    //Response.Write(string.Format("{0}---{1}---{2}---{3}<br>", reader["tid"], reader["author"], reader["subject"].ToString().Replace("??", "--"), reader["views"]));
                    sb.Append(string.Format("<a target=\"_blank\" title=\"{1}\" href=\"http://192.168.1.250/viewthread.php?tid={0}&extra=page%3D1\">{2}{1}</a>\r\n", reader["tid"], reader["subject"].ToString().Replace("??", "--"), ShowFidName(reader["fid"])));
                }
                strContent = sb.ToString();
                reader.Close();
                cmd.Dispose();
                conn.Close();
            }

            //huodong1
            if (strCategory == "4")
            {
                cmd = new MySQLCommand("SELECT fid,tid,author,subject,views FROM `cdb_threads` WHERE fid = 18 ORDER BY dateline DESC LIMIT 0,7", conn);
                //cmd = new MySQLCommand("SELECT fid,tid,author,subject,views FROM `pre_forum_thread` WHERE fid = 18 ORDER BY dateline DESC LIMIT 0,7", conn);
                MySQLDataReader reader = cmd.ExecuteReaderEx();
                while (reader.Read())
                {
                    //Response.Write(string.Format("{0}---{1}---{2}---{3}<br>", reader["tid"], reader["author"], reader["subject"].ToString().Replace("??", "--"), reader["views"]));
                    sb.Append(string.Format("<a target=\"_blank\" title=\"{1}\" href=\"http://192.168.1.250/viewthread.php?tid={0}&extra=page%3D1\">{2}{1}</a>\r\n", reader["tid"], reader["subject"].ToString().Replace("??", "--"), ShowFidName(reader["fid"])));
                }
                strContent = sb.ToString();
                reader.Close();
                cmd.Dispose();
                conn.Close();
            }

            //huodong2
            if (strCategory == "5")
            {
                cmd = new MySQLCommand("SELECT fid,tid,author,subject,views FROM `cdb_threads` WHERE fid = 18 ORDER BY dateline DESC LIMIT 7,7", conn);
                //cmd = new MySQLCommand("SELECT fid,tid,author,subject,views FROM `pre_forum_thread` WHERE fid = 18 ORDER BY dateline DESC LIMIT 7,7", conn);
                MySQLDataReader reader = cmd.ExecuteReaderEx();
                while (reader.Read())
                {
                    //Response.Write(string.Format("{0}---{1}---{2}---{3}<br>", reader["tid"], reader["author"], reader["subject"].ToString().Replace("??", "--"), reader["views"]));
                    sb.Append(string.Format("<a target=\"_blank\" title=\"{1}\" href=\"http://192.168.1.250/viewthread.php?tid={0}&extra=page%3D1\">{2}{1}</a>\r\n", reader["tid"], reader["subject"].ToString().Replace("??", "--"), ShowFidName(reader["fid"])));
                }
                strContent = sb.ToString();
                reader.Close();
                cmd.Dispose();
                conn.Close();
            }

            //MySQLCommand commn = new MySQLCommand("set names gb2312", conn);
            //commn.ExecuteNonQuery();
            //DataTable dt = new MySQLSelectCommand(conn, new string[] { "tid", "author", "subject", "views" }, new string[] { "cdb_threads" }, null, null, null, true, 0, 10, false).Table;
            //foreach (DataRow row in dt.Rows)
            //{
            //    Response.Write(string.Format("{0}---{1}---{2}---{3}", row["tid"], row["author"], row["subject"], row["views"]));
            //}
            //dt.Dispose();
            //commn.Dispose();
        }