Esempio n. 1
0
        public PasteCode selectPasteCodeById(int id)
        {
            init();
            con.Open();
            string sql = "select * from paste_code where "
                         + "id = " + id;

            System.Diagnostics.Debug.WriteLine(sql);
            MySQLCommand    cmd       = new MySQLCommand(sql, con);
            MySQLDataReader reader    = cmd.ExecuteReaderEx();
            PasteCode       pasteCode = new PasteCode();

            while (reader.Read())
            {
                pasteCode.id     = (int)reader[0];
                pasteCode.poster = reader[1].ToString();
                System.Diagnostics.Debug.WriteLine(pasteCode.poster);
                pasteCode.language = reader[2].ToString();
                System.Diagnostics.Debug.WriteLine(pasteCode.language);
                pasteCode.languagemode = reader[3].ToString();
                System.Diagnostics.Debug.WriteLine(pasteCode.languagemode);
                pasteCode.theme = reader[4].ToString();
                System.Diagnostics.Debug.WriteLine(pasteCode.theme);
                byte[] buf = (byte[])reader[5];
                pasteCode.code = System.Text.Encoding.UTF8.GetString(buf);
                System.Diagnostics.Debug.WriteLine(pasteCode.code);
                pasteCode.time = reader[6].ToString();
                System.Diagnostics.Debug.WriteLine(pasteCode.time);
            }
            con.Close();
            return(pasteCode);
        }
Esempio n. 2
0
        public bool IsBangHuiNameExist(string strBhName)
        {
            MySQLConnection conn = this._DBConns.PopDBConnection();
            bool            result;

            try
            {
                string          sql    = string.Format("SELECT * FROM t_banghui where bhname='{0}'", strBhName);
                MySQLCommand    cmd    = new MySQLCommand(sql, conn);
                MySQLDataReader reader = cmd.ExecuteReaderEx();
                if (reader.Read())
                {
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            catch (Exception ex)
            {
                result = true;
            }
            finally
            {
                this._DBConns.PushDBConnection(conn);
            }
            return(result);
        }
Esempio n. 3
0
   /// <summary>
   /// Gets the volunteer timestamps to an array.@deprecated Use getLastActiveTimestamp. unstable!!
   /// </summary>
   /// <param name="VolunteerID"></param>
   /// <param name="ACTIVE_ONLY"></param>
   /// <param name="ONLY_TODAY"></param>
   /// <returns>A 2 dimension array of timestamps or an empty array</returns>
       public object [][] getVolunteerTimestamps(uint VolunteerID,Boolean ACTIVE_ONLY=false,Boolean ONLY_TODAY=true){
        //Build Query
		string qry="SELECT * FROM Checkin WHERE VolunteerID="+VolunteerID;
		if(ACTIVE_ONLY==true)
			qry+=" AND Active=1";
		if(ONLY_TODAY==true)
			qry+=" AND DATE(TimeIn)=DATE(NOW())";
		qry+=" ORDER BY CheckID DESC;";
        //Query Data
         MySQLCommand mc = new MySQLCommand(qry, vlcon);
         MySQLDataReader dr = mc.ExecuteReaderEx();

         List<object>[] rval = { new List<object>(), new List<object>(), new List<object>(), new List<object>()};//data string list
         int cnt=0;
         try{
             while (dr.Read())
             {
                 for (byte curfield = 0; curfield < rval.Length; curfield++)
                 {
                     rval[curfield].Insert(cnt, dr.GetString(curfield));
                     Console.WriteLine(rval.GetValue(curfield).ToString());
                 }
                 cnt++;
             }
            }finally{
                dr.Close();
                mc.Dispose();
            }
            return new object[][]{rval[0].ToArray(),rval[1].ToArray(),rval[2].ToArray(),rval[3].ToArray()};
        }
        static void Main(string[] args)
        {
            conn = new MySQLConnection(new MySQLConnectionString("10.125.103.139", "heartlink", "qwe", "123").AsString);
            cmd  = new MySQLCommand();
            da   = new MySQLDataAdapter();

            String pass = "******";
            String sql  = "select ID from students where password="******"ID = {0}", DBReader.GetString(0));
                }
            }
            finally
            {
                DBReader.Close();
                conn.Close();
            }
        }
Esempio n. 5
0
        public User selectUserById(int id)
        {
            init();
            con.Open();
            string sql = "select * from user where "
                         + "id = " + id;

            System.Diagnostics.Debug.WriteLine(sql);
            MySQLCommand    cmd    = new MySQLCommand(sql, con);
            MySQLDataReader reader = cmd.ExecuteReaderEx();
            User            user   = new User();

            if (!reader.Read())
            {
                return(null);
            }
            else
            {
                user.id           = (int)reader[0];
                user.name         = (string)reader[1];
                user.password     = (string)reader[2];
                user.phone        = (string)reader[3];
                user.email        = (string)reader[4];
                user.registerTime = reader[5].ToString();
                user.isAdmin      = (int)reader[6];
                user.follow       = (int)reader[7];
                user.fans         = (int)reader[8];
                user.like         = (int)reader[9];
                user.collect      = (int)reader[10];
                user.comment      = (int)reader[11];
            }
            con.Close();
            return(user);
        }
Esempio n. 6
0
        public string ToClass(string str)
        {
            string          flag = "";
            MySQLConnection DBConn;

            DBConn = new MySQLConnection(new MySQLConnectionString(Form2.Ip, Form2.KuName, Form2.Username, Form2.Password, Form2.Port).AsString);
            DBConn.Open();
            MySQLCommand    DBComm   = new MySQLCommand("select CLASS from config", DBConn);
            MySQLDataReader DBReader = DBComm.ExecuteReaderEx();

            while (DBReader.Read())
            {
                flag   = DBReader.GetString(0);
                DBComm = new MySQLCommand("select keyword from config where CLASS='" + DBReader.GetString(0) + "'", DBConn);
                MySQLDataReader DBReader1 = DBComm.ExecuteReaderEx();
                if (DBReader1.Read())
                {
                    if (str.Contains(DBReader1.GetString(0)))
                    {
                        flag = DBReader.GetString(0);
                        DBConn.Close();
                        return(flag);
                    }
                }
            }
            DBConn.Close();
            return(flag);
        }
