private void link_ZZO_OrderAmount_XX(ZZ_OrderDataTable dt) { var pks = dt.getPrimaryKeys(); var qrydb = new NsDbQuery(); qrydb.setSelect(s => { var t1 = s.from <ZZ_OrderDetail>(); s.select( t1.ZZOD_OrderId, (t1.ZZOD_Qty.isnull(0) * t1.ZZOD_UnitPrice.isnull(0)).sum().As("Amt") ); s.Where = t1.ZZOD_OrderId.batchin(pks.toConstReq1()); s.groupBy(s.Selects[0]); }); var dt2 = qrydb.queryData(); dt2.Constraints.Add("PK", dt2.Columns[0], true); FtdDataHelper.linkTable(dt, dt2, new FtdDataHelper.LinkInfo(AppDataName.ZZO_OrderId, AppDataName.ZZO_OrderAmount_XX, "Amt", 0)); }
public ZZ_OrderDataTable ZzOrder_create(int rowCount = 1) { var dt = new ZZ_OrderDataTable(); 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 ZZE010Edit(FormCollection collection) { var token = collection["__RequestVerificationToken"]; var mode = collection["ViewMode"]; var id = collection[AppDataName.ZZO_OrderId]; var msgOK = "OK"; ZZ_OrderDataTable dt = null; ZZ_OrderRow row = null; try { if (mode.equalIgnoreCase("create")) { dt = ZzDataService.Instance.ZzOrder_create(); msgOK = FtdStatus.InsertSuccess.ToString(); } else { //找出該筆資料 dt = ZzDataService.Instance.ZzOrder_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) { var errors = ModelState.Values.Where(x => x.Errors.Count > 0).SelectMany(x => x.Errors.Select(y => y.ErrorMessage)).ToArray(); return(Json(new { Result = jTable_ERROR_CODE, Message = string.Join("<br/>", errors) })); } #region //驗證欄位 List <string> lstError = new List <string>(); if (row.ZZO_OrderId.isNullOrEmpty()) { lstError.Add("訂單ID不能為空"); } if (row.ZZO_OrderNo.isNullOrEmpty()) { lstError.Add("訂單號碼不能為空"); } if (!row.ZZO_Date.HasValue) { lstError.Add("訂單日期不能為空"); } if (row.ZZO_Desc.isNullOrEmpty()) { lstError.Add("訂單說明不能為空"); } if (row.ZZO_IsEnable.isNullOrEmpty()) { lstError.Add("啟用不能為空"); } if (row.ZZO_IsEnableName_XX.isNullOrEmpty()) { lstError.Add("啟用不能為空"); } if (!row.ZZO_OrderAmount_XX.HasValue) { lstError.Add("訂單總金額不能為空"); } //回傳錯誤訊息 if (lstError.Count > 0) { return(Json(new { Result = jTable_ERROR_CODE, Message = string.Join("<br/>", lstError.ToArray()) })); } //檢查鍵值是否重覆 if (ZzDataService.Instance.ZzOrder_checkDuplicate(row.ZZO_OrderId, row.ZZO_OrderNo)) { 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 })); } }