Пример #1
0
 /// <summary>
 /// 是否是日期
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public static bool IsDate(this string data)
 {
     return(ValidateHelper.IsDate(data));
 }
Пример #2
0
        /// <summary>
        /// 注册
        /// </summary>
        public ActionResult Register()
        {
            string returnUrl = WebHelper.GetQueryString("returnUrl");

            if (returnUrl.Length == 0)
            {
                returnUrl = Url.Action("index", "home");
            }

            if (WorkContext.MallConfig.RegType.Length == 0)
            {
                return(PromptView(returnUrl, "商城目前已经关闭注册功能!"));
            }
            if (WorkContext.Uid > 0)
            {
                return(PromptView(returnUrl, "你已经是本商城的注册用户,无需再注册!"));
            }
            if (WorkContext.MallConfig.RegTimeSpan > 0)
            {
                DateTime registerTime = Users.GetRegisterTimeByRegisterIP(WorkContext.IP);
                if ((DateTime.Now - registerTime).Minutes <= WorkContext.MallConfig.RegTimeSpan)
                {
                    return(PromptView(returnUrl, "你注册太频繁,请间隔一定时间后再注册!"));
                }
            }

            //get请求
            if (WebHelper.IsGet())
            {
                RegisterModel model = new RegisterModel();

                model.ReturnUrl    = returnUrl;
                model.ShadowName   = WorkContext.MallConfig.ShadowName;
                model.IsVerifyCode = CommonHelper.IsInArray(WorkContext.PageKey, WorkContext.MallConfig.VerifyPages);

                return(View(model));
            }

            //ajax请求
            string accountName = WebHelper.GetFormString(WorkContext.MallConfig.ShadowName).Trim().ToLower();
            string password    = WebHelper.GetFormString("password");
            string confirmPwd  = WebHelper.GetFormString("confirmPwd");
            string verifyCode  = WebHelper.GetFormString("verifyCode");

            StringBuilder errorList = new StringBuilder("[");

            #region 验证

            //账号验证
            if (string.IsNullOrWhiteSpace(accountName))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名不能为空", "}");
            }
            else if (accountName.Length < 4 || accountName.Length > 50)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名必须大于3且不大于50个字符", "}");
            }
            else if (accountName.Contains(" "))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名中不允许包含空格", "}");
            }
            else if (accountName.Contains(":"))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名中不允许包含冒号", "}");
            }
            else if (accountName.Contains("<"))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名中不允许包含'<'符号", "}");
            }
            else if (accountName.Contains(">"))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名中不允许包含'>'符号", "}");
            }
            else if ((!SecureHelper.IsSafeSqlString(accountName, false)))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名不符合系统要求", "}");
            }
            else if (CommonHelper.IsInArray(accountName, WorkContext.MallConfig.ReservedName, "\n"))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "此账户名不允许被注册", "}");
            }
            else if (FilterWords.IsContainWords(accountName))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名包含禁止单词", "}");
            }

            //密码验证
            if (string.IsNullOrWhiteSpace(password))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "password", "密码不能为空", "}");
            }
            else if (password.Length < 4 || password.Length > 32)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "password", "密码必须大于3且不大于32个字符", "}");
            }
            else if (password != confirmPwd)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "password", "两次输入的密码不一样", "}");
            }

            //验证码验证
            if (CommonHelper.IsInArray(WorkContext.PageKey, WorkContext.MallConfig.VerifyPages))
            {
                if (string.IsNullOrWhiteSpace(verifyCode))
                {
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "verifyCode", "验证码不能为空", "}");
                }
                else if (verifyCode.ToLower() != Sessions.GetValueString(WorkContext.Sid, "verifyCode"))
                {
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "verifyCode", "验证码不正确", "}");
                }
            }

            //其它验证
            int gender = WebHelper.GetFormInt("gender");
            if (gender < 0 || gender > 2)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "gender", "请选择正确的性别", "}");
            }

            string nickName = WebHelper.GetFormString("nickName");
            if (nickName.Length > 10)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "nickName", "昵称的长度不能大于10", "}");
            }
            else if (FilterWords.IsContainWords(nickName))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "nickName", "昵称中包含禁止单词", "}");
            }

            if (WebHelper.GetFormString("realName").Length > 5)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "realName", "真实姓名的长度不能大于5", "}");
            }

            string bday = WebHelper.GetFormString("bday");
            if (bday.Length == 0)
            {
                string bdayY = WebHelper.GetFormString("bdayY");
                string bdayM = WebHelper.GetFormString("bdayM");
                string bdayD = WebHelper.GetFormString("bdayD");
                bday = string.Format("{0}-{1}-{2}", bdayY, bdayM, bdayD);
            }
            if (bday.Length > 0 && bday != "--" && !ValidateHelper.IsDate(bday))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "bday", "请选择正确的日期", "}");
            }

            string idCard = WebHelper.GetFormString("idCard");
            if (idCard.Length > 0 && !ValidateHelper.IsIdCard(idCard))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "idCard", "请输入正确的身份证号", "}");
            }

            int regionId = WebHelper.GetFormInt("regionId");
            if (regionId > 0)
            {
                if (Regions.GetRegionById(regionId) == null)
                {
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "regionId", "请选择正确的地址", "}");
                }
                if (WebHelper.GetFormString("address").Length > 75)
                {
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "address", "详细地址的长度不能大于75", "}");
                }
            }

            if (WebHelper.GetFormString("bio").Length > 150)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "bio", "简介的长度不能大于150", "}");
            }

            //当以上验证都通过时
            UserInfo userInfo = null;
            if (errorList.Length == 1)
            {
                if (WorkContext.MallConfig.RegType.Contains("2") && ValidateHelper.IsEmail(accountName))//验证邮箱
                {
                    string emailProvider = CommonHelper.GetEmailProvider(accountName);
                    if (WorkContext.MallConfig.AllowEmailProvider.Length != 0 && (!CommonHelper.IsInArray(emailProvider, WorkContext.MallConfig.AllowEmailProvider, "\n")))
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "不能使用'" + emailProvider + "'类型的邮箱", "}");
                    }
                    else if (CommonHelper.IsInArray(emailProvider, WorkContext.MallConfig.BanEmailProvider, "\n"))
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "不能使用'" + emailProvider + "'类型的邮箱", "}");
                    }
                    else if (Users.IsExistEmail(accountName))
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "邮箱已经存在", "}");
                    }
                    else
                    {
                        userInfo          = new UserInfo();
                        userInfo.UserName = string.Empty;
                        userInfo.Email    = accountName;
                        userInfo.Mobile   = string.Empty;
                    }
                }
                else if (WorkContext.MallConfig.RegType.Contains("3") && ValidateHelper.IsMobile(accountName))//验证手机
                {
                    if (Users.IsExistMobile(accountName))
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "手机号已经存在", "}");
                    }
                    else
                    {
                        userInfo          = new UserInfo();
                        userInfo.UserName = string.Empty;
                        userInfo.Email    = string.Empty;
                        userInfo.Mobile   = accountName;
                    }
                }
                else if (WorkContext.MallConfig.RegType.Contains("1"))//验证用户名
                {
                    if (accountName.Length > 20)
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "用户名长度不能超过20个字符", "}");
                    }
                    else if (BrnMall.Services.Users.IsExistUserName(accountName))
                    {
                        errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "用户名已经存在", "}");
                    }
                    else
                    {
                        userInfo          = new UserInfo();
                        userInfo.UserName = accountName;
                        userInfo.Email    = string.Empty;
                        userInfo.Mobile   = string.Empty;
                    }
                }
            }

            #endregion

            if (errorList.Length > 1)//验证失败
            {
                return(AjaxResult("error", errorList.Remove(errorList.Length - 1, 1).Append("]").ToString(), true));
            }
            else//验证成功
            {
                #region 绑定用户信息

                userInfo.Salt     = Randoms.CreateRandomValue(6);
                userInfo.Password = Users.CreateUserPassword(password, userInfo.Salt);
                userInfo.UserRid  = UserRanks.GetLowestUserRank().UserRid;
                userInfo.StoreId  = 0;
                userInfo.MallAGid = 1;//非管理员组
                if (nickName.Length > 0)
                {
                    userInfo.NickName = WebHelper.HtmlEncode(nickName);
                }
                else
                {
                    userInfo.NickName = "bma" + Randoms.CreateRandomValue(7);
                }
                userInfo.Avatar       = "";
                userInfo.PayCredits   = 0;
                userInfo.RankCredits  = 0;
                userInfo.VerifyEmail  = 0;
                userInfo.VerifyMobile = 0;

                userInfo.LastVisitIP   = WorkContext.IP;
                userInfo.LastVisitRgId = WorkContext.RegionId;
                userInfo.LastVisitTime = DateTime.Now;
                userInfo.RegisterIP    = WorkContext.IP;
                userInfo.RegisterRgId  = WorkContext.RegionId;
                userInfo.RegisterTime  = DateTime.Now;

                userInfo.Gender   = WebHelper.GetFormInt("gender");
                userInfo.RealName = WebHelper.HtmlEncode(WebHelper.GetFormString("realName"));
                userInfo.Bday     = bday.Length > 0 ? TypeHelper.StringToDateTime(bday) : new DateTime(1900, 1, 1);
                userInfo.IdCard   = WebHelper.GetFormString("idCard");
                userInfo.RegionId = WebHelper.GetFormInt("regionId");
                userInfo.Address  = WebHelper.HtmlEncode(WebHelper.GetFormString("address"));
                userInfo.Bio      = WebHelper.HtmlEncode(WebHelper.GetFormString("bio"));

                #endregion

                //创建用户
                userInfo.Uid = Users.CreateUser(userInfo);

                //添加用户失败
                if (userInfo.Uid < 1)
                {
                    return(AjaxResult("exception", "创建用户失败,请联系管理员"));
                }

                //发放注册积分
                Credits.SendRegisterCredits(ref userInfo, DateTime.Now);
                //更新购物车中用户id
                Carts.UpdateCartUidBySid(userInfo.Uid, WorkContext.Sid);
                //将用户信息写入cookie
                MallUtils.SetUserCookie(userInfo, 0);

                //发送注册欢迎信息
                if (WorkContext.MallConfig.IsWebcomeMsg == 1)
                {
                    if (userInfo.Email.Length > 0)
                    {
                        Emails.SendWebcomeEmail(userInfo.Email);
                    }
                    if (userInfo.Mobile.Length > 0)
                    {
                        SMSes.SendWebcomeSMS(userInfo.Mobile);
                    }
                }

                //同步上下文
                WorkContext.Uid        = userInfo.Uid;
                WorkContext.UserName   = userInfo.UserName;
                WorkContext.UserEmail  = userInfo.Email;
                WorkContext.UserMobile = userInfo.Mobile;
                WorkContext.NickName   = userInfo.NickName;

                return(AjaxResult("success", "注册成功"));
            }
        }
