public static MobileModel Sale_SMS(int Id, String mobile, int collected, DateTime ExcTime, string detail = null)
        {
            s26webDataContext db = new s26webDataContext();
            IntroductionModel intro = new IntroductionModel();
            var msg = intro.Get_One(Id);
            var data = db.Volunteers.FirstOrDefault(f => f.Mobile == mobile);

            /////////////////////
            msg.Content = msg.Content.Replace("<--end_time-->", ExcTime.AddHours(8).ToString("yyyy/MM/dd HH:mm"));
            msg.Content = msg.Content.Replace("<--collected-->", collected.ToString());
            /////////////////////
            var mm = SMS_Send(msg, mobile);
            SMS sms = new SMS
            {
                sms_id = mm.error_code,
                content = mm.error_msg,
                CreateTime = DateTime.UtcNow,
                mobile = mobile,
                detail = detail
            };
            db.SMS.InsertOnSubmit(sms);
            db.SubmitChanges();
            db.Connection.Close();
            //return the response
            return mm;
        }
 public SiteOptionShow Get()
 {
     s26webDataContext db = new s26webDataContext();
     var data = db.WebConfig.FirstOrDefault();
     db.Connection.Close();
     if (data != null)
     {
         return new SiteOptionShow
         {
             Id = data.Id,
             WebTitle = data.WebTitle,
             WebIcon = data.WebIcon,
             WebLogo = Method.RootPath + data.WebLogo,
             WebSEO = data.WebSEO,
             WebDescription = data.WebDescription,
             SMTP_Server = data.SMTP_Server,
             SMTP_Port = data.SMTP_Port,
             SMTP_Login = data.SMTP_Login,
             SMTP_SSL = data.SMTP_SSL,
             SMTP_Account = data.SMTP_Account,
             SMTP_Password = data.SMTP_Password,
             Service_Mail = data.Service_Mail,
             FromName = data.FromName,
             ExportMail = data.Export_Mail,
             OrdersMail = data.OrdersMail,
             iOS_Version = data.iOS_Version,
             Android_Version = data.Android_Version
         };
     }
     return new SiteOptionShow();
 }
        public List<OnlineModelShow> Get_Data(int p = 1, int take = 10)
        {
            try
            {
                s26webDataContext db = new s26webDataContext();

                var data = Get().OrderByDescending(o => o.Id).Skip((p - 1) * take).Take(take);
                foreach (var i in data)
                {
                    string[] typestr = i.Type.Split(',');
                    string list = "";
                    foreach (var j in typestr)
                    {
                        if (j != "")
                        {
                            int typeint = int.Parse(j);
                            list += db.Category.FirstOrDefault(f => f.Id == typeint).Name + ",";
                        }
                    }
                    i.Type = list;
                };

                List<OnlineModelShow> item = Convert(data.ToList());
                db.Connection.Close();
                return item;
            }
            catch { return new List<OnlineModelShow>(); }
        }
        public static List<SelectListItem> Get_Area_Select(int city, int area, bool zip, bool all)
        {
            s26webDataContext db = new s26webDataContext();
            List<SelectListItem> data = new List<SelectListItem>();
            data.Add(new SelectListItem
            {
                Selected = area == 0,
                Text = all ? "全部" : "請選擇",
                Value = "0"
            });
            if (city == 0)
            {
                return data;
            }
            
                data.AddRange(db.Area.Where(w => w.City_Id == city).OrderBy(o => o.Id).ThenBy(t => t.ZipCode).Select(s =>
                    new SelectListItem
                    {
                        Selected = area == s.Id,
                        Text = (zip ? s.ZipCode : "") + s.Name,
                        Value = s.Id.ToString()
                    }));
            

            db.Connection.Close();
            return data;
        }
 public IQueryable<SalesPromotion> Get()
 {
     s26webDataContext db = new s26webDataContext();
     IQueryable<SalesPromotion> data = db.SalesPromotion;
     db.Connection.Close();
     return data;
 }
 public IQueryable<Online> Get()
 {
     s26webDataContext db = new s26webDataContext();
     IQueryable<Online> data = db.Online;
     db.Connection.Close();
     return data;
 }
 public List<GiftModelShow> Get_Data()
 {
     s26webDataContext db = new s26webDataContext();
     var gift = Convert(db.Gift.OrderByDescending(o => o.Id).ToList());
     foreach(var i in gift)
     {
         string[] typestr= i.MemberType.Split(',');
         string list = "";
         string item = "";
         foreach(var j in typestr)
         {
         if (j != "") 
         {
             int typeint = int.Parse(j);
             
             if(typeint == 1)
             { item = "懷孕中"; }
             else if (typeint == 2)
             { item = "使用S-26產品"; }
             else if (typeint == 3)
             { item = "全母乳餵哺"; }
             else if (typeint == 4)
             { item = "其他"; }
             
             //list += db.Category.FirstOrDefault(f => f.Id == typeint).Name + ",";
         }
         list += item + ",";
         }
         i.MemberType = list;
     };
     db.Connection.Close();
     return gift;
 }
 public List<Category> Get_MemberType()
 {
     s26webDataContext db = new s26webDataContext();
     GiftModelShow data = new GiftModelShow();
     data.membertype_list = db.Category.Where(w => w.Fun_Id == 2).ToList();
     db.Connection.Close();
     return data.membertype_list;
 }
 public List<Category> Get_Category()
 {
         s26webDataContext db = new s26webDataContext();
         PointModelShow data = new PointModelShow();
         data.Point_Category = db.Category.Where(w => w.Fun_Id == 3).ToList();
         db.Connection.Close();
         return data.Point_Category;
 }
 public ActionResult CheckMobile(string Mobile)
 {
     s26webDataContext db = new s26webDataContext();
     var result = db.Volunteers.FirstOrDefault(f => f.Mobile == Mobile);
     db.Connection.Close();
     if (result != null)
         return Json(false, JsonRequestBehavior.AllowGet);
     else
         return Json(true, JsonRequestBehavior.AllowGet);
 }
 public static int getSMSPoint()
 {
     s26web.Models.s26webDataContext db = new s26web.Models.s26webDataContext();
     int point = 0;
     var result = db.SMS.Where(w=>w.sms_id.Equals("000")).OrderByDescending(o => o.CreateTime).FirstOrDefault();
     List<string> sms_content = new List<string>();
     if(result != null)
         sms_content = result.content.Split('|').ToList();
     point = Convert.ToInt32(sms_content.LastOrDefault());
     return point;
 }
        public ActionResult Delivery_Order(string Osid, int Id)
        {
            string Session_name = Method.SessionUserId_Home;
            int memberid = int.Parse(Method.Get_Session(Session, Session_name));
            s26webDataContext db = new s26webDataContext();
            Osid = db.Orders.FirstOrDefault(f => f.Id == Id).Osid;
            db.Connection.Close();

            OrdersModel orders = new OrdersModel();
            var orderdetail = orders.Get_Detail(Osid);
            return View(orderdetail);
        }
 public void Update(string[] UserName, string[] FBUrl)
 {
     s26webDataContext db = new s26webDataContext();
     for (int i = 0; i < UserName.Count(); i++)
     {
         var data = db.eCRM.FirstOrDefault(f => f.Id == (i + 1));
         data.UserName = UserName[i];
         data.FBUrl = FBUrl[i];
     }
     db.SubmitChanges();
     db.Connection.Close();
 }
        public List<SalesPromotionModelShow> Get_Data(int p = 1, int take = 10)
        {
            try
            {
                s26webDataContext db = new s26webDataContext();

                var data = Get().OrderByDescending(o=>o.Id).Skip((p - 1) * take).Take(take);
                List<SalesPromotionModelShow> item = Convert(data.ToList());
                db.Connection.Close();
                return item;
            }
            catch { return new List<SalesPromotionModelShow>(); }
        }
        public ActionResult Index()//HttpSessionStateBase Session
        {
            s26webDataContext db = new s26webDataContext();
            string Session_name = Method.SessionUserId_Home;
            string account = Method.Get_Session(Session, Session_name);

            var vol = db.Volunteers.FirstOrDefault(w => w.Id == int.Parse(account));
            ViewData["Bir_year"] = vol.BabyBirthday.ToString("yyyy");
            ViewData["Bir_month"] = vol.BabyBirthday.ToString("MM");
            ViewData["Bir_date"] = vol.BabyBirthday.ToString("dd");

            return View();
        }
 public ActionResult Edit(SalesPromotionModel.SalesPromotionModelShow item, int p = 1)
 {
     {
         s26webDataContext db = new s26webDataContext();
         var old = db.SalesPromotion.FirstOrDefault(f => f.Id == item.Id);
         db.Connection.Close();
         if (data.Update(item) <= 0)
         {
             TempData["err"] = "SalesPromotion_5";
             return RedirectToAction("Index");
         }
     }
     return RedirectToAction("Index", new { p = p });
 }
 public static string Get_Title(int id)
 {
     try
     {
         s26webDataContext db = new s26webDataContext();
         var data = db.Introduction.FirstOrDefault(f => f.Id == id);
         db.Connection.Close();
         if (data != null)
         {
             return data.Title;
         }
     }
     catch { }
     return "";
 }
 public LoginRecordModelShow Get_One(int id)
 {
     try
     {
         s26webDataContext db = new s26webDataContext();
         var data = db.LoginRecord.FirstOrDefault(f => f.Id == id);
         if (data != null)
         {
             return Convert(data);
         }
         db.Connection.Close();
     }
     catch { }
     return null;
 }
        public ActionResult Index(int year, int month, int date)
        {
            s26webDataContext db = new s26webDataContext();
            DeliveryModel data = new DeliveryModel();

            string Session_name = Method.SessionUserId_Home;
            string account = Method.Get_Session(Session, Session_name);
            DateTime New_BabyBirthday = new DateTime(year, month, date);
            //string New_BabyBirthday = year+"/"+month+"/"+date;
            DateTime vol_BabyBirthday = db.Volunteers.FirstOrDefault(w => w.Id == int.Parse(account)).BabyBirthday;

            if (vol_BabyBirthday != New_BabyBirthday)
            {
                data.Update_BabyBirthday(account, New_BabyBirthday);
            }
            return RedirectToAction("article");
        }
 public List<CRMMemberInfo> Get_Data()
 {
     s26webDataContext db = new s26webDataContext();
     var data = db.eCRM;
     List<CRMMemberInfo> mm = new List<CRMMemberInfo>();
     foreach (var i in data)
     {
         mm.Add(new CRMMemberInfo
         {
             Id = i.Id,
             CategoryName = i.CategoryName,
             FBUrl = i.FBUrl,
             UserName = i.UserName
         });
     }
     db.Connection.Close();
     return mm;
 }
 public static List<SelectListItem> Get_City_Select(int city, bool all)
 {
     s26webDataContext db = new s26webDataContext();
     List<SelectListItem> data = new List<SelectListItem>();
     data.Add(new SelectListItem
     {
         Selected = city == 0,
         Text = all ? "全部" : "請選擇",
         Value = "0"
     });
     data.AddRange(db.City.OrderBy(o => o.Id).Select(s =>
         new SelectListItem
         {
             Selected = city == s.Id,
             Text = s.Name,
             Value = s.Id.ToString()
         }));
     db.Connection.Close();
     return data;
 }
        public ActionResult Edit(GiftModel.GiftModelShow item, int p = 1, string[] MemberTypelist = null)
        {
            {
                s26webDataContext db = new s26webDataContext();
                var old = db.Gift.FirstOrDefault(f => f.Id == item.Id);
                db.Connection.Close();
                foreach (var i in MemberTypelist)
                { item.MemberType += i + ","; }

                //刪除最後一個逗號
                item.MemberType = item.MemberType.Remove(item.MemberType.LastIndexOf(","), 1);

                if (data.Update(item) <= 0)
                {
                    TempData["err"] = "Gift_5";
                    return RedirectToAction("Index");
                }
            }
            return RedirectToAction("Index", new { p = p });
        }
        public ActionResult Create(PointModel.PointModelShow item, string phone)
        {
            s26webDataContext db = new s26webDataContext();
            List<string> mobile_list = new List<string>();
            mobile_list = phone.Split(',').ToList();

            int user_id = Method.Get_UserId_Admin(Request.Cookies, Session);
            item.UId = user_id;
            item.Category = 2;
            item.Result = true;
            foreach (var i in mobile_list)
            {
                item.Mobile = i;
                if (data.Insert(item) <= 0)
                {
                    TempData["err"] = "";
                    return RedirectToAction("Index");
                }
            }
            return RedirectToAction("Index");
        }
 public IntroductionModelShow Get_One(int id)
 {
     try
     {
         s26webDataContext db = new s26webDataContext();
         var data = db.Introduction.FirstOrDefault(f => f.Id == id);
         if (data != null)
         {
             return new IntroductionModelShow
             {
                 Id = data.Id,
                 Title = data.Title,
                 Content = HttpUtility.HtmlDecode(data.Content),
                 CreateTime = data.CreateTime.AddHours(8),
                 UpdateTime = data.UpdateTime.AddHours(8)
             };
         }
         return null;
     }
     catch { return null; }
 }
        public ActionResult Count(SalesCodeModel.SalesCodeModelShow item)
        {
            SalesCodeModel data = new SalesCodeModel();

            int Num = data.Check_Code_Front(item);
            //促銷碼已經兌換過 
            if (Num == -1)
            {
                return RedirectToAction("Count", new { Code_Error = -1, Code = item.Code });
            }
            //促銷碼輸入錯誤
            else if (Num == -2)
            {
                return RedirectToAction("Count", new { Code_Error = -2, Code = item.Code });
            }
            //兌換成功
            else
            {
                s26webDataContext db = new s26webDataContext();
                int Point = db.SalesCode.FirstOrDefault(w => w.Code == item.Code).SalesPromotionPoint;
                return RedirectToAction("Premiums_complete", new { Point = Point });
            }
        }
 public int Set(IntroductionModelShow item)
 {
     try
     {
         s26webDataContext db = new s26webDataContext();
         if (item.Id > 0)
         {
             var data = db.Introduction.FirstOrDefault(f => f.Id == item.Id);
             if (data != null)
             {
                 data.Title = item.Title;
                 data.Content = item.Content;
                 data.UpdateTime = DateTime.UtcNow;
                 db.SubmitChanges();
                 db.Connection.Close();
                 return item.Id;
             }
         }
         db.Connection.Close();
         return -1;
     }
     catch { return -1; }
 }
 public List<Category> Get_Type()
 {
     s26webDataContext db = new s26webDataContext();
     OnlineModelShow data = new OnlineModelShow();
     data.type_list = db.Category.Where(w => w.Fun_Id == 10).ToList();
     db.Connection.Close();
     return data.type_list;
 }
 public void Delete(int Id)
 {
     s26webDataContext db = new s26webDataContext();
     var data = db.Online.Where(w => w.Id == Id);
     if (data.Any())
     {
         db.Online.DeleteAllOnSubmit(data);
         db.SubmitChanges();
     }
     db.Connection.Close();
 }
 public int Update(OnlineModelShow item)
 {
     try
     {
         s26webDataContext db = new s26webDataContext();
         var data = db.Online.FirstOrDefault(f => f.Id == item.Id);
         if (data != null)
         {
             data.Type = item.Type;
             data.Name = item.Name;
             data.Content = item.Content;
             if (item.Banner_PC != null)
             {
                 data.Banner_PC = item.Banner_PC;
             }
             if (item.Banner_Mobile != null)
             {
                 data.Banner_Mobile = item.Banner_Mobile;
             }
             data.Url = item.Url;
             data.Display = item.Display;
             data.StartTime = item.StartTime.AddHours(-8);
             if (item.EndTime != DateTime.Parse("0001/1/1 上午 12:00:00"))
             {
                 data.EndTime = item.EndTime.AddHours(-8);
             }
             else
             {
                 data.EndTime = null;
             }
             data.UpdateTime = DateTime.UtcNow;
             db.SubmitChanges();
             db.Connection.Close();
             return data.Id;
         }
         db.Connection.Close();
         return -1;
     }
     catch { return -1; }
 }
        public int Insert(OnlineModelShow item)
        {
            s26webDataContext db = new s26webDataContext();
            try
            {
                //有輸入下線時間
                if (item.EndTime != DateTime.Parse("0001/1/1 上午 12:00:00"))
                {
                    Online new_item = new Online
                    {
                        Type = item.Type,
                        Name = item.Name,
                        Content = item.Content,
                        Banner_PC = item.Banner_PC,
                        Banner_Mobile = item.Banner_Mobile,
                        Url = item.Url,
                        Display = item.Display,
                        StartTime = item.StartTime.AddHours(-8),
                        EndTime = item.EndTime.AddHours(-8),
                        UpdateTime = DateTime.UtcNow
                    };

                    db.Online.InsertOnSubmit(new_item);
                    db.SubmitChanges();
                    db.Connection.Close();
                    return new_item.Id;
                }
                else
                {
                    Online new_item = new Online
                    {
                        Type = item.Type,
                        Name = item.Name,
                        Content = item.Content,
                        Banner_PC = item.Banner_PC,
                        Banner_Mobile = item.Banner_Mobile,
                        Url = item.Url,
                        Display = item.Display,
                        StartTime = item.StartTime.AddHours(-8),
                        UpdateTime = DateTime.UtcNow
                    };

                    db.Online.InsertOnSubmit(new_item);
                    db.SubmitChanges();
                    db.Connection.Close();
                    return new_item.Id;
                }
            }
            catch
            {
                return -1;
            }
        }