private void ChangeData_Click(object sender, EventArgs e) { if (textBoxNAME.Text == "" || textBoxPASSWORD.Text == "" || textBoxAGE.Text == "" || textBoxOCC.Text == "" || textBoxHOB.Text == "") { MessageBox.Show("请把所有为空的项目填写完整", "提示"); } else { string updatepasswoad = "update UI set PASSWORD='******' where UID='" + DB.UserData.PublicValue.UserID + "'"; string updatename = "update UI set NAME='" + textBoxNAME.Text.ToString() + "' where UID='" + DB.UserData.PublicValue.UserID + "'"; string updatesex = "update UI set SEX='" + comboBoxSEX.Text.ToString() + "' where UID='" + DB.UserData.PublicValue.UserID + "'"; string updateage = "update UI set AGE='" + textBoxAGE.Text.ToString() + "' where UID='" + DB.UserData.PublicValue.UserID + "'"; string updateocc = "update UI set OCC='" + textBoxOCC.Text.ToString() + "' where UID='" + DB.UserData.PublicValue.UserID + "'"; string updatehob = "update UI set HOB='" + textBoxHOB.Text.ToString() + "' where UID='" + DB.UserData.PublicValue.UserID + "'"; DB.UserData.PublicValue.UserPassword = textBoxPASSWORD.Text.ToString(); //更新全局变量 DB.UserData.PublicValue.UserName = textBoxNAME.Text.ToString(); DB.UserData.PublicValue.UserSex = comboBoxSEX.Text; DB.UserData.PublicValue.UserAge = textBoxAGE.Text.ToString(); DB.UserData.PublicValue.UserOcc = textBoxOCC.Text.ToString(); DB.UserData.PublicValue.UserHob = textBoxHOB.Text.ToString(); DB.SQLHelper update = new DB.SQLHelper(); int num = update.Execute(updatepasswoad) + update.Execute(updatename) + update.Execute(updatesex) + update.Execute(updateage) + update.Execute(updateocc) + update.Execute(updatehob); if (num > 5) { MessageBox.Show("更新成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("更新失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void Reg_Click(object sender, EventArgs e) { string strUID = textBoxUID.Text.Trim(); string strPWD = textBoxPASSWORD.Text.Trim(); string strNAME = textBoxNAME.Text.Trim(); string strSEX = comboBoxSEX.Text; string strAGE = textBoxAGE.Text.Trim(); string strOCC = textBoxOCC.Text.Trim(); string strHOB = textBoxHOB.Text.Trim(); //创建命令向数据库插入数据 if (strUID == "" || strPWD == "" || strNAME == "" || strSEX == "" || strAGE == "" || strOCC == "" || strHOB == "") { MessageBox.Show("注册失败!请将信息填写完整!", "提示"); } else { string name = "select UID from UI where UID='" + strUID + "'"; DB.SQLHelper select = new DB.SQLHelper(); SqlDataReader read = select.read(name); if (read.Read()) { MessageBox.Show("注册失败!UID已存在!", "提示"); } else { DB.SQLHelper Insert = new DB.SQLHelper(); string strInsert = "Insert into UI (UID,PASSWORD,NAME,SEX,AGE,OCC,HOB) Values('" + strUID + "','" + strPWD + "','" + strNAME + "','" + strSEX + "','" + strAGE + "','" + strOCC + "','" + strHOB + "')"; int n = Insert.Execute(strInsert); //返回用户创建结果 if (n > 0) { MessageBox.Show("注册成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; this.Dispose(); this.Close(); } else { MessageBox.Show("注册失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
private void Retext1_Click(object sender, EventArgs e) { try { string retext = retextbox.Text.Trim(); if (retext == "") { MessageBox.Show("回复不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { DB.SQLHelper selectflr = new DB.SQLHelper(); string time = DateTime.Now.ToString("yyyy/MM/dd"); string FLRinPost = "select MAX(FLR) from RETEXT where PID=" + DB.UserData.PublicValue.viewPID + ""; SqlDataReader readflr = selectflr.read(FLRinPost); readflr.Read(); DB.UserData.PublicValue.FLR = readflr[0] == DBNull.Value?1:(Convert.ToInt32(readflr[0]) + 1); //判断是不是为空,全局变量,将flr查询结果用read读出后再用Convert.ToInt32转换为int string sqlretext = "insert into RETEXT(UID,PID,REDATE,RETEXT,FLR) values ('" + DB.UserData.PublicValue.UserID + "'," + DB.UserData.PublicValue.viewPID + ",'" + time + "','" + retext + "'," + DB.UserData.PublicValue.FLR + ")"; DB.SQLHelper Insert = new DB.SQLHelper(); int n = Insert.Execute(sqlretext); //返回用户创建结果 if (n > 0) { MessageBox.Show("回复成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); PublishRetext_Load(null, null); } else { MessageBox.Show("回复失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Pubilshthepost_Click(object sender, EventArgs e) { string posttitle = publishtitle.Text.Trim(); string postmain = publishmain.Text.Trim(); if (posttitle == "" || postmain == "") { MessageBox.Show("标题或内容不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { string time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); string LV = LVOfPost.Text.Trim(); string pid = "select MAX(PID) from POST"; DB.SQLHelper selectpid = new DB.SQLHelper(); SqlDataReader readpid = selectpid.read(pid); readpid.Read(); DB.UserData.PublicValue.PID = Convert.ToInt32(readpid[0]) + 1; //全局变量,将pid查询结果用read读出后再用Convert.ToInt32转换为int string insert = "insert into POST(UID,PID,PDATE,TITLE,PTEXT,LV) values ('" + DB.UserData.PublicValue.UserID + "'," + DB.UserData.PublicValue.PID + ",'" + time + "','" + posttitle + "','" + postmain + "','" + LV + "')"; try { DB.SQLHelper sqlHelper = new DB.SQLHelper(); int n = sqlHelper.Execute(insert); if (n > 0) { MessageBox.Show("发表成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("因未知原因发表失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }