Exemplo n.º 1
0
        /// <summary>
        /// 创建新用户(管理员、二级用户)
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static int CreateUser(Dal.Models.UserInfo user, OleDbConnection conn, OleDbTransaction tran = null)
        {
            StringBuilder sbSql = new StringBuilder();
            int?          iResult;

            if (user == null ||
                user.CreateUser == null ||
                string.IsNullOrEmpty(user.UserName))
            {
                throw new Exception("用户信息不全!");
            }

            if (string.IsNullOrEmpty(user.UserType))
            {
                Dal.Models.UserInfo userCreator = GetUserInfo(user.CreateUser.Value, conn, tran);
                if (userCreator.UserType == "0801")
                {
                    // 超级管理员创建系统管理员和协会管理员,默认系统管理员
                    user.UserType = "0802";
                }
                else if (userCreator.UserType == "0802")
                {
                    // 系统管理员创建协会管理员
                    user.UserType = "0803";
                }
                else if (userCreator.UserType == "0803")
                {
                    // 协会管理员创建管理员
                    user.UserType = "0804";
                }
                else if (userCreator.UserType == "0804")
                {
                    // 管理员创建会员用户
                    user.UserType = "0806";
                }
                else if (userCreator.UserType == "0806")
                {
                    // 一级用户创建二级用户
                    user.UserType = "0807";
                }
                else
                {
                    // 参数错误
                    throw new Exception("参数错误!");
                }
            }

            // 判断用户名是否存在
            user.UserName = user.UserName.Trim();
            if (GetUserByName(user.UserName, conn, tran) != null ||
                BLL.Organization.GetOrganizationByName(user.UserName, conn, tran) != null ||
                BLL.Organization.GetOrganizationByCode(user.UserName, conn, tran) != null)
            {
                // 用户名已存在,
                throw new Exception("用户名已存在,不可再次创建!");
            }

            user.Email = user.Email.Trim();
            if (!string.IsNullOrEmpty(user.Email))
            {
                if (!Common.IsValidEmail(user.Email))
                {
                    // 邮箱格式错误
                    throw new Exception("邮箱格式错误,请重新填写!");
                }

                if (GetUserByMail(user.Email, conn, tran) != null)
                {
                    // 邮箱已存在,
                    throw new Exception("邮箱已存在,请换其他邮箱!");
                }
            }

            sbSql.Append("  INSERT INTO Users ( ");
            sbSql.Append("          UserName ");
            sbSql.Append("         ,Password ");
            sbSql.Append("         ,UserType ");
            sbSql.Append("         ,Email    ");
            sbSql.Append("         ,UserStatus ");
            sbSql.Append("         ,CreateTime ");
            sbSql.Append("         ,CreateUser ");
            sbSql.Append("         ,LastUpdateTime ");
            sbSql.Append("         ,IsPasswordChanged ");
            sbSql.Append(" ) VALUES ( ?, dbo.Fn_MD5Encrypt(?), ?, ?, '0701', GetDate(), ?, GetDate(),0) ");

            iResult = Dal.OleDbHlper.ExecuteNonQuery(sbSql.ToString(), conn, CommandType.Text, tran
                                                     , new OleDbParameter("@UserName", OleDbType.VarWChar)
            {
                Value = user.UserName
            }
                                                     , new OleDbParameter("@Password", OleDbType.VarWChar)
            {
                Value = user.Password
            }
                                                     , new OleDbParameter("@UserType", OleDbType.VarWChar)
            {
                Value = user.UserType
            }
                                                     , new OleDbParameter("@Email", OleDbType.VarWChar)
            {
                Value = user.Email
            }
                                                     , new OleDbParameter("@CreateUser", OleDbType.Integer)
            {
                Value = user.CreateUser
            }
                                                     );

            user.UserID = GetUserByName(user.UserName, conn, tran).UserID;

            Dictionary <string, string> dictAppSettings = SysConstant.GetAppSettingDict("", conn, tran);
            string strSendMailWhenCreateUser            = dictAppSettings["SendMailWhenCreateUser"];

            if (strSendMailWhenCreateUser.ToLower() == "true")
            {
                Dal.Models.MailInfo mailinfo = new Dal.Models.MailInfo();
                mailinfo.Subject       = "";
                mailinfo.SenderAddress = dictAppSettings["SenderAddress"];
                mailinfo.SmtpAcount    = dictAppSettings["SmtpAcount"];
                mailinfo.SmtpPassword  = dictAppSettings["SmtpPassword"];
                mailinfo.RecipientAddress.Add(user.Email);
                mailinfo.IsBodyHtml = true;
                mailinfo.Content    = "您已成功注册" + dictAppSettings["SystemName"] + "系统的账号!";
                Common.SendMail(mailinfo);
            }

            return(user.UserID.Value);
        }
