public ActionResult Edit(string id, SysField entity) { if (entity != null && ModelState.IsValid) { //数据校验 string currentPerson = GetCurrentPerson(); entity.UpdateTime = DateTime.Now; entity.UpdatePerson = currentPerson; string returnValue = string.Empty; if (m_BLL.Edit(ref validationErrors, entity)) { LogClassModels.WriteServiceLog(Suggestion.UpdateSucceed + ",数据字典信息的Id为" + id, "数据字典" ); //写入日志 return(Json(Suggestion.UpdateSucceed)); //提示更新成功 } else { if (validationErrors != null && validationErrors.Count > 0) { validationErrors.All(a => { returnValue += a.ErrorMessage; return(true); }); } LogClassModels.WriteServiceLog(Suggestion.UpdateFail + ",数据字典信息的Id为" + id + "," + returnValue, "数据字典" ); //写入日志 return(Json(Suggestion.UpdateFail + returnValue)); //提示更新失败 } } return(Json(Suggestion.UpdateFail + "请核对输入的数据的格式")); //提示输入的数据的格式不对 }
public ActionResult Create(SysField entity) { if (entity != null && ModelState.IsValid) { string currentPerson = GetCurrentPerson(); entity.CreateTime = DateTime.Now; entity.CreatePerson = currentPerson; entity.Id = Result.GetNewId(); string returnValue = string.Empty; if (m_BLL.Create(ref validationErrors, entity)) { LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",数据字典的信息的Id为" + entity.Id, "数据字典" );//写入日志 return(Json(Suggestion.InsertSucceed)); } else { if (validationErrors != null && validationErrors.Count > 0) { validationErrors.All(a => { returnValue += a.ErrorMessage; return(true); }); } LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",数据字典的信息," + returnValue, "数据字典" ); //写入日志 return(Json(Suggestion.InsertFail + returnValue)); //提示插入失败 } } return(Json(Suggestion.InsertFail + ",请核对输入的数据的格式")); //提示输入的数据的格式不对 }
private SysField ValidateEntity(SysEntity entity, Dictionary <string, object> valueDict = null) { if (entity == null) { throw new Exception("实体不能为空"); } List <SysField> source = base.Where <SysField>(p => p.EntityId == entity.EntityId); if (source.Count < 1) { throw new Exception("没有定义字段"); } List <SysField> list2 = (from p in source where p.DataType == 1 select p).ToList <SysField>(); if (list2.Count == 0) { throw new Exception("主键未定义"); } if (list2.Count > 1) { throw new Exception("不支持多个主键定义"); } SysField field = list2.First <SysField>(); if (valueDict != null) { if (valueDict.Count < 1) { throw new Exception("没有提供值"); } using (Dictionary <string, object> .KeyCollection.Enumerator enumerator = valueDict.Keys.GetEnumerator()) { while (enumerator.MoveNext()) { Func <SysField, bool> predicate = null; string key = enumerator.Current; if (predicate == null) { predicate = p => p.FieldName == key; } int num = source.Where <SysField>(predicate).Count <SysField>(); if (num == 0) { throw new Exception(string.Format("字段{0}未定义", key)); } if (num > 1) { throw new Exception(string.Format("字段{0}重复定义", key)); } } } } return(field); }
public static SysField GetKeyField(this SysEntity entity, DataContext context) { string key_name = entity.GetKeyFieldName(); SysField field = context.FirstOrDefault <SysField>(f => (f.EntityId == entity.EntityId) && (f.FieldName == key_name)); if (field == null) { throw new ApplicationException(string.Format("没有找到主键字段:{0} -{1}", entity.EntityName, key_name)); } return(field); }
public static long GetDefaultKeyFieldId(this SysEntity entity, DataContext context) { int fieldType = Convert.ToInt32(DataTypeEnum.pkey); SysField field = context.FirstOrDefault <SysField>(f => (f.EntityId == entity.EntityId) && (f.DataType == fieldType)); if (field == null) { throw new ApplicationException(string.Format("实体{0}未定义主键!", entity.EntityName)); } return(field.FieldId); }
public bool Bind(IEnumerable <SysField> entitys, string parentId) { if (!string.IsNullOrEmpty(parentId)) { listTree = (from o in entitys where o.ParentId == parentId select o); } else { listTree = (from o in entitys where o.ParentId == null select o); } //填充数据 if (listTree != null && listTree.Any()) { if (!string.IsNullOrWhiteSpace(parentId)) { SysField t = entitys.Where(o => o.Id == parentId).FirstOrDefault(); if (t != null) { sb.Append(string.Format(@"<fieldset> <legend> <input type=""checkbox"" onclick=""getfather('{0}')"" id=""{0}"" /><label for=""{0}"">{1}</label></legend> <div class=""bigdivshowHeight""> ", !string.IsNullOrWhiteSpace(t.Id) ? t.Id : "allmenus", !string.IsNullOrWhiteSpace(t.MyTexts) ? t.MyTexts : "全部^ReplaceClassMyTexts^")); } } else { sb.Append(string.Format(@"<fieldset style="" width:748px; ""> <legend> <input type=""button"" onclick=""back()"" value=""返回列表"" /> <input type=""button"" onclick=""save()"" value=""保存设置"" /> <input type=""button"" onclick=""allchecked1()"" value=""全部选择"" id=""{0}"" /> <input type=""button"" onclick=""allchecked0()"" value=""全部取消"" id=""unallmenus"" /> </legend> <div class=""bigdivshowHeight2""> ", "allmenus", "全部选择")); } foreach (var item in listTree) { if (Bind(entitys, item.Id)) {//递归调用 Bind sb.Append(string.Format(@" <input type=""checkbox"" onclick=""getson('{0}')"" id=""{0}"" /><label for=""{0}"">{1}</label>", item.Id, item.MyTexts)); } } sb.Append(@"</div></fieldset>"); return(false); } else { return(true); } }
/// <summary> /// 创建一个数据字典 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="db">数据库上下文</param> /// <param name="entity">一个数据字典</param> /// <returns></returns> public bool Create(ref ValidationErrors validationErrors, SysField entity) { try { return(repository.Create(entity) == 1); } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } return(false); }
/// <summary> /// 编辑一个数据字典 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="entity">一个数据字典</param> /// <returns></returns> public bool Edit(ref ValidationErrors validationErrors, SysField entity) { try { repository.Edit(db, entity); return(repository.Save(db) == 1); } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } return(false); }
private string GetChangeFieldDisplayText(SysChangeLog log, SysChangeLogDetail logDetail) { string result = string.Empty; SysEntity entity = this.EntityCache.SysEntity.FirstOrDefault(p => p.EntityName == log.EntityName); if (entity != null) { SysField field = entity.Fields.FirstOrDefault(p => p.FieldName == logDetail.FieldName); if (field != null) { result = field.DisplayText; } } return(result); }
/// <summary> /// 自定义/系统字段操作 添加表列 /// </summary> /// <param name="tableName"></param> /// <param name="mSysField"></param> /// <returns></returns> public string AddTableFieldPackaing(string tableName, SysField mSysField) { StringBuilder addSQL = new StringBuilder(); for (int i = 0; i < mSysField.Name.Length; i++) { addSQL.Append("alter table "); addSQL.Append(tableName); addSQL.Append(" add "); addSQL.Append(mSysField.Name[i]); //类型 addSQL.Append(" "); if (mSysField.TypeLength != null) { addSQL.Append(ToSqlServerType(mSysField.DataType[i], mSysField.TypeLength[i])); } else { addSQL.Append(ToSqlServerType(mSysField.DataType[i], null)); } addSQL.Append(" "); // 列允许空值 if (mSysField.IsNull[i]) { addSQL.Append(" null "); } else // 列不允许空值 { addSQL.Append(" not null "); } // 缺省值 addSQL.Append(" default("); addSQL.Append(ParseDefaultValue(mSysField.DefaultValue[i], mSysField.DataType[i])); addSQL.Append(")"); addSQL.Append(";"); } return(addSQL.ToString()); }
public int DynamicInsert(SysEntity entity, Dictionary <string, object> valueDict) { SysField field = this.ValidateEntity(entity, valueDict); int num = this.GetNextIdentity_Int(false); valueDict[field.FieldName] = num; List <DbParameter> list = new List <DbParameter>(); StringBuilder builder = new StringBuilder(0x400); builder.AppendFormat("insert into {0} (", entity.EntityName); int num2 = 0; foreach (KeyValuePair <string, object> pair in valueDict) { if (num2 > 0) { builder.Append(","); } builder.AppendFormat("{0}", pair.Key); num2++; } builder.Append(")values("); num2 = 0; foreach (KeyValuePair <string, object> pair in valueDict) { if (num2 > 0) { builder.Append(","); } string str = base.AddPrefixToParameterName(pair.Key); builder.Append(str); object obj2 = pair.Value ?? DBNull.Value; int? type = null; DbParameter item = base.CreateParameter(str, obj2, type); list.Add(item); num2++; } builder.Append(")"); Trace.WriteLine(builder.ToString()); base.ExecuteNonQuery(builder.ToString(), list.ToArray()); return(num); }
/// <summary> /// 创建 /// </summary> /// <param name="entity">实体对象</param> /// <returns></returns> public Common.ClientResult.Result Post([FromBody] SysField entity) { Common.ClientResult.Result result = new Common.ClientResult.Result(); if (entity != null && ModelState.IsValid) { //string currentPerson = GetCurrentPerson(); //entity.CreateTime = DateTime.Now; //entity.CreatePerson = currentPerson; entity.Id = Result.GetNewId(); string returnValue = string.Empty; if (m_BLL.Create(ref validationErrors, entity)) { LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",数据字典的信息的Id为" + entity.Id, "数据字典" );//写入日志 result.Code = Common.ClientCode.Succeed; result.Message = Suggestion.InsertSucceed; return(result); //提示创建成功 } else { if (validationErrors != null && validationErrors.Count > 0) { validationErrors.All(a => { returnValue += a.ErrorMessage; return(true); }); } LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",数据字典的信息," + returnValue, "数据字典" );//写入日志 result.Code = Common.ClientCode.Fail; result.Message = Suggestion.InsertFail + returnValue; return(result); //提示插入失败 } } result.Code = Common.ClientCode.FindNull; result.Message = Suggestion.InsertFail + ",请核对输入的数据的格式"; //提示输入的数据的格式不对 return(result); }
public void DynamicUpdate(SysEntity entity, object id, Dictionary <string, object> valueDict) { string str; DbParameter parameter; SysField field = this.ValidateEntity(entity, valueDict); if (valueDict.ContainsKey(field.FieldName)) { valueDict.Remove(field.FieldName); } List <DbParameter> list = new List <DbParameter>(); StringBuilder builder = new StringBuilder(0x400); builder.AppendFormat("update {0} set ", entity.EntityName); int num = 0; foreach (KeyValuePair <string, object> pair in valueDict) { if (pair.Key != field.FieldName) { if (num > 0) { builder.Append(","); } str = base.AddPrefixToParameterName(pair.Key); builder.AppendFormat("{0}={1}", pair.Key, str); object obj2 = pair.Value ?? DBNull.Value; int? type = null; parameter = base.CreateParameter(str, obj2, type); list.Add(parameter); num++; } } builder.Append(" where "); str = base.AddPrefixToParameterName(field.FieldName); builder.AppendFormat("{0}={1}", field.FieldName, str); parameter = base.CreateParameter(str, id, typeof(int)); list.Add(parameter); Trace.WriteLine(builder.ToString()); base.ExecuteNonQuery(builder.ToString(), list.ToArray()); }
public Dictionary <string, object> DynamicFindById(SysEntity entity, object id) { Func <DataColumn, object> elementSelector = null; Dictionary <string, object> dictionary = new Dictionary <string, object>(); SysField field = this.ValidateEntity(entity, null); string name = base.AddPrefixToParameterName(field.FieldName); DbParameter parameter = base.CreateParameter(name, id, typeof(int)); string message = string.Format("select * from {0} where {1} = {2}", entity.EntityName, field.FieldName, name); Trace.WriteLine(message); DataTable dt = base.ExecuteDataTable(message, new DbParameter[] { parameter }); if (dt.Rows.Count != 1) { return(dictionary); } if (elementSelector == null) { elementSelector = p => (dt.Rows[0][p] == DBNull.Value) ? null : dt.Rows[0][p]; } return(dt.Columns.Cast <DataColumn>().ToDictionary <DataColumn, string, object>(p => p.ColumnName.ToLower(), elementSelector)); }
public ActionResult Details(string id) { SysField item = m_BLL.GetById(id); return(View(item)); }
protected void btnNextStep_Click(object sender, EventArgs e) { try { string entityType = this.ddlEntityType.SelectedValue; string displayText = this.txtSysEntity.Text.Trim(); string entityName = "T_" + displayText.ToPingYin(); string formName = this.txtFormName.Text.Trim(); string formTitle = this.txtFormTitle.Text.Trim(); string formDecription = this.txtFormDescription.Text.Trim(); if (string.IsNullOrEmpty(formName)) { throw new Exception("表单名称不能为空"); } using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope()) { using (BizDataContext db = new BizDataContext()) { switch (entityType) { case "0": case "1": if (this.EntityId == null) { throw new Exception("关联实体不能为空"); } break; case "2": if (string.IsNullOrEmpty(displayText)) { throw new Exception("关联实体不能为空"); } if (string.IsNullOrEmpty(entityName)) { throw new Exception("关联实体表名不能为空"); } SysEntity tempEntity = db.FirstOrDefault <SysEntity>(p => p.EntityName == entityName || p.DisplayText == displayText); if (tempEntity != null) { throw new Exception("当前新增的关联实体名称已存在"); } tempEntity = new SysEntity() { EntityId = db.GetNextIdentity(), EntityName = entityName, DisplayText = displayText, Description = displayText, IsFormEntity = true, CreateTime = DateTime.Now, }; db.Insert(tempEntity); this.EntityId = tempEntity.EntityId; //默认加一个主键字段 SysField tempField = new SysField() { FieldId = db.GetNextIdentity(), EntityId = tempEntity.EntityId, FieldName = displayText.ToPingYin() + "_Id", DisplayText = displayText + "ID", Description = displayText + "ID", DataType = (int)DataTypeEnum.pkey, IsFormField = true, //2013-9-24 zhumin }; db.Insert(tempField); break; default: break; } if (this.FormId != null) { SysForm form = db.FindById <SysForm>(this.FormId); if (form != null) { form.FormName = formName; form.EntityId = this.EntityId; form.UpdateTime = DateTime.Now; form.UpdateUserId = this.LoginUserID; form.FormTitle = formTitle; form.FormDescription = formDecription; db.UpdatePartial(form, p => new { p.FormName, p.FormTitle, p.FormDescription, p.EntityId, p.UpdateTime, p.UpdateUserId }); } else { throw new Exception("表单不存在"); } } else { SysForm form = new SysForm() { FormId = db.GetNextIdentity(), FormName = formName, FormTitle = formTitle, FormDescription = formDecription, EntityId = this.EntityId, CreateTime = DateTime.Now, CreateUserId = this.LoginUserID, OwnerId = this.LoginUserID, State = (int)FormState.New, }; db.Insert(form); this.FormId = form.FormId; } } ts.Complete(); } Response.Redirect(string.Format("FormDesigner_SecondStep.aspx?id={0}", this.FormId)); } catch (Exception ex) { this.AjaxAlertAndEnableButton(ex); } }
/// <summary> /// 根据ID获取数据模型 /// </summary> /// <param name="id">编号</param> /// <returns></returns> public SysField Get(string id) { SysField item = m_BLL.GetById(id); return(item); }
/// <summary> /// 选中现有字段并添加为表单字段 /// </summary> /// <param name="sectionId"></param> /// <param name="parameter"></param> /// <returns></returns> private string SelectField(long sectionId, string parameter) { StringBuilder sb = new StringBuilder(); SysFormFieldSection section = this.DataHelper.FindById <SysFormFieldSection>(sectionId); if (section != null) { JavaScriptSerializer js = new JavaScriptSerializer(); object[] fieldList = js.DeserializeObject(parameter) as object[]; if (fieldList == null) { throw new Exception("回调参数不正确"); } var source = fieldList.Select(p => p as Dictionary <string, object>) .Select(p => new { FieldId = p["FieldId"].ToLong(), RelationId = p["RelationId"].ToStringNullable().ToLongNullable(), }); int maxOrder = this.DataHelper.Set <SysFormField>().Where(p => p.FormSectionId == sectionId).Max(p => p.DisplayOrder ?? 0); using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope()) { using (BizDataContext db = new BizDataContext()) { foreach (var p in source) { SysField field = this.EntityCache.FindById <SysField>(p.FieldId); if (field == null) { field = db.FindById <SysField>(p.FieldId); } if (field != null) { SysFormField ff = new SysFormField() { FormFieldId = db.GetNextIdentity(), FormSectionId = sectionId, FormId = section.FormId, FieldId = p.FieldId, RelationId = p.RelationId, DisplayOrder = ++maxOrder, EntityId = field.EntityId, DataType = field.DataType, IsNullable = true, CreateUserId = this.LoginUserID, CreateTime = DateTime.Now, }; db.Insert(ff); sb.AppendFormat("<div id=\"{0}\" class=\"field unselected\" onclick=\"Select(this);\">{1}</div>", ff.FormFieldId, field.DisplayText); } else { throw new Exception("找不到关联字段"); } } } ts.Complete(); } } else { throw new Exception("找不到表单段落"); } return(sb.ToString()); }
/// <summary> /// 自定义/系统字段操作 往字段表中插入记录 /// </summary> /// <param name="mSysField"></param> /// <param name="id"></param> /// <param name="modelID"></param> /// <param name="orders"></param> /// <returns></returns> public string InsertModelFieldRowPackaing(SysField mSysField, string[] id, string modelID, int[] orders) { StringBuilder insertSQL; insertSQL = new StringBuilder(); for (int i = 0; i < id.Length; i++) { insertSQL.Append("if not exists(select top 1 * from K_ModelField where Name='" + mSysField.Name[i] + "' and ModelId='" + modelID + "')"); insertSQL.Append("insert into K_ModelField(ID,ModelFieldGroupId,ModelID,Name,FieldAlias,IsSystemFiierd,IsInputValue,Orders,IsSearch,IsListEnable,SystemFirerdHtml,SysFieldType,TextBoxMaxLength,TextBoxWidth,TextBoxHieght)"); insertSQL.Append("values('"); insertSQL.Append(id[i]); // ID字段 主键 insertSQL.Append("','"); insertSQL.Append("0"); // 所属模型组 insertSQL.Append("','"); insertSQL.Append(modelID); // 所属模型 insertSQL.Append("','"); insertSQL.Append(mSysField.Name[i]); // 字段名称 insertSQL.Append("','"); insertSQL.Append(mSysField.Alias[i]); // 别名 insertSQL.Append("',"); insertSQL.Append(1); // 是否是系统字段 insertSQL.Append(","); if (mSysField.IsEdit) { insertSQL.Append(0); // 在编辑页解析显示 } else { insertSQL.Append(0); // 不在编辑页解析显示 } insertSQL.Append(","); insertSQL.Append(orders[i]); // 排序 insertSQL.Append(","); if (mSysField.IsSearch) // 是否搜索 { insertSQL.Append(0); } else { insertSQL.Append(0); } insertSQL.Append(","); if (mSysField.IsList) // 是否在列表页显示 { insertSQL.Append(1); } else { insertSQL.Append(0); } insertSQL.Append(",'"); insertSQL.Append(mSysField.ID); insertSQL.Append("',1,512,180,40"); insertSQL.Append(");"); } return(insertSQL.ToString()); }
/// <summary> /// 获取解析后的预定义字段的设置 /// </summary> /// <param name="originalValue"></param> /// <param name="chklSysFieldSelectedValue"></param> /// <returns>[0] 需要删除 [1] 需要添加</returns> public List <SysField>[] GetSysField(string originalValue, string chklSysFieldSelectedValue) { string configPath; // 自定义字段配置文件路径 string xpath; // 获取根节点的xpath语句 XPathNodeIterator navNodeXPath; // 系统自定义配置根节点指针 XPathNodeIterator currentNav; // 临时指针 string currentValue; // 需更新的值列 string[] originalNodeID; // 更新前的配置节点ID string[] currentNodeID; // 需要更新的字段配置节点ID List <SysField> originalField; // 更新前的自定义(系统)字段模(节点) List <SysField> currentField; // 需更新的自定义(系统)字段模(节点) List <SysField>[] returnValue; List <string[]> lstSysFieldID; // [0] 要删除 [1] 要添加 currentValue = chklSysFieldSelectedValue; originalField = new List <SysField>(); currentField = new List <SysField>(); returnValue = new List <SysField> [2]; // 没有更改链接选择则返回 if (string.Equals(originalValue, currentValue)) { return(returnValue); } configPath = AppDomain.CurrentDomain.BaseDirectory + Utils.GetResourcesValue("Model", "SysFieldPath"); xpath = "/config"; navNodeXPath = GetNodeIterator(configPath, xpath); lstSysFieldID = CHKLValueGrouped(originalValue, currentValue); currentNodeID = lstSysFieldID[1]; originalNodeID = lstSysFieldID[0]; if (navNodeXPath != null && navNodeXPath.Count > 0) { navNodeXPath.MoveNext(); } // 选择的字段 if (currentNodeID.Length > 0) { // 遍历数组中的ID获取<field>节点的字段配置信息 foreach (string fieldID in currentNodeID) { if (!string.IsNullOrEmpty(fieldID)) { currentNav = navNodeXPath.Current.Select("field[@id=" + fieldID + "]"); } else { continue; } if (currentNav != null && currentNav.Count > 0) { currentNav.MoveNext(); } else { continue; } SysField temp = new SysField(); try { temp.ID = currentNav.Current.GetAttribute("id", ""); temp.Title = currentNav.Current.GetAttribute("title", ""); if (currentNav.Current.SelectSingleNode("name") != null) { temp.Name = ToStringArray(currentNav.Current.SelectSingleNode("name").Value); } if (currentNav.Current.SelectSingleNode("alias") != null) { temp.Alias = ToStringArray(currentNav.Current.SelectSingleNode("alias").Value); } if (currentNav.Current.SelectSingleNode("sql") != null) { temp.DataType = ToStringArray(currentNav.Current.SelectSingleNode("sql").GetAttribute("type", "")); // 只有为字符串类型时来有此属性 if (currentNav.Current.SelectSingleNode("sql").GetAttribute("length", "") != null) { temp.TypeLength = ToIntArray(currentNav.Current.SelectSingleNode("sql").GetAttribute("length", "")); } else { temp.TypeLength = null; } temp.DefaultValue = ToStringArray(currentNav.Current.SelectSingleNode("sql").GetAttribute("default", "")); temp.IsNull = ToBollArray(currentNav.Current.SelectSingleNode("sql").GetAttribute("isnull", "")); } if (currentNav.Current.SelectSingleNode("search") != null) { temp.IsSearch = Utils.ParseBool(currentNav.Current.SelectSingleNode("search").GetAttribute("enable", "")); } if (currentNav.Current.SelectSingleNode("list") != null) { temp.IsList = Utils.ParseBool(currentNav.Current.SelectSingleNode("list").GetAttribute("enable", "")); } if (currentNav.Current.SelectSingleNode("edit") != null) { temp.IsEdit = Utils.ParseBool(currentNav.Current.SelectSingleNode("edit").GetAttribute("enable", "")); } currentField.Add(temp); } catch { currentField = null; // 异常提示信息:链接配置文件读取异常 } } } // 取消的字段 if (originalNodeID.Length > 0) { // 遍历数组中的ID获取<field>节点的字段配置信息 foreach (string fieldID in originalNodeID) { if (!string.IsNullOrEmpty(fieldID)) { currentNav = navNodeXPath.Current.Select("field[@id=" + fieldID + "]"); } else { continue; } if (currentNav != null && currentNav.Count > 0) { currentNav.MoveNext(); } else { continue; } SysField temp = new SysField(); try { temp.ID = currentNav.Current.GetAttribute("id", ""); temp.Title = currentNav.Current.GetAttribute("title", ""); if (currentNav.Current.SelectSingleNode("name") != null) { temp.Name = ToStringArray(currentNav.Current.SelectSingleNode("name").Value); } if (currentNav.Current.SelectSingleNode("alias") != null) { temp.Alias = ToStringArray(currentNav.Current.SelectSingleNode("alias").Value); } if (currentNav.Current.SelectSingleNode("sql") != null) { temp.DataType = ToStringArray(currentNav.Current.SelectSingleNode("sql").GetAttribute("type", "")); // 只有为字符串类型时来有此属性 if (currentNav.Current.SelectSingleNode("sql").GetAttribute("length", "") != null) { temp.TypeLength = ToIntArray(currentNav.Current.SelectSingleNode("sql").GetAttribute("length", "")); } else { temp.TypeLength = null; } temp.DefaultValue = ToStringArray(currentNav.Current.SelectSingleNode("sql").GetAttribute("default", "")); temp.IsNull = ToBollArray(currentNav.Current.SelectSingleNode("sql").GetAttribute("isnull", "")); } if (currentNav.Current.SelectSingleNode("search") != null) { temp.IsSearch = Utils.ParseBool(currentNav.Current.SelectSingleNode("search").GetAttribute("enable", "")); } if (currentNav.Current.SelectSingleNode("list") != null) { temp.IsList = Utils.ParseBool(currentNav.Current.SelectSingleNode("list").GetAttribute("enable", "")); } if (currentNav.Current.SelectSingleNode("edit") != null) { temp.IsList = Utils.ParseBool(currentNav.Current.SelectSingleNode("edit").GetAttribute("enable", "")); } originalField.Add(temp); } catch { // 异常提示信息:链接配置文件读取异常 originalField = null; } } } returnValue[0] = originalField; returnValue[1] = currentField; return(returnValue); }
internal EntityData LoadFullWithEntity(SysEntity entity, int object_id, ProcessInstanceCacheFactory piCacheFactory) { EntityData data = null; Type tableType = TableCache.GetTableType(entity.EntityName); object obj2 = this.context.FindById(tableType, new object[] { object_id }); if (obj2 != null) { data = ObjectToEntityData(obj2, entity); } if (data != null) { EntityCache cache = new EntityCache(this); using (IEnumerator <SysField> enumerator = entity.Fields.GetEnumerator()) { while (enumerator.MoveNext()) { Func <SysEnumItem, bool> predicate = null; SysField p = enumerator.Current; if (p.DataType == 12) { if ((p.RefEntity != null) && (data[p.FieldName] != null)) { string displayFieldName = p.RefEntity.GetDisplayFieldName(); EntityData da = cache.GetObject(p.RefEntity, (int)data[p.FieldName]); if (da == null) { throw new ApplicationException(string.Format("[{0}]-[{1}]的引用字段[{2}]有值[{3}],但是对应的[{4}]不存在", new object[] { entity.EntityName, object_id, p.FieldName, data[p.FieldName], p.RefEntity.EntityName })); } if (da.ContainsKey(displayFieldName)) { da[p.FieldName] = data[displayFieldName]; } } } else { if (p.DataType == 13) { if (((p.RefEnum != null) && (p.RefEnum.EnumItems != null)) && (data[p.FieldName] != null)) { if (predicate == null) { predicate = delegate(SysEnumItem i) { int?itemValue = i.ItemValue; int num = (int)data[p.FieldName]; return((itemValue.GetValueOrDefault() == num) && itemValue.HasValue); }; } SysEnumItem item = p.RefEnum.EnumItems.FirstOrDefault <SysEnumItem>(predicate); if (item != null) { data[p.FieldName] = item.DisplayText; } } continue; } if (p.DataType == 11) { if (data[p.FieldName].ToInt() == 0) { data[p.FieldName] = "否"; } else { data[p.FieldName] = "是"; } continue; } if ((p.DataType == 15) && (data[p.FieldName] != null)) { string[] source = data[p.FieldName].ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (source.Count <string>() != 2) { throw new ApplicationException(string.Format("[{0}]中[entity_id]或者[object_id]缺失", data[p.FieldName])); } long entityId = source[0].ToLong(); int num2 = source[1].ToInt(); SysEntity entityCache = piCacheFactory.PCacheFactory.GetEntityCache(entityId); if (entityCache != null) { string key = entityCache.GetDisplayFieldName(); EntityData data2 = cache.GetObject(entityCache, num2); if (data2 == null) { throw new ApplicationException(string.Format("[{0}]-[{1}]的引用字段[{2}]有值[{3}],但是对应的[{4}]不存在", new object[] { entity.EntityName, num2, p.FieldName, data[p.FieldName], entityCache.EntityName })); } if (data2.ContainsKey(key)) { data[p.FieldName] = data2[key]; } } } } } } } return(data); }
/// <summary> /// 新增表单字段 /// </summary> /// <param name="sectionId"></param> /// <param name="parameter"></param> /// <param name="otherContent"></param> /// <returns></returns> private string NewField(long sectionId, string parameter, ref object otherContent) { string result = string.Empty; SysFormFieldSection section = this.DataHelper.FindById <SysFormFieldSection>(sectionId); if (section != null) { SysForm form = this.DataHelper.FindById <SysForm>(section.FormId); if (form == null) { throw new Exception("表单不存在"); } JavaScriptSerializer js = new JavaScriptSerializer(); var valueDict = js.DeserializeObject(parameter) as Dictionary <string, object>; if (valueDict == null) { throw new Exception("回调参数不正确"); } string displayText = valueDict["DisplayText"].ToStringNullable(); string fieldName = valueDict["FieldName"].ToStringNullable(); int? dataType = valueDict["DataType"].ToStringNullable().ToIntNullable(); int temp = this.DataHelper.Set <SysField>().Where(p => p.EntityId == form.EntityId && (p.DisplayText == displayText || p.FieldName == fieldName)).Count(); if (temp > 0) { throw new Exception("当前新增的字段名称已经存在"); } int maxOrder = this.DataHelper.Set <SysFormField>().Where(p => p.FormSectionId == sectionId).Max(p => p.DisplayOrder ?? 0); using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope()) { using (BizDataContext db = new BizDataContext()) { //新增字段 SysField field = new SysField() { FieldId = db.GetNextIdentity(), DisplayText = displayText, FieldName = fieldName, EntityId = form.EntityId, Description = displayText, DataType = dataType, IsFormField = true,//2013-9-24 zhumin }; db.Insert(field); //新增表单字段 SysFormField ff = new SysFormField() { FormFieldId = db.GetNextIdentity(), FormSectionId = sectionId, EntityId = form.EntityId, DisplayOrder = maxOrder + 1, FormId = form.FormId, FieldId = field.FieldId, DataType = field.DataType, IsNullable = true, CreateTime = DateTime.Now, CreateUserId = this.LoginUserID, }; db.Insert(ff); result = string.Format("<div id=\"{0}\" class=\"field unselected\" onclick=\"Select(this);\">{1}</div>", ff.FormFieldId, field.DisplayText); otherContent = string.Format("<div class=\"divField\"><span><input type=\"checkbox\" fid=\"{0}\" /></span><span>{1}</span><span>{2}</span></div>", field.FieldId, field.DisplayText, field.FieldName); } ts.Complete(); } } return(result); }