Пример #3
0
        /// <summary>
        /// 编辑用户信息
        /// </summary>
        public ActionResult EditUser()
        {
            string userName = WebHelper.GetFormString("userName");
            string nickName = WebHelper.GetFormString("nickName");
            string avatar   = WebHelper.GetFormString("avatar");
            string realName = WebHelper.GetFormString("realName");
            int    gender   = WebHelper.GetFormInt("gender");
            string idCard   = WebHelper.GetFormString("idCard");
            string bday     = WebHelper.GetFormString("bday");
            int    regionId = WebHelper.GetFormInt("regionId");
            string address  = WebHelper.GetFormString("address");
            string bio      = WebHelper.GetFormString("bio");

            StringBuilder errorList = new StringBuilder("[");

            //验证用户名
            if (WorkContext.UserName.Length == 0 && userName.Length > 0)
            {
                if (userName.Length < 4 || userName.Length > 10)
                {
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "userName", "用户名必须大于3且不大于10个字符", "}");
                }
                else if (userName.Contains(" "))
                {
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "userName", "用户名中不允许包含空格", "}");
                }
                else if (userName.Contains(":"))
                {
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "userName", "用户名中不允许包含冒号", "}");
                }
                else if (userName.Contains("<"))
                {
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "userName", "用户名中不允许包含'<'符号", "}");
                }
                else if (userName.Contains(">"))
                {
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "userName", "用户名中不允许包含'>'符号", "}");
                }
                else if ((!SecureHelper.IsSafeSqlString(userName)))
                {
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "userName", "用户名不符合系统要求", "}");
                }
                else if (CommonHelper.IsInArray(userName, WorkContext.ShopConfig.ReservedName, "\n"))
                {
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "userName", "用户名已经存在", "}");
                }
                else if (FilterWords.IsContainWords(userName))
                {
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "userName", "用户名包含禁止单词", "}");
                }
                else if (Users.IsExistUserName(userName))
                {
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "userName", "用户名已经存在", "}");
                }
            }
            else
            {
                userName = WorkContext.UserName;
            }

            //验证昵称
            if (nickName.Length > 10)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "nickName", "昵称的长度不能大于10", "}");
            }
            else if (FilterWords.IsContainWords(nickName))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "nickName", "昵称中包含禁止单词", "}");
            }

            //验证真实姓名
            if (realName.Length > 5)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "realName", "真实姓名的长度不能大于5", "}");
            }

            //验证性别
            if (gender < 0 || gender > 2)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "gender", "请选择正确的性别", "}");
            }

            //验证身份证号
            if (idCard.Length > 0 && !ValidateHelper.IsIdCard(idCard))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "idCard", "请输入正确的身份证号", "}");
            }

            //验证出生日期
            if (bday.Length == 0)
            {
                string bdayY = WebHelper.GetFormString("bdayY");
                string bdayM = WebHelper.GetFormString("bdayM");
                string bdayD = WebHelper.GetFormString("bdayD");
                bday = string.Format("{0}-{1}-{2}", bdayY, bdayM, bdayD);
            }
            if (bday.Length > 0 && bday != "--" && !ValidateHelper.IsDate(bday))
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "bday", "请选择正确的日期", "}");
            }

            //验证区域
            if (regionId > 0)
            {
                RegionInfo regionInfo = Regions.GetRegionById(regionId);
                if (regionInfo == null || regionInfo.Layer != 3)
                {
                    errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "regionId", "请选择正确的地址", "}");
                }
            }

            //验证详细地址
            if (address.Length > 75)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "address", "详细地址的长度不能大于75", "}");
            }

            //验证简介
            if (bio.Length > 150)
            {
                errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "bio", "简介的长度不能大于150", "}");
            }

            if (errorList.Length == 1)
            {
                if (bday.Length == 0 || bday == "--")
                {
                    bday = "1900-1-1";
                }

                if (regionId < 1)
                {
                    regionId = 0;
                }

                Users.UpdateUser(WorkContext.Uid, userName, WebHelper.HtmlEncode(nickName), WebHelper.HtmlEncode(avatar), gender, WebHelper.HtmlEncode(realName), TypeHelper.StringToDateTime(bday), idCard, regionId, WebHelper.HtmlEncode(address), WebHelper.HtmlEncode(bio));
                if (userName.Length > 0 && nickName.Length > 0 && avatar.Length > 0 && realName.Length > 0 && bday != "1900-1-1" && idCard.Length > 0 && regionId > 0 && address.Length > 0)
                {
                    //Credits.SendCompleteUserInfoCredits(ref WorkContext.PartUserInfo, DateTime.Now);
                }
                return(AjaxResult("success", "信息更新成功"));
            }
            else
            {
                return(AjaxResult("error", errorList.Remove(errorList.Length - 1, 1).Append("]").ToString(), true));
            }
        }
