Example #1
0
        public int Insert(LotteryAwardInfo awardInfo)
        {
            var awardId = 0;

            IDataParameter[] parms = null;

            var sqlInsert = BaiRongDataProvider.TableStructureDao.GetInsertSqlString(awardInfo.ToNameValueCollection(), ConnectionString, TableName, out parms);

            using (var conn = GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        awardId = ExecuteNonQueryAndReturnId(trans, sqlInsert, parms);

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        throw;
                    }
                }
            }

            return(awardId);
        }
Example #2
0
        public int Insert(LotteryAwardInfo awardInfo)
        {
            var awardID = 0;

            IDataParameter[] parms = null;

            var SQL_INSERT = BaiRongDataProvider.TableStructureDao.GetInsertSqlString(awardInfo.ToNameValueCollection(), ConnectionString, TABLE_NAME, out parms);

            using (var conn = GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        ExecuteNonQuery(trans, SQL_INSERT, parms);

                        awardID = BaiRongDataProvider.DatabaseDao.GetSequence(trans, TABLE_NAME);

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        throw;
                    }
                }
            }

            return(awardID);
        }
Example #3
0
        public void Update(LotteryAwardInfo awardInfo)
        {
            IDataParameter[] parms = null;
            var SQL_UPDATE         = BaiRongDataProvider.TableStructureDao.GetUpdateSqlString(awardInfo.ToNameValueCollection(), ConnectionString, TABLE_NAME, out parms);


            ExecuteNonQuery(SQL_UPDATE, parms);
        }
Example #4
0
        public void ExportLotteryCSV(string filePath, List <LotteryWinnerInfo> winnerInfoList)
        {
            var head = new List <string>();

            head.Add("序号");
            head.Add("奖项");
            head.Add("姓名");
            head.Add("手机");
            head.Add("邮箱");
            head.Add("地址");
            head.Add("状态");
            head.Add("中奖时间");
            head.Add("兑奖码");
            head.Add("兑奖时间");

            var rows = new List <List <string> >();

            var index = 1;

            foreach (var winnerInfo in winnerInfoList)
            {
                LotteryAwardInfo awardInfo = null;
                if (awardInfoMap.ContainsKey(winnerInfo.AwardID))
                {
                    awardInfo = awardInfoMap[winnerInfo.AwardID];
                }
                else
                {
                    awardInfo = DataProviderWX.LotteryAwardDAO.GetAwardInfo(winnerInfo.AwardID);
                    awardInfoMap.Add(winnerInfo.AwardID, awardInfo);
                }

                var award = string.Empty;
                if (awardInfo != null)
                {
                    award = awardInfo.AwardName + ":" + awardInfo.Title;
                }

                var row = new List <string>();

                row.Add((index++).ToString());
                row.Add(award);
                row.Add(winnerInfo.RealName);
                row.Add(winnerInfo.Mobile);
                row.Add(winnerInfo.Email);
                row.Add(winnerInfo.Address);
                row.Add(EWinStatusUtils.GetText(EWinStatusUtils.GetEnumType(winnerInfo.Status)));
                row.Add(DateUtils.GetDateAndTimeString(winnerInfo.AddDate));
                row.Add(winnerInfo.CashSN);
                row.Add(DateUtils.GetDateAndTimeString(winnerInfo.CashDate));

                rows.Add(row);
            }

            CSVUtils.Export(filePath, head, rows);
        }
Example #5
0
        private static LotteryAwardInfo GetAwardInfo(List <LotteryAwardInfo> awardInfoList, int awardId)
        {
            LotteryAwardInfo awardInfo = null;

            foreach (var lotteryAwardInfo in awardInfoList)
            {
                if (lotteryAwardInfo.Id == awardId)
                {
                    awardInfo = lotteryAwardInfo;
                    break;
                }
            }
            return(awardInfo);
        }
