private void DeleteToolStripMenuItem_Click(object sender, EventArgs e) { try { string deleteoftype = "select TYPE from UI where UID='" + DB.UserData.PublicValue.UserID + "'"; string strFLR = queryofretext.SelectedRows[0].Cells["楼层数"].Value.ToString(); string deleteofuid = "select UID from RETEXT where PID=" + DB.UserData.PublicValue.viewPID + " AND FLR='" + strFLR + "'"; DB.SQLHelper delete = new DB.SQLHelper(); SqlDataReader readuid = delete.read(deleteofuid); readuid.Read(); DialogResult dialogResult = MessageBox.Show("你确定要删除" + strFLR + "楼的回复吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.No)//选择NO则不进行下一步 { return; } if (deleteoftype == "1" || readuid[0].ToString() == DB.UserData.PublicValue.UserID) //判断,若为管理员或回复者则可以删除回复 { string deleteRetext = "delete from RETEXT where PID=" + DB.UserData.PublicValue.viewPID + " and FLR='" + strFLR + "'"; DB.SQLHelper sqlhelp = new DB.SQLHelper(); sqlhelp.OperateTb(deleteRetext); Queryretextbutton_Click(null, null); } else { MessageBox.Show("你不是回复用户或管理员,不能删除该回复!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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 PublishRetext_Load(object sender, EventArgs e) { dataGridViewofretext.SelectionMode = DataGridViewSelectionMode.FullRowSelect; showPID.Text = DB.UserData.PublicValue.viewPID.ToString(); try {//进行评论的加载 string sqlofretext = "select UID as 用户ID ,REDATE as 回复日期,RETEXT as 内容,FLR as 楼层数 from RETEXT where PID=" + DB.UserData.PublicValue.viewPID + ""; sqlofretext += " order by FLR"; DB.SQLHelper Queryretext = new DB.SQLHelper(); DataSet ds = Queryretext.GetDataSet(sqlofretext); DataTable dt = ds.Tables[0]; dataGridViewofretext.DataSource = dt; if (dt.Rows.Count == 0) { dataGridViewofretext.ContextMenuStrip = null; } else { dataGridViewofretext.ContextMenuStrip = contextMenuStripofretext; } } catch (Exception ex) { MessageBox.Show(ex.Message); } try { string title = "select TITLE from POST where PID=" + DB.UserData.PublicValue.viewPID + ""; string main = "select PTEXT from POST where PID=" + DB.UserData.PublicValue.viewPID + ""; DB.SQLHelper showpost = new DB.SQLHelper(); SqlDataReader readtitle = showpost.read(title); SqlDataReader readmain = showpost.read(main); readtitle.Read(); readmain.Read(); titletext.Text = readtitle[0].ToString().Trim(); maintext.Text = readmain[0].ToString().Trim(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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 除ToolStripMenuItem_Click(object sender, EventArgs e) //删除菜单 { string deleteoftype = "select TYPE from UI where UID='" + DB.UserData.PublicValue.UserID + "'"; string strPID = dataGridViewpost.SelectedRows[0].Cells["帖子ID"].Value.ToString();//捕捉选中的单元格 string deleteofuid = "select UID from POST where PID='" + strPID + "'"; DB.SQLHelper delete = new DB.SQLHelper(); SqlDataReader readuid = delete.read(deleteofuid); readuid.Read(); DialogResult dialogResult = MessageBox.Show("你确定要删除帖子ID为:" + strPID + "的帖子信息吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.No)//选择NO则不进行下一步 { return; } if (deleteoftype == "1" || readuid[0].ToString() == DB.UserData.PublicValue.UserID) { string strdelete = "Delete From POST Where PID='" + strPID + "'"; try { DB.SQLHelper sqlhelp = new DB.SQLHelper(); sqlhelp.OperateTb(strdelete); Qpost_Click(null, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("你不是发帖用户或管理员,不能删除该帖子!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
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); } } }
private void Queryretextbutton_Click(object sender, EventArgs e) { string RUID = uidofretext.Text.Trim(); string Rtime = timeofretext.Text.Trim(); if (RUID == "" && Rtime == "") { MessageBox.Show("你必须输入一个查询约束条件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { try { string sqlquery = "select UID as 用户ID ,PID as 帖子ID,REDATE as 回复日期,RETEXT as 内容,FLR as 楼层数 from RETEXT where UID='" + RUID + "' "; if (Rtime.Length > 0) { sqlquery += " and REDATE='" + Rtime + "'"; } DB.SQLHelper Queryretext = new DB.SQLHelper(); DataSet ds = Queryretext.GetDataSet(sqlquery); DataTable dt = ds.Tables[0]; queryofretext.DataSource = dt; if (dt.Rows.Count == 0) { queryofretext.ContextMenuStrip = null;//删除菜单在无数据时不显示 MessageBox.Show("没有符合条件的帖子记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { queryofretext.ContextMenuStrip = contextMenuStripofretext; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
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 Qpost_Click(object sender, EventArgs e) { string Quid = QueryUID.Text.Trim();//查询的文本内容 string Qpid = QueryPID.Text.Trim(); string Qtime = time.Text.Trim(); if (Quid == "" && Qpid == "" && Qtime == "") { MessageBox.Show("你必须输入一个查询约束条件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { try { if (Qpid.Length == 0 && Quid.Length == 0) { string sql = "select UID as 用户ID ,PID as 帖子ID,PDATE as 发帖日期,TITLE as 标题,PTEXT as 内容,LV as 等级 from POST where PDATE between '" + Qtime + " 00:00:00' and '" + Qtime + " 23:59:59'"; sql += " order by PDATE"; DB.SQLHelper Querypost = new DB.SQLHelper(); DataSet ds = Querypost.GetDataSet(sql); DataTable dt = ds.Tables[0]; dataGridViewpost.DataSource = dt; if (dt.Rows.Count == 0) { MessageBox.Show("没有符合条件的帖子记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else if (Quid.Length == 0) { time.Text = ""; string sql = "select UID as 用户ID ,PID as 帖子ID,PDATE as 发帖日期,TITLE as 标题,PTEXT as 内容,LV as 等级 from POST where PID='" + Qpid + "' "; sql += " order by PDATE"; DB.SQLHelper Querypost = new DB.SQLHelper(); DataSet ds = Querypost.GetDataSet(sql); DataTable dt = ds.Tables[0]; dataGridViewpost.DataSource = dt; if (dt.Rows.Count == 0) { MessageBox.Show("没有符合条件的帖子记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { string sql = "select UID as 用户ID ,PID as 帖子ID,PDATE as 发帖日期,TITLE as 标题,PTEXT as 内容,LV as 等级 from POST where UID='" + Quid + "' "; if (Qpid.Length > 0) { sql += " and PID='" + Qpid + "' "; } if (Qtime.Length > 0) { sql += " and PDATE BETWEEN '" + Qtime + " 00:00:00' and '" + Qtime + " 23:59:59' "; } sql += " order by PDATE"; DB.SQLHelper Querypost = new DB.SQLHelper(); DataSet ds = Querypost.GetDataSet(sql); DataTable dt = ds.Tables[0]; dataGridViewpost.DataSource = dt; if (dt.Rows.Count == 0) { dataGridViewpost.ContextMenuStrip = null;//删除菜单在无数据时不显示 MessageBox.Show("没有符合条件的帖子记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { dataGridViewpost.ContextMenuStrip = deleteMenuStrip; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void Loginin_Click(object sender, EventArgs e) { string userUID = this.txtUserName.Text.Trim(); string userPassword = this.txtPassword.Text.Trim(); // 验证数据 // 验证用户输入是否为空,若为空,提示用户信息 if (userUID.Equals("") || userPassword.Equals("")) { MessageBox.Show("用户名或密码不能为空!"); } // 若不为空,验证用户名和密码是否与数据库匹配 // 这里只做字符串对比验证 else { //用户名和密码验证正确,提示成功,并执行跳转界面。 try { string User = "******" + userUID + "' And PASSWORD='******'"; string userName = "******" + userUID + "'"; string userSex = "SELECT SEX from UI where UID='" + userUID + "'"; string userAge = "SELECT AGE from UI where UID='" + userUID + "'"; string userOcc = "SELECT OCC from UI where UID='" + userUID + "'"; string userHob = "SELECT HOB from UI where UID='" + userUID + "'"; DB.SQLHelper loginthesystem = new DB.SQLHelper(); SqlDataReader read1 = loginthesystem.read(User); SqlDataReader readname = loginthesystem.read(userName); SqlDataReader readsex = loginthesystem.read(userSex); SqlDataReader readage = loginthesystem.read(userAge); SqlDataReader readocc = loginthesystem.read(userOcc); SqlDataReader readhob = loginthesystem.read(userHob); if (read1.Read()) { MessageBox.Show("登录成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); DB.UserData.PublicValue.UserID = userUID; DB.UserData.PublicValue.UserPassword = userPassword; readname.Read(); DB.UserData.PublicValue.UserName = readname[0].ToString(); //将名字存入全局变量 readsex.Read(); DB.UserData.PublicValue.UserSex = readsex[0].ToString(); //将性别存入全局变量 readage.Read(); DB.UserData.PublicValue.UserAge = readage[0].ToString(); //将年龄存入全局变量 readocc.Read(); DB.UserData.PublicValue.UserOcc = readocc[0].ToString(); //将职业存入全局变量 readhob.Read(); DB.UserData.PublicValue.UserHob = readhob[0].ToString(); //将爱好存入全局变量 MainSystem.WindowsOfUser From2 = new MainSystem.WindowsOfUser(); From2.Show(); this.Hide(); } //用户名和密码验证错误,提示错误。 else { MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }