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 static List<Export> Get_Export(SalesCodeModel data)
        {

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

                export.Id = d.Id.ToString();
                export.SalesPromotionName = Get_SalesPromotionName(d.SalesPromotionId);
                export.Code = d.Code;
                export.SalesPromotionDeadline = d.SalesPromotionDeadline.ToString("yyyy/MM/dd");
                export.SalesPromotionPoint = d.SalesPromotionPoint.ToString();
                if (d.ExchangeStatus == true)
                {
                    export.ExchangeStatus = "已兌換";
                }
                else
                {
                    export.ExchangeStatus = "未兌換";
                }
                if (d.ExchangeTime != null)
                {
                    export.ExchangeTime = d.ExchangeTime.Value.ToString("yyyy/MM/dd HH:mm:ss");
                }
                if (d.VolunteersId != 0)
                {
                    export.VolunteersId = d.VolunteersId.Value.ToString("");
                }
                exp.Add(export);
                export = new Export();
            }
            db.Connection.Close();
            return exp;
        }
 public ActionResult Create(SalesCodeModel.SalesCodeModelShow item)
 {
     try
     {
         if (data.Insert(item) <= 0)
         {
             TempData["err"] = "SalesCode_0";
             return RedirectToAction("Index");
         }
     }
     catch { TempData["err"] = "SalesCode_1"; }
     return RedirectToAction("Index");
 }
        public ActionResult Import(string savedFileName, int SalesPromotionId = 0)
        {
            var jo = new JObject();
            string result;
            try
            {
                var fileName = string.Concat(Server.MapPath(fileSavedPath), "/", savedFileName);

                var importSalesCodes = new List<SalesCodeModel.ImportClass>();

                var helper = new SalesCodeModel();
                var checkResult = helper.CheckImportData(fileName, importSalesCodes);

                jo.Add("Result", checkResult.Success);
                jo.Add("Msg", checkResult.Success ? string.Empty : checkResult.ErrorMessage);
                jo.Add("RowCount", checkResult.RowCount);
                if (checkResult.Success)
                {
                    //儲存匯入的資料
                    helper.SaveImportData(importSalesCodes, SalesPromotionId, fileName);
                }
                result = JsonConvert.SerializeObject(jo);
            }
            catch (Exception ex)
            {
                throw;
            }
            return Content(result, "application/json");
        }
        public ActionResult Edit(SalesCodeModel.SalesCodeModelShow item, int p = 1)
        {
            if (data.Update(item) <= 0)
            {
                TempData["err"] = "SalesCode_5";
                return RedirectToAction("Index");
            }

            return RedirectToAction("Index", new { p = p });
        }