Esempio n. 1
0
        /// <summary>
        /// 更新HMNUMCosting的信息,用于HMNUM Management页面的的inline-edit的编辑更新
        /// 需要注意的是每一次的跟新都将在库表新增一条价格信息,影响将来报表的生成。
        /// CreateDate:2013年11月13日6:00:34
        /// </summary>
        /// <param name="model"></param>
        /// <param name="costing"></param>
        /// <returns></returns>
        public bool EditHMNUMCosting(CMS_HMNUM_Model model, CMS_HM_Costing_Model costing, string User_Account)
        {
            //逻辑:先讲当前最新的价格插入到Costing表(注意是新增不是编辑),然后更新当前HMNUM的Costing信息,取最新的那条。
            //EF本身自带有Transaction功能。
            using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
            {
                int retVal     = 0;
                var newCosting = new CMS_HM_Costing
                {
                    CreateBy      = User_Account,
                    CreateOn      = DateTime.Now,
                    EffectiveDate = DateTime.Now,

                    HMNUM           = costing.HMNUM,
                    FirstCost       = Convert.ToDecimal(costing.FirstCost),
                    LandedCost      = Convert.ToDecimal(costing.LandedCost),
                    EstimateFreight = Convert.ToDecimal(costing.EstimateFreight),

                    OceanFreight      = Convert.ToDecimal(costing.OceanFreight),
                    USAHandlingCharge = Convert.ToDecimal(costing.USAHandlingCharge),
                    Drayage           = Convert.ToDecimal(costing.Drayage),
                };
                db.CMS_HM_Costing.Add(newCosting);
                long newCostID = newCosting.HMCostID;
                var  HMNUM     = db.CMS_HMNUM.FirstOrDefault(h => h.ProductID == model.ProductID);
                HMNUM.HMCostID = newCostID;
                retVal         = db.SaveChanges();

                newCosting.HisProductID = HMNUM.ProductID;
                retVal = db.SaveChanges();
                return(retVal > 0);
            }
        }
        /// <summary>
        /// 算法:根据组合产品的ProductID和其子产品的ChildrenProductID唯一确定一条记录,删除再插入。删除插入一并做,会大大简化程序和客户端的各种判断。
        /// CreateDate: 2013年11月19日11:43:22
        /// </summary>
        /// <param name="rModel"></param>
        /// <param name="User_Account"></param>
        /// <returns>如果新增成功,返回新的ID</returns>
        public long AddNewHM4Group(CMS_HMGroup_Relation_Model rModel, String User_Account)
        {
            using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
            {
                //这种方法如果表结构改动,会大大增加维护成本。根据实际情况,可能组合产品的新增操作不是很频繁,并不会很大程度上影响性能,所以还是用EF来做
                //using (TransactionScope transaction = new TransactionScope())
                //{
                //  //db.Database.ExecuteSqlCommand("delete from CMS_HMGroup_Relation where ProductID = @ProductID and ChildrenProductID", new SqlParameter("@ProductID", rModel.ProductID));
                //}
                //if (rModel.RID > 0)//说明是在原有的基础上编辑而不是新增,直接删除了吧...2013年11月20日14:42:23
                //{
                //    var relation = new CMS_HMGroup_Relation { RID = rModel.RID };
                //    db.Set<CMS_HMGroup_Relation>().Attach(relation);
                //    db.CMS_HMGroup_Relation.Remove(relation);
                //}

                //var query = db.CMS_HMGroup_Relation.Where(r => r.ProductID == rModel.ProductID && r.ChildrenProductID == rModel.ChildrenProductID).FirstOrDefault();
                //if (query != null)
                //{
                //    //db.Set<CMS_HMGroup_Relation>().Attach(query);
                //    db.CMS_HMGroup_Relation.Remove(query);
                //}

                //var rel = db.CMS_HMGroup_Relation.FirstOrDefault(r => r.RID == rModel.RID);

                /*使用RID来做判断,在2014年4月28日 下发生产环境的时候遇到很多问题,最典型的一个就是前端使用复制HMNUM,
                 * 然后选择下拉单,然后离开鼠标,客户端触发了2次RID为0的AJAX数据,造成该条数据重复插入两次。经过调试发现,ProductID是可以当成一个KEY读取,比如一个组合产品的ProductID
                 * 只会有一个,即使下一次再Create一个同样名称的组合产品,由于库表是自动增长的ID,所以名称一样没关系,ID不一样 2014年4月29日9:26:55
                 */
                var rel = db.CMS_HMGroup_Relation.FirstOrDefault(r => r.ProductID == rModel.ProductID && r.ChildrenProductID == rModel.ChildrenProductID);
                if (rel == null)
                {
                    var newModel = new CMS_HMGroup_Relation
                    {
                        ProductID         = rModel.ProductID,
                        ChildrenProductID = rModel.ChildrenProductID,
                        SellSets          = rModel.SellSets,
                        CreateBy          = User_Account,
                        CreateOn          = DateTime.Now
                    };
                    db.CMS_HMGroup_Relation.Add(newModel);
                    db.SaveChanges();
                    return(newModel.RID);
                }
                else
                {
                    rel.ProductID         = rModel.ProductID;
                    rel.SellSets          = rModel.SellSets;
                    rel.ChildrenProductID = rModel.ChildrenProductID;
                    db.SaveChanges();
                    return(rel.RID);
                }
            }
        }
        /// <summary>
        /// 插入基础产品的HMNUM
        /// </summary>
        /// <param name="db"></param>
        /// <param name="groupProductID">组合产品的ID</param>
        /// <param name="newHMCost"></param>
        /// <param name="newHM"></param>
        /// <param name="newCTN"></param>
        /// <param name="newDim"></param>
        /// <param name="SellSets">...</param>
        public void InsertBasicHM(PermaisuriCMSEntities db, long groupProductID, CMS_HM_Costing newHMCost, CMS_HMNUM newHM,
                                  CMS_ProductCTN newCTN, CMS_ProductDimension newDim, int SellSets)
        {
            //先判断是否存在这个基础HMNUM
            long basicProductID = 0;
            var  isExistHM      = db.CMS_HMNUM.FirstOrDefault(h => h.HMNUM == newHM.HMNUM);

            if (isExistHM == null)
            {
                db.CMS_HM_Costing.Add(newHMCost);
                long newHMCostID = newHMCost.HMCostID;

                newHM.HMCostID = newHMCostID;
                db.CMS_HMNUM.Add(newHM);
                db.SaveChanges();
                basicProductID         = newHM.ProductID;
                newHMCost.HisProductID = newHM.ProductID;

                //尺寸箱柜
                newCTN.ProductID = basicProductID;
                newDim.ProductID = basicProductID;
                db.CMS_ProductCTN.Add(newCTN);
                db.CMS_ProductDimension.Add(newDim);
            }
            else
            {
                OnOperateNotify(this, new HMEventArgs(String.Format("CMS_HMNUM(基础数据)表已经存在HMNUM={0}的数据,忽略过不插入", newHM.HMNUM)));
                HMLog.Info(String.Format("CMS_HMNUM(基础数据)表已经存在HMNUM={0}的数据,忽略过不插入", newHM.HMNUM));
                basicProductID = isExistHM.ProductID;
            }

            var newRelation = db.CMS_HMGroup_Relation.FirstOrDefault(r => r.ProductID == groupProductID && r.ChildrenProductID == basicProductID);

            if (newRelation == null)
            {
                //组合产品--基础产品--的关系表
                var newRel = new CMS_HMGroup_Relation
                {
                    ChildrenProductID = basicProductID,
                    ProductID         = groupProductID,
                    SellSets          = SellSets,
                    CreateBy          = UpdateBy,
                    CreateOn          = DateTime.Now
                };
                db.CMS_HMGroup_Relation.Add(newRel);
            }
            else
            {
                OnOperateNotify(this, new HMEventArgs(String.Format("CMS_HMGroup_Relation表已经存在ProductID={0},ChildrenProductID={1}的数据,忽略过不插入", groupProductID, basicProductID)));
                HMLog.Info(String.Format("CMS_HMGroup_Relation表已经存在ProductID={0},ChildrenProductID={1}的数据,忽略过不插入", groupProductID, basicProductID));
            }
            db.SaveChanges();
        }
