/// <summary> /// 绑定数据 /// </summary> private void Bind() { try { AssTemplate outputDto = _autofacConfig.SettingService.GetAtbyId(TempId); if (outputDto != null) { txtAssID.Text = outputDto.TEMPLATEID; txtName.Text = outputDto.NAME; txtPrice.Text = outputDto.PRICE.ToString(); txtSpe.Text = outputDto.SPECIFICATION; txtUnit.Text = outputDto.UNIT; txtVendor.Text = outputDto.VENDOR; ImgPicture.ResourceID = outputDto.IMAGE; txtNote.Text = outputDto.NOTE; var type = _autofacConfig.assTypeService.GetByID(outputDto.TYPEID); btnType.Text = type.NAME; btnType.Tag = outputDto.TYPEID; } } catch (Exception ex) { Toast(ex.Message); } }
/// <summary> /// 修改资产模板 /// </summary> /// <param name="inputDto">资产模板信息</param> /// <returns></returns> public ReturnInfo UpdateAssTemplate(AssTemplateInputDto inputDto) { ReturnInfo RInfo = new ReturnInfo(); StringBuilder sb = new StringBuilder(); //产生资产编号 string ValidateInfo = Helper.BasicValidate(inputDto).ToString(); sb.Append(ValidateInfo); if (sb.Length == 0) { try { AssTemplate assets = _assTemplateRepository.GetById(inputDto.TEMPLATEID).FirstOrDefault(); if (assets != null) { assets.IMAGE = inputDto.IMAGE; assets.NAME = inputDto.NAME; assets.NOTE = inputDto.NOTE; assets.PRICE = inputDto.PRICE; assets.SPECIFICATION = inputDto.SPECIFICATION; assets.TYPEID = inputDto.TYPEID; assets.UNIT = inputDto.UNIT; assets.VENDOR = inputDto.VENDOR; _unitOfWork.RegisterDirty(assets); } 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 bsAss_BarcodeScanned(object sender, BarcodeResultArgs e) { try { if (string.IsNullOrEmpty(e.error)) { String templateId = e.Value; AssTemplate assTemplate = _autofacConfig.SettingService.GetAtbyId(templateId); if (assTemplate != null) { if (TemplateIds.Contains(templateId)) { throw new Exception("该模板已添加,请勿重复添加!"); } else { TemplateIds.Add(templateId); decimal price = 0; if (assTemplate.PRICE != null) { price = assTemplate.PRICE.Value; } AssRowInputDto rowInputDto = new AssRowInputDto { TEMPLATEID = templateId, QUANT = 0, PRICE = 0, TPRICE = price, IMAGE = assTemplate.IMAGE, NAME = assTemplate.NAME }; Rows.Add(rowInputDto); Bind(); } } else { throw new Exception("编号为" + templateId + "模板不存在,请检查!"); } } } catch (Exception ex) { Toast(ex.Message); } }
/// <summary> /// 选中资产模板时 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void popTemp_Selected(object sender, EventArgs e) { try { if (popTemp.Selection != null) { btnTemplate.Text = popTemp.Selection.Text + " > "; btnTemplate.Tag = popTemp.Selection.Value; AssTemplate tempOutput = _autofacConfig.SettingService.GetAtbyId(btnTemplate.Tag.ToString()); Image = tempOutput.IMAGE; GetTotal(); } } catch (Exception ex) { Toast(ex.Message); } }
/// <summary> /// 添加资产模板 /// </summary> /// <param name="inputDto">资产模板信息</param> /// <returns></returns> public ReturnInfo AddAssTemplate(AssTemplateInputDto inputDto) { ReturnInfo RInfo = new ReturnInfo(); StringBuilder sb = new StringBuilder(); if (string.IsNullOrEmpty(inputDto.TEMPLATEID)) { string MaxId = _assTemplateRepository.GetMaxId(); string atId = Helper.GenerateIDEx("AT", MaxId); //产生资产编号 inputDto.TEMPLATEID = atId; } string ValidateInfo = Helper.BasicValidate(inputDto).ToString(); sb.Append(ValidateInfo); if (sb.Length == 0) { try { AssTemplate assets = Mapper.Map <AssTemplateInputDto, AssTemplate>(inputDto); _unitOfWork.RegisterNew(assets); bool result = _unitOfWork.Commit(); RInfo.IsSuccess = result; RInfo.ErrorInfo = inputDto.TEMPLATEID; 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="UserId">用户编号</param> /// <returns></returns> public DataTable GetOrders(string UserId) { var area = _assPurchaseOrderRepository.GetAll(); if (!string.IsNullOrEmpty(UserId)) { area = area.Where(a => a.PURCHASER == UserId); } var list = from assPurchaseOrder in area join user in SMOWMSDbContext.coreUsers on assPurchaseOrder.PURCHASER equals user.USER_ID orderby assPurchaseOrder.CREATEDATE descending select new AssPOListOutputDto() { REALID = assPurchaseOrder.REALID, POID = assPurchaseOrder.POID, NAME = assPurchaseOrder.NAME, PURCHASER = assPurchaseOrder.PURCHASER, PURCHASERNAME = user.USER_NAME, STATUS = assPurchaseOrder.STATUS, STATUSNAME = "", CREATEDATE = assPurchaseOrder.CREATEDATE, Time = "" }; var temTable = LINQToDataTable.ToDataTable(list); foreach (DataRow row in temTable.Rows) { AssPurchaseOrderRow assPurchaseOrderRow = _assPoRowRepository.GetByPOID(row["POID"].ToString()).FirstOrDefault(); AssTemplate assTemplate = _assTemplateRepository.GetById(assPurchaseOrderRow.TEMPLATEID).FirstOrDefault(); row["Image"] = assTemplate.IMAGE; int status = int.Parse(row["STATUS"].ToString()); row["STATUSNAME"] = Enum.GetName(typeof(PurchaseOrderStatus), status); row["Time"] = DateTime.Parse(row["CREATEDATE"].ToString()).ToShortDateString(); } return(temTable); }
/// <summary> /// 采购入库 /// </summary> /// <param name="inputDto">采购入库相关信息</param> /// <returns></returns> public ReturnInfo InstorageAss(AssInStorageInputDto inputDto) { ReturnInfo RInfo = new ReturnInfo(); StringBuilder sb = new StringBuilder(); string ValidateInfo = Helper.BasicValidate(inputDto).ToString(); sb.Append(ValidateInfo); if (sb.Length == 0) { try { //先确定数量是否超出 AssPurchaseOrderRow row = _assPoRowRepository .GetByPOIDandTemplateID(inputDto.POID, inputDto.TEMPLATEID).FirstOrDefault(); if (row != null) { if (row.QUANTPURCHASED < row.QUANTSTORED + inputDto.SnList.Count) { RInfo.IsSuccess = false; RInfo.ErrorInfo = "入库量超过采购量!"; return(RInfo); } else { row.QUANTSTORED = row.QUANTSTORED + inputDto.SnList.Count; var asspo = _assPurchaseOrderRepository.GetById(inputDto.POID).FirstOrDefault(); if (asspo != null) { asspo.STATUS = (int)PurchaseOrderStatus.入库中; if (row.QUANTPURCHASED == row.QUANTSTORED) { row.STATUS = (int)PurchaseOrderStatus.已完成; //判断是否需要将整个采购单状态改为"已完成" //得到采购单的行项数 var count = _assPoRowRepository.GetByPOID(inputDto.POID).Count(); //得到已完成的行项数 var count2 = _assPoRowRepository.GetByPOID(inputDto.POID) .Count(a => a.STATUS == (int)PurchaseOrderStatus.已完成); if (count == count2 + 1) { //包括当前行项,所有行项均已完成,则更新整个采购单状态为"已完成" asspo.STATUS = (int)PurchaseOrderStatus.已完成; _unitOfWork.RegisterDirty(asspo); } } else { row.STATUS = (int)PurchaseOrderStatus.入库中; } } _unitOfWork.RegisterDirty(row); } } AssTemplate assTemplate = _assTemplateRepository.GetById(inputDto.TEMPLATEID).AsNoTracking() .FirstOrDefault(); if (assTemplate != null) { for (int i = 0; i < inputDto.SnList.Count; i++) { //资产入库 string MaxId = _assetsRepository.GetMaxID(); string ASSID = Helper.GenerateASSID("ASS", MaxId, i); Assets assets = new Assets { STATUS = (int)STATUS.闲置, ASSID = ASSID, BUYDATE = DateTime.Now, CREATEUSER = inputDto.UserId, EXPIRYDATE = DateTime.Now.AddYears(1), IMAGE = assTemplate.IMAGE, ISINWAREHOUSE = 1, ISLOCKED = 0, MODIFYUSER = inputDto.UserId, NAME = assTemplate.NAME, NOTE = assTemplate.NOTE, PRICE = assTemplate.PRICE, SLID = inputDto.SLID, WAREID = inputDto.WAREID, STID = inputDto.STID, SPECIFICATION = assTemplate.SPECIFICATION, TYPEID = assTemplate.TYPEID, UNIT = assTemplate.UNIT, VENDOR = assTemplate.VENDOR, CREATEDATE = DateTime.Now, MODIFYDATE = DateTime.Now, SN = inputDto.SnList[i], TEMPLATEID = inputDto.TEMPLATEID }; _unitOfWork.RegisterNew(assets); var pr = new AssProcessRecord { ASSID = ASSID, CREATEDATE = DateTime.Now, CREATEUSER = inputDto.UserId, HANDLEDATE = DateTime.Now, HANDLEMAN = inputDto.UserId, MODIFYDATE = DateTime.Now, MODIFYUSER = inputDto.UserId, PROCESSCONTENT = inputDto.UserId + "入库了" + ASSID + ",数量为1", PROCESSMODE = (int)PROCESSMODE.入库, QUANTITY = 1 }; _unitOfWork.RegisterNew(pr); string SN = inputDto.SnList[i]; //添加采购入库关联表 AssPurchaseOrderInstorage instorage = new AssPurchaseOrderInstorage { POID = inputDto.POID, SN = SN, TEMPLATEID = inputDto.TEMPLATEID, // Time = DateTime.Now }; _unitOfWork.RegisterNew(instorage); } bool result = _unitOfWork.Commit(); RInfo.IsSuccess = result; RInfo.ErrorInfo = ""; return(RInfo); } else { RInfo.IsSuccess = false; RInfo.ErrorInfo = "该资产模板不存在!"; 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> /// 点击ActionButton /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void frmAssTemplate_ActionButtonPress(object sender, ActionButtonPressEventArgs e) { try { switch (e.Index) { case 0: //模板新增 try { frmAssTemplateCreate assTemplateCreate = new frmAssTemplateCreate(); Show(assTemplateCreate, (MobileForm sender1, object args) => { if (assTemplateCreate.ShowResult == ShowResult.Yes) { Bind(); } } ); } catch (Exception ex) { Toast(ex.Message); } break; case 1: //模板复制 try { if (string.IsNullOrEmpty(SelectTemplateId)) { throw new Exception("请先选择模板."); } var assTemplate = _autofacConfig.SettingService.GetAtbyId(SelectTemplateId); frmAssTemplateCreate assTemplateCreate = new frmAssTemplateCreate { ImgPicture = { ResourceID = assTemplate.IMAGE }, txtName = { Text = assTemplate.NAME }, txtNote = { Text = assTemplate.NOTE }, txtPrice = { Text = assTemplate.PRICE.ToString() }, txtSpe = { Text = assTemplate.SPECIFICATION }, btnType = { Text = assTemplate.TYPEID, Tag = assTemplate.TYPEID }, txtUnit = { Text = assTemplate.UNIT }, txtVendor = { Text = assTemplate.VENDOR } }; Show(assTemplateCreate, (MobileForm sender1, object args) => { if (assTemplateCreate.ShowResult == ShowResult.Yes) { Bind(); } } ); } catch (Exception ex) { Toast(ex.Message); } break; case 2: //打印标签 try { if (string.IsNullOrEmpty(SelectTemplateId)) { throw new Exception("请先选择模板."); } AssTemplate outputDto = _autofacConfig.SettingService.GetAtbyId(SelectTemplateId); PosPrinterEntityCollection Commands = new PosPrinterEntityCollection(); Commands.Add(new PosPrinterProtocolEntity(PosPrinterProtocol.Initial)); Commands.Add(new PosPrinterProtocolEntity(PosPrinterProtocol.EnabledBarcode)); Commands.Add(new PosPrinterProtocolEntity(PosPrinterProtocol.AbsoluteLocation)); Commands.Add(new PosPrinterBarcodeEntity(PosBarcodeType.CODE128Height, "62")); Commands.Add(new PosPrinterBarcodeEntity(PosBarcodeType.CODE128, outputDto.TEMPLATEID)); //Commands.Add(new PosPrinterBarcodeEntity(PosBarcodeType.CODE128, "E2000017320082231027BD")); Commands.Add(new PosPrinterProtocolEntity(PosPrinterProtocol.DisabledBarcode)); Commands.Add(new PosPrinterContentEntity(System.Environment.NewLine)); Commands.Add(new PosPrinterProtocolEntity(PosPrinterProtocol.Cut)); posPrinter1.Print(Commands, (obj, args) => { if (args.isError == true) { this.Toast("Error: " + args.error); } else { this.Toast("打印成功"); } }); } catch (Exception ex) { Toast(ex.Message); } break; } } catch (Exception ex) { Toast(ex.Message); } }