Пример #4
0
        /// <summary>
        ///   Valida las celdas al terminar de ser editadas
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        ///   [vku] 27/Jun/2016 Created
        /// </history>
        private void dgrTourTimes_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            object item = dgrTourTimes.SelectedItem;

            if (e.EditAction == DataGridEditAction.Cancel)
            {
                isCancel = true;
            }
            else
            {
                isCancel = false;
                TextBox changedTextBox = e.EditingElement as TextBox;
                switch (e.Column.Header.ToString())
                {
                    #region Tour Time
                case "Tour Time":
                    if (changedTextBox.Text.ToString() == "")
                    {
                        isCancel = true;
                    }
                    else
                    {
                        if (ValidateHelper.IsValidTimeFormat(changedTextBox.Text.ToString()) || ValidateHelper.IsDate(changedTextBox.Text.ToString()))
                        {
                            string   tt   = changedTextBox.Text.ToString();
                            DateTime time = Convert.ToDateTime(tt);
                            if (ExistTime(time))
                            {
                                isCancel = true;
                                UIHelper.ShowMessage(time.ToString("hh:mm tt") + " already exists", MessageBoxImage.Warning, "IM.Administrator");
                            }
                            else
                            {
                                switch (_enumTourTimes)
                                {
                                case EnumTourTimesSchema.ttsByLeadSourceSalesRoom:
                                    ((TourTime)dgrTourTimes.SelectedItem).ttT = time;
                                    break;

                                case EnumTourTimesSchema.ttsByLeadSourceSalesRoomWeekDay:
                                    ((TourTimeByDay)dgrTourTimes.SelectedItem).ttT = time;
                                    break;

                                case EnumTourTimesSchema.ttsBySalesRoomWeekDay:
                                    ((TourTimeBySalesRoomWeekDay)dgrTourTimes.SelectedItem).ttT = time;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            UIHelper.ShowMessage("Invalid Time", MessageBoxImage.Error, "IM.Administrator");
                        }
                    }
                    break;

                    #endregion
                    #region Pickup Time
                case "Pickup Time":
                    if (changedTextBox.Text.ToString() == "")
                    {
                        isCancel = true;
                    }
                    else
                    {
                        if (ValidateHelper.IsValidTimeFormat(changedTextBox.Text.ToString()) || ValidateHelper.IsDate(changedTextBox.Text.ToString()))
                        {
                            string   pt   = changedTextBox.Text.ToString();
                            DateTime time = Convert.ToDateTime(pt);
                            switch (_enumTourTimes)
                            {
                            case EnumTourTimesSchema.ttsByLeadSourceSalesRoom:
                                ((TourTime)dgrTourTimes.SelectedItem).ttPickUpT = time;
                                break;

                            case EnumTourTimesSchema.ttsByLeadSourceSalesRoomWeekDay:
                                ((TourTimeByDay)dgrTourTimes.SelectedItem).ttPickUpT = time;
                                break;

                            case EnumTourTimesSchema.ttsBySalesRoomWeekDay:
                                ((TourTimeBySalesRoomWeekDay)dgrTourTimes.SelectedItem).ttPickUpT = time;
                                break;
                            }
                        }
                        else
                        {
                            UIHelper.ShowMessage("Invalid Time", MessageBoxImage.Error, "IM.Administrator");
                        }
                    }
                    break;

                    #endregion
                    #region Max Books
                case "Max Books":
                    string maxBooks = changedTextBox.Text.ToString();
                    if (!ValidateHelper.OnlyNumbers(maxBooks))
                    {
                        isCancel = true;
                        UIHelper.ShowMessage("Invalid number", MessageBoxImage.Warning, "IM.Administrator");
                    }
                    else
                    {
                        if (Convert.ToInt32(maxBooks) > 255)
                        {
                            isCancel = true;
                            UIHelper.ShowMessage("can not be greater than 255", MessageBoxImage.Warning, "IM.Administrator");
                        }
                        else if (Convert.ToInt32(maxBooks) < 0)
                        {
                            isCancel = true;
                            UIHelper.ShowMessage("can not be lower than 0", MessageBoxImage.Warning, "IM.Administrator");
                        }
                        else
                        {
                            switch (_enumTourTimes)
                            {
                            case EnumTourTimesSchema.ttsByLeadSourceSalesRoom:
                                if (!e.Row.IsNewItem && Convert.ToByte(maxBooks) == ((TourTime)dgrTourTimes.SelectedItem).ttMaxBooks)
                                {
                                    isCancel = true;
                                }
                                else
                                {
                                    ((TourTime)dgrTourTimes.SelectedItem).ttMaxBooks = Convert.ToByte(maxBooks);
                                }
                                break;

                            case EnumTourTimesSchema.ttsByLeadSourceSalesRoomWeekDay:
                                if (!e.Row.IsNewItem && Convert.ToByte(maxBooks) == ((TourTimeByDay)dgrTourTimes.SelectedItem).ttMaxBooks)
                                {
                                    isCancel = true;
                                }
                                else
                                {
                                    ((TourTimeByDay)dgrTourTimes.SelectedItem).ttMaxBooks = Convert.ToByte(maxBooks);
                                }
                                break;

                            case EnumTourTimesSchema.ttsBySalesRoomWeekDay:
                                if (!e.Row.IsNewItem && Convert.ToByte(maxBooks) == ((TourTimeBySalesRoomWeekDay)dgrTourTimes.SelectedItem).ttMaxBooks)
                                {
                                    isCancel = true;
                                }
                                else
                                {
                                    ((TourTimeBySalesRoomWeekDay)dgrTourTimes.SelectedItem).ttMaxBooks = Convert.ToByte(maxBooks);
                                }
                                break;
                            }
                        }
                    }
                    break;
                    #endregion
                }
            }
        }
Пример #5
0
        /// <summary>
        ///   Valida las fechas ingresadas
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        ///   [vku] 28/Jul/2016 Created
        /// </history>
        private void dgrDates_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            if (e.EditAction == DataGridEditAction.Cancel)
            {
                isCancel = true;
            }
            else
            {
                isCancel       = false;
                changedTextBox = e.EditingElement as TextBox;
                if (changedTextBox.Text.ToString() != "")
                {
                    if (ValidateHelper.IsDate(changedTextBox.Text.ToString()))
                    {
                        string   ssd    = changedTextBox.Text.ToString();
                        DateTime ssDate = Convert.ToDateTime(ssd);
                        if (ssDate.Year == _year.Year)
                        {
                            ValidateRangeDates(ssDate, e.Column.SortMemberPath.ToString(), e.Row.IsNewItem, Convert.ToInt32(e.Row.GetIndex().ToString()));
                            if (!isCancel)
                            {
                                List <RangeDatesTraslape> lstRangeDates     = new List <RangeDatesTraslape>();
                                RangeDatesTraslape        lstRangeTranslape = new RangeDatesTraslape();
                                if (isEdit)
                                {
                                    lstRangeDates     = BRSeasons.GetRangeDatesForValidateTraslapeIsEdit(ssDate, season.ssID);
                                    lstRangeTranslape = lstRangeDates.Cast <RangeDatesTraslape>().FirstOrDefault();
                                }
                                else
                                {
                                    lstRangeDates     = BRSeasons.GetRangeDatesForValidateTraslape(ssDate);
                                    lstRangeTranslape = lstRangeDates.Cast <RangeDatesTraslape>().FirstOrDefault();
                                }
                                if (lstRangeDates.Count > 0)
                                {
                                    isCancel = true;

                                    UIHelper.ShowMessage("The date is in the range of dates " + "(" + lstRangeTranslape.sdStartD.ToShortDateString() + " to " + lstRangeTranslape.sdEndD.ToShortDateString() + ")" + " of season " + "'" + lstRangeTranslape.ssN + "'" + ". " + "Specify another date.");
                                    SeasonDate data = e.Row.DataContext as SeasonDate;
                                    if (isEdit)
                                    {
                                        string strColumn = e.Column.SortMemberPath.ToString();
                                        switch (strColumn)
                                        {
                                        case "sdStartD":
                                            changedTextBox.Text = data.sdStartD.ToShortDateString();
                                            break;

                                        case "sdEndD":
                                            changedTextBox.Text = data.sdEndD.ToShortDateString();
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        changedTextBox.Text = string.Empty;
                                    }
                                }
                                else
                                {
                                    GridHelper.UpdateSourceFromARow(sender as DataGrid);
                                }
                            }
                        }
                        else
                        {
                            isCancel = true;
                            UIHelper.ShowMessage("The date does not belong to the year being edited " + _year.Year, MessageBoxImage.Exclamation, "IM.Administrator");
                            changedTextBox.Text = string.Empty;
                        }
                    }
                    else
                    {
                        isCancel = true;
                        UIHelper.ShowMessage("Invalid Date", MessageBoxImage.Error, "IM.Administrator");
                        changedTextBox.Text = string.Empty;
                    }
                }
                else
                {
                    if (e.Column.SortMemberPath == "sdEndD")
                    {
                        UIHelper.ShowMessage("Specify a Date", MessageBoxImage.Error, "IM.Administrator");
                        e.Cancel = true;
                    }
                    else
                    {
                        isCancel = true;
                    }
                }
            }
        }