当前位置: 首页>>代码示例>>C#>>正文


C# KuanMaiEntities.Dispose方法代码示例

本文整理汇总了C#中KM.JXC.DBA.KuanMaiEntities.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# KuanMaiEntities.Dispose方法的具体用法?C# KuanMaiEntities.Dispose怎么用?C# KuanMaiEntities.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在KM.JXC.DBA.KuanMaiEntities的用法示例。


在下文中一共展示了KuanMaiEntities.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SyncPermissionWithAction

        /// <summary>
        /// Sync actions with Permission object
        /// </summary>
        public void SyncPermissionWithAction()
        {
            Type permission=typeof(Permission);
            FieldInfo[] fields = permission.GetFields();
            if (fields == null || fields.Length<=0)
            {
                return;
            }

            KuanMaiEntities db = new KuanMaiEntities();

            try
            {
                foreach (FieldInfo field in fields)
                {
                    var action = from a in db.Admin_Action where a.action_name == field.Name select a;
                    if (action == null || action.ToList<Admin_Action>().Count == 0)
                    {
                        Admin_Action new_action = new Admin_Action();
                        new_action.action_name = field.Name;
                        new_action.action_description = field.Name;
                        new_action.enable = true;
                        db.Admin_Action.Add(new_action);
                    }
                }
                db.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {

            }
            finally
            {
                db.Dispose();
            }
        }
开发者ID:Bobom,项目名称:kuanmai,代码行数:39,代码来源:PermissionManager.cs

示例2: AuthorizationCallBack


//.........这里部分代码省略.........
                        shop_User.Shop_ID = shop.Shop_ID;
                        db.Shop_User.Add(shop_User);

                        //update dbuser
                        dbUser.Shop_ID = shop.Shop_ID;
                        db.SaveChanges();
                        //create default stock house
                        Store_House shouse = new Store_House();
                        shouse.Shop_ID = shop.Shop_ID;
                        shouse.Title = "默认仓库";
                        shouse.User_ID = requester.ID;
                        shouse.Create_Time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                        db.Store_House.Add(shouse);
                        db.SaveChanges();
                    }

                    if (shop != null && requester.Parent_ID == 0)
                    {
                        //sync mall sub users to system
                        //List<BUser> subUsers = this.MallUserManager.GetSubUsers(requester);
                        //if (subUsers != null && subUsers.Count > 0 && shop.Shop_ID > 0)
                        //{
                        //    foreach (BUser user in subUsers)
                        //    {
                        //        User db1User = new User();
                        //        db1User.Parent_Mall_ID = requester.Mall_ID;
                        //        db1User.Parent_Mall_Name = requester.Mall_Name;
                        //        db1User.Parent_User_ID = (int)requester.ID;
                        //        db1User.Mall_Name = user.Mall_Name;
                        //        db1User.Mall_ID = user.Mall_ID;
                        //        db1User.Mall_Type = user.Type.Mall_Type_ID;
                        //        db1User.Name = user.Name;
                        //        db1User.Password = "";
                        //        db.User.Add(db1User);

                        //        db.SaveChanges();

                        //        if (db1User.User_ID > 0)
                        //        {
                        //            //add shop user
                        //            Shop_User shop_User1 = new Shop_User();
                        //            shop_User1.User_ID = requester.ID;
                        //            shop_User1.Shop_ID = shop.Shop_ID;
                        //            db.Shop_User.Add(shop_User1);

                        //            if (user.EmployeeInfo != null)
                        //            {
                        //                user.EmployeeInfo.User_ID = db1User.User_ID;
                        //                db.Employee.Add(user.EmployeeInfo);
                        //                //db.SaveChanges();
                        //            }
                        //        }
                        //    }

                        //    db.SaveChanges();
                        //}
                    }
                }
                else
                {
                    //Verify if local db has non expried accesstoken
                    requester = users[0];

                    Access_Token local_token = GetLocalToken(requester.ID, this.Mall_Type_ID);
                    if (local_token != null)
                    {
                        long timeNow = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);

                        //last access token is expried
                        if (timeNow >= local_token.Expirse_In + local_token.Request_Time)
                        {
                            request_token = TokenManager.RequestAccessToken(code);
                            request_token.User_ID = requester.ID;
                            UpdateLocalAccessToken(request_token);
                        }
                        else
                        {
                            request_token = local_token;
                        }
                    }
                }
            }
            catch (DbEntityValidationException dbex)
            {
                throw new KMJXCException("登录失败,请联系管理员");
            }
            catch (Exception ex)
            {
                throw new KMJXCException(ex.Message, ExceptionLevel.SYSTEM);
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }

            return request_token;
        }
开发者ID:Bobom,项目名称:kuanmai,代码行数:101,代码来源:AccessManager.cs

示例3: CreateBackStock


