private static void addDefault() { String checkName = "select * from loginInfo where userName='******'" ; DBOperation op = new DBOperation(); DataTable checkDefault = op.getDataTable(checkName, "loginInfo"); if (checkDefault.Rows.Count == 0) { String defpass = AddAccount.MD5("123456"); String addDefault = "insert into loginInfo(userName, password, privilege) values('default', '" + defpass + "', 0)"; op.singleOperation(addDefault); MessageBox.Show("已添加默认账号"); } }
public worker() { InitializeComponent(); db = new DBOperation(); lvWorker.GridLines = true; lvWorker.FullRowSelect = true; lvWorker.View = View.Details; lvWorker.Clear(); lvWorker.Columns.Add("员工号", 100, HorizontalAlignment.Center); lvWorker.Columns.Add("姓", 100, HorizontalAlignment.Center); lvWorker.Columns.Add("名", 100, HorizontalAlignment.Center); lvWorker.Columns.Add("性别", 100, HorizontalAlignment.Center); //lvWorker.Columns.Add("年龄", 100, HorizontalAlignment.Center); lvWorker.Columns.Add("工资", 100, HorizontalAlignment.Center); lvWorker.Columns.Add("职称", 100, HorizontalAlignment.Center); lvWorker.Columns.Add("工作部门", 100, HorizontalAlignment.Center); lvWorker.ColumnClick += new ColumnClickEventHandler(lvWorker_ColumnClick); // tv_worker.Click += new System.EventHandler(tv_worker_NodeMouseDoubleClick); }
private void submit_Click(object sender, EventArgs e) { if (this.name.Text == "") { MessageBox.Show("请输入用户名"); return; } if (this.pass.Text == "") { MessageBox.Show("请输入密码"); return; } //1-6权限分别对应售货,员工,收支,购物卡,设备,仓库,0为最高权限,可以进入所有模块 String checkName = "select * from loginInfo where userName='******'" ; DBOperation op = new DBOperation(); DataTable namedt = op.getDataTable(checkName, "loginInfo"); if (namedt.Rows.Count == 0) { MessageBox.Show("用户名错误"); return; } else { String password = namedt.Rows[0]["password"].ToString(); String priv = namedt.Rows[0]["privilege"].ToString(); String md5pass = AddAccount.MD5(this.pass.Text); if (!password.Equals(md5pass)) { MessageBox.Show("密码错误"); } else { if (Welcome.current.Equals("worker")) { if (priv.Equals("2") || priv.Equals("0")) { this.workers = new worker(); this.before(); this.workers.ShowDialog(); this.after(); this.workers.Dispose(); } else { MessageBox.Show("您没有权限访问此模块"); this.name.Text = ""; this.pass.Text = ""; } } else if (Welcome.current.Equals("card")) { if (priv.Equals("4") || priv.Equals("0")) { cards = new Cards(); this.before(); cards.ShowDialog(); this.after(); cards.Dispose(); } else { MessageBox.Show("您没有权限访问此模块"); this.name.Text = ""; this.pass.Text = ""; } } else if (Welcome.current.Equals("warehouse")) { if (priv.Equals("6") || priv.Equals("0")) { dep = new Depository(); this.before(); dep.ShowDialog(); this.after(); dep.Dispose(); } else { MessageBox.Show("您没有权限访问此模块"); this.name.Text = ""; this.pass.Text = ""; } } else if (Welcome.current.Equals("facility")) { if (priv.Equals("5") || priv.Equals("0")) { facility = new Facility(); this.before(); facility.ShowDialog(); this.after(); facility.Dispose(); } else { MessageBox.Show("您没有权限访问此模块"); this.name.Text = ""; this.pass.Text = ""; } } else if (Welcome.current.Equals("information")) { if (priv.Equals("0")) { info = new Information(); this.before(); info.ShowDialog(); this.after(); info.Dispose(); } else { MessageBox.Show("您没有权限访问此模块"); this.name.Text = ""; this.pass.Text = ""; } } else if (Welcome.current.Equals("finance")) { if (priv.Equals("3") || priv.Equals("0")) { finance = new FinancialForm(); this.before(); finance.ShowDialog(); this.after(); finance.Dispose(); } else { MessageBox.Show("您没有权限访问此模块"); this.name.Text = ""; this.pass.Text = ""; } } else if (Welcome.current.Equals("sales")) { if (priv.Equals("1") || priv.Equals("0")) { sales = new Sales(); this.before(); sales.ShowDialog(); this.after(); sales.Dispose(); } else { MessageBox.Show("您没有权限访问此模块"); this.name.Text = ""; this.pass.Text = ""; } } else if (Welcome.current.Equals("addCourse")) { if (priv.Equals("0")) { add = new AddAccount(); this.before(); add.ShowDialog(); this.after(); add.Dispose(); } else { MessageBox.Show("您没有权限访问此模块"); this.name.Text = ""; this.pass.Text = ""; } } } } }
private void button1_Click(object sender, EventArgs e) { if(this.addname.Text == "") { MessageBox.Show("请输入用户名"); return; } if(this.addpass.Text == "") { MessageBox.Show("请输入密码"); return; } if (this.addrepass.Text == "") { MessageBox.Show("请输入密码"); return; } if (this.privilege.Text == "") { MessageBox.Show("请选择权限"); return; } if (this.addname.Text.Length > 16 || this.addname.Text.Length < 6) { MessageBox.Show("用户名应为6至16位"); return; } if (this.addpass.Text.Length > 20 || this.addpass.Text.Length < 6) { MessageBox.Show("密码应为6至20位"); return; } if(!this.addpass.Text.Equals(this.addrepass.Text)) { MessageBox.Show("两次输入密码不匹配"); return; } op = new DBOperation(); String check = "select * from loginInfo where userName='******'"; DataTable search = op.getDataTable(check, "loginInfo"); if (search.Rows.Count != 0) { MessageBox.Show("该用户名已存在"); return; } String md5 = MD5(this.addpass.Text); op = new DBOperation(); String addAccount = "insert into loginInfo(userName, password, privilege) values('" + this.addname.Text + "', '" + md5 + "', " + this.addPri.Text + ")"; MessageBox.Show(md5); if (op.singleOperation(addAccount)) { this.addname.Text = ""; this.addpass.Text = ""; this.addPri.Text = ""; MessageBox.Show("添加成功"); } }