Beispiel #1
0
 /// <summary>
 /// 保存节点属性
 /// </summary>
 /// <param name="dp">属性</param>
 public void SaveDictionaryProperty(DictionaryProperty dp)
 {
     using (var dbContext = new StoreDbContext())
     {
         dbContext.Insert <DictionaryProperty>(dp);
     }
 }
Beispiel #2
0
 /// <summary>
 /// 添加节点
 /// </summary>
 /// <param name="dt">树结构</param>
 public void InsertDictionaryTree(DictionaryTree dt)
 {
     using (var dbContext = new StoreDbContext())
     {
         dbContext.Insert <DictionaryTree>(dt);
     }
 }
Beispiel #3
0
 /// <summary>
 /// 由于按订单出库,因此单独有表记录订单出库数量
 /// </summary>
 /// <param name="obr"></param>
 public void InsertOutBoundRecord(OutBoundRecord obr)
 {
     using (var dbContext = new StoreDbContext())
     {
         dbContext.Insert <OutBoundRecord>(obr);
     }
 }
Beispiel #4
0
        /// <summary>
        /// 入库,如果有增加数量,如果没有新增
        /// </summary>
        /// <param name="st"></param>
        public void InsertStoreItem(StoreTable st)
        {
            using (var dbContext = new StoreDbContext())
            {
                var item = dbContext.StoreTable.Where(u => u.store_item_id == st.store_item_id).FirstOrDefault();

                if (item == null)
                {
                    st.kcid = Guid.NewGuid();
                    dbContext.Insert <StoreTable>(st);
                }
                else
                {
                    decimal totalnumber = item.number.Value;
                    string  guid        = item.kcid.ToString();
                    Guid    tempguid    = new Guid(guid);
                    st.number += totalnumber;
                    st.kcid    = tempguid;

                    ///问题的原因在于,我们之前已经附加过当前实体,如果再进行Attach的时候,就会报这样的错。
                    // 解决办法:1.销毁之前的上下文,重新开启上下文。(等于白说)
                    //2.更改当前上下文的实体的状态。(这个是问题关键)
                    var entry = dbContext.Set <StoreTable>().Find(tempguid);
                    if (entry != null)
                    {
                        dbContext.Entry <StoreTable>(entry).State = System.Data.EntityState.Detached; //这个是在同一个上下文能修改的关键
                    }
                    dbContext.Update <StoreTable>(st);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// 插入库存操作记录
        /// </summary>
        /// <param name="ibr"></param>
        public void InsertInboundRecord(InBoundRecord ibr)
        {
            using (var dbContext = new StoreDbContext())
            {
                StoreTable st = dbContext.StoreTable.Include("DictionaryProperty.DictionaryTree").Where(u => u.store_item_id == ibr.inbound_id).FirstOrDefault();

                if (st == null)
                {
                    ibr.before_number = 0;
                }
                else
                {
                    ibr.before_number = st.number;
                    ibr.khmc          = GetParentNameByLeafID(st.DictionaryProperty.leaf_id.Value);
                }

                dbContext.Insert <InBoundRecord>(ibr);
            }
        }