//.........这里部分代码省略.........
                }

                //dbbackSale.Status = backSaleStatus;

                var bdetails = from bsd in db.Back_Sale_Detail
                               where bsd.Back_Sale_ID == backsale_id
                               select bsd;

                string[] order_id = (from o in orders select o.Order_ID).ToArray<string>();
                if (order_id != null)
                {
                    bdetails = bdetails.Where(d => order_id.Contains(d.Order_ID));
                }
                List<Sale_Detail> saleDetails=(from s in db.Sale_Detail where order_id.Contains(s.Mall_Order_ID) select s).ToList<Sale_Detail>();
                List<Back_Sale_Detail> backSaleDetails = bdetails.ToList<Back_Sale_Detail>();
                //Check if current sale trade has leave stock records
                //if the sale doesn't have leave stock, so no need to back stock
                Leave_Stock leave_Stock=(from ls in db.Leave_Stock where ls.Sale_ID==dbbackSale.Sale_ID select ls).FirstOrDefault<Leave_Stock>();
                if (leave_Stock!=null)
                {
                    List<Leave_Stock_Detail> leaveDetails=(from ld in db.Leave_Stock_Detail where ld.Leave_Stock_ID==leave_Stock.Leave_Stock_ID select ld).ToList<Leave_Stock_Detail>();

                    BBackStock backStock = new BBackStock();
                    backStock.BackSaleID = dbbackSale.Back_Sale_ID;
                    backStock.BackSale = new BBackSale() { ID = dbbackSale.Back_Sale_ID };
                    if (backSaleStatus == 1 || backSaleStatus==2)
                    {
                        backStock.UpdateStock = true;
                    }
                    else
                    {
                        backStock.UpdateStock = false;
                    }
                    backStock.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    backStock.BackDateTime = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    backStock.Created_By = new BUser() { ID = this.CurrentUser.ID };
                    if (!string.IsNullOrEmpty(dbbackSale.Description))
                    {
                        backStock.Description = dbbackSale.Description + "<br/> 生成了退库单";
                    }
                    else
                    {
                        backStock.Description = "生成了退库单";
                    }

                    backStock.Shop = new BShop() { ID = dbbackSale.Shop_ID };

                    //collect back stock details info from leave stock details

                    backStock.Details = new List<BBackStockDetail>();

                    foreach (Back_Sale_Detail bsd in backSaleDetails)
                    {
                        BOrder order=(from o in orders where bsd.Order_ID == o.Order_ID select o).FirstOrDefault<BOrder>();
                        Sale_Detail saleDetail=(from s in saleDetails where s.Mall_Order_ID==bsd.Order_ID select s).FirstOrDefault<Sale_Detail>();
                        Leave_Stock_Detail leaveStockDetail = (from lsd in leaveDetails where lsd.Order_ID == bsd.Order_ID select lsd).FirstOrDefault<Leave_Stock_Detail>();
                        if (leaveStockDetail == null)
                        {
                            continue;
                        }
                        BBackStockDetail bsDetail = new BBackStockDetail();
                        bsDetail.Price = leaveStockDetail.Price;
                        bsDetail.Quantity = leaveStockDetail.Quantity;
                        if (order != null && order.Quantity > 0 && order.Quantity<=leaveStockDetail.Quantity)
                        {
                            bsDetail.Quantity = order.Quantity;
                        }

                        bsDetail.ProductID = leaveStockDetail.Product_ID;
                        bsDetail.ParentProductID = leaveStockDetail.Parent_Product_ID;
                        bsDetail.Batch = new BStockBatch() { ID = leaveStockDetail.Batch_ID };
                        bsDetail.StoreHouse = new BStoreHouse() { ID = leaveStockDetail.StoreHouse_ID };
                        backStock.Details.Add(bsDetail);
                        bsd.Status = backSaleStatus;
                        //5 means refound and successfully back to sock
                        saleDetail.Status1 = (int)SaleDetailStatus.REFOUND_HANDLED;
                        saleDetail.SyncResultMessage = "退货已经处理";
                    }

                    if (backStock.Details.Count > 0)
                    {
                        this.CreateBackStock(backStock);
                    }
                }

                db.SaveChanges();
            }
            catch (KMJXCException kex)
            {
                throw kex;
            }
            catch(Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.Dispose();
            }
        }
开发者ID:Bobom,项目名称:kuanmai,代码行数:101,代码来源:StockManager.cs

示例4: CreateLeaveStocks


