Exemplo n.º 1
0
        /// <summary>
        /// 添加组织
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Add(Model.UserInfoGroupModel model)
        {
            int obj = 0;

            using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionString))
            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("insert into UserInfo_Group(GroupName) values('" + model.GroupName + "')");
                        strSql.Append(";select @@IDENTITY");
                        SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strSql.ToString());
                        string a = SqlHelper.ExecuteDataTable(trans, CommandType.Text, "select @@IDENTITY").Rows[0][0].ToString();
                        obj = Convert.ToInt32(a);
                        if (obj > 0)
                        {
                            foreach (Model.PermissionModel m in model.PerList)
                            {
                                string sql = "insert into Permission(MenuId,GroupId,MenuBid) values(" + m.MenuId + "," + obj + "," + m.MenuBid + ") ";
                                SqlHelper.ExecuteNonQuery(trans, CommandType.Text, sql);
                            }
                        }
                        trans.Commit();
                        return(1);
                    }
                    catch (Exception)
                    {
                        trans.Rollback();
                        return(0);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int Update(Model.UserInfoGroupModel model)
        {
            int j = 0;

            using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionString))
            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("update   UserInfo_Group set GroupName='" + model.GroupName + "' where groupid=" + model.GroupId);

                        j = SqlHelper.ExecuteNonQuery(trans, CommandType.Text, strSql.ToString());


                        if (j > 0)
                        {
                            foreach (Model.PermissionModel m in model.PerList)
                            {
                                string sql = "insert into Permission(MenuId,GroupId,MenuBid) values(" + m.MenuId + "," + model.GroupId + "," + m.MenuBid + ") ";
                                SqlHelper.ExecuteNonQuery(trans, CommandType.Text, sql);
                            }
                        }
                        trans.Commit();
                        return(1);
                    }
                    catch (Exception)
                    {
                        trans.Rollback();
                        return(0);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public Model.UserInfoGroupModel GetModel(int groupId)
        {
            string sql = "select groupid,groupName from UserInfo_Group where GroupId =" + groupId;

            Model.UserInfoGroupModel model = new Model.UserInfoGroupModel();
            DataTable dt = SqlHelper.ExecuteDataTable(conn, CommandType.Text, sql);

            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["GroupId"] != null && dt.Rows[0]["GroupId"].ToString() != "")
                {
                    model.GroupId = int.Parse(dt.Rows[0]["GroupId"].ToString());
                }
                if (dt.Rows[0]["GroupName"] != null && dt.Rows[0]["GroupName"].ToString() != "")
                {
                    model.GroupName = dt.Rows[0]["GroupName"].ToString();
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }