private void button1_Click(object sender, EventArgs e) { UserManage adduser = new UserManage(); if (textBox1.Text == null) { MessageBox.Show("用户名不能为空!"); return; } else if (textBox5.Text == null) { MessageBox.Show("用户密码不能为空!"); return; } else if (textBox6.Text == null) { MessageBox.Show("用户权限不能为空!"); return; } String name = textBox1.Text; String password = textBox5.Text; int limit = Convert.ToInt32(textBox6.Text); int test = adduser.testUser(name); if (test == 1) { MessageBox.Show("用户名已经存在!"); return; } int tt = adduser.addUser(name, password, limit); if (tt == 1) { MessageBox.Show("添加成功!", "添加成功"); this.Close(); User_service myservice = new User_service(); IList <User> userlist = myservice.getAllUsers(); dataview.Rows.Clear(); for (int i = 0; i < userlist.Count; i++) { User user = userlist[i]; String[] row = { user.Userid.ToString(), user.Username, user.Password, user.Limit.ToString() }; dataview.Rows.Add(row); } } }
//初始化数据 public void InitialData() { User_service myservice = new User_service(); IList <User> userlist = myservice.getAllUsers(); IList <CangKu> cangkulist = myservice.getAllCangku(); // IList<Product> productlist = myservice.getAllProduct(); this.dataGridView1.Rows.Clear(); //this.dataGridView2.Rows.Clear(); this.Userdataview.Rows.Clear(); for (int i = 0; i < userlist.Count; i++) { User user = userlist[i]; String[] row = { user.Userid.ToString(), user.Username, user.Password, user.Limit.ToString() }; this.Userdataview.Rows.Add(row); } for (int j = 0; j < cangkulist.Count; j++) { CangKu cangku = cangkulist[j]; String[] row1 = { cangku.Cangku_id.ToString(), cangku.Cangku_name }; this.dataGridView1.Rows.Add(row1); } /* for (int k = 0; k < productlist.Count;k++ ) * { * Product product = productlist[k]; * String[] row2 = { product.Pro_id.ToString(),product.Pro_name}; * this.dataGridView2.Rows.Add(row2); * } */ /* * String connectionString = "server = localhost; database = menagesystem; user id = root; password = 123456;"; * MySqlConnection connection = new MySqlConnection(connectionString); * String sql = "select *from product"; * DataSet ds = new DataSet(); * MySqlDataAdapter da = new MySqlDataAdapter(sql,connection); * da.Fill(ds, "product"); * dataGridView2.DataSource = ds.DefaultViewManager; */ }