示例#1
0
        /// <summary>
        /// Create new supplier
        /// </summary>
        /// <param name="supplier"></param>
        /// <returns></returns>
        public bool CreateSupplier(Supplier supplier)
        {
            bool result = false;

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

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

            if (supplier.User_ID == 0 && this.CurrentUser!=null)
            {
                supplier.User_ID = this.CurrentUser.ID;
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                var obj = (from sp in db.Supplier where (sp.Shop_ID == this.Shop.Shop_ID || sp.Shop_ID == this.Main_Shop.Shop_ID) && supplier.Name.Contains(sp.Name) select sp);
                if (obj.ToList<Supplier>().Count > 0)
                {
                    throw new KMJXCException("供应商名称已经存在");
                }
                db.Supplier.Add(supplier);
                db.SaveChanges();
                result = true;
            }

            return result;
        }
示例#2
0
        /// <summary>
        /// Add properties for parent product or child product
        /// </summary>
        /// <param name="product_id"></param>
        /// <param name="props"></param>
        /// <returns></returns>
        public bool AddProductProperties(int product_id, List<BProductProperty> props)
        {
            Product dbProduct = this.GetProduct(product_id);
            if (dbProduct == null)
            {
                throw new KMJXCException("产品不存在");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                if (props != null && props.Count > 0)
                {
                    List<Product_Specifications> specs = (from ps in db.Product_Specifications where ps.Product_ID == dbProduct.Product_ID select ps).ToList<Product_Specifications>();
                    foreach (BProductProperty prop in props)
                    {
                        Product_Specifications ps = (from sp in specs where sp.Product_Spec_ID == prop.PID && sp.Product_Spec_Value_ID == prop.PVID && sp.Product_ID==product_id select sp).FirstOrDefault<Product_Specifications>();
                        if (ps == null)
                        {
                            ps = new Product_Specifications();
                            ps.Product_Spec_Value_ID = prop.PVID;
                            ps.Product_Spec_ID = prop.PID;
                            ps.Product_ID = product_id;
                            db.Product_Specifications.Add(ps);
                        }
                    }
                    db.SaveChanges();
                }
            }

            return true;
        }
示例#3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="bug"></param>
 /// <returns></returns>
 public bool CreateNewBug(BBug bug)
 {
     if (bug.Created_By == null)
     {
         throw new KMJXCException("创建Bug时必须有创建人");
     }
     bool result = false;
     using (KuanMaiEntities db = new KuanMaiEntities())
     {
         Bug dbBug = new Bug();
         dbBug.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
         if (bug.Created_By != null)
         {
             dbBug.Created_By = bug.Created_By.ID;
         }
         dbBug.Description = bug.Description;
         if (bug.Feature != null)
         {
             dbBug.Feature = bug.Feature.ID;
         }
         dbBug.Function = 0;
         dbBug.Modified = dbBug.Created;
         dbBug.Modified_By = dbBug.Created_By;
         dbBug.Resolved = 0;
         dbBug.Resolved_By = 0;
         dbBug.Status = 1;
         dbBug.Title = bug.Title;
         db.Bug.Add(dbBug);
         db.SaveChanges();
         result = true;
     }
     return result;
 }
示例#4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="image"></param>
 /// <returns></returns>
 public bool CreateImage(KM.JXC.DBA.Image image)
 {
     bool result = false;
     using (KuanMaiEntities db = new KuanMaiEntities())
     {
         db.Image.Add(image);
         db.SaveChanges();
         result = true;
     }
     return result;
 }
