void sendMsg() { if (msgtb.Text == "") { return; } string today = DateTime.Now.Year.ToString() + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day; foreach (DataRow item in MySQLHelperClass.ExecuteDataTable("show tables").Rows) { if (item[0].ToString() == today) { MySQLHelperClass.ExecuteNonQuery("INSERT INTO " + today + " (username,talkdata, talkdate) VALUES ('" + username + "','" + msgtb.Text + "','" + DateTime.Now + "')"); msgtb.Text = ""; return; } } var str = "CREATE TABLE " + today + "(id INT NOT NULL AUTO_INCREMENT, username VARCHAR(100) NOT NULL, talkdata VARCHAR(100) NOT NULL,talkdate DateTime,PRIMARY KEY ( id ))ENGINE=InnoDB DEFAULT CHARSET=utf8; "; MySQLHelperClass.ExecuteNonQuery(str); MySQLHelperClass.ExecuteNonQuery("INSERT INTO " + today + " (username,talkdata, talkdate) VALUES ('" + username + "','" + msgtb.Text + "','" + DateTime.Now + "')"); msgtb.Text = ""; }
private void timer1_Tick(object sender, EventArgs e) { string today = DateTime.Now.Year.ToString() + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day; var rows = MySQLHelperClass.ExecuteDataTable("select * from " + today).Rows; if (rows.Count > talkcount) { addMsg(MySQLHelperClass.ExecuteDataTable("select * from " + today + " order by id limit " + talkcount.ToString() + "," + (rows.Count - talkcount).ToString() + ";")); talkcount = rows.Count; } }
private void talkForm_Load(object sender, EventArgs e) { msgtb.Focus(); sizeChange(); MySQLHelperClass.connectionString = "server = localhost; user = root; database = talkdata; port = databaseport; password = thisisjim1!"; var dataTable = MySQLHelperClass.ExecuteDataTable("show tables"); string today = DateTime.Now.Year.ToString() + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day; foreach (DataRow item in MySQLHelperClass.ExecuteDataTable("show tables").Rows) { if (item[0].ToString() == today) { addMsg(MySQLHelperClass.ExecuteDataTable("select * from " + today)); } } talkcount = MySQLHelperClass.ExecuteDataTable("select * from " + today).Rows.Count; timer1.Start(); }
private void rebt_Click(object sender, EventArgs e) { if (rusernametb.Text == "" || ruserpswtb.Text == "" || rerpswtb.Text == "" || mailCodetb.Text == "" || rmailtb.Text == "") { message("输入框不能为空"); return; } if (rerpswtb.Text != ruserpswtb.Text) { message("两次密码不匹配!"); return; } if (mailCodetb.Text != code) { message("验证码不匹配"); return; } if (MySQLHelperClass.ExecuteScalar("SELECT * from user WHERE username='******';") != null) { message("用户名"); return; } try { MySQLHelperClass.ExecuteNonQuery("INSERT INTO user (username,usermail, userpsw) VALUES ('" + rusernametb.Text + "','" + rmailtb.Text + "','" + ruserpswtb.Text + "')"); message("注册成功"); rusernametb.Text = ""; ruserpswtb.Text = ""; rerpswtb.Text = ""; mailCodetb.Text = ""; rmailtb.Text = ""; } catch (Exception ee) { message(ee.Message); } }