Esempio n. 7
0
        public static string GetAward(DBManager dbMgr, int zoneID, int roleID)
        {
            string          result = "";
            MySQLConnection conn   = null;

            try
            {
                conn = dbMgr.DBConns.PopDBConnection();
                string          cmdText = string.Format("SELECT type,state FROM t_spread_award WHERE zoneID = '{0}' AND roleID = '{1}'", zoneID, roleID);
                MySQLCommand    cmd     = new MySQLCommand(cmdText, conn);
                MySQLDataReader reader  = cmd.ExecuteReaderEx();
                while (reader.Read())
                {
                    if (result != "")
                    {
                        result += "$";
                    }
                    result  = result + reader["type"].ToString() + "#";
                    result += reader["state"].ToString();
                }
                GameDBManager.SystemServerSQLEvents.AddEvent(string.Format("+SQL: {0}", cmdText), EventLevels.Important);
                cmd.Dispose();
            }
            finally
            {
                if (null != conn)
                {
                    dbMgr.DBConns.PushDBConnection(conn);
                }
            }
            return(result);
        }
Esempio n. 8
0
        /*public int ConMysql()
         * {
         *  MySQLConnection DBConn;
         *  DBConn = new MySQLConnection(new MySQLConnectionString(Form2.Ip, Form2.KuName, Form2.Username, Form2.Password, Form2.Port).AsString);
         *  DBConn.Open();
         *  return 0;
         * }
         *
         * public int CloseMysql(MySQLConnection DBConn)
         * {
         *  DBConn.Close();
         *  return 0;
         * }*/

        public static int Joinclass()
        {
            if (Form3.key != "")
            {
                MySQLConnection DBConn;
                DBConn = new MySQLConnection(new MySQLConnectionString(Form2.Ip, Form2.KuName, Form2.Username, Form2.Password, Form2.Port).AsString);
                DBConn.Open();
                MySQLCommand    DBComm   = new MySQLCommand("select CLASS from config where CLASS='" + Form3.cla + "'", DBConn);
                MySQLDataReader DBReader = DBComm.ExecuteReaderEx();
                if (!DBReader.Read())
                {
                    DBComm = new MySQLCommand("insert into config(CLASS) values('" + Form3.cla + "')", DBConn);
                    DBComm.ExecuteNonQuery();
                }
                else if (Form3.cla != DBReader.GetString(0))
                {
                    DBComm = new MySQLCommand("insert into config(CLASS) values('" + Form3.cla + "')", DBConn);
                    DBComm.ExecuteNonQuery();
                }
                DBComm = new MySQLCommand("update config set keyword='" + Form3.key + "' where CLASS='" + Form3.cla + "'", DBConn);
                DBComm.ExecuteNonQuery();
                DBConn.Close();
            }
            return(0);
        }
Esempio n. 9
0
        private void button1_Click(object sender, EventArgs e)
        {
            string search = textBox1.Text;

            try
            {
                MySQLConnection DBConn;
                DBConn = new MySQLConnection(new MySQLConnectionString(Form2.Ip, Form2.KuName, Form2.Username, Form2.Password, Form2.Port).AsString);
                DBConn.Open();

                //清空数据
                dataGridView1.Rows.Clear();

                int i = 0;

                MySQLCommand    DBComm   = new MySQLCommand("select id,DATE,IP,URL,CLASS,MD5 from xls where URL like '%" + search + "%'", DBConn);
                MySQLDataReader DBReader = DBComm.ExecuteReaderEx();
                while (DBReader.Read())
                {
                    i = dataGridView1.Rows.Add();
                    dataGridView1.Rows[i].Cells[0].Value = DBReader.GetString(0);
                    dataGridView1.Rows[i].Cells[1].Value = DBReader.GetString(1);
                    dataGridView1.Rows[i].Cells[2].Value = DBReader.GetString(2);
                    dataGridView1.Rows[i].Cells[3].Value = DBReader.GetString(3);
                    dataGridView1.Rows[i].Cells[4].Value = DBReader.GetString(4);
                    dataGridView1.Rows[i].Cells[5].Value = DBReader.GetString(5);
                }
                DBConn.Close();
            }
            catch (MySQLException)
            {
                MessageBox.Show("请先连接数据库!");
            }
        }
Esempio n. 10
0
        public void Grview(string str)
        {
            try
            {
                MySQLConnection DBConn;
                DBConn = new MySQLConnection(new MySQLConnectionString(Form2.Ip, Form2.KuName, Form2.Username, Form2.Password, Form2.Port).AsString);
                DBConn.Open();

                //清空数据
                dataGridView1.Rows.Clear();

                int i = 0;

                MySQLCommand    DBComm   = new MySQLCommand("select id,DATE,IP,URL,CLASS,MD5 from xls where CLASS='" + str + "'", DBConn);
                MySQLDataReader DBReader = DBComm.ExecuteReaderEx();
                while (DBReader.Read())
                {
                    i = dataGridView1.Rows.Add();
                    dataGridView1.Rows[i].Cells[0].Value = DBReader.GetString(0);
                    dataGridView1.Rows[i].Cells[1].Value = DBReader.GetString(1);
                    dataGridView1.Rows[i].Cells[2].Value = DBReader.GetString(2);
                    dataGridView1.Rows[i].Cells[3].Value = DBReader.GetString(3);
                    dataGridView1.Rows[i].Cells[4].Value = DBReader.GetString(4);
                    dataGridView1.Rows[i].Cells[5].Value = DBReader.GetString(5);
                }
                DBConn.Close();
            }
            finally { }
        }
