private void toolSave_Click(object sender, EventArgs e) { if (txtUserName.Text == "" || txtUserPassword.Text == "" || cboUserType.Text == "") { MessageBox.Show("请将信息添加完整!"); return; } Model.UserInfo model = new Model.UserInfo();//实例化model层 model.UserName = txtUserName.Text.Trim(); model.UserPassword = txtUserPassword.Text.Trim(); model.UserType = cboUserType.Text.Trim(); BLL.UserInfo bll = new BLL.UserInfo();//实例化BLL层 model = bll.ToMD5(model); switch (flag) { case 0: { } break; case 1: { if (bll.Add(model)) //将员工信息添加到数据库中,根据返回值判断是否添加成功 { DataBind(); //窗体登录时绑定数据到DataGridView ControlStatus(); } } break; case 2: { if (bll.Update(model)) //根据返回布尔值判断是否修改数据成功 { DataBind(); //窗体登录时绑定数据到DataGridView txtUserName.ReadOnly = false; ControlStatus(); } } break; case 3: { if (bll.Delete(model)) //根据返回布尔值判断是否删除数据成功 { DataBind(); //窗体登录时绑定数据到DataGridView ControlStatus(); } } break; } }
private void btnLogin_Click_1(object sender, EventArgs e) { Model.UserInfo model = new Model.UserInfo();//实例化Model层 model.UserName = txtUserName.Text.Trim(); model.UserPassword = txtPassword.Text.Trim(); BLL.UserInfo bll = new BLL.UserInfo(); //实例化BLL层 model = bll.ToMD5(model); DataSet ds = new DataSet(); //定义DataSet对象 ds = bll.GetList(model); //调用BLL层中的GetList方法,返还DataSet对象 if (ds.Tables[0].Rows.Count > 0) { Main main = new Main(); main.Type = ds.Tables[0].Rows[0]["用户类别"].ToString(); main.Show(); this.Hide(); } else { MessageBox.Show("用户名或者密码输入错误!"); } }