Пример #1
0
    //送出預約
    protected void vSendButton_Click(object sender, EventArgs e)
    {
        try
        {
            //檢查是否所有資都填了
            List <string> Errors = new List <string>();

            #region MemberInfo

            //vMemberName
            string MemberName = this.vMemberName.Text.Replace(" ", "");
            if (string.IsNullOrWhiteSpace(MemberName) == true)
            {
                Errors.Add("請輸入 大學生姓名");
            }

            //MemberIdCardNumber
            string MemberIdCardNumber = this.vMemberAccount.Text.Replace(" ", "").ToUpper();
            if (string.IsNullOrWhiteSpace(MemberIdCardNumber) == true)
            {
                Errors.Add("請輸入 身分證字號");
            }
            else if (UserManager.IdCheck(MemberIdCardNumber) == false)
            {
                Errors.Add("身分證字號m錯誤");
            }
            else if (ConfigManager.GetByConfigKey(ConfigKey.黑名單).Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Contains(MemberIdCardNumber) == true)
            {
                Errors.Add("身份證字號無效");
            }

            //vMemberPhone
            string MemberPhone = this.vMemberPhone.Text.Replace(" ", "");
            if (string.IsNullOrWhiteSpace(MemberPhone) == true)
            {
                Errors.Add("請輸入 行動電話");
            }
            else if (MemberPhone.Contains("09") == false)
            {
                Errors.Add("行動電話格式不正確");
            }

            #endregion

            #region MemberArea

            string Area = this.vAreaSelector.SelectedItem.Text;
            if (Area == "請選擇")
            {
                Errors.Add("請選擇 地區");
            }

            string School = this.vSchoolSelector.SelectedItem.Text;
            if (School == "請選擇")
            {
                Errors.Add("請選擇 學校");
            }

            #endregion

            #region ShopInfos

            if (string.IsNullOrWhiteSpace(_CurrentOrderItem.ShopId) == true)
            {
                Errors.Add("請選擇 預約LOHAS門市");
            }
            else if (string.IsNullOrWhiteSpace(_CurrentOrderItem.ShopName) == true)
            {
                Errors.Add("請選擇 預約LOHAS門市");
            }
            else if (string.IsNullOrWhiteSpace(_CurrentOrderItem.ShopPhone) == true)
            {
                Errors.Add("請選擇 預約LOHAS門市");
            }
            else if (string.IsNullOrWhiteSpace(_CurrentOrderItem.ShopAddress) == true)
            {
                Errors.Add("請選擇 預約LOHAS門市");
            }
            else if (string.IsNullOrWhiteSpace(_CurrentOrderItem.Shoplatitude) == true)
            {
                Errors.Add("請選擇 預約LOHAS門市");
            }
            else if (string.IsNullOrWhiteSpace(_CurrentOrderItem.Shoplongitude) == true)
            {
                Errors.Add("請選擇 預約LOHAS門市");
            }

            #endregion

            #region OrderRound

            DateTime OrderDate;
            if (DateTime.TryParse(this.vSelectedDate.Value.Trim(), out OrderDate) == false)
            {
                Errors.Add("請選擇 預約日期");
            }

            if (string.IsNullOrWhiteSpace(_CurrentOrderItem.OrderRound) == true)
            {
                Errors.Add("請選擇 預約時段");
            }
            #endregion

            if (Errors.Count > 0)
            {
                throw new Exception(string.Join("\\r\\n", Errors));
            }

            //檢查 重複報名
            if (_IsUpdateMode == false && OrderItemManager.Get(MemberIdCardNumber, MemberPhone) != null)
            {
                Errors.Add("每人僅有一次機會,不可重複預約");
            }

            if (Errors.Count > 0)
            {
                throw new Exception(string.Join("\\r\\n", Errors));
            }


            //檢查 是否額滿
            int SameRoundOrderAmount = OrderItemManager.GetRoundCount(_CurrentOrderItem.ShopId, (DateTime)_CurrentOrderItem.OrderDate, _CurrentOrderItem.OrderRound);
            int LimitPairAmount      = ShopItemManager.GetById(_CurrentOrderItem.ShopId).RoundItems.FirstOrDefault(r => r.Name == _CurrentOrderItem.OrderRound).LimitPairAmount;
            if ((SameRoundOrderAmount + 1) > LimitPairAmount)
            {
                Errors.Add("場次已經額滿,請挑選新的場次");
            }

            if (Errors.Count > 0)
            {
                throw new Exception(string.Join("\\r\\n", Errors));
            }

            _CurrentOrderItem.MemberName    = MemberName;
            _CurrentOrderItem.MemberAccount = MemberIdCardNumber;
            _CurrentOrderItem.MemberPhone   = MemberPhone;

            _CurrentOrderItem.MemberArea   = Area;
            _CurrentOrderItem.MemberSchool = School;

            _CurrentOrderItem.OrderDate = OrderDate;

            OrderItemManager.SaveTemp(_CurrentOrderItem);
            ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "Message", "top.location.replace('Questionnaire_Form.aspx');", true);

            //OrderItemManager.Save(_CurrentOrderItem);
            //ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "Message", "top.location.replace('Finish_Form.aspx?" + Server.UrlEncode(LeftHand.Gadget.Encoder.AES_Encryption(_CurrentOrderItem.Id.ToString())) + "');", true);
        }
        catch (Exception ex)
        {
            LeftHand.Gadget.Dialog.Alert(ex.Message);
        }
    }