/// <summary> /// 保存修改节点 /// </summary> /// <param name="id">节点ID</param> public void SaveDictionaryTree(DictionaryTree dt) { using (var dbContext = new StoreDbContext()) { dbContext.Update <DictionaryTree>(dt); } }
public void AddBranch(K key, V value) { var branch = new DictionaryTree <K, V>(key, value); branch._Root = this; Branches.Add(key, branch); }
public void Add_Multiple_Words_Word_Does_Not_Exist() { DictionaryTree dict = new DictionaryTree(); dict.addWords(new string[] { "word", "words", "john", "joan", "art" }); Assert.IsFalse(dict.isWord("henry")); }
public void Add_Multiple_Words_Get_Possible_Results() { DictionaryTree dict = new DictionaryTree(); dict.addWords(new string[] { "word", "words", "john", "joan", "art" }); CollectionAssert.AreEqual(dict.getPossibleWords("wo"), new string[] { "word", "words" }); }
public void Add_Word_Check_If_Partial_Word_Does_Not_Exist() { DictionaryTree dict = new DictionaryTree(); dict.addWords(new string[] { "word" }); Assert.IsFalse(dict.isWord("wo")); }
public void Add_Multiple_Words_Secondary_Word_Exists() { DictionaryTree dict = new DictionaryTree(); dict.addWords(new string[] { "word", "words", "john", "joan", "art" }); Assert.IsTrue(dict.isWord("words")); }
public void Add_Word_Word_Exists() { DictionaryTree dict = new DictionaryTree(); dict.addWords(new string[] { "word" }); Assert.IsTrue(dict.isWord("word")); }
/// <summary> /// 添加节点 /// </summary> /// <param name="dt">树结构</param> public void InsertDictionaryTree(DictionaryTree dt) { using (var dbContext = new StoreDbContext()) { dbContext.Insert <DictionaryTree>(dt); } }
private static void GroupBulkInsertByName(DictionaryTree <string, string> groups) { if (!groups.Any()) { return; } var request = new RestRequest(Method.POST) { Timeout = int.MaxValue, RequestFormat = DataFormat.Json }; var body = new { NewGroups = (GroupNameTree)groups, RootPath = rootPath }; request.AddJsonBody(body); var url = "http://localhost:58994/odata/v4/groups/BulkInsertByName"; var response = new RestClient(url) .Execute(request); if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw new Exception(response.Content); } }
/// <summary> /// 根据id获取名称 /// </summary> /// <param name="treeid"></param> /// <returns></returns> public string GetTreeName(Guid treeid) { using (var dbContext = new StoreDbContext()) { DictionaryTree dt = dbContext.DictionaryTree.Include("DictionaryProperty").FirstOrDefault(u => u.dt_id == treeid); return(dt.name); } }
/// <summary> /// 根据叶子节点ID获取父节点名称 /// </summary> /// <param name="id"></param> /// <returns></returns> public string GetParentNameByLeafID(Guid id) { using (var dbContext = new StoreDbContext()) { DictionaryTree dt = dbContext.DictionaryTree.Where(u => u.dt_id == id).FirstOrDefault(); DictionaryTree pdt = dbContext.DictionaryTree.Where(u => u.dt_id == dt.parent_id).FirstOrDefault(); return(pdt.name); } }
public ActionResult AddType(FormCollection collection) { var dataString = collection[0].ToString(); DictionaryTree dt = new DictionaryTree(); TreeProperty treeProperty = JsonHelper.JsonDeserialize <TreeProperty>(dataString); dt.dt_id = treeProperty.id; dt.is_leaf = treeProperty.type; dt.name = treeProperty.name; dt.parent_id = treeProperty.pid; if (treeProperty.pid.ToString() != "11111111-1111-1111-1111-111111111111") { dt.parent_name = this.StoreService.GetTreeName(treeProperty.pid); } this.StoreService.InsertDictionaryTree(dt); //var list = this.StoreService.GetDictionaryTreeList(null); return(View()); }
public Dictionary <char, string> CreateDictionary(string text) { var occurence = new Dictionary <char, Sign>(); foreach (var letter in text) { if (occurence.ContainsKey(letter)) { occurence[letter].AddOccurence(); } else { var sign = new Sign(letter); occurence.Add(letter, sign); } } var tree = new DictionaryTree(); return(tree.CreateDictionary(occurence)); }
public void SetUp() { _dictionaryTree = new DictionaryTree(); }
public RamConfigBehavior(DictionaryTree <String, String> config, String path = null, ConfigOptions options = ConfigOptions.None) : this(config, path, null, options) { }
public RamConfigBehavior(DictionaryTree <String, String> config, String path, ICryptKey crypt, ConfigOptions options = ConfigOptions.None) : base(path ?? "RAM", crypt, options) { Config = config; }
public LazyWriteRamConfigBehavior(DictionaryTree <String, String> config, String path = null, ConfigOptions options = ConfigOptions.None) : base(config, path, options) { }
private static void GetData(out List <DataDeputado> datas, out DictionaryTree <string, string> groups, Func <string, string> treatIndex) { datas = new List <DataDeputado>(); groups = new DictionaryTree <string, string>(s => treatIndex(s), "Verba indenizatória"); var xmlDoc = new System.Xml.XmlDocument(); xmlDoc.Load(@"C:\Users\MyUser\source\repos\CSharp.Data.Task\CSharp.Politica.DeputadosTask\CSharp.Politica.DeputadosTask\Dados.xml"); var xpath = "xml/dados/despesa"; var nodes = xmlDoc.SelectNodes(xpath); foreach (System.Xml.XmlNode childrenNode in nodes) { var datasCount = datas.Count; if (datasCount > 0 && datasCount % 5000 == 0) { GroupBulkInsertByName(groups); DataBulkInsert(datas, treatIndex); datas = new List <DataDeputado>(); groups = new DictionaryTree <string, string>(s => treatIndex(s), "Verba indenizatória"); } var dataEmissaoText = childrenNode.SelectSingleNode("dataEmissao").InnerText; var dataEmissao = string.IsNullOrWhiteSpace(dataEmissaoText) ? (DateTime?)null : DateTime.Parse(dataEmissaoText); var ano = int.Parse(childrenNode.SelectSingleNode("ano").InnerText); var mes = int.Parse(childrenNode.SelectSingleNode("mes").InnerText); var vlLiquidoText = childrenNode.SelectSingleNode("valorLiquido").InnerText; var vlLiquido = string.IsNullOrWhiteSpace(vlLiquidoText) ? (decimal?)null : decimal.Parse(vlLiquidoText, System.Globalization.CultureInfo.InvariantCulture); var vlDevolvidoText = childrenNode.SelectSingleNode("restituicao").InnerText; var vlDevolvido = string.IsNullOrWhiteSpace(vlDevolvidoText) ? (decimal?)null : decimal.Parse(vlDevolvidoText, System.Globalization.CultureInfo.InvariantCulture) * -1; var isCancelado = vlDevolvido.HasValue; //valorLiquido ?? restituicao * -1 string tpDocumento; switch (childrenNode.SelectSingleNode("tipoDocumento").InnerText.Trim()) { case "0": tpDocumento = "Tipo 0 (NotaFiscal) - "; break; case "1": tpDocumento = "Tipo 1 (Recibo) - "; break; case "2": tpDocumento = "Tipo 2 - "; break; case "3": tpDocumento = "Tipo 3 - "; break; case "4": tpDocumento = "Tipo 4 - "; break; default: tpDocumento = "Tipo indefinido - "; break; } var numeroDocumento = tpDocumento + childrenNode.SelectSingleNode("numero").InnerText; var group = groups.AddIfNew( childrenNode.SelectSingleNode("siglaUF").InnerText, childrenNode.SelectSingleNode("siglaPartido").InnerText, childrenNode.SelectSingleNode("nomeParlamentar").InnerText, childrenNode.SelectSingleNode("codigoLegislatura").InnerText.Trim(), childrenNode.SelectSingleNode("descricao").InnerText, childrenNode.SelectSingleNode("fornecedor").InnerText, numeroDocumento, isCancelado ? "Cancelado" : "Reembolsado"); var data = new DataDeputado() { Date = dataEmissao ?? new DateTime(ano, mes, 1), Group = group, Value = isCancelado ? vlDevolvido.Value * -1 : vlLiquido.Value, Parcela = childrenNode.SelectSingleNode("parcela").InnerText }; datas.Add(data); ////Console.WriteLine(childrenNode.SelectSingleNode("razao_social").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("nr_processo").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("cd_orgao").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("ds_orgao").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("cd_unidade").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("ds_unidade").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("cd_despesa").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("ds_despesa").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("categoria_despesa").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("ds_categoria").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("grupo_despesa").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("ds_grupo").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("cd_modalidade").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("ds_modalidade").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("nr_mes").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("nr_ano").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("vl_pagamento").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("cnpj").InnerText); } }
private static void GetDespesas(int year, int month, out List <DataPrfOsasco> datas, out DictionaryTree <string, string> despesas, Func <string, string> treatIndex) { datas = new List <DataPrfOsasco>(); despesas = new DictionaryTree <string, string>(s => treatIndex(s), "Despesas"); var parameters = "{" + $"\"edtExercicio\":{year},\"edtMes\":{month},\"edtCategoria\":\"%\"" + "}"; var parametersEncoded = Encoding.UTF8.GetBytes(parameters); var parametersBase64 = Convert.ToBase64String(parametersEncoded); var client = new RestClient("http://eportal.osasco.sp.gov.br/eportais-api/api/relatorio/gerarRelatorioXML/Despesa%20paga%20por%20Fornecedor/" + parametersBase64); var request = new RestRequest(Method.GET); var response = client.Execute(request); if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw new Exception(response.Content); } var xml = response.Content; var xmlDoc = new System.Xml.XmlDocument(); xmlDoc.LoadXml(xml); var xpath = "DespesapagaporFornecedor/registro"; var nodes = xmlDoc.SelectNodes(xpath); foreach (System.Xml.XmlNode childrenNode in nodes) { var year2 = int.Parse(childrenNode.SelectSingleNode("nr_ano").InnerText); var month2 = int.Parse(childrenNode.SelectSingleNode("nr_mes").InnerText); var date = new DateTime(year2, month2, 1); var valor = decimal.Parse(childrenNode.SelectSingleNode("vl_pagamento").InnerText, CultureInfo.InvariantCulture); var cpfCnpj = childrenNode.SelectSingleNode("cnpj").InnerText; var tpPessoa = "Indefinido"; if (IsCpf(cpfCnpj)) { tpPessoa = "Pessoa"; } else if (IsCnpj(cpfCnpj)) { tpPessoa = "Empresa"; } var despesa = despesas.AddIfNew( childrenNode.SelectSingleNode("ds_categoria").InnerText, childrenNode.SelectSingleNode("ds_grupo").InnerText, childrenNode.SelectSingleNode("ds_modalidade").InnerText, childrenNode.SelectSingleNode("ds_despesa").InnerText, childrenNode.SelectSingleNode("ds_orgao").InnerText, childrenNode.SelectSingleNode("ds_unidade").InnerText, tpPessoa, childrenNode.SelectSingleNode("razao_social").InnerText); var data = new DataPrfOsasco() { Date = date, Group = despesa, Value = valor }; datas.Add(data); ////Console.WriteLine(childrenNode.SelectSingleNode("razao_social").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("nr_processo").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("cd_orgao").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("ds_orgao").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("cd_unidade").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("ds_unidade").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("cd_despesa").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("ds_despesa").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("categoria_despesa").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("ds_categoria").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("grupo_despesa").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("ds_grupo").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("cd_modalidade").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("ds_modalidade").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("nr_mes").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("nr_ano").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("vl_pagamento").InnerText); ////Console.WriteLine(childrenNode.SelectSingleNode("cnpj").InnerText); } }
public void AddBranch(DictionaryTree <K, V> branch) { branch._Root = this; Branches.Add(branch.Key, branch); }
private static void GetViagens(int year, out List <DataPrfOsasco> datas, out DictionaryTree <string, string> despesas, Func <string, string> treatIndex) { datas = new List <DataPrfOsasco>(); despesas = new DictionaryTree <string, string>(s => treatIndex(s), "Viagens"); var viagensCsv = GetViagensCsv(year); var viagensXml = GetViagensXml(year); var viagens = from x in viagensXml join c in viagensCsv on new { x.Nro_Processo } equals new { c.Nro_Processo } select new { x.Destino, x.Motivo, x.Observacao, x.Valor, x.Inicio, x.Fim, x.Orgao, x.Unidade, c.Nome, c.Cargo }; if (viagensCsv.Count() != viagens.Count()) { throw new Exception("Missing data"); } foreach (var viagem in viagens) { var groupValor = despesas.AddIfNew( viagem.Orgao, viagem.Unidade, viagem.Destino, viagem.Motivo, viagem.Observacao, viagem.Cargo, viagem.Nome, "Valor"); var dataValor = new DataPrfOsasco() { Date = viagem.Inicio, Group = groupValor, Value = viagem.Valor }; datas.Add(dataValor); var groupDias = despesas.AddIfNew( "Prefeituras", "Osasco", "Viagens", viagem.Orgao, viagem.Unidade, viagem.Destino, viagem.Motivo, viagem.Observacao, viagem.Cargo, viagem.Nome, "Dias"); var dataDias = new DataPrfOsasco() { Date = viagem.Inicio, Group = groupDias, Value = viagem.Valor }; datas.Add(dataDias); } }
public LazyWriteRamConfigBehavior(DictionaryTree <String, String> config, String path, ICryptKey crypt, ConfigOptions options = ConfigOptions.None) : base(config, path, crypt, options) { }
private AtivaTradeData(DateTime date, DictionaryTree <string, string> group, decimal value) { Date = date; Group = group; Value = value; }