Example #1
0
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="keyValue">主键</param>
        public void RemoveForm(string keyValue)
        {
            IEnumerable <InbillItemEntity> list = null;

            if (!string.IsNullOrEmpty(keyValue))
            {
                //查询明细 先减库存再删除明细
                InbillItemService dal = new InbillItemService();
                list = dal.GetListByfinbillid(keyValue);
            }

            IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();

            try
            {
                // 删主表
                db.Delete <InbillEntity>(keyValue);
                // 删明细
                db.Delete <InbillItemEntity>(t => t.finbillid.Equals(keyValue));

                // 删库存
                if (list != null && list.Count() > 0)
                {
                    foreach (InbillItemEntity item in list)
                    {
                        var strSqls = RemoveGoodsRepertorySql(item);

                        db.ExecuteBySql(strSqls.ToString());
                    }
                }

                db.Commit();
            }
            catch (Exception)
            {
                db.Rollback();
                throw;
            }
        }
Example #2
0
        /// <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;
            }
        }