/// <summary> /// Open existing worksheet or add one and populate it if the sheet does not exist /// </summary> public void OpenWorksheet(string sheetName) { if (content.Worksheets[sheetName] == null) { content.Worksheets.Add(sheetName); SpreadsheetTemplates.SpreadsheetPresetType type = helper.GetSheetType(sheetName); switch (type) { case SpreadsheetTemplates.SpreadsheetPresetType.AREA: { InitAreaSheet(sheetName); currentSheet = content.Worksheets[sheetName]; helper.AutoAdjustColumns(currentGroupsByName.Values); return; } case SpreadsheetTemplates.SpreadsheetPresetType.ENEMY: { InitMobSheet(sheetName); currentSheet = content.Worksheets[sheetName]; helper.AutoAdjustColumns(currentGroupsByName.Values); return; } } } if (!sheetToAdresses.ContainsKey(sheetName)) { Dicts dicts = SpreadsheetHelper.LoadSpreadsheet(content, sheetName, helper.GetSheetType(sheetName)); sheetToAdresses.Add(sheetName, dicts.addresses); sheetToGroups.Add(sheetName, dicts.groups); } currentSheet = content.Worksheets[sheetName]; }
protected void lnk_Delete_Click(object sender, System.EventArgs e) { if (!base.IsAuthorizedOp(ActionType.Delete.ToString())) { base.ShowAjaxMsg(this.UpdatePanel1, "Không có thẩm quyền"); } else { int @int = WebUtils.GetInt((sender as LinkButton).CommandArgument); DictsInfo dataById = Dicts.GetDataById(@int); if (dataById == null) { base.ShowAjaxMsg(this.UpdatePanel1, "Những thông tin này không được tìm thấy, các dữ liệu không tồn tại hoặc đã bị xóa"); } else if (dataById.IsSystem) { base.ShowAjaxMsg(this.UpdatePanel1, "Từ điển hệ thống không thể bị xóa"); } else if (Dicts.Delete(@int)) { this.BindData(); PageBase.log.AddEvent(base.LoginAccount.AccountName, "xóa từ điển[" + dataById.DictName + "] thành công"); base.ShowAjaxMsg(this.UpdatePanel1, "Thao tác thành công"); } else { base.ShowAjaxMsg(this.UpdatePanel1, "Thao tác thất bại"); } } }
public Dicts InitializeMobSheet(string mobName, MobAsociatedDrops data) { Dicts d = new Dicts(true); interaction.InsertValue(new ExcelCellAddress(1, 1), "Spreadsheet for enemy: " + interaction.currentSheet.Name); interaction.InsertValue(new ExcelCellAddress(1, 4), "Num killed:"); interaction.InsertValue(new ExcelCellAddress(1, 5), 0); Dictionary <string, string[]> itemEntries = Program.gameRecognizer.enemyHandling.mobDrops.GetDropsForMob(mobName); ExcelCellAddress startAddr = new ExcelCellAddress("A2"); foreach (string key in itemEntries.Keys) { interaction.currentSheet.Cells[startAddr.Address].Value = key; for (int i = 0; i < itemEntries[key].Length; i++) { int _offset = i + 1; ExcelCellAddress itemName = new ExcelCellAddress(startAddr.Row + _offset, startAddr.Column); ExcelCellAddress yangVal = new ExcelCellAddress(startAddr.Row + _offset, startAddr.Column + 1); ExcelCellAddress totalDroped = new ExcelCellAddress(startAddr.Row + _offset, startAddr.Column + 2); interaction.InsertValue(itemName, itemEntries[key][i]); d.addresses.Add(itemEntries[key][i], totalDroped); interaction.InsertValue(yangVal, DefinitionParser.instance.currentGrammarFile.GetYangValue(itemEntries[key][i])); interaction.InsertValue(totalDroped, 0); } startAddr = new ExcelCellAddress(2, startAddr.Column + 4); } interaction.Save(); return(d); }
public void MergeTest() { var dictionary1 = new Dictionary <int, int> { { 1, 2 } }; var dictionary2 = new Dictionary <int, int> { { 3, 4 } }; var dictionary3 = new Dictionary <int, int> { { 5, 6 } }; var kvp = new KeyValuePair <int, int>(7, 8); dictionary1.Count.ShouldBe(1); dictionary2.Count.ShouldBe(1); dictionary3.Count.ShouldBe(1); Dicts.Add(dictionary1, dictionary2); dictionary1.Count.ShouldBe(2); dictionary2.Count.ShouldBe(1); dictionary3.Count.ShouldBe(1); dictionary1.Add(dictionary3); dictionary1.Count.ShouldBe(3); dictionary2.Count.ShouldBe(1); dictionary3.Count.ShouldBe(1); dictionary1.Add(kvp); dictionary1.Count.ShouldBe(4); dictionary2.Count.ShouldBe(1); dictionary3.Count.ShouldBe(1); }
public void AddValueOrUpdateTest() { var dictionary = new Dictionary <int, int> { { 1, 2 } }; dictionary.Count.ShouldBe(1); dictionary[1].ShouldBe(2); Dicts.AddValueOrUpdate(dictionary, 1, k => 200, (k, v) => v * 111); dictionary.Count.ShouldBe(1); dictionary[1].ShouldBe(222); Dicts.AddValueOrUpdate(dictionary, 2, k => 200, (k, v) => v * 111); dictionary.Count.ShouldBe(2); dictionary[1].ShouldBe(222); dictionary[2].ShouldBe(200); dictionary.AddValueOrUpdate(2, k => 200, (k, v) => v * 111); dictionary.AddValueOrUpdate(3, k => 300, (k, v) => v * 111); dictionary.Count.ShouldBe(3); dictionary[1].ShouldBe(222); dictionary[2].ShouldBe(22200); dictionary[3].ShouldBe(300); }
/// <summary> /// 添加字典数据 /// </summary> /// <param name="catalog"></param> /// <param name="project"></param> /// <param name="subject"></param> /// <param name="dType"></param> /// <param name="dName"></param> /// <param name="dValue"></param> /// <param name="parentID"></param> protected virtual void addDict(Catalog catalog, Project project, Subject subject, string dType, string dName, string dValue, string parentID) { //删除相同的项目 ConnectionManager.Context.table("Dicts").where ("ParentDictID = '" + parentID + "'" + (catalog != null ? (" and CatalogID = '" + catalog.CatalogID + "'") : string.Empty) + (project != null ? (" and ProjectID = '" + project.ProjectID + "'") : string.Empty) + (subject != null ? (" and SubjectID = '" + subject.SubjectID + "'") : string.Empty) + " and DictType = '" + dType + "' and DictName = '" + dName + "'").delete(); Dicts dict = new Dicts(); dict.DictID = Guid.NewGuid().ToString(); if (catalog != null) { dict.CatalogID = catalog.CatalogID; } if (project != null) { dict.ProjectID = project.ProjectID; } if (subject != null) { dict.SubjectID = subject.SubjectID; } dict.DictType = dType; dict.DictName = dName; dict.DictValue = dValue; dict.ParentDictID = parentID; dict.copyTo(ConnectionManager.Context.table("Dicts")).insert(); }
private void BindCert() { this.DropDownList12.DataSource = Dicts.GetCacheDictsByName("CertType").Items; this.DropDownList12.DataTextField = "KeyValue"; this.DropDownList12.DataValueField = "KeyName"; this.DropDownList12.DataBind(); }
static Namer() { var d = new Dicts(); Adjectives = d.Adjectives; Nouns = d.Nouns; _random = new Random(); }
public void SetValueWithKeyNotExistsTest() { var dictionary = new Dictionary <int, int>(); Dicts.SetValue(dictionary, 1, 100); dictionary.Count.ShouldBe(1); dictionary[1].ShouldBe(100); }
private void BindData() { int recordCount = 0; int num = 0; string strSort = "AutoID DESC"; this.Repeater1.DataSource = Dicts.GetPagerList(this.GetCondition(), strSort, this.SinGooPager1.PageIndex, this.SinGooPager1.PageSize, ref recordCount, ref num); this.Repeater1.DataBind(); this.SinGooPager1.RecordCount = recordCount; }
private void BindData() { DictsInfo dataById = Dicts.GetDataById(base.OpID); if (dataById != null) { this.Repeater1.DataSource = dataById.Items; this.Repeater1.DataBind(); } }
public void GetOrDefaultFromDictionaryAndReturnSystemValueTest() { var dictionary = new Dictionary <int, int> { { 1, 2 }, { 3, 4 }, { 5, 6 } }; var val1 = Dicts.GetValueOrDefault(dictionary, 1); var val2 = Dicts.GetValueOrDefault(dictionary, 7); val1.ShouldBe(2); val2.ShouldBe(default);
private void InitForModify() { DictsInfo dataById = Dicts.GetDataById(base.OpID); this.TextBox1.Text = dataById.DictName; if (dataById.IsSystem) { this.TextBox1.Enabled = false; } this.TextBox2.Text = dataById.DisplayName; }
public void InitAreaSheet(string areaName) { _currentSheet = content.Worksheets[areaName]; Dicts dicts = templates.InitializeAreaSheet(DefinitionParser.instance.currentGrammarFile); if (!sheetToAdresses.ContainsKey(areaName)) { sheetToAdresses.Add(areaName, dicts.addresses); sheetToGroups.Add(areaName, dicts.groups); } Save(); }
protected void Page_Load(object sender, System.EventArgs e) { this.dictCurrent = Dicts.GetDataById(WebUtils.GetQueryInt("dictid")); if (this.dictCurrent == null) { base.ShowMsgAndRdirect("Chúng tôi không tìm thấy thông tin từ điển, lỗi thông số", base.Request.UrlReferrer.ToString()); } else if (base.IsEdit && !base.IsPostBack) { this.InitForModify(); } }
public void InitMobSheet(string mobName) { _currentSheet = content.Worksheets[mobName]; Dicts dicts = templates.InitializeMobSheet(mobName, Program.gameRecognizer.enemyHandling.mobDrops); if (!sheetToAdresses.ContainsKey(mobName)) { sheetToAdresses.Add(mobName, dicts.addresses); sheetToGroups.Add(mobName, dicts.groups); } Save(); }
/// <summary> /// 更新があるかどうかを確認します。 /// </summary> /// <param name="infos"></param> /// <returns></returns> protected override bool CheckUpdate(ImageInfo[] infos) { foreach (var info in infos) { var dict = Dicts.FirstOrDefault(d => d.SpritesWithActualPath.ContainsKey(info.Path)); if (dict == null || dict.SpritesWithActualPath[info.Path].LastWriteTime != info.LastWriteTime) { return(false); } } return(true); }
public Dicts InitializeAreaSheet(DefinitionParserData data) { Dicts d = new Dicts(true); interaction.InsertValue(new ExcelCellAddress(1, 1), "Spreadsheet for zone: " + interaction.currentSheet.Name); int[] rowOfEachGroup = new int[data.groups.Length]; int[] columnOfEachGroup = new int[data.groups.Length]; int groupcounter = 0; foreach (string group in data.groups) { rowOfEachGroup[groupcounter] = 2; columnOfEachGroup[groupcounter] = groupcounter * columnOffset + 1; ExcelCellAddress address = new ExcelCellAddress(rowOfEachGroup[groupcounter], columnOfEachGroup[groupcounter]); interaction.currentSheet.Select(new ExcelAddress(address.Row, address.Column, address.Row, address.Column + 2)); ExcelRange r = interaction.currentSheet.SelectedRange; r.Merge = true; r.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; interaction.InsertValue(address, group); groupcounter += 1; SpreadsheetInteraction.Group g = new SpreadsheetInteraction.Group(address, new ExcelCellAddress(address.Row + 1, address.Column), new ExcelCellAddress(address.Row + 1, address.Column + 1), new ExcelCellAddress(address.Row + 1, address.Column + 2)); d.groups.Add(group, g); } foreach (DefinitionParserData.Item entry in data.entries) { SpreadsheetInteraction.Group g = d.groups[entry.group]; g.totalEntries++; d.groups[entry.group] = g; for (int i = 0; i < data.groups.Length; i++) { if (data.groups[i] == entry.group) { groupcounter = i; } } rowOfEachGroup[groupcounter] += 1; ExcelCellAddress nameAddr = new ExcelCellAddress(rowOfEachGroup[groupcounter], columnOfEachGroup[groupcounter]); ExcelCellAddress yangVal = new ExcelCellAddress(rowOfEachGroup[groupcounter], columnOfEachGroup[groupcounter] + 1); ExcelCellAddress collected = new ExcelCellAddress(rowOfEachGroup[groupcounter], columnOfEachGroup[groupcounter] + 2); interaction.InsertValue(nameAddr, entry.mainPronounciation); interaction.InsertValue(yangVal, entry.yangValue); interaction.InsertValue(collected, 0); interaction.currentSheet.Cells[yangVal.Address].Style.Numberformat.Format = "###,###,###,###,###"; d.addresses.Add(entry.mainPronounciation, collected); } interaction.Save(); return(d); }
public void GetOrDefaultFromDictionaryAndReturnGivenValueTest() { var dictionary = new Dictionary <int, int> { { 1, 2 }, { 3, 4 }, { 5, 6 } }; var val1 = Dicts.GetValueOrDefault(dictionary, 1, 100); var val2 = Dicts.GetValueOrDefault(dictionary, 7, 8); val1.ShouldBe(2); val2.ShouldBe(8); }
private void InitForModify() { DictItemInfo dictItemInfo = (from p in Dicts.GetDataById(WebUtils.GetQueryInt("dictid")).Items where p.KeyName.Equals(WebUtils.GetQueryString("key")) select p).FirstOrDefault <DictItemInfo>(); if (dictItemInfo != null) { this.TextBox1.Text = dictItemInfo.KeyName; this.TextBox2.Text = dictItemInfo.KeyValue; this.TextBox3.Text = dictItemInfo.Sort.ToString(); } }
private void GetDictItemsByName() { DictsInfo cacheDictsByName = Dicts.GetCacheDictsByName(WebUtils.GetQueryString("dictname")); if (cacheDictsByName != null && cacheDictsByName.Items.Count > 0) { base.Response.Write(JsonUtils.ObjectToJson <System.Collections.Generic.IList <DictItemInfo> >(cacheDictsByName.Items)); } else { base.Response.Write(string.Empty); } }
private string listBadValues(Dicts dicts, Regex r) { var allWords = new List <string>(); var type1 = dicts.GetType(); var allFields = type1.GetFields(BindingFlags.Instance | BindingFlags.NonPublic); var fields = allFields.Where(fi => fi.FieldType == typeof(List <string>)); foreach (var field in fields) { List <string> list = field.GetValue(dicts) as List <string>; allWords.AddRange(list); } var s1 = string.Join(",", allWords.FindAll(x => !r.IsMatch(x))); return($" BAD VALUES: \n\n\n {s1} \n\n\n\n"); }
public void AddValueOrDoTest() { var dictionary = new Dictionary <int, int> { { 1, 2 } }; dictionary.Count.ShouldBe(1); dictionary[1].ShouldBe(2); string show = ""; Dicts.AddValueOrDo(dictionary, 1, k => 200, (k, v) => { show = $"{k}-{v}"; }); dictionary.Count.ShouldBe(1); dictionary[1].ShouldBe(2); show.ShouldBe("1-2"); show = ""; Dicts.AddValueOrDo(dictionary, 2, k => 200, (k, v) => { show = $"{k}-{v}"; }); dictionary.Count.ShouldBe(2); dictionary[1].ShouldBe(2); dictionary[2].ShouldBe(200); show.ShouldBe(""); show = ""; dictionary.AddValueOrDo(2, k => 200, (k, v) => { show = $"{k}-{v}"; }); dictionary.Count.ShouldBe(2); dictionary[1].ShouldBe(2); dictionary[2].ShouldBe(200); show.ShouldBe("2-200"); show = ""; dictionary.AddValueOrDo(3, k => 300, (k, v) => { show = $"{k}-{v}"; }); dictionary.Count.ShouldBe(3); dictionary[1].ShouldBe(2); dictionary[2].ShouldBe(200); dictionary[3].ShouldBe(300); show.ShouldBe(""); }
protected void lnk_Delete_Click(object sender, System.EventArgs e) { if (!base.IsAuthorizedOp(ActionType.Delete.ToString())) { base.ShowAjaxMsg(this.UpdatePanel1, "Không có thẩm quyền"); } else { DictsInfo dataById = Dicts.GetDataById(base.OpID); if (dataById == null) { base.ShowAjaxMsg(this.UpdatePanel1, "Thông tin từ điển không được tìm thấy, từ điển không tồn tại hoặc đã bị xóa"); } else { string commandArgument = ((LinkButton)sender).CommandArgument; System.Collections.Generic.List <DictItemInfo> list = new System.Collections.Generic.List <DictItemInfo>(); foreach (DictItemInfo current in dataById.Items) { if (!(current.KeyName == commandArgument.Split(new char[] { '|' })[0]) || !(current.KeyValue == commandArgument.Split(new char[] { '|' })[1])) { list.Add(current); } } dataById.DictValue = JsonUtils.ObjectToJson <System.Collections.Generic.List <DictItemInfo> >(list); if (Dicts.Update(dataById)) { CacheUtils.Del("JsonLeeCMS_CacheForGetDicts"); this.BindData(); PageBase.log.AddEvent(base.LoginAccount.AccountName, "xóa từ điển[" + commandArgument + "] thành công"); base.ShowAjaxMsg(this.UpdatePanel1, "Thao tác thành công"); } else { base.ShowAjaxMsg(this.UpdatePanel1, "Thao tác thất bại"); } } } }
protected void btn_SaveSort_Click(object sender, System.EventArgs e) { DictsInfo dataById = Dicts.GetDataById(base.OpID); System.Collections.Generic.List <DictItemInfo> list = new System.Collections.Generic.List <DictItemInfo>(); string[] array = WebUtils.GetFormString("key").Split(new char[] { ',' }); string[] array2 = WebUtils.GetFormString("value").Split(new char[] { ',' }); string[] array3 = WebUtils.GetFormString("sort").Split(new char[] { ',' }); if (array.Length > 0) { for (int i = 0; i < array.Length; i++) { list.Add(new DictItemInfo { KeyName = array[i], KeyValue = array2[i], Sort = WebUtils.GetInt(array3[i]) }); } list = (from p in list orderby p.Sort select p).ToList <DictItemInfo>(); dataById.DictValue = JsonUtils.ObjectToJson <System.Collections.Generic.List <DictItemInfo> >(list); if (Dicts.Update(dataById)) { this.BindData(); PageBase.log.AddEvent(base.LoginAccount.AccountName, "Đặt từ điển [" + dataById.DictName + "] sắp xếp thành công"); base.ShowAjaxMsg(this.UpdatePanel1, "Thao tác thành công"); } else { base.ShowAjaxMsg(this.UpdatePanel1, "Thao tác thất bại"); } } }
public void AddValueOrOverrideTest() { var dictionary = new Dictionary <int, int> { { 1, 2 } }; Dicts.AddValueOrOverride(dictionary, 1, 100); Dicts.AddValueOrOverride(dictionary, 2, 200); dictionary.Count.ShouldBe(2); dictionary[1].ShouldBe(100); dictionary[2].ShouldBe(200); dictionary.AddValueOrOverride(1, 300); dictionary.AddValueOrOverride(3, 400); dictionary.Count.ShouldBe(3); dictionary[1].ShouldBe(300); dictionary[2].ShouldBe(200); dictionary[3].ShouldBe(400); }
public void GroupAsDictionaryWithValueFuncTest() { var list = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; var dict = Dicts.GroupByAsDictionary(list, v => v % 2, v => v * 10); dict.Count.ShouldBe(2); // 0 or 1 dict[0].Count.ShouldBe(4); dict[1].Count.ShouldBe(5); dict[0][0].ShouldBe(20); dict[0][1].ShouldBe(40); dict[0][2].ShouldBe(60); dict[0][3].ShouldBe(80); dict[1][0].ShouldBe(10); dict[1][1].ShouldBe(30); dict[1][2].ShouldBe(50); dict[1][3].ShouldBe(70); dict[1][4].ShouldBe(90); }
public void GroupAsDictionaryTest() { var list = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; var dict = Dicts.GroupByAsDictionary(list, v => v % 2); dict.Count.ShouldBe(2); // 0 or 1 dict[0].Count.ShouldBe(4); dict[1].Count.ShouldBe(5); dict[0][0].ShouldBe(2); dict[0][1].ShouldBe(4); dict[0][2].ShouldBe(6); dict[0][3].ShouldBe(8); dict[1][0].ShouldBe(1); dict[1][1].ShouldBe(3); dict[1][2].ShouldBe(5); dict[1][3].ShouldBe(7); dict[1][4].ShouldBe(9); }
private void InitSettings() { if (!this.isLoad) { this.dropField.Attributes.Add("FieldID", base.FieldName); this.dropField.Items.Clear(); if (base.Settings.DataSource.IsNullOrEmpty()) { this.dropField.Items.Add(new ListItem("未设置", "-1")); } else { string dataFrom = base.Settings.DataFrom; if (dataFrom != null) { if (!(dataFrom == "Text")) { if (!(dataFrom == "DataDictionary")) { if (dataFrom == "SQLQuery") { this.dropField.DataSource = BaseFieldControl.dbo.GetDataTable(base.Settings.DataSource); this.dropField.DataTextField = "KeyValue"; this.dropField.DataValueField = "KeyName"; this.dropField.DataBind(); } } else { this.dropField.DataSource = Dicts.GetCacheDictsByName(base.Settings.DataSource).Items; this.dropField.DataTextField = "KeyValue"; this.dropField.DataValueField = "KeyName"; this.dropField.DataBind(); } } else { string[] array = base.Settings.DataSource.Split(new char[] { ',' }); for (int i = 0; i < array.Length; i++) { string text = array[i]; string[] array2 = text.Split(new char[] { '|' }); if (array2.Length == 2) { this.dropField.Items.Add(new ListItem(array2[0], array2[1])); } else { this.dropField.Items.Add(new ListItem(text, text)); } } } } } } this.isLoad = true; }
public static string RequestDicts(string dicts) { using (CommonDomain domain = new CommonDomain()) { string[] required_dicts = dicts.Split(','); Dicts list_dicts = new Dicts(); if (required_dicts.Contains("pvd")) { foreach (var item in domain._dictPVDs.OrderBy(d => d.pvdn)) { list_dicts.PVDs.Add(new DictItem() { ID = item.ID, Name = item.pvdn }); } } if (required_dicts.Contains("um")) { foreach (var item in domain._dictUMs.OrderBy(d => d.umn1)) { list_dicts.UMs.Add(new DictItem() { ID = item.ID, Name = item.umn1 }); } } if (required_dicts.Contains("sf")) { foreach (var item in domain._dictSFs.OrderBy(d => d.sfn)) { list_dicts.SFs.Add(new DictItem() { ID = item.ID, Name = item.sfn }); } } if (required_dicts.Contains("s")) { foreach (var item in domain._dicts.OrderBy(d => d.so)) { list_dicts.Ss.Add(new DictItem() { ID = item.id, Name = item.sn1 }); } } if (required_dicts.Contains("ste")) { foreach (var item in domain._dictS_tes.OrderBy(d => d.type)) { list_dicts.STEs.Add(new DictItem() { ID = item.id, Name = item.type }); } } JavaScriptSerializer serializer = new JavaScriptSerializer(); return serializer.Serialize(list_dicts); } }
private void GetDictListXML() { int queryInt = WebUtils.GetQueryInt("id"); System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); System.Collections.Generic.List <DictsInfo> list = (System.Collections.Generic.List <DictsInfo>)Dicts.GetCacheDictsList(); if (list != null && list.Count > 0) { foreach (DictsInfo current in list) { stringBuilder.Append(string.Concat(new object[] { "{id:'", current.AutoID.ToString(), "',name:'", current.DisplayName, "',isParent:false,'iconSkin':'leaf','click':\"AppendVal(", current.AutoID, ",'", current.DisplayName, "')\"}," })); } } base.Response.Write("[" + stringBuilder.ToString().TrimEnd(new char[] { ',' }) + "]"); }