示例#5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="action"></param>
        public void CreateActionLog(BUserActionLog action)
        {
            if (action == null || action.Shop==null)
            {
                return;
            }
            KuanMaiEntities db = null;
            try
            {
                db = new KuanMaiEntities();
                User_Action_Log log = new User_Action_Log();

                log.Action = action.Action.Action_ID;

                log.Description = action.Description;
                if (action.User != null && action.User.ID > 0)
                {
                    log.User_ID = action.User.ID;
                }
                else
                {
                    log.User_ID = this.CurrentUser.ID;
                }

                log.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                if (string.IsNullOrEmpty(log.Description))
                {
                    log.Description = "";
                }
                log.Shop_ID = action.Shop.ID;
                db.User_Action_Log.Add(log);
                db.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {

            }
            catch (Exception ex)
            {

            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
        }
示例#6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="buyPrice"></param>
        /// <returns></returns>
        public bool CreateBuyPrice(BBuyPrice buyPrice)
        {
            bool result = false;

            if (this.CurrentUserPermission.CREATE_BUY_PRICE == 0)
            {
                throw new KMJXCException("没有权限创建采购询价单");
            }

            if (buyPrice == null)
            {
                throw new KMJXCException("输入不正确");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Buy_Price dbBuyPrice = new Buy_Price();
                if (buyPrice.Created <= 0)
                {
                    dbBuyPrice.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                }

                dbBuyPrice.Shop_ID = this.Shop.Shop_ID;
                if (buyPrice.Shop != null && buyPrice.Shop.ID > 0)
                {
                    dbBuyPrice.Shop_ID = buyPrice.Shop.ID;
                }

                dbBuyPrice.User_ID = this.CurrentUser.ID;
                if (buyPrice.User != null && buyPrice.User.ID > 0)
                {
                    dbBuyPrice.User_ID = buyPrice.User.ID;
                }

                dbBuyPrice.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                dbBuyPrice.Title = buyPrice.Title;
                dbBuyPrice.Description = buyPrice.Desc;
                db.Buy_Price.Add(dbBuyPrice);
                db.SaveChanges();
                result = true;
                if (dbBuyPrice.ID > 0 && buyPrice.Details!=null && buyPrice.Details.Count>0)
                {
                    result = result & this.SaveBuyPriceDetails(buyPrice.Details, dbBuyPrice.ID);
                }
            }

            return result;
        }
示例#7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="image_id"></param>
        /// <returns></returns>
        public bool DeleteProductImage(int product_id)
        {
            bool result = false;
            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                List<Image> images = (from img in db.Image where img.ProductID == product_id select img).ToList<Image>();

                foreach (Image img in images)
                {
                    db.Image.Remove(img);
                }
                db.SaveChanges();
                result = true;
            }
            return result;
        }
示例#8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="image_id"></param>
        /// <returns></returns>
        public bool DeleteImage(int image_id,out Image image)
        {
            bool result = false;
            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                image=(from img in db.Image where img.ID==image_id select img).FirstOrDefault<Image>();
                if (image == null)
                {
                    throw new KMJXCException("图片不存在");
                }

                db.Image.Remove(image);
                db.SaveChanges();
                result = true;
            }
            return result;
        }
示例#9
0
 /// <summary>
 /// Add new mall in local db
 /// </summary>
 /// <param name="mall"></param>
 /// <returns></returns>
 public bool AddNewMall(Mall_Type mall)
 {
     bool result = false;
     if (mall == null)
     {
         return result;
     }
     if (string.IsNullOrEmpty(mall.Name)) {
         return result;
     }
     using (KuanMaiEntities db = new KuanMaiEntities())
     {
         db.Mall_Type.Add(mall);
         db.SaveChanges();
         result = true;
     }
     return result;
 }
示例#10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public bool DisableCategory(int categoryId)
        {
            bool result = false;
            if (this.CurrentUserPermission.DISABLE_CATEGORY == 0)
            {
                throw new KMJXCException("没有权限禁用类目");
            }
            KuanMaiEntities db = new KuanMaiEntities();
            try
            {
                Product_Class cate=(from pc in db.Product_Class where pc.Product_Class_ID==categoryId select pc).FirstOrDefault<Product_Class>();
                if (cate == null)
                {
                    throw new KMJXCException("要操作的类目不存在");
                }

                cate.Enabled = false;
                db.SaveChanges();
                result = true;
            }
            catch (KMJXCException kex)
            {
                throw kex;
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }

            return result;
        }
示例#11
0
        /// <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;
        }
示例#12
0
        /// <summary>
        /// Create new category
        /// </summary>
        /// <param name="category">Product_Class object</param>
        /// <returns></returns>
        public bool CreateCategory(BCategory category)
        {
            bool result = false;
            if (category == null)
            {
                throw new KMJXCException("输入错误");
            }

            if (string.IsNullOrEmpty(category.Name))
            {
                throw new KMJXCException("类目名不能为空");
            }

            if (this.CurrentUserPermission.ADD_PRODUCT_CLASS == 0)
            {
                throw new KMJXCException("没有权限添加类目");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {

                Product_Class pc = new Product_Class();
                pc.Create_Time = category.Created;
                pc.Create_User_ID = this.CurrentUser.ID;
                pc.Enabled = true;
                pc.Mall_CID = category.Mall_ID;
                pc.Mall_PCID = category.Mall_PID;
                pc.Name = category.Name;
                pc.Order = category.Order;
                if (category.Shop == null || category.Shop.ID == 0)
                {
                    pc.Shop_ID = this.Shop.Shop_ID;
                }
                else
                {
                    pc.Shop_ID = category.Shop.ID;
                }
                if (category.Parent == null || category.Parent.ID <= 0)
                {
                    pc.Parent_ID = 0;
                }
                else {
                    pc.Parent_ID = category.Parent.ID;
                }

                Product_Class existed = (from ca in db.Product_Class where ca.Name.ToLower() == category.Name.ToLower() && ca.Shop_ID == pc.Shop_ID && ca.Parent_ID==pc.Parent_ID select ca).FirstOrDefault<Product_Class>();
                if (existed != null)
                {
                    if (pc.Parent_ID > 0)
                    {
                        throw new KMJXCException("名为" + category.Name + "的子类目已经存在");
                    }
                    else
                    {
                        throw new KMJXCException("名为" + category.Name + "的类目已经存在");
                    }
                }

                db.Product_Class.Add(pc);
                db.SaveChanges();
                category.ID = pc.Product_Class_ID;
                result = true;
                base.CreateActionLog(new BUserActionLog() { Shop = new BShop { ID = this.Shop.Shop_ID }, Action = new BUserAction() { Action_ID = UserLogAction.CREATE_PRODUCT_CATEGORY }, Description = "" });
            }
            return result;
        }
示例#13
0
        /// <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;
        }
