// GET: SourceListDtls/Details/5 貨源清單明細檢視畫面
        public ActionResult DetailsDtl(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SourceListDtl sourceListDtl = db.SourceListDtl.Find(id);

            if (sourceListDtl == null)
            {
                return(HttpNotFound());
            }
            return(View(sourceListDtl));
        }
        // GET: SourceListDtls/Edit/5 貨源清單明細編輯畫面
        public ActionResult EditDtl(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SourceListDtl sourceListDtl = db.SourceListDtl.Find(id);

            if (sourceListDtl == null)
            {
                return(HttpNotFound());
            }
            ViewBag.SourceListID = new SelectList(db.SourceList, "SourceListID", "PartNumber", sourceListDtl.SourceListID);
            return(View(sourceListDtl));
        }
        // GET: SourceListDtls/Create貨源清單明細新增畫面
        //[HttpPost]
        public ActionResult CreateDtl2(string id)
        {
            ViewBag.SourceListID  = new SelectList(db.SourceList, "SourceListID", "PartNumber");
            ViewBag.SourceListIDD = id;

            SourceListDtl s = new SourceListDtl();

            s.SourceListID      = id;
            s.DiscountBeginDate = DateTime.Now;
            s.DiscountEndDate   = DateTime.Now.AddDays(1);
            return(View(s));
            //ViewBag.PartNumber = new SelectList(db.Part, "PartNumber", "PartName");
            //ViewBag.SupplierCode = new SelectList(db.SupplierInfo, "SupplierCode", "SupplierName");
            //return View();
        }
        public ActionResult CreateDtl2([Bind(Include = "SourceListDtlOID,SourceListID,QtyDemanded,Discount,DiscountBeginDate,DiscountEndDate,CreateDate")] SourceListDtl sourceListDtl)
        {
            if (ModelState.IsValid)
            {
                //SourceList s = this.db.SourceList.Find(sourceList.PartNumber);
                //db.Entry(s).State = EntityState.Detached;
                //sourceList.PartNumber = s.PartNumber;
                sourceListDtl.CreateDate = DateTime.Now;
                //sourceListDtl.Discount = (((-sourceListDtl.Discount) + 100) / 100);

                db.SourceListDtl.Add(sourceListDtl);
                db.SaveChanges();
                return(RedirectToAction("IndexDtl"));
            }

            ViewBag.SourceListID = new SelectList(db.SourceList, "SourceListID", "PartNumber", sourceListDtl.SourceListID);
            return(View(sourceListDtl));
        }
 public ActionResult DeleteDtl(int?id)
 {
     try
     {
         if (id == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         SourceListDtl sourceListDtl = db.SourceListDtl.Find(id);
         if (sourceListDtl == null)
         {
             return(HttpNotFound());
         }
         db.SourceListDtl.Remove(sourceListDtl);
         db.SaveChanges();
         return(RedirectToAction("IndexDtl"));
     }
     catch
     {
         return(Content("<script> alert('刪除失敗');window.location.href='../Index'</script>"));
     }
 }