public JsonResult GetFormContentField(long formId, string fieldName) { KStarFormData formData = _kStarFormStorageService.GetFormDataById(formId); FormContentModel formContent = formData.FormContent; var model = JObject.Parse(formContent.FormDataToJson); var response = new ResponseMode() { message = KStarForm_Prompt.GetSuccessfully }; response.data = model[fieldName].ToString(); if (model[fieldName] == null) { response.code = 999; response.message = KStarForm_Prompt.GetFailure; } return(Json(response)); }
public async Task <FormContentModel> RetriveContentForAsync(int trustId) { //string sampleCOADataString = "{\"1556\": \"3632.77\", \"1557\": \"-7023.99\", \"1558\": \"88.89\", \"1559\": \"-333.24\", \"1560\": \"8168.60\", \"4000\": \"7871.64\", \"4002\": \"-2986.61\", \"4003\": \"503.84\", \"4004\": \"602.90\", \"4005\": \"27.74\", \"4006\": \"3260.90\", \"4007\": \"1.0\"}"; //object mockRetrivedData = new FormContentModel() //{ // SubmissionId = submissionId, // TrustId = trustId, // DataSourceId = 1, // CoAJsonString = sampleCOADataString //}; object formData = await _dbService.GetFromStagingDBAsync(trustId); var dataString = JsonConvert.SerializeObject(formData); FormContentModel formContent = JsonConvert.DeserializeObject <FormContentModel>(dataString); return(await Task.FromResult(formContent)); }
/// <summary> /// 移除自定义表单实例 /// </summary> /// <param name="keyValue"></param> /// <param name="contentEntity"></param> /// <returns></returns> public int RemoveEntity(string keyValue, Form_ModuleContentEntity contentEntity) { try { FormContentModel contentModel = contentEntity.F_FrmContent.ToObject <FormContentModel>(); if (contentModel.type == "1") { DataBaseLinkService dbService = new DataBaseLinkService(); string strSql = "DELETE FROM " + contentModel.dbTable + " WHERE " + contentModel.dbPkey + " = @" + contentModel.dbPkey; var parameter = new List <DbParameter>(); parameter.Add(DbParameters.CreateDbParameter("@" + contentModel.dbPkey, keyValue)); dbService.ExecuteBySql(contentModel.dbId, strSql, parameter.ToArray()); } return(this.BaseRepository().Delete <FormModuleInstanceEntity>(keyValue)); } catch (Exception) { throw; } }
/// <summary> /// 保存表单模块实例数据 /// </summary> /// <param name="keyValue"></param> /// <param name="entity"></param> /// <param name="contentEntity"></param> /// <returns>主键值</returns> public string SaveEntity(string keyValue, FormModuleInstanceEntity entity, Form_ModuleContentEntity contentEntity) { try { string resKeyValue = ""; FormContentModel contentModel = contentEntity.F_FrmContent.ToObject <FormContentModel>(); switch (contentModel.type) { case "1": DataBaseLinkService dbService = new DataBaseLinkService(); string strSql = ""; var parameter = new List <DbParameter>(); List <FormInstanceModel> filedsData = entity.F_FrmInstanceJson.ToObject <List <FormInstanceModel> >(); if (string.IsNullOrEmpty(keyValue)) { string pkValue = Guid.NewGuid().ToString(); strSql = " INSERT INTO " + contentModel.dbTable + " ( " + contentModel.dbPkey; string sqlValue = "( @" + contentModel.dbPkey; parameter.Add(DbParameters.CreateDbParameter("@" + contentModel.dbPkey, pkValue)); foreach (var item in filedsData) { if (!string.IsNullOrEmpty(item.value)) { strSql += "," + item.field; sqlValue += ",@" + item.field; parameter.Add(DbParameters.CreateDbParameter("@" + item.field, item.value)); } } strSql += " ) VALUES " + sqlValue + ")"; entity.Create(); entity.F_Id = pkValue; dbService.ExecuteBySql(contentModel.dbId, strSql, parameter.ToArray()); this.BaseRepository().Insert(entity); resKeyValue = entity.F_Id; } else { strSql = " UPDATE " + contentModel.dbTable + " SET "; bool isFirst = true; foreach (var item in filedsData) { if (!string.IsNullOrEmpty(item.value)) { if (!isFirst) { strSql += ","; } strSql += item.field + "=@" + item.field; parameter.Add(DbParameters.CreateDbParameter("@" + item.field, item.value)); isFirst = false; } } strSql += " WHERE " + contentModel.dbPkey + "=@" + contentModel.dbPkey; parameter.Add(DbParameters.CreateDbParameter("@" + contentModel.dbPkey, keyValue)); entity.Modify(keyValue); dbService.ExecuteBySql(contentModel.dbId, strSql, parameter.ToArray()); this.BaseRepository().Update(entity); resKeyValue = entity.F_Id; } break; case "0": case "2": if (string.IsNullOrEmpty(keyValue)) //新增 { entity.Create(); this.BaseRepository().Insert(entity); } else //更新 { entity.Modify(keyValue); this.BaseRepository().Update(entity); } resKeyValue = entity.F_Id; break; } return(resKeyValue); } catch (Exception) { throw; } }