private void btnSave_Click_1(object sender, EventArgs e) { if (CheckInput()) { if (_currentDepartmentTable == null) { _currentDepartmentTable = new BaseDepartmentTable(); } _currentDepartmentTable.CODE = txtCode.Text; _currentDepartmentTable.NAME = txtName.Text; _currentDepartmentTable.PARENT_CODE = txtParentCode.Text; _currentDepartmentTable.COMPANY_CODE = txtCompanyCode.Text; _currentDepartmentTable.LAST_UPDATE_USER = _userInfo.CODE; try { if (bDepartment.Exists(txtCode.Text.Trim())) { bDepartment.Update(_currentDepartmentTable); } else { _currentDepartmentTable.CREATE_USER = _userInfo.CODE; bDepartment.Add(_currentDepartmentTable); } } catch (Exception ex) { //log.error MessageBox.Show(""); return; } result = DialogResult.OK; this.Close(); } }
private void txtCode_Leave(object sender, EventArgs e) { //判断编号是否已存在 BaseDepartmentTable DepartmentCode = new BaseDepartmentTable(); DepartmentCode = bDepartment.GetModel(txtCode.Text); if (DepartmentCode != null) { txtCode.Focus(); txtCode.Text = ""; MessageBox.Show("部门编号已存在,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
/// <summary> /// 获得当前选中的数据 /// </summary> private void GetCurrentSelectedTable() { try { string code = dgvData.SelectedRows[0].Cells["CODE"].Value.ToString(); if (code != "") { _currentDepartmentTable = bDepartment.GetModel(code); } } catch (Exception ex) { } if (_currentDepartmentTable == null || _currentDepartmentTable.CODE == null || "".Equals(_currentDepartmentTable.CODE)) { _currentDepartmentTable = null; } }
/// <summary> /// 得到一个对象实体 /// </summary> public BaseDepartmentTable GetModel(string CODE) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 CODE,NAME,PARENT_CODE,COMPANY_CODE,STATUS_FLAG,CREATE_USER,CREATE_DATE_TIME,LAST_UPDATE_USER,LAST_UPDATE_TIME,PARENT_NAME,COMPANY_NAME from base_department_view "); strSql.Append(" where CODE=@CODE "); strSql.AppendFormat(" and STATUS_FLAG <> {0}", CConstant.DELETE_STATUS); SqlParameter[] parameters = { new SqlParameter("@CODE", SqlDbType.VarChar, 50) }; parameters[0].Value = CODE; BaseDepartmentTable model = new BaseDepartmentTable(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { model.CODE = ds.Tables[0].Rows[0]["CODE"].ToString(); model.NAME = ds.Tables[0].Rows[0]["NAME"].ToString(); model.PARENT_CODE = ds.Tables[0].Rows[0]["PARENT_CODE"].ToString(); model.COMPANY_CODE = ds.Tables[0].Rows[0]["COMPANY_CODE"].ToString(); if (ds.Tables[0].Rows[0]["STATUS_FLAG"].ToString() != "") { model.STATUS_FLAG = int.Parse(ds.Tables[0].Rows[0]["STATUS_FLAG"].ToString()); } model.CREATE_USER = ds.Tables[0].Rows[0]["CREATE_USER"].ToString(); if (ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString() != "") { model.CREATE_DATE_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString()); } model.LAST_UPDATE_USER = ds.Tables[0].Rows[0]["LAST_UPDATE_USER"].ToString(); if (ds.Tables[0].Rows[0]["LAST_UPDATE_TIME"].ToString() != "") { model.LAST_UPDATE_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["LAST_UPDATE_TIME"].ToString()); } model.PARENT_NAME = ds.Tables[0].Rows[0]["PARENT_NAME"].ToString(); model.COMPANY_NAME = ds.Tables[0].Rows[0]["COMPANY_NAME"].ToString(); return(model); } else { return(null); } }
private void txtParentCode_Leave(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.txtParentCode.Text.Trim())) { BaseDepartmentTable Parent = new BaseDepartmentTable(); Parent = bDepartment.GetModel(this.txtParentCode.Text); if (Parent == null || "".Equals(Parent)) { txtParentCode.Focus(); txtParentCode.Text = ""; txtParentName.Text = ""; MessageBox.Show("上级编号不存在,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { txtParentName.Text = Parent.NAME; } } }
/// <summary> /// 打开新窗口 /// </summary> private void OpenDialogFrm(int mode) { if (mode == CConstant.MODE_NEW || _currentDepartmentTable != null) { FrmDepartmentDialog frm = new FrmDepartmentDialog(); frm.UserInfo = _userInfo; frm.CurrentDepartmentTable = _currentDepartmentTable; frm.Mode = mode; DialogResult resule = frm.ShowDialog(this); if (resule == DialogResult.OK && isSearch) { Search(this.pgControl.GetCurrentPage()); } frm.Dispose(); } else { //MessageBox.Show("请选择正确的行!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } _currentDepartmentTable = null; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(BaseDepartmentTable model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update BASE_DEPARTMENT set "); strSql.Append("NAME=@NAME,"); strSql.Append("PARENT_CODE=@PARENT_CODE,"); strSql.Append("COMPANY_CODE=@COMPANY_CODE,"); strSql.Append("STATUS_FLAG=@STATUS_FLAG,"); strSql.Append("LAST_UPDATE_USER=@LAST_UPDATE_USER,"); strSql.Append("LAST_UPDATE_TIME=GETDATE()"); strSql.Append(" where CODE=@CODE "); SqlParameter[] parameters = { new SqlParameter("@CODE", SqlDbType.VarChar, 20), new SqlParameter("@NAME", SqlDbType.NVarChar, 100), new SqlParameter("@PARENT_CODE", SqlDbType.VarChar, 20), new SqlParameter("@COMPANY_CODE", SqlDbType.VarChar, 20), new SqlParameter("@STATUS_FLAG", SqlDbType.Int, 4), new SqlParameter("@LAST_UPDATE_USER", SqlDbType.VarChar, 20) }; parameters[0].Value = model.CODE; parameters[1].Value = model.NAME; parameters[2].Value = model.PARENT_CODE; parameters[3].Value = model.COMPANY_CODE; parameters[4].Value = CConstant.NORMAL_STATUS; parameters[5].Value = model.LAST_UPDATE_USER; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 删除 /// </summary> private void MasterToolBar_DoDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("确定要删除吗?", this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.OK) { try { GetCurrentSelectedTable(); if (_currentDepartmentTable != null) { bDepartment.Delete(_currentDepartmentTable.CODE); Search(this.pgControl.GetCurrentPage()); } else { MessageBox.Show("请选择正确的行!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show("删除失败,请重试或与系统管理员联系。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } _currentDepartmentTable = null; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(BaseDepartmentTable model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(BaseDepartmentTable model) { return(dal.Add(model)); }