//.........这里部分代码省略.........
                            if (stockPileProductId == 0 && string.IsNullOrEmpty(order.Mall_SkuID) && order.Parent_Product_ID>0)
                            {
                                stockPileProductId = order.Parent_Product_ID;
                            }

                            dbDetail.Leave_Stock_ID = dbStock.Leave_Stock_ID;
                            dbDetail.Price = order.Price;
                            dbDetail.Quantity = order.Quantity;
                            dbDetail.Amount = order.Amount;
                            Stock_Pile stockPile = null;
                            if (house != null)
                            {
                                //order_detail.SyncResultMessage = "默认仓库:" + house.Title;
                                //create leave stock from default store house
                                stockPile = (from sp in stockPiles where sp.Product_ID == stockPileProductId && sp.StockHouse_ID == house.StoreHouse_ID && sp.Quantity >= order.Quantity select sp).OrderBy(s=>s.Batch_ID).FirstOrDefault<Stock_Pile>();
                            }

                            if (stockPile == null)
                            {
                                if (!string.IsNullOrEmpty(order_detail.SyncResultMessage))
                                {
                                    //order_detail.SyncResultMessage = "默认仓库:" + house.Title + "没有库存或者库存数量不够<br/>";
                                }
                                //get store house when it has the specific product
                                var tmpstockPile = from sp in stockPiles where sp.Product_ID == stockPileProductId && sp.Quantity >= order.Quantity select sp;
                                if (tmpstockPile.Count() > 0)
                                {
                                    stockPile = tmpstockPile.OrderBy(s=>s.Batch_ID).ToList<Stock_Pile>()[0];
                                    Store_House tmpHouse = (from h in houses where h.StoreHouse_ID == stockPile.StockHouse_ID select h).FirstOrDefault<Store_House>();
                                    if (tmpHouse != null)
                                    {
                                        house = tmpHouse;
                                    }
                                }
                                else
                                {
                                    //cannot leave stock, no stock pile
                                    order_detail.Status1 = (int)SaleDetailStatus.NO_ENOUGH_STOCK;
                                    order_detail.SyncResultMessage = "没有足够的库存,不能出库";
                                }
                            }

                            //no stock cannot leave stock
                            if (stockPile != null)
                            {
                                order_detail.Status1 = (int)SaleDetailStatus.LEAVED_STOCK;
                                order_detail.SyncResultMessage = "出库仓库:" + house.Title;
                                dbDetail.Parent_Product_ID = order.Parent_Product_ID;
                                dbDetail.Product_ID = order.Product_ID;
                                dbDetail.StoreHouse_ID = stockPile.StockHouse_ID;
                                dbDetail.Batch_ID = stockPile.Batch_ID;
                                //Update stock
                                stockPile.Quantity = stockPile.Quantity - order.Quantity;

                                //Update stock field in Product table
                                Product product=(from pdt in allproducts where pdt.Product_ID==dbDetail.Parent_Product_ID select pdt).FirstOrDefault<Product>();
                                if (product != null)
                                {
                                    product.Quantity = product.Quantity - order.Quantity;
                                }
                                dbDetail.Order_ID = order.Order_ID;
                                dbLDetails.Add(dbDetail);
                                //db.Leave_Stock_Detail.Add(dbDetail);
                            }
                        }
                        #endregion

                        if (isNew && dbLDetails.Count>0)
                        {
                            db.Leave_Stock.Add(dbStock);
                            db.SaveChanges();
                            foreach (Leave_Stock_Detail d in dbLDetails)
                            {
                                if (d.Leave_Stock_ID == 0)
                                {
                                    d.Leave_Stock_ID = dbStock.Leave_Stock_ID;
                                }

                                db.Leave_Stock_Detail.Add(d);
                            }
                        }
                    }
                }

                base.CreateActionLog(new BUserActionLog() { Shop=new BShop{ ID=shop.Shop_ID}, Action = new BUserAction() { Action_ID = UserLogAction.CREATE_LEAVE_STOCK }, Description = "同步商城订单到进销存,成功调用商城API,未出库的订单已成功出库并更新了产品库存" });
                db.SaveChanges();
            }
            catch (KMJXCException kex)
            {
                throw kex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.Dispose();
            }
        }
开发者ID:Bobom,项目名称:kuanmai,代码行数:101,代码来源:SalesManager.cs

