private void Query() { //查询的时候先清空两个DataGridView表数据 //清空物料代码表数据 DataTable dt_User = (DataTable)dgv_User.DataSource; if (dt_User != null) { dt_User.Clear(); } DataTable dt_Menu = (DataTable)dgv_Menu.DataSource; if (dt_Menu != null) { dt_Menu.Clear(); } string strWhere = " WHERE 1=1"; if (txt_MaterialCode.Text != string.Empty)//料号 { strWhere += string.Format(" AND UserID='{0}'", txt_MaterialCode.Text.Trim()); } DataTable dt = BLL_SysDatUser.Select(strWhere); dgv_User.DataSource = dt; }
/// <summary> /// 删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_del_Click(object sender, EventArgs e) { string strWhere = string.Empty; int iSelectedRow = 0; bool b_DelOK = false;//是否删除过 DialogResult result = MsgBox.Question("确认删除?"); if (result == DialogResult.Cancel) { return; } int Count = 0; foreach (DataGridViewRow row in dgv_User.Rows) { if (row.Cells[CHK.Name].EditedFormattedValue.ToString() == "True") { if (strWhere == string.Empty) { strWhere += string.Format("WHERE {0} in ('{1}'", UserID.Name, row.Cells[UserID.Name].Value.ToString()); } else { strWhere += string.Format(",'{0}'", row.Cells[UserID.Name].Value.ToString()); } Count++; iSelectedRow++; if (Count == 20) { strWhere += ")"; BLL_SysDatUser.Delete(strWhere); BLL_SysDatUserMenuMap.Delete(strWhere); strWhere = string.Empty; Count = 0; b_DelOK = true; } } } if (strWhere != string.Empty) { strWhere += ")"; BLL_SysDatUser.Delete(strWhere); BLL_SysDatUserMenuMap.Delete(strWhere); b_DelOK = true; } if (iSelectedRow == 0) { MsgBox.Error("请先选中行!"); return; } if (b_DelOK) { Query(); new PubUtils().ShowNoteOKMsg("删除成功!"); string MaterialCode = string.Empty; } }
private void Query() { string strWhere = " Where 1=1"; if (txt_userName.Text != string.Empty) { strWhere += string.Format(" AND a.UserName='******'", txt_userName.Text.Trim()); } dtUser = BLL_SysDatUser.QueryUserOrg(strWhere); dgv_user.DataSource = dtUser; }
/// <summary> /// 删除人员管理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_del_Click(object sender, EventArgs e) { if (dgv_user.CurrentRow == null || dgv_user.CurrentRow.Index == -1) { new PubUtils().ShowNoteNGMsg("请选中行", 1, grade.OrdinaryError); return; } if (MsgBox.Question("确认删除") == DialogResult.OK) { string userID = dgv_user.CurrentRow.Cells["UserID"].Value.ToString(); BLL_SysDatUser.DeleteUserOrg(userID); Query(); new PubUtils().ShowNoteOKMsg("删除成功"); } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_ok_Click(object sender, EventArgs e) { txt_UserID.Focus(); if (!CheckData()) { return; } bool isSucess = false; if (_Action_Type == false) { //1、保存用户信息 BLL_SysDatUser.Insert(txt_UserID.Text.Trim(), txt_UserName.Text.Trim(), txt_Password.Text.Trim()); //2、用户菜单信息 foreach (DataRow dr in dt_Menu.Rows) { if (dr["flag"].ToString() == "2")//新增 { BLL_SysDatUserMenuMap.Insert(dr[MenuCode.Name].ToString(), txt_UserID.Text.Trim()); } } isSucess = true; } else { //1、保存用户信息 BLL_SysDatUser.UpdateUserName(txt_UserID.Text.Trim(), txt_UserName.Text.Trim()); //2、用户菜单信息 foreach (DataRow dr in dt_Menu.Rows) { if (dr["flag"].ToString() == "2")//新增 { BLL.BLL_SysDatUserMenuMap.Insert(dr[MenuCode.Name].ToString(), txt_UserID.Text.Trim()); } else if (dr["flag"].ToString() == "3")//删除 { BLL.BLL_SysDatUserMenuMap.Delete(string.Format(@" WHERE MenuCode='{0}' AND UserID='{1}'", dr[MenuCode.Name].ToString(), txt_UserID.Text.Trim())); } } isSucess = true; } if (isSucess) { new PubUtils().ShowNoteOKMsg("保存成功!"); this.result = DialogResult.OK; this.Close(); } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_ok_Click(object sender, EventArgs e) { SysDatUser user = new SysDatUser(); //用户表对象 SysdatOrg Org = new SysdatOrg(); //用户部门表对象 if (txt_userID.Text == string.Empty) { new PubUtils().ShowNoteNGMsg("用户ID不能为空", 2, grade.RepeatedError); return; } if (txt_userName.Text == string.Empty) { new PubUtils().ShowNoteNGMsg("用户名不能为空", 2, grade.RepeatedError); return; } if (cbo_Org.Text == string.Empty) { new PubUtils().ShowNoteNGMsg("所属部门不能为空", 2, grade.RepeatedError); return; } bool isSuccess = false; user.UserID = txt_userID.Text.Trim(); //用户ID user.UserName = txt_userName.Text.Trim(); //用户名 Org.ID = Convert.ToInt32(cbo_Org.SelectedValue); //部门 if (operationType == OperationType.Add) { string strSql = string.Format("select * from SysDatUser where UserID='{0}'", txt_userID.Text.Trim()); dtUser = NMS.QueryDataTable(PubUtils.uContext, strSql); if (dtUser.Rows.Count > 0) { new PubUtils().ShowNoteNGMsg("用户ID不能重复", 2, grade.RepeatedError); return; } isSuccess = BLL_SysDatUser.InsertUserOrg(user, Org); } else { isSuccess = BLL_SysDatUser.UpdateUserOrg(user, Org); } if (isSuccess) { new PubUtils().ShowNoteOKMsg("保存成功"); this.DialogResult = DialogResult.OK; this.Close(); } }
private void FrmUserEdit_Load(object sender, EventArgs e) { if (_Action_Type == true) { txt_Password.Visible = false; lbl_Pwd.Visible = false; DataTable dt = BLL_SysDatUser.Select(string.Format(" Where UserID='{0}'", _UserID)); if (dt.Rows.Count > 0) { txt_UserID.Text = _UserID; txt_UserName.Text = dt.Rows[0]["UserName"].ToString(); //txt_Password.Text = dt.Rows[0]["Password"].ToString(); dt_Menu = BLL_SysdatMenu.Select(_UserID); dgv_Menu.DataSource = dt_Menu; } } else { dt_Menu = BLL_SysdatMenu.Select(_UserID);//空值 dgv_Menu.DataSource = dt_Menu; } }