public ActionResult BulkAssociate(long[] ids, string AssociatedType, string HostingEntity, string HostingEntityID) { var HostingID = Convert.ToInt64(HostingEntityID); if (HostingID == 0) { return(Json("Error", "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); } if (HostingEntity == "T_Facility" && AssociatedType == "T_FacilityUnit") { foreach (var id in ids.Where(p => p > 0)) { T_Unit obj = db.T_Units.Find(id); db.Entry(obj).State = EntityState.Modified; obj.T_FacilityUnitID = HostingID; db.SaveChanges(); } } return(Json("Success", "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); }
public ActionResult EditQuick(int?id, string UrlReferrer, string HostingEntityName, string AssociatedType, string viewtype) { if (!User.CanEdit("T_Unit") || !CustomAuthorizationBeforeEdit(id, HostingEntityName, AssociatedType)) { return(RedirectToAction("Index", "Error")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (string.IsNullOrEmpty(viewtype)) { viewtype = "EditQuick"; } GetTemplatesForEditQuick(viewtype); T_Unit t_unit = db.T_Units.Find(id); if (t_unit == null) { return(HttpNotFound()); } if (UrlReferrer != null) { ViewData["T_UnitParentUrl"] = UrlReferrer; } if (ViewData["T_UnitParentUrl"] == null && Request.UrlReferrer != null && !Request.UrlReferrer.AbsolutePath.EndsWith("/T_Unit") && !Request.UrlReferrer.AbsolutePath.EndsWith("/T_Unit/Edit/" + t_unit.Id + "") && !Request.UrlReferrer.AbsolutePath.EndsWith("/T_Unit/Create")) { ViewData["T_UnitParentUrl"] = Request.UrlReferrer; } ViewData["HostingEntityName"] = HostingEntityName; ViewData["AssociatedType"] = AssociatedType; LoadViewDataBeforeOnEdit(t_unit); ViewBag.T_UnitIsHiddenRule = checkHidden("T_Unit", "OnEdit", false); ViewBag.T_UnitIsGroupsHiddenRule = checkHidden("T_Unit", "OnEdit", true); ViewBag.T_UnitIsSetValueUIRule = checkSetValueUIRule("T_Unit", "OnEdit"); var objT_Unit = new List <T_Unit>(); ViewBag.T_UnitDD = new SelectList(objT_Unit, "ID", "DisplayValue"); return(View(t_unit)); }
public ActionResult EditQuick([Bind(Include = "Id,ConcurrencyKey,T_FacilityUnitID,T_Name,T_Description")] T_Unit t_unit, string UrlReferrer, bool?IsAddPop, string AssociatedEntity) { string command = Request.Form["hdncommand"]; CheckBeforeSave(t_unit, command); if (ModelState.IsValid) { bool customsave_hasissues = false; if (!CustomSaveOnEdit(t_unit, out customsave_hasissues, command)) { db.Entry(t_unit).State = EntityState.Modified; db.SaveChanges(); } var result = new { Result = "Succeed", UrlRefr = UrlReferrer }; if (!customsave_hasissues) { return(Json(result, "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); } } else { var errors = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { errors += error.ErrorMessage + ". "; } } var result = new { Result = "fail", UrlRefr = errors }; return(Json(result, "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); } LoadViewDataAfterOnEdit(t_unit); ViewBag.T_UnitIsHiddenRule = checkHidden("T_Unit", "OnEdit", false); ViewBag.T_UnitIsGroupsHiddenRule = checkHidden("T_Unit", "OnEdit", true); ViewBag.T_UnitIsSetValueUIRule = checkSetValueUIRule("T_Unit", "OnEdit"); return(View(t_unit)); }
// GET: /T_Unit/Delete/5 public ActionResult Delete(int id) { if (!User.CanDelete("T_Unit") || !CustomAuthorizationBeforeDelete(id)) { return(RedirectToAction("Index", "Error")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } T_Unit t_unit = db.T_Units.Find(id); if (t_unit == null) { throw(new Exception("Deleted")); } if (ViewData["T_UnitParentUrl"] == null && Request.UrlReferrer != null && !Request.UrlReferrer.AbsolutePath.EndsWith("/T_Unit")) { ViewData["T_UnitParentUrl"] = Request.UrlReferrer; } return(View(t_unit)); }
public ActionResult CreateQuick([Bind(Include = "Id,ConcurrencyKey,T_FacilityUnitID,T_Name,T_Description")] T_Unit t_unit, string UrlReferrer, bool?IsAddPop, string AssociatedEntity, string HostingEntityName, string HostingEntityID) { CheckBeforeSave(t_unit); if (ModelState.IsValid) { bool customcreate_hasissues = false; if (!CustomSaveOnCreate(t_unit, out customcreate_hasissues, "Create")) { db.T_Units.Add(t_unit); db.SaveChanges(); } if (!customcreate_hasissues) { return(Json("FROMPOPUP", "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); } } else { var errors = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { errors += error.ErrorMessage + ". "; } } return(Json(errors, "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); } LoadViewDataAfterOnCreate(t_unit); ViewBag.T_UnitIsHiddenRule = checkHidden("T_Unit", "OnCreate", false); ViewBag.T_UnitIsGroupsHiddenRule = checkHidden("T_Unit", "OnCreate", true); ViewBag.T_UnitIsSetValueUIRule = checkSetValueUIRule("T_Unit", "OnCreate"); if (!string.IsNullOrEmpty(AssociatedEntity)) { LoadViewDataForCount(t_unit, AssociatedEntity); } return(View(t_unit)); }
protected override void EditObject() { if (this.gvUnit.GetFocusedRow() == null) { return; } T_Unit unit = this.gvUnit.GetFocusedRow() as T_Unit; CodeEditWindow form = new CodeEditWindow(10, CharacterCasing.Lower, true); form.Code = unit.Code; form.Desc = unit.Desc; form.FormClosed += (o, e) => { unit.Desc = form.Desc; _Proxy.UpdateUnit(unit); this.gvUnit.RefreshData(); }; form.ShowDialog(); }
private void InitUnitList() { UnitList = new List <T_Unit>(); T_Unit unitA = new T_Unit() { Code = "m", Desc = "米" }; T_Unit unitB = new T_Unit() { Code = "t", Desc = "吨" }; T_Unit unitC = new T_Unit() { Code = "g", Desc = "克" }; T_Unit unitD = new T_Unit() { Code = "kg", Desc = "千克" }; T_Unit unitE = new T_Unit() { Code = "¥", Desc = "元" }; T_Unit unitF = new T_Unit() { Code = "$", Desc = "美元" }; UnitList.Add(unitA); UnitList.Add(unitB); UnitList.Add(unitC); UnitList.Add(unitD); UnitList.Add(unitE); UnitList.Add(unitF); }
public void AfterSave(T_Unit t_unit) { // Write your logic here }
public void OnSaving(T_Unit t_unit, ApplicationContext db) { // Write your logic here }
public void OnDeleting(T_Unit t_unit) { // Write your logic here }
private RedirectToRouteResult CustomRedirectUrl(T_Unit t_unit, string action, string command = "") { // Sample Custom implemention below // return RedirectToAction("Index", "T_Unit"); return(null); }
private void CustomLoadViewDataListBeforeEdit(T_Unit t_unit) { }
private void CustomLoadViewDataListAfterOnCreate(T_Unit t_unit) { }
public ActionResult Edit([Bind(Include = "Id,ConcurrencyKey,T_FacilityUnitID,T_Name,T_Description")] T_Unit t_unit, string UrlReferrer) { string command = Request.Form["hdncommand"]; CheckBeforeSave(t_unit, command); if (ModelState.IsValid) { bool customsave_hasissues = false; if (!CustomSaveOnEdit(t_unit, out customsave_hasissues, command)) { db.Entry(t_unit).State = EntityState.Modified; db.SaveChanges(); } if (!customsave_hasissues) { RedirectToRouteResult customRedirectAction = CustomRedirectUrl(t_unit, "Edit", command); if (customRedirectAction != null) { return(customRedirectAction); } if (command != "Save") { if (command == "SaveNextPrev") { long NextPreId = Convert.ToInt64(Request.Form["hdnNextPrevId"]); return(RedirectToAction("Edit", new { Id = NextPreId, UrlReferrer = UrlReferrer })); } else { return(RedirectToAction("Edit", new { Id = t_unit.Id, UrlReferrer = UrlReferrer })); } } if (!string.IsNullOrEmpty(UrlReferrer)) { var uri = new Uri(UrlReferrer); var query = HttpUtility.ParseQueryString(uri.Query); if (Convert.ToBoolean(query.Get("IsFilter")) == true) { return(RedirectToAction("Index")); } else { return(Redirect(UrlReferrer)); } } else { return(RedirectToAction("Index")); } } } // NEXT-PREVIOUS DROP DOWN CODE TempData.Keep(); string json = ""; if (TempData["T_Unitlist"] == null) { json = Newtonsoft.Json.JsonConvert.SerializeObject(db.T_Units.Select(z => new { ID = z.Id, DisplayValue = z.DisplayValue }).ToList()); } else { ViewBag.EntityT_UnitDisplayValueEdit = TempData["T_Unitlist"]; json = Newtonsoft.Json.JsonConvert.SerializeObject(TempData["T_Unitlist"]); } Newtonsoft.Json.JsonSerializerSettings serSettings = new Newtonsoft.Json.JsonSerializerSettings(); serSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(); var lst = Newtonsoft.Json.JsonConvert.DeserializeObject <IEnumerable <object> >(json, serSettings); ViewBag.EntityT_UnitDisplayValueEdit = new SelectList(lst, "ID", "DisplayValue"); // LoadViewDataAfterOnEdit(t_unit); ViewData["T_UnitParentUrl"] = UrlReferrer; ViewBag.T_UnitIsHiddenRule = checkHidden("T_Unit", "OnEdit", false); ViewBag.T_UnitIsGroupsHiddenRule = checkHidden("T_Unit", "OnEdit", true); ViewBag.T_UnitIsSetValueUIRule = checkSetValueUIRule("T_Unit", "OnEdit"); return(View(t_unit)); }
public ActionResult Edit(int?id, string UrlReferrer, string HostingEntityName, string AssociatedType, string defaultview) { if (!User.CanEdit("T_Unit") || !CustomAuthorizationBeforeEdit(id, HostingEntityName, AssociatedType)) { return(RedirectToAction("Index", "Error")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } T_Unit t_unit = db.T_Units.Find(id); // NEXT-PREVIOUS DROP DOWN CODE TempData.Keep(); string json = ""; if (TempData["T_Unitlist"] == null) { json = Newtonsoft.Json.JsonConvert.SerializeObject(db.T_Units.Select(z => new { ID = z.Id, DisplayValue = z.DisplayValue }).ToList()); } else { ViewBag.EntityT_UnitDisplayValueEdit = TempData["T_Unitlist"]; json = Newtonsoft.Json.JsonConvert.SerializeObject(TempData["T_Unitlist"]); } Newtonsoft.Json.JsonSerializerSettings serSettings = new Newtonsoft.Json.JsonSerializerSettings(); serSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(); var lst = Newtonsoft.Json.JsonConvert.DeserializeObject <IEnumerable <object> >(json, serSettings); ViewBag.EntityT_UnitDisplayValueEdit = new SelectList(lst, "ID", "DisplayValue"); // if (t_unit == null) { return(HttpNotFound()); } if (string.IsNullOrEmpty(defaultview)) { defaultview = "Edit"; } GetTemplatesForEdit(defaultview); // NEXT-PREVIOUS DROP DOWN CODE SelectList selitm = new SelectList(lst, "ID", "DisplayValue"); List <SelectListItem> newList = selitm.ToList(); if (Request.UrlReferrer != null && Request.UrlReferrer.AbsolutePath.EndsWith("/T_Unit/Create")) { newList.Insert(0, (new SelectListItem { Text = t_unit.DisplayValue, Value = t_unit.Id.ToString() })); ViewBag.EntityT_UnitDisplayValueEdit = newList; TempData["T_Unitlist"] = newList.Select(z => new { ID = z.Value, DisplayValue = z.Text }); } else if (!newList.Exists(p => p.Value == Convert.ToString(t_unit.Id))) { if (newList.Count > 0) { newList[0].Text = t_unit.DisplayValue; newList[0].Value = t_unit.Id.ToString(); } else { newList.Insert(0, (new SelectListItem { Text = t_unit.DisplayValue, Value = t_unit.Id.ToString() })); } ViewBag.EntityT_UnitDisplayValueEdit = newList; TempData["T_Unitlist"] = newList.Select(z => new { ID = z.Value, DisplayValue = z.Text }); } // if (UrlReferrer != null) { ViewData["T_UnitParentUrl"] = UrlReferrer; } if (ViewData["T_UnitParentUrl"] == null && Request.UrlReferrer != null && !Request.UrlReferrer.AbsolutePath.EndsWith("/T_Unit") && !Request.UrlReferrer.AbsolutePath.EndsWith("/T_Unit/Edit/" + t_unit.Id + "") && !Request.UrlReferrer.AbsolutePath.EndsWith("/T_Unit/Create")) { ViewData["T_UnitParentUrl"] = Request.UrlReferrer; } ViewData["HostingEntityName"] = HostingEntityName; ViewData["AssociatedType"] = AssociatedType; LoadViewDataBeforeOnEdit(t_unit); ViewBag.T_UnitIsHiddenRule = checkHidden("T_Unit", "OnEdit", false); ViewBag.T_UnitIsGroupsHiddenRule = checkHidden("T_Unit", "OnEdit", true); ViewBag.T_UnitIsSetValueUIRule = checkSetValueUIRule("T_Unit", "OnEdit"); return(View(t_unit)); }
public void AddUnit(T_Unit unit) { UnitList.Add(unit); }
public void UpdateUnit(T_Unit unit) { UnitList.Remove(UnitList.Find(o => o.Code == unit.Code)); UnitList.Add(unit); }
private void CustomLoadViewDataListAfterEdit(T_Unit t_unit) { }