/// <summary> /// 添加资产 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Press(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(LocationId)) { throw new Exception("请选择区域!"); } decimal price; if (btnType.Tag == null) { throw new Exception("请选择类别!"); } if (!decimal.TryParse(txtPrice.Text, out price)) { throw new Exception("请输入正确的单价!"); } AssetsInputDto assetsInputDto = new AssetsInputDto { AssId = txtAssID.Text, BuyDate = DatePickerBuy.Value, CreateUser = UserId, CurrentUser = "", DepartmentId = DepId, ExpiryDate = DatePickerExpiry.Value, Image = ImgPicture.ResourceID, LocationId = LocationId, Manager = ManagerId, ModifyUser = UserId, Name = txtName.Text, Note = txtNote.Text, Place = txtPlace.Text, Price = price, Specification = txtSpe.Text, TypeId = btnType.Tag.ToString(), Unit = txtUnit.Text, Vendor = txtVendor.Text, SN = txtSN.Text }; if (String.IsNullOrEmpty(txtPrice.Text) == false) { assetsInputDto.Price = decimal.Parse(txtPrice.Text); } ReturnInfo returnInfo = _autofacConfig.SettingService.AddAssets(assetsInputDto); if (returnInfo.IsSuccess) { ShowResult = ShowResult.Yes; Close(); Toast("添加成功.资产编号为" + returnInfo.ErrorInfo); } else { Toast(returnInfo.ErrorInfo); } } catch (Exception ex) { Toast(ex.Message); } }
/// <summary> /// 添加资产 /// </summary> /// <param name="entity"></param> /// <returns></returns> public ReturnInfo AddAssets(AssetsInputDto entity) { ReturnInfo RInfo = new ReturnInfo(); StringBuilder sb = new StringBuilder(); if (string.IsNullOrEmpty(entity.AssId)) { string MaxId = _AssetsRepository.GetMaxID(); string AssId = Helper.GenerateID("ASS", MaxId); //产生资产编号 entity.AssId = AssId; } string ValidateInfo = Helper.ValidateAssets(entity).ToString(); sb.Append(ValidateInfo); if (sb.Length == 0) { try { Assets assets = Mapper.Map <AssetsInputDto, Assets>(entity); assets.STATUS = (int)STATUS.闲置; assets.CREATEDATE = DateTime.Now; assets.MODIFYDATE = DateTime.Now; _unitOfWork.RegisterNew(assets); var pr = new AssProcessRecord { ASSID = entity.AssId, CREATEDATE = DateTime.Now, CREATEUSER = entity.CreateUser, HANDLEDATE = DateTime.Now, HANDLEMAN = entity.CreateUser, MODIFYDATE = DateTime.Now, MODIFYUSER = entity.ModifyUser, PROCESSCONTENT = entity.CreateUser + "入库了" + entity.AssId + ",数量为1", PROCESSMODE = (int)PROCESSMODE.入库, QUANTITY = 1 }; _unitOfWork.RegisterNew(pr); bool result = _unitOfWork.Commit(); RInfo.IsSuccess = result; RInfo.ErrorInfo = entity.AssId; 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); } }
private AutofacConfig _autofacConfig = new AutofacConfig();//调用配置类 private void btnSave_Press(object sender, EventArgs e) { try { AssetsInputDto assetsInputDto = new AssetsInputDto { AssId = txtAssID.Text, BuyDate = DatePickerBuy.Value, CreateUser = UserId, CurrentUser = "", DepartmentId = txtDepart.Text, ExpiryDate = DatePickerExpiry.Value, Image = ImgPicture.ResourceID, // assetsInputDto.LocationId = LocationId; LocationId = LocationId, Manager = ManagerId, ModifyUser = UserId, Name = txtName.Text, Note = txtNote.Text, Place = txtPlace.Text, Price = decimal.Parse(txtPrice.Text), Specification = txtSpe.Text, // assetsInputDto.TypeId = TypeId; TypeId = TypeId, Unit = txtUnit.Text, Vendor = txtVendor.Text, SN = txtSN.Text }; ReturnInfo returnInfo = _autofacConfig.SettingService.AddAssets(assetsInputDto); if (returnInfo.IsSuccess) { ShowResult = ShowResult.Yes; Close(); // FrmAssetsDetail assetsDetail=new FrmAssetsDetail(){AssId = returnInfo.ErrorInfo}; // Show(assetsDetail); // Close(); Toast("添加成功.资产编号为" + returnInfo.ErrorInfo); } else { Toast(returnInfo.ErrorInfo); } } catch (Exception ex) { Toast(ex.Message); } }
public static StringBuilder ValidateAssets(AssetsInputDto inputDto) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(BasicValidate(inputDto).ToString()); //额外验证 //判断SN是否重复 if (!string.IsNullOrEmpty(inputDto.SN)) { if (AssetsRepository.SNIsExists(inputDto.SN)) { stringBuilder.Append("SN" + inputDto.SN + "已经存在."); } } return(stringBuilder); }
public string AssId; //资产编号 #endregion /// <summary> /// 修改资产 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button1_Press(object sender, EventArgs e) { try { AssetsInputDto assetsInputDto = new AssetsInputDto { AssId = txtAssID.Text, BuyDate = DatePickerBuy.Value, CreateUser = UserId, CurrentUser = CurrentUserId, DepartmentId = DepId, Image = ImgPicture.ResourceID, LocationId = LocationId, Manager = ManagerId, ModifyUser = UserId, Name = txtName.Text, Note = txtNote.Text, Place = txtPlace.Text, Specification = txtSpe.Text, TypeId = TypeId, Unit = txtUnit.Text, Vendor = txtVendor.Text, ExpiryDate = DatePickerExpiry.Value, SN = txtSN.Text }; if (String.IsNullOrEmpty(txtPrice.Text) == false) { assetsInputDto.Price = decimal.Parse(txtPrice.Text); } ReturnInfo returnInfo = _autofacConfig.SettingService.UpdateAssets(assetsInputDto); if (returnInfo.IsSuccess) { ShowResult = ShowResult.Yes; Close(); Toast("修改成功."); } else { Toast(returnInfo.ErrorInfo); } } catch (Exception ex) { Toast(ex.Message); } }
public async Task UpdateAssets(AssetsInputDto input) { var assets = await db.Assetss.SingleOrDefaultAsync(m => m.Id == input.AssetsId && !m.IsDelete); if (assets == null) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "该资产信息不存在" })) }); } var department = await db.Departments.SingleOrDefaultAsync(m => m.Id == input.DepartmentId && !m.IsDelete); if (department == null) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "该部门不存在" })) }); } assets.AssetsTypeId = input.AssetsTypeId; assets.DepartmentId = input.DepartmentId; assets.Desc = input.Desc; assets.Number = input.Number; assets.CompanyId = input.CompanyId; if (await db.SaveChangesAsync() <= 0) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "更新失败" })) }); } }
/// <summary> /// 修改资产 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button1_Press(object sender, EventArgs e) { try { AssetsInputDto assetsInputDto = new AssetsInputDto { ASSID = txtAssID.Text, BUYDATE = DatePickerBuy.Value, CREATEUSER = UserId, IMAGE = ImgPicture.ResourceID, SLID = SLID, STID = STID, WAREID = WAREID, MODIFYUSER = UserId, NAME = txtName.Text, NOTE = txtNote.Text, PLACE = txtPlace.Text, SPECIFICATION = txtSpe.Text, TYPEID = TypeId, UNIT = txtUnit.Text, VENDOR = txtVendor.Text, EXPIRYDATE = DatePickerExpiry.Value, SN = txtSN.Text }; if (String.IsNullOrEmpty(txtPrice.Text) == false) { assetsInputDto.PRICE = decimal.Parse(txtPrice.Text); } ReturnInfo returnInfo = _autofacConfig.SettingService.UpdateAssets(assetsInputDto); if (returnInfo.IsSuccess) { ShowResult = ShowResult.Yes; Close(); Toast("修改成功."); } else { Toast(returnInfo.ErrorInfo); } } catch (Exception ex) { Toast(ex.Message); } }
public async Task AddAssets(AssetsInputDto input) { var department = await db.Departments.SingleOrDefaultAsync(m => m.Id == input.DepartmentId && !m.IsDelete); if (department == null) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "该部门不存在" })) }); } db.Assetss.Add(new Assets { Id = IdentityManager.NewId(), DepartmentId = input.DepartmentId, AssetsTypeId = input.AssetsTypeId, Desc = input.Desc, Number = input.Number, IsDelete = false, CompanyId = input.CompanyId }); if (await db.SaveChangesAsync() <= 0) { throw new HttpResponseException(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(new ResponseApi() { Code = EExceptionType.Implement, Message = "添加失败" })) }); } }
/// <summary> /// 更新资产信息 /// </summary> /// <param name="entity">资产信息</param> /// <returns></returns> public ReturnInfo UpdateAssets(AssetsInputDto entity) { ReturnInfo RInfo = new ReturnInfo(); StringBuilder sb = new StringBuilder(); //产生资产编号 string ValidateInfo = Helper.BasicValidate(entity).ToString(); sb.Append(ValidateInfo); if (sb.Length == 0) { try { Assets assets = _AssetsRepository.GetByID(entity.AssId).FirstOrDefault(); var originAss = Mapper.Map <Assets, AssetsOutputDto>(assets); if (assets != null) { assets.BUYDATE = entity.BuyDate; assets.CREATEUSER = entity.CreateUser; assets.DEPARTMENTID = entity.DepartmentId; assets.EXPIRYDATE = entity.ExpiryDate; assets.IMAGE = entity.Image; assets.LOCATIONID = entity.LocationId; assets.MODIFYUSER = entity.ModifyUser; assets.NAME = entity.Name; assets.NOTE = entity.Note; assets.PLACE = entity.Place; assets.PRICE = entity.Price; assets.SN = entity.SN; assets.SPECIFICATION = entity.Specification; assets.TYPEID = entity.TypeId; assets.UNIT = entity.Unit; assets.VENDOR = entity.Vendor; assets.MODIFYDATE = DateTime.Now; assets.CREATEDATE = assets.CREATEDATE; _unitOfWork.RegisterDirty(assets); } var pr = new AssProcessRecord { ASSID = entity.AssId, CREATEDATE = DateTime.Now, CREATEUSER = entity.CreateUser, HANDLEDATE = DateTime.Now, HANDLEMAN = entity.CreateUser, MODIFYDATE = DateTime.Now, MODIFYUSER = entity.ModifyUser, PROCESSCONTENT = entity.CreateUser + "修改了" + entity.AssId }; pr.PROCESSCONTENT = "修改资产" + entity.AssId + "。修改前数据:" + originAss.BuyDate + "," + originAss.DepartmentId + "," + originAss.ExpiryDate + "," + originAss.Image + "," + originAss.Name + "," + originAss.Note + "," + originAss.Place + "," + originAss.Price + "," + originAss.SN + "," + originAss.Specification + "," + originAss.TypeId + "," + originAss.Unit + "," + originAss.Vendor + " 修改后数据:" + assets.BUYDATE + "," + assets.DEPARTMENTID + "," + assets.EXPIRYDATE + "," + assets.IMAGE + "," + assets.NAME + "," + assets.NOTE + "," + assets.PLACE + "," + assets.PRICE + "," + assets.SN + "," + assets.SPECIFICATION + "," + assets.TYPEID + "," + assets.UNIT + "," + assets.VENDOR; pr.PROCESSMODE = (int)PROCESSMODE.修改内容; _unitOfWork.RegisterNew(pr); 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="entity">资产信息</param> /// <returns></returns> public ReturnInfo UpdateAssets(AssetsInputDto entity) { ReturnInfo RInfo = new ReturnInfo(); StringBuilder sb = new StringBuilder(); //产生资产编号 string ValidateInfo = Helper.BasicValidate(entity).ToString(); sb.Append(ValidateInfo); if (sb.Length == 0) { try { Assets assets = _AssetsRepository.GetByID(entity.ASSID).FirstOrDefault(); if (assets != null) { assets.BUYDATE = entity.BUYDATE; assets.CREATEUSER = entity.CREATEUSER; assets.EXPIRYDATE = entity.EXPIRYDATE; assets.IMAGE = entity.IMAGE; assets.SLID = entity.SLID; assets.MODIFYUSER = entity.MODIFYUSER; assets.NAME = entity.NAME; assets.NOTE = entity.NOTE; assets.PLACE = entity.PLACE; assets.PRICE = entity.PRICE; assets.SN = entity.SN; assets.SPECIFICATION = entity.SPECIFICATION; assets.TYPEID = entity.TYPEID; assets.UNIT = entity.UNIT; assets.VENDOR = entity.VENDOR; assets.MODIFYDATE = DateTime.Now; assets.CREATEDATE = assets.CREATEDATE; _unitOfWork.RegisterDirty(assets); } var pr = new AssProcessRecord { ASSID = entity.ASSID, CREATEDATE = DateTime.Now, CREATEUSER = entity.CREATEUSER, HANDLEDATE = DateTime.Now, HANDLEMAN = entity.CREATEUSER, MODIFYDATE = DateTime.Now, MODIFYUSER = entity.MODIFYUSER, PROCESSCONTENT = entity.CREATEUSER + "修改了" + entity.ASSID }; ; pr.PROCESSMODE = (int)PROCESSMODE.修改内容; _unitOfWork.RegisterNew(pr); 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="entity"></param> // /// <returns></returns> // public ReturnInfo AddAssetsSN(AssetsSNInputDto entity) // { // // throw new System.NotImplementedException(); // } // /// <summary> // /// 删除资产 // /// </summary> // /// <param name="entity"></param> // /// <returns></returns> // public ReturnInfo DeleteAssets(AssetsInputDto entity) // { // throw new System.NotImplementedException(); // } // /// <summary> // /// 删除序列号 // /// </summary> // /// <param name="entity"></param> // /// <returns></returns> // public ReturnInfo DeleteAssetsSN(AssetsSNInputDto entity) // { // throw new System.NotImplementedException(); // } // /// <summary> // /// 入库 // /// </summary> // /// <param name="inStorage"></param> // /// <returns></returns> // public ReturnInfo InStorage(AssetsInStorageInputDto inStorage) // { // throw new NotImplementedException(); // } // // /// <summary> // /// 冲销 // /// </summary> // /// <param name="writeOff"></param> // /// <returns></returns> // public ReturnInfo WriteOff(AssetsWriteOffInputDto writeOff) // { // throw new NotImplementedException(); // } public ReturnInfo UpdateAssets(AssetsInputDto entity) { ReturnInfo RInfo = new ReturnInfo(); StringBuilder sb = new StringBuilder(); // if (inStorageInput.Quantity<0) // { // sb.Append("请输入正确的数量。"); // } //产生资产编号 string ValidateInfo = Helper.BasicValidate(entity).ToString(); sb.Append(ValidateInfo); if (sb.Length == 0) { try { Assets assets = _AssetsRepository.GetByID(entity.AssId).FirstOrDefault(); // Assets assets = Mapper.Map<AssetsInputDto, Assets>(entity); // assets = Mapper.Map<AssetsInputDto, Assets>(entity); // assets.CreateDate = DateTime.Now; if (assets != null) { assets.BUYDATE = entity.BuyDate; assets.CREATEUSER = entity.CreateUser; // assets.CURRENTUSER = entity.CurrentUser; assets.DEPARTMENTID = entity.DepartmentId; assets.EXPIRYDATE = entity.ExpiryDate; assets.IMAGE = entity.Image; assets.LOCATIONID = entity.LocationId; // assets.MANAGER = entity.Manager; assets.MODIFYUSER = entity.ModifyUser; assets.NAME = entity.Name; assets.NOTE = entity.Note; assets.PLACE = entity.Place; assets.PRICE = entity.Price; assets.SN = entity.SN; assets.SPECIFICATION = entity.Specification; assets.TYPEID = entity.TypeId; assets.UNIT = entity.Unit; assets.VENDOR = entity.Vendor; assets.MODIFYDATE = DateTime.Now; assets.CREATEDATE = assets.CREATEDATE; _unitOfWork.RegisterDirty(assets); } var pr = new AssProcessRecord { ASSID = entity.AssId, CREATEDATE = DateTime.Now, CREATEUSER = entity.CreateUser, HANDLEDATE = DateTime.Now, HANDLEMAN = entity.CreateUser, MODIFYDATE = DateTime.Now, MODIFYUSER = entity.ModifyUser, PROCESSCONTENT = entity.CreateUser + "修改了" + entity.AssId }; // pr.HANDLEMAN = "18875878973"; // pr.PRId = ""; ; pr.PROCESSMODE = (int)PROCESSMODE.修改内容; _unitOfWork.RegisterNew(pr); bool result = _unitOfWork.Commit(); RInfo.IsSuccess = result; RInfo.ErrorInfo = sb.ToString(); return(RInfo); // if (inStorageInput.Quantity>0) // { // RInfo = InStorage(inStorageInput); // return RInfo; // } // else // { // 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="sender"></param> /// <param name="e"></param> private void Button1_Press(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(txtAssID.Text)) { throw new Exception("请输入唯一号."); } if (string.IsNullOrEmpty(txtSN.Text)) { throw new Exception("请输入SN号."); } if (string.IsNullOrEmpty(btnType.Text)) { throw new Exception("请选择资产类型."); } if (string.IsNullOrEmpty(btnBrand.Text)) { throw new Exception("请选择品牌型号."); } if (string.IsNullOrEmpty(txtSpe.Text)) { throw new Exception("请选择机房."); } if (string.IsNullOrEmpty(txtLocation.Text)) { throw new Exception("请输入正确的位置."); } if (string.IsNullOrEmpty(txtStatus1.Text)) { throw new Exception("请选择状态."); } if (string.IsNullOrEmpty(txtPayman1.Text)) { throw new Exception("请选择挂账人."); } AssetsInputDto assetsInputDto = new AssetsInputDto { //id = id, uuid = txtAssID.Text, IP = txtName.Text, asset_number = txtNUm.Text, SN = txtSN.Text, //TypeName = btnType.Text, //Brandname = btnBrand.Text, //LocationName = txtSpe.Text, Position = txtLocation.Text, Status = Status, //Payman = txtPayman1.Text, //Project = txtPro1.Text, //Team = txtTeam1.Text, //Role = txtRole1.Text, //CurrentUserName = txtUserman1.Text, //give_time = txtBordate1.Tag != null ? txtBordate1.Value : new Nullable<DateTime>(), //return_time = txtRedate1.Tag != null ? txtRedate1.Value : new Nullable<DateTime>(), give_time = give_time, return_time = return_time, remark = txtNote.Text, asset_type_id = TypeId, brand_id = Brandid, machine_room_id = LocationId, pay_man_id = Pay_man_id, //project_id = popPro.Selection != null ? Project_id : null, //role_id = popRole.Selection != null ? Role_id : null, //team_id = popTeam.Selection != null ? Team_id : null, //use_man_id = popUser.Selection != null ? CurrentUser : null, project_id = Project_id, role_id = Role_id, team_id = Team_id, use_man_id = CurrentUser, modify_date = DateTime.Now }; //MessageBox.Show(txtRedate1.Value.ToString()); string username = Client.Session["local_username"].ToString(); ReturnInfo returnInfo = _autofacConfig.SettingService.UpdateAssets(assetsInputDto, username); if (returnInfo.IsSuccess) { //ShowResult = ShowResult.No; ShowResult = ShowResult.Yes; Close(); Toast("修改成功."); } else { Toast(returnInfo.ErrorInfo); } } catch (Exception ex) { Toast(ex.Message); } }
/// <summary> /// 添加资产 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Press(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(txtAssID.Text)) { throw new Exception("请输入唯一号."); } if (string.IsNullOrEmpty(txtSN.Text)) { throw new Exception("请输入SN号."); } if (btnBrand.Text == "选择(必填) > ") { throw new Exception("请选择品牌型号."); } if (btnType.Text == "选择(必填) > ") { throw new Exception("请选择资产类型."); } if (txtSpe.Text == "选择(必填) > ") { throw new Exception("请选择机房."); } if (string.IsNullOrEmpty(txtLocation.Text)) { throw new Exception("请输入正确的位置."); } if (txtStatus1.Text == "选择(必填) > ") { throw new Exception("请选择状态."); } if (txtPayman1.Text == "选择(必填) > ") { throw new Exception("请选择挂账人."); } List <string> uuid_list = _autofacConfig.SettingService.GetAlluuid(); if (uuid_list.Contains(txtAssID.Text)) { throw new Exception("唯一号为" + txtAssID.Text + "的资产已存在"); } //MessageBox.Show(btnBrand.Tag.ToString()); AssetsInputDto assetsInputDto = new AssetsInputDto { //id = 0, uuid = txtAssID.Text, IP = txtName.Text, asset_number = txtNUm.Text, SN = txtSN.Text, //TypeName = btnType.Text, //Brandname = btnBrand.Text, //LocationName = txtSpe.Text, Position = txtLocation.Text, Status = Status, //Payman = txtPayman1.Text, //Project = txtPro1.Text, //Team = txtTeam1.Text, //Role = txtRole1.Text, //CurrentUserName = txtUserman1.Text, //BorrowDate = txtBordate1.Value, //ReturnDate = txtRedate1.Value, give_time = txtBordate1.Tag != null ? txtBordate1.Value : new Nullable <DateTime>(), return_time = txtRedate1.Tag != null ? txtRedate1.Value : new Nullable <DateTime>(), //give_time = DateTime.Now, //return_time = DateTime.Now, remark = txtNote.Text, asset_type_id = TypeId, brand_id = Brandid, machine_room_id = LocationId, pay_man_id = Pay_man_id, project_id = popPro.Selection != null ? Project_id : null, role_id = popRole.Selection != null ? Role_id : null, team_id = popTeam.Selection != null ? Team_id : null, use_man_id = popUser.Selection != null ? CurrentUser : null, //project_id = (bool)txtPro1.Tag == true ? Project_id : null, //role_id = (bool)txtRole1.Tag == true ? Role_id : null, //team_id = (bool)txtTeam1.Tag == true ? Team_id : null, //use_man_id = (bool)txtUserman1.Tag == true ? CurrentUser : null, modify_date = DateTime.Now }; string username = Client.Session["local_username"].ToString(); ReturnInfo returnInfo = _autofacConfig.SettingService.AddAssets(assetsInputDto, username); if (returnInfo.IsSuccess) { ShowResult = ShowResult.No; Close(); Toast("添加成功.资产唯一号为" + returnInfo.ErrorInfo); } else { Toast(returnInfo.ErrorInfo); } } catch (Exception ex) { Toast(ex.Message); } //try //{ // if (string.IsNullOrEmpty(LocationId)) // { // throw new Exception("请选择区域!"); // } // decimal price; // if(btnType.Tag == null) // { // throw new Exception("请选择类别!"); // } // if (!decimal.TryParse(txtPrice.Text, out price)) // { // throw new Exception("请输入正确的单价!"); // } // AssetsInputDto assetsInputDto = new AssetsInputDto // { // AssId = txtAssID.Text, // BuyDate = DatePickerBuy.Value, // CreateUser = UserId, // CurrentUser = "", // DepartmentId = DepId, // ExpiryDate = DatePickerExpiry.Value, // Image = ImgPicture.ResourceID, // LocationId = LocationId, // Manager =ManagerId, // ModifyUser = UserId, // Name = txtName.Text, // Note = txtNote.Text, // Place = txtPlace.Text, // Price = price, // Specification = txtSpe.Text, // TypeId = btnType.Tag.ToString(), // Unit = txtUnit.Text, // Vendor = txtVendor.Text, // SN = txtSN.Text // }; // if (String.IsNullOrEmpty(txtPrice.Text) == false) // assetsInputDto.Price = decimal.Parse(txtPrice.Text); // ReturnInfo returnInfo = _autofacConfig.SettingService.AddAssets(assetsInputDto); // if (returnInfo.IsSuccess) // { // ShowResult = ShowResult.Yes; // Close(); // Toast("添加成功.资产编号为"+returnInfo.ErrorInfo); // } // else // { // Toast(returnInfo.ErrorInfo); // } //} //catch (Exception ex) //{ // Toast(ex.Message); //} }
/// <summary> /// 更新资产信息 /// </summary> /// <param name="entity">资产信息</param> /// <returns></returns> public ReturnInfo UpdateAssets(AssetsInputDto entity, string username) { ReturnInfo RInfo = new ReturnInfo(); StringBuilder sb = new StringBuilder(); //产生资产编号 //string ValidateInfo = Helper.BasicValidate(entity).ToString(); //sb.Append(ValidateInfo); if (sb.Length == 0) { try { cmdb_asset assets = _AssetsRepository.GetByID(entity.SN).AsNoTracking().FirstOrDefault(); //var originAss = Mapper.Map<cmdb_asset, AssetsOutputDto>(assets); if (assets != null) { //assets.id = entity.id; assets.uuid = entity.uuid; assets.IP = entity.IP; assets.sn = entity.SN; assets.asset_number = entity.asset_number; assets.position = entity.Position; assets.status = (short)entity.Status; //assets.give_time = entity.BorrowDate; //assets.return_time = entity.BorrowDate; if (entity.give_time.HasValue) { assets.give_time = entity.give_time; } else { assets.give_time = null; } if (entity.return_time.HasValue) { assets.return_time = entity.return_time; } else { assets.return_time = null; } assets.remark = entity.remark; assets.modify_date = DateTime.Now; assets.asset_type_id = entity.asset_type_id; assets.brand_id = entity.brand_id; assets.machine_room_id = entity.machine_room_id; assets.pay_man_id = entity.pay_man_id; assets.project_id = entity.project_id; assets.role_id = entity.role_id; assets.team_id = entity.team_id; assets.use_man_id = entity.use_man_id; _unitOfWork.RegisterDirty(assets); } cmdb_assettype type = _assetsTypeRepository.GetByID(entity.asset_type_id).AsNoTracking().FirstOrDefault(); string type_name = type.name; var pr = new cmdb_modityhistory { username = username, m_time = DateTime.Now, content = "修改--> 资产-->" + type_name + "--> 唯一号:" + assets.uuid, }; _unitOfWork.RegisterNew(pr); 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="entity"></param> /// <returns></returns> public ReturnInfo AddAssets(AssetsInputDto entity, string dealman) { ReturnInfo RInfo = new ReturnInfo(); StringBuilder sb = new StringBuilder(); //if (entity.id == 0) //{ // int MaxId = _AssetsRepository.GetMaxID(); // int id = MaxId + 1; // //string AssId = Helper.GenerateID("ASS", MaxId); // //产生资产编号 // entity.id = id; //} string ValidateInfo = Helper.ValidateAssets(entity).ToString(); sb.Append(ValidateInfo); if (sb.Length == 0) { try { cmdb_asset assets = Mapper.Map <AssetsInputDto, cmdb_asset>(entity); //Console.WriteLine(assets.IP); //Console.WriteLine(assets.asset_number); //Console.WriteLine(assets.sn); //Console.WriteLine(assets.position); //Console.WriteLine(assets.status); //Console.WriteLine(assets.give_time); //Console.WriteLine(assets.return_time); //Console.WriteLine(assets.remark); //Console.WriteLine(assets.asset_type_id); //Console.WriteLine(assets.brand_id); //Console.WriteLine(assets.machine_room_id); //Console.WriteLine(assets.pay_man_id); //Console.WriteLine(assets.project_id); //Console.WriteLine(assets.role_id); //Console.WriteLine(assets.use_man_id); //Console.WriteLine(assets.team_id); //Console.WriteLine(assets.modify_date); //assets.status = (int)status.闲置; //assets.MODIFYDATE=DateTime.Now; _unitOfWork.RegisterNew(assets); cmdb_assettype type = _assetsTypeRepository.GetByID(entity.asset_type_id).AsNoTracking().FirstOrDefault(); string type_name = type.name; var pr = new cmdb_modityhistory { username = dealman, m_time = DateTime.Now, content = "添加--> 资产-->" + type_name + "--> 唯一号:" + assets.uuid, }; _unitOfWork.RegisterNew(pr); bool result = _unitOfWork.Commit(); RInfo.IsSuccess = result; RInfo.ErrorInfo = entity.uuid; 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); } }