public ActionResult Save(TestMasterInfo entity, bool isPartialView = true, string fun = null) { if (!string.IsNullOrWhiteSpace(fun)) { if (fun == "Cancel") { return(Content("")); } if (fun == "Close") { return(Read(new TestMasterInfo.Conditions { SID = entity.SID, ID = entity.ID })); } } if (ModelState.IsValid) { var biz = new TestBiz.Master(); if (biz.Update(entity) > 0) { //return Read(new TestMasterInfo.Conditions { ID = entity.ID }); string js = string.Format("$('#dumyID').val('{0}');$('#dumyList').submit();$('#dumyRead').submit();", entity.ID); return(JavaScript(js)); } } if (isPartialView) { return(PartialView("~/Views/Shared/Test/_Edit.cshtml", entity)); } else { return(View(entity)); } }
protected void dvMaster_ItemUpdating(object sender, DetailsViewUpdateEventArgs e) { int SID = Convert.ToInt32(dvMaster.DataKey.Values[0]); string ID = dvMaster.DataKey.Values[1].ToString(); var entity = new TestMasterInfo { SID = SID, ID = ID, NO = e.NewValues["NO"]?.ToString(), Name = e.NewValues["Name"]?.ToString(), Address = e.NewValues["Address"]?.ToString(), Phone = e.NewValues["Phone"]?.ToString(), Birthday = e.NewValues["Birthday"] == null ? default(DateTime?) : Convert.ToDateTime(e.NewValues["Birthday"]) }; var biz = new TestBiz.Master(); int i = biz.Update(entity); if (i == 0) { e.Cancel = true; } else { dvMaster.ChangeMode(DetailsViewMode.ReadOnly); bindMasterDetail(SID, ID); bindMaster(null); } }
protected void fvMaster_ItemUpdating(object sender, FormViewUpdateEventArgs e) { int SID = Convert.ToInt32(fvMaster.DataKey.Values[0]); string ID = fvMaster.DataKey.Values[1].ToString(); var entity = new TestMasterInfo { SID = SID, ID = ID, NO = e.NewValues["NO"]?.ToString(), Name = e.NewValues["Name"]?.ToString(), Address = e.NewValues["Address"]?.ToString(), Phone = e.NewValues["Phone"]?.ToString(), Birthday = string.IsNullOrEmpty(e.NewValues["Birthday"].ToString()) ? default(DateTime?) : Convert.ToDateTime(e.NewValues["Birthday"]), }; var biz = new TestBiz.Master(); int i = biz.Update(entity); if (i == 0) { e.Cancel = true; } else { fvMaster.ChangeMode(FormViewMode.ReadOnly); bindMasterForm(null, entity.ID); bindMaster(null); } }
protected void fvMaster_ItemUpdating(object sender, FormViewUpdateEventArgs e) { int SID = Convert.ToInt32(fvMaster.DataKey.Values[0]); string ID = fvMaster.DataKey.Values[1].ToString(); var entity = new TestMasterInfo { SID = SID, ID = ID, //NO = e.Values["NO"] == null ? null: e.Values["NO"].ToString(), //原本寫法 NO = e.NewValues["NO"]?.ToString(), //精簡寫法 Name = e.NewValues["Name"]?.ToString(), //Address = e.NewValues["Address"]?.ToString(), Address = e.NewValues["Address"]?.ToString().Split(new string[] { ":::" }, System.StringSplitOptions.None)[0], //Address = ((DropDownList)fvMaster.FindControl("ddlAddress")).SelectedValue, Phone = e.NewValues["Phone"]?.ToString(), Birthday = string.IsNullOrEmpty(e.NewValues["Birthday"].ToString())? default(DateTime?) : Convert.ToDateTime(e.NewValues["Birthday"]) }; var biz = new TestBiz.Master(); int i = biz.Update(entity); if (i == 0) { e.Cancel = true; //失敗的話執行這個 } else { fvMaster.ChangeMode(FormViewMode.ReadOnly); bindMasterForm(null, entity.ID); bindMaster(null); } }