/// <summary> /// 提交操作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Press(object sender, EventArgs e) { try { if (String.IsNullOrEmpty(txtSTID.Text)) { throw new Exception("类型编号不能为空"); } if (String.IsNullOrEmpty(txtSTName.Text)) { throw new Exception("类型名称不能为空"); } WHStorageTypeInputDto inputDto = new WHStorageTypeInputDto { WAREID = txtWareID.Text, ISENABLE = switchIsEnable.Checked ? 1 : 0, NAME = txtSTName.Text, STID = txtSTID.Text, MODIFYUSER = Client.Session["UserID"].ToString() }; if (isCreate) { inputDto.CREATEUSER = Client.Session["UserID"].ToString(); //添加 ReturnInfo rInfo = autofacConfig.wareHouseService.AddWhStorageType(inputDto); if (rInfo.IsSuccess) { this.Close(); Toast("创建仓库类型成功"); //刷新页面数据 ((frmWHStorgageType)Form).Bind(); } else { throw new Exception(rInfo.ErrorInfo); } } else if (isEdit) { //编辑 ReturnInfo rInfo = autofacConfig.wareHouseService.UpdateWhStorageType(inputDto); if (rInfo.IsSuccess) { this.Close(); Toast("编辑仓库类型成功"); //刷新页面数据 ((frmWHStorageLocation)Form).Bind(); } else { throw new Exception(rInfo.ErrorInfo); } } } catch (Exception ex) { Form.Toast(ex.Message); } }
/// <summary> /// 添加存储类型 /// </summary> /// <param name="inputDto">存储类型信息</param> /// <returns></returns> public ReturnInfo AddWhStorageType(WHStorageTypeInputDto inputDto) { //验证 ReturnInfo rInfo = new ReturnInfo(); StringBuilder sb = new StringBuilder(); sb.Append(Helper.BasicValidate(inputDto).ToString()); if (sb.Length == 0) { bool isExist = _wHStorageTypeReposity.IsExist(inputDto.WAREID, inputDto.STID); if (isExist) { rInfo.IsSuccess = false; rInfo.ErrorInfo = "已经存在!"; return(rInfo); } var whStorageType = Mapper.Map <WHStorageTypeInputDto, WHStorageType>(inputDto); whStorageType.CREATEDATE = DateTime.Now; whStorageType.MODIFYDATE = DateTime.Now; try { _unitOfWork.RegisterNew(whStorageType); bool result = _unitOfWork.Commit(); rInfo.IsSuccess = result; rInfo.ErrorInfo = sb.ToString(); return(rInfo); } catch (Exception ex) { _unitOfWork.Rollback(); sb.Append(ex.Message); rInfo.IsSuccess = false; rInfo.ErrorInfo = sb.ToString(); return(rInfo); } } else { rInfo.IsSuccess = false; rInfo.ErrorInfo = sb.ToString(); return(rInfo); } }
/// <summary> /// 更新存储类型 /// </summary> /// <param name="inputDto">存储类型信息</param> /// <returns></returns> public ReturnInfo UpdateWhStorageType(WHStorageTypeInputDto inputDto) { ReturnInfo RInfo = new ReturnInfo(); StringBuilder sb = new StringBuilder(); string ValidateInfo = Helper.BasicValidate(inputDto).ToString(); sb.Append(ValidateInfo); if (sb.Length == 0) { try { WHStorageType whStorageType = _wHStorageTypeReposity.GetById(inputDto.WAREID, inputDto.STID).FirstOrDefault(); if (whStorageType != null) { whStorageType.NAME = inputDto.NAME; whStorageType.ISENABLE = inputDto.ISENABLE; whStorageType.MODIFYUSER = inputDto.MODIFYUSER; whStorageType.MODIFYDATE = DateTime.Now; _unitOfWork.RegisterDirty(whStorageType); } bool result = _unitOfWork.Commit(); RInfo.IsSuccess = result; RInfo.ErrorInfo = sb.ToString(); return(RInfo); } catch (Exception ex) { _unitOfWork.Rollback(); sb.Append(ex.Message); RInfo.IsSuccess = false; RInfo.ErrorInfo = sb.ToString(); return(RInfo); } } else { RInfo.IsSuccess = false; RInfo.ErrorInfo = sb.ToString(); return(RInfo); } }