/// <summary> /// Carrega ou recarrega todos os projectnodes em uma estrutura TFWHierarquicalList e traz o elemento correspondente /// </summary> /// <param name="id"></param> /// <returns></returns> public virtual TFWHierarchicalParameter GetProjectNode(int id) { if (AreNewProjectNodes()) { _projectNodes.Clear(); foreach (ProjectNode pn in _db.ProjectNodes) { _projectNodes.Add(pn.Id, pn.Pai_Id, pn.Nome); } } return(_projectNodes.Where(p => p.Id == id).FirstOrDefault()); }
/// <summary> /// obtém uma estrutura TFWHierarchicalList com os projectnodes montados /// </summary> /// <returns>TFWHierarchicalList - lista com todos os projectnodes em forma de elementos hierárquicos</returns> public TFWHierarchicalList GetTree() { TFWHierarchicalList result = new TFWHierarchicalList(); foreach (var n in this._db.ProjectNodes.AsNoTracking().OrderBy(x => x.Nome)) { result.Add(n.Id, n.Pai != null ? n.Pai.Id : new Nullable <int>(), n.NodeLabel.Nome + ": " + n.Nome); } return(result); }
private void CarregaNodes(int?valor = null) { var nodes = db.ProjectNodes.ToList(); TFWHierarchicalList lst = new TFWHierarchicalList(); foreach (var n in nodes) { lst.Add(n.Id, n.Pai != null ? n.Pai.Id : new Nullable <int>(), n.Nome); } ViewBag.Nodes = lst; }
private void CarregaProjetos(int?valor = null) { var nodes = db.ProjectNodes.AsNoTracking().ToList(); TFWHierarchicalList lst = new TFWHierarchicalList(); foreach (var n in nodes) { lst.Add(n.Id, n.Pai != null ? n.Pai.Id : new Nullable <int>(), n.Nome); } //SelectList NodeSelectList = new SelectList(nodes, "Id", "Nome", valor); ViewBag.Nodes = lst; }
/// <summary> /// obtém todos os nós de projeto em forma de um TFWHierarchicalList /// deixando pré selecionada a opção que vier como parâmetro em caso de edição da form /// </summary> /// <param name="valor">int? - valor que já estava selecionado ou salvo no Model</param> /// <returns>TFWHierarchicalList - lista para usar em um combo com simulação de hierarquia no estilo</returns> public static TFWHierarchicalList GetNodes(int?valor = null) { TPAContext db = new TPAContext(); TFWHierarchicalList lstUsuario = new TFWHierarchicalList(); TFWHierarchicalList lst = new TFWHierarchicalList(); List <int> idsNodesUsuario = new List <int>(); var usu = HttpContext.Current.User.Identity.Name; var usuLogado = db.Usuarios.Where(u => u.Login == usu).FirstOrDefault(); if (usuLogado != null) { var nodes = usuLogado.NosDoUsuario.ToList(); if (nodes != null && nodes.Any()) { foreach (var n in nodes) { lstUsuario.Add(n.Id, n.Pai != null ? n.Pai.Id : new Nullable <int>(), n.Nome); } } } idsNodesUsuario.AddRange(lstUsuario.Select(s => s.Id).ToList()); foreach (var node in db.ProjectNodes.ToList()) { if (idsNodesUsuario.Contains(node.Id)) { lst.Add(node.Id, node.Pai_Id != null ? node.Pai_Id : new Nullable <int>(), node.Nome); } else { lst.Add(node.Id, node.Pai != null ? node.Pai.Id : new Nullable <int>(), node.Nome, false); } } return(lst); }
private void CarregaProjetos(int?valor = null) { TFWHierarchicalList lstUsuario = new TFWHierarchicalList(); TFWHierarchicalList lst = new TFWHierarchicalList(); List <int> idsNodesUsuario = new List <int>(); var usu = this.User.Identity.Name; var usuLogado = db.Usuarios.Where(u => u.Login == usu).FirstOrDefault(); if (usuLogado != null) { var nodes = usuLogado.NosDoUsuario.ToList(); if (nodes != null && nodes.Any()) { foreach (var n in nodes) { lstUsuario.Add(n.Id, n.Pai != null ? n.Pai.Id : new Nullable <int>(), n.Nome); } } } idsNodesUsuario.AddRange(lstUsuario.Select(s => s.Id).ToList()); foreach (var node in db.ProjectNodes.ToList()) { if (idsNodesUsuario.Contains(node.Id)) { lst.Add(node.Id, node.Pai_Id != null ? node.Pai_Id : new Nullable <int>(), node.Nome); } else { lst.Add(node.Id, node.Pai != null ? node.Pai.Id : new Nullable <int>(), node.Nome, false); } } ViewBag.Nodes = lst; }
/// <summary> /// obtém os ProjectNodes organizados na forma de TFWHierarchicalList, com lazy load /// </summary> /// <returns>TFWHierarchicalList - estrutura hierárquica com todos os ProjectNodes</returns> public virtual TFWHierarchicalList GetNodeTree() { if (_listNodes == null) { _listNodes = new TFWHierarchicalList(); } if (_listNodes.Count == 0) { foreach (ProjectNode n in _rep.GetAll()) { _listNodes.Add(n.Id, n.Pai_Id, n.Nome); } } TFWHierarchicalList result = new TFWHierarchicalList(); foreach (TFWHierarchicalParameter p in _listNodes) { result.Add(p.Id, p.IdPai, p.Valor); } return(result); }
/// <summary> /// importa uma planilha do excel com atividades para um usuário /// </summary> /// <param name="idUsuario">int - id do usuário</param> /// <param name="pkg">ExcelPackage - package da Epplus criado com os dados da planilha como stream</param> /// <returns>ImportacaoPlanilhaAtividadesUsuarioViewModel - viewmodel com as atividades para serem editadas e postadas</returns> public virtual ImportacaoPlanilhaAtividadesUsuarioViewModel TransformarPlanilhaUsuario(int idUsuario, ExcelPackage pkg) { TFWHierarchicalList projetos = new TFWHierarchicalList(); foreach (var pn in _db.ProjectNodes.AsNoTracking().ToList()) { projetos.Add(pn.Id, pn.Pai == null? new Nullable <int>() : pn.Pai.Id, pn.Nome); } ImportacaoPlanilhaAtividadesUsuarioViewModel result = new ImportacaoPlanilhaAtividadesUsuarioViewModel(); CalendarioServices cal = new CalendarioServices(); result.IdUsuario = idUsuario; const int LINHA_INICIAL = 15; const int LINHA_FINAL = 79; const int COLUNA_PROJETO = 1; const int COLUNA_DATA = 2; const int COLUNA_ENTM = 3; const int COLUNA_SAIM = 4; const int COLUNA_ENTT = 5; const int COLUNA_SAIT = 6; const int COLUNA_HORAS = 9; const int COLUNA_TIPOATIVIDADE = 10; const int COLUNA_DESCRICAO = 11; var currentSheet = pkg.Workbook.Worksheets; var workSheet = currentSheet.First(); var noOfCol = workSheet.Dimension.End.Column; var noOfRow = workSheet.Dimension.End.Row; for (int rowIterator = LINHA_INICIAL; rowIterator <= noOfRow || rowIterator <= LINHA_FINAL; rowIterator++) { ItemImportacaoPlanilha item = new ItemImportacaoPlanilha(); item.IdUsuario = idUsuario; TimeSpan qtdHoras = ExcelToTimeSpan(workSheet.Cells[rowIterator, COLUNA_HORAS].Value); if ((workSheet.Cells[rowIterator, COLUNA_PROJETO].Value != null) && (qtdHoras > TimeSpan.MinValue)) { DateTime?data = ExcelToNullableDateTime(workSheet.Cells[rowIterator, COLUNA_DATA].Value); //a data tem que ser não nula e dia util if ((data != null) && (cal.IsDiaUtil(data.Value))) { item.Data = data.Value; item.Descricao = workSheet.Cells[rowIterator, COLUNA_DESCRICAO].Value != null ? workSheet.Cells[rowIterator, COLUNA_DESCRICAO].Value.ToString() : ""; item.EntradaManha = ExcelToNullableTimeSpan(workSheet.Cells[rowIterator, COLUNA_ENTM].Value); item.SaidaManha = ExcelToNullableTimeSpan(workSheet.Cells[rowIterator, COLUNA_SAIM].Value); item.EntradaTarde = ExcelToNullableTimeSpan(workSheet.Cells[rowIterator, COLUNA_ENTT].Value); item.SaidaTarde = ExcelToNullableTimeSpan(workSheet.Cells[rowIterator, COLUNA_SAIT].Value); if (workSheet.Cells[rowIterator, COLUNA_PROJETO].Value != null) { string nome = workSheet.Cells[rowIterator, COLUNA_PROJETO].Value.ToString(); //procura por path completo var proj = projetos.Where(n => n.ValorPath == nome).FirstOrDefault(); if (proj != null) { item.IdProjeto = proj.Id; } else { //procura só por nome proj = projetos.Where(n => n.Valor == nome).FirstOrDefault(); if (proj != null) { item.IdProjeto = proj.Id; } } } if (workSheet.Cells[rowIterator, COLUNA_TIPOATIVIDADE].Value != null) { string nome = workSheet.Cells[rowIterator, COLUNA_TIPOATIVIDADE].Value.ToString(); var atv = _db.TiposAtividade.Where(n => n.Nome == nome).FirstOrDefault(); if (atv != null) { item.IdTipoAtividade = atv.Id; } } result.Itens.Add(item); } } } return(result); }