示例5: CreatePropertyValues

        /// <summary>
        /// 
        /// </summary>
        /// <param name="propertyId"></param>
        /// <param name="value"></param>
        public void CreatePropertyValues(int propertyId, List<string> value)
        {
            KuanMaiEntities db = new KuanMaiEntities();
            try
            {
                Product_Spec ps=(from prop in db.Product_Spec where prop.Product_Spec_ID==propertyId select prop).FirstOrDefault<Product_Spec>();
                if (ps == null)
                {
                    throw new KMJXCException("属性不存在,不能添加属性值");
                }

                List<Product_Spec_Value> psValues=(from psv in db.Product_Spec_Value where psv.Product_Spec_ID==propertyId select psv).ToList<Product_Spec_Value>();

                if (value != null && value.Count > 0)
                {
                    foreach (string v in value)
                    {
                        Product_Spec_Value propValue = (from propv in psValues where propv.Name == v select propv).FirstOrDefault<Product_Spec_Value>();
                        if (propValue == null)
                        {
                            propValue = new Product_Spec_Value();
                            propValue.Product_Spec_ID = propertyId;
                            propValue.Name = v;
                            propValue.Mall_PVID = "";
                            propValue.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                            db.Product_Spec_Value.Add(propValue);
                        }
                    }

                    db.SaveChanges();
                }
            }
            catch
            {
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
        }
开发者ID:Bobom,项目名称:kuanmai,代码行数:48,代码来源:PropertyManager.cs

示例6: UpdateEmployeeInfo

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool UpdateEmployeeInfo(Employee employee)
        {
            bool result = false;
            if (this.CurrentUserPermission.UPDATE_EMPLOYEE == 0)
            {
                throw new KMJXCException("没有权限更新员工信息");
            }
            KuanMaiEntities db = new KuanMaiEntities();
            try
            {
                User user = (from u in db.User where u.User_ID == employee.User_ID select u).FirstOrDefault<User>();
                if (user != null)
                {
                    Employee existing = (from e in db.Employee where e.User_ID == employee.User_ID select e).FirstOrDefault<Employee>();
                    if (existing == null)
                    {
                        db.Employee.Add(employee);
                    }
                    else
                    {
                        this.UpdateProperties(existing, employee);
                    }
                    result = true;
                }
            }
            catch
            {

            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }

            return result;
        }
开发者ID:Bobom,项目名称:kuanmai,代码行数:43,代码来源:UserManager.cs

示例7: SyncPermissionWithAction

        /// <summary>
        /// Sync actions with Permission object
        /// </summary>
        public static void SyncPermissionWithAction()
        {
            Type permission = typeof(Permission);
            FieldInfo[] fields = permission.GetFields();
            if (fields == null || fields.Length <= 0)
            {
                return;
            }

            KuanMaiEntities db = new KuanMaiEntities();

            try
            {
                List<AdminActionAttribute> cates=new List<AdminActionAttribute>();
                List<Admin_Action> allActions=(from action in db.Admin_Action select action).ToList<Admin_Action>();
                List<Admin_Category> allCates=(from cate in db.Admin_Category select cate).ToList<Admin_Category>();
                foreach (FieldInfo field in fields)
                {
                    AdminActionAttribute attr = field.GetCustomAttribute<AdminActionAttribute>();
                    Admin_Action action = (from a in allActions where a.action_name == field.Name select a).FirstOrDefault<Admin_Action>();
                    if (action == null)
                    {
                        action = new Admin_Action();
                        action.action_name = field.Name;
                        action.enable = true;
                        db.Admin_Action.Add(action);
                    }

                    if (attr != null)
                    {
                        action.category_id = attr.ID;
                        action.action_description = attr.ActionDescription;
                        AdminActionAttribute existed = (from pcate in cates where pcate.ID == attr.ID select pcate).FirstOrDefault<AdminActionAttribute>();
                        if (existed == null)
                        {
                            cates.Add(attr);
                        }
                    }
                }
                db.SaveChanges();

                foreach (Admin_Action action in allActions)
                {
                    bool found = false;

                    foreach (FieldInfo field in fields)
                    {
                        if (action.action_name == field.Name)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        action.enable = false;
                        //db.Admin_Action.Remove(action);
                    }
                }

                db.SaveChanges();

                //category
                foreach (AdminActionAttribute pcate in cates)
                {
                    Admin_Category dbCate=(from c in allCates where c.ID==pcate.ID select c).FirstOrDefault<Admin_Category>();
                    if (dbCate == null)
                    {
                        dbCate = new Admin_Category();
                        dbCate.ID = pcate.ID;
                        dbCate.Name = pcate.CategoryName;
                        dbCate.System_category = pcate.IsSystem;
                        dbCate.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                        db.Admin_Category.Add(dbCate);
                    }
                }
                db.SaveChanges();
            }
            catch (Exception ex)
            {

            }
            finally
            {
                db.Dispose();
            }
        }
开发者ID:Bobom,项目名称:kuanmai,代码行数:91,代码来源:PermissionManagement.cs

示例8: AddNewPropValue

        /// <summary>
        /// 
        /// </summary>
        /// <param name="propertyId"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        public bool AddNewPropValue(int propertyId, List<string> values)
        {
            bool result = false;
            KuanMaiEntities db = new KuanMaiEntities();

            try
            {
                int[] child_shops = (from c in this.DBChildShops select c.Shop_ID).ToArray<int>();
                Product_Spec ps = (from pc in db.Product_Spec where pc.Product_Spec_ID == propertyId select pc).FirstOrDefault<Product_Spec>();
                if (ps == null)
                {
                    throw new KMJXCException("属性丢失,不能添加属性值");
                }

                if (this.Shop.Shop_ID != this.Main_Shop.Shop_ID)
                {
                    if (ps.Shop_ID == this.Main_Shop.Shop_ID)
                    {
                        throw new KMJXCException("您不能修改主店铺产品库存属性");
                    }

                    if (ps.Shop_ID == this.Shop.Shop_ID)
                    {
                        throw new KMJXCException("您不能其他主店铺产品库存属性");
                    }
                }
                else
                {
                    if (ps.Shop_ID != this.Main_Shop.Shop_ID && !child_shops.Contains(ps.Shop_ID))
                    {
                        throw new KMJXCException("您不能修改其他店铺的产品库存属性,只能修改主店铺或者子店铺产品库存属性");
                    }
                }

                StringBuilder error = new StringBuilder();
                if (values != null && values.Count > 0)
                {

                    foreach (string value in values)
                    {
                        Product_Spec_Value pv = (from psv in db.Product_Spec_Value where psv.Product_Spec_ID == propertyId && psv.Name == value select psv).FirstOrDefault<Product_Spec_Value>();
                        if (pv != null)
                        {
                            error.Append("属性值:"+value+" 已经存在<br/>");
                            continue;
                        }
                        pv = new Product_Spec_Value();
                        pv.Product_Spec_ID = propertyId;
                        pv.Name = value;
                        pv.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                        pv.User_ID = this.CurrentUser.ID;
                        db.Product_Spec_Value.Add(pv);
                    }

                    db.SaveChanges();
                    result = true;
                    if (!string.IsNullOrEmpty(error.ToString()))
                    {
                        result = false;
                        throw new KMJXCException(error.ToString());
                    }
                }

                base.CreateActionLog(new BUserActionLog() { Shop = new BShop { ID = this.Shop.Shop_ID }, Action = new BUserAction() { Action_ID = UserLogAction.CREATE_PRODUCT_PROPERTY }, Description = "" });
            }
            catch (KMJXCException ex)
            {
                throw ex;
            }
            catch (Exception nex)
            {

            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }

            return result;
        }
开发者ID:Bobom,项目名称:kuanmai,代码行数:89,代码来源:ShopCategoryManager.cs

示例9: UpdateProduct


//.........这里部分代码省略.........
                        {
                            db.Image.Remove(oldImg);
                            if (rootPath != null && System.IO.File.Exists(rootPath + oldImg.Path))
                            {
                                System.IO.File.Delete(rootPath + oldImg.Path);
                            }
                        }
                    }
                }

                //update suppliers
                if (product.Suppliers != null)
                {
                    foreach (Supplier s in product.Suppliers)
                    {
                        Product_Supplier ps = new Product_Supplier() { Product_ID = product.ID, Supplier_ID = s.Supplier_ID, Enabled=true,Created=DateTimeUtil.ConvertDateTimeToInt(DateTime.Now),Created_By=this.CurrentUser.ID };
                        db.Product_Supplier.Add(ps);
                    }
                }

                //update children
                List<Product> children=(from p in db.Product where p.Parent_ID==dbProduct.Product_ID select p).ToList<Product>();
                foreach (Product child in children)
                {
                    child.Name = dbProduct.Name;
                    child.Product_Class_ID = dbProduct.Product_Class_ID;
                    child.Description = dbProduct.Description;
                }

                db.SaveChanges();

                if (product.Children != null && product.Children.Count > 0)
                {
                    foreach (BProduct child in product.Children)
                    {
                        if (child.ID == 0)
                        {
                            //create new child product with properties
                            child.Parent = product;
                            child.Children = null;
                            this.CreateProduct(child);
                        }
                        else
                        {
                            //Update properties
                            if (child.Properties != null && child.Properties.Count > 0)
                            {
                                List<Product_Specifications> properties = (from prop in db.Product_Specifications
                                                                           where prop.Product_ID == child.ID
                                                                           select prop).ToList<Product_Specifications>();

                                List<Product_Specifications> newProps = new List<Product_Specifications>();
                                if (properties.Count > 0)
                                {
                                    //current just support edit existed property's value, doesn't support deleting property
                                    foreach (BProductProperty p in child.Properties)
                                    {
                                        Product_Specifications psprop = (from ep in properties where ep.Product_Spec_ID == p.PID  select ep).FirstOrDefault<Product_Specifications>();
                                        if (psprop == null)
                                        {
                                            //cretae new property for existed product
                                            psprop = new Product_Specifications() { Product_ID=child.ID, Product_Spec_ID=p.PID, Product_Spec_Value_ID=p.PVID, Created=DateTimeUtil.ConvertDateTimeToInt(DateTime.Now), User_ID=this.CurrentUser.ID };
                                            db.Product_Specifications.Add(psprop);
                                        }
                                        else
                                        {
                                            //update existed property's value
                                            if (psprop.Product_Spec_Value_ID != p.PVID)
                                            {
                                                psprop.Product_Spec_Value_ID = p.PVID;
                                            }
                                        }
                                    }

                                    db.SaveChanges();
                                }
                            }
                        }
                    }
                }

                bproduct = this.GetProductFullInfo(product.ID);

                base.CreateActionLog(new BUserActionLog() { Shop = new BShop { ID = bproduct.Shop.Shop_ID }, Action = new BUserAction() { Action_ID = UserLogAction.UPDATE_PRODUCT }, Description = "商品编号:" + bproduct.ID+ "\n商品名称:" + bproduct.Title });
                result = true;

            }
            catch (KMJXCException kex)
            {
                throw kex;
            }
            catch
            {
            }
            finally
            {
                db.Dispose();
            }
            return result;
        }