Esempio n. 11
0
        private void sure_Click(object sender, EventArgs e)
        {
            DBConn.Open();
            MySQLCommand DBComm   = new MySQLCommand("select * from `parkingsystem`.`manager`", DBConn);
            MySQLCommand firstCmd = new MySQLCommand("set names big5", DBConn);

            firstCmd.ExecuteNonQuery();
            MySQLDataReader DBReader = DBComm.ExecuteReaderEx();
            bool            error    = true;

            DBReader.Read();
            do
            {
                string id       = ("" + DBReader.GetValue(0)); //id
                string passoord = ("" + DBReader.GetValue(2)); //password

                string enter = System.DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss");
                if (tB_id.Text == id && tB_password.Text == passoord)
                {
                    error = false;
                    MySQLCommand    DBCom     = new MySQLCommand("INSERT INTO `parkingsystem`.`login_record` (`date`,`id`,`result`)VALUES ('" + enter + "','" + tB_id.Text + "','" + "帳密正確" + "');", DBConn);
                    MySQLDataReader DBReader1 = DBCom.ExecuteReaderEx();
                    this.Close();
                }
            } while (DBReader.Read());
            if (error)
            {
                MessageBox.Show("登錄檔作業失敗!! =" + "\r\n" + "帳號或密碼有錯!請再確認");
            }
        }
Esempio n. 12
0
 public MySQLDataReader ExecuteReader(string sql, params MySQLParameter[] cmdParms)
 {
     try
     {
         if (this._MySQLDataReader != null && !this._MySQLDataReader.IsClosed)
         {
             this._MySQLDataReader.Close();
             this._MySQLDataReader = null;
         }
         using (MySQLCommand cmd = new MySQLCommand(sql, this.DbConn))
         {
             if (cmdParms.Length > 0)
             {
                 MyDbConnection3.PrepareCommand(cmd, this.DbConn, null, sql, cmdParms);
             }
             MySQLDataReader myReader = cmd.ExecuteReaderEx();
             if (cmdParms.Length > 0)
             {
                 cmd.Parameters.Clear();
             }
             this._MySQLDataReader = myReader;
             this.LogSql(sql);
             return(myReader);
         }
     }
     catch (Exception ex)
     {
         LogManager.WriteLog(LogTypes.Exception, string.Format("执行SQL异常: {0}\r\n{1}", sql, ex.ToString()), null, true);
         LogManager.WriteLog(LogTypes.Error, string.Format("写入数据库失败: {0}", sql), null, true);
     }
     return(null);
 }
Esempio n. 13
0
        private MySQLDataReader ExecSelect(string sql)
        {
            MySQLConnection conn = null;
            MySQLDataReader result;

            try
            {
                conn = DBManager.getInstance().DBConns.PopDBConnection();
                MySQLCommand cmd = new MySQLCommand(sql, conn);
                GameDBManager.SystemServerSQLEvents.AddEvent(string.Format("+SQL: {0}", sql), EventLevels.Important);
                MySQLDataReader reader = cmd.ExecuteReaderEx();
                cmd.Dispose();
                result = reader;
            }
            catch (Exception ex)
            {
                LogManager.WriteException(ex.Message);
                result = null;
            }
            finally
            {
                if (null != conn)
                {
                    DBManager.getInstance().DBConns.PushDBConnection(conn);
                }
            }
            return(result);
        }