Example #6
0
        void rptContents_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var winnerInfo = new LotteryWinnerInfo(e.Item.DataItem);

                var ltlItemIndex = e.Item.FindControl("ltlItemIndex") as Literal;
                var ltlAward     = e.Item.FindControl("ltlAward") as Literal;
                var ltlRealName  = e.Item.FindControl("ltlRealName") as Literal;
                var ltlMobile    = e.Item.FindControl("ltlMobile") as Literal;
                var ltlEmail     = e.Item.FindControl("ltlEmail") as Literal;
                var ltlAddress   = e.Item.FindControl("ltlAddress") as Literal;
                var ltlStatus    = e.Item.FindControl("ltlStatus") as Literal;
                var ltlAddDate   = e.Item.FindControl("ltlAddDate") as Literal;
                var ltlCashSN    = e.Item.FindControl("ltlCashSN") as Literal;
                var ltlCashDate  = e.Item.FindControl("ltlCashDate") as Literal;

                ltlItemIndex.Text = (e.Item.ItemIndex + 1).ToString();

                LotteryAwardInfo awardInfo = null;
                if (awardInfoMap.ContainsKey(winnerInfo.AwardID))
                {
                    awardInfo = awardInfoMap[winnerInfo.AwardID];
                }
                else
                {
                    awardInfo = DataProviderWX.LotteryAwardDAO.GetAwardInfo(winnerInfo.AwardID);
                    awardInfoMap.Add(winnerInfo.AwardID, awardInfo);
                }
                if (awardInfo != null)
                {
                    ltlAward.Text =
                        $@"<a href=""{GetRedirectUrl(PublishmentSystemID,
                            ELotteryTypeUtils.GetEnumType(winnerInfo.LotteryType), winnerInfo.LotteryID, winnerInfo.AwardID,
                            returnUrl)}"">{awardInfo.AwardName + ":" + awardInfo.Title}</a>";
                }

                ltlRealName.Text = winnerInfo.RealName;
                ltlMobile.Text   = winnerInfo.Mobile;
                ltlEmail.Text    = winnerInfo.Email;
                ltlAddress.Text  = winnerInfo.Address;
                ltlStatus.Text   = EWinStatusUtils.GetText(EWinStatusUtils.GetEnumType(winnerInfo.Status));
                ltlAddDate.Text  = DateUtils.GetDateAndTimeString(winnerInfo.AddDate);
                ltlCashSN.Text   = winnerInfo.CashSN;
                ltlCashDate.Text = DateUtils.GetDateAndTimeString(winnerInfo.CashDate);
            }
        }
Example #7
0
        public LotteryAwardInfo GetAwardInfo(int awardID)
        {
            LotteryAwardInfo awardInfo = null;

            string SQL_WHERE  = $"WHERE ID = {awardID}";
            var    SQL_SELECT = BaiRongDataProvider.TableStructureDao.GetSelectSqlString(ConnectionString, TABLE_NAME, 0, SqlUtils.Asterisk, SQL_WHERE, null);

            using (var rdr = ExecuteReader(SQL_SELECT))
            {
                if (rdr.Read())
                {
                    awardInfo = new LotteryAwardInfo(rdr);
                }
                rdr.Close();
            }

            return(awardInfo);
        }
Example #8
0
        public LotteryAwardInfo GetAwardInfo(int awardId)
        {
            LotteryAwardInfo awardInfo = null;

            string sqlWhere  = $"WHERE ID = {awardId}";
            var    sqlSelect = BaiRongDataProvider.TableStructureDao.GetSelectSqlString(ConnectionString, TableName, 0, SqlUtils.Asterisk, sqlWhere, null);

            using (var rdr = ExecuteReader(sqlSelect))
            {
                if (rdr.Read())
                {
                    awardInfo = new LotteryAwardInfo(rdr);
                }
                rdr.Close();
            }

            return(awardInfo);
        }
Example #9
0
        public List <LotteryAwardInfo> GetLotteryAwardInfoList(int publishmentSystemID)
        {
            var list = new List <LotteryAwardInfo>();

            var builder = new StringBuilder(
                $"WHERE {LotteryAwardAttribute.PublishmentSystemID} = {publishmentSystemID}");
            var SQL_SELECT = BaiRongDataProvider.TableStructureDao.GetSelectSqlString(ConnectionString, TABLE_NAME, 0, SqlUtils.Asterisk, builder.ToString(), "ORDER BY ID");

            using (var rdr = ExecuteReader(SQL_SELECT))
            {
                while (rdr.Read())
                {
                    var awardInfo = new LotteryAwardInfo(rdr);
                    list.Add(awardInfo);
                }
                rdr.Close();
            }

            return(list);
        }
Example #10
0
        public List <LotteryAwardInfo> GetLotteryAwardInfoList(int publishmentSystemId, int lotteryId)
        {
            var list = new List <LotteryAwardInfo>();

            var builder = new StringBuilder(
                $"WHERE {LotteryAwardAttribute.PublishmentSystemId} = {publishmentSystemId} AND {LotteryAwardAttribute.LotteryId} = {lotteryId}");
            var sqlSelect = BaiRongDataProvider.TableStructureDao.GetSelectSqlString(ConnectionString, TableName, 0, SqlUtils.Asterisk, builder.ToString(), "ORDER BY ID");

            using (var rdr = ExecuteReader(sqlSelect))
            {
                while (rdr.Read())
                {
                    var awardInfo = new LotteryAwardInfo(rdr);
                    list.Add(awardInfo);
                }
                rdr.Close();
            }

            return(list);
        }