示例#14
0
        public void UpdateStatus(int bug_id, int status)
        {
            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Bug bug=(from b in db.Bug where b.ID==bug_id select b).FirstOrDefault<Bug>();
                if (bug == null)
                {
                    throw new KMJXCException("编号为:"+bug_id+" 的问题不存在");
                }

                Bug_Status dbStatus=(from s in db.Bug_Status where s.ID==status select s).FirstOrDefault<Bug_Status>();
                if (dbStatus == null)
                {
                    throw new KMJXCException("状态数据:"+status+" 为无效数据");
                }

                if (bug.Status == status)
                {
                    throw new KMJXCException("当前的状态为:"+dbStatus.Status+", 选择其他状态进行设置");
                }

                bug.Status = status;
                db.SaveChanges();
            }
        }
示例#15
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="property_ids"></param>
        /// <param name="category"></param>
        /// <returns></returns>
        public bool BatchUpdatePropertiesCategory(int[] property_ids, int category)
        {
            bool result = false;
            if (this.CurrentUserPermission.UPDATE_PORPERTY==0)
            {
                throw new KMJXCException("没有权限修改属性");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                List<Product_Spec> properties=(from p in db.Product_Spec where property_ids.Contains(p.Product_Spec_ID) select p).ToList<Product_Spec>();
                foreach (Product_Spec prop in properties)
                {
                    prop.Product_Class_ID = category;
                }

                db.SaveChanges();
                result = true;
            }
            return result;
        }
示例#16
0
        /// <summary>
        /// Update actions
        /// </summary>
        /// <param name="actions"></param>
        public void UpdateAction(List<Admin_Action> actions)
        {
            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                foreach (Admin_Action action in actions)
                {
                    if (action.id > 0)
                    {
                        db.Admin_Action.Attach(action);
                    }
                }

                db.SaveChanges();
            }
        }
