/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <returns></returns> public void SaveForm(string keyValue, InbillItemEntity entity) { try { service.SaveForm(keyValue, entity); } catch (Exception) { throw; } }
/// <summary> /// 加库存的Sql /// </summary> /// <param name="entryList"></param> /// <param name="i"></param> /// <returns></returns> public StringBuilder AddGoodsRepertorySql(InbillItemEntity item) { var strSqls = new StringBuilder(); strSqls.AppendFormat(@" UPDATE tb_wh_goodsinfo SET fcount = ISNULL(fcount, 0) + {0} , fmoney = ( ISNULL(fmoney, 0) + {1} ) , fprice = (CASE WHEN (((ISNULL(fmoney, 0) + {1}) <= 0) or ((ISNULL(fcount, 0) + {0}) = 0)) THEN 0 ELSE ROUND(CONVERT(FLOAT, ( ISNULL(fmoney, 0) + {1} )) / ( ISNULL(fcount, 0) + {0} ), 2) END) WHERE fgoodsid = '{2}' ", item.fnumber, item.fmoney, item.fgoodsid); return(strSqls); }
/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <returns></returns> public void SaveForm(string keyValue, InbillItemEntity entity) { if (!string.IsNullOrEmpty(keyValue)) { entity.Modify(keyValue); this.BaseRepository().Update(entity); } else { entity.Create(); entity.fitemid = entity.finbillid + "00" + modifyid(entity.finbillid); //生成领用单物品信息编号 this.BaseRepository().Insert(entity); } }
/// <summary> /// 减库存的Sql /// </summary> /// <param name="item"></param> /// <returns></returns> public StringBuilder RemoveGoodsRepertorySql(InbillItemEntity item) { var strSqls = new StringBuilder(); strSqls.AppendFormat(@" UPDATE tb_wh_goodsinfo SET fcount = ( CASE WHEN ( ISNULL(fcount, 0) - {0} ) <= 0 THEN 0 ELSE ISNULL(fcount, 0) - {0} END ) , fmoney = ( CASE WHEN (( ISNULL(fmoney, 0) - {1} ) <= 0 OR ( ISNULL(fcount, 0) - {0} ) <= 0) THEN 0 ELSE ( fmoney - {1} ) END ) , fprice = ( CASE WHEN (( ISNULL(fmoney, 0) - {1} ) <= 0 OR ( ISNULL(fcount, 0) - {0} ) <= 0) THEN 0 ELSE ROUND(CONVERT(FLOAT, ( ISNULL(fmoney, 0) - {1} )) / CONVERT(FLOAT, ( fcount - {0} )), 2) END ) WHERE fgoodsid = '{2}' ", item.fnumber, item.fmoney, item.fgoodsid); return(strSqls); }
//[HandlerAuthorize(PermissionMode.Enforce)] public ActionResult SaveForm(string keyValue, InbillItemEntity entity, string Type) { //默认金额传过来的是单价 type=-1 是单价 type=-2是总价 if (Type == "-2") { decimal price = entity.fprice; //获取到金额 entity.fmoney = price; // 总价为传过来的金额; entity.fprice = entity.fmoney / Convert.ToDecimal(entity.fnumber); //单价就为总价除数量 } else if (Type == "-1") { //为单价类型的话 entity.fmoney = entity.fprice * Convert.ToDecimal(entity.fnumber); //总价为单价乘数量 } else { //为空不做操作 } inbillitembll.SaveForm(keyValue, entity); return(Success("操作成功。")); }
/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <returns></returns> public void SaveForm(string keyValue, InbillEntity entity, List <InbillItemEntity> entryList) { IRepository db = this.BaseRepository().BeginTrans(); try { if (!string.IsNullOrEmpty(keyValue)) { //主表 db.Update(entity); // 查询明细 InbillItemService dal = new InbillItemService(); IEnumerable <InbillItemEntity> list = dal.GetListByfinbillid(keyValue); if (list != null && list.Count() > 0) { // 减历史库存 foreach (InbillItemEntity item in list) { var strSqls = RemoveGoodsRepertorySql(item); db.ExecuteBySql(strSqls.ToString()); } // 删明细 string deletesql = " delete tb_wh_inbill_item where finbillid='" + keyValue + "' "; db.ExecuteBySql(deletesql); } int i = 0; foreach (InbillItemEntity item in entryList) { // 加明细 item.Create(); item.finbillid = entity.finbillid; item.fitemid = entity.finbillid + "-" + Utils.SupplementZero((i + 1).ToString(), 3); //生成领用单物品信息编号 db.Insert(item); #region 编辑期间如果有出库动作的,要计算进来,否则会导致库存数量不对 Author:Jerry.Li Time:2017/10/25 17:31 InbillItemEntity inentity = new InbillItemEntity(); inentity.fnumber = item.fnumber; inentity.fmoney = item.fmoney; inentity.fgoodsid = item.fgoodsid; string safeSql = string.Format(@" SELECT * FROM tb_wh_outbill_item i LEFT JOIN dbo.tb_wh_outbill o ON o.foutbillid = i.foutbillid WHERE i.fgoodsid = '{0}' AND o.finputdate >= '{1}'", item.fgoodsid, entity.finputdate); IEnumerable <OutbillitemEntity> olist = new RepositoryFactory().BaseRepository().FindList <OutbillitemEntity>(safeSql); if (olist != null) { foreach (OutbillitemEntity obill in olist.ToList()) { inentity.fnumber = Convert.ToInt32(inentity.fnumber) - Convert.ToInt32(obill.fnumber); inentity.fmoney = inentity.fmoney - Convert.ToDecimal(obill.fmoney); } } #endregion //加库存 var strSqls = AddGoodsRepertorySql(inentity); db.ExecuteBySql(strSqls.ToString()); i++; } } else { //主表 entity.Create(); entity.finputdate = DateTime.Now; int userid = 0; int.TryParse(OperatorProvider.Provider.Current().OldSystemUserID, out userid); entity.fuserid = userid; db.Insert(entity); //明细 for (int i = 0; i < entryList.Count; i++) { entryList[i].finbillid = entity.finbillid; entryList[i].fitemid = entity.finbillid + "-" + Utils.SupplementZero((i + 1).ToString(), 3); //生成领用单物品信息编号 db.Insert(entryList[i]); //加库存 var strSqls = AddGoodsRepertorySql(entryList[i]); db.ExecuteBySql(strSqls.ToString()); } } db.Commit(); } catch (Exception) { db.Rollback(); throw; } }
/// <summary> /// 删除数据 /// </summary> /// <param name="keyValue">主键</param> /// <param name="type">inid 入库单 outid 出库单</param> public void RemoveForm(string keyValue, string type) { IRepository db = this.BaseRepository().BeginTrans(); try { if (type == "inid") { #region 入库单删除 InbillItemEntity ent = GetEntity(keyValue); if (ent != null) { GoodsinfoIService dal_g = new GoodsinfoService(); GoodsinfoEntity ent_g = dal_g.GetEntity(ent.fgoodsid); if (ent_g != null) { double dbe = ent_g.fcount - ent.fnumber.ToDouble(); if (dbe < 0) { dbe = 0; } ent_g.fcount = dbe; decimal dl = ent_g.fmoney - ent.fmoney; if (dl < 0) { dl = 0; } ent_g.fmoney = dl; db.Update(ent_g); } } db.Delete <InbillItemEntity>(keyValue); #endregion } else if (type == "outid") { #region 出库单删除 OutbillitemIService dal = new OutbillitemService(); OutbillitemEntity ent = dal.GetEntity(keyValue); if (ent != null) { GoodsinfoIService dal_g = new GoodsinfoService(); GoodsinfoEntity ent_g = dal_g.GetEntity(ent.fgoodsid); if (ent_g != null) { ent_g.fcount = ent_g.fcount + ent.fnumber.ToDouble(); decimal dl = ent_g.fmoney + ent.fmoney.ToDecimal(); ent_g.fmoney = dl; db.Update(ent_g); } } db.Delete <OutbillitemEntity>(keyValue); #endregion } db.Commit(); } catch (System.Exception) { db.Rollback(); throw; } }