Esempio n. 14
0
        public void CheckPassword()
        {
            // 檢查帳密正確性
            // 權限設定還沒寫
            DBConn.Open();
            MySQLCommand DBComm   = new MySQLCommand("select * from `RFID_Project`.`user`", DBConn);
            MySQLCommand firstCmd = new MySQLCommand("set names big5", DBConn);

            firstCmd.ExecuteNonQuery();
            MySQLDataReader DBReader = DBComm.ExecuteReaderEx();
            bool            error    = true;

            DBReader.Read();
            do
            {
                string id       = ("" + DBReader.GetValue(0)); //id
                string passoord = ("" + DBReader.GetValue(1)); //password

                string enter = System.DateTime.Now.ToString("yyyy/MM/dd/ HH:mm:ss");
                if (tB_Id.Text == id && tB_Password.Text == passoord)
                {
                    error = false;
                    MySQLCommand    DBCom     = new MySQLCommand("INSERT INTO `RFID_Project`.`login_record` (`date`,`id`,`result`)VALUES ('" + enter + "','" + tB_Id.Text + "','" + "success" + "');", DBConn); //登錄記錄
                    MySQLDataReader DBReader1 = DBCom.ExecuteReaderEx();
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            } while (DBReader.Read());
            if (error)
            {
                MessageBox.Show("登錄檔作業失敗!! " + "\r\n" + "帳號或密碼有錯!請再確認");
            }
            DBConn.Close();
        }
Esempio n. 15
0
        private void timer4_Tick(object sender, EventArgs e)
        {
            DBConn.Open();
            MySQLCommand DBComm   = new MySQLCommand("select * from `parkingsystem`.`login_record`", DBConn);
            MySQLCommand firstCmd = new MySQLCommand("set names big5", DBConn);

            firstCmd.ExecuteNonQuery();
            MySQLDataReader DBReader = DBComm.ExecuteReaderEx();

            DBReader.Read();
            do
            {
                if (DBReader.GetString(2) == "帳密正確")
                {
                    tSB_Exit.Enabled    = true;
                    tSB_search.Enabled  = true;
                    TSMI_help.Enabled   = true;
                    tabControl1.Enabled = true;
                    MySQLCommand    DBCom     = new MySQLCommand("UPDATE `parkingsystem`.`login_record` SET `result` = '成功登入' WHERE CONVERT( `login_record`.`date` USING utf8 ) = '" + DBReader.GetString(0) + "' LIMIT 1 ;", DBConn);
                    MySQLDataReader DBReader1 = DBCom.ExecuteReaderEx();
                    timer4.Enabled = false;
                    break;
                }
            } while (DBReader.Read());
            DBConn.Close();
        }
Esempio n. 16
0
        public int validarUsuario(string u, string c)
        {
            int    cont      = 0;
            String CadenaSql = "select count(1) as cont from usuario where usuario = '" + u + "' and clave = md5('" + c + "')";

            try
            {
                MySQLDataReader ds;
                MySQLCommand    query;
                cnn.Open();
                query = new MySQLCommand(CadenaSql, cnn);
                ds    = query.ExecuteReaderEx();

                ds.Read();
                cont = int.Parse(ds.GetValue(0).ToString());
            }
            catch (MySQLException e)
            {
                System.Console.WriteLine(e.Message.ToString());
            }
            finally
            {
                cnn.Close();
            }
            return(cont);
        }
Esempio n. 17
0
        public static List <string> Query()
        {
            List <string> ret = new List <string>();

            lock (conn)
            {
                try
                {
                    MySQLCommand commn;
                    commn = new MySQLCommand("create table if not exists monsqldb (text varchar(1000))", conn);
                    commn.ExecuteNonQuery();
                    commn = new MySQLCommand("select text from monsqldb", conn);
                    MySQLDataReader mdr = commn.ExecuteReaderEx();
                    while (mdr.Read())
                    {
                        ret.Add(mdr.GetString(0));
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("数据库访问出错:" + ex.Message);
                }
            }
            return(ret);
        }
Esempio n. 18
0
        //显示数据按钮
        private void button4_Click_1(object sender, EventArgs e)
        {
            MySQLConnection myconn = null;

            myconn = new MySQLConnection(new MySQLConnectionString("localhost", "water", "root", "root", 3306).AsString);

            try {
                myconn.Open();  //打开连接
                MySQLCommand cmd = new MySQLCommand("select * from waterinfor", myconn);

                //cmd.ExecuteNonQuery();
                MySQLDataReader sdr = cmd.ExecuteReaderEx();

                while (sdr.Read())
                {
                    //构建一个ListView的数据,存入数据库数据,以便添加到listView1的行数据中
                    ListViewItem lt = new ListViewItem();
                    //将数据库数据转变成ListView类型的一行数据
                    lt.Text = sdr["id"].ToString();
                    lt.SubItems.Add(sdr["time"].ToString());
                    lt.SubItems.Add(sdr["place"].ToString());
                    // lt.SubItems.Add(sdr.GetString ( 2 ));
                    lt.SubItems.Add(sdr["value"].ToString());
                    // Console.WriteLine(st);
                    //  Console.WriteLine(System.Text.Encoding.Default.EncodingName);
                    //将lt数据添加到listView1控件中
                    listView1.Items.Add(lt);
                }
                myconn.Close();
                sdr.Close();
            }
            catch {
                myconn.Close();
            }
        }
Esempio n. 19
0
        public int contarEstudiantes()
        {
            int    cont      = 0;
            String CadenaSql = "select count(1) from estudiante ";

            try
            {
                MySQLDataReader ds;
                MySQLCommand    query;
                cnn.Open();
                query = new MySQLCommand(CadenaSql, cnn);
                ds    = query.ExecuteReaderEx();

                ds.Read();
                cont = int.Parse(ds.GetValue(0).ToString());
            }
            catch (MySQLException e)
            {
                System.Console.WriteLine(e.Message.ToString());
            }
            finally
            {
                cnn.Close();
            }
            return(cont);
        }
Esempio n. 20
0
        public int insertNewPasteCode(PasteCode pasteCode)
        {
            init();
            con.Open();
            string sql = "insert into paste_code value(null,"
                         + "\"" + pasteCode.poster + "\","
                         + "\"" + pasteCode.language + "\","
                         + "\"" + pasteCode.languagemode + "\","
                         + "\"" + pasteCode.theme + "\","
                         + "\"" + pasteCode.code + "\","
                         + "\"" + pasteCode.time + "\")";

            System.Diagnostics.Debug.WriteLine(sql);
            MySQLCommand cmd = new MySQLCommand(sql, con);

            cmd.ExecuteNonQuery();
            sql = "select id from paste_code where "
                  + "poster = " + "\"" + pasteCode.poster + "\" && "
                  + "time = " + "\"" + pasteCode.time + "\"";
            System.Diagnostics.Debug.WriteLine(sql);
            cmd = new MySQLCommand(sql, con);
            MySQLDataReader reader = cmd.ExecuteReaderEx();
            int             id     = 0;

            while (reader.Read())
            {
                id = (int)reader[0];
            }
            con.Close();
            return(id);
        }
Esempio n. 21
0
        public Dictionary <string, object> selectCommentByArticleId(int id)
        {
            init();
            con.Open();
            string sql = "select a.*,b.name from comment_list a right join user b on a.user_id = b.id "
                         + "where a.article_id = " + id;

            System.Diagnostics.Debug.WriteLine(sql);
            MySQLCommand    cmd       = new MySQLCommand(sql, con);
            MySQLDataReader reader    = cmd.ExecuteReaderEx();
            List <Comment>  comments  = new List <Comment>();
            List <string>   usernames = new List <string>();

            while (reader.Read())
            {
                comments.Add(new Comment((int)reader[0],
                                         (int)reader[1],
                                         (int)reader[2],
                                         encode.numToString(System.Text.Encoding.UTF8.GetString((byte[])reader[3])),
                                         reader[4].ToString()));
                usernames.Add((string)reader[5]);
            }
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("comments", comments);
            dic.Add("usernames", usernames);
            con.Close();
            return(dic);
        }
Esempio n. 22
0
        private void timer5_Tick(object sender, EventArgs e)
        {
            DBConn.Open();
            MySQLCommand DBComm   = new MySQLCommand("select * from `parkingsystem`.`record`", DBConn);
            MySQLCommand firstCmd = new MySQLCommand("set names big5", DBConn);

            firstCmd.ExecuteNonQuery();
            MySQLDataReader DBReader = DBComm.ExecuteReaderEx();
            bool            s        = true;

            while (DBReader.Read())
            {
                if (DBReader.GetString(2) == "E" || DBReader.GetString(2) == "")
                {
                    tSSL_C.Text = "開啟";
                    s           = false;
                    break;
                }
            }
            if (s)
            {
                tSSL_C.Text = "關閉";
            }
            DBConn.Close();
        }
        private JieriRecvKingItemData QueryRoleJieriRecvKing(DBManager dbMgr, string fromDate, string toDate, int roleID)
        {
            JieriRecvKingItemData result = null;
            MySQLConnection       conn   = null;

            try
            {
                conn = dbMgr.DBConns.PopDBConnection();
                string          cmdText = "SELECT t_roles.rid, t_roles.rname, t_roles.zoneid, x.totalrecv from t_roles,  (SELECT t_jierizengsong.receiver, SUM(t_jierizengsong.goodscnt) AS totalrecv " + string.Format(" FROM t_jierizengsong WHERE t_jierizengsong.receiver={0} AND sendtime>= '{1}' AND sendtime<='{2}') x ", roleID, fromDate, toDate) + " where t_roles.isdel=0 and t_roles.rid = x.receiver ";
                MySQLCommand    cmd     = new MySQLCommand(cmdText, conn);
                MySQLDataReader reader  = cmd.ExecuteReaderEx();
                if (reader.Read())
                {
                    result           = new JieriRecvKingItemData();
                    result.RoleID    = Convert.ToInt32(reader["rid"].ToString());
                    result.Rolename  = reader["rname"].ToString();
                    result.ZoneID    = Convert.ToInt32(reader["zoneid"].ToString());
                    result.TotalRecv = Convert.ToInt32(reader["totalrecv"].ToString());
                    result.Rank      = -1;
                }
                GameDBManager.SystemServerSQLEvents.AddEvent(string.Format("+SQL: {0}", cmdText), EventLevels.Important);
                cmd.Dispose();
            }
            finally
            {
                if (null != conn)
                {
                    dbMgr.DBConns.PushDBConnection(conn);
                }
            }
            return(result);
        }
Esempio n. 24
0
        RequestBean getNextRequest()
        {
            Monitor.Enter(this);

            RequestBean bean = null;

            int    modenId  = -1;
            string portName = null;

            for (int i = 0; i < portNameDataGridView.RowCount - 1; i++)
            {
                if ("free" == (string)portNameDataGridView.Rows [i].Cells [1].Value)
                {
                    portName = (string)portNameDataGridView.Rows [i].Cells [0].Value;
                    modenId  = i;
                    break;
                }
            }

            bean          = new RequestBean();
            bean.modenId  = modenId;
            bean.portName = portName;
            bean.batchId  = 1;
            bean.mobileId = 1;
            bean.mobile   = "18601345193";

            Monitor.Exit(this);
            return(bean);

            if (modenId != -1 && portName != null)
            {
                MySQLConnection conn = getConn();

                string       sqlstr = "select * from ring_request where doing=0 order by priority desc,time limit 1";
                MySQLCommand comm   = new MySQLCommand(sqlstr, conn);

                MySQLDataReader dbReader = comm.ExecuteReaderEx();
                if (dbReader.Read())
                {
                    portNameDataGridView.Rows [modenId].Cells [1].Value = "准备中.....";

                    string       sqlstr2 = "update ring_request set doing=1 where id=" + dbReader.GetInt32(0);
                    MySQLCommand comm2   = new MySQLCommand(sqlstr2, conn);
                    comm2.ExecuteNonQuery();

                    bean          = new RequestBean();
                    bean.modenId  = modenId;
                    bean.portName = portName;
                    bean.batchId  = dbReader.GetInt32(1);
                    bean.mobileId = dbReader.GetInt32(0);
                    bean.mobile   = dbReader.GetString(2);
                }
                dbReader.Close();
            }


            Monitor.Exit(this);
            return(bean);
        }
Esempio n. 25
0
        /// <summary>
        /// 查询返回多个实例
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns>List<T>形式查询结果集s</returns>
        protected List <T> queryForList(string sql)
        {
            MySQLConnection conn = null;
            List <T>        list = null;

            try
            {
                conn = dbMgr.DBConns.PopDBConnection();

                MySQLCommand    cmd    = new MySQLCommand(sql, conn);
                MySQLDataReader reader = cmd.ExecuteReaderEx();

                int columnNum = reader.FieldCount;

                //list = new List<T>();

                while (reader.Read())
                {
                    //索引下标
                    int index = 0;

                    T obj = Activator.CreateInstance <T>();
                    for (int i = 0; i < columnNum; i++)
                    {
                        int    _index      = index++;
                        string columnName  = reader.GetName(_index);
                        Object columnValue = reader.GetValue(_index);

                        if (null == list)
                        {
                            list = new List <T>();
                        }

                        setValue(obj, columnName, columnValue);
                    }

                    list.Add(obj);
                }

                GameDBManager.SystemServerSQLEvents.AddEvent(string.Format("+SQL: {0}", sql), EventLevels.Important);

                cmd.Dispose();
                cmd = null;
            }
            catch (Exception e)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("查询数据库失败: {0},exception:{1}", sql, e));
                return(null);
            }
            finally
            {
                if (null != conn)
                {
                    dbMgr.DBConns.PushDBConnection(conn);
                }
            }

            return(list);
        }
        private Dictionary <int, int> _QueryEachAwardIdFlag(DBManager dbMgr, string fromDate, string toDate, string userid, int zoneId, string[] AwardIdArray)
        {
            Dictionary <int, int> result;

            if (dbMgr == null || string.IsNullOrEmpty(fromDate) || string.IsNullOrEmpty(toDate) || string.IsNullOrEmpty(userid) || AwardIdArray == null || AwardIdArray.Length == 0)
            {
                result = null;
            }
            else
            {
                Dictionary <int, int> eachAwardIdFlag = new Dictionary <int, int>();
                MySQLConnection       conn            = null;
                try
                {
                    string cmdText = string.Format("SELECT keystr,hasgettimes FROM t_huodongawarduserhist WHERE userid='{0}' AND activitytype={1} AND keystr LIKE '{2}%'", userid, 61, Global.GetHuoDongKeyString(fromDate, toDate));
                    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 extKey    = reader["keystr"].ToString();
                            int    awardFlag = Convert.ToInt32(reader["hasgettimes"].ToString());
                            int    awardId   = 0;
                            if (this._GetAwardIdByExtKey(extKey, out awardId))
                            {
                                int flag;
                                if (!eachAwardIdFlag.TryGetValue(awardId, out flag))
                                {
                                    eachAwardIdFlag[awardId] = awardFlag;
                                }
                                else
                                {
                                    eachAwardIdFlag[awardId] = (flag | awardFlag);
                                }
                            }
                        }
                    }
                    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 = eachAwardIdFlag;
            }
            return(result);
        }