Esempio n. 4
0
        public bool AddChannel(Channel_Model model, string user, ref string msg)
        {
            using (var db = new PermaisuriCMSEntities())
            {
                var isExist = db.Channel.FirstOrDefault(c => c.ChannelName == model.ChannelName);
                msg = string.Empty;
                if (isExist != null)
                {
                    msg = "This item does exist";
                    return(false);
                }

                var newChannel = new Channel
                {
                    ChannelName = model.ChannelName,
                    ShortName   = model.ShortName,
                    Modifier    = user,
                    Modify_Date = DateTime.Now,
                    API         = model.API,
                    Export2CSV  = model.Export2CSV
                };
                db.Channel.Add(newChannel);
                return(db.SaveChanges() > 0);
            }
        }
        /// <summary>
        /// 2013年12月25日10:55:28
        /// Change1:将原来自动删除该图像关联的SKU信息,改成查询判断如果存在关联信息,则不自动删除,返回报错信息给前端 。 2014年5月15日11:29:15
        /// </summary>
        /// <param name="MediaID"></param>
        /// <returns></returns>
        public bool DeleteCMSMedia(long MediaID, out string errMsg)
        {
            errMsg = string.Empty;
            using (var db = new PermaisuriCMSEntities())
            {
                ////这样做的好处在于能直接删除一个对象,而不需要先从数据库中提取数据,创建实体对象,再查找并删除之,从而能有效地提升效率
                //MediaLibrary media = new MediaLibrary { MediaID = MediaID };
                //db.Set<MediaLibrary>().Attach(media);
                //db.MediaLibrary.Remove(media);
                //return db.SaveChanges() > 0;

                //var query = db.MediaLibrary.Include(s=>s.SKU_Media_Relation).FirstOrDefault(s => s.MediaID == MediaID);
                //db.MediaLibrary.Remove(query);
                //return db.SaveChanges() > 0;

                var query = db.MediaLibrary.FirstOrDefault(s => s.MediaID == MediaID);
                if (query != null && query.SKU_Media_Relation.Count > 0)
                {
                    errMsg = "This item can no be delete, because some skus have been associated with it.";
                    return(false);
                }
                db.MediaLibrary.Remove(query);
                /*以下方法是用于删除图像的时候,自动删除所关联的信息,如果不删除,将会引发打开数据异常!*/
                //db.Entry(query).Collection(m => m.SKU_Media_Relation).Load();
                //db.MediaLibrary.Remove(query);
                return(db.SaveChanges() > 0);
            }
        }
