Esempio n. 1
0
        /// <summary>
        /// 根据分页获得数据列表
        /// </summary>
        /// <param name="TbFields">返回字段</param>
        /// <param name="strWhere">查询条件</param>
        /// <param name="OrderField">排序字段</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页尺寸</param>
        /// <param name="TotalCount">返回总记录数</param>
        /// <returns>IList<AdminRoleInfo></returns>
        public IList <AdminRoleInfo> Find(string tbFields, string strWhere, string orderField, int pageIndex, int pageSize, out int totalCount)
        {
            IList <AdminRoleInfo> list = new List <AdminRoleInfo>();

            using (DbCommand cmd = db.GetStoredProcCommand("SP_SqlPagenation"))
            {
                db.AddInParameter(cmd, "@TbName", DbType.String, "AdminRole");
                db.AddInParameter(cmd, "@TbFields", DbType.String, tbFields);
                db.AddInParameter(cmd, "@StrWhere", DbType.String, strWhere);
                db.AddInParameter(cmd, "@OrderField", DbType.String, orderField);
                db.AddInParameter(cmd, "@PageIndex", DbType.Int32, pageIndex);
                db.AddInParameter(cmd, "@PageSize", DbType.Int32, pageSize);
                db.AddOutParameter(cmd, "@Total", DbType.Int32, int.MaxValue);
                using (DataTable dt = db.ExecuteDataSet(cmd).Tables[0])
                {
                    if (dt.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            AdminRoleInfo model = new AdminRoleInfo();
                            model.LoadFromDataRow(dr);
                            list.Add(model);
                        }
                    }
                }

                totalCount = (int)db.GetParameterValue(cmd, "@Total");
                return(list);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 更新数据
 /// </summary>
 /// <param name="mod">AdminRoleInfo</param>
 /// <returns>受影响行数</returns>
 public int Update(AdminRoleInfo mod)
 {
     using (DbConnection conn = db.CreateConnection())
     {
         conn.Open();
         using (DbTransaction tran = conn.BeginTransaction())
         {
             try
             {
                 using (DbCommand cmd = db.GetStoredProcCommand("SP_AdminRole_Update"))
                 {
                     db.AddInParameter(cmd, "@AdminID", DbType.Int32, mod.AdminID);
                     db.AddInParameter(cmd, "@RoleID", DbType.Int32, mod.RoleID);
                     db.AddInParameter(cmd, "@State", DbType.Int32, mod.State);
                     db.AddInParameter(cmd, "@IsDeleted", DbType.Int32, mod.IsDeleted);
                     db.AddInParameter(cmd, "@Sort", DbType.Int32, mod.Sort);
                     tran.Commit();
                     return(db.ExecuteNonQuery(cmd));
                 }
             }
             catch (Exception e)
             {
                 tran.Rollback();
                 throw e;
             }
             finally
             {
                 conn.Close();
             }
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="mod">AdminRoleInfo</param>
        /// <returns>受影响行数</returns>
        public int Update(AdminRoleInfo mod)
        {
           using (DbConnection conn = db.CreateConnection())
			{
				conn.Open();
				using (DbTransaction tran = conn.BeginTransaction())
				{ 
					try
					{ 
						using (DbCommand cmd = db.GetStoredProcCommand("SP_AdminRole_Update"))
						{
							db.AddInParameter(cmd, "@AdminID", DbType.Int32, mod.AdminID); 
							db.AddInParameter(cmd, "@RoleID", DbType.Int32, mod.RoleID); 
							db.AddInParameter(cmd, "@State", DbType.Int32, mod.State); 
							db.AddInParameter(cmd, "@IsDeleted", DbType.Int32, mod.IsDeleted); 
							db.AddInParameter(cmd, "@Sort", DbType.Int32, mod.Sort); 
							tran.Commit();
							return db.ExecuteNonQuery(cmd);
						} 
					}
					catch (Exception e)
					{
						tran.Rollback();
						throw e;
					}
					finally
					{
						conn.Close();
					}
				}
			}
        }  
Esempio n. 4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <returns>最后插入记录主键值</returns>
        public int Save(AdminRoleInfo mod)
        {
           using (DbConnection conn = db.CreateConnection())
			{
				conn.Open();
				using (DbTransaction tran = conn.BeginTransaction())
				{ 
					try
					{ 
						using (DbCommand cmd = db.GetStoredProcCommand("SP_AdminRole_Add"))
						{
							db.AddInParameter(cmd, "@State", DbType.Int32, mod.State); 
							db.AddInParameter(cmd, "@IsDeleted", DbType.Int32, mod.IsDeleted); 
							db.AddInParameter(cmd, "@Sort", DbType.Int32, mod.Sort); 
							int id = Convert.ToInt32(db.ExecuteScalar(cmd));
							tran.Commit();
							return id;
						} 
					}
					catch (Exception e)
					{
						tran.Rollback();
						throw e;
					}
					finally
					{
						conn.Close();
					}
				}
			}
        }
 private void SerializeInternal(AdminRoleInfo model, IDictionary<string, object> result)
 { 
     result.Add("adminid", model.AdminID);
     result.Add("roleid", model.RoleID);
     result.Add("state", model.State);
     result.Add("isdeleted", model.IsDeleted);
     result.Add("sort", model.Sort);
 }
Esempio n. 6
0
        void GetGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.ToLower() == "add")
            {
                GridViewRow row = (e.CommandSource as Control).Parent.Parent as GridViewRow;
                Hashtable   htd = new Hashtable();

                foreach (TemplateField tf in GridViewManager1.GridView.Columns)
                {
                    GenericItem item = tf.FooterTemplate as GenericItem;
                    if (item == null)
                    {
                        continue;
                    }
                    try
                    {
                        foreach (DictionaryEntry de in item.ExtractValues(row))
                        {
                            htd.Add(de.Key, de.Value);
                        }
                    }
                    catch (Exception ex)
                    {
                        Exceptions.Logger.Error(ex);
                        HtmlHelper.Alert(ex.Message, Page);
                        return;
                    }
                }

                try
                {
                    AdminRoleController ctrl = new AdminRoleController();
                    AdminRoleInfo       info = new AdminRoleInfo();
                    foreach (System.Reflection.PropertyInfo property in CBO.GetPropertyInfo(typeof(AdminRoleInfo)))
                    {
                        if (htd[property.Name] != null)
                        {
                            property.SetValue(info, htd[property.Name], null);
                        }
                    }
                    ctrl.InsertAdminRole(info);
                    GridViewManager1.GridView.PageIndex = GridViewManager1.GridView.PageCount;
                    GridViewManager1.LoadData();
                }
                catch (Exception ex)
                {
                    Exceptions.Logger.Error(ex);
                    HtmlHelper.Alert(ex.Message, Page);
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 获得实体
        /// </summary>
        /// <param name="keyValue">编号</param>
        /// <returns>AdminRoleInfo</returns>
        public AdminRoleInfo Get(int keyValue)
        {
            AdminRoleInfo model = null;

            using (DbCommand cmd = db.GetStoredProcCommand("SP_GetRecord"))
            {
                db.AddInParameter(cmd, "@TableName", DbType.String, "AdminRole");
                db.AddInParameter(cmd, "@KeyName", DbType.String, "AdminID");
                db.AddInParameter(cmd, "@KeyValue", DbType.Int32, keyValue);
                using (DataTable dt = db.ExecuteDataSet(cmd).Tables[0])
                {
                    if (dt.Rows.Count > 0)
                    {
                        model = new AdminRoleInfo();
                        model.LoadFromDataRow(dt.Rows[0]);
                    }
                }
                return(model);
            }
        }
Esempio n. 8
0
 public ActionResult SaveGroup(AdminRoleInfo roleinfo)
 {
     try
     {
         if (adminUserBLL.ExistsAdminRoleName(roleinfo.id, roleinfo.RoleName))
         {
             return(Json(new { Error = 1, Message = "此分組名已存在" }));
         }
         var falg = adminUserBLL.SaveAdminRoleInfo(roleinfo);
         if (falg)
         {
             return(Json(new { Error = 0 }));
         }
         else
         {
             return(Json(new { Error = 1 }));
         }
     }
     catch (Exception ex)
     {
         LogHelper.Error(ex);
         return(Json(new { Error = 1, Message = ex.Message }));
     }
 }
Esempio n. 9
0
 public bool SaveAdminRoleInfo(AdminRoleInfo role)
 {
     return(adminUserDAL.SaveAdminRoleInfo(role));
 }
Esempio n. 10
0
        /// <summary>
        /// 根据分页获得数据列表
        /// </summary>
        /// <param name="TbFields">返回字段</param>
        /// <param name="strWhere">查询条件</param>
        /// <param name="OrderField">排序字段</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页尺寸</param> 
        /// <param name="TotalCount">返回总记录数</param>
        /// <returns>IList<AdminRoleInfo></returns>
        public IList<AdminRoleInfo> Find(string tbFields, string strWhere, string orderField, int pageIndex, int pageSize, out int totalCount)
        {
			IList<AdminRoleInfo> list = new List<AdminRoleInfo>();
			using (DbCommand cmd = db.GetStoredProcCommand("SP_SqlPagenation"))
			{
				db.AddInParameter(cmd, "@TbName", DbType.String, "AdminRole");
				db.AddInParameter(cmd, "@TbFields", DbType.String, tbFields);
				db.AddInParameter(cmd, "@StrWhere", DbType.String, strWhere);
				db.AddInParameter(cmd, "@OrderField", DbType.String, orderField);
				db.AddInParameter(cmd, "@PageIndex", DbType.Int32, pageIndex);
				db.AddInParameter(cmd, "@PageSize", DbType.Int32, pageSize);
				db.AddOutParameter(cmd, "@Total", DbType.Int32, int.MaxValue);
				using (DataTable dt = db.ExecuteDataSet(cmd).Tables[0])
				{
					if (dt.Rows.Count > 0)
					{
						foreach (DataRow dr in dt.Rows)
						{
							AdminRoleInfo model = new AdminRoleInfo();
							model.LoadFromDataRow(dr);
							list.Add(model);
						}
					}
				}

				totalCount = (int)db.GetParameterValue(cmd, "@Total");
				return list;
			}
		} 
Esempio n. 11
0
        /// <summary>
        /// 获得实体
        /// </summary>
        /// <param name="keyValue">编号</param>
        /// <returns>AdminRoleInfo</returns>
        public AdminRoleInfo Get(int keyValue)
        {
            AdminRoleInfo model = null;
			using (DbCommand cmd = db.GetStoredProcCommand("SP_GetRecord"))
			{
				db.AddInParameter(cmd, "@TableName", DbType.String, "AdminRole");
				db.AddInParameter(cmd, "@KeyName", DbType.String, "AdminID");
				db.AddInParameter(cmd, "@KeyValue", DbType.Int32, keyValue);
				using (DataTable dt = db.ExecuteDataSet(cmd).Tables[0])
				{
					if (dt.Rows.Count > 0)
					{
						model = new AdminRoleInfo();
						model.LoadFromDataRow(dt.Rows[0]);
					}
				}
				return model;
			}
        } 
Esempio n. 12
0
        public bool SaveAdminRoleInfo(AdminRoleInfo role)
        {
            string UPDATE_SQL = "";
            var    db         = DbSFO2OMain;
            var    parameters = db.CreateParameterCollection();

            parameters.Append("RoleName", role.RoleName);

            string Part_Sql = "";

            if (role.ModuleIDList != null && role.ModuleIDList.Count > 0)
            {
                Part_Sql = "INSERT INTO AdminRoleMenu(RoleID,ModuleID)VALUES" + String.Join(",", role.ModuleIDList.Select(p => "(@RoleID," + p.ToString() + ")"));
            }

            if (role.id != 0) //编辑
            {
                UPDATE_SQL = string.Format(@"begin transaction 
                                declare @error int
                                set @error = 0
                                    DELETE rm
                                    FROM AdminRoleMenu rm
                                    INNER JOIN AdminRole r ON r.id=rm.RoleID
                                    WHERE r.id=@RoleID
                                set @error = @error + @@error 
                                    update AdminRole set RoleName=@RoleName WHERE id=@RoleID
                                set @error = @error + @@error    
                                    {0} 
                                set @error = @error + @@error	
                                if @error <> 0  
                                rollback transaction   
                                else   
                                commit transaction", Part_Sql);
                parameters.Append("RoleID", role.id);
            }
            else
            {
                UPDATE_SQL = string.Format(@"begin transaction 
                                    declare @error int;
                                    declare @RoleID int; 
                                    set @error = 0;
                                    set @RoleID= 0  
                                         --添加角色
                                         insert into AdminRole(RoleName,Status)values(@RoleName,1)
                                    set @error = @error + @@error   
                                    set @RoleID = ( select Scope_Identity() as RoleID)
                                         --添加关系
                                        {0}
                                    set @error = @error + @@error 
                                    if @error <> 0  
                                    rollback transaction   
                                    else   
                                    commit transaction", Part_Sql);
            }
            try
            {
                return(db.ExecuteSqlNonQuery(UPDATE_SQL, parameters) > 0);
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(false);
        }