/// <summary> /// 读取记录列表。 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public IList <MemCGScopeEntity> GetMemCGScopeAllByMemId(int memid) { string where = " where 1=1 "; if (memid > 0) { where += " and CGMemId=@CGMemId "; } string sql = @"SELECT [Id],[CGMemId],[BrandId],[BrandName],[ClassId],[ClassName],ScopeType,[CreateManId],[CreateTime] from dbo.[MemCGScope] WITH(NOLOCK) " + where; IList <MemCGScopeEntity> entityList = new List <MemCGScopeEntity>(); DbCommand cmd = db.GetSqlStringCommand(sql); if (memid > 0) { db.AddInParameter(cmd, "@CGMemId", DbType.Int32, memid); } using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { MemCGScopeEntity entity = new MemCGScopeEntity(); entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.CGMemId = StringUtils.GetDbInt(reader["CGMemId"]); entity.BrandId = StringUtils.GetDbInt(reader["BrandId"]); entity.BrandName = StringUtils.GetDbString(reader["BrandName"]); entity.ClassId = StringUtils.GetDbInt(reader["ClassId"]); entity.ClassName = StringUtils.GetDbString(reader["ClassName"]); entity.ScopeType = StringUtils.GetDbInt(reader["ScopeType"]); entity.CreateManId = StringUtils.GetDbInt(reader["CreateManId"]); entity.CreateTime = StringUtils.GetDbDateTime(reader["CreateTime"]); entityList.Add(entity); } } return(entityList); }
/// <summary> /// 根据主键值读取记录。如果数据库不存在这条数据将返回null /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public MemCGScopeEntity GetMemCGScope(int id) { string sql = @"SELECT [Id],[CGMemId],[BrandId],[BrandName],[ClassId],[ClassName],ScopeType,[CreateManId],[CreateTime] FROM dbo.[MemCGScope] WITH(NOLOCK) WHERE [Id]=@id" ; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Id", DbType.Int32, id); MemCGScopeEntity entity = new MemCGScopeEntity(); using (IDataReader reader = db.ExecuteReader(cmd)) { if (reader.Read()) { entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.CGMemId = StringUtils.GetDbInt(reader["CGMemId"]); entity.BrandId = StringUtils.GetDbInt(reader["BrandId"]); entity.BrandName = StringUtils.GetDbString(reader["BrandName"]); entity.ClassId = StringUtils.GetDbInt(reader["ClassId"]); entity.ClassName = StringUtils.GetDbString(reader["ClassName"]); entity.ScopeType = StringUtils.GetDbInt(reader["ScopeType"]); entity.CreateManId = StringUtils.GetDbInt(reader["CreateManId"]); entity.CreateTime = StringUtils.GetDbDateTime(reader["CreateTime"]); } } return(entity); }
/// <summary> /// 插入一条记录到表MemCGScope,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0。 /// 该方法提供给界面等UI层调用 /// </summary> /// <param name="memCGScope">要添加的MemCGScope数据实体对象</param> public int AddMemCGScope(MemCGScopeEntity memCGScope) { if (memCGScope.ScopeType == (int)ScopeTypeEnum.Car) { CarTypeBrandEntity cartype = CarTypeBrandBLL.Instance.GetParentByName(memCGScope.BrandName); if (cartype != null && cartype.Id > 0) { if (cartype.BrandName == memCGScope.BrandName) { memCGScope.BrandId = cartype.Id; } else { MemCGScopeEntity parentcgscope = new MemCGScopeEntity(); parentcgscope.BrandName = cartype.BrandName; parentcgscope.CGMemId = memCGScope.CGMemId; parentcgscope.ClassName = memCGScope.ClassName; if (MemCGScopeBLL.Instance.IsExist(parentcgscope)) { return((int)CommonStatus.ADD_Fail_Exist); } } } } else if (memCGScope.ScopeType == (int)ScopeTypeEnum.Normal) { ClassCGScopeEntity classscope = ClassCGScopeBLL.Instance.GetParentByScopeName(memCGScope.BrandName); if (classscope != null && classscope.Id > 0) { if (classscope.ScopeClassName == memCGScope.BrandName) { memCGScope.BrandId = classscope.Id; } else { MemCGScopeEntity parentcgscope = new MemCGScopeEntity(); parentcgscope.BrandName = classscope.ScopeClassName; parentcgscope.CGMemId = memCGScope.CGMemId; parentcgscope.ClassName = memCGScope.ClassName; if (MemCGScopeBLL.Instance.IsExist(parentcgscope)) { return((int)CommonStatus.ADD_Fail_Exist); } } } } if (MemCGScopeBLL.Instance.IsExist(memCGScope)) { return((int)CommonStatus.ADD_Fail_Exist); } else { return(MemCGScopeDA.Instance.AddMemCGScope(memCGScope)); } }
/// <summary> /// 读取记录列表。 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param> public IList <MemCGScopeEntity> GetMemCGScopeList(int pagesize, int pageindex, ref int recordCount) { string sql = @"SELECT [Id],[CGMemId],[BrandId],[BrandName],[ClassId],[ClassName],ScopeType,[CreateManId],[CreateTime] FROM (SELECT ROW_NUMBER() OVER (ORDER BY Id desc) AS ROWNUMBER, [Id],[CGMemId],[BrandId],[BrandName],[ClassId],[ClassName],ScopeType,[CreateManId],[CreateTime] from dbo.[MemCGScope] WITH(NOLOCK) WHERE 1=1 ) as temp where rownumber BETWEEN ((@PageIndex - 1) * @PageSize + 1) AND @PageIndex * @PageSize" ; string sql2 = @"Select count(1) from dbo.[MemCGScope] with (nolock) "; IList <MemCGScopeEntity> entityList = new List <MemCGScopeEntity>(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@PageIndex", DbType.Int32, pageindex); db.AddInParameter(cmd, "@PageSize", DbType.Int32, pagesize); using (IDataReader reader = db.ExecuteReader(cmd)) { while (reader.Read()) { MemCGScopeEntity entity = new MemCGScopeEntity(); entity.Id = StringUtils.GetDbInt(reader["Id"]); entity.CGMemId = StringUtils.GetDbInt(reader["CGMemId"]); entity.BrandId = StringUtils.GetDbInt(reader["BrandId"]); entity.BrandName = StringUtils.GetDbString(reader["BrandName"]); entity.ClassId = StringUtils.GetDbInt(reader["ClassId"]); entity.ClassName = StringUtils.GetDbString(reader["ClassName"]); entity.ScopeType = StringUtils.GetDbInt(reader["ScopeType"]); entity.CreateManId = StringUtils.GetDbInt(reader["CreateManId"]); entity.CreateTime = StringUtils.GetDbDateTime(reader["CreateTime"]); entityList.Add(entity); } } cmd = db.GetSqlStringCommand(sql2); using (IDataReader reader = db.ExecuteReader(cmd)) { if (reader.Read()) { recordCount = StringUtils.GetDbInt(reader[0]); } else { recordCount = 0; } } return(entityList); }
/// <summary> /// 根据主键值更新记录的全部字段(注意:该方法不会对自增字段、timestamp类型字段以及主键字段更新!如果要更新主键字段,请使用Update方法)。 /// 如果数据库有数据被更新了则返回True,否则返回False /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="memCGScope">待更新的实体对象</param> public int UpdateMemCGScope(MemCGScopeEntity entity) { string sql = @" UPDATE dbo.[MemCGScope] SET [CGMemId]=@CGMemId,[BrandId]=@BrandId,[BrandName]=@BrandName,[ClassId]=@ClassId,[ClassName]=@ClassName,[CreateManId]=@CreateManId,[CreateTime]=@CreateTime WHERE [Id]=@id"; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id); db.AddInParameter(cmd, "@CGMemId", DbType.Int32, entity.CGMemId); db.AddInParameter(cmd, "@BrandId", DbType.Int32, entity.BrandId); db.AddInParameter(cmd, "@BrandName", DbType.String, entity.BrandName); db.AddInParameter(cmd, "@ClassId", DbType.Int32, entity.ClassId); db.AddInParameter(cmd, "@ClassName", DbType.String, entity.ClassName); db.AddInParameter(cmd, "@CreateManId", DbType.Int32, entity.CreateManId); db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, entity.CreateTime); return(db.ExecuteNonQuery(cmd)); }
/// <summary> /// 判断当前节点是否已存在相同的 /// </summary> /// <param name="entity"></param> /// <returns></returns> public int ExistNum(MemCGScopeEntity entity) { ///id=0,判断总数,ID>0判断除自己之外的总数 string sql = @"Select count(1) from dbo.[MemCGScope] WITH(NOLOCK) where BrandName=@BrandName and ClassName=@ClassName and CGMemId=@CGMemId "; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@BrandName", DbType.String, entity.BrandName); db.AddInParameter(cmd, "@ClassName", DbType.String, entity.ClassName); db.AddInParameter(cmd, "@CGMemId", DbType.Int32, entity.CGMemId); object identity = db.ExecuteScalar(cmd); if (identity == null || identity == DBNull.Value) { return(0); } return(Convert.ToInt32(identity)); }
/// <summary> /// 插入一条记录到表MemCGScope,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0 /// </summary> /// <param name="db">数据库操作对象</param> /// <param name="memCGScope">待插入的实体对象</param> public int AddMemCGScope(MemCGScopeEntity entity) { string sql = @"insert into MemCGScope( [CGMemId],[BrandId],[BrandName],[ClassId],[ClassName],ScopeType,[CreateManId],[CreateTime])VALUES ( @CGMemId,@BrandId,@BrandName,@ClassId,@ClassName,@ScopeType,@CreateManId,@CreateTime); SELECT SCOPE_IDENTITY();" ; DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@CGMemId", DbType.Int32, entity.CGMemId); db.AddInParameter(cmd, "@BrandId", DbType.Int32, entity.BrandId); db.AddInParameter(cmd, "@BrandName", DbType.String, entity.BrandName); db.AddInParameter(cmd, "@ScopeType", DbType.Int32, entity.ScopeType); db.AddInParameter(cmd, "@ClassId", DbType.Int32, entity.ClassId); db.AddInParameter(cmd, "@ClassName", DbType.String, entity.ClassName); db.AddInParameter(cmd, "@CreateManId", DbType.Int32, entity.CreateManId); db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, entity.CreateTime); object identity = db.ExecuteScalar(cmd); if (identity == null || identity == DBNull.Value) { return(0); } return(Convert.ToInt32(identity)); }
/// <summary> /// 供应商备货通知 /// </summary> /// <param name="code"></param> /// <returns></returns> public bool CGMemStockNote(string code) { bool result = false; ConfirmOrderEntity order = ConfirmOrderBLL.Instance.GetConfirmOrderByCode(code); IList <VWConfirmOrderCGMemEntity> memberlist = ConfirmOrderProductBLL.Instance.GetConfirmCGMemsByCode(code); if (order != null && order.Id > 0 && memberlist != null && memberlist.Count > 0) { foreach (VWConfirmOrderCGMemEntity member in memberlist) { //if (order.ScopeType==(int)SuperMarket.Model.ScopeTypeEnum.Normal) //{ // ClassCGScopeEntity cgscope = new ClassCGScopeEntity(); // cgscope.ScopeClassName = order.CarBrandName; // cgscope.ClassId = 0; // cgscope.IsActive = 1; // cgscope.Sort = 0; // cgscope.IsRoot = 0; // cgscope.ParentId = 0; // ClassCGScopeBLL.Instance.AddClassCGScope(cgscope); //} MemCGScopeEntity scope = new MemCGScopeEntity(); scope.BrandId = order.CarBrandId; scope.BrandName = order.CarBrandName; scope.ClassId = 0; scope.ClassName = ""; scope.CGMemId = member.CGMemId; scope.CreateTime = DateTime.Now; scope.IsActive = 1; scope.ScopeType = (int)ScopeTypeEnum.Car; MemCGScopeBLL.Instance.AddMemCGScope(scope); VWMemberEntity _cgmementity = MemberBLL.Instance.GetVWMember(member.CGMemId); if (!string.IsNullOrEmpty(_cgmementity.WeChat)) { string redirecturl = ConfigCore.Instance.ConfigCommonEntity.InquiryMobileWebUrl + string.Format(WebUrlEnum.ConfirmCGStockNote, code); Hashtable hashentity = new Hashtable(); hashentity.Add("first", new WeiXinUnitEntity() { value = "订单已确认,准备发货啦" }); hashentity.Add("keyword1", new WeiXinUnitEntity() { value = code }); hashentity.Add("keyword2", new WeiXinUnitEntity() { value = member.CGTotalPrice.ToString("0.00") }); hashentity.Add("keyword3", new WeiXinUnitEntity() { value = "易店心" }); hashentity.Add("keyword4", new WeiXinUnitEntity() { value = "待发货" }); hashentity.Add("remark", new WeiXinUnitEntity() { value = "客户已确认,尽快备货吧" }); WeiXinJsSdk.Instance.SendWeiXinMsgNote(_cgmementity.WeChat, redirecturl, WeiXinTemplet.OrderStockNote, hashentity); } } } return(result); }
/// <summary> /// 判断对象是否存在 /// </summary> /// <param name="dicEnum"></param> /// <returns></returns> public bool IsExist(MemCGScopeEntity memCGScope) { return(MemCGScopeDA.Instance.ExistNum(memCGScope) > 0); }
/// <summary> /// 更新一条MemCGScope记录。 /// 该方法提供给界面等UI层调用 /// </summary> /// <param name="memCGScope">待更新的实体对象</param> /// <param name="columns">要更新的列名,不提供任何列名时默认将更新主键之外的所有列</param> public int UpdateMemCGScope(MemCGScopeEntity memCGScope) { return(MemCGScopeDA.Instance.UpdateMemCGScope(memCGScope)); }