/// <summary> /// 根据职业类型改变对应的DataTable的Row /// </summary> /// <param name="dr">改变的Row</param> /// <param name="hostTable">Row所属的Table</param> private void ChangedRowWithVocation(DataRow dr, DataTable hostTable) { int voc = Int32.Parse(dr[1].ToString()); VOCATION v = (VOCATION)voc; object[] data = dr.ItemArray; //源table和目标table不是同一个 if (!hostTable.TableName.Equals(VocationTableSet[v].TableName)) { //这里不需要事件的参与 DeleteTableEvent(VocationTableSet[v]); DataRow r = VocationTableSet[v].NewRow(); r.ItemArray = data; VocationTableSet[v].Rows.Add(r); //恢复事件 AddTableEvent(VocationTableSet[v]); //如果源table不是all-table,将行从源table中删除。 if (!gSpell_All_DataList.TableName.Equals(hostTable.TableName)) { DeleteTableEvent(hostTable); hostTable.Rows.Remove(dr); //根据所有职业的table构建出总的table BuildAllVocationTableFromSubVocationTable(); spellList.Refresh(); AddTableEvent(hostTable); } } //不是在所有职业的table下修改数据 if (!gSpell_All_DataList.TableName.Equals(hostTable.TableName)) { int VocationCount = 0; foreach (DataTable t in VocationTableSet.Values) { VocationCount += t.Rows.Count; } //所有职业的table行数与 all-table行数相等,则修改数据 if (VocationCount != gSpell_All_DataList.Rows.Count) { DeleteTableEvent(gSpell_All_DataList); DataRow r = gSpell_All_DataList.NewRow(); r.ItemArray = data; gSpell_All_DataList.Rows.Add(r); AddTableEvent(gSpell_All_DataList); } else { } } else { //重新切分数据 DvideDataTableWithVocation(); } }
/// <summary> /// 更新TableRowCountSet /// </summary> private void UpdateVocationTableRowCountSet() { VocationTableRowCountSet[gSpell_All_DataList] = gSpell_All_DataList.Rows.Count; for (VOCATION v = VOCATION.VOCATION_INVALID; v < VOCATION.VOCATION_MAX; v++) { DataTable dt = gSpell_Vocation_DataList[(int)v]; VocationTableRowCountSet[dt] = dt.Rows.Count; } }
/// <summary> /// 初始化配置 /// </summary> public static void InitConfig() { configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigSet = configuration.AppSettings.Settings; VocationFilterList.Add(Vocation_Filter_ALL); // 初始化所有职业 for (VOCATION v = VOCATION.VOCATION_INVALID; v < VOCATION.VOCATION_MAX; v++) { VocationFilterList.Add(DataTableSerializer.vocationNameDict[GetVocationName(v)]); } }
public static bool LoadVocationCSV(string filePath, int rowIndex = 2) { if (string.IsNullOrEmpty(filePath)) { Trace.Error("路径为空!"); return(false); } if (!File.Exists(filePath)) { Trace.Error("文件不存在:" + filePath); return(false); } try { using (StreamReader reader = new StreamReader(filePath, Config.FileEncoding, false)) { reader.ReadLine(); reader.ReadLine(); while (reader.Peek() > 0) { string _line = reader.ReadLine(); string[] _split = _line.Split(','); VOCATION v = (VOCATION)int.Parse(_split[0]); string key = v.ToString(); string name = _split[5]; vocationNameDict.Add(key, name); } vocationNameDict.Add(VOCATION.VOCATION_INVALID.ToString(), "通用技能"); vocationNameDict.Add(VOCATION.VOCATION_RANDOM.ToString(), "随机"); vocationNameDict[VOCATION.VOCATION_MAX.ToString()] = "最大职业"; reader.Close(); return(true); } } catch (ArgumentException e) { string erroMsg; //erroMsg = "[" + i.ToString() + "列," + j.ToString() + "行]参数错误,"; erroMsg = e.Message; Trace.Error(erroMsg); return(false); } }
private void SpellEditorForm_Load(object sender, EventArgs e) { string patch = "../Server/Scp/"; patch += VocationFileName; patch += ".csv"; DataTableSerializer.LoadVocationCSV(patch); Config.InitConfig(); ExportPatchTextBox.Text = Config.GetExportPatch(); ImportPatchTextBox.Text = Config.GetImportPatch(); LogArearInstance = LogArear; BitMaskFlagHelper.PostSpell(); BulidSpellDatable(ref gSpell_All_DataList, Config.Vocation_Filter_ALL); // Build所有职业 for (VOCATION v = VOCATION.VOCATION_INVALID; v < VOCATION.VOCATION_MAX; v++) { BulidSpellDatable(ref gSpell_Vocation_DataList[(int)v], Config.GetVocationName(v)); } // 绑定所有职业 for (VOCATION v = VOCATION.VOCATION_INVALID; v < VOCATION.VOCATION_MAX; v++) { VocationTableSet.Add(v, gSpell_Vocation_DataList[(int)v]); } VocationTableSet = VocationTableSet.OrderBy(o => (int)o.Key).ToDictionary(p => p.Key, o => o.Value); //按VOCATION排一次序 DataTableSerializer.BuildDataGridViewFromDataTable(ref spellList, gSpell_All_DataList, typeof(SPELL.SPELL_DATA)); DataTableSerializer.FillDataGridViewFromDataTable(ref spellList, gSpell_All_DataList); DataTableSerializer.AddButtonToDataGridView(ref spellList, EditButtonHaderText, EditButtonHaderText, EditButtonCallBack); DataTableSerializer.AddButtonToDataGridView(ref spellList, AddButtonHaderText, AddButtonHaderText, AddButtonCallBack); spellList.SelectionChanged += spellList_SelectionChanged; CsvFilecheckBox.Checked = true; VocationFilterList.DataSource = Config.VocationFilterList; Trace.Normal("请点击加载按钮加载配置文件..."); }
/// <summary> /// 改变职业过滤 /// </summary> /// <param name="filter"></param> private void ChangeVocationFilter(string filter) { if (filter != Config.Vocation_Filter_ALL) { bool isFind = false; foreach (KeyValuePair <string, string> kv in DataTableSerializer.vocationNameDict) { if (kv.Value == filter) { filter = kv.Key; isFind = true; break; } } if (!isFind) { return; } } switch (filter) { case Config.Vocation_Filter_ALL: { BuildAllVocationTableFromSubVocationTable(); DataTableSerializer.FillDataGridViewFromDataTable(ref spellList, gSpell_All_DataList); CurrentVocation = VOCATION.VOCATION_MAX; } break; default: { VOCATION v = Config.GetVocationByName(filter); DataTableSerializer.FillDataGridViewFromDataTable(ref spellList, VocationTableSet[v]); CurrentVocation = v; } break; } CurrentVocationFilter = filter; }
/// <summary> /// 把DataTable里的数据按职业切分 /// </summary> private void DvideDataTableWithVocation() { // 清空所有职业数据 for (VOCATION v = VOCATION.VOCATION_INVALID; v < VOCATION.VOCATION_MAX; v++) { gSpell_Vocation_DataList[(int)v].Clear(); } foreach (DataRow dr in gSpell_All_DataList.Rows) { int voc = Int32.Parse(dr[1].ToString()); VOCATION v = (VOCATION)voc; object[] data = dr.ItemArray; DeleteTableEvent(VocationTableSet[v]); DataRow r = VocationTableSet[v].NewRow(); r.ItemArray = data; VocationTableSet[v].Rows.Add(r); //恢复事件 AddTableEvent(VocationTableSet[v]); } }
/// <summary> /// 获取职业对应的名称 /// </summary> /// <param name="voc"></param> /// <returns></returns> public static string GetVocationName(VOCATION voc) { return(Enum.GetName(typeof(VOCATION), voc)); }