Ejemplo n.º 1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.manager_role GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder str1   = new StringBuilder();

            Model.manager_role model = new Model.manager_role();
            //利用反射获得属性的所有公共属性
            PropertyInfo[] pros = model.GetType().GetProperties();
            foreach (PropertyInfo p in pros)
            {
                //拼接字段,忽略List<T>
                if (!typeof(System.Collections.IList).IsAssignableFrom(p.PropertyType))
                {
                    str1.Append(p.Name + ",");//拼接字段
                }
            }
            strSql.Append("select top 1 " + str1.ToString().Trim(','));
            strSql.Append(" from " + databaseprefix + "manager_role");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;
            DataTable dt = DbHelperSQL.Query(strSql.ToString(), parameters).Tables[0];

            if (dt.Rows.Count > 0)
            {
                return(DataRowToModel(dt.Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
 private void ShowInfo(int _id)
 {
     BLL.manager_role   bll   = new BLL.manager_role();
     Model.manager_role model = bll.GetModel(_id);
     txtRoleName.Text          = model.role_name;
     ddlRoleType.SelectedValue = model.role_type.ToString();
     //管理菜单
     if (model.manager_role_values != null)
     {
         for (int i = 0; i < rptList.Items.Count; i++)
         {
             string       navName       = ((HiddenField)rptList.Items[i].FindControl("hidName")).Value;
             CheckBoxList cblActionType = (CheckBoxList)rptList.Items[i].FindControl("cblActionType");
             for (int n = 0; n < cblActionType.Items.Count; n++)
             {
                 Model.manager_role_value modelt = model.manager_role_values.Find(p => p.nav_name == navName && p.action_type == cblActionType.Items[n].Value);
                 if (modelt != null)
                 {
                     cblActionType.Items[n].Selected = true;
                 }
             }
         }
     }
     //管理权限
     if (model.RolePemissionList != null)
     {
         hCodeStr.Value           = "," + string.Join(",", model.RolePemissionList.ConvertAll(u => u.urp_code).ToArray()) + ",";
         rptPermission.DataSource = model.RolePemissionList;
         rptPermission.DataBind();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.manager_role model)
        {
            using (OleDbConnection conn = new OleDbConnection(DbHelperOleDb.connectionString))
            {
                conn.Open();
                using (OleDbTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("insert into " + databaseprefix + "manager_role(");
                        strSql.Append("role_name,role_type,is_sys)");
                        strSql.Append(" values (");
                        strSql.Append("@role_name,@role_type,@is_sys)");
                        OleDbParameter[] parameters =
                        {
                            new OleDbParameter("@role_name", OleDbType.VarChar, 100),
                            new OleDbParameter("@role_type", OleDbType.Integer,   4),
                            new OleDbParameter("@is_sys",    OleDbType.Integer, 4)
                        };
                        parameters[0].Value = model.role_name;
                        parameters[1].Value = model.role_type;
                        parameters[2].Value = model.is_sys;
                        DbHelperOleDb.ExecuteSql(conn, trans, strSql.ToString(), parameters);
                        //取得新插入的ID
                        model.id = GetMaxId(conn, trans);

                        StringBuilder strSql2;
                        if (model.manager_role_values != null)
                        {
                            foreach (Model.manager_role_value modelt in model.manager_role_values)
                            {
                                strSql2 = new StringBuilder();
                                strSql2.Append("insert into " + databaseprefix + "manager_role_value(");
                                strSql2.Append("role_id,nav_name,action_type)");
                                strSql2.Append(" values (");
                                strSql2.Append("@role_id,@nav_name,@action_type)");
                                OleDbParameter[] parameters2 =
                                {
                                    new OleDbParameter("@role_id",     OleDbType.Integer,   4),
                                    new OleDbParameter("@nav_name",    OleDbType.VarChar, 100),
                                    new OleDbParameter("@action_type", OleDbType.VarChar, 50)
                                };
                                parameters2[0].Value = model.id;
                                parameters2[1].Value = modelt.nav_name;
                                parameters2[2].Value = modelt.action_type;
                                DbHelperOleDb.ExecuteSql(conn, trans, strSql2.ToString(), parameters2);
                            }
                        }
                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return(-1);
                    }
                }
            }
            return(model.id);
        }
Ejemplo n.º 4
0
        public Model.manager_role FillModelByRow(DataRow row)
        {
            Model.manager_role model = new Model.manager_role();
            if (row["id"].ToString() != "")
            {
                model.id = int.Parse(row["id"].ToString());
            }
            model.role_name = row["role_name"].ToString

                                  ();
            if (row["role_type"].ToString() != "")
            {
                model.role_type = int.Parse(row["role_type"].ToString());
            }
            if (row["is_sys"].ToString() != "")
            {
                model.is_sys = int.Parse(row["is_sys"].ToString());
            }
            if (row["agentId"].ToString() != "")
            {
                model.agentId = int.Parse(row["agentId"].ToString());
            }

            return(model);
        }
Ejemplo n.º 5
0
        private bool DoAdd()
        {
            bool result = true;
            Model.manager_role model = new Model.manager_role();
            BLL.manager_role bll = new BLL.manager_role();

            model.role_name = txtRoleName.Text.Trim();
            model.role_type = int.Parse(ddlRoleType.SelectedValue);

            List<Model.manager_role_value> ls = new List<Model.manager_role_value>();
            //基本设置
            for (int i = 0; i < rptList1.Items.Count; i++)
            {
                HiddenField hidNavName = rptList1.Items[i].FindControl("hidName") as HiddenField;
                HtmlInputCheckBox hcbNavValue = rptList1.Items[i].FindControl("cblNavName") as HtmlInputCheckBox;
                if (hidNavName != null && hcbNavValue!=null)
                {
                    if (hcbNavValue.Checked == true)
                    {
                        ls.Add(new Model.manager_role_value { channel_id = 0, channel_name = hidNavName.Value, action_type = hcbNavValue.Value });
                    }
                }
            }
            //频道设置
            for (int i = 0; i < rptList3.Items.Count; i++)
            {
                int channelId = Convert.ToInt32(((HiddenField)rptList3.Items[i].FindControl("hidChannelId")).Value);
                HtmlInputCheckBox hcbView = rptList3.Items[i].FindControl("cbView") as HtmlInputCheckBox;
                HtmlInputCheckBox hcbAdd = rptList3.Items[i].FindControl("cbAdd") as HtmlInputCheckBox;
                HtmlInputCheckBox hcbEdit = rptList3.Items[i].FindControl("cbEdit") as HtmlInputCheckBox;
                HtmlInputCheckBox hcbDelete = rptList3.Items[i].FindControl("cbDelete") as HtmlInputCheckBox;
                if (hcbView != null && hcbView.Checked == true)
                {
                    ls.Add(new Model.manager_role_value { channel_id = channelId, channel_name = "channel", action_type = ActionEnum.View.ToString() });
                }
                if (hcbAdd != null && hcbAdd.Checked == true)
                {
                    ls.Add(new Model.manager_role_value { channel_id = channelId, channel_name = "channel", action_type = ActionEnum.Add.ToString() });
                }
                if (hcbEdit != null && hcbEdit.Checked == true)
                {
                    ls.Add(new Model.manager_role_value { channel_id = channelId, channel_name = "channel", action_type = ActionEnum.Edit.ToString() });
                }
                if (hcbDelete != null && hcbDelete.Checked == true)
                {
                    ls.Add(new Model.manager_role_value { channel_id = channelId, channel_name = "channel", action_type = ActionEnum.Delete.ToString() });
                }
            }

            model.manager_role_values = ls;
            if (bll.Add(model) < 1)
            {
                result = false;
            }
            return result;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 将对象转换实体
        /// </summary>
        public Model.manager_role DataRowToModel(DataRow row)
        {
            Model.manager_role model = new Model.manager_role();
            if (row != null)
            {
                #region 主表信息======================
                //利用反射获得属性的所有公共属性
                Type modelType = model.GetType();
                for (int i = 0; i < row.Table.Columns.Count; i++)
                {
                    //查找实体是否存在列表相同的公共属性
                    PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName);
                    if (proInfo != null && row[i] != DBNull.Value)
                    {
                        proInfo.SetValue(model, row[i], null);//用索引值设置属性值
                    }
                }
                #endregion

                #region 子表信息======================
                StringBuilder strSql1 = new StringBuilder();
                strSql1.Append("select * from " + databaseprefix + "manager_role_value");
                strSql1.Append(" where role_id=@role_id");
                SqlParameter[] parameters1 =
                {
                    new SqlParameter("@role_id", SqlDbType.Int, 4)
                };
                parameters1[0].Value = model.id;

                DataTable dt1 = DbHelperSQL.Query(strSql1.ToString(), parameters1).Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int rowsCount = dt1.Rows.Count;
                    List <Model.manager_role_value> models = new List <Model.manager_role_value>();
                    Model.manager_role_value        modelt;
                    for (int n = 0; n < rowsCount; n++)
                    {
                        modelt = new Model.manager_role_value();
                        Type modeltType = modelt.GetType();
                        for (int i = 0; i < dt1.Rows[n].Table.Columns.Count; i++)
                        {
                            PropertyInfo proInfo = modeltType.GetProperty(dt1.Rows[n].Table.Columns[i].ColumnName);
                            if (proInfo != null && dt1.Rows[n][i] != DBNull.Value)
                            {
                                proInfo.SetValue(modelt, dt1.Rows[n][i], null);
                            }
                        }
                        models.Add(modelt);
                    }
                    model.manager_role_values = models;
                }
                #endregion
            }
            return(model);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.manager_role model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into " + databaseprefix + "manager_role(");
            strSql.Append("role_name,role_type,is_sys,agentId)");
            strSql.Append(" values (");
            strSql.Append("@role_name,@role_type,@is_sys,@agentId)");
            strSql.Append(";set @ReturnValue= @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@role_name",   SqlDbType.NVarChar, 100),
                new SqlParameter("@role_type",   SqlDbType.TinyInt,    1),
                new SqlParameter("@is_sys",      SqlDbType.TinyInt,    1),
                new SqlParameter("@agentId",     SqlDbType.Int,        4),
                new SqlParameter("@ReturnValue", SqlDbType.Int)
            };
            parameters[0].Value     = model.role_name;
            parameters[1].Value     = model.role_type;
            parameters[2].Value     = model.is_sys;
            parameters[3].Value     = model.agentId;
            parameters[4].Direction = ParameterDirection.Output;
            List <CommandInfo> sqllist = new List <CommandInfo>();
            CommandInfo        cmd     = new CommandInfo(strSql.ToString(), parameters);

            sqllist.Add(cmd);

            StringBuilder strSql2;

            if (model.manager_role_values != null)
            {
                foreach (Model.manager_role_value modelt in model.manager_role_values)
                {
                    strSql2 = new StringBuilder();
                    strSql2.Append("insert into " + databaseprefix + "manager_role_value(");
                    strSql2.Append("role_id,nav_name,action_type)");
                    strSql2.Append(" values (");
                    strSql2.Append("@role_id,@nav_name,@action_type)");
                    SqlParameter[] parameters2 =
                    {
                        new SqlParameter("@role_id",     SqlDbType.Int,        4),
                        new SqlParameter("@nav_name",    SqlDbType.NVarChar, 100),
                        new SqlParameter("@action_type", SqlDbType.NVarChar, 50)
                    };
                    parameters2[0].Direction = ParameterDirection.InputOutput;
                    parameters2[1].Value     = modelt.nav_name;
                    parameters2[2].Value     = modelt.action_type;
                    cmd = new CommandInfo(strSql2.ToString(), parameters2);
                    sqllist.Add(cmd);
                }
            }
            DbHelperSQL.ExecuteSqlTranWithIndentity(sqllist);
            return((int)parameters[4].Value);
        }
Ejemplo n.º 8
0
 private void ShowInfo(int _id)
 {
     BLL.manager_role   bll   = new BLL.manager_role();
     Model.manager_role model = bll.GetModel(_id);
     txtRoleName.Text          = model.role_name;
     ddlRoleType.SelectedValue = model.role_type.ToString();
     //基本设置
     for (int i = 0; i < rptList1.Items.Count; i++)
     {
         string navName  = ((HiddenField)rptList1.Items[i].FindControl("hidName")).Value;
         string navValue = ((HtmlInputCheckBox)rptList1.Items[i].FindControl("cblNavName")).Value;
         if (model.manager_role_values != null)
         {
             Model.manager_role_value modelt = model.manager_role_values.Find(p => p.channel_name == navName && p.action_type == navValue);
             if (modelt != null)
             {
                 ((HiddenField)rptList1.Items[i].FindControl("hidId")).Value = modelt.id.ToString();
                 ((HtmlInputCheckBox)rptList1.Items[i].FindControl("cblNavName")).Checked = true;
             }
         }
     }
     //频道设置
     for (int i = 0; i < rptList3.Items.Count; i++)
     {
         int channelId = Convert.ToInt32(((HiddenField)rptList3.Items[i].FindControl("hidChannelId")).Value);
         if (model.manager_role_values != null)
         {
             Model.manager_role_value modelt1 = model.manager_role_values.Find(p => p.channel_id == channelId && p.action_type == ActionEnum.View.ToString());
             if (modelt1 != null)
             {
                 ((HiddenField)rptList3.Items[i].FindControl("hidViewId")).Value      = modelt1.id.ToString();
                 ((HtmlInputCheckBox)rptList3.Items[i].FindControl("cbView")).Checked = true;
             }
             Model.manager_role_value modelt2 = model.manager_role_values.Find(p => p.channel_id == channelId && p.action_type == ActionEnum.Add.ToString());
             if (modelt2 != null)
             {
                 ((HiddenField)rptList3.Items[i].FindControl("hidAddId")).Value      = modelt2.id.ToString();
                 ((HtmlInputCheckBox)rptList3.Items[i].FindControl("cbAdd")).Checked = true;
             }
             Model.manager_role_value modelt3 = model.manager_role_values.Find(p => p.channel_id == channelId && p.action_type == ActionEnum.Edit.ToString());
             if (modelt3 != null)
             {
                 ((HiddenField)rptList3.Items[i].FindControl("hidEditId")).Value      = modelt3.id.ToString();
                 ((HtmlInputCheckBox)rptList3.Items[i].FindControl("cbEdit")).Checked = true;
             }
             Model.manager_role_value modelt4 = model.manager_role_values.Find(p => p.channel_id == channelId && p.action_type == ActionEnum.Delete.ToString());
             if (modelt4 != null)
             {
                 ((HiddenField)rptList3.Items[i].FindControl("hidDeleteId")).Value      = modelt4.id.ToString();
                 ((HtmlInputCheckBox)rptList3.Items[i].FindControl("cbDelete")).Checked = true;
             }
         }
     }
 }
Ejemplo n.º 9
0
        private string DoAdd()
        {
            Model.manager_role model = new Model.manager_role();
            BLL.manager_role   bll   = new BLL.manager_role();

            model.role_name = txtRoleName.Text.Trim();
            model.role_type = int.Parse(ddlRoleType.SelectedValue);

            //管理权限
            if (!string.IsNullOrEmpty(hCodeStr.Value))
            {
                string[] codelist = hCodeStr.Value.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                List <Model.userRolePemission> ps = new List <Model.userRolePemission>();
                foreach (string item in codelist)
                {
                    ps.Add(new Model.userRolePemission()
                    {
                        urp_type = 2, urp_code = item
                    });
                }
                model.RolePemissionList = ps;
                if (model.RolePemissionList.FindAll(p => p.urp_code == "0603" || p.urp_code == "0402" || p.urp_code == "0601").Count > 1)
                {
                    return("同一个角色不能同时开通区域审批权(0603)、财务部审批(0402)、总经理审批(0601)中的两个权限");
                }
            }

            //管理菜单
            List <Model.manager_role_value> ls = new List <Model.manager_role_value>();

            for (int i = 0; i < rptList.Items.Count; i++)
            {
                string       navName       = ((HiddenField)rptList.Items[i].FindControl("hidName")).Value;
                CheckBoxList cblActionType = (CheckBoxList)rptList.Items[i].FindControl("cblActionType");
                for (int n = 0; n < cblActionType.Items.Count; n++)
                {
                    if (cblActionType.Items[n].Selected == true)
                    {
                        ls.Add(new Model.manager_role_value {
                            nav_name = navName, action_type = cblActionType.Items[n].Value
                        });
                    }
                }
            }
            model.manager_role_values = ls;

            if (bll.Add(model) > 0)
            {
                AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加管理角色:" + model.role_name); //记录日志
                return("");
            }
            return("添加失败");
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 增加一条数据,及其子表数据
        /// </summary>
        public int Add(Model.manager_role model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into gm_dt_sysuser_role(");
            strSql.Append("role_name,role_type,role_value)");
            strSql.Append(" values (");
            strSql.Append("@role_name,@role_type,@role_value)");
            strSql.Append(";set @ReturnValue= @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@role_name",   SqlDbType.NVarChar, 100),
                new SqlParameter("@role_type",   SqlDbType.TinyInt,    1),
                new SqlParameter("@role_value",  SqlDbType.Int,        4),
                new SqlParameter("@ReturnValue", SqlDbType.Int)
            };
            parameters[0].Value     = model.role_name;
            parameters[1].Value     = model.role_type;
            parameters[2].Value     = model.role_value;
            parameters[3].Direction = ParameterDirection.Output;

            List <CommandInfo> sqllist = new List <CommandInfo>();
            CommandInfo        cmd     = new CommandInfo(strSql.ToString(), parameters);

            sqllist.Add(cmd);
            StringBuilder strSql2;

            foreach (Model.manager_role_value models in model.manager_role_values)
            {
                strSql2 = new StringBuilder();
                strSql2.Append("insert into gm_dt_sysuser_role_value(");
                strSql2.Append("role_id,channel_name,channel_id,action_type)");
                strSql2.Append(" values (");
                strSql2.Append("@role_id,@channel_name,@channel_id,@action_type)");
                SqlParameter[] parameters2 =
                {
                    new SqlParameter("@role_id",      SqlDbType.Int,        4),
                    new SqlParameter("@channel_name", SqlDbType.NVarChar, 255),
                    new SqlParameter("@channel_id",   SqlDbType.Int,        4),
                    new SqlParameter("@action_type",  SqlDbType.NVarChar, 100)
                };
                parameters2[0].Direction = ParameterDirection.InputOutput;
                parameters2[1].Value     = models.channel_name;
                parameters2[2].Value     = models.channel_id;
                parameters2[3].Value     = models.action_type;

                cmd = new CommandInfo(strSql2.ToString(), parameters2);
                sqllist.Add(cmd);
            }
            DbHelperSQL.ExecuteSqlTranWithIndentity(sqllist);
            return((int)parameters[3].Value);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 检查管理员权限
        /// </summary>
        /// <param name="nav_name">菜单名称</param>
        /// <param name="action_type">操作类型</param>
        public void ChkAdminLevel(string nav_name, string action_type, out Model.manager_role rolemodel)
        {
            Model.manager    model  = GetAdminInfo();
            BLL.manager_role bll    = new BLL.manager_role();
            bool             result = bll.Exists(model.role_id, nav_name, action_type, out rolemodel);

            if (!result)
            {
                string msgbox = "parent.jsdialog(\"错误提示\", \"您没有管理该页面的权限,请勿非法进入!\", \"back\")";
                Response.Write("<script type=\"text/javascript\">" + msgbox + "</script>");
                Response.End();
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// 检查是否有权限
 /// </summary>
 public bool Exists(int role_id, string nav_name, string action_type)
 {
     Model.manager_role model = dal.GetModel(role_id);
     if (model != null)
     {
         if (model.role_type == 1)
         {
             return(true);
         }
         Model.manager_role_value modelt = model.manager_role_values.Find(p => p.nav_name == nav_name && p.action_type == action_type);
         if (modelt != null)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 检查是否有权限
 /// </summary>
 public bool Exists(int role_id, int channel_id, string action_type)
 {
     Model.manager_role model = GetModel(role_id);
     if (model != null)
     {
         if (model.role_type == 1)
         {
             return(true);
         }
         Model.manager_role_value modelt = model.manager_role_values.Find(p => p.channel_id == channel_id && p.action_type == action_type);
         if (modelt != null)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 14
0
        private bool DoAdd()
        {
            Model.manager adminEntity = GetAdminInfo();
            bool          result      = false;

            Model.manager_role model = new Model.manager_role();
            model.agentId   = adminEntity.id;
            model.role_name = txtRoleName.Text.Trim();
            //model.role_type = int.Parse(ddlRoleType.SelectedValue);
            model.role_type = 2;

            //管理权限
            List <Model.manager_role_value> ls = new List <Model.manager_role_value>();

            for (int i = 0; i < rptList.Items.Count; i++)
            {
                string       navName       = ((HiddenField)rptList.Items[i].FindControl("hidName")).Value;
                CheckBoxList cblActionType = (CheckBoxList)rptList.Items[i].FindControl("cblActionType");
                for (int n = 0; n < cblActionType.Items.Count; n++)
                {
                    if (cblActionType.Items[n].Selected == true)
                    {
                        ls.Add(new Model.manager_role_value {
                            nav_name = navName, action_type = cblActionType.Items[n].Value
                        });
                    }
                }
            }
            model.manager_role_values = ls;

            if (rBll.Add(model) > 0)
            {
                AddAdminLog(MXEnums.ActionEnum.Add.ToString(), "添加角色:" + model.role_name); //记录日志
                result = true;
            }
            return(result);
        }
Ejemplo n.º 15
0
 private void ShowInfo(int _id)
 {
     BLL.manager_role   bll   = new BLL.manager_role();
     Model.manager_role model = bll.GetModel(_id);
     txtRoleName.Text          = model.role_name;
     ddlRoleType.SelectedValue = model.role_type.ToString();
     //管理权限
     if (model.manager_role_values != null)
     {
         for (int i = 0; i < rptList.Items.Count; i++)
         {
             string       navName       = ((HiddenField)rptList.Items[i].FindControl("hidName")).Value;
             CheckBoxList cblActionType = (CheckBoxList)rptList.Items[i].FindControl("cblActionType");
             for (int n = 0; n < cblActionType.Items.Count; n++)
             {
                 Model.manager_role_value modelt = model.manager_role_values.Find(p => p.nav_name == navName && p.action_type == cblActionType.Items[n].Value);
                 if (modelt != null)
                 {
                     cblActionType.Items[n].Selected = true;
                 }
             }
         }
     }
 }
Ejemplo n.º 16
0
        private bool DoEdit(int _id)
        {
            bool result = false;

            BLL.manager_role   bll   = new BLL.manager_role();
            Model.manager_role model = bll.GetModel(_id);

            model.role_name = txtRoleName.Text.Trim();
            model.role_type = int.Parse(ddlRoleType.SelectedValue);

            //管理权限
            List <Model.manager_role_value> ls = new List <Model.manager_role_value>();

            for (int i = 0; i < rptList.Items.Count; i++)
            {
                string       navName       = ((HiddenField)rptList.Items[i].FindControl("hidName")).Value;
                CheckBoxList cblActionType = (CheckBoxList)rptList.Items[i].FindControl("cblActionType");
                for (int n = 0; n < cblActionType.Items.Count; n++)
                {
                    if (cblActionType.Items[n].Selected == true)
                    {
                        ls.Add(new Model.manager_role_value {
                            role_id = _id, nav_name = navName, action_type = cblActionType.Items[n].Value
                        });
                    }
                }
            }
            model.manager_role_values = ls;

            if (bll.Update(model))
            {
                AddAdminLog(AXEnums.ActionEnum.Edit.ToString(), "修改管理角色:" + model.role_name); //记录日志
                result = true;
            }
            return(result);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.manager_role model)
        {
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();//打开数据连接
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        #region 主表信息==========================
                        StringBuilder strSql = new StringBuilder();
                        StringBuilder str1   = new StringBuilder(); //数据字段
                        StringBuilder str2   = new StringBuilder(); //数据参数
                        //利用反射获得属性的所有公共属性
                        PropertyInfo[]      pros  = model.GetType().GetProperties();
                        List <SqlParameter> paras = new List <SqlParameter>();
                        strSql.Append("insert into " + databaseprefix + "manager_role(");
                        foreach (PropertyInfo pi in pros)
                        {
                            //如果不是主键和LIST<T>则追加sql字符串
                            if (!pi.Name.Equals("id") && !typeof(System.Collections.IList).IsAssignableFrom(pi.PropertyType))
                            {
                                //判断属性值是否为空
                                if (pi.GetValue(model, null) != null && !pi.GetValue(model, null).ToString().Equals(""))
                                {
                                    str1.Append(pi.Name + ",");                                           //拼接字段
                                    str2.Append("@" + pi.Name + ",");                                     //声明参数
                                    paras.Add(new SqlParameter("@" + pi.Name, pi.GetValue(model, null))); //对参数赋值
                                }
                            }
                        }
                        strSql.Append(str1.ToString().Trim(','));
                        strSql.Append(") values (");
                        strSql.Append(str2.ToString().Trim(','));
                        strSql.Append(") ");
                        strSql.Append(";select @@IDENTITY;");
                        object obj = DbHelperSQL.GetSingle(conn, trans, strSql.ToString(), paras.ToArray());//带事务
                        model.id = Convert.ToInt32(obj);
                        #endregion

                        #region 菜单表信息====================
                        if (model.manager_role_values != null)
                        {
                            StringBuilder strSql2; //SQL字符串
                            StringBuilder str21;   //数据库字段
                            StringBuilder str22;   //声明参数
                            foreach (Model.manager_role_value modelt in model.manager_role_values)
                            {
                                strSql2 = new StringBuilder();
                                str21   = new StringBuilder();
                                str22   = new StringBuilder();
                                PropertyInfo[]      pros2  = modelt.GetType().GetProperties();
                                List <SqlParameter> paras2 = new List <SqlParameter>();
                                strSql2.Append("insert into " + databaseprefix + "manager_role_value(");
                                foreach (PropertyInfo pi in pros2)
                                {
                                    if (!pi.Name.Equals("id"))
                                    {
                                        if (pi.GetValue(modelt, null) != null && !pi.GetValue(modelt, null).ToString().Equals(""))
                                        {
                                            str21.Append(pi.Name + ",");
                                            str22.Append("@" + pi.Name + ",");
                                            if (pi.Name.Equals("role_id"))
                                            {
                                                paras2.Add(new SqlParameter("@" + pi.Name, model.id));//将刚插入的父ID赋值
                                            }
                                            else
                                            {
                                                paras2.Add(new SqlParameter("@" + pi.Name, pi.GetValue(modelt, null)));
                                            }
                                        }
                                    }
                                }
                                strSql2.Append(str21.ToString().Trim(','));
                                strSql2.Append(") values (");
                                strSql2.Append(str22.ToString().Trim(','));
                                strSql2.Append(") ");
                                DbHelperSQL.ExecuteSql(conn, trans, strSql2.ToString(), paras2.ToArray());
                            }
                        }
                        #endregion

                        #region 权限表信息
                        if (model.RolePemissionList != null)
                        {
                            string sql = "";
                            foreach (Model.userRolePemission item in model.RolePemissionList)
                            {
                                sql = "insert into MS_userRolePemission(urp_type,urp_roleid,urp_username,urp_code) values(@type,@rid,'',@code)";
                                SqlParameter[] sp = new SqlParameter[] {
                                    new SqlParameter("@type", item.urp_type),
                                    new SqlParameter("@rid", model.id),
                                    new SqlParameter("@code", item.urp_code)
                                };
                                DbHelperSQL.ExecuteSql(conn, trans, sql, sp);
                            }
                        }
                        #endregion

                        trans.Commit(); //提交事务
                    }
                    catch
                    {
                        trans.Rollback(); //回滚事务
                        return(0);
                    }
                }
            }
            return(model.id);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.manager_role model)
        {
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        #region 主表信息==========================
                        StringBuilder strSql = new StringBuilder();
                        StringBuilder str1   = new StringBuilder();
                        //利用反射获得属性的所有公共属性
                        PropertyInfo[]      pros  = model.GetType().GetProperties();
                        List <SqlParameter> paras = new List <SqlParameter>();
                        strSql.Append("update " + databaseprefix + "manager_role set ");
                        foreach (PropertyInfo pi in pros)
                        {
                            //如果不是主键和LIST<T>则追加sql字符串
                            if (!pi.Name.Equals("id") && !typeof(System.Collections.IList).IsAssignableFrom(pi.PropertyType))
                            {
                                //判断属性值是否为空
                                if (pi.GetValue(model, null) != null && !pi.GetValue(model, null).ToString().Equals(""))
                                {
                                    str1.Append(pi.Name + "=@" + pi.Name + ",");                          //声明参数
                                    paras.Add(new SqlParameter("@" + pi.Name, pi.GetValue(model, null))); //对参数赋值
                                }
                            }
                        }
                        strSql.Append(str1.ToString().Trim(','));
                        strSql.Append(" where id=@id ");
                        paras.Add(new SqlParameter("@id", model.id));
                        DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), paras.ToArray());
                        #endregion

                        #region 菜单表信息====================
                        //删除菜单
                        StringBuilder strSql1 = new StringBuilder();
                        strSql1.Append("delete from " + databaseprefix + "manager_role_value where role_id=@role_id");
                        SqlParameter[] parameters1 =
                        {
                            new SqlParameter("@role_id", SqlDbType.Int, 4)
                        };
                        parameters1[0].Value = model.id;
                        DbHelperSQL.ExecuteSql(conn, trans, strSql1.ToString(), parameters1);
                        //重新添加菜单
                        if (model.manager_role_values != null)
                        {
                            StringBuilder strSql2; //SQL字符串
                            StringBuilder str21;   //数据库字段
                            StringBuilder str22;   //声明参数
                            foreach (Model.manager_role_value modelt in model.manager_role_values)
                            {
                                strSql2 = new StringBuilder();
                                str21   = new StringBuilder();
                                str22   = new StringBuilder();
                                PropertyInfo[]      pros2  = modelt.GetType().GetProperties();
                                List <SqlParameter> paras2 = new List <SqlParameter>();
                                strSql2.Append("insert into " + databaseprefix + "manager_role_value(");
                                foreach (PropertyInfo pi in pros2)
                                {
                                    if (!pi.Name.Equals("id"))
                                    {
                                        if (pi.GetValue(modelt, null) != null && !pi.GetValue(modelt, null).ToString().Equals(""))
                                        {
                                            str21.Append(pi.Name + ",");
                                            str22.Append("@" + pi.Name + ",");
                                            if (pi.Name.Equals("role_id"))
                                            {
                                                paras2.Add(new SqlParameter("@" + pi.Name, model.id));//将刚角色的ID赋值
                                            }
                                            else
                                            {
                                                paras2.Add(new SqlParameter("@" + pi.Name, pi.GetValue(modelt, null)));
                                            }
                                        }
                                    }
                                }
                                strSql2.Append(str21.ToString().Trim(','));
                                strSql2.Append(") values (");
                                strSql2.Append(str22.ToString().Trim(','));
                                strSql2.Append(") ");
                                DbHelperSQL.ExecuteSql(conn, trans, strSql2.ToString(), paras2.ToArray());
                            }
                        }
                        #endregion

                        #region 权限表信息
                        string         sql = "delete from MS_userRolePemission where urp_roleid=@rid";
                        SqlParameter[] sp1 = new SqlParameter[] {
                            new SqlParameter("@rid", model.id)
                        };
                        DbHelperSQL.ExecuteSql(conn, trans, sql, sp1);
                        if (model.RolePemissionList != null)
                        {
                            sql = "";
                            foreach (Model.userRolePemission item in model.RolePemissionList)
                            {
                                sql = "insert into MS_userRolePemission(urp_type,urp_roleid,urp_username,urp_code) values(@type,@rid,'',@code)";
                                SqlParameter[] sp = new SqlParameter[] {
                                    new SqlParameter("@type", item.urp_type),
                                    new SqlParameter("@rid", model.id),
                                    new SqlParameter("@code", item.urp_code)
                                };
                                DbHelperSQL.ExecuteSql(conn, trans, sql, sp);
                            }
                        }
                        #endregion

                        trans.Commit(); //提交事务
                    }
                    catch
                    {
                        trans.Rollback(); //回滚事务
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 19
0
        private bool DoAdd()
        {
            bool result = true;

            Model.manager_role model = new Model.manager_role();
            BLL.manager_role   bll   = new BLL.manager_role();

            model.role_name = txtRoleName.Text.Trim();
            model.role_type = int.Parse(ddlRoleType.SelectedValue);

            List <Model.manager_role_value> ls = new List <Model.manager_role_value>();

            //基本設置
            for (int i = 0; i < rptList1.Items.Count; i++)
            {
                HiddenField       hidNavName  = rptList1.Items[i].FindControl("hidName") as HiddenField;
                HtmlInputCheckBox hcbNavValue = rptList1.Items[i].FindControl("cblNavName") as HtmlInputCheckBox;
                if (hidNavName != null && hcbNavValue != null)
                {
                    if (hcbNavValue.Checked == true)
                    {
                        ls.Add(new Model.manager_role_value {
                            channel_id = 0, channel_name = hidNavName.Value, action_type = hcbNavValue.Value
                        });
                    }
                }
            }
            //會員設置
            for (int i = 0; i < rptList2.Items.Count; i++)
            {
                HiddenField       hidNavName  = rptList2.Items[i].FindControl("hidName") as HiddenField;
                HtmlInputCheckBox hcbNavValue = rptList2.Items[i].FindControl("cblNavName") as HtmlInputCheckBox;
                if (hidNavName != null && hcbNavValue != null)
                {
                    if (hcbNavValue.Checked == true)
                    {
                        ls.Add(new Model.manager_role_value {
                            channel_id = 0, channel_name = hidNavName.Value, action_type = hcbNavValue.Value
                        });
                    }
                }
            }
            //銷售設置
            for (int i = 0; i < rptList21.Items.Count; i++)
            {
                HiddenField       hidNavName  = rptList21.Items[i].FindControl("hidName") as HiddenField;
                HtmlInputCheckBox hcbNavValue = rptList21.Items[i].FindControl("cblNavName") as HtmlInputCheckBox;
                if (hidNavName != null && hcbNavValue != null)
                {
                    if (hcbNavValue.Checked == true)
                    {
                        ls.Add(new Model.manager_role_value {
                            channel_id = 0, channel_name = hidNavName.Value, action_type = hcbNavValue.Value
                        });
                    }
                }
            }
            //頻道設置
            for (int i = 0; i < rptList3.Items.Count; i++)
            {
                int channelId               = Convert.ToInt32(((HiddenField)rptList3.Items[i].FindControl("hidChannelId")).Value);
                HtmlInputCheckBox hcbView   = rptList3.Items[i].FindControl("cbView") as HtmlInputCheckBox;
                HtmlInputCheckBox hcbAdd    = rptList3.Items[i].FindControl("cbAdd") as HtmlInputCheckBox;
                HtmlInputCheckBox hcbEdit   = rptList3.Items[i].FindControl("cbEdit") as HtmlInputCheckBox;
                HtmlInputCheckBox hcbDelete = rptList3.Items[i].FindControl("cbDelete") as HtmlInputCheckBox;
                if (hcbView != null && hcbView.Checked == true)
                {
                    ls.Add(new Model.manager_role_value {
                        channel_id = channelId, channel_name = "channel", action_type = DTEnums.ActionEnum.View.ToString()
                    });
                }
                if (hcbAdd != null && hcbAdd.Checked == true)
                {
                    ls.Add(new Model.manager_role_value {
                        channel_id = channelId, channel_name = "channel", action_type = DTEnums.ActionEnum.Add.ToString()
                    });
                }
                if (hcbEdit != null && hcbEdit.Checked == true)
                {
                    ls.Add(new Model.manager_role_value {
                        channel_id = channelId, channel_name = "channel", action_type = DTEnums.ActionEnum.Edit.ToString()
                    });
                }
                if (hcbDelete != null && hcbDelete.Checked == true)
                {
                    ls.Add(new Model.manager_role_value {
                        channel_id = channelId, channel_name = "channel", action_type = DTEnums.ActionEnum.Delete.ToString()
                    });
                }
            }

            model.manager_role_values = ls;
            if (bll.Add(model) < 1)
            {
                result = false;
            }
            return(result);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.manager_role model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + databaseprefix + "manager_role set ");
            strSql.Append("role_name=@role_name,");
            strSql.Append("role_type=@role_type,");
            strSql.Append("is_sys=@is_sys");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@role_name", SqlDbType.NVarChar, 100),
                new SqlParameter("@role_type", SqlDbType.TinyInt,    1),
                new SqlParameter("@is_sys",    SqlDbType.TinyInt,    1),
                new SqlParameter("@id",        SqlDbType.Int, 4)
            };
            parameters[0].Value = model.role_name;
            parameters[1].Value = model.role_type;
            parameters[2].Value = model.is_sys;
            parameters[3].Value = model.id;

            List <CommandInfo> sqllist = new List <CommandInfo>();
            CommandInfo        cmd     = new CommandInfo(strSql.ToString(), parameters);

            sqllist.Add(cmd);

            //先删除该角色所有权限
            StringBuilder strSql2 = new StringBuilder();

            strSql2.Append("delete from " + databaseprefix + "manager_role_value where role_id=@role_id ");
            SqlParameter[] parameters2 =
            {
                new SqlParameter("@role_id", SqlDbType.Int, 4)
            };
            parameters2[0].Value = model.id;
            cmd = new CommandInfo(strSql2.ToString(), parameters2);
            sqllist.Add(cmd);

            //添加权限
            if (model.manager_role_values != null)
            {
                StringBuilder strSql3;
                foreach (Model.manager_role_value modelt in model.manager_role_values)
                {
                    strSql3 = new StringBuilder();
                    strSql3.Append("insert into " + databaseprefix + "manager_role_value(");
                    strSql3.Append("role_id,nav_name,action_type)");
                    strSql3.Append(" values (");
                    strSql3.Append("@role_id,@nav_name,@action_type)");
                    SqlParameter[] parameters3 =
                    {
                        new SqlParameter("@role_id",     SqlDbType.Int,        4),
                        new SqlParameter("@nav_name",    SqlDbType.NVarChar, 100),
                        new SqlParameter("@action_type", SqlDbType.NVarChar, 50)
                    };
                    parameters3[0].Value = model.id;
                    parameters3[1].Value = modelt.nav_name;
                    parameters3[2].Value = modelt.action_type;
                    cmd = new CommandInfo(strSql3.ToString(), parameters3);
                    sqllist.Add(cmd);
                }
            }

            int rowsAffected = DbHelperSQL.ExecuteSqlTran(sqllist);

            if (rowsAffected > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 21
0
        private bool DoEdit(int _id)
        {
            bool result = true;

            BLL.manager_role   bll   = new BLL.manager_role();
            Model.manager_role model = bll.GetModel(_id);

            model.role_name  = txtRoleName.Text.Trim();
            model.role_type  = int.Parse(ddlRoleType.SelectedValue);
            model.role_value = int.Parse(txtRoleValue.Text.Trim());

            List <Model.manager_role_value> ls = new List <Model.manager_role_value>();

            //系统设置
            for (int i = 0; i < rptList1.Items.Count; i++)
            {
                int               hidId       = Convert.ToInt32(((HiddenField)rptList1.Items[i].FindControl("hidId")).Value);
                HiddenField       hidNavName  = rptList1.Items[i].FindControl("hidName") as HiddenField;
                HtmlInputCheckBox hcbNavValue = rptList1.Items[i].FindControl("cblNavName") as HtmlInputCheckBox;
                if (hidNavName != null && hcbNavValue != null)
                {
                    if (hcbNavValue.Checked == true)
                    {
                        ls.Add(new Model.manager_role_value {
                            id = hidId, role_id = _id, channel_id = 0, channel_name = hidNavName.Value, action_type = hcbNavValue.Value
                        });
                    }
                }
            }
            //工时设置
            for (int i = 0; i < rptList2.Items.Count; i++)
            {
                HiddenField       hidNavName  = rptList2.Items[i].FindControl("hidName") as HiddenField;
                HtmlInputCheckBox hcbNavValue = rptList2.Items[i].FindControl("cblNavName") as HtmlInputCheckBox;
                if (hidNavName != null && hcbNavValue != null)
                {
                    if (hcbNavValue.Checked == true)
                    {
                        ls.Add(new Model.manager_role_value {
                            channel_id = 0, channel_name = hidNavName.Value, action_type = hcbNavValue.Value
                        });
                    }
                }
            }
            //工单设置
            for (int i = 0; i < rptList3.Items.Count; i++)
            {
                HiddenField       hidNavName  = rptList3.Items[i].FindControl("hidName") as HiddenField;
                HtmlInputCheckBox hcbNavValue = rptList3.Items[i].FindControl("cblNavName") as HtmlInputCheckBox;
                if (hidNavName != null && hcbNavValue != null)
                {
                    if (hcbNavValue.Checked == true)
                    {
                        ls.Add(new Model.manager_role_value {
                            channel_id = 0, channel_name = hidNavName.Value, action_type = hcbNavValue.Value
                        });
                    }
                }
            }
            //客户设置
            for (int i = 0; i < rptList4.Items.Count; i++)
            {
                HiddenField       hidNavName  = rptList4.Items[i].FindControl("hidName") as HiddenField;
                HtmlInputCheckBox hcbNavValue = rptList4.Items[i].FindControl("cblNavName") as HtmlInputCheckBox;
                if (hidNavName != null && hcbNavValue != null)
                {
                    if (hcbNavValue.Checked == true)
                    {
                        ls.Add(new Model.manager_role_value {
                            channel_id = 0, channel_name = hidNavName.Value, action_type = hcbNavValue.Value
                        });
                    }
                }
            }
            ////会员设置
            //for (int i = 0; i < rptList2.Items.Count; i++)
            //{
            //    int hidId = Convert.ToInt32(((HiddenField)rptList2.Items[i].FindControl("hidId")).Value);
            //    HiddenField hidNavName = rptList2.Items[i].FindControl("hidName") as HiddenField;
            //    HtmlInputCheckBox hcbNavValue = rptList2.Items[i].FindControl("cblNavName") as HtmlInputCheckBox;
            //    if (hidNavName != null && hcbNavValue != null)
            //    {
            //        if (hcbNavValue.Checked == true)
            //        {
            //            ls.Add(new Model.manager_role_value { id = hidId, role_id = _id, channel_id = 0, channel_name = hidNavName.Value, action_type = hcbNavValue.Value });
            //        }
            //    }
            //}
            ////销售设置
            //for (int i = 0; i < rptList21.Items.Count; i++)
            //{
            //    int hidId = Convert.ToInt32(((HiddenField)rptList21.Items[i].FindControl("hidId")).Value);
            //    HiddenField hidNavName = rptList21.Items[i].FindControl("hidName") as HiddenField;
            //    HtmlInputCheckBox hcbNavValue = rptList21.Items[i].FindControl("cblNavName") as HtmlInputCheckBox;
            //    if (hidNavName != null && hcbNavValue != null)
            //    {
            //        if (hcbNavValue.Checked == true)
            //        {
            //            ls.Add(new Model.manager_role_value { id = hidId, role_id = _id, channel_id = 0, channel_name = hidNavName.Value, action_type = hcbNavValue.Value });
            //        }
            //    }
            //}
            ////频道设置
            //for (int i = 0; i < rptList3.Items.Count; i++)
            //{
            //    int channelId = Convert.ToInt32(((HiddenField)rptList3.Items[i].FindControl("hidChannelId")).Value);
            //    HtmlInputCheckBox hcbView = rptList3.Items[i].FindControl("cbView") as HtmlInputCheckBox;
            //    HtmlInputCheckBox hcbAdd = rptList3.Items[i].FindControl("cbAdd") as HtmlInputCheckBox;
            //    HtmlInputCheckBox hcbEdit = rptList3.Items[i].FindControl("cbEdit") as HtmlInputCheckBox;
            //    HtmlInputCheckBox hcbDelete = rptList3.Items[i].FindControl("cbDelete") as HtmlInputCheckBox;
            //    int hidViewId = Convert.ToInt32(((HiddenField)rptList3.Items[i].FindControl("hidViewId")).Value);
            //    int hidAddId = Convert.ToInt32(((HiddenField)rptList3.Items[i].FindControl("hidAddId")).Value);
            //    int hidEditId = Convert.ToInt32(((HiddenField)rptList3.Items[i].FindControl("hidEditId")).Value);
            //    int hidDeleteId = Convert.ToInt32(((HiddenField)rptList3.Items[i].FindControl("hidDeleteId")).Value);

            //    if (hcbView != null && hcbView.Checked == true)
            //    {
            //        ls.Add(new Model.manager_role_value { id = hidViewId, role_id = _id, channel_id = channelId, channel_name = "channel", action_type = DTEnums.ActionEnum.View.ToString() });
            //    }
            //    if (hcbAdd != null && hcbAdd.Checked == true)
            //    {
            //        ls.Add(new Model.manager_role_value { id = hidAddId, role_id = _id, channel_id = channelId, channel_name = "channel", action_type = DTEnums.ActionEnum.Add.ToString() });
            //    }
            //    if (hcbEdit != null && hcbEdit.Checked == true)
            //    {
            //        ls.Add(new Model.manager_role_value { id = hidEditId, role_id = _id, channel_id = channelId, channel_name = "channel", action_type = DTEnums.ActionEnum.Edit.ToString() });
            //    }
            //    if (hcbDelete != null && hcbDelete.Checked == true)
            //    {
            //        ls.Add(new Model.manager_role_value { id = hidDeleteId, role_id = _id, channel_id = channelId, channel_name = "channel", action_type = DTEnums.ActionEnum.Delete.ToString() });
            //    }
            //}

            model.manager_role_values = ls;
            if (!bll.Update(model))
            {
                result = false;
            }

            return(result);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 更新一条数据及其子表
        /// </summary>
        public bool Update(Model.manager_role model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update dt_manager_role set ");
            strSql.Append("role_name=@role_name,");
            strSql.Append("role_type=@role_type");
            strSql.Append(" where id=@id ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id",        SqlDbType.Int,        4),
                new SqlParameter("@role_name", SqlDbType.NVarChar, 100),
                new SqlParameter("@role_type", SqlDbType.TinyInt, 1)
            };
            parameters[0].Value = model.id;
            parameters[1].Value = model.role_name;
            parameters[2].Value = model.role_type;

            List <CommandInfo> sqllist = new List <CommandInfo>();
            CommandInfo        cmd     = new CommandInfo(strSql.ToString(), parameters);

            sqllist.Add(cmd);

            //删除权限
            StringBuilder strSql2 = new StringBuilder();

            strSql2.Append("delete from dt_manager_role_value where role_id=@role_id ");
            StringBuilder idList = new StringBuilder();

            if (model.manager_role_values != null)
            {
                foreach (Model.manager_role_value models in model.manager_role_values)
                {
                    if (models.id > 0)
                    {
                        idList.Append(models.id + ",");
                    }
                }
                string id_list = Utils.DelLastChar(idList.ToString(), ",");
                if (!string.IsNullOrEmpty(id_list))
                {
                    strSql2.Append(" and id not in(" + id_list + ")");
                }
            }
            SqlParameter[] parameters2 =
            {
                new SqlParameter("@role_id", SqlDbType.Int, 4)
            };
            parameters2[0].Value = model.id;

            cmd = new CommandInfo(strSql2.ToString(), parameters2);
            sqllist.Add(cmd);

            //添加权限
            if (model.manager_role_values != null)
            {
                StringBuilder strSql3;
                foreach (Model.manager_role_value models in model.manager_role_values)
                {
                    strSql3 = new StringBuilder();
                    if (models.id == 0)
                    {
                        strSql3.Append("insert into dt_manager_role_value(");
                        strSql3.Append("role_id,channel_name,channel_id,action_type)");
                        strSql3.Append(" values (");
                        strSql3.Append("@role_id,@channel_name,@channel_id,@action_type)");
                        SqlParameter[] parameters3 =
                        {
                            new SqlParameter("@role_id",      SqlDbType.Int,        4),
                            new SqlParameter("@channel_name", SqlDbType.NVarChar, 255),
                            new SqlParameter("@channel_id",   SqlDbType.Int,        4),
                            new SqlParameter("@action_type",  SqlDbType.NVarChar, 100)
                        };
                        parameters3[0].Value = model.id;
                        parameters3[1].Value = models.channel_name;
                        parameters3[2].Value = models.channel_id;
                        parameters3[3].Value = models.action_type;

                        cmd = new CommandInfo(strSql3.ToString(), parameters3);
                        sqllist.Add(cmd);
                    }
                }
            }

            int rowsAffected = DbHelperSQL.ExecuteSqlTran(sqllist);

            if (rowsAffected > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 23
0
        private bool DoAdd()
        {
            bool result = false;
            Model.manager_role model = new Model.manager_role();
            BLL.manager_role bll = new BLL.manager_role();

            model.role_name = txtRoleName.Text.Trim();
            model.role_type = int.Parse(ddlRoleType.SelectedValue);

            //管理权限
            List<Model.manager_role_value> ls = new List<Model.manager_role_value>();
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                string navName = ((HiddenField)rptList.Items[i].FindControl("hidName")).Value;
                CheckBoxList cblActionType = (CheckBoxList)rptList.Items[i].FindControl("cblActionType");
                for (int n = 0; n < cblActionType.Items.Count; n++)
                {
                    if (cblActionType.Items[n].Selected == true)
                    {
                        ls.Add(new Model.manager_role_value { nav_name = navName, action_type = cblActionType.Items[n].Value });
                    }
                }
            }
            model.manager_role_values = ls;

            if (bll.Add(model) > 0)
            {
                AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加管理角色:" + model.role_name); //记录日志
                result = true;
            }
            return result;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.manager_role model)
        {
            using (OleDbConnection conn = new OleDbConnection(DbHelperOleDb.connectionString))
            {
                conn.Open();
                using (OleDbTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("update " + databaseprefix + "manager_role set ");
                        strSql.Append("role_name=@role_name,");
                        strSql.Append("role_type=@role_type,");
                        strSql.Append("is_sys=@is_sys");
                        strSql.Append(" where id=@id");
                        OleDbParameter[] parameters =
                        {
                            new OleDbParameter("@role_name", OleDbType.VarChar, 100),
                            new OleDbParameter("@role_type", OleDbType.Integer,   4),
                            new OleDbParameter("@is_sys",    OleDbType.Integer,   4),
                            new OleDbParameter("@id",        OleDbType.Integer, 4)
                        };
                        parameters[0].Value = model.role_name;
                        parameters[1].Value = model.role_type;
                        parameters[2].Value = model.is_sys;
                        parameters[3].Value = model.id;
                        DbHelperOleDb.ExecuteSql(conn, trans, strSql.ToString(), parameters);

                        //先删除该角色所有权限
                        StringBuilder strSql2 = new StringBuilder();
                        strSql2.Append("delete from " + databaseprefix + "manager_role_value where role_id=@role_id ");
                        OleDbParameter[] parameters2 =
                        {
                            new OleDbParameter("@role_id", OleDbType.Integer, 4)
                        };
                        parameters2[0].Value = model.id;
                        DbHelperOleDb.ExecuteSql(conn, trans, strSql2.ToString(), parameters2);

                        //添加权限
                        if (model.manager_role_values != null)
                        {
                            StringBuilder strSql3;
                            foreach (Model.manager_role_value modelt in model.manager_role_values)
                            {
                                strSql3 = new StringBuilder();
                                strSql3.Append("insert into " + databaseprefix + "manager_role_value(");
                                strSql3.Append("role_id,nav_name,action_type)");
                                strSql3.Append(" values (");
                                strSql3.Append("@role_id,@nav_name,@action_type)");
                                OleDbParameter[] parameters3 =
                                {
                                    new OleDbParameter("@role_id",     OleDbType.Integer,   4),
                                    new OleDbParameter("@nav_name",    OleDbType.VarChar, 100),
                                    new OleDbParameter("@action_type", OleDbType.VarChar, 50)
                                };
                                parameters3[0].Value = model.id;
                                parameters3[1].Value = modelt.nav_name;
                                parameters3[2].Value = modelt.action_type;
                                DbHelperOleDb.ExecuteSql(conn, trans, strSql3.ToString(), parameters3);
                            }
                        }

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 25
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Model.manager_role model)
 {
     return(dal.Add(model));
 }
Ejemplo n.º 26
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.manager_role model)
        {
            //StringBuilder strSql = new StringBuilder();
            //strSql.Append("update " + databaseprefix + "manager_role set ");
            //strSql.Append("role_name=@role_name,");
            //strSql.Append("role_type=@role_type,");
            //strSql.Append("is_sys=@is_sys");
            //strSql.Append(" where id=@id");
            //SqlParameter[] parameters = {
            //        new SqlParameter("@role_name", SqlDbType.NVarChar,100),
            //        new SqlParameter("@role_type", SqlDbType.TinyInt,1),
            //        new SqlParameter("@is_sys", SqlDbType.TinyInt,1),
            //        new SqlParameter("@id", SqlDbType.Int,4)};
            //parameters[0].Value = model.role_name;
            //parameters[1].Value = model.role_type;
            //parameters[2].Value = model.is_sys;
            //parameters[3].Value = model.id;



            StringBuilder             strSql     = new StringBuilder();
            Collection <SqlParameter> parameters = new Collection <SqlParameter>

                                                       ();
            SqlParameter parameter = null;
            int          count     = 0;

            strSql.Append("update dt_manager_role set ");
            parameter = new SqlParameter("@id",

                                         SqlDbType.Int, 4);
            parameter.Value = model.id;
            parameters.Add(parameter);
            if (model.role_name_IsEdit)
            {
                strSql.Append(" role_name = @role_name,");
                parameter = new SqlParameter("@role_name",

                                             SqlDbType.NVarChar, 100);
                parameter.Value = model.role_name;
                parameters.Add(parameter);
                count++;
            }



            if (model.role_type_IsEdit)
            {
                strSql.Append(" role_type = @role_type,");
                parameter = new SqlParameter("@role_type",

                                             SqlDbType.TinyInt, 1);
                parameter.Value = model.role_type;
                parameters.Add(parameter);
                count++;
            }



            if (model.is_sys_IsEdit)
            {
                strSql.Append(" is_sys = @is_sys,");
                parameter = new SqlParameter("@is_sys",

                                             SqlDbType.TinyInt, 1);
                parameter.Value = model.is_sys;
                parameters.Add(parameter);
                count++;
            }



            if (model.agentId_IsEdit)
            {
                strSql.Append(" agentId = @agentId,");
                parameter = new SqlParameter("@agentId",

                                             SqlDbType.Int, 4);
                parameter.Value = model.agentId;
                parameters.Add(parameter);
                count++;
            }

            if (count > 0)
            {
                strSql.Remove(strSql.Length - 1, 1);
            }
            if (count == 0)
            {
                return(false);
            }
            strSql.Append(" where id=@id ");
            // 将参数泛形集合转传为数组
            SqlParameter[] args = new SqlParameter[parameters.Count];
            parameters.CopyTo(args, 0);
            List <CommandInfo> sqllist = new List <CommandInfo>();
            CommandInfo        cmd     = new CommandInfo(strSql.ToString(), args);

            sqllist.Add(cmd);

            //先删除该角色所有权限
            StringBuilder strSql2 = new StringBuilder();

            strSql2.Append("delete from " + databaseprefix + "manager_role_value where role_id=@role_id ");
            SqlParameter[] parameters2 =
            {
                new SqlParameter("@role_id", SqlDbType.Int, 4)
            };
            parameters2[0].Value = model.id;
            cmd = new CommandInfo(strSql2.ToString(), parameters2);
            sqllist.Add(cmd);

            //添加权限
            if (model.manager_role_values != null)
            {
                StringBuilder strSql3;
                foreach (Model.manager_role_value modelt in model.manager_role_values)
                {
                    strSql3 = new StringBuilder();
                    strSql3.Append("insert into " + databaseprefix + "manager_role_value(");
                    strSql3.Append("role_id,nav_name,action_type)");
                    strSql3.Append(" values (");
                    strSql3.Append("@role_id,@nav_name,@action_type)");
                    SqlParameter[] parameters3 =
                    {
                        new SqlParameter("@role_id",     SqlDbType.Int,        4),
                        new SqlParameter("@nav_name",    SqlDbType.NVarChar, 100),
                        new SqlParameter("@action_type", SqlDbType.NVarChar, 50)
                    };
                    parameters3[0].Value = model.id;
                    parameters3[1].Value = modelt.nav_name;
                    parameters3[2].Value = modelt.action_type;
                    cmd = new CommandInfo(strSql3.ToString(), parameters3);
                    sqllist.Add(cmd);
                }
            }

            int rowsAffected = DbHelperSQL.ExecuteSqlTran(sqllist);

            if (rowsAffected > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 27
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.manager_role model)
 {
     return(dal.Update(model));
 }
Ejemplo n.º 28
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.manager_role GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,role_name,role_type,is_sys from " + databaseprefix + "manager_role ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Model.manager_role model = new Model.manager_role();
            DataSet            ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                #region 父表信息
                if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                model.role_name = ds.Tables[0].Rows[0]["role_name"].ToString();
                if (ds.Tables[0].Rows[0]["role_type"].ToString() != "")
                {
                    model.role_type = int.Parse(ds.Tables[0].Rows[0]["role_type"].ToString());
                }
                if (ds.Tables[0].Rows[0]["is_sys"].ToString() != "")
                {
                    model.is_sys = int.Parse(ds.Tables[0].Rows[0]["is_sys"].ToString());
                }
                #endregion

                #region 子表信息
                StringBuilder strSql2 = new StringBuilder();
                strSql2.Append("select id,role_id,nav_name,action_type from " + databaseprefix + "manager_role_value ");
                strSql2.Append(" where role_id=@role_id");
                SqlParameter[] parameters2 =
                {
                    new SqlParameter("@role_id", SqlDbType.Int, 4)
                };
                parameters2[0].Value = id;
                DataSet ds2 = DbHelperSQL.Query(strSql2.ToString(), parameters2);
                if (ds2.Tables[0].Rows.Count > 0)
                {
                    List <Model.manager_role_value> models = new List <Model.manager_role_value>();
                    Model.manager_role_value        modelt;
                    foreach (DataRow dr in ds2.Tables[0].Rows)
                    {
                        modelt = new Model.manager_role_value();
                        if (dr["id"].ToString() != "")
                        {
                            modelt.id = int.Parse(dr["id"].ToString());
                        }
                        if (dr["role_id"].ToString() != "")
                        {
                            modelt.role_id = int.Parse(dr["role_id"].ToString());
                        }
                        modelt.nav_name    = dr["nav_name"].ToString();
                        modelt.action_type = dr["action_type"].ToString();
                        models.Add(modelt);
                    }
                    model.manager_role_values = models;
                }
                #endregion

                return(model);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// �õ�һ������ʵ��
        /// </summary>
        public Model.manager_role GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,role_name,role_type,is_sys from " + databaseprefix + "manager_role ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int,4)};
            parameters[0].Value = id;

            Model.manager_role model = new Model.manager_role();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                #region ������Ϣ
                if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                model.role_name = ds.Tables[0].Rows[0]["role_name"].ToString();
                if (ds.Tables[0].Rows[0]["role_type"].ToString() != "")
                {
                    model.role_type = int.Parse(ds.Tables[0].Rows[0]["role_type"].ToString());
                }
                if (ds.Tables[0].Rows[0]["is_sys"].ToString() != "")
                {
                    model.is_sys = int.Parse(ds.Tables[0].Rows[0]["is_sys"].ToString());
                }
                #endregion

                #region �ӱ���Ϣ
                StringBuilder strSql2 = new StringBuilder();
                strSql2.Append("select id,role_id,nav_name,action_type from dt_manager_role_value ");
                strSql2.Append(" where role_id=@role_id");
                SqlParameter[] parameters2 = {
                    new SqlParameter("@role_id", SqlDbType.Int,4)};
                parameters2[0].Value = id;
                DataSet ds2 = DbHelperSQL.Query(strSql2.ToString(), parameters2);
                if (ds2.Tables[0].Rows.Count > 0)
                {
                    List<Model.manager_role_value> models = new List<Model.manager_role_value>();
                    Model.manager_role_value modelt;
                    foreach (DataRow dr in ds2.Tables[0].Rows)
                    {
                        modelt = new Model.manager_role_value();
                        if (dr["id"].ToString() != "")
                        {
                            modelt.id = int.Parse(dr["id"].ToString());
                        }
                        if (dr["role_id"].ToString() != "")
                        {
                            modelt.role_id = int.Parse(dr["role_id"].ToString());
                        }
                        modelt.nav_name = dr["nav_name"].ToString();
                        modelt.action_type = dr["action_type"].ToString();
                        models.Add(modelt);
                    }
                    model.manager_role_values = models;
                }
                #endregion

                return model;
            }
            else
            {
                return null;
            }
        }