Esempio n. 6
0
        public bool EditShipVia(CMS_ShipVia_Model shipViaModel, User_Profile_Model userModel, out string msg)
        {
            using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
            {
                msg = string.Empty;
                var query = db.CMS_ShipVia.FirstOrDefault(s => s.SHIPVIAID == shipViaModel.SHIPVIAID);
                if (query == null)
                {
                    msg = string.Format("The name of {0} does not exist", shipViaModel.SHIPVIA);
                    return(false);
                }

                //如果客户端请求讲当前SHIPVIA作为默认的项目传送给eCom,则需要单独处理
                if (shipViaModel.IsDefaultShipVia == true)
                {
                    db.CMS_ShipVia.Where(s => s.ShipViaTypeID == shipViaModel.ShipViaTypeID).Update(s => new CMS_ShipVia
                    {
                        IsDefaultShipVia = false
                    });
                }
                //query.SHIPVIA = shipViaModel.SHIPVIA;
                query.ShipViaTypeID    = shipViaModel.ShipViaTypeID;
                query.ExpressMethod    = shipViaModel.ExpressMethod;
                query.ExpressNumLength = shipViaModel.ExpressNumLength;
                query.IsDefaultShipVia = shipViaModel.IsDefaultShipVia;
                query.CarrierCode      = shipViaModel.CarrierCode;
                query.CarrierRouting   = shipViaModel.CarrierRouting;
                query.ExpressRule      = shipViaModel.ExpressRule;
                query.UpdateBy         = userModel.User_Account;
                query.UpdateOn         = DateTime.Now;
                return(db.SaveChanges() > 0);
            }
        }
        public bool AddBrand(Brands_Info_Model model, string user, ref string msg)
        {
            using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
            {
                var isExist = db.Brand.FirstOrDefault(c => c.BrandName == model.Brand_Name);
                msg = string.Empty;

                if (isExist != null)
                {
                    msg = "This item does exist";
                    return(false);
                }

                var newBrand = new Brand
                {
                    BrandName     = model.Brand_Name,
                    ShortName     = model.Short_Name,
                    Modifier      = user,
                    Modifier_Date = DateTime.Now,
                    Active        = model.Active
                };
                db.Brand.Add(newBrand);
                return(db.SaveChanges() > 0);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 更新当前用户对于的Channel信息,用户User Management模块的Channel Setting
        /// Author:Lee Date:2013年11月1日18:06:15
        /// </summary>
        /// <param name="userGuid"></param>
        /// <param name="ArrChannels"></param>
        /// <returns></returns>
        public bool UpdateUserChannel(Guid userGuid, IEnumerable <int> ArrChannels)
        {
            using (var db = new PermaisuriCMSEntities())
            {
                using (var transaction = new TransactionScope())
                {
                    db.Database.ExecuteSqlCommand("delete from User_Channel_Relation where User_Guid = @User_Guid",
                                                  new SqlParameter("@User_Guid", userGuid));

                    //User_Channel_Relation relation = new User_Channel_Relation { User_Guid = User_Guid };
                    //db.Set<User_Channel_Relation>().Attach(relation);
                    //db.User_Channel_Relation.Remove(relation);这种方法没有数据的时候会报错
                    if (ArrChannels != null)
                    {
                        foreach (var mediaId in ArrChannels)
                        {
                            db.User_Channel_Relation.Add(new User_Channel_Relation
                            {
                                User_Guid = userGuid,
                                ChannelID = mediaId
                            });
                        }
                    }
                    var retInt = db.SaveChanges();
                    transaction.Complete(); // don't be miss,or the SQL statement will never be executed
                    return(retInt > 0);
                }
            }
        }
Esempio n. 9
0
 /// <summary>
 /// 算法:根据组合产品的ProductID和SKUID唯一确定一条记录,删除再插入。删除插入一并做,会大大简化程序和客户端的各种判断。
 /// CreateDate: 2013年11月19日11:43:22
 /// </summary>
 /// <param name="rModel"></param>
 /// <param name="User_Account"></param>
 /// <returns>如果新增成功,返回新的ID</returns>
 public Boolean AddNewHM4SKU(SKU_HM_Relation_Model rModel, String User_Account)
 {
     using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
     {
         var query = db.SKU_HM_Relation.FirstOrDefault(r => r.SKUID == rModel.SKUID);
         if (query == null)
         {
             var newModel = new SKU_HM_Relation
             {
                 ProductID  = rModel.ProductID,
                 SKUID      = rModel.SKUID,
                 R_QTY      = rModel.R_QTY,
                 StockKeyID = rModel.StockKeyID,
                 CreateBy   = User_Account,
                 CreateOn   = DateTime.Now,
                 UpdateBy   = User_Account,
                 UpdateOn   = DateTime.Now
             };
             db.SKU_HM_Relation.Add(newModel);
         }
         else
         {
             query.StockKeyID = rModel.StockKeyID;
             query.R_QTY      = rModel.R_QTY;
             query.ProductID  = rModel.ProductID;
             query.UpdateBy   = User_Account;
             query.UpdateOn   = DateTime.Now;
         }
         return(db.SaveChanges() > 0);
     }
 }
 /// <summary>
 /// 赋予/撤销用户权限算法
 /// </summary>
 /// <param name="role_guid">需要赋予当前用户什么权限</param>
 /// <param name="user_guid">当前用户唯一标识</param>
 /// <returns></returns>
 public bool UpdateRoleInUser(string[] role_guid, Guid user_guid)
 {
     using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
     {
         /***
          * var tranny = DbContext.Database.Connection.BeginTransaction();
          * tranny.Commit();
          ***/
         using (TransactionScope transaction = new TransactionScope())
         {
             db.Database.ExecuteSqlCommand("delete from User_Role_Relation where User_Guid = @User_Guid", new SqlParameter("@User_Guid", user_guid));
             foreach (string role_guids in role_guid)
             {
                 var newRelation = new User_Role_Relation
                 {
                     Role_Guid = new Guid(role_guids),
                     User_Guid = user_guid
                 };
                 db.User_Role_Relation.Add(newRelation);
             }
             int retInt = db.SaveChanges();
             transaction.Complete();// don't be miss,or the SQL statement will never be executed
             return(retInt > 0);
         }
     }
 }
Esempio n. 11
0
        /// <summary>
        /// 根据传递进来的文件名删除文件
        /// Change1:在删除文件之前,必须先删除文件的关系表
        /// </summary>
        /// <param name="MediaID"></param>
        /// <returns></returns>
        public bool removeMediaLibraryByID(long MediaID)
        {
            using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
            {
                //必须先删除关系,否则会造成数据大概 整个页面Null reference Object!

                /*Store update, insert, or delete statement affected an unexpected number of rows (0).
                 * Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager
                 * SQL Profiler查询追踪到的是 exec sp_executesql N'delete [dbo].[SKU_Media_Relation] where ([RelationID] = @0)',N'@0 bigint',@0=0
                 * 明显的 ,是以RelationID做为Key去删除!所以这种方法不科学....2014年2月14日14:57:34*/
                //SKU_Media_Relation mr = new SKU_Media_Relation { MediaID = MediaID };
                //db.Set<SKU_Media_Relation>().Attach(mr);
                //db.SKU_Media_Relation.Remove(mr);


                //var query = db.SKU_Media_Relation.Where(r=>r.MediaID==MediaID);
                //foreach (var m in query)
                //{
                //    db.SKU_Media_Relation.Remove(m);
                //}

                //MediaLibrary ml = new MediaLibrary { MediaID = MediaID };
                //db.Set<MediaLibrary>().Attach(ml);
                //db.MediaLibrary.Remove(ml);
                //return db.SaveChanges() > 0;

                /*以下方法是用于删除图像的时候,自动删除所关联的信息,如果不删除,将会引发打开数据异常!*/
                var query = db.MediaLibrary.FirstOrDefault(s => s.MediaID == MediaID);
                db.Entry(query).Collection(m => m.SKU_Media_Relation).Load();
                db.MediaLibrary.Remove(query);
                return(db.SaveChanges() > 0);
            }
        }
Esempio n. 12
0
 public bool addMediaLibrary(MediaLibrary_Model c, string User_Account, out long newID)
 {
     using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
     {
         var          hm        = db.CMS_HMNUM.FirstOrDefault(h => h.ProductID == c.ProductID);
         var          ExistPImg = hm.CMS_StockKey.MediaLibrary.FirstOrDefault(r => r.PrimaryImage == true);
         MediaLibrary newMedia  = new MediaLibrary
         {
             ProductID     = c.ProductID,
             StockKeyID    = hm.StockKeyID,
             HMNUM         = c.HMNUM,
             SerialNum     = c.SerialNum,
             ImgName       = c.ImgName,
             MediaType     = c.MediaType,
             fileFormat    = c.fileFormat,
             fileSize      = c.fileSize,
             fileWidth     = c.fileWidth,
             fileHeight    = c.fileHeight,
             Description   = c.Description,
             CreateOn      = DateTime.Now,
             CreateBy      = User_Account,
             CloudStatusID = 1,
             PrimaryImage  = ExistPImg == null ? true : false
         };
         db.MediaLibrary.Add(newMedia);
         int eVal = db.SaveChanges();
         newID = newMedia.MediaID;
         return(eVal > 0);
     }
 }
Esempio n. 13
0
        public bool DeleteShipVia(CMS_ShipVia_Model shipViaModel, User_Profile_Model userModel, out string msg)
        {
            using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
            {
                msg = string.Empty;
                var isDefault = false;
                var query     = db.CMS_ShipVia.FirstOrDefault(s => s.SHIPVIAID == shipViaModel.SHIPVIAID);
                if (query == null)
                {
                    msg = string.Format("The name of {0} does not exist", shipViaModel.SHIPVIA);
                    return(false);
                }

                //如果客户端请求讲当前SHIPVIA作为默认的项目传送给eCom,则需要单独处理
                isDefault = query.IsDefaultShipVia;
                db.CMS_ShipVia.Remove(query);
                if (isDefault)
                {
                    var randomSV = db.CMS_ShipVia.Where(s => s.SHIPVIAID != shipViaModel.SHIPVIAID && s.ShipViaTypeID == query.ShipViaTypeID)
                                   .OrderByDescending(r => r.SHIPVIAID).FirstOrDefault();
                    if (randomSV != null)
                    {
                        randomSV.IsDefaultShipVia = true;
                    }
                }
                return(db.SaveChanges() > 0);
            }
        }
Esempio n. 14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctnModel"></param>
        /// <param name="userAccount"></param>
        /// <param name="ctnid"></param>
        /// <returns></returns>
        public bool AddHmCarton(CMS_ProductCTN_Model ctnModel, string userAccount, out long ctnid)
        {
            using (var db = new PermaisuriCMSEntities())
            {
                var hmnum = db.CMS_HMNUM.FirstOrDefault(h => h.ProductID == ctnModel.ProductID);
                if (hmnum == null)
                {
                    ctnid = 0;
                    return(false);
                }

                var newModel = new CMS_ProductCTN
                {
                    CTNComment = ctnModel.CTNComment,
                    CTNCube    = ctnModel.CTNCube,
                    CTNHeight  = ctnModel.CTNHeight,
                    CTNLength  = ctnModel.CTNLength,
                    CTNTitle   = ctnModel.CTNTitle,
                    CTNWidth   = ctnModel.CTNWidth,
                    HMNUM      = ctnModel.HMNUM,
                    ProductID  = ctnModel.ProductID,
                    UpdateBy   = userAccount,
                    UpdateOn   = DateTime.Now,
                    CreateOn   = DateTime.Now,
                    CTNWeight  = ctnModel.CTNWeight
                };

                db.CMS_ProductCTN.Add(newModel);

                hmnum.SKU_HM_Relation.Select(r => r.CMS_SKU.CMS_Ecom_Sync ?? (r.CMS_SKU.CMS_Ecom_Sync = new CMS_Ecom_Sync
                {
                    StatusID = 1//这里可以不用做任何设置,因为后面那个操作会全面覆盖这个...
                })).ForEach(k =>
                {
                    k.StatusID   = 0;
                    k.StatusDesc = "NeedSend";
                    k.UpdateBy   = userAccount;
                    k.UpdateOn   = DateTime.Now;
                });

                BllExtention.DbRecorder(new LogOfUserOperatingDetails
                {
                    ModelName    = ModelName,
                    ActionName   = MethodBase.GetCurrentMethod().Name,
                    ActionType   = LogActionTypeEnum.Inert.GetHashCode(),
                    ProductID    = hmnum.ProductID,
                    HMNUM        = hmnum.HMNUM,
                    Descriptions = "Add new carton  [ <b>" + newModel.CTNTitle + " </b>] for " + hmnum.HMNUM,
                    CreateBy     = userAccount,
                    CreateOn     = DateTime.Now
                });


                var retVal = db.SaveChanges();
                ctnid = newModel.CTNID;
                return(retVal > 0);
            }
        }
Esempio n. 15
0
        public bool EditHmCartons(IEnumerable <CMS_ProductCTN_Model> ctnList, string userAccount)
        {
            if (ctnList == null)
            {
                throw new ArgumentNullException("ctnList");
            }

            using (var db = new PermaisuriCMSEntities())
            {
                var retVal = 0;
                foreach (var model in ctnList)
                {
                    var ctn = db.CMS_ProductCTN.FirstOrDefault(c => c.CTNID == model.CTNID);
                    if (ctn != null)
                    {
                        ctn.CTNCube    = model.CTNCube;
                        ctn.CTNLength  = model.CTNLength;
                        ctn.CTNWidth   = model.CTNWidth;
                        ctn.CTNHeight  = model.CTNHeight;
                        ctn.CTNComment = model.CTNComment;
                        ctn.UpdateBy   = userAccount;
                        ctn.CTNWeight  = model.CTNWeight;//新增重量信息 2014年3月6日


                        ctn.CMS_HMNUM.SKU_HM_Relation.Select(r => r.CMS_SKU.CMS_Ecom_Sync ?? (r.CMS_SKU.CMS_Ecom_Sync = new CMS_Ecom_Sync
                        {
                            StatusID = 1//这里可以不用做任何设置,因为后面那个操作会全面覆盖这个...
                        })).ForEach(k =>
                        {
                            k.StatusID   = 0;
                            k.StatusDesc = "NeedSend";
                            k.UpdateBy   = userAccount;
                            k.UpdateOn   = DateTime.Now;
                        });

                        var entry = db.Entry(ctn);
                        BllExtention.DbRecorder(entry, new LogOfUserOperatingDetails
                        {
                            ModelName  = ModelName,
                            ActionName = MethodBase.GetCurrentMethod().Name,
                            ActionType = LogActionTypeEnum.Update.GetHashCode(),
                            ProductID  = ctn.ProductID,
                            HMNUM      = ctn.HMNUM,
                            CreateBy   = userAccount,
                            CreateOn   = DateTime.Now
                        });


                        ctn.UpdateOn = DateTime.Now;
                    }


                    retVal = db.SaveChanges();//如果上面的几个Value都没有改变,则返回的值还是0 2013年11月15日17:20:03
                }
                return(retVal > 0);
            }
        }
Esempio n. 16
0
        /// <summary>
        /// 编辑HM#基本信息,用于HMNUM Configuration页面
        /// </summary>
        /// <param name="model"></param>
        /// <param name="userAccount"></param>
        /// <returns></returns>
        public bool EditHmBasicInfo(CMS_HMNUM_Model model, string userAccount)
        {
            using (var db = new PermaisuriCMSEntities())
            {
                var hmnum = db.CMS_HMNUM.FirstOrDefault(h => h.ProductID == model.ProductID);
                if (hmnum == null)
                {
                    return(db.SaveChanges() > 0);
                }
                hmnum.StockKey      = model.StockKey;
                hmnum.Comments      = model.Comments;
                hmnum.StatusID      = model.StatusID;
                hmnum.ShipViaTypeID = model.ShipViaTypeID;
                hmnum.NetWeight     = model.NetWeight;
                hmnum.SKU_HM_Relation.Select(r => r.CMS_SKU.CMS_Ecom_Sync ?? (r.CMS_SKU.CMS_Ecom_Sync = new CMS_Ecom_Sync
                {
                    StatusID = 1//这里可以不用做任何设置,因为后面那个操作会全面覆盖这个...
                })).ForEach(k =>
                {
                    k.StatusID   = 0;
                    k.StatusDesc = "NeedSend";
                    k.UpdateBy   = userAccount;
                    k.UpdateOn   = DateTime.Now;
                });

                var entry = db.Entry(hmnum);
                BllExtention.DbRecorder(entry, new LogOfUserOperatingDetails
                {
                    ModelName  = ModelName,
                    ActionName = MethodBase.GetCurrentMethod().Name,
                    ActionType = LogActionTypeEnum.Update.GetHashCode(),
                    ProductID  = hmnum.ProductID,
                    HMNUM      = hmnum.HMNUM,
                    CreateBy   = userAccount,
                    CreateOn   = DateTime.Now
                });

                hmnum.ModifyBy = userAccount;
                hmnum.ModifyOn = DateTime.Now;


                return(db.SaveChanges() > 0);
            }
        }
        /// <summary>
        /// Parallel方法实现,仅供参考,注意数据库实例需要放在Parallel里面实现
        /// </summary>
        private void StartToDo2()
        {
            //构建连接字符串
            OleDbConnection Conn = new OleDbConnection(connStr);

            Conn.Open();
            //填充数据
            string           sql = string.Format("select * from [{0}$]", "Final data");
            OleDbDataAdapter da  = new OleDbDataAdapter(sql, connStr);
            DataSet          ds  = new DataSet();

            da.Fill(ds);
            Conn.Close();
            var Test = ds.Tables[0].AsEnumerable();
            //using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
            //{
            int j = 0;

            Parallel.ForEach(Test, (dr, loopState) =>
            {
                using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
                {
                    j++;
                    OnOperateNotify(this, new HMEventArgs(string.Format("开始第{0}的处理", j)));
                    string strColor    = dr["Final Color"].ToString();
                    string strMaterial = dr["Final Material"].ToString();
                    if (!String.IsNullOrEmpty(strColor))
                    {
                        var newC = new CMS_SKU_Colour
                        {
                            ColourName = strColor,
                            CreateBy   = UpdateBy,
                            CreateOn   = DateTime.Now,
                            ModifyBy   = UpdateBy,
                            ModifyOn   = DateTime.Now
                        };
                        db.CMS_SKU_Colour.Add(newC);
                    }

                    if (!String.IsNullOrEmpty(strMaterial))
                    {
                        db.CMS_SKU_Material.Add(new CMS_SKU_Material
                        {
                            MaterialName = strMaterial,
                            CreateBy     = UpdateBy,
                            CreateOn     = DateTime.Now,
                            ModifyBy     = UpdateBy,
                            ModifyOn     = DateTime.Now
                        });
                    }
                    db.SaveChanges();
                }
            });//end of Parallel.ForEach
        }
 public bool EditRole(Security_Role_Model model, string curUserAccount)
 {
     using (PermaisuriCMSEntities db = new PermaisuriCMSEntities()) {
         var entity = db.Security_Role.Where(a => a.Role_GUID == model.Role_GUID).FirstOrDefault();
         entity.Role_Name   = model.Role_Name;
         entity.Role_Desc   = model.Role_Desc;
         entity.Modified_By = curUserAccount;
         entity.Modified_On = DateTime.Now;
         return(db.SaveChanges() > 0);
     }
 }
Esempio n. 19
0
 public bool DeleteUser(Menu_Resource_Model model)
 {
     using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
     {
         var user = new Menu_Resource {
             MR_ID = model.MR_ID
         };
         db.Set <Menu_Resource>().Attach(user);
         db.Menu_Resource.Remove(user);
         return(db.SaveChanges() > 0);
     }
 }
 public bool DeleteRole(Security_Role_Model model)
 {
     using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
     {
         var role = new Security_Role {
             Role_GUID = model.Role_GUID
         };
         db.Set <Security_Role>().Attach(role);
         db.Security_Role.Remove(role);
         return(db.SaveChanges() > 0);
     }
 }
Esempio n. 21
0
 public bool DeleteCarton(long ctnid)
 {
     using (var db = new PermaisuriCMSEntities())
     {
         //这样做的好处在于能直接删除一个对象,而不需要先从数据库中提取数据,创建实体对象,再查找并删除之,从而能有效地提升效率
         var ctn = new CMS_ProductCTN {
             CTNID = ctnid
         };
         db.Set <CMS_ProductCTN>().Attach(ctn);
         db.CMS_ProductCTN.Remove(ctn);
         return(db.SaveChanges() > 0);
     }
 }
Esempio n. 22
0
 /// <summary>
 /// Delete A User By User_Guid
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool DeleteUser(User_Profile_Model model)
 {
     using (var db = new PermaisuriCMSEntities())
     {
         //这样做的好处在于能直接删除一个对象,而不需要先从数据库中提取数据,创建实体对象,再查找并删除之,从而能有效地提升效率
         var user = new User_Profile {
             User_Guid = model.User_Guid
         };
         db.Set <User_Profile>().Attach(user);
         db.User_Profile.Remove(user);
         return(db.SaveChanges() > 0);
     }
 }
Esempio n. 23
0
 public bool DeleteDimension(long dimId)
 {
     using (var db = new PermaisuriCMSEntities())
     {
         //这样做的好处在于能直接删除一个对象,而不需要先从数据库中提取数据,创建实体对象,再查找并删除之,从而能有效地提升效率
         var dim = new CMS_ProductDimension {
             DimID = dimId
         };
         db.Set <CMS_ProductDimension>().Attach(dim);
         db.CMS_ProductDimension.Remove(dim);
         return(db.SaveChanges() > 0);
     }
 }
 /// <summary>
 /// 删除组合产品中的某一个子产品
 /// </summary>
 /// <param name="rModel"></param>
 /// <param name="errMsg"></param>
 /// <returns></returns>
 public bool DeleteChildrenHM(CMS_HMGroup_Relation_Model rModel, ref string errMsg)
 {
     using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
     {
         var query = db.CMS_HMGroup_Relation.FirstOrDefault(r => r.RID == rModel.RID);
         if (query == null)
         {
             errMsg = "This item does not exist";
             return(false);
         }
         db.CMS_HMGroup_Relation.Remove(query);
         return(db.SaveChanges() > 0);
     }
 }
 public bool AddRole(Security_Role_Model model, String curUserAccount)
 {
     using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
     {
         var newRole = new Security_Role
         {
             Role_GUID  = Guid.NewGuid(),
             Role_Name  = model.Role_Name,
             Created_By = curUserAccount,
             Created_On = DateTime.Now,
             Role_Desc  = model.Role_Desc
         };
         db.Security_Role.Add(newRole);
         return(db.SaveChanges() > 0);
     }
 }
Esempio n. 26
0
 /// <summary>
 /// 更新用户的登录时间,CheckUserLogin成功过后执行
 /// </summary>
 /// <param name="User_Guid"></param>
 /// <returns></returns>
 public bool UpdateUserLast_Logon(Guid User_Guid)
 {
     using (var db = new PermaisuriCMSEntities())
     {
         var query = db.User_Profile.FirstOrDefault(u => u.User_Guid == User_Guid);
         if (query == null)
         {
             NBCMSLoggerManager.Error(
                 String.Format("try to update user_profile last_logon faile,because {0} does not exist!",
                               User_Guid));
             return(false);
         }
         query.Last_Logon = DateTime.Now;
         return(db.SaveChanges() > 0);
     }
 }
Esempio n. 27
0
 public bool EditMenu(Menu_Resource_Model model, String modeifer)
 {
     using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
     {
         var entity = db.Menu_Resource.Where(a => a.MR_ID == model.MR_ID).FirstOrDefault();
         entity.MenuName     = model.MenuName;
         entity.ParentMenuID = model.ParentMenuID;
         entity.SortNo       = model.SortNo;
         entity.Icon         = model.iconSkin;
         entity.Memo         = model.Memo;
         entity.MenuUrl      = model.MenuUrl;
         entity.Visible      = model.Visible;
         entity.Modified_By  = modeifer;
         entity.Modified_On  = System.DateTime.Now;
         return(db.SaveChanges() > 0);
     }
 }
Esempio n. 28
0
        /// <summary>
        /// 2014年5月12日10:05:27。CMS只需要知道SHIPVIAType(物流or快递)就足够了,但是同步到eCom需要确切知道type下面的子类型
        /// </summary>
        /// <param name="sModel"></param>
        /// <returns></returns>
        public bool UpdateDefaultShipVia(CMS_ShipVia_Model sModel, User_Profile_Model userModel)
        {
            using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
            {
                //先设置这个类型(快递Or物流)所有的ShipVia子类型都为false
                db.CMS_ShipVia.Where(s => s.ShipViaTypeID == sModel.ShipViaTypeID).Update(s => new CMS_ShipVia {
                    IsDefaultShipVia = false
                });

                //再设置当前被CMS操作员点击的那个ShipVia为默认的ShipVia的类型
                db.CMS_ShipVia.Where(s => s.SHIPVIAID == sModel.SHIPVIAID && s.ShipViaTypeID == sModel.ShipViaTypeID).Update(s => new CMS_ShipVia
                {
                    IsDefaultShipVia = true,
                    UpdateBy         = userModel.User_Account,
                    UpdateOn         = DateTime.Now
                });
                return(db.SaveChanges() > -1);
            }
        }
        /// <summary>
        /// 2014年3月14日
        /// </summary>
        /// <param name="ProductID"></param>
        /// <param name="ChildrenProductID"></param>
        /// <param name="SellSets"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool UpdateSellSets(long ProductID, long ChildrenProductID, int SellSets, User_Profile_Model user)
        {
            using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
            {
                var relation = db.CMS_HMGroup_Relation.FirstOrDefault(h => h.ProductID == ProductID && h.ChildrenProductID == ChildrenProductID);
                if (relation == null)
                {
                    return(false);
                }

                StringBuilder sb = new StringBuilder();
                sb.Append(" <b> [sub-HMNUM=" + relation.CMS_HMNUM_Children.HMNUM + ", SellSets:] </b> : old value =  <span style='color:red'>  " + relation.SellSets + " </span> , new Value = <span style='color:red'>  " + SellSets + "  </span>");
                sb.Append("<br>");

                relation.SellSets = SellSets;

                relation.CMS_HMNUM.SKU_HM_Relation.Select(r => r.CMS_SKU.CMS_Ecom_Sync == null ? r.CMS_SKU.CMS_Ecom_Sync = new CMS_Ecom_Sync
                {
                    StatusID = 1 //这里可以不用做任何设置,因为后面那个操作会全面覆盖这个...
                } : r.CMS_SKU.CMS_Ecom_Sync).ForEach(k =>
                {
                    k.StatusID   = 0;
                    k.StatusDesc = "NeedSend";
                    k.UpdateBy   = user.User_Account;
                    k.UpdateOn   = DateTime.Now;
                });


                BllExtention.DbRecorder(new LogOfUserOperatingDetails
                {
                    ModelName    = Model_Name,
                    ActionName   = MethodBase.GetCurrentMethod().Name,
                    ActionType   = LogActionTypeEnum.Inert.GetHashCode(),
                    ProductID    = relation.ProductID,
                    HMNUM        = relation.CMS_HMNUM.HMNUM,
                    Descriptions = sb.ToString(),
                    CreateBy     = user.User_Account,
                    CreateOn     = DateTime.Now
                });

                return(db.SaveChanges() > -1);
            }
        }
Esempio n. 30
0
 /// <summary>
 /// 由于CMS的子产品允许有多张图片,eCom只接收一张,所以必须在CMS页面指定一个“Primary Image”的规则,设置了
 /// Primaryiamge的图片会发送到eCom去。(无法用组合产品的Primary image,因为当前子产品又可以和其他产品组合
 /// 成一个新的组合产品)。  2014年4月21日
 /// </summary>
 /// <param name="ProductID"></param>
 /// <param name="MediaID"></param>
 /// <returns></returns>
 public bool SetPrimaryImageForHMNUM(long ProductID, long MediaID)
 {
     //设置所有和SKUID相关的MediaLibrary的PrimaryImage字段为false
     using (PermaisuriCMSEntities db = new PermaisuriCMSEntities())
     {
         db.MediaLibrary.Where(r => r.ProductID == ProductID).ForEach(r =>
         {
             if (r.MediaID == MediaID)
             {
                 r.PrimaryImage = true;
             }
             else
             {
                 r.PrimaryImage = false;
             }
         });
         return(db.SaveChanges() > 0);
     }
 }