Esempio n. 27
0
        protected Dictionary <object, T> queryForDictionary(string sql, string keyName)
        {
            MySQLConnection        conn          = null;
            Dictionary <object, T> objDictionary = null;

            try
            {
                conn = this.dbMgr.DBConns.PopDBConnection();
                MySQLCommand    cmd       = new MySQLCommand(sql, conn);
                MySQLDataReader reader    = cmd.ExecuteReaderEx();
                int             columnNum = reader.FieldCount;
                objDictionary = new Dictionary <object, T>();
                string[] nameArray = new string[columnNum];
                while (reader.Read())
                {
                    int    index = 0;
                    T      obj   = Activator.CreateInstance <T>();
                    object key   = null;
                    for (int i = 0; i < columnNum; i++)
                    {
                        int _index = index++;
                        if (null == nameArray[_index])
                        {
                            nameArray[_index] = reader.GetName(_index);
                        }
                        string columnName  = nameArray[_index];
                        object columnValue = reader.GetValue(_index);
                        this.setValue(obj, columnName, columnValue);
                        if (null != key)
                        {
                            if (keyName.Equals(reader.GetName(_index)) || keyName == reader.GetName(_index))
                            {
                                key = reader.GetValue(_index);
                            }
                        }
                    }
                    if (null != key)
                    {
                        objDictionary.Add(key, obj);
                    }
                }
                GameDBManager.SystemServerSQLEvents.AddEvent(string.Format("+SQL: {0}", sql), EventLevels.Important);
                cmd.Dispose();
            }
            catch (Exception)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("查询数据库失败: {0}", sql), null, true);
                return(null);
            }
            finally
            {
                if (null != conn)
                {
                    this.dbMgr.DBConns.PushDBConnection(conn);
                }
            }
            return(objDictionary);
        }
        private void button1_Click(object sender, EventArgs e)   //處理鍵
        {
            //更新異常事件為已處理
            MySQLCommand    DBComm   = new MySQLCommand("UPDATE `RFID_Project`.`event_record` SET `result` = 'y' WHERE CONVERT( `event_record`.`no` USING utf8 ) = '" + Global.no + "' LIMIT 1 ;", DBConn);
            MySQLDataReader DBReader = DBComm.ExecuteReaderEx();

            //關閉視窗
            this.Close();
        }
        public void Find()
        {
            //在異常事件記錄抓未處理資料出來
            DBConn.Open();
            MySQLCommand DBComm   = new MySQLCommand("select * from `RFID_Project`.`event_record`", DBConn);
            MySQLCommand firstCmd = new MySQLCommand("set names big5", DBConn);

            firstCmd.ExecuteNonQuery();
            MySQLDataReader DBReader = DBComm.ExecuteReaderEx();

            while (DBReader.Read())
            {
                if (DBReader.GetString(5) == Global.event_place && DBReader.GetString(3) == Global.event_stu && DBReader.GetString(7) == "n")  //依位置判斷未處理的異常事件
                {
                    tB_place.Text = DBReader.GetString(5);
                    tB_temp.Text  = DBReader.GetString(6);
                    tB_date.Text  = DBReader.GetString(1);
                    tB_time.Text  = DBReader.GetString(2);

                    Time = DBReader.GetString(2);
                    //抓學生資料
                    string          stu_id       = DBReader.GetString(3);
                    MySQLCommand    DBCom        = new MySQLCommand("select * from `RFID_Project`.`student`", DBConn);
                    MySQLDataReader DBReader_stu = DBCom.ExecuteReaderEx();
                    DBReader_stu.Read();
                    do
                    {
                        if (DBReader_stu.GetString(0) == stu_id)
                        {
                            tB_id.Text             = DBReader_stu.GetString(0);
                            tB_name.Text           = DBReader_stu.GetString(2);
                            tB_sex.Text            = DBReader_stu.GetString(5);
                            tB_tagId.Text          = DBReader_stu.GetString(1);
                            tB_class.Text          = DBReader_stu.GetString(6);
                            tB_CWHO.Text           = DBReader_stu.GetString(8);
                            tB_CTEL.Text           = DBReader_stu.GetString(9);
                            tB_address.Text        = DBReader_stu.GetString(7);
                            pB_photo.ImageLocation = DBReader_stu.GetString(4); //圖片

                            //抓老師資料
                            MySQLCommand    DBComT           = new MySQLCommand("select * from `RFID_Project`.`teacher`", DBConn);
                            MySQLDataReader DBReader_teacher = DBComT.ExecuteReaderEx();
                            DBReader_teacher.Read();
                            do
                            {
                                if (DBReader_teacher.GetString(2) == DBReader_stu.GetString(6))
                                {
                                    tB_teacher.Text = DBReader_teacher.GetString(1);
                                    tB_tTEL.Text    = DBReader_teacher.GetString(4);
                                }
                            } while (DBReader_teacher.Read());
                        }
                    } while (DBReader_stu.Read());
                    break;
                }
            }
        }
