public static bool IsValueTableSingle(ConstructItem constructItem, object value, out string errorMsg) { bool isValid = true; errorMsg = ""; ContentFile contentFile = TableContentManager.Instance.GetFileByName(constructItem.ItemType2[0].Name); if (contentFile == null) { errorMsg = "表格无效"; return(false); } string valueType = (string)value; ContentRow contentRow = contentFile.ContentRow.GetRowByID(valueType); if (contentRow == null) { errorMsg = "表格ID无效"; return(false); } return(isValid); }
public ContentItem(ContentRow row, ConstructItem construct, int constructIdx) { _ItemConstruct = construct; _ContructRepeatIndex = constructIdx; ContentRow = row; }
public static bool IsValueEnum(ConstructItem constructItem, object value, out string errorMsg) { bool isValid = true; errorMsg = ""; string valueType = (string)value; if (string.IsNullOrEmpty(valueType)) {//空值直接返回 return(true); } EnumInfo enumInfo = EnumManager.Instance.GetEnum(constructItem.ItemType2[0].Name); if (enumInfo == null) { errorMsg = "枚举无效"; return(false); } EnumItem enumItem = enumInfo.GetEnumItemByValue(valueType); if (enumItem == null) { errorMsg = "枚举值无效"; return(false); } return(isValid); }
public static void ReadItem(ConstructItem constructItem, DataRecord data, ref ContentRow row) { for (int i = 0; i < constructItem.ItemRepeat; ++i) { if (constructItem.ItemCode == "rate") { int test = 1 + 1; } ContentItem contentItem = new ContentItem(row, constructItem, i + 1); string columnName = constructItem.Name; if (constructItem.ItemRepeat > 1) { columnName = (constructItem.Name + (i + 1).ToString()); } columnName = "\"" + columnName + "\""; if (data.HeaderRecord.Contains(columnName)) { contentItem.Value = data[columnName]; } else { contentItem.Value = ""; } row.AddContentItem(contentItem); } }
private static bool IsVector3Valid(ConstructItem constructItem, object value, out string errorMsg) { bool isValid = true; errorMsg = ""; var valueList = ContentItem.GetSplitValue((string)value); if (valueList.Count != 3) { isValid = false; errorMsg = "类型错误"; } foreach (var valueSingle in valueList) { isValid = IsFloatValid(constructItem, valueSingle, out errorMsg); if (!isValid) { break; } } return(isValid); }
private static bool IsBaseTypeValid(ConstructItem constructItem, object value, out string errorMsg) { bool isValid = true; errorMsg = ""; switch (constructItem.ItemType2[0].Name) { case ConstructConfig.ITEM_TYPE_BASE_STRING: isValid = IsStringValid(constructItem, value, out errorMsg); break; case ConstructConfig.ITEM_TYPE_BASE_INT: isValid = IsIntValid(constructItem, value, out errorMsg); break; case ConstructConfig.ITEM_TYPE_BASE_FLOAT: isValid = IsFloatValid(constructItem, value, out errorMsg); break; case ConstructConfig.ITEM_TYPE_BASE_BOOL: isValid = IsBoolValid(constructItem, value, out errorMsg); break; case ConstructConfig.ITEM_TYPE_BASE_VECTOR3: isValid = IsVector3Valid(constructItem, value, out errorMsg); break; } return(isValid); }
private static bool IsStringValid(ConstructItem constructItem, object value, out string errorMsg) { bool isValid = true; errorMsg = ""; return(isValid); }
public GetLookupDataResponse DatasetLookup(string category, bool validItemsOnly) { SqlCommand SqlCommand; GetLookupDataResponse result = new GetLookupDataResponse(); SqlDataReader reader; getDbReader.GetReader(category, validItemsOnly, out SqlCommand, out reader); try { while (reader.Read()) { var CategoryValue = (string)reader["CategoryValue"]; var CategoryName = (string)reader["CategoryName"]; var targetCategory = result.Datasets.Where(o => o.Value == CategoryValue).FirstOrDefault(); if (targetCategory == null) { targetCategory = new Dataset() { Name = CategoryName, Value = CategoryValue }; } targetCategory = ConstructItem.AddItem(targetCategory, reader); result.Datasets.Add(targetCategory); if (result.Datasets == null) { targetCategory = new Dataset() { Name = "Dataset empty", Value = "Dataset empty" }; } } } catch (Exception ex) { var msg = ex.Message; } finally { if (result.Datasets.Count == 0) { result.Datasets.Add(new Dataset() { Name = "Error", Value = "Dataset Not Found" }); } SqlCommand.Connection.Close(); } return(result); }
private string CSTableItemTypeCode(ConstructItem constructItem) { string typeCode = ""; if (constructItem.ItemType1 == ConstructConfig.CONSTRUCT_ITEM_TYPE_BASE) { switch (constructItem.ItemType2[0].Name) { case ConstructConfig.ITEM_TYPE_BASE_INT: typeCode = "int"; break; case ConstructConfig.ITEM_TYPE_BASE_FLOAT: typeCode = "float"; break; case ConstructConfig.ITEM_TYPE_BASE_STRING: typeCode = "string"; break; case ConstructConfig.ITEM_TYPE_BASE_BOOL: typeCode = "bool"; break; case ConstructConfig.ITEM_TYPE_BASE_VECTOR3: typeCode = "Vector3"; break; } } else if (constructItem.ItemType1 == ConstructConfig.CONSTRUCT_ITEM_TYPE_ENUM) { typeCode = constructItem.ItemType2[0].Name; } else if (constructItem.ItemType1 == ConstructConfig.CONSTRUCT_ITEM_TYPE_TABLE_ID) { if (constructItem.ItemType2.Count == 1) { typeCode = constructItem.ItemType2[0].Name + "Record"; } else { typeCode = "MultiTable"; } } if (constructItem.ItemRepeat > 1) { typeCode = "List<" + typeCode + ">"; } return(typeCode); }
public GetLookupDataResponse Get(string category, bool validItemsOnly) { SqlCommand SqlCommand; SqlDataReader reader; // Pass 'category' and 'validItemsOnly' to the DB Reader method getDbReader.GetReader(category, validItemsOnly, out SqlCommand, out reader); try { while (reader.Read()) { var CategoryValue = (string)reader["CategoryValue"]; var CategoryName = (string)reader["CategoryName"]; var targetCategory = result.Datasets.Where(o => o.Value == CategoryValue).FirstOrDefault(); if (targetCategory == null) { targetCategory = new Dataset() { Name = CategoryName, Value = CategoryValue }; } targetCategory = ConstructItem.AddItem(targetCategory, reader); result.Datasets.Add(targetCategory); } } catch (Exception ex) { var msg = ex.Message; } // Check whether datasets exist in the response, after the database reader and constructors have executed. finally { if (result.Datasets.Count == 0) { result.Datasets.Add(new Dataset() { Name = "Error", Value = "Dataset Not Found" }); } SqlCommand.Connection.Close(); } return(result); }
private static bool IsBoolValid(ConstructItem constructItem, object value, out string errorMsg) { bool isValid = true; errorMsg = ""; bool valueType; if (!bool.TryParse((string)value, out valueType)) { isValid = false; errorMsg = "不是布尔型"; } return(isValid); }
private static bool IsFloatValid(ConstructItem constructItem, object value, out string errorMsg) { bool isValid = true; errorMsg = ""; float valueType; if (!float.TryParse((string)value, out valueType)) { isValid = false; errorMsg = "不是32位浮点数数"; } return(isValid); }
private static bool IsIntValid(ConstructItem constructItem, object value, out string errorMsg) { bool isValid = true; errorMsg = ""; int valueInt; if (!Int32.TryParse((string)value, out valueInt)) { isValid = false; errorMsg = "不是32位整数"; } return(isValid); }
public static bool IsValueTableMulti(ConstructItem constructItem, object value, out string errorMsg) { errorMsg = ""; var valueList = ContentItem.GetSplitValue((string)value); if (valueList.Count != 2) { errorMsg = "格式无效"; return(false); } if (string.IsNullOrEmpty(valueList[0]) || string.IsNullOrEmpty(valueList[1])) { errorMsg = ""; return(true); } if (constructItem.ItemType2.GetByName(valueList[0]) == null) { errorMsg = "不支持该表"; return(false); } ContentFile contentFile = TableContentManager.Instance.GetFileByName(valueList[0]); if (contentFile == null) { errorMsg = "表格无效"; return(false); } ContentRow contentRow = contentFile.ContentRow.GetRowByID(valueList[1]); if (contentRow == null) { errorMsg = "表格ID无效"; return(false); } return(true); }
public static bool IsValueValid(ConstructItem constructItem, object value, out string errorMsg) { bool isValid = true; errorMsg = ""; switch (constructItem.ItemType1) { case ConstructConfig.CONSTRUCT_ITEM_TYPE_BASE: isValid = IsBaseTypeValid(constructItem, value, out errorMsg); break; case ConstructConfig.CONSTRUCT_ITEM_TYPE_ENUM: isValid = IsValueEnum(constructItem, value, out errorMsg); break; case ConstructConfig.CONSTRUCT_ITEM_TYPE_TABLE_ID: isValid = IsValueTableIdx(constructItem, value, out errorMsg); break; } return(isValid); }
public static bool IsValueTableIdx(ConstructItem constructItem, object value, out string errorMsg) { bool isValid = true; errorMsg = ""; string valueType = (string)value; if (string.IsNullOrEmpty(valueType)) {//空值直接返回 return(true); } if (constructItem.ItemType2.Count == 1) { isValid = IsValueTableSingle(constructItem, value, out errorMsg); } else { isValid = IsValueTableMulti(constructItem, value, out errorMsg); } return(isValid); }
public static bool IsValueValid(ConstructItem constructItem, object value) { string errorMsg = ""; return(IsValueValid(constructItem, value, out errorMsg)); }
private StringBuilder CSTableItemParseCode(ConstructItem constructItem, int dataIdx, int repeatIdx) { var parseBuilder = new StringBuilder(); string parseValueStart = " = "; string parseValueEnd = ""; if (repeatIdx > -1) { parseValueStart = ".Add("; parseValueEnd = ")"; } if (constructItem.ItemType1 == ConstructConfig.CONSTRUCT_ITEM_TYPE_BASE) { switch (constructItem.ItemType2[0].Name) { case ConstructConfig.ITEM_TYPE_BASE_INT: parseBuilder.Append(" pair.Value." + constructItem.ItemCode + parseValueStart + "TableReadBase.ParseInt(pair.Value.ValueStr[" + dataIdx + "])" + parseValueEnd + ";"); break; case ConstructConfig.ITEM_TYPE_BASE_FLOAT: parseBuilder.Append(" pair.Value." + constructItem.ItemCode + parseValueStart + "TableReadBase.ParseFloat(pair.Value.ValueStr[" + dataIdx + "])" + parseValueEnd + ";"); break; case ConstructConfig.ITEM_TYPE_BASE_STRING: parseBuilder.Append(" pair.Value." + constructItem.ItemCode + parseValueStart + "TableReadBase.ParseString(pair.Value.ValueStr[" + dataIdx + "])" + parseValueEnd + ";"); break; case ConstructConfig.ITEM_TYPE_BASE_BOOL: parseBuilder.Append(" pair.Value." + constructItem.ItemCode + parseValueStart + "TableReadBase.ParseBool(pair.Value.ValueStr[" + dataIdx + "])" + parseValueEnd + ";"); break; case ConstructConfig.ITEM_TYPE_BASE_VECTOR3: parseBuilder.Append(" pair.Value." + constructItem.ItemCode + parseValueStart + "TableReadBase.ParseVector3(pair.Value.ValueStr[" + dataIdx + "])" + parseValueEnd + ";"); break; } } else if (constructItem.ItemType1 == ConstructConfig.CONSTRUCT_ITEM_TYPE_ENUM) { parseBuilder.Append(" pair.Value." + constructItem.ItemCode + parseValueStart + " (" + constructItem.ItemType2[0].Name + ")TableReadBase.ParseInt(pair.Value.ValueStr[" + dataIdx + "])" + parseValueEnd + ";"); } else if (constructItem.ItemType1 == ConstructConfig.CONSTRUCT_ITEM_TYPE_TABLE_ID) { if (constructItem.ItemType2.Count == 1) { parseBuilder.Append(" if (!string.IsNullOrEmpty(pair.Value.ValueStr[" + dataIdx + "]))\n"); parseBuilder.Append(" {\n"); //parseBuilder.Append(" pair.Value.Step.Add(TableReader." + constructItem.ItemType2[0].Name + ".GetRecord(pair.Value.ValueStr[" + dataIdx + "]));\n"); parseBuilder.Append(" pair.Value." + constructItem.ItemCode + parseValueStart + " TableReader." + constructItem.ItemType2[0].Name + ".GetRecord(pair.Value.ValueStr[" + dataIdx + "])" + parseValueEnd + ";"); parseBuilder.Append(" }\n"); parseBuilder.Append(" else\n"); parseBuilder.Append(" {\n"); parseBuilder.Append(" pair.Value." + constructItem.ItemCode + parseValueStart + "null" + parseValueEnd + ";\n"); parseBuilder.Append(" }"); } else { parseBuilder.Append(" pair.Value." + constructItem.ItemCode + parseValueStart + " TableReadBase.ParseMultiTable(pair.Value.ValueStr[" + dataIdx + "])" + parseValueEnd + ";"); } } if (constructItem.ItemRepeat > 1) { //parseBuilder.Append("List<" + parseCode + ">"); } parseBuilder.Append("\n"); //parseBuilder.Append(parseCode); return(parseBuilder); }
private void CSCreateTableItem(ConstructItem constructItem, ref StringBuilder builder) { }