示例#17
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public Product_Spec CreateNewProperty(int categoryId, string propertyName, List<string> value)
        {
            Product_Spec ps=null;
            if (string.IsNullOrEmpty(propertyName))
            {
                throw new KMJXCException("属性名称不能为空");
            }

            KuanMaiEntities db = new KuanMaiEntities();
            List<Product_Spec> properties = new List<Product_Spec>();
            try
            {
                var propes=from props in db.Product_Spec where props.Name==propertyName && props.Shop_ID==this.Shop.Shop_ID select props;
                if (categoryId > 0)
                {
                    propes.Where(c=>c.Product_Class_ID==categoryId);
                }

                properties = propes.ToList<Product_Spec>();
                if (properties.Count > 0)
                {
                    throw new KMJXCException("名为"+propertyName+"已经存在");
                }

                ps = new Product_Spec();
                ps.Product_Class_ID = categoryId;
                ps.Shop_ID = this.Shop.Shop_ID;
                ps.User_ID = this.CurrentUser.ID;
                ps.Name = propertyName;
                ps.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                ps.Mall_PID = "";

                db.Product_Spec.Add(ps);
                db.SaveChanges();

                int psId = ps.Product_Spec_ID;
                if (psId == 0)
                {
                    throw new KMJXCException("产品属性创建失败");
                }

                if (value != null)
                {
                    foreach (string v in value)
                    {
                        Product_Spec_Value psv = new Product_Spec_Value();
                        psv.Product_Spec_ID = psId;
                        psv.Name = v;
                        psv.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                        psv.User_ID = ps.User_ID;
                        psv.Mall_PVID = "";
                    }
                }
            }
            catch
            {
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
            return ps;
        }
示例#18
0
        /// <summary>
        /// Update user object
        /// </summary>
        /// <param name="newUser"></param>
        public void UpdateUser(BUser user)
        {
            if (this.CurrentUserPermission.UPDATE_USER == 0)
            {
                throw new UserException("没有权限创建新用户");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                var old = from ou in db.User where ou.User_ID == user.ID select ou;

                User dbUser = old.FirstOrDefault<User>();
                if (dbUser != null)
                {
                    dbUser.User_ID = user.ID;
                    dbUser.Mall_ID = user.Mall_ID;
                    dbUser.Mall_Name = user.Mall_Name;
                    dbUser.Name = user.Name;
                    dbUser.Password = user.Password;
                    //dbUser.Mall_Type = user.Type.Mall_Type_ID;
                    if (user.Parent != null)
                    {
                        dbUser.Parent_Mall_ID = user.Parent.Mall_ID;
                        dbUser.Parent_Mall_Name = user.Parent.Mall_Name;
                        dbUser.Parent_User_ID = user.Parent.ID;
                    }

                    Employee employee = (from em in db.Employee where em.User_ID == dbUser.User_ID select em).FirstOrDefault<Employee>();
                    if (employee != null)
                    {
                        base.UpdateProperties(employee, user.EmployeeInfo);
                    }
                }
                db.SaveChanges();
            }
        }
示例#19
0
        /// <summary>
        /// The leave stocks won't be created while orders products are not mapped with local products
        /// </summary>
        /// <param name="trades"></param>
        private void CreateLeaveStocks(List<BSale> trades,Shop shop)
        {
            if (trades == null)
            {
                return;
            }
            if (shop == null)
            {
                return;
            }
            KuanMaiEntities db = new KuanMaiEntities();

            int[] csp_ids = (from child in this.DBChildShops select child.Shop_ID).ToArray<int>();
            if (csp_ids == null)
            {
                csp_ids = new int[1];
            }

            List<Product> allproducts = (from pdt in db.Product where (pdt.Shop_ID == shop.Shop_ID || pdt.Shop_ID == this.Main_Shop.Shop_ID || csp_ids.Contains(pdt.Shop_ID)) select pdt).ToList<Product>();
            string[] sale_ids=(from sale in trades select sale.Sale_ID).ToArray<string>();
            List<Leave_Stock> cacheLeaveStocks=(from ls in db.Leave_Stock where sale_ids.Contains(ls.Sale_ID) select ls).ToList<Leave_Stock>();
            Store_House house = (from store in db.Store_House where store.Default == true && (store.Shop_ID == shop.Shop_ID || store.Shop_ID == this.Main_Shop.Shop_ID || csp_ids.Contains(store.Shop_ID)) select store).FirstOrDefault<Store_House>();
            List<Store_House> houses = (from store in db.Store_House select store).ToList<Store_House>();
            List<Stock_Pile> stockPiles = (from sp in db.Stock_Pile where sp.Shop_ID == shop.Shop_ID || sp.Shop_ID == this.Main_Shop.Shop_ID || csp_ids.Contains(sp.Shop_ID) select sp).ToList<Stock_Pile>();
            List<Sale_Detail> tradeDetails=(from tradeDetail in db.Sale_Detail where sale_ids.Contains(tradeDetail.Mall_Trade_ID) select tradeDetail).ToList<Sale_Detail>();
            List<Stock_Batch> batches=(from b in db.Stock_Batch where b.ShopID==shop.Shop_ID select b).ToList<Stock_Batch>();
            try
            {
                foreach (BSale trade in trades)
                {
                    bool isNew = false;
                    Leave_Stock dbStock = null;

                    dbStock=(from cstock in cacheLeaveStocks where cstock.Sale_ID==trade.Sale_ID select cstock).FirstOrDefault<Leave_Stock>();
                    if (dbStock == null)
                    {
                        isNew = true;
                        dbStock = new Leave_Stock();
                        dbStock.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                        dbStock.Leave_Date = trade.Synced;
                        dbStock.Sale_ID = trade.Sale_ID;
                        dbStock.Shop_ID = shop.Shop_ID;
                        dbStock.User_ID = this.CurrentUser.ID;
                    }

                    if (trade.Orders != null)
                    {
                        List<Leave_Stock_Detail> dbLDetails = new List<Leave_Stock_Detail>();
                        #region handle sale orders
                        foreach (BOrder order in trade.Orders)
                        {
                            Leave_Stock_Detail dbDetail = new Leave_Stock_Detail();
                            int stockPileProductId = 0;

                            Sale_Detail order_detail = (from orderDetail in tradeDetails where orderDetail.Mall_Trade_ID == trade.Sale_ID && orderDetail.Mall_Order_ID == order.Order_ID select orderDetail).FirstOrDefault<Sale_Detail>();
                            if (order_detail == null)
                            {
                                continue;
                            }

                            order_detail.SyncResultMessage = "";
                            if (order.Refound)
                            {
                                order_detail.Status1 = (int)SaleDetailStatus.REFOUND_BEFORE_SEND;
                                order_detail.SyncResultMessage = "已经退货,不需要出库";
                                db.SaveChanges();
                                continue;
                            }

                            Product parentPdt = (from pdt in allproducts where pdt.Product_ID == order.Parent_Product_ID select pdt).FirstOrDefault<Product>();
                            Product childPdt = (from pdt in allproducts where pdt.Product_ID == order.Product_ID select pdt).FirstOrDefault<Product>();

                            order.Parent_Product_ID = 0;
                            if (parentPdt != null)
                            {
                                order.Parent_Product_ID = parentPdt.Product_ID;
                                if (childPdt != null)
                                {
                                    order.Product_ID = childPdt.Product_ID;
                                }
                                else
                                {
                                    if (!string.IsNullOrEmpty(order.Mall_SkuID))
                                    {
                                        order_detail.Status1 = (int)SaleDetailStatus.NOT_CONNECTED;
                                        order_detail.SyncResultMessage = "SKU未关联,不能更新库存";
                                        db.SaveChanges();
                                        continue;
                                    }
                                }
                            }
                            else
                            {
                                if (childPdt != null)
                                {
                                    order.Parent_Product_ID = childPdt.Parent_ID;
                                    order.Product_ID = childPdt.Product_ID;
                                }
                            }

                            //no need to create leave stock while the mall product is not mapped with local product
                            if (order.Product_ID == 0 && order.Parent_Product_ID == 0)
                            {
                                order_detail.Status1 = (int)SaleDetailStatus.NOT_CONNECTED;
                                order_detail.SyncResultMessage = "宝贝未关联,不能更新库存";
                                db.SaveChanges();
                                continue;
                            }

                            stockPileProductId = order.Product_ID;
                            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();
            }
        }
示例#20
0
        /// <summary>
        /// Update mall name or description
        /// </summary>
        /// <param name="mall"></param>
        /// <returns></returns>
        public bool UpdateMall(Mall_Type mall)
        {
            bool result = false;
            Mall_Type mall_type = null;
            using (KuanMaiEntities db = new KuanMaiEntities())
            {

                if (mall.Mall_Type_ID > 0)
                {
                    mall_type = this.GetMallDetail(mall.Mall_Type_ID);
                }
                else if (!string.IsNullOrEmpty(mall.Name))
                {
                    mall_type = this.GetMallDetail(mall.Name);
                }

                if (mall_type != null)
                {
                    db.Mall_Type.Attach(mall_type);
                    mall_type.Name = mall.Name;
                    mall_type.Description = mall.Description;
                    db.SaveChanges();
                    result = true;
                }
            }

            return result;
        }
示例#21
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public void CreateNewResponse(int bugId,string response)
        {
            if (response == null)
            {
                throw new KMJXCException("问题创建失败");
            }

            if (bugId <= 0)
            {
                throw new KMJXCException("问题创建失败");
            }
            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Bug_Response resp = new Bug_Response();

                resp.BugID = bugId;
                resp.Create_By = this.currentUser.ID;
                resp.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                resp.Description = response;

                db.Bug_Response.Add(resp);
                db.SaveChanges();
            }
        }
示例#22
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="bugId"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public bool ResolveBug(int bugId,int user_id)
        {
            bool result = false;
            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Bug existed = (from b in db.Bug where b.ID == bugId select b).FirstOrDefault<Bug>();
                if (existed == null)
                {
                    throw new KMJXCException("所需更新的Bug信息不存在");
                }

                existed.Status = 6;
                existed.Resolved = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                existed.Resolved_By = user_id;
                db.SaveChanges();
                result = true;
            }
            return result;
        }
示例#23
0
        /// <summary>
        /// Update single category
        /// </summary>
        /// <param name="category">Product_Class object</param>
        /// <returns></returns>
        public bool UpdateCategory(BCategory category)
        {
            bool result = false;
            if (category == null)
            {
                throw new KMJXCException("输入错误");
            }

            if (string.IsNullOrEmpty(category.Name))
            {
                throw new KMJXCException("类目名不能为空");
            }

            if (this.CurrentUserPermission.UPDATE_PRODUCT_CLASS == 0)
            {
                throw new KMJXCException("没有权限更新类目");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                int[] child_shops = (from c in this.DBChildShops select c.Shop_ID).ToArray<int>();

                Product_Class oldCategory = (from pc in db.Product_Class where pc.Product_Class_ID == category.ID select pc).ToList<Product_Class>()[0];

                if (oldCategory == null)
                {
                    throw new KMJXCException("您要修改的类目信息不存在");
                }

                if (this.Shop.Shop_ID != this.Main_Shop.Shop_ID)
                {
                    if (oldCategory.Shop_ID == this.Main_Shop.Shop_ID)
                    {
                        throw new KMJXCException("您不能修改主店铺类目");
                    }

                    if (oldCategory.Shop_ID == this.Shop.Shop_ID)
                    {
                        throw new KMJXCException("您不能其他主店铺类目");
                    }
                }
                else
                {
                    if (oldCategory.Shop_ID != this.Main_Shop.Shop_ID || !child_shops.Contains(oldCategory.Shop_ID))
                    {
                        throw new KMJXCException("您无法修改其他店铺的类目,只能修改主店铺或者子店铺类目");
                    }
                }

                oldCategory.Name = category.Name;
                oldCategory.Enabled = category.Enabled;
                if (category.Parent != null)
                {
                    oldCategory.Parent_ID = category.Parent.ID;
                }
                db.SaveChanges();
                result = true;
            }

            return result;
        }
示例#24
0
        /// <summary>
        /// Update access token in local db
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        private bool UpdateLocalAccessToken(Access_Token token)
        {
            bool result = false;

            Access_Token local_token = null;

            KuanMaiEntities db = new KuanMaiEntities();

            var etoken = from p in db.Access_Token where p.Mall_Type_ID == token.Mall_Type_ID && p.User_ID == token.User_ID select p;

            if (etoken != null)
            {
                local_token = etoken.ToList<Access_Token>()[0];
            }

            if (local_token != null)
            {
                local_token.Access_Token1 = token.Access_Token1;
                local_token.Expirse_In = token.Expirse_In;
                local_token.Request_Time = token.Request_Time;
                local_token.RExpirse_In = token.RExpirse_In;

                db.Access_Token.Attach(local_token);
                db.SaveChanges();
                result = true;
            }

            return result;
        }
示例#25
0
        /// <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();
                }
            }
        }
