Example #1
0
        public bool add(RoleModel pm, IList<RolePowerModel> list)
        {
            SqlConnection cn = null;
            SqlTransaction tc = null;
            try
            {
                cn = DbHelperSQL.getConnection();
                tc = DbHelperSQL.startTransaction(cn);
                int maxevenid=-1;
                if (roleDal.add(cn, tc, pm))
                {
                    object obj = DbHelperSQL.ExeScalar(cn, tc, "SELECT MAX(Evenid) FROM Role");
                    if (obj != null)
                    {
                         int.TryParse(obj.ToString(), out maxevenid);
                    }
                }
                pm.Evenid = maxevenid;
                pm.RoleID = maxevenid.ToString();
                roleDal.update(cn, tc, pm);

                foreach (var item in list)
                {
                    item.RoleID = maxevenid.ToString();
                }

                if ( rolePowerDal.add(cn, tc, list))
                {
                    DbHelperSQL.commitTransaction(tc);
                    return true;
                }
                return false;
            }
            catch (SqlException sql)
            {
                DbHelperSQL.rollBackTransaction(tc);
                throw new MakeException(ExpSort.数据库, sql.Message);
            }
            finally
            {
                DbHelperSQL.closeConnection(cn);
            }
        }
Example #2
0
        public bool update(RoleModel pm, IList<RolePowerModel> list)
        {
            SqlConnection cn = null;
            SqlTransaction tc = null;
            try
            {
                cn = DbHelperSQL.getConnection();
                tc = DbHelperSQL.startTransaction(cn);
                IList<QueryModel> qmlist = new List<QueryModel>();
                qmlist.Add(MakeUtil.getQueryModel("RoleId", "'", SqlWhere.WhereOperator.Equal, pm.RoleID));
                RoleModel oldrm = roleDal.getModel(cn, tc, qmlist);
                if (oldrm.RoleID.Length == 0)
                {
                    throw new MakeException(ExpSort.普通, "角色id:" + pm.RoleID + ",已不存在.");
                }
                foreach (var item in list)
                {
                    item.RoleID = pm.RoleID;
                }
                qmlist.Clear();
                qmlist.Add(MakeUtil.getQueryModel("RoleId", "'", SqlWhere.WhereOperator.Equal, pm.RoleID));
                roleDal.update(cn, tc, pm);
                rolePowerDal.del(cn, tc, qmlist);
                rolePowerDal.add(cn, tc, list);
                DbHelperSQL.commitTransaction(tc);
                return true;

            }
            catch (SqlException sqlex)
            {
                DbHelperSQL.rollBackTransaction(tc);
                throw new MakeException(ExpSort.数据库, sqlex.Message);
            }
            finally
            {
                DbHelperSQL.closeConnection(cn);
            }
        }
Example #3
0
 public bool update(SqlConnection cn, SqlTransaction tc, RoleModel RM)
 {
     return DbHelperSQL.updateModel<RoleModel>(RM, "Role", "Evenid", RM.Evenid.ToString(), "'", cn, tc);
 }
Example #4
0
 public RoleModel getMstModel(IList<QueryModel> qmlist)
 {
     SqlConnection cn = null;
     RoleModel pm = new RoleModel();
     try
     {
         cn = DbHelperSQL.getConnection();
         pm = roleDal.getModel(cn, null, qmlist);
     }
     catch (SqlException sqlex)
     {
         throw new MakeException(ExpSort.数据库, sqlex.Message);
     }
     finally
     {
         DbHelperSQL.closeConnection(cn);
     }
     return pm;
 }
Example #5
0
 public bool add(SqlConnection cn, SqlTransaction tc, RoleModel RM)
 {
     return DbHelperSQL.insertModel<RoleModel>(RM, "Role", cn, tc);
 }