public ActionResult Edit(VolunteersModel.VolunteersShowEdit item, int p = 1)
        {
            //if (ModelState.IsValid)
            {
                s26webDataContext db = new s26webDataContext();
                var old = db.Volunteers.FirstOrDefault(f => f.Id == item.Id);
                db.Connection.Close();

                int user_id = Method.Get_UserId_Admin(Request.Cookies, Session);
                item.LastMemberId = user_id;

                if (data.Update(item) <= 0)
                {
                    TempData["err"] = "Volunteers_5";
                    return RedirectToAction("Index");
                }
                //if (item.SendSMS)
                //{
                //    IntroductionModel intro = new IntroductionModel();
                //    var results = intro.Get_One(38);
                //    var result = MobileAPIModel.sendToServer(38, item.VolunteersMobile, null, 0, "", item.Id);
                //}
            }
            return RedirectToAction("Index", new { p = p });
        }
        public ActionResult Edit(VolunteersModel.VolunteersShowEdit item, int year, int month, int date, HttpPostedFileBase Photos = null)
        {
            DateTime bir = new DateTime(year, month, date);
            item.BabyBirthday = bir;
            string Session_name = Method.SessionUserId_Home;
            int memberid = int.Parse(Method.Get_Session(Session, Session_name));
            item.Id = memberid;

            if(item.BabyBirthday > DateTime.Today)
            { item.NowBrand = 1; }

            if (data.MemberUpdate(item, Photos, "Manual/" + item.Id, Server) <= 0)
            {
                TempData["err"] = "MemberUpdate_Err";
                return RedirectToAction("Index", "Member");
            }
            return RedirectToAction("Index", "Member");
        }
        public ActionResult Index(VolunteersModel.RegisterModel item, int year, int month, int date) //HttpSessionStateBase Session,
        {
            try
            {
                DateTime bir = new DateTime(year, month, date);
                string Session_name = Method.SessionUserId_Home;
                string account = Method.Get_Session(Session, Session_name);

                item.Id = int.Parse(account);

                if (data.Update(item, bir) <= 0)
                {
                    return RedirectToAction("Index");
                }
            }
            catch { TempData["err"] = "Login,更新失敗(請輸入完整資訊)"; }

            return RedirectToAction("Index");
        }
        public static List<Export> Get_Export(VolunteersModel datas)
        {

            /*-------------------匯出宣告-------------------*/
            s26webDataContext db = new s26webDataContext();
            Export export = new Export();
            List<Export> exp = new List<Export>();
            List<string> bir = new List<string> { "", "", "" };
            var newdata = datas.Get().OrderByDescending(o => o.Id);
            /*-------------------匯出宣告End-------------------*/
            foreach (var d in newdata)
            {
                export.Phone = d.Mobile;

                export.Name = d.Name;
                //export.BabyBirthday = d.BabyBirthday.Value.Date.ToString();

                if (d.NowBrand == 1)
                    export.NowBrand = "懷孕中";
                else if (d.NowBrand == 2)
                    export.NowBrand = "使用S-26產品";
                else if (d.NowBrand == 3)
                    export.NowBrand = "全母乳餵哺";
                else if (d.NowBrand == 4)
                    export.NowBrand = "其他";

                export.BrandName = d.BrandName;
                export.Email = d.Email;

                if (d.Status == 1)
                    export.Status = "審核中";
                else if (d.Status == 2)
                    export.Status = "通過";
                else if (d.Status == 3)
                    export.Status = "未通過";

                export.FBConnect = d.FBConnect ? "是" : "否";
                export.FBFriend = d.FBFriend ? "是" : "否";
                export.CreateTime = d.CreateTime.AddHours(8).ToString("yyyy/MM/dd HH:mm");
                export.UpdateTime = d.UpdateTime.AddHours(8).ToString("yyyy/MM/dd HH:mm");
                export.Memo = d.Memo;
                export.FailReason = d.FailReason;
                
                exp.Add(export);
                export = new Export();
            }
            db.Connection.Close();
            return exp;
        }
        public int Update(VolunteersModel.RegisterModel item, DateTime Birthday)
        {
            try
            {
                s26webDataContext db = new s26webDataContext();
                var data = db.Volunteers.FirstOrDefault(f => f.Id == item.Id);
                if (data != null)
                {
                    data.BabyBirthday = Birthday;
                    data.NowBrand = item.Product;
                    data.BrandName = item.BrandName;
                    
                    data.UpdateTime = DateTime.UtcNow; //使用者更新時間
                    data.LastMemberId = item.Id;

                    db.SubmitChanges();
                    db.Connection.Close();
                    return data.Id;
                }
                db.Connection.Close();
                return -1;
            }
            catch { return -1; }
        }
        public ActionResult Index(VolunteersModel.LoginModel item, int year, int month, int date, string returnurl = "")
        {
            item.BabaBirthday = new DateTime(year, month, date);

            if (ModelState.IsValid)
            {
                if (Session["Login"] == null)
                    Session["Login"] = 0;
                else
                {
                    if ((int)Session["Login"] < 3)
                        Session["Login"] = Convert.ToInt32(Session["Login"]) + 1;
                }

                if ((int)Session["Login"] < 3)
                {
                    if (returnurl == null || returnurl == "")
                    {
                        returnurl = Method.RootPath + "/Login/Index";
                    }
                    var accunt = data.Get_One_Mobile(item.Mobile);
                    if (accunt != null)
                    {
                        //if (accunt.FaceBookId != null & data.Get_HashPasswords(item.Password) == data.Get_PWByMobile(item.UserName))
                        //{
                        //    TempData["err"] = "此帳號是使用FB註冊,請使用FB帳號登入。";
                        //    ViewBag.ReturnUrl = returnurl;

                        //    return View(item);
                        //}

                        //if (accunt.Status == 1 & data.Get_HashPassword(item.Password) == data.Get_PWByMobile(item.Mobile))
                        //{
                        //    TempData["err"] = "帳號尚未完成審核,請等候惠氏VIP服務專員與您聯繫。";
                        //    ViewBag.ReturnUrl = returnurl;

                        //    return View(item);
                        //    //return RedirectToAction("Error");
                        //}
                        //else if (accunt.Password != data.Get_HashPassword(item.Password))
                        //{
                        //    TempData["err"] = "手機號碼或密碼錯誤。"/*Session["Login"]*/;

                        //    return View(item);
                        //}
                        //else if (accunt.Status == 3 & data.Get_HashPassword(item.Password) == data.Get_PWByMobile(item.Mobile))
                        //{
                        //    TempData["err"] = "帳號審核失敗,請重新註冊。";
                        //    ViewBag.ReturnUrl = returnurl;

                        //    return RedirectToAction("Register", "Login", new { error = "Enable" });
                        //}
                        //else
                        //{
                        //    LoginAccount(accunt);
                        //    returnurl = Method.RootPath + "/Home/Index";
                        //    return RedirectToLocal(returnurl);
                        //}

                        //20150327 改為用寶寶生日當作密碼
                        if (accunt.Status == 1 & accunt.BabyBirthday == item.BabaBirthday)
                        {
                            TempData["err"] = "帳號尚未完成審核,請等候惠氏VIP服務專員與您聯繫。";
                            ViewBag.ReturnUrl = returnurl;

                            return View(item);
                            //return RedirectToAction("Error");
                        }
                        else if (accunt.BabyBirthday != item.BabaBirthday)
                        {
                            TempData["err"] = "手機號碼或密碼錯誤。"/*Session["Login"]*/;

                            return View(item);
                        }
                        else if (accunt.Status == 3 & accunt.BabyBirthday == item.BabaBirthday)
                        {
                            TempData["err"] = "帳號審核失敗,請重新註冊。";
                            ViewBag.ReturnUrl = returnurl;

                            return RedirectToAction("Register", "Login", new { error = "Enable" });
                        }
                        else
                        {
                            LoginAccount(accunt);
                            returnurl = Method.RootPath + "/Home/Index";
                            return RedirectToLocal(returnurl);
                        }
                    }
                    else
                    {
                        TempData["err"] = "手機號碼或密碼錯誤。"/*Session["Login"]*/;
                        ViewBag.ReturnUrl = returnurl;

                    }
                    return RedirectToLocal(returnurl);
                }
                else
                {
                    TempData["err"] = "您登入失敗太多次,帳號已被鎖定30分鐘,請稍後再試。";
                    ViewBag.ReturnUrl = returnurl;

                    return View(item);
                }


            }
            if (item.BabaBirthday == null & item.Mobile == null)
            {
                TempData["err"] = "請輸入手機號碼及密碼";
            }
            else if (item.Mobile == null)
            {
                TempData["err"] = "請輸入手機號碼";
            }
            else 
            {
                TempData["err"] = "請輸入密碼";
            }

            ViewBag.ReturnUrl = returnurl;
            return View(item);
        }
        public ActionResult Register(VolunteersModel.RegisterModel item, int year, int month, int date, HttpPostedFileBase id_image = null)
        {
            try
            {
                int vid = Method.Get_UserId(Request.Cookies, Session);
                data.Insert(item, id_image, "Manual/" + vid, Server, year, month, date);
            }
            catch { TempData["err"] = "Login,帳號註冊失敗(請輸入完整資訊)"; }

            return RedirectToAction("member_complete", "Login");
        }
 public ActionResult Create(VolunteersModel.VolunteersShow item, HttpPostedFileBase file = null)
 {
     try
     {
             int vid = Method.Get_UserId(Request.Cookies, Session);
             item.LastMemberId = vid;
                 if (data.Insert(item, file, "Manual/" + vid, Server) <= 0)
                 {
                     TempData["err"] = "Volunteers_2,帳號新增失敗(請避免帳號重複)";
                     return RedirectToAction("Index");
                 }
     }
     catch { TempData["err"] = "Volunteers_4,帳號新增失敗(請輸入完整資訊)"; }
     return RedirectToAction("Index");
 }