Example #1
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;
            }
        }
Example #2
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;
            }
        }