示例#26
0
        /// <summary>
        /// Calback from Mall Open API Authorization, it will verify if current login user has access to the system
        /// </summary>
        /// <param name="code">returns by Mall Open API Authorization</param>
        /// <returns></returns>
        public Access_Token AuthorizationCallBack(string code)
        {
            Access_Token request_token = null;
            BUser requester = new BUser();
            //must get access token after mall authorization to identify user
            request_token = TokenManager.RequestAccessToken(code);
            if (request_token == null)
            {
                throw new KMJXCException("没有获取到Access token", ExceptionLevel.SYSTEM);
            }

            requester.Type = new BMallType() { ID = this.Mall_Type_ID };
            requester.Mall_ID = request_token.Mall_User_ID;
            requester.Mall_Name = request_token.Mall_User_Name;
            requester.Parent_ID = 0;
            requester.Parent = null;

            KuanMaiEntities db = new KuanMaiEntities();
            try
            {
                var db_user = from u in db.User
                              where u.Mall_ID == requester.Mall_ID && u.Mall_Name == requester.Mall_Name && u.Mall_Type == this.Mall_Type_ID
                              select new BUser
                              {
                                  ID = u.User_ID,
                                  Name = u.Name,
                                  Mall_Name = u.Mall_Name,
                                  Mall_ID = u.Mall_ID,
                                  Password = u.Password,
                                  Parent_ID = (int)u.Parent_User_ID,
                              };
                List<BUser> users = db_user.ToList<BUser>();
                //Create user in local db with mall owner id
                if (users.Count == 0)
                {
                    this.InitializeMallManagers(request_token);

                    if (this.ShopManager == null)
                    {
                        throw new KMJXCException("IShopManager 实例为null", ExceptionLevel.SYSTEM);
                    }

                    //check if current user's shop is ready in system
                    Shop shop = this.ShopManager.GetShop(requester);
                    if (shop == null)
                    {
                        BUser subUser = this.MallUserManager.GetSubUser(requester.Mall_ID, requester.Mall_Name);
                        if (subUser == null)
                        {
                            throw new KMJXCException("用户:" + requester.Mall_Name + " 没有对应的" + ((KM.JXC.BL.Open.OBaseManager)this.ShopManager).MallType.Description + ",并且不属于任何店铺的子账户", ExceptionLevel.ERROR);
                        }
                        else
                        {
                            //
                            if (subUser.Parent == null || string.IsNullOrEmpty(subUser.Parent.Mall_Name))
                            {
                                throw new KMJXCException("用户:" + requester.Mall_Name + " 没有对应的" + ((KM.JXC.BL.Open.OBaseManager)this.ShopManager).MallType.Description + ",并且不属于任何店铺的子账户", ExceptionLevel.ERROR);
                            }

                            BUser mainUser = null;

                            var u = from us in db.User
                                    where us.Mall_ID == subUser.Parent.Mall_ID && us.Mall_Type == requester.Type.ID && us.Mall_Name == subUser.Parent.Mall_Name
                                    select new BUser
                                    {
                                        ID = us.User_ID,
                                        Name = us.Name,
                                        Mall_Name = us.Mall_Name,
                                        Mall_ID = us.Mall_ID,
                                        Password = us.Password,
                                        Parent_ID = (int)us.Parent_User_ID,
                                        Type = new BMallType { ID = us.Mall_Type }
                                    };
                            if (u.ToList<BUser>().Count() == 1)
                            {
                                mainUser = u.ToList<BUser>()[0];
                            }

                            if (mainUser == null)
                            {
                                throw new KMJXCException("主账户:" + subUser.Parent.Mall_Name + " 还没有初始化店铺信息,所有子账户无法登录系统", ExceptionLevel.ERROR);
                            }

                            requester.Parent_ID = mainUser.ID;
                            requester.Parent = mainUser;
                            requester.EmployeeInfo = subUser.EmployeeInfo;

                        }
                    }

                    //create user in local db
                    requester.Name = requester.Mall_Name;
                    requester.Password = Guid.NewGuid().ToString();

                    User dbUser = new User();
                    dbUser.User_ID = requester.ID;
                    dbUser.Mall_ID = requester.Mall_ID;
                    dbUser.Mall_Name = requester.Mall_Name;
                    dbUser.NickName = "";
                    dbUser.Name = requester.Name;
                    dbUser.Mall_Type = requester.Type.ID;
                    dbUser.Parent_Mall_ID = "";
                    dbUser.Parent_Mall_Name = "";
                    dbUser.Parent_User_ID = 0;
                    dbUser.Password = "";
                    dbUser.Name = dbUser.Mall_Name;
                    dbUser.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    dbUser.Modified = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    dbUser.Modified_By = 0;

                    if (requester.Parent != null)
                    {
                        dbUser.Parent_Mall_ID = requester.Parent.Mall_ID;
                        dbUser.Parent_Mall_Name = requester.Parent.Mall_Name;
                        dbUser.Parent_User_ID = requester.Parent.ID;
                    }

                    db.User.Add(dbUser);
                    db.SaveChanges();

                    //create access token for the new user
                    request_token.User_ID = dbUser.User_ID;
                    requester.ID = dbUser.User_ID;
                    db.Access_Token.Add(request_token);

                    //save employee
                    if (requester.Parent_ID > 0 && requester.EmployeeInfo != null)
                    {
                        requester.EmployeeInfo.User_ID = requester.ID;
                        Employee employee = new Employee();
                        employee.Name = requester.EmployeeInfo.Name;
                        employee.IdentityCard = requester.EmployeeInfo.IdentityCard;
                        employee.MatureDate = requester.EmployeeInfo.MatureDate;
                        employee.Phone = requester.EmployeeInfo.Phone;
                        employee.User_ID=requester.EmployeeInfo.User_ID;
                        employee.HireDate = requester.EmployeeInfo.HireDate;
                        employee.Gendar = requester.EmployeeInfo.Gendar;
                        employee.Duty = requester.EmployeeInfo.Duty;
                        employee.Email = requester.EmployeeInfo.Email;
                        employee.Department = requester.EmployeeInfo.Department;
                        employee.BirthDate = requester.EmployeeInfo.BirthDate;
                        employee.Address = requester.EmployeeInfo.Address;
                        db.Employee.Add(employee);
                    }

                    if (shop != null)
                    {
                        //create local shop information for the new main user
                        shop.User_ID = requester.ID;
                        shop.Parent_Shop_ID = 0;
                        shop.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                        shop.Synced = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                        db.Shop.Add(shop);
                        db.SaveChanges();

                        //save shop user
                        Shop_User shop_User = new Shop_User();
                        shop_User.User_ID = requester.ID;
                        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;
        }
示例#27
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="shop_id"></param>
        /// <returns></returns>
        public bool SyncShopSubUsers(int shop_id)
        {
            bool result = false;

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                BUser dbUser = (from us in db.User
                                from sp in db.Shop
                                where us.User_ID == sp.User_ID && sp.Shop_ID == shop_id
                                select new BUser
                                {
                                    ID = us.User_ID,
                                    //EmployeeInfo = (from e in db.Employee where e.User_ID == us.User_ID select e).FirstOrDefault<Employee>(),
                                    Mall_ID = us.Mall_ID,
                                    Mall_Name = us.Mall_Name,
                                    Type = (from type in db.Mall_Type where type.Mall_Type_ID == us.Mall_Type
                                            select new BMallType { ID=type.Mall_Type_ID,Name=type.Name,Description=type.Description }).FirstOrDefault<BMallType>(),
                                    Parent_ID = (int)us.Parent_User_ID,
                                    Parent = null,
                                    Name = us.Name,
                                    Password = us.Password
                                }).FirstOrDefault<BUser>();

                if (dbUser == null)
                {
                    throw new KMJXCException("没有找到对应店铺的卖家信息");
                }

                List<BUser> subUsers = this.MallUserManager.GetSubUsers(dbUser);
                List<BUser> existedUsers = (from us in db.User
                                            from sp in db.Shop_User
                                            where us.User_ID == sp.User_ID && sp.Shop_ID == shop_id
                                            select new BUser
                                            {
                                                ID = us.User_ID,
                                                //EmployeeInfo = (from e in db.Employee where e.User_ID == us.User_ID select e).FirstOrDefault<Employee>(),
                                                Mall_ID = us.Mall_ID,
                                                Mall_Name = us.Mall_Name,
                                                Type = (from type in db.Mall_Type where type.Mall_Type_ID == us.Mall_Type
                                                        select new BMallType { ID=type.Mall_Type_ID,Name=type.Name,Description=type.Description }).FirstOrDefault<BMallType>(),
                                                Parent_ID = (int)us.Parent_User_ID,
                                                Parent = null,
                                                Name = us.Name,
                                                Password = us.Password
                                            }).ToList<BUser>();

                foreach (BUser user in subUsers)
                {
                    bool found = false;
                    foreach (BUser eUser in existedUsers)
                    {
                        if (user.Mall_ID == eUser.Mall_ID && user.Mall_Name == eUser.Mall_Name)
                        {
                            //Update user
                            found = true;
                            eUser.EmployeeInfo = user.EmployeeInfo;
                            eUser.Name = user.Name;
                            break;
                        }
                    }

                    if (!found)
                    {
                        //add new sub user
                        User dbUser1 = new User();
                        //dbUser1.User_ID = user.ID;
                        dbUser1.Mall_ID = user.Mall_ID;
                        dbUser1.Mall_Name = user.Mall_Name;
                        dbUser1.Name = user.Name;
                        dbUser1.Mall_Type = user.Type.ID;
                        if (user.Parent != null)
                        {
                            dbUser1.Parent_Mall_ID = user.Parent.Mall_ID;
                            dbUser1.Parent_Mall_Name = user.Parent.Mall_Name;
                            dbUser1.Parent_User_ID = user.Parent.ID;
                        }
                        db.User.Add(dbUser1);
                        db.SaveChanges();

                        if (user.EmployeeInfo != null && dbUser1.User_ID>0)
                        {
                            Employee employee = new Employee();
                            employee.Name = user.EmployeeInfo.Name;
                            employee.IdentityCard = user.EmployeeInfo.IdentityCard;
                            employee.MatureDate = user.EmployeeInfo.MatureDate;
                            employee.Phone = user.EmployeeInfo.Phone;
                            employee.User_ID = user.EmployeeInfo.User_ID;
                            employee.HireDate = user.EmployeeInfo.HireDate;
                            employee.Gendar = user.EmployeeInfo.Gendar;
                            employee.Duty = user.EmployeeInfo.Duty;
                            employee.Email = user.EmployeeInfo.Email;
                            employee.Department = user.EmployeeInfo.Department;
                            employee.BirthDate = user.EmployeeInfo.BirthDate;
                            employee.Address = user.EmployeeInfo.Address;
                            db.Employee.Add(employee);
                        }

                        Shop_User sp = new Shop_User();
                        sp.Shop_ID = shop_id;
                        sp.User_ID = dbUser1.User_ID;
                        db.Shop_User.Add(sp);
                    }
                }

                db.SaveChanges();
            }

            return result;
        }
示例#28
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="bug"></param>
        /// <returns></returns>
        public bool UpdateBug(BBug bug)
        {
            if (bug.Modified_By == null)
            {
                throw new KMJXCException("更新Bug时必须有更新人");
            }
            bool result = false;
            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Bug existed=(from b in db.Bug where b.ID==bug.ID select b).FirstOrDefault<Bug>();
                if (existed == null)
                {
                    throw new KMJXCException("所需更新的Bug信息不存在");
                }

                if (bug.Status != null)
                {
                    existed.Status = bug.Status.ID;
                }

                if (bug.Modified_By != null)
                {
                    existed.Modified_By = bug.Modified_By.ID;
                    existed.Modified = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                }
                if (!string.IsNullOrEmpty(bug.Title))
                {
                    existed.Title = bug.Title;
                }

                if (!string.IsNullOrEmpty(bug.Description))
                {
                    existed.Description = bug.Description;
                }
                db.SaveChanges();
                result = true;
            }
            return result;
        }
示例#29
0
        /// <summary>
        /// Create new user
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public BUser CreateNewUser(BUser user)
        {
            if (user == null) {
                throw new UserException("用户实体不能为空引用");
            }

            if (string.IsNullOrEmpty(user.Name)) {
                throw new UserException("用户名不能为空");
            }

            if (this.CurrentUserPermission.ADD_USER == 0)
            {
                throw new UserException("没有权限创建新用户");
            }

            KuanMaiEntities dba = new KuanMaiEntities();
            try
            {
                if (GetUser(user) != null)
                    throw new UserException("用户名已经存在");

                User dbUser = new User();
                dbUser.User_ID = user.ID;
                dbUser.Mall_ID = user.Mall_ID;
                dbUser.Mall_Name = user.Mall_Name;
                dbUser.Name = user.Name;
                dbUser.Mall_Type = user.Type.ID;
                if (user.Parent != null)
                {
                    dbUser.Parent_Mall_ID = user.Parent.Mall_ID;
                    dbUser.Parent_Mall_Name = user.Parent.Mall_Name;
                    dbUser.Parent_User_ID = user.Parent.ID;
                }
                dba.User.Add(dbUser);
                dba.SaveChanges();
                return user;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (dba != null)
                {
                    dba.Dispose();
                }
            }
        }
示例#30
0
        /// <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();
            }
        }