//重置密码 private void button1_Click(object sender, EventArgs e) { if (!ClassGlobalUserInfo.checkValidate())//操作员没有权限 { CValidateTools.showError("权限不足"); return; } if (!CValidateTools.checkLength(textBox_id.Text, 1, 20)) { CValidateTools.showError("请先选择一个用户"); return; } if (CValidateTools.showYesNoDialog("确定要重置密码吗?") == DialogResult.Cancel) return; string strUpdate = "update userInfo set AdmPwd = '888888' where userNumber = '#usernumber' "; strUpdate = strUpdate.Replace("#usernumber", textBox_id.Text); bool result = false; try { ADOHelper db = new ADOHelper(); result = db.ExecuteUpdate(strUpdate); } catch (Exception ex) { CValidateTools.showError(ex.Message); return; } if (result) CValidateTools.showOK("密码重置成功!"); }
//保存数据 private void button_save_Click(object sender, EventArgs e) { if (!ClassGlobalUserInfo.checkValidate())//操作员没有权限 { CValidateTools.showError("权限不足"); return; } if (textBox_uTitle.ReadOnly ) return; if (textBox_uTitle.Text.Length <= 0 || textBox_des.Text.Length <= 0) { CValidateTools.showError("待修改内容不能为空"); return; } string rowID = dview_UploadInfo.Rows[dview_UploadInfo.SelectedCells[0].RowIndex].Cells["编号"].Value.ToString(); if (rowID == null || rowID.Length <= 0) { CValidateTools.showError("请选择要修改的数据"); return; } string strUpdate = "update fileUpload set uploadTitle = '#title' , uploadDes = '#uploadDes' where ID = #ID1 "; strUpdate = strUpdate.Replace("#title", textBox_uTitle.Text).Replace("#uploadDes", textBox_des.Text).Replace("#ID1", rowID); bool result = false; try { ADOHelper db = new ADOHelper(); result = db.ExecuteUpdate(strUpdate); } catch (Exception ex) { CValidateTools.showError(ex.Message); return; } if (result) { CValidateTools.showOK("上传信息修改成功!"); getUploadData(); ChangeDataSoure(srcTable); } textBox_uTitle.ReadOnly = true; textBox_des.ReadOnly = true; }
//保存修改 private void button_save_Click(object sender, EventArgs e) { if (!ClassGlobalUserInfo.checkValidate())//操作员没有权限 { CValidateTools.showError("权限不足"); return; } if (textBox_cname.ReadOnly) return; int roleID = int.Parse(comboBox_role.SelectedValue.ToString()); int depID = int.Parse(comboBox_dep.SelectedValue.ToString()); string strUpdate = "update userInfo set cName = '#cname' , depID = #depid , roleID = #roldid where userNumber = '#usernumber'"; strUpdate = strUpdate.Replace("#cname", textBox_cname.Text).Replace("#depid", depID.ToString()).Replace("#roldid", roleID.ToString()).Replace("#usernumber", textBox_id.Text); bool result = false; try { ADOHelper db = new ADOHelper(); result = db.ExecuteUpdate(strUpdate); } catch (Exception ex) { CValidateTools.showError(ex.Message); return; } if (result) CValidateTools.showOK("用户修改成功!"); getUserInfo(); textBox_cname.ReadOnly = true; textBox_id.ReadOnly = true; }
//添加用户 private void button_add_Click(object sender, EventArgs e) { if (!checkValide()) return; //格式化数据 string sid = textBox_id.Text; string admName = textBox_name.Text; string cName = textBox_cname.Text; int roleID = int.Parse(comboBox_role.SelectedValue.ToString()); int depID = int.Parse(comboBox_dep.SelectedValue.ToString()); //查询记录中是否已经有相同记录 string queryString = "select * from userInfo where userNumber = '#user1' or AdmName = '#aname' "; string str1 = queryString.Replace("#user1", sid); str1 = str1.Replace("#aname", admName); ADOHelper db = new ADOHelper(); if (db.ExecuteRead(str1).HasRows) { MessageBox.Show("编号或用户名已存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //插入新用户 string insertString = "insert into userInfo (admname,usernumber,admpwd,roleid,depcid,depid,cname) values( '#admName', '#userNum', '#pwd', #roleID, #depCID, #depID, '#cName' )"; string str = insertString.Replace("#admName", admName); str = str.Replace("#userNum", sid); str = str.Replace("#pwd", "888888"); str = str.Replace("#userNum", sid); str = str.Replace("#roleID", roleID.ToString()); str = str.Replace("#depCID", DevTools.getDepartmentId());//默认用2,2为交管局,1为公安局 str = str.Replace("#depID", depID.ToString()); str = str.Replace("#cName", cName); if (db.ExecuteUpdate(str)) { CValidateTools.showOK("添加用户成功"); clearControlData();//清除录入数据 } else { CValidateTools.showError("添加用户失败"); } }
private bool uploadFileToDB(string filename, string strCreateTime) { string uploadString = @"insert into fileUpload (uid1,uid2,uploadTime,uploadTitle,uploadDes,createTime,fileDir) values ( '#uid1', '#uid2', '#uploadTime', '#uploadTitle','#uploadDes','#createTime','#fileDir')"; uploadString = uploadString.Replace("#uid1", comboBox_uid1.SelectedValue.ToString()).Replace("#uid2", ClassGlobalUserInfo.userNumber); uploadString = uploadString.Replace("#uploadTime",dateTimePicker1.Value.ToString("yyyy/MM/dd HH:mm:ss")); uploadString = uploadString.Replace("#uploadTitle",textBox_uTitle.Text); uploadString = uploadString.Replace("#uploadDes", textBox_des.Text); uploadString = uploadString.Replace("#createTime", strCreateTime); uploadString = uploadString.Replace("#fileDir", filename); try { ADOHelper db = new ADOHelper(); //for (int i = 0; i < 800; i++ )//for test db.ExecuteUpdate(uploadString); } catch (Exception ex) { ErrorLog.WriteLog(ex); CValidateTools.showError(ex.Message); return false; } return true; }
//修改密码 private void button_add_Click(object sender, EventArgs e) { if (CValidateTools.isNull(textBox_oldPwd.Text)) { CValidateTools.showError("请输入旧密码"); return; } if (CValidateTools.isNull(textBox_new1.Text)) { CValidateTools.showError("请输入新密码"); return; } if (textBox_new1.Text != textBox_new2.Text) { CValidateTools.showError("二次密码输入不一致"); return; } //查询此用户的旧密码是否正确 string str = "select * from userInfo where AdmName = '#username' and AdmPwd = '#pwd' "; str = str.Replace("#username", m_usname); str = str.Replace("#pwd", textBox_oldPwd.Text); ADOHelper db = new ADOHelper(); if (!db.ExecuteRead(str).HasRows) { CValidateTools.showError("旧密码不正确,无法修改新密码"); return; } //替换新密码 string strUpdate = "update userInfo set AdmPwd = '#pwd' where admName = '#admName' "; strUpdate = strUpdate.Replace("#admName", m_usname).Replace("#pwd", textBox_new1.Text); bool result = false; try { ADOHelper db1 = new ADOHelper(); result = db1.ExecuteUpdate(strUpdate); } catch (Exception ex) { CValidateTools.showError(ex.Message); return; } if (result) CValidateTools.showOK("密码重置成功!"); }