private void SetDataContent(ConstructItem item) { if (item == null) { return; } ConstructItemInfoPanel infoPanel = new ConstructItemInfoPanel(); infoPanel.DataContext = item; ContentTransition.ChangeContent(infoPanel, PathContentTranstitionType.NO_ANIM); //ItemAttrPanel.Visibility = System.Windows.Visibility.Visible; //ItemAttrPanel.DataContext = item; //if (item.ItemReadOnly) //{ // this.Name.IsEnabled = false; // this.ItemCode.IsEnabled = false; // this.ItemDefault.IsEnabled = false; // this.ItemRepeat.IsEnabled = false; //} //else { //this.Name.IsEnabled = true; //this.ItemCode.IsEnabled = true; //this.ItemDefault.IsEnabled = true; //this.ItemRepeat.IsEnabled = true; } }
private static bool IsStringValid(ConstructItem constructItem, object value, out string errorMsg) { bool isValid = true; errorMsg = ""; 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; }
public ContentItem(ContentRow row, ConstructItem construct, int constructIdx) { _ItemConstruct = construct; _ContructRepeatIndex = constructIdx; ContentRow = row; }
public ConstructItem CreateNewItem(string name) { ConstructItem item = new ConstructItem(name); item.ItemType2.AddNewItem(new TableBaseItem()); ConstructItems.AddNewItem(item); return item; }
private void Button_New(object sender, RoutedEventArgs e) { if (_ConstructFile != null) { ConstructItem item = _ConstructFile.CreateNewItem(); SetDataContent(item); } }
public static ConstructItem ReadColumn(XmlElement columnEle) { ConstructItem item = new ConstructItem(""); foreach (XmlElement childElement in columnEle.ChildNodes.OfType <XmlElement>()) { if (childElement.Name == ConstructConfig.CONSTRUCT_ELEMENT_NAME) { item.Name = childElement.InnerText; if (item.Name == ConstructConfig.NEW_FILE_DEFAULT_ID_NAME || item.Name == ConstructConfig.NEW_FILE_DEFAULT_NAME_NAME || item.Name == ConstructConfig.NEW_FILE_DEFAULT_DESC_NAME) { item.ItemReadOnly = true; } } if (childElement.Name == ConstructConfig.CONSTRUCT_ELEMENT_CODE) { item.ItemCode = childElement.InnerText; } if (childElement.Name == ConstructConfig.CONSTRUCT_ELEMENT_TYPE1) { item.ItemType1 = childElement.InnerText; } if (childElement.Name == ConstructConfig.CONSTRUCT_ELEMENT_TYPE2) { foreach (XmlElement type2Ele in childElement.ChildNodes.OfType <XmlElement>()) { item.ItemType2.AddNewItem(new TableBaseItem() { Name = type2Ele.InnerText }); } } if (childElement.Name == ConstructConfig.CONSTRUCT_ELEMENT_DEFAULT) { item.ItemDefault = childElement.InnerText; } if (childElement.Name == ConstructConfig.CONSTRUCT_ELEMENT_REPEAT) { item.ItemRepeat = int.Parse(childElement.InnerText); } } if (string.IsNullOrEmpty(item.Name)) { return(null); } return(item); }
private void StackPanel_DataContextChanged_1(object sender, DependencyPropertyChangedEventArgs e) { ConstructItem constructItem = e.NewValue as ConstructItem; if (constructItem == null) { return; } }
public ConstructItem CreateNewItem(string name) { ConstructItem item = new ConstructItem(name); item.ItemType2.AddNewItem(new TableBaseItem()); ConstructItems.AddNewItem(item); return(item); }
private void MenuItem_Remove(object sender, RoutedEventArgs e) { ConstructItem itemInfo = LinkList.SelectedItem as ConstructItem; if (itemInfo == null) { return; } _ConstructFile.ConstructItems.RemoveByName(itemInfo.Name); }
private void Button_DecRelate(object sender, RoutedEventArgs e) { ConstructItem constructItem = this.DataContext as ConstructItem; if (constructItem == null) { return; } constructItem.ItemType2.Remove(constructItem.ItemType2.Last <TableBaseItem>()); }
private void ComboBox_SelectionChanged_1(object sender, SelectionChangedEventArgs e) { ConstructItem constructItem = this.DataContext as ConstructItem; if (constructItem == null) { return; } constructItem.SetDefaultByType(e.AddedItems[0].ToString()); }
public void ConItem_SelectionChanged(object sender, SelectionChangedEventArgs e) { //ItemAttrPanel.Visibility = System.Windows.Visibility.Visible; if (e.AddedItems.Count > 0) { _CurItem = e.AddedItems[0] as ConstructItem; SetDataContent(e.AddedItems[0] as ConstructItem); } //InitItemType1(); }
private void Button_AddRelate(object sender, RoutedEventArgs e) { ConstructItem constructItem = this.DataContext as ConstructItem; if (constructItem == null) { return; } constructItem.ItemType2.AddNewItem(new TableBaseItem()); constructItem.WriteFlag = true; }
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 void ReadFile(FileInfo fileInfo) { XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(fileInfo.FullName); string fileName = fileInfo.Name.Remove(fileInfo.Name.LastIndexOf(".")); ConstructFile file = new ConstructFile(fileName, false); ConstructFold.Instance.AddFile(file); file.Path = fileInfo.FullName.Replace(_ConstructPath, "").Replace(fileInfo.Name, ""); XmlNode root = xmlDoc.SelectSingleNode(ConstructConfig.DOC_ROOT_STR); foreach (XmlElement childElement in root.ChildNodes.OfType <XmlElement>()) { if (childElement.Name == ConstructConfig.CONSTRUCT_TABLE_CLASS) { file.Class = childElement.InnerText; } else if (childElement.Name == ConstructConfig.CONSTRUCT_TABLE_DESC) { file.Desc = childElement.InnerText; } else if (childElement.Name == ConstructConfig.CONSTRUCT_TABLE_OLD_NAME) { file.OldName = childElement.InnerText; } else if (childElement.Name == ConstructConfig.CONSTRUCT_ELEMENT_COLUMN) { ConstructItem item = ReadColumn(childElement); if (item != null) { file.ConstructItems.AddNewItem(item); //重置写标记 item.WriteFlag = false; } } } //重置写标记 file.ConstructItems.WriteFlag = false; file.WriteFlag = false; } catch (Exception e) { } }
private void MenuItem_Rename(object sender, RoutedEventArgs e) { ConstructItem itemInfo = LinkList.SelectedItem as ConstructItem; if (itemInfo == null) { return; } string newName = DialogMessage.DialogString(); if (!string.IsNullOrEmpty(newName)) { itemInfo.Name = newName; } }
public static ConstructItem ReadColumn(XmlElement columnEle) { ConstructItem item = new ConstructItem(""); foreach (XmlElement childElement in columnEle.ChildNodes.OfType<XmlElement>()) { if (childElement.Name == ConstructConfig.CONSTRUCT_ELEMENT_NAME) { item.Name = childElement.InnerText; if (item.Name == ConstructConfig.NEW_FILE_DEFAULT_ID_NAME || item.Name == ConstructConfig.NEW_FILE_DEFAULT_NAME_NAME || item.Name == ConstructConfig.NEW_FILE_DEFAULT_DESC_NAME) { item.ItemReadOnly = true; } } if (childElement.Name == ConstructConfig.CONSTRUCT_ELEMENT_CODE) item.ItemCode = childElement.InnerText; if (childElement.Name == ConstructConfig.CONSTRUCT_ELEMENT_TYPE1) item.ItemType1 = childElement.InnerText; if (childElement.Name == ConstructConfig.CONSTRUCT_ELEMENT_TYPE2) { foreach (XmlElement type2Ele in childElement.ChildNodes.OfType<XmlElement>()) { item.ItemType2.AddNewItem(new TableBaseItem() { Name = type2Ele.InnerText }); } } if (childElement.Name == ConstructConfig.CONSTRUCT_ELEMENT_DEFAULT) item.ItemDefault = childElement.InnerText; if (childElement.Name == ConstructConfig.CONSTRUCT_ELEMENT_REPEAT) item.ItemRepeat = int.Parse(childElement.InnerText); } if (string.IsNullOrEmpty(item.Name)) return null; return item; }
private void MenuItem_New(object sender, RoutedEventArgs e) { ConstructItem itemInfo = LinkList.SelectedItem as ConstructItem; if (itemInfo == null) { return; } int pos = _ConstructFile.ConstructItems.IndexOf(itemInfo); if (_ConstructFile != null) { ConstructItem item = _ConstructFile.CreateNewItem(); SetDataContent(item); _ConstructFile.ConstructItems.MovePosToPos(_ConstructFile.ConstructItems.IndexOf(item), pos); } }
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; }
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 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 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; }
private void SetDataContent(ConstructItem item) { if (item == null) return; ConstructItemInfoPanel infoPanel = new ConstructItemInfoPanel(); infoPanel.DataContext = item; ContentTransition.ChangeContent(infoPanel, PathContentTranstitionType.NO_ANIM); //ItemAttrPanel.Visibility = System.Windows.Visibility.Visible; //ItemAttrPanel.DataContext = item; //if (item.ItemReadOnly) //{ // this.Name.IsEnabled = false; // this.ItemCode.IsEnabled = false; // this.ItemDefault.IsEnabled = false; // this.ItemRepeat.IsEnabled = false; //} //else { //this.Name.IsEnabled = true; //this.ItemCode.IsEnabled = true; //this.ItemDefault.IsEnabled = true; //this.ItemRepeat.IsEnabled = true; } }
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 ConstructFile(string name, bool createDefaultColumn = true) { Name = name; //新建表,自动添加ID,名称,描述项 if (createDefaultColumn) { ConstructItem idItem = CreateNewItem(ConstructConfig.NEW_FILE_DEFAULT_ID_NAME); idItem.ItemCode = ConstructConfig.NEW_FILE_DEFAULT_ID_CODE; idItem.ItemType1 = ConstructConfig.NEW_FILE_DEFAULT_ID_TYPE1; if (idItem.ItemType2.Count != 0) { idItem.ItemType2[0] = new TableBaseItem() { Name = ConstructConfig.NEW_FILE_DEFAULT_ID_TYPE2 }; } else { idItem.ItemType2.AddNewItem(new TableBaseItem() { Name = ConstructConfig.NEW_FILE_DEFAULT_ID_TYPE2 }); } idItem.ItemDefault = ConstructConfig.NEW_FILE_DEFAULT_ID_DEFAULT; idItem.ItemRepeat = ConstructConfig.NEW_FILE_DEFAULT_ID_REPEAT; idItem.ItemReadOnly = true; ConstructItem nameItem = CreateNewItem(ConstructConfig.NEW_FILE_DEFAULT_NAME_NAME); nameItem.ItemCode = ConstructConfig.NEW_FILE_DEFAULT_NAME_CODE; nameItem.ItemType1 = ConstructConfig.NEW_FILE_DEFAULT_NAME_TYPE1; if (nameItem.ItemType2.Count != 0) { nameItem.ItemType2[0] = new TableBaseItem() { Name = ConstructConfig.NEW_FILE_DEFAULT_NAME_TYPE2 }; } else { nameItem.ItemType2.AddNewItem(new TableBaseItem() { Name = ConstructConfig.NEW_FILE_DEFAULT_NAME_TYPE2 }); } nameItem.ItemDefault = ConstructConfig.NEW_FILE_DEFAULT_NAME_DEFAULT; nameItem.ItemRepeat = ConstructConfig.NEW_FILE_DEFAULT_NAME_REPEAT; nameItem.ItemReadOnly = true; ConstructItem descItem = CreateNewItem(ConstructConfig.NEW_FILE_DEFAULT_DESC_NAME); descItem.ItemCode = ConstructConfig.NEW_FILE_DEFAULT_DESC_CODE; descItem.ItemType1 = ConstructConfig.NEW_FILE_DEFAULT_DESC_TYPE1; if (descItem.ItemType2.Count != 0) { descItem.ItemType2[0] = new TableBaseItem() { Name = ConstructConfig.NEW_FILE_DEFAULT_DESC_TYPE2 }; } else { descItem.ItemType2.AddNewItem(new TableBaseItem() { Name = ConstructConfig.NEW_FILE_DEFAULT_DESC_TYPE2 }); } descItem.ItemDefault = ConstructConfig.NEW_FILE_DEFAULT_DESC_DEFAULT; descItem.ItemRepeat = ConstructConfig.NEW_FILE_DEFAULT_DESC_REPEAT; descItem.ItemReadOnly = true; } }
public static void ReadItem(ConstructItem constructItem, DataRecord data, ref ContentRow row) { for (int i = 0; i < constructItem.ItemRepeat; ++i) { 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); } }
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; }
private void CSCreateTableItem(ConstructItem constructItem, ref StringBuilder builder) { }
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 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; }
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 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; }