Example #11
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (Page.IsPostBack && Page.IsValid)
            {
                var selectedStep = 0;
                if (phStep1.Visible)
                {
                    selectedStep = 1;
                }
                else if (phStep2.Visible)
                {
                    selectedStep = 2;
                }
                else if (phStep3.Visible)
                {
                    selectedStep = 3;
                }
                else if (phStep4.Visible)
                {
                    selectedStep = 4;
                }
                else if (phStep5.Visible)
                {
                    selectedStep = 5;
                }

                phStep1.Visible = phStep2.Visible = phStep3.Visible = phStep4.Visible = phStep5.Visible = false;

                if (selectedStep == 1)
                {
                    var isConflict       = false;
                    var conflictKeywords = string.Empty;
                    if (!string.IsNullOrEmpty(tbKeywords.Text))
                    {
                        if (lotteryID > 0)
                        {
                            var lotteryInfo = DataProviderWX.LotteryDAO.GetLotteryInfo(lotteryID);
                            isConflict = KeywordManager.IsKeywordUpdateConflict(PublishmentSystemID, lotteryInfo.KeywordID, PageUtils.FilterXSS(tbKeywords.Text), out conflictKeywords);
                        }
                        else
                        {
                            isConflict = KeywordManager.IsKeywordInsertConflict(PublishmentSystemID, PageUtils.FilterXSS(tbKeywords.Text), out conflictKeywords);
                        }
                    }

                    if (isConflict)
                    {
                        FailMessage($"触发关键词“{conflictKeywords}”已存在,请设置其他关键词");
                        phStep1.Visible = true;
                    }
                    else
                    {
                        phStep2.Visible = true;
                    }
                }
                else if (selectedStep == 2)
                {
                    phStep3.Visible = true;
                }
                else if (selectedStep == 3)
                {
                    var isItemReady = true;

                    var awardMaxCount      = TranslateUtils.ToInt(tbAwardMaxCount.Text);
                    var awardMaxDailyCount = TranslateUtils.ToInt(tbAwardMaxDailyCount.Text);
                    if (awardMaxDailyCount > awardMaxCount)
                    {
                        FailMessage("摇摇乐保存失败,每人每天最多允许抽奖次数必须小于每人最多抽奖次数");
                        isItemReady = false;
                    }

                    if (isItemReady)
                    {
                        var itemCount = TranslateUtils.ToInt(Request.Form["itemCount"]);

                        if (itemCount < 1)
                        {
                            FailMessage("摇摇乐保存失败,至少需要设置一个奖项");
                            isItemReady = false;
                        }
                        else
                        {
                            var itemIDList      = TranslateUtils.StringCollectionToIntList(Request.Form["itemID"]);
                            var awardNameList   = TranslateUtils.StringCollectionToStringList(Request.Form["itemAwardName"]);
                            var titleList       = TranslateUtils.StringCollectionToStringList(Request.Form["itemTitle"]);
                            var totalNumList    = TranslateUtils.StringCollectionToIntList(Request.Form["itemTotalNum"]);
                            var probabilityList = TranslateUtils.StringCollectionToDecimalList(Request.Form["itemProbability"]);

                            decimal probabilityAll = 0;

                            var awardInfoList = new List <LotteryAwardInfo>();
                            for (var i = 0; i < itemCount; i++)
                            {
                                var awardInfo = new LotteryAwardInfo {
                                    ID = itemIDList[i], PublishmentSystemID = PublishmentSystemID, LotteryID = lotteryID, AwardName = awardNameList[i], Title = titleList[i], TotalNum = totalNumList[i], Probability = probabilityList[i]
                                };

                                if (string.IsNullOrEmpty(awardInfo.AwardName))
                                {
                                    FailMessage("保存失败,奖项名称为必填项");
                                    isItemReady = false;
                                }
                                if (string.IsNullOrEmpty(awardInfo.Title))
                                {
                                    FailMessage("保存失败,奖品名为必填项");
                                    isItemReady = false;
                                }
                                if (awardInfo.Probability < 0 || awardInfo.Probability > 100)
                                {
                                    FailMessage("保存失败,各项中奖概率总和不能超过100%");
                                    isItemReady = false;
                                }

                                probabilityAll += awardInfo.Probability;

                                awardInfoList.Add(awardInfo);
                            }

                            if (probabilityAll <= 0 || probabilityAll > 100)
                            {
                                FailMessage("摇摇乐保存失败,获奖概率之和必须在1%到100%之间");
                                isItemReady = false;
                            }

                            if (isItemReady)
                            {
                                DataProviderWX.LotteryAwardDAO.DeleteAllNotInIDList(PublishmentSystemID, lotteryID, itemIDList);

                                foreach (var awardInfo in awardInfoList)
                                {
                                    var newAwardInfo = DataProviderWX.LotteryAwardDAO.GetAwardInfo(awardInfo.ID);
                                    if (awardInfo.ID > 0)
                                    {
                                        var wonNum = DataProviderWX.LotteryWinnerDAO.GetTotalNum(awardInfo.ID);
                                        if (awardInfo.TotalNum < wonNum)
                                        {
                                            awardInfo.TotalNum = wonNum;
                                        }
                                        awardInfo.WonNum = newAwardInfo.WonNum;
                                        DataProviderWX.LotteryAwardDAO.Update(awardInfo);
                                    }
                                    else
                                    {
                                        DataProviderWX.LotteryAwardDAO.Insert(awardInfo);
                                    }
                                }
                            }
                        }
                    }

                    if (isItemReady)
                    {
                        phStep4.Visible = true;
                    }
                    else
                    {
                        phStep3.Visible = true;
                    }
                }
                else if (selectedStep == 4)
                {
                    phStep5.Visible = true;
                    btnSubmit.Text  = "确 认";
                }
                else if (selectedStep == 5)
                {
                    var lotteryInfo = new LotteryInfo();
                    if (lotteryID > 0)
                    {
                        lotteryInfo = DataProviderWX.LotteryDAO.GetLotteryInfo(lotteryID);
                    }
                    lotteryInfo.PublishmentSystemID = PublishmentSystemID;
                    lotteryInfo.LotteryType         = ELotteryTypeUtils.GetValue(ELotteryType.YaoYao);

                    lotteryInfo.KeywordID  = DataProviderWX.KeywordDAO.GetKeywordID(PublishmentSystemID, lotteryID > 0, tbKeywords.Text, EKeywordType.YaoYao, lotteryInfo.KeywordID);
                    lotteryInfo.IsDisabled = !cbIsEnabled.Checked;

                    lotteryInfo.StartDate       = dtbStartDate.DateTime;
                    lotteryInfo.EndDate         = dtbEndDate.DateTime;
                    lotteryInfo.Title           = PageUtils.FilterXSS(tbTitle.Text);
                    lotteryInfo.ImageUrl        = imageUrl.Value;;
                    lotteryInfo.Summary         = tbSummary.Text;
                    lotteryInfo.ContentImageUrl = contentImageUrl.Value;
                    lotteryInfo.ContentUsage    = tbContentUsage.Text;

                    lotteryInfo.AwardUsage         = tbAwardUsage.Text;
                    lotteryInfo.IsAwardTotalNum    = cbIsAwardTotalNum.Checked;
                    lotteryInfo.AwardMaxCount      = TranslateUtils.ToInt(tbAwardMaxCount.Text);
                    lotteryInfo.AwardMaxDailyCount = TranslateUtils.ToInt(tbAwardMaxDailyCount.Text);
                    lotteryInfo.AwardCode          = tbAwardCode.Text;
                    lotteryInfo.AwardImageUrl      = awardImageUrl.Value;

                    lotteryInfo.IsFormRealName    = cbIsFormRealName.Checked;
                    lotteryInfo.FormRealNameTitle = tbFormRealNameTitle.Text;
                    lotteryInfo.IsFormMobile      = cbIsFormMobile.Checked;
                    lotteryInfo.FormMobileTitle   = tbFormMobileTitle.Text;
                    lotteryInfo.IsFormEmail       = cbIsFormEmail.Checked;
                    lotteryInfo.FormEmailTitle    = tbFormEmailTitle.Text;
                    lotteryInfo.IsFormAddress     = cbIsFormAddress.Checked;
                    lotteryInfo.FormAddressTitle  = tbFormAddressTitle.Text;

                    lotteryInfo.EndTitle    = tbEndTitle.Text;
                    lotteryInfo.EndImageUrl = endImageUrl.Value;
                    lotteryInfo.EndSummary  = tbEndSummary.Text;

                    try
                    {
                        if (lotteryID > 0)
                        {
                            DataProviderWX.LotteryDAO.Update(lotteryInfo);

                            LogUtils.AddLog(BaiRongDataProvider.AdministratorDao.UserName, "修改摇摇乐",
                                            $"摇摇乐:{tbTitle.Text}");
                            SuccessMessage("修改摇摇乐成功!");
                        }
                        else
                        {
                            lotteryID = DataProviderWX.LotteryDAO.Insert(lotteryInfo);

                            DataProviderWX.LotteryAwardDAO.UpdateLotteryID(PublishmentSystemID, lotteryID);

                            LogUtils.AddLog(BaiRongDataProvider.AdministratorDao.UserName, "添加摇摇乐",
                                            $"摇摇乐:{tbTitle.Text}");
                            SuccessMessage("添加摇摇乐成功!");
                        }

                        var redirectUrl = BackgroundLottery.GetRedirectUrl(PublishmentSystemID, ELotteryType.YaoYao);
                        AddWaitAndRedirectScript(redirectUrl);
                    }
                    catch (Exception ex)
                    {
                        FailMessage(ex, "摇摇乐设置失败!");
                    }
                }
            }
        }
