public ActionResult List(FormCollection collection, int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null) { //查詢參數 var qm = new CrRegistrationQryModel(); var isOK = this.TryUpdateModel(qm); var token = collection["__RequestVerificationToken"]; var courseId = qm.Q_CourseId; CR_ClassDataTable dt = null; if (!courseId.isNullOrEmpty()) { dt = CrDataService.Instance.CrClass_getListByCourseId(courseId); } else { dt = CrDataService.Instance.CrClass_getList(qm); } //排序 var dtSorted = dt.sort(jtSorting); if (Request.IsAjaxRequest()) { return(converToJTableSource(dtSorted, jtStartIndex, jtPageSize)); } else { return(View(dt)); } }
public CR_ClassDataTable CrClass_createWithCourseId(string courseId, int rowCount = 1) { var dt = new CR_ClassDataTable(); if (rowCount < 0) { rowCount = 0; } for (int i = 0; i < rowCount; i++) { var row = dt.newTypedRow(); row.ns_AssignNewId(); row.CRCL_CourseId = courseId; dt.addTypedRow(row); } dt.ns_linkColumns(new[] { AppDataName.CRCL_CourseCode_XX, AppDataName.CRCL_CourseName_XX, AppDataName.CRCL_CourseEnable_XX, AppDataName.CRCL_StartDate_XX, AppDataName.CRCL_EndDate_XX, AppDataName.CRCL_RegisterStartDate_XX, AppDataName.CRCL_RegisterEndDate_XX }); return(dt); }
public CR_ClassDataTable CrClass_create(int rowCount = 1) { var dt = new CR_ClassDataTable(); if (rowCount < 0) { rowCount = 0; } for (int i = 0; i < rowCount; i++) { var row = dt.newTypedRow(); row.ns_AssignNewId(); dt.addTypedRow(row); } return(dt); }
public ActionResult Edit(FormCollection collection) { var token = collection["__RequestVerificationToken"]; var mode = collection["ViewMode"]; var id = collection[AppDataName.CRCL_ClassId]; var msgOK = "OK"; CR_ClassDataTable dt = null; CR_ClassRow row = null; try { if (mode.equalIgnoreCase("create")) { dt = CrDataService.Instance.CrClass_create(); msgOK = FtdStatus.InsertSuccess.ToString(); } else { //找出該筆資料 dt = CrDataService.Instance.CrClass_getById(id); if (dt == null || dt.Count == 0) { return(Json(new { Result = jTable_ERROR_CODE, Message = "資料不存在" })); } msgOK = FtdStatus.UpdateSuccess.ToString(); } //將Form sumit的資料更新至DataRow row = dt.FirstRow; var isOK = this.TryUpdateModel(row); //若驗證失敗-->回傳錯誤訊息 if (!ModelState.IsValid) { return(Json(new { Result = jTable_ERROR_CODE, Message = string.Join("<br/>", ModelState.Values) })); } #region //驗證欄位 List <string> lstError = new List <string>(); if (row.CRCL_ClassId.isNullOrEmpty()) { lstError.Add("班別ID不能為空"); } if (row.CRCL_CourseId.isNullOrEmpty()) { lstError.Add("課程ID不能為空"); } if (row.CRCL_Code.isNullOrEmpty()) { lstError.Add("班別代號不能為空"); } if (!row.CRCL_LimitQty.HasValue) { lstError.Add("人數限制不能為空"); } if (row.CRCL_ClassDate.isNullOrEmpty()) { lstError.Add("上課日期不能為空"); } if (row.CRCL_ClassTime.isNullOrEmpty()) { lstError.Add("上課時間不能為空"); } if (row.CRCL_Place.isNullOrEmpty()) { lstError.Add("上課地點不能為空"); } if (row.CRCL_Address.isNullOrEmpty()) { lstError.Add("地址不能為空"); } //回傳錯誤訊息 if (lstError.Count > 0) { return(Json(new { Result = jTable_ERROR_CODE, Message = string.Join("<br/>", lstError.ToArray()) })); } //檢查鍵值是否重覆 if (CrDataService.Instance.CrClass_cehckDuplicate(row.CRCL_ClassId, row.CRCL_CourseId, row.CRCL_Code)) { return(Json(new { Result = jTable_ERROR_CODE, Message = "相同鍵值的資料已存在" })); } #endregion dt.ns_update(); dt.AcceptChanges(); return(Json(new { Result = msgOK })); } catch (Exception ex) { return(Json(new { Result = jTable_ERROR_CODE, Message = ex.Message })); } }