Beispiel #1
0
        private void Bind()
        {
            Ernie bll = new Ernie();

            if (!Id.Equals(Guid.Empty))
            {
                Page.Title = "编辑摇奖设定";

                var model = bll.GetModel(Id);
                if (model == null)
                {
                    return;
                }

                hErnieId.Value           = model.Id.ToString();
                txtStartTime.Value       = model.StartTime.ToString("yyyy-MM-dd HH:mm");
                txtEndTime.Value         = model.EndTime.ToString("yyyy-MM-dd HH:mm");
                txtUserBetMaxCount.Value = model.UserBetMaxCount.ToString();
                var li = rdIsDisable.Items.FindByValue(model.IsDisable.ToString().ToLower());
                if (li != null)
                {
                    li.Selected = true;
                }
            }
            else
            {
                if (bll.IsExistLatest())
                {
                    abtnSaveErnie.Visible = false;
                    lbMsg.InnerText       = "系统提示:已存在摇奖设置且未结束,无法再添加摇奖设置!";
                }
            }
        }
Beispiel #2
0
        private void SaveErnie(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            Guid Id = Guid.Empty;

            if (!string.IsNullOrWhiteSpace(context.Request.Form["Id"]))
            {
                Guid.TryParse(context.Request.Form["Id"], out Id);
            }

            if (string.IsNullOrWhiteSpace(context.Request.Form["startTime"]))
            {
                context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Params_InvalidError + "\"}");
                return;
            }
            DateTime startTime = DateTime.MinValue;

            if (!string.IsNullOrWhiteSpace(context.Request.Form["startTime"]))
            {
                DateTime.TryParse(context.Request.Form["startTime"], out startTime);
            }
            if (startTime == DateTime.MinValue)
            {
                context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Params_InvalidError + "\"}");
                return;
            }
            DateTime endTime = DateTime.MinValue;

            if (!string.IsNullOrWhiteSpace(context.Request.Form["endTime"]))
            {
                DateTime.TryParse(context.Request.Form["endTime"], out endTime);
            }
            if (endTime == DateTime.MinValue)
            {
                context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Params_InvalidError + "\"}");
                return;
            }

            if (startTime >= endTime)
            {
                context.Response.Write("{\"success\": false,\"message\": \"结束时间必须大于开始时间,请正确操作\"}");
                return;
            }

            int userBetMaxCount = 0;

            if (!string.IsNullOrWhiteSpace(context.Request.Form["userBetMaxCount"]))
            {
                int.TryParse(context.Request.Form["userBetMaxCount"], out userBetMaxCount);
            }

            bool isDisable = false;

            bool.TryParse(context.Request.Form["isDisable"], out isDisable);

            ErnieInfo model = new ErnieInfo();

            model.Id = Id;
            model.LastUpdatedDate = DateTime.Now;
            model.StartTime       = startTime;
            model.UserBetMaxCount = userBetMaxCount;
            model.EndTime         = endTime;
            model.IsDisable       = isDisable;

            Ernie bll    = new Ernie();
            int   effect = -1;

            if (!Id.Equals(Guid.Empty))
            {
                var oldModel = bll.GetModel(Id);
                if (oldModel == null)
                {
                    throw new ArgumentException(MessageContent.Submit_Data_NotExists);
                }
                model.IsOver = oldModel.IsOver;
                effect       = bll.Update(model);
            }
            else
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    if (bll.IsExistLatest())
                    {
                        throw new ArgumentException("已存在摇奖设置且未结束,无法再添加摇奖设置!");
                    }
                    else
                    {
                        model.IsOver = false;
                        Id           = Guid.NewGuid();
                        model.Id     = Id;
                        effect       = bll.Insert(model);
                    }

                    scope.Complete();
                }
            }

            context.Response.Write("{\"success\": true,\"message\": \"" + Id + "\"}");
        }