Example #12
0
        public static bool Lottery(LotteryInfo lotteryInfo, List <LotteryAwardInfo> awardInfoList, string cookieSN, string wxOpenID, out LotteryAwardInfo awardInfo, out LotteryWinnerInfo winnerInfo, string userName, out string errorMessage)
        {
            errorMessage = string.Empty;

            awardInfo  = null;
            winnerInfo = DataProviderWx.LotteryWinnerDao.GetWinnerInfo(lotteryInfo.PublishmentSystemId, lotteryInfo.Id, cookieSN, wxOpenID, userName);
            if (winnerInfo != null)
            {
                awardInfo = GetAwardInfo(awardInfoList, winnerInfo.AwardId);
            }
            else
            {
                var isMaxCount      = false;
                var isMaxDailyCount = false;

                DataProviderWx.LotteryLogDao.AddCount(lotteryInfo.PublishmentSystemId, lotteryInfo.Id, cookieSN, wxOpenID, userName, lotteryInfo.AwardMaxCount, lotteryInfo.AwardMaxDailyCount, out isMaxCount, out isMaxDailyCount);

                if (isMaxCount)
                {
                    errorMessage = $"对不起,每人最多允许抽奖{lotteryInfo.AwardMaxCount}次";
                    return(false);
                }
                else if (isMaxDailyCount)
                {
                    errorMessage = $"对不起,每人每天最多允许抽奖{lotteryInfo.AwardMaxDailyCount}次";
                    return(false);
                }
                else
                {
                    if (awardInfoList != null && awardInfoList.Count > 0)
                    {
                        var idWithProbabilityDictionary = new Dictionary <int, decimal>();
                        foreach (var lotteryAwardInfo in awardInfoList)
                        {
                            idWithProbabilityDictionary.Add(lotteryAwardInfo.Id, lotteryAwardInfo.Probability);
                        }

                        var awardID = WeiXinManager.Lottery(idWithProbabilityDictionary);
                        if (awardID > 0)
                        {
                            var lotteryAwardInfo = GetAwardInfo(awardInfoList, awardID);

                            if (lotteryAwardInfo != null && lotteryAwardInfo.TotalNum > 0)
                            {
                                var wonNum = DataProviderWx.LotteryWinnerDao.GetTotalNum(awardID);
                                if (lotteryAwardInfo.TotalNum > wonNum)
                                {
                                    awardInfo  = lotteryAwardInfo;
                                    winnerInfo = new LotteryWinnerInfo {
                                        PublishmentSystemId = lotteryInfo.PublishmentSystemId, LotteryType = lotteryInfo.LotteryType, LotteryId = lotteryInfo.Id, AwardId = awardID, Status = EWinStatusUtils.GetValue(EWinStatus.Won), CookieSn = cookieSN, WxOpenId = wxOpenID, UserName = userName, AddDate = DateTime.Now
                                    };
                                    winnerInfo.Id = DataProviderWx.LotteryWinnerDao.Insert(winnerInfo);

                                    DataProviderWx.LotteryAwardDao.UpdateWonNum(awardID);

                                    DataProviderWx.LotteryDao.AddUserCount(winnerInfo.LotteryId);
                                }
                            }
                        }
                    }
                }
            }

            return(true);
        }