Esempio n. 30
0
        private void button1_Click(object sender, EventArgs e)
        {
            string choice;

            choice = comboBox1.Text;
            DBConn.Open();
            MySQLCommand firstCmd = new MySQLCommand("set names big5", DBConn);

            firstCmd.ExecuteNonQuery();

            MySQLCommand    DBComm;
            MySQLDataReader DBReader;

            switch (choice)
            {
            case "車場硬體設備":
                DBComm     = new MySQLCommand("select * from `parkingsystem`.`reader`", DBConn);
                DBReader   = DBComm.ExecuteReaderEx();
                Mshow.Text = ("");
                while (DBReader.Read())
                {
                    Mshow.Text += (" 編號: " + DBReader.GetValue(0));
                    Mshow.Text += (" 位置: " + DBReader.GetValue(1));
                    Mshow.Text += (" 購買日期: " + DBReader.GetValue(2));
                    Mshow.Text += (" 位置: " + DBReader.GetValue(3));
                    Mshow.Text += (" 購買價錢: " + DBReader.GetValue(4) + "\r\n");
                }
                break;

            case "車輛停放記錄":
                DBComm     = new MySQLCommand("select * from `parkingsystem`.`record`", DBConn);
                DBReader   = DBComm.ExecuteReaderEx();
                Mshow.Text = ("");
                while (DBReader.Read())
                {
                    Mshow.Text += (" 車號: " + DBReader.GetValue(1));
                    Mshow.Text += (" 進入日期: " + DBReader.GetValue(3));
                    Mshow.Text += (" 出去日期: " + DBReader.GetValue(4));
                    Mshow.Text += (" 消費經額: " + DBReader.GetValue(7) + "\r\n");
                }
                break;

            case "管理人員資料":
                DBComm     = new MySQLCommand("select * from `parkingsystem`.`manager`", DBConn);
                DBReader   = DBComm.ExecuteReaderEx();
                Mshow.Text = ("");
                while (DBReader.Read())
                {
                    Mshow.Text += (" 帳號: " + DBReader.GetValue(0));
                    Mshow.Text += (" 姓名: " + DBReader.GetValue(1));
                    Mshow.Text += (" 電話: " + DBReader.GetValue(4) + "\r\n");
                }
                break;
            }
            DBConn.Close();
        }