Exemplo n.º 2
0
        public static int SetPrize(
            Dal.Models.Prize prize, List <int> LstPrizeLimitNum, OleDbConnection conn, OleDbTransaction tran)
        {
            if (prize == null || string.IsNullOrEmpty(prize.PrizeName) || prize.SpecialtyID == null)
            {
                throw new Exception("参数错误!");
            }

            Dal.Models.Specialty specialty = Specialty.GetSpecialty(prize.SpecialtyID.Value, conn, tran);

            // 所选专业不存在
            if (specialty == null)
            {
                throw new Exception("所选专业不存在!");
            }
            if ((specialty.ChildCount ?? 0) > 0)
            {
                throw new Exception("奖项创建失败,该专业下已存在子专业,无法创建奖项。");
            }

            // 同一专业中,奖项不允许重名
            Dal.Models.Prize prizeOriginal = GetPrize(prize.PrizeName, prize.SpecialtyID.Value, conn, tran);
            if (prizeOriginal != null && prize.PrizeID != prizeOriginal.PrizeID)
            {
                throw new Exception("同一专业中,奖项不允许重名!");
            }

            //奖项类别为空时,默认类别为综合奖
            if (string.IsNullOrEmpty(prize.PrizeTypeCode) ||
                !(new string[] { "0301", "0302", "0303", "0304" }).Contains(prize.PrizeTypeCode))
            {
                prize.PrizeTypeCode = "0301";
            }

            if (prize.ParticipantLimit == null)
            {
                prize.ParticipantLimit = Convert.ToInt32(
                    SysConstant.GetConstant(prize.PrizeTypeCode, conn, tran).CorrelationValue);
            }

            if (string.IsNullOrEmpty(prize.TemplateCode))
            {
                prize.TemplateCode = specialty.TemplateCode;
            }

            StringBuilder sbSql = new StringBuilder();

            if (prize.PrizeID == null)
            {
                sbSql.Append(" INSERT INTO Prize ( ");
                sbSql.Append("           PrizeName");
                sbSql.Append("          ,SpecialtyID ");
                sbSql.Append("          ,PrizeTypeCode ");
                sbSql.Append("          ,TemplateCode ");
                sbSql.Append("          ,IsMultipleVoting ");
                sbSql.Append("          ,VoteType ");
                sbSql.Append("          ,ParticipantLimit ");
                sbSql.Append("          ,AppendixDiscription ");
                sbSql.Append("          ,CreateTime ");
                sbSql.Append("          ,LastUpdateTime ");
                sbSql.Append(" ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, GETDATE(), GETDATE() ) ");

                int iResult = Dal.OleDbHlper.ExecuteNonQuery(
                    sbSql.ToString(), conn, CommandType.Text, tran
                    , new OleDbParameter("@PrizeName", OleDbType.VarWChar)
                {
                    Value = prize.PrizeName
                }
                    , new OleDbParameter("@SpecialtyID", OleDbType.Integer)
                {
                    Value = prize.SpecialtyID
                }
                    , new OleDbParameter("@PrizeTypeCode", OleDbType.VarWChar)
                {
                    Value = prize.PrizeTypeCode
                }
                    , new OleDbParameter("@TemplateCode", OleDbType.VarWChar)
                {
                    Value = prize.TemplateCode
                }
                    , new OleDbParameter("@IsMultipleVoting", OleDbType.Boolean)
                {
                    Value = prize.IsMultipleVoting
                }
                    , new OleDbParameter("@VoteType", OleDbType.VarWChar)
                {
                    Value = prize.VoteType
                }
                    , new OleDbParameter("@ParticipantNumber", OleDbType.Integer)
                {
                    Value = prize.ParticipantLimit
                }
                    , new OleDbParameter("@AppendixDiscription", OleDbType.VarWChar)
                {
                    Value = prize.AppendixDiscription
                }
                    );

                prize.PrizeID = GetPrize(prize.PrizeName, prize.SpecialtyID.Value, conn, tran).PrizeID;
            }
            else
            {
                sbSql.Append(" UPDATE Prize ");
                sbSql.Append("   SET  PrizeName = ? ");
                sbSql.Append("       ,IsMultipleVoting = ? ");
                sbSql.Append("       ,VoteType = ? ");
                sbSql.Append("       ,ParticipantLimit = ? ");
                sbSql.Append("       ,AppendixDiscription = ? ");
                sbSql.Append("       ,LastUpdateTime = GETDATE() ");
                sbSql.Append("  WHERE PrizeID = ? ");

                int iResult = Dal.OleDbHlper.ExecuteNonQuery(
                    sbSql.ToString(), conn, CommandType.Text, tran
                    , new OleDbParameter("@PrizeName", OleDbType.VarWChar)
                {
                    Value = prize.PrizeName
                }
                    , new OleDbParameter("@IsMultipleVoting", OleDbType.Boolean)
                {
                    Value = prize.IsMultipleVoting
                }
                    , new OleDbParameter("@VoteType", OleDbType.VarWChar)
                {
                    Value = prize.VoteType
                }
                    , new OleDbParameter("@ParticipantLimit", OleDbType.Integer)
                {
                    Value = prize.ParticipantLimit
                }
                    , new OleDbParameter("@AppendixDiscription", OleDbType.VarWChar)
                {
                    Value = prize.AppendixDiscription
                }
                    , new OleDbParameter("@PrizeID", OleDbType.Integer)
                {
                    Value = prize.PrizeID
                }
                    );
            }

            //奖项数量
            SetPrizeLevel(prize, LstPrizeLimitNum, conn, tran);

            SetOrdinal(prize, conn, tran);

            return(prize.PrizeID.Value);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 创建活动
        /// </summary>
        /// <param name="activity"></param>
        /// <returns>活动编号</returns>
        public static int CreateActivity(Dal.Models.Activity activity, OleDbConnection conn, OleDbTransaction trans = null)
        {
            if (string.IsNullOrEmpty(activity.ActivityTypeCode))
            {
                throw new Exception("参数错误");
            }

            if (GetActivity(activity.ActivityTypeCode, conn, trans) != null)
            {
                throw new Exception("当前活动类型已经有激活的活动,不能重复创建");
            }

            if (activity.CreateTime == null || activity.LastUpdateTime == null)
            {
                activity.CreateTime = DateTime.Now;
                activity.LastUpdateTime = activity.CreateTime;
            }

            if (string.IsNullOrEmpty(activity.ActivityName))
            {
                activity.ActivityName = activity.CreateTime.Value.ToString("yyyy届")
                    + SysConstant.GetConstant(activity.ActivityTypeCode, conn, trans).ConstantValue
                    + "评选活动";
            }

            activity.ActivityStatus = "1101";

            StringBuilder sbSql = new StringBuilder();
            int? iResult = 0;

            sbSql.Append(" INSERT INTO Activity ( ");
            sbSql.Append("        ActivityName ");
            sbSql.Append("       ,ActivityTypeCode ");
            sbSql.Append("       ,ActivityStatus ");
            sbSql.Append("       ,CreateTime ");
            sbSql.Append("       ,LastUpdateTime ");
            sbSql.Append(" )VALUES(?, ?, '1101', GETDATE(), GETDATE()) ");
            iResult = Dal.OleDbHlper.ExecuteNonQuery(sbSql.ToString(), conn, CommandType.Text, trans
                , new OleDbParameter("@ActivityName", OleDbType.VarWChar) { Value = activity.ActivityName }
                , new OleDbParameter("@ActivityTypeCode", OleDbType.VarWChar) { Value = activity.ActivityTypeCode });

            if (iResult != 1)
            {
                throw new Exception("创建失败");
            }
            else
            {
                activity.ActivityID = GetActivity(activity.ActivityTypeCode, conn, trans).ActivityID;
            }

            // 创建活动的同时,创建基础专业
            sbSql.Clear();
            sbSql.Append(" INSERT INTO Specialty ( ");
            sbSql.Append("   ActivityID ,SpecialtyCode ,SpecialtyName ,SpecialtyLevel ,SpecialtyIcon ");
            sbSql.Append(" , TemplateCode, IsShareQuota, IsInheritSchedule, IsInheritTemplet, IsAllowUpdate ");
            sbSql.Append(" , ParentID, CreateTime, LastUpdateTime ");
            sbSql.Append(" , IsSendReceivePost, IsSendUpdatePost, IsSendDeletePost, IsInheritAppendix,IsInheritAtlas ");
            sbSql.Append(" , Ordinal, TotalOrdinal) ");
            sbSql.Append(" SELECT ? , SubString(ConstantCode, 3, 2) + '0000', ConstantValue, '一级', CorrelationValue ");
            sbSql.Append(" , '02' + SubString(ConstantCode, 3, 2), 0, 1, 1, 0 ");
            sbSql.Append(" , NULL, GETDATE(), GETDATE() ");
            sbSql.Append(" , 0, 0, 0, 1, 1 ");
            sbSql.Append(" , SubString(ConstantCode,3,2) , SubString(ConstantCode,3,2) ");
            sbSql.Append(" FROM SysConstant where ConstantType = '17' ");
            Dal.OleDbHlper.ExecuteNonQuery(sbSql.ToString(), conn, CommandType.Text, trans
                 , new OleDbParameter("@ActivityID", OleDbType.Integer) { Value = activity.ActivityID });

            return activity.ActivityID.Value;
        }