public List <CompanyStructureNode> GetNodesByType(TypeOfNode typeOfNode)
        {
            List <CompanyStructureNode> nodes = new List <CompanyStructureNode>();

            using (SqlConnection connection = new SqlConnection(Constants.CONNECTION_STRING))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand())
                {
                    command.CommandText = "Select * from CompanyStructureNode where TypeOfNode = @typeOfNode";
                    command.Parameters.Add("@typeOfNode", SqlDbType.Int).Value = typeOfNode;
                    command.Connection = connection;

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            CompanyStructureNode node = new CompanyStructureNode();
                            node.NodeId       = reader.GetInt32(0);
                            node.CodeOfNode   = reader.GetString(1);
                            node.NameOfNode   = reader.GetString(2);
                            node.TypeOfNode   = (TypeOfNode)reader.GetInt32(3);
                            node.HeadOfNodeId = reader.IsDBNull(5) ? 0 : reader.GetInt32(5);

                            nodes.Add(node);
                        }
                    }
                }
            }

            return(nodes);
        }
        public CompanyStructureNode GetNodeById(int nodeId)
        {
            CompanyStructureNode node = new CompanyStructureNode();

            using (SqlConnection connection = new SqlConnection(Constants.CONNECTION_STRING))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand())
                {
                    command.CommandText = "Select * from CompanyStructureNode where NodeId = @nodeId";
                    command.Parameters.Add("@nodeId", SqlDbType.Int).Value = nodeId;
                    command.Connection = connection;

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            node.NodeId     = reader.GetInt32(0);
                            node.CodeOfNode = reader.GetString(1);
                            node.NameOfNode = reader.GetString(2);
                            node.TypeOfNode = (TypeOfNode)reader.GetInt32(3);
                        }
                    }
                }
            }

            return(node);
        }
Esempio n. 3
0
        public CompanyStructureNode CreateFirm(string codeOfNode, string nameOfNode, TypeOfNode typeOfNode)
        {
            CompanyStructureNode firm = new CompanyStructureNode();

            firm.CodeOfNode = codeOfNode;
            firm.NameOfNode = nameOfNode;
            firm.TypeOfNode = typeOfNode;

            return(firm);
        }
Esempio n. 4
0
        public CompanyStructureNode CreateNode(string codeOfNode, string nameOfNode, TypeOfNode typeOfNode, int parentNode)
        {
            CompanyStructureNode node = new CompanyStructureNode();

            node.CodeOfNode  = codeOfNode;
            node.NameOfNode  = nameOfNode;
            node.TypeOfNode  = typeOfNode;
            node.NodeAboveId = parentNode;

            return(node);
        }
Esempio n. 5
0
        public void AddNode(TypeOfNode typeOfNode, int parentId)
        {
            CompanyStructureNode node = new CompanyStructureNode();

            if (HeadOfNodeId == 0)
            {
                node = _nodeFactory.CreateNode(CodeOfNode, NameOfNode, typeOfNode, parentId);
                RepositoryManager.CompanyStructureNodeRepository.AddNode(node);
            }
            else
            {
                node = _nodeFactory.CreateNode(CodeOfNode, NameOfNode, typeOfNode, parentId, HeadOfNodeId);
                RepositoryManager.CompanyStructureNodeRepository.AddNodeWithHead(node);
            }
        }
        public void AddFirm(CompanyStructureNode node)
        {
            using (SqlConnection connection = new SqlConnection(Constants.CONNECTION_STRING))
            {
                connection.Open();
                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandText = @"insert into CompanyStructureNode (CodeOfNode, NameOfNode, TypeOfNode)
                                            values(@codeOfNode, @nameOfNode, @typeOfNode)";

                    command.Parameters.Add("@codeOfNode", SqlDbType.NVarChar).Value = node.CodeOfNode;
                    command.Parameters.Add("@nameOfNode", SqlDbType.NVarChar).Value = node.NameOfNode;
                    command.Parameters.Add("@typeOfNode", SqlDbType.Int).Value      = node.TypeOfNode;

                    command.ExecuteNonQuery();
                }
            }
        }