Esempio n. 31
0
        //�ΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡΡι��캯��
        public UserManager(string name)
            : base(name, 560, 300)
        {
            MySQLConnection obSql;
            string linkStr = new MySQLConnectionString("localhost", "flox", "root", "00", 3306).AsString;
            linkStr += ";Character Set=GBK";
            obSql = new MySQLConnection(linkStr);
            obSql.Open(); // ִ�в�ѯ���

            MessageBox.Show(linkStr, "���ӳɹ�");
            MySQLCommand obCommand = null;
            MySQLDataReader obReader = null;
            string str = "";
            try
            {
                obCommand = new MySQLCommand("select username from cdb_members", obSql);
                obReader = obCommand.ExecuteReaderEx();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ִ�д���");
            }
            if (obReader != null)
            {
                try
                {
                    str += obReader.FieldCount.ToString() + "\r\n";
                    while (obReader.Read())
                    {
                        for (int i = 0; i < obReader.FieldCount; i++)
                        {
                            string inputStr = obReader.GetString(i);

                            #region //note
                            ///Encoding inputCode = Encoding.GetEncoding("GBK");
                            ///Encoding outCode = Encoding.Unicode;
                            ///byte[] bta = inputCode.GetBytes(inputStr);
                            ///byte[] bta2 = Encoding.Convert(inputCode, outCode, bta);
                            ///string outStr = outCode.GetString(bta2);
                            #endregion

                            str += inputStr;
                        }
                        str += "\r\n";
                    }
                }
                finally
                {
                    obReader.Close();
                    obCommand.Dispose();
                    obSql.Close();
                }
            }
            MessageBox.Show(str, "�û��б�");
        }
        public static MySQLDataReader ExecuteReader(string SQLString, params MySQLParameter[] cmdParms)
        {
            MySQLConnection connection = new MySQLConnection(connectionString);
            MySQLCommand cmd = new MySQLCommand();
            MySQLDataReader myReader = null;
            try
            {
                PrepareCommand(cmd, connection, null, SQLString, cmdParms);
                myReader = cmd.ExecuteReaderEx();
                cmd.Parameters.Clear();
                return myReader;
            }
            catch (MySQLException e)
            {
                throw e;
            }
            finally
            {
                myReader.Close();
                cmd.Dispose();
                connection.Close();

            }
        }
        public static MySQLDataReader ExecuteReader(string strSQL)
        {
            MySQLConnection connection = new MySQLConnection(connectionString);
            MySQLCommand cmd = new MySQLCommand(strSQL, connection);
            MySQLDataReader myReader = null;
            try
            {
                connection.Open();
                MySQLDataAdapter command = new MySQLDataAdapter(strSQL, connection);
                MySQLCommand commn = new MySQLCommand("set names gbk", connection);
                myReader = cmd.ExecuteReaderEx();

                return myReader;
            }
            catch (MySQLException e)
            {
                throw e;
            }
            finally
            {
                myReader.Close();
            }
        }
        private int saveModel()
        {
            if (WFModelInst == null)
                return -3;
            else
            {
                try
                {
                    MySQLConnection DBConn = new MySQLConnection(new MySQLConnectionString(Configuration.getDBIp(), "workflow", Configuration.getDBUsername(), Configuration.getDBPassword()).AsString);
                    string checkSql = "select model_name from wf_model where model_name = '" + WFModelInst.WFModel_Name + "';";
                    DBConn.Open();
                    MySQLCommand mcd = new MySQLCommand(checkSql, DBConn);
                    MySQLDataReader DBReader = mcd.ExecuteReaderEx(); //DBComm.ExecuteReaderEx();
                    if (DBReader.Read())
                    {
                        return -1;
                    }
                    else
                    {
                        string insertSql = "insert into wf_model (model_name,model_type,owner) values ('" + WFModelInst.WFModel_Name + "','" + WFModelInst.WFModel_Type + "','" + WFModelInst.WFModel_Owner + "');";
                        try
                        {
                            MySQLCommand mcd2 = new MySQLCommand(insertSql, DBConn);
                            mcd2.ExecuteNonQuery();
                            return 0;
                        }
                        catch (Exception Ex)
                        {
                            return -2;

                        }
                    }
                }
                catch (MySQLException e) {
                    //MessageBox.Show("数据库连接失败,请检查网络连接或者数据库配置");
                    return -2;
                }
            }

        }
Esempio n. 35
0
 public bool CheckOnlineUser(int user_id)
 {
     try
     {
         con.Open();
         sql = "SELECT * FROM user_online WHERE user_id=" + user_id;
         MySQLCommand com = new MySQLCommand(sql, con);
         MySQLDataReader reader = com.ExecuteReaderEx();
         if (reader.Read())
             return true;
         else
             return false;
     }
     catch
     {
         return false;
     }
     finally
     {
         con.Close();
     }
 }
