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

            if (!string.IsNullOrEmpty(keyValue))
            {
                //查询明细 先加库存再删除明细
                OutbillitemIService dal = new OutbillitemService();
                list = dal.GetListByFoutbillid(keyValue);
            }

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

            try
            {
                db.Delete <OutbillEntity>(keyValue);
                db.Delete <OutbillitemEntity>(t => t.foutbillid.Equals(keyValue));
                if (list != null && list.Count() > 0)
                {
                    foreach (OutbillitemEntity item in list)
                    {
                        var strSqls = new StringBuilder();
                        strSqls.Append("UPDATE tb_wh_goodsinfo SET   ");
                        strSqls.Append(" fcount=ISNULL(fcount,0)+" + item.fnumber);
                        strSqls.Append(",fmoney=(CASE WHEN ISNULL(fmoney,0)<=0 THEN 0 ELSE (fmoney+" + item.fmoney + ") END) ");
                        strSqls.Append(",fprice=(CASE WHEN (fcount+" + item.fnumber + ")<=0 THEN 0 ELSE Round(convert(float,(ISNULL(fmoney,0)+" + item.fmoney + "))/convert(float,(fcount+" + item.fnumber + ")),2) END) ");
                        strSqls.Append("  WHERE fgoodsid='" + item.fgoodsid + "'  ");

                        db.ExecuteBySql(strSqls.ToString());
                    }
                }
                db.Commit();
            }
            catch (Exception)
            {
                db.Rollback();
                throw;
            }
        }
Beispiel #2
0
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="keyValue">主键</param>
        /// <param name="type">inid 入库单  outid 出库单</param>
        public void RemoveFormAll(string keyValue, string type)
        {
            IRepository db = this.BaseRepository().BeginTrans();

            try
            {
                if (type == "inid")
                {
                    #region 入库单删除
                    IEnumerable <InbillItemEntity> list = GetListByfinbillid(keyValue);
                    if (list.Count() > 0)
                    {
                        foreach (InbillItemEntity item in list)
                        {
                            GoodsinfoIService dal_g = new GoodsinfoService();
                            GoodsinfoEntity   ent_g = dal_g.GetEntity(item.fgoodsid);
                            if (ent_g != null)
                            {
                                double dbe = ent_g.fcount - item.fnumber.ToDouble();
                                if (dbe < 0)
                                {
                                    dbe = 0;
                                }
                                ent_g.fcount = dbe;
                                decimal dl = ent_g.fmoney - item.fmoney;
                                if (dl < 0)
                                {
                                    dl = 0;
                                }
                                ent_g.fmoney = dl;
                                db.Update(ent_g);
                            }
                        }
                    }
                    var expression = LinqExtensions.True <InbillItemEntity>();
                    expression = expression.And(t => t.finbillid == keyValue);
                    //子表
                    db.Delete(expression);
                    //主表
                    db.Delete <InbillEntity>(keyValue);
                    #endregion
                }
                else if (type == "outid")
                {
                    #region 出库单删除
                    OutbillitemIService             dal  = new OutbillitemService();
                    IEnumerable <OutbillitemEntity> list = dal.GetListByFoutbillid(keyValue);
                    if (list.Count() > 0)
                    {
                        foreach (OutbillitemEntity item in list)
                        {
                            GoodsinfoIService dal_g = new GoodsinfoService();
                            GoodsinfoEntity   ent_g = dal_g.GetEntity(item.fgoodsid);
                            if (ent_g != null)
                            {
                                ent_g.fcount = ent_g.fcount + item.fnumber.ToDouble();
                                decimal dl = ent_g.fmoney + item.fmoney.ToDecimal();
                                ent_g.fmoney = dl;
                                db.Update(ent_g);
                            }
                        }
                    }

                    var expression = LinqExtensions.True <OutbillitemEntity>();
                    expression = expression.And(t => t.foutbillid == keyValue);
                    //子表
                    db.Delete(expression);
                    //主表
                    db.Delete <OutbillEntity>(keyValue);

                    #endregion
                }
                db.Commit();
            }
            catch (System.Exception)
            {
                db.Rollback();
                throw;
            }
        }
Beispiel #3
0
        /// <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;
            }
        }
Beispiel #4
0
        /// <summary>
        /// 保存表单(新增、修改)
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="entity">实体对象</param>
        /// <param name="entryList">子表</param>
        /// <returns></returns>
        public void SaveForm(string keyValue, OutbillEntity entity, List <OutbillitemEntity> entryList)
        {
            IEnumerable <OutbillitemEntity> list = null;

            if (!string.IsNullOrEmpty(keyValue))
            {
                //查询明细 先加库存再删除明细
                OutbillitemIService dal = new OutbillitemService();
                list = dal.GetListByFoutbillid(keyValue);
            }

            IRepository db = this.BaseRepository().BeginTrans();

            try
            {
                if (!string.IsNullOrEmpty(keyValue))
                {
                    //主表
                    db.Update(entity);

                    if (list != null && list.Count() > 0)
                    {
                        // 加库存
                        foreach (OutbillitemEntity item in list)
                        {
                            var strSqls = AddGoodsRepertorySql(item);

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

                        //明细
                        string deletesql = " delete tb_wh_outbill_item where foutbillid='" + keyValue + "' ";
                        db.ExecuteBySql(deletesql);
                    }

                    for (int i = 0; i < entryList.Count; i++)
                    {
                        entryList[i].foutbillid = entity.foutbillid;
                        entryList[i].fitemid    = entity.foutbillid + "-" + Utils.SupplementZero((i + 1).ToString(), 3); //生成领用单物品信息编号

                        // 明细
                        db.Insert(entryList[i]);

                        //减库存
                        var strSql = RemoveGoodsRepertorySql(entryList[i]);
                        db.ExecuteBySql(strSql.ToString());
                    }
                }
                else
                {
                    //主表
                    entity.Create();
                    entity.finputdate = DateTime.Now;
                    entity.foutdate   = 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].foutbillid = entity.foutbillid;
                        entryList[i].fitemid    = entity.foutbillid + "-" + Utils.SupplementZero((i + 1).ToString(), 3); //生成领用单物品信息编号

                        db.Insert(entryList[i]);

                        var strSql = RemoveGoodsRepertorySql(entryList[i]);

                        // 减库存
                        db.ExecuteBySql(strSql.ToString());
                    }
                }
                db.Commit();
            }
            catch (Exception)
            {
                db.Rollback();
                throw;
            }
        }