// 產品修改畫面 public ActionResult ProEdit(string appSer) { // 1. 取得Get 參數, app_Ser System.Diagnostics.Debug.WriteLine(" >>>> ProEdit AppSer: " + appSer); // 2. 於資料庫搜尋此筆資料 //----> 程式碼 Models.ShopCarDatasetTableAdapters.ProductTableAdapter proadp = new Models.ShopCarDatasetTableAdapters.ProductTableAdapter(); DataTable dt; dt = proadp.GetProductData(Convert.ToInt32(appSer)); DataRow drow = dt.Rows[0]; string price, s_price; price = wf.tos(drow["prod_price"]); if (price.IndexOf(".") >= 0) { price = price.Substring(0, price.IndexOf(".")); } s_price = wf.tos(drow["prod_special_price"]); if (s_price.IndexOf(".") >= 0) { s_price = s_price.Substring(0, s_price.IndexOf(".")); } /* if (wf.tos(drow["pro_active"]) == "on") { productOn = "on"; productOff = ""; } else { productOn = ""; productOff = "on"; } * */ // 3. 將找到的Row, 使用物件 儲存起來回丟給前端 ProEdit.cshtml var prodItem = new { appSer = wf.tos(drow["app_ser"]), proNo = wf.tos(drow["ProductID"]), proName = wf.tos(drow["ProName"]), proPrice = price, proSpecialPrice = s_price, proClassId = wf.tos(drow["prod_class_id"]), proActive = wf.tos(drow["pro_active"]), prodFeature = wf.tos(drow["prod_feature"]), prodDesc = wf.tos(drow["pro_desc"]) }; return View("ProEdit", prodItem); }
public ActionResult ProUpdate(FormCollection formCollection) { // 1. 取得前端 form 的欄位資料 System.Diagnostics.Debug.WriteLine(" >>>> ProUpdate -------------------------->>>> "); System.Diagnostics.Debug.WriteLine(" >>>> ProUpdate proNo: " + formCollection["proNo"]); System.Diagnostics.Debug.WriteLine(" >>>> ProUpdate proName: " + formCollection["proName"]); System.Diagnostics.Debug.WriteLine(" >>>> ProUpdate proPrice: " + formCollection["proPrice"]); System.Diagnostics.Debug.WriteLine(" >>>> ProUpdate proSpecialPrice: " + formCollection["proSpecialPrice"]); System.Diagnostics.Debug.WriteLine(" >>>> ProUpdate proClassId: " + formCollection["proClassId"]); System.Diagnostics.Debug.WriteLine(" >>>> ProUpdate pro_active: " + formCollection["pro_active"]); System.Diagnostics.Debug.WriteLine(" >>>> ProUpdate prodFeature: " + formCollection["prodFeature"]); System.Diagnostics.Debug.WriteLine(" >>>> ProUpdate prodDesc: " + formCollection["prodDesc"]); // 2. 更新產品資料表 //----> 程式碼 decimal price; Nullable<decimal> special_price; price = Convert.ToDecimal(formCollection["proPrice"]); if (formCollection["proSpecialPrice"] == "") { special_price = null; } else { special_price = Convert.ToDecimal(formCollection["proSpecialPrice"]); } string proactive = ""; if (!string.IsNullOrEmpty(formCollection["pro_active"])) { proactive = formCollection["pro_active"].ToString(); } Models.ShopCarDatasetTableAdapters.ProductTableAdapter proadp = new Models.ShopCarDatasetTableAdapters.ProductTableAdapter(); proadp.UpdateProductData(formCollection["proNo"], formCollection["proName"], price, special_price, Convert.ToInt32(formCollection["proClassId"]), proactive, formCollection["prodFeature"], formCollection["prodDesc"], Convert.ToInt32(formCollection["appser"])); // 3. 使用物件 儲存起來回丟給前端 ProEdit.cshtml //string proActiveOnstr = ""; //if (!string.IsNullOrEmpty(formCollection["proActiveOn"])) //{ // proActiveOnstr = formCollection["proActiveOn"].ToString(); //} //string proActiveOffstr = ""; //if (!string.IsNullOrEmpty(formCollection["proActiveOff"])) //{ // proActiveOffstr = formCollection["proActiveOff"].ToString(); //} var prodItem = new { appSer = formCollection["appser"], proNo = formCollection["proNo"].ToString(), proName = formCollection["proName"].ToString(), proPrice = formCollection["proPrice"].ToString(), proSpecialPrice = formCollection["proSpecialPrice"].ToString(), proClassId = formCollection["proClassId"].ToString(), proActive = wf.tos(proactive), prodFeature = formCollection["prodFeature"].ToString(), prodDesc = formCollection["prodDesc"].ToString() }; return View("ProEdit", prodItem); }
public ActionResult ProDelete(FormCollection formCollection) { System.Diagnostics.Debug.WriteLine(" >>>> ProDelete -------------------------->>>> "); System.Diagnostics.Debug.WriteLine(" >>>> ProAdd proNo: " + formCollection["appSer"]); Int32 appser = Convert.ToInt32(formCollection["appSer"]); // 2. 刪除該appser產品 //----> 程式碼 Models.ShopCarDatasetTableAdapters.ProductTableAdapter proadp = new Models.ShopCarDatasetTableAdapters.ProductTableAdapter(); proadp.DeleteProductData(appser); // 3. Return pro_list return RedirectToAction("ProList"); //DataTable table = proadp.GetData(); //Hashtable myHT = new Hashtable(); //myHT.Add("aaData", table); //string obj_json = JsonConvert.SerializeObject(myHT); //return Content(obj_json, "application/json"); //return RedirectToAction("ProList"); }