private void Save() { int Id = 0; int.TryParse(gridView.GetRowCellValue(gridView.FocusedRowHandle, "Id").ToString(), out Id); if (string.IsNullOrEmpty(gridView.GetRowCellValue(gridView.FocusedRowHandle, "Name").ToString())) { MessageBox.Show("Vui lòng nhập tên bộ phận.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrEmpty(gridView.GetRowCellValue(gridView.FocusedRowHandle, "BaseLabours").ToString()) && Convert.ToDouble(gridView.GetRowCellValue(gridView.FocusedRowHandle, "BaseLabours").ToString()) <= 0) { MessageBox.Show("lao động định biên phải lớn hơn 0, hoặc bạn nhập sai định dạng dữ liệu.\n", "Lỗi nhập liệu"); } else { var obj = new P_Department(); obj.Id = Id; obj.Name = gridView.GetRowCellValue(gridView.FocusedRowHandle, "Name").ToString(); obj.BaseLabours = Convert.ToInt32(gridView.GetRowCellValue(gridView.FocusedRowHandle, "BaseLabours").ToString()); var rs = BLLDepartment.Instance.InsertOrUpdate(obj); if (rs.IsSuccess) { LoadGrid(); } else { MessageBox.Show(rs.Messages[0].msg, rs.Messages[0].Title, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// 新增 /// </summary> /// <param name="value"></param> /// <returns></returns> public MessageEntity Post([FromBody] P_Department value) { if (value == null) { return(MessageEntityTool.GetMessage(ErrorType.FieldError)); } return(_departmentDAL.Add(value)); }
/// <summary> /// 修改 /// </summary> /// <param name="iDeptID"></param> /// <param name="value"></param> /// <returns></returns> public MessageEntity Put(int iDeptID, [FromBody] P_Department value) { if (value == null) { return(MessageEntityTool.GetMessage(ErrorType.FieldError)); } value.iDeptID = iDeptID; return(_departmentDAL.Update(value)); }
public MessageEntity Update(P_Department department) { if (IsExist(department)) { return(MessageEntityTool.GetMessage(ErrorType.NotUnique, "已存在相同部门名称")); } base.UpdateEntity(department, ConnectionFactory.DBConnNames.GisPlateform, out MessageEntity messageEntity); return(messageEntity); }
public MessageEntity Delete(P_Department department) { if (IsExistUser(department)) { return(MessageEntityTool.GetMessage(ErrorType.OprationError, "", "该部门下存在用户,不允许删除")); } base.DeleteEntity(department, ConnectionFactory.DBConnNames.GisPlateform, out MessageEntity messageEntity); return(messageEntity); }
public ResponseBase InsertOrUpdate(P_Department objModel) { var rs = new ResponseBase(); using (var db = new PMSEntities()) { try { if (CheckName(objModel.Id, objModel.Name.Trim(), db) != null) { rs.IsSuccess = false; rs.Messages.Add(new Message() { msg = "Tên Bộ phận đã tồn tại. Vui lòng chọn lại tên khác", Title = "Lỗi trùng tên" }); } else { if (objModel.Id == 0) { db.P_Department.Add(objModel); rs.IsSuccess = true; } else { var oldObj = db.P_Department.FirstOrDefault(x => !x.IsDeleted && x.Id == objModel.Id); if (oldObj != null) { oldObj.Name = objModel.Name; oldObj.BaseLabours = objModel.BaseLabours; rs.IsSuccess = true; } else { rs.IsSuccess = false; rs.Messages.Add(new Message() { msg = "Bộ phận đang thao tác không tồn tại hoặc đã bị xóa. Vui lòng chọn lại tên khác", Title = "Lỗi trùng tên" }); } } if (rs.IsSuccess) { db.SaveChanges(); rs.IsSuccess = true; } } } catch (Exception) { } } return(rs); }
public Model.P_Department ToPOCO() { var o = new P_Department() { ID = this.ID, Name = this.Name, ParentID = this.ParentID, IsActive = this.IsActive, Remark = this.Remark, SN = this.SN, DispatchSationID = this.DispatchSationID, DispatchSubCenterID = this.DispatchSubCenterID }; return o; }
public Model.P_Department ToPOCO() { var o = new P_Department() { ID = this.ID, Name = this.Name, ParentID = this.ParentID, IsActive = this.IsActive, Remark = this.Remark, SN = this.SN, DispatchSationID = this.DispatchSationID, DispatchSubCenterID = this.DispatchSubCenterID }; return(o); }
//获取combobox部门名称 public object GetDepList() { List <P_Department> list = new List <P_Department>(); StringBuilder strSQL = new StringBuilder(); strSQL.Append(@"select ID,Name from P_Department where IsActive = 1"); DataSet ds = SqlHelper.ExecuteDataSet(SqlHelper.MainConnectionString, CommandType.Text, strSQL.ToString(), null); if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { P_Department info = new P_Department(); info.ID = Convert.ToInt32(dr["ID"]); info.Name = dr["Name"].ToString(); list.Add(info); } } return(list); }
/// <summary> /// 该部门下是否存在用户 /// </summary> /// <param name="role"></param> /// <returns></returns> public bool IsExistUser(P_Department department) { using (var conn = ConnectionFactory.GetDBConn(ConnectionFactory.DBConnNames.GisPlateform)) { try { string sql = $@"select count(0) as count from P_Admin p where p.iDeptID = {department.iDeptID}"; List <dynamic> pointcc = conn.Query <dynamic>(sql).ToList(); if (pointcc[0].count > 0) { return(true); } else { return(false); } } catch (Exception e) { return(false); } } }