Esempio n. 36
0
        RequestBean getNextRequest()
        {
            Monitor.Enter (this);

            RequestBean bean = null;

            int modenId = -1;
            string portName = null;
            for (int i = 0; i < portNameDataGridView.RowCount - 1; i++) {
                if ("free" == (string)portNameDataGridView.Rows [i].Cells [1].Value) {

                    portName = (string)portNameDataGridView.Rows [i].Cells [0].Value;
                    modenId = i;
                    break;
                }
            }

            bean = new RequestBean ();
            bean.modenId = modenId;
            bean.portName = portName;
            bean.batchId = 1;
            bean.mobileId = 1;
            bean.mobile = "18601345193";

            Monitor.Exit (this);
            return bean;

            if (modenId != -1 && portName != null) {
                MySQLConnection conn = getConn ();

                string sqlstr = "select * from ring_request where doing=0 order by priority desc,time limit 1";
                MySQLCommand comm = new MySQLCommand (sqlstr, conn);

                MySQLDataReader dbReader = comm.ExecuteReaderEx ();
                if (dbReader.Read ()) {
                    portNameDataGridView.Rows [modenId].Cells [1].Value = "准备中.....";

                    string sqlstr2 = "update ring_request set doing=1 where id=" + dbReader.GetInt32 (0);
                    MySQLCommand comm2 = new MySQLCommand (sqlstr2, conn);
                    comm2.ExecuteNonQuery ();

                    bean = new RequestBean ();
                    bean.modenId = modenId;
                    bean.portName = portName;
                    bean.batchId = dbReader.GetInt32 (1);
                    bean.mobileId = dbReader.GetInt32 (0);
                    bean.mobile = dbReader.GetString (2);

                }
                dbReader.Close ();

            }

            Monitor.Exit (this);
            return bean;
        }
Esempio n. 37
0
        static void Main(string[] args)
        {
            //   while (true)
            //    {

                try
                {
                    StreamReader objReader = new StreamReader("setting.ini");
                    string sLine = "";
                    ArrayList arrText = new ArrayList();
                    while (sLine != null)
                    {
                        sLine = objReader.ReadLine();
                        if (sLine != null)
                            arrText.Add(sLine);
                    }
                    objReader.Close();
                   // foreach (string sOutput in arrText)
                   // dbconn = sOutput;
                    //MySQLConnection conn = new MySQLConnection(new MySQLConnectionString("192.168.234.129", "qqnotic", "toryzen", "q1w2e3r4").AsString);//实例化一个连接对象其中myquest为数据库名,root为数据库用户名,amttgroup为数据库密码
                    MySQLConnection conn = new MySQLConnection(new MySQLConnectionString(arrText[0].ToString(), arrText[1].ToString(), arrText[2].ToString(), arrText[3].ToString()).AsString);//实例化一个连接对象其中myquest为数据库名,root为数据库用户名,amttgroup为数据库密码
                    conn.Open();
                    MySQLCommand commn = new MySQLCommand("set names gb2312;", conn);
                    commn.ExecuteNonQuery();
                    MySQLCommand cmds = new MySQLCommand("select * from qqnotic where isok = 0 limit 1", conn);
                    MySQLDataReader reader = cmds.ExecuteReaderEx();
                    while (reader.Read())
                    {
                        int userid = int.Parse(reader["userid"].ToString()); //用户id
                        int checktype = int.Parse(reader["btype"].ToString()); //业务类型

                        MySQLCommand cmdname = new MySQLCommand("select * from qqname where id = " + userid, conn);
                        MySQLDataReader readername = cmdname.ExecuteReaderEx();
                        while (readername.Read())
                        {
                            qq = int.Parse(readername["qqnum"].ToString()); //qq号码
                            qqname = (string)readername["qqname"];   //qq昵称
                            realname = (string)readername["realname"]; //用户真名
                        }

                        bbtype = "光宇信息中心通知";   //通知标题
                        bbcontent = (string)reader["content"];  //通知内容

                        /* 若指定通知类型 */
                        if (checktype != 0)
                        {

                            MySQLCommand cmdtype = new MySQLCommand("select * from btype where id = " + checktype, conn);
                            MySQLDataReader btype = cmdtype.ExecuteReaderEx();
                            while (btype.Read())
                            {
                                bbtype = (string)btype["type"]; //通知标题
                                bbcontent = (string)btype["content"]; //通知内容
                            }

                        }

                        System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));

                        int timeStamp = (int)(System.DateTime.Now - startTime).TotalSeconds;

                        MySQLCommand excmds = new MySQLCommand("UPDATE `qqnotic`.`qqnotic` SET `isok` = '1',`extime` = " + timeStamp + " WHERE `qqnotic`.`id` =" + reader["id"], conn);

                        excmds.ExecuteNonQuery(); //写入系统时间

                        notis = bbtype + ":\n" + realname + "您好," + bbcontent;

                        Console.WriteLine(System.DateTime.Now + "向用户" + realname + "(" + qq + ") 发送一条信息!");
                    }
                    conn.Close();
                }
                catch { Exception e; }

                if (qq != 0 && notis != "")
                {
                    try
                    {
                        Clipboard.Clear();
                        Clipboard.SetDataObject(notis,true);
                    }
                    catch { Exception e; }
                    const int WM_CHAR = 0x0102;
                    const int WM_KEYDOWN = 0x0100;
                    const int WM_PASTE = 0x0302;
                    const int WM_SETTEXT = 0x000C;
                    const int WM_Close = 0x0010;
                    string[] cmd = new string[] { "start tencent://message/?uin=" + qq + "&Site=gyyx.cn&Menu=yes" };
                    Cmd(cmd);
                    Thread.Sleep(1000);
                    EnumWindows(PrintWindow, IntPtr.Zero);
                    string tr = notis;
                    IntPtr hwndCalc = hander;

                    //ShowWindow(hwndCalc,1);

                    PostMessage(hwndCalc, WM_PASTE, 0, 0);
                    Thread.Sleep(500);
                    PostMessage(hwndCalc, WM_KEYDOWN, 13, 0);
                    Thread.Sleep(500);
                    //PostMessage(hwndCalc, WM_KEYDOWN, 27, 0);
                    PostMessage(hwndCalc, WM_Close, 0, 0);
                    Thread.Sleep(1000);
                    qq = 0;
                    notis = "";
                }
             //   else { Thread.Sleep(6000); }

               //     }
        }