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 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 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 除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 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); } } }