开发者ID:Bobom,项目名称:kuanmai,代码行数:101,代码来源:ProductManager.cs

示例10: SyncUserAction

        public static void SyncUserAction()
        {
            Type action = typeof(UserLogAction);

            FieldInfo[] fields = action.GetFields();
            if (fields == null || fields.Length <= 0)
            {
                return;
            }

            KuanMaiEntities db = new KuanMaiEntities();

            try
            {
                List<User_Action> allActions=(from ac in db.User_Action select ac).ToList<User_Action>();
                foreach (FieldInfo field in fields)
                {
                    UserActionAttribute attr = field.GetCustomAttribute<UserActionAttribute>();
                    int aValue = (int)field.GetValue(null);
                    User_Action userAc=(from ac in allActions where ac.Action_ID==aValue && ac.Action_Name==field.Name select ac).FirstOrDefault<User_Action>();
                    if (userAc == null)
                    {
                        userAc = new User_Action();
                        userAc.Action_ID = aValue;
                        userAc.Action_Name = field.Name;
                        userAc.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                        if (attr != null)
                        {
                            userAc.Action_Description = attr.Description;
                        }
                        db.User_Action.Add(userAc);
                    }
                    else
                    {
                        if (attr != null)
                        {
                            userAc.Action_Description = attr.Description;
                        }
                    }
                }

                db.SaveChanges();
            }
            catch(Exception ex)
            {

            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
        }
开发者ID:Bobom,项目名称:kuanmai,代码行数:55,代码来源:PermissionManagement.cs

示例11: GetProductFullInfo


//.........这里部分代码省略.........
            {
                throw new KMJXCException("获取产品详细信息时候,必须输入产品编号或者已关联的商城宝贝编号");
            }

            BProduct product = null;
            KuanMaiEntities db = new KuanMaiEntities();

            try
            {
                if (productId == 0 && !string.IsNullOrEmpty(mall_id))
                {
                    productId=(from mp in db.Mall_Product where mp.Mall_ID==mall_id select mp.Outer_ID).FirstOrDefault<int>();
                }

                if (productId == 0)
                {
                    throw new KMJXCException("获取产品详细信息时候,必须输入产品编号或者已关联的商城宝贝编号");
                }

                product = (from pudt in db.Product
                           where pudt.Product_ID == productId
                           select new BProduct
                           {
                               Shop = (from sp in db.Shop where sp.Shop_ID == pudt.Shop_ID select sp).FirstOrDefault<Shop>(),
                               ID = pudt.Product_ID,
                               Description = pudt.Description,
                               Title = pudt.Name,
                               Code = pudt.Code,
                               CreateTime = pudt.Create_Time,
                               Category = (from c in db.Product_Class
                                           where pudt.Product_Class_ID == c.Product_Class_ID
                                           select new BCategory
                                           {
                                               Name = c.Name,
                                               ID = c.Product_Class_ID,
                                               ParentID=(int)c.Parent_ID
                                           }).FirstOrDefault<BCategory>(),
                               User = (from u in db.User
                                       where u.User_ID == pudt.User_ID
                                       select new BUser
                                       {
                                           ID = u.User_ID,
                                           Mall_Name = u.Mall_Name,
                                           Mall_ID = u.Mall_ID,
                                       }).FirstOrDefault<BUser>()

                           }).FirstOrDefault<BProduct>();

                if (product != null)
                {
                    product.Images = (from img in db.Image where img.ProductID == product.ID select img).ToList<Image>();
                    product.Suppliers = (from sp in db.Supplier
                                         join ps in db.Product_Supplier on sp.Supplier_ID equals ps.Supplier_ID
                                         where ps.Product_ID == product.ID && ps.Enabled==true
                                         select sp
                                      ).ToList<Supplier>();

                    //product.Properties = properties;
                    List<Product> children = (from p in db.Product where p.Parent_ID == product.ID select p).ToList<Product>();
                    int[] children_ids=(from c in children select c.Product_ID).ToArray<int>();
                    List<BProductProperty> properties = (from pp in db.Product_Specifications
                                                         where children_ids.Contains(pp.Product_ID)
                                                         select new BProductProperty
                                                         {
                                                             ProductID=pp.Product_ID,
                                                             PID = pp.Product_Spec_ID,
                                                             PName = (from prop in db.Product_Spec where prop.Product_Spec_ID == pp.Product_Spec_ID select prop.Name).FirstOrDefault<string>(),
                                                             PVID = pp.Product_Spec_Value_ID,
                                                             PValue = (from propv in db.Product_Spec_Value where propv.Product_Spec_Value_ID == pp.Product_Spec_Value_ID select propv.Name).FirstOrDefault<string>()
                                                         }).OrderBy(p=>p.PID).ToList<BProductProperty>();

                    if (children != null && children.Count > 0)
                    {
                        if (product.Children == null)
                        {
                            product.Children = new List<BProduct>();
                        }
                        foreach (Product pdt in children)
                        {
                            BProduct child = new BProduct() {  ID=pdt.Product_ID,Title=product.Title};
                            child.Properties=(from prop in properties where prop.ProductID==child.ID select prop).ToList<BProductProperty>();
                            product.Children.Add(child);
                        }
                    }
                }
            }
            catch (KMJXCException kex)
            {
                throw kex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.Dispose();
            }
            return product;
        }
开发者ID:Bobom,项目名称:kuanmai,代码行数:101,代码来源:ProductManager.cs

示例12: Initialize

        protected void Initialize()
        {
            if (this.Mall_Type_ID <= 0)
            {
                throw new Exception("Mall Type ID is invalid for open API");
            }
            KuanMaiEntities db = new KuanMaiEntities();
            try
            {

                var openKey = db.Open_Key.Where(p => p.Mall_Type_ID == this.Mall_Type_ID);
                if (openKey != null)
                {
                    List<Open_Key> keys = openKey.ToList<Open_Key>();
                    if (keys.Count == 1)
                    {
                        this.Open_Key = keys[0];
                    }
                    else
                    {
                        throw new Exception("More app key and secret pair for Mall Type ID:" + this.Mall_Type_ID);
                    }
                }
                else
                {
                    throw new Exception("Didn't find app key and secret for Mall Type ID:" + this.Mall_Type_ID);
                }

                var t = from tp in db.Mall_Type where tp.Mall_Type_ID == this.Mall_Type_ID select new BMallType { ID=tp.Mall_Type_ID,Name=tp.Name };
                if (t.ToList<BMallType>().Count == 1)
                {
                    this.MallType = t.ToList<BMallType>()[0];
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
        }
开发者ID:Bobom,项目名称:kuanmai,代码行数:47,代码来源:OBaseManager.cs

示例13: EnterStockDetail

        /// <summary>
        /// Add one enter stock detail record
        /// </summary>
        /// <param name="detail"></param>
        /// <returns></returns>
        public bool EnterStockDetail(int stockId,BEnterStockDetail detail)
        {
            bool result = false;
            if (this.CurrentUserPermission.ADD_ENTER_STOCK == 0)
            {
                throw new KMJXCException("没有新增入库单的权限");
            }

            if (detail.EnterStock == null && stockId<=0)
            {
                throw new KMJXCException("必须选择入库单");
            }

            KuanMaiEntities db = new KuanMaiEntities();
            if (stockId > 0)
            {
                Enter_Stock dbStock= (from st in db.Enter_Stock where st.Enter_Stock_ID == stockId select st).FirstOrDefault<Enter_Stock>();
                detail.EnterStock = new BEnterStock() { ID = stockId, StoreHouse = new BStoreHouse() { ID = dbStock.StoreHouse_ID } };
            }
            else
            {
                if (detail.EnterStock.ID <= 0)
                {
                    throw new KMJXCException("必须选择入库单");
                }
            }

            if (detail.Product == null)
            {
                throw new KMJXCException("必须指定商品");
            }

            if (detail.Quantity == 0)
            {
                throw new KMJXCException("数量必须大于零");
            }
            try
            {

                Enter_Stock_Detail dbDetail = new Enter_Stock_Detail();
                dbDetail.Create_Date = detail.Created;
                dbDetail.Enter_Stock_ID = detail.EnterStock.ID;
                dbDetail.Have_Invoice = detail.Invoiced;
                dbDetail.Invoice_Amount = detail.InvoiceAmount;
                dbDetail.Invoice_Num = detail.InvoiceNumber;
                dbDetail.Price = detail.Price;
                dbDetail.Product_ID = detail.Product.ID;
                dbDetail.Quantity = (int)detail.Quantity;
                db.Enter_Stock_Detail.Add(dbDetail);
                db.SaveChanges();

                //update stock pile
                Stock_Pile stockPile = (from sp in db.Stock_Pile where sp.Product_ID == dbDetail.Product_ID && sp.StockHouse_ID==detail.EnterStock.StoreHouse.ID select sp).FirstOrDefault<Stock_Pile>();
                if (stockPile != null)
                {
                    stockPile.Quantity = stockPile.Quantity + dbDetail.Quantity;
                    stockPile.Price = dbDetail.Price;
                    if (stockPile.First_Enter_Time == 0)
                    {
                        stockPile.First_Enter_Time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    }
                }

                result = true;
            }
            catch
            {
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }

            return result;
        }
开发者ID:Bobom,项目名称:kuanmai,代码行数:83,代码来源:StockManager.cs

示例14: CreateProperty

        /// <summary>
        /// 
        /// </summary>
        /// <param name="categoryId"></param>
        /// <param name="propName"></param>
        /// <param name="propValues"></param>
        /// <returns></returns>
        public BProperty CreateProperty(int categoryId,string propName,List<string> propValues,int shop_id=0)
        {
            BProperty bproperty = null;
            if (string.IsNullOrEmpty(propName))
            {
                throw new KMJXCException("属性名称不能为空");
            }
            KuanMaiEntities db = new KuanMaiEntities();
            try
            {
                var existed = from props in db.Product_Spec where props.Name==propName select props;

                if (categoryId > 0)
                {
                    //existed = existed.Where(a=>a.Product_Class_ID==categoryId);
                }

                if (this.Shop.Parent_Shop_ID > 0)
                {
                    var pexisted = existed.Where(a=>a.Shop_ID==this.Main_Shop.Shop_ID);
                    if (pexisted.FirstOrDefault<Product_Spec>() != null)
                    {
                        throw new KMJXCException("主店铺已经有此属性,不能重复创建,请使用现有主店铺的属性");
                    }
                }

                existed = existed.Where(a => a.Shop_ID == this.Shop.Shop_ID);
                if (existed.FirstOrDefault<Product_Spec>() != null)
                {
                    throw new KMJXCException("此属性已经存在,不能重复创建");
                }

                Product_Spec property = new Product_Spec();
                property.Product_Class_ID = categoryId;
                property.Name = propName;
                property.User_ID = this.CurrentUser.ID;
                property.Shop_ID = this.Shop.Shop_ID;
                if (shop_id > 0)
                {
                    property.Shop_ID = shop_id;
                }
                property.Mall_PID = "";
                property.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                db.Product_Spec.Add(property);
                db.SaveChanges();
                if (property.Product_Spec_ID <= 0)
                {
                    throw new KMJXCException("属性创建失败");
                }
                bproperty = new BProperty();
                bproperty.ID = property.Product_Spec_ID;
                bproperty.Created_By = this.CurrentUser;
                bproperty.Created = (int)property.Created;
                bproperty.CategoryId = categoryId;
                bproperty.MID = "";
                bproperty.Name = propName;

                if (propValues != null)
                {
                    if (bproperty.Values == null)
                    {
                        bproperty.Values = new List<Product_Spec_Value>();
                    }
                    foreach (string v in propValues)
                    {
                        Product_Spec_Value psv = new Product_Spec_Value();
                        psv.Mall_PVID = "";
                        psv.Name = v;
                        psv.Product_Spec_ID = property.Product_Spec_ID;
                        psv.Product_Spec_Value_ID = 0;
                        psv.User_ID = this.CurrentUser.ID;
                        psv.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                        db.Product_Spec_Value.Add(psv);
                    }
                    db.SaveChanges();
                    bproperty.Values=(from pv in db.Product_Spec_Value where pv.Product_Spec_ID==property.Product_Spec_ID select pv).ToList<Product_Spec_Value>();
                }
            }
            catch(KMJXCException ex)
            {
                throw ex;
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
            return bproperty;
        }
开发者ID:Bobom,项目名称:kuanmai,代码行数:98,代码来源:ShopCategoryManager.cs

示例15: UpdateSupplier

        /// <summary>
        /// Update supplier basic information
        /// </summary>
        /// <param name="supplier"></param>
        /// <returns></returns>
        public bool UpdateSupplier(Supplier supplier)
        {
            bool result = false;

            if (this.CurrentUserPermission.UPDATE_SUPPLIER == 0)
            {
                throw new KMJXCException("没有权限更新供应商");
            }

            if (string.IsNullOrEmpty(supplier.Name))
            {
                throw new KMJXCException("供应商名称不能为空");
            }
            KuanMaiEntities db = null;

            try
            {

                db = new KuanMaiEntities();
                int[] child_shops = (from c in this.DBChildShops select c.Shop_ID).ToArray<int>();
                Supplier existed = (from supp in db.Supplier where supp.Supplier_ID == supplier.Supplier_ID select supp).FirstOrDefault<Supplier>();
                if (existed == null)
                {
                    throw new KMJXCException("要修改的供应商不存在");
                }
                var obj = (from sp in db.Supplier where (child_shops.Contains(sp.Shop_ID) || sp.Shop_ID == this.Shop.Shop_ID || sp.Shop_ID == this.Main_Shop.Shop_ID) && supplier.Name.Contains(sp.Name) && sp.Supplier_ID!=existed.Supplier_ID select sp);

                if (obj.ToList<Supplier>().Count > 0)
                {
                    throw new KMJXCException("供应商名称已经存在,请换个名字");
                }

                if (this.Shop.Shop_ID != this.Main_Shop.Shop_ID)
                {
                    if (existed.Shop_ID == this.Main_Shop.Shop_ID)
                    {
                        if (this.CurrentUser.Shop.ID != existed.Shop_ID)
                        {
                            throw new KMJXCException("您不能修改主店铺供应商");
                        }
                    }
                    else if (existed.Shop_ID!=this.Shop.Shop_ID)
                    {
                        throw new KMJXCException("您不能其他主店铺供应商");
                    }

                }
                else
                {
                    if (existed.Shop_ID != this.Main_Shop.Shop_ID && !child_shops.Contains(existed.Shop_ID))
                    {
                        throw new KMJXCException("您不能修改其他店铺的供应商,只能修改主店铺或者子店铺供应商");
                    }
                }

                supplier.Modified = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                supplier.Modified_By = this.CurrentUser.ID;
                this.UpdateProperties(existed, supplier);
                db.SaveChanges();
                result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.Dispose();
            }
            return result;
        }
开发者ID:Bobom,项目名称:kuanmai,代码行数:76,代码来源:SupplierManager.cs


注:本文中的KM.JXC.DBA.KuanMaiEntities.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。