Ejemplo n.º 1
0
        private ElementoPreventivoModel convertiMateriaPrimaInElementoPreventivo(MateriaPrimaModel materiaPrima, decimal idElementoPreventivo, decimal idPadre)
        {
            ElementoPreventivoModel elemento = new ElementoPreventivoModel();

            elemento.IdElementoPreventivo = idElementoPreventivo;
            elemento.IdPadre           = idPadre;
            elemento.IdPreventivo      = _preventivoSelezionato.IdPreventivo;
            elemento.Codice            = materiaPrima.Codice;
            elemento.Reparto           = null;
            elemento.Ricarico          = materiaPrima.Ricarico;
            elemento.CostoOrario       = materiaPrima.Costo;
            elemento.IncludiPreventivo = materiaPrima.IncludiPreventivo;
            elemento.IdEsterna         = -1;
            elemento.TabellaEsterna    = string.Empty;
            elemento.PezziOrari        = 0;
            elemento.Peso        = 0;
            elemento.Superficie  = 0;
            elemento.Quantita    = 1;
            elemento.Descrizione = "MATERIA PRIMA";
            elemento.Articolo    = materiaPrima.Descrizione;
            elemento.Nota        = string.Empty;
            return(elemento);
        }
Ejemplo n.º 2
0
        private MateriaPrimaModel CarregarModel()
        {
            var tabelaPrecoModel = new MateriaPrimaModel
            {
                Retorno = new BusinessMateriaPrima().Listar()
            };

            if (tabelaPrecoModel.Retorno.IsValido)
            {
                var retorno = new BusinessMateriaPrima().CarregarDominios();

                if (retorno.IsValido)
                {
                    tabelaPrecoModel.Dominios = retorno.Entity as DominiosDto;
                }
                else
                {
                    tabelaPrecoModel.Retorno = retorno;
                }
            }

            return(tabelaPrecoModel);
        }
Ejemplo n.º 3
0
        private void treeView1_DragDrop(object sender, DragEventArgs e)
        {
            Point targetPoint = treeView1.PointToClient(new Point(e.X, e.Y));


            TreeNode draggedNode = (TreeNode)e.Data.GetData(typeof(TreeNode));

            if (draggedNode != null)
            {
                if (draggedNode == null)
                {
                    return;
                }

                TreeNode targetNode = treeView1.GetNodeAt(targetPoint);

                if (targetNode == null)
                {
                    draggedNode.Remove();
                    treeView1.Nodes.Add(draggedNode);
                    draggedNode.Expand();
                }
                else
                {
                    TreeNode parentNode = targetNode;

                    if (!draggedNode.Equals(targetNode) && targetNode != null)
                    {
                        bool canDrop = true;
                        while (canDrop && (parentNode != null))
                        {
                            canDrop    = !Object.ReferenceEquals(draggedNode, parentNode);
                            parentNode = parentNode.Parent;
                        }

                        if (canDrop)
                        {
                            draggedNode.Remove();
                            targetNode.Nodes.Add(draggedNode);

                            ElementoPreventivoModel elementoSpostato = (ElementoPreventivoModel)draggedNode.Tag;
                            decimal idPadre = estraiIdPadre(targetNode);
                            elementoSpostato.IdPadre = idPadre;
                            eliminaElementoDallaLista(elementoSpostato);
                            inserisciElementoNellaLista(elementoSpostato, draggedNode, idPadre);
                            RefreshGridView();
                            targetNode.Expand();
                        }
                    }
                }
            }
            else
            {
                TreeNode nodeToDropIn = this.treeView1.GetNodeAt(this.treeView1.PointToClient(new Point(e.X, e.Y)));
                if (nodeToDropIn == null)
                {
                    return;
                }

                // il nodo viene inserito sopra al node to drop in, in cascata, almeno che non siala radice

                if (nodeToDropIn.Parent == null || e.KeyState == 4)
                {
                    decimal idPadre = estraiIdPadre(nodeToDropIn);
                    decimal idElementoPreventivo = MPIntranet.Business.Articolo.EstraId();

                    FaseModel fase = (FaseModel)e.Data.GetData(typeof(FaseModel));
                    ElementoPreventivoModel elemento;
                    if (fase == null)
                    {
                        MateriaPrimaModel materiaPrima = (MateriaPrimaModel)e.Data.GetData(typeof(MateriaPrimaModel));
                        if (materiaPrima == null)
                        {
                            return;
                        }
                        elemento = convertiMateriaPrimaInElementoPreventivo(materiaPrima, idElementoPreventivo, idPadre);
                    }
                    else
                    {
                        elemento = convertiFaseInElementoPreventivo(fase, idElementoPreventivo, idPadre);
                    }
                    aggungiNodo(nodeToDropIn, elemento);

                    inserisciElementoNellaLista(elemento, nodeToDropIn, idPadre);
                    nodeToDropIn.ExpandAll();
                }
                else
                {
                    TreeNode padre = nodeToDropIn.Parent;
                    treeView1.Nodes.Remove(nodeToDropIn);

                    decimal idPadre = estraiIdPadre(padre);
                    decimal idElementoPreventivo = MPIntranet.Business.Articolo.EstraId();

                    FaseModel fase = (FaseModel)e.Data.GetData(typeof(FaseModel));
                    ElementoPreventivoModel elemento;
                    if (fase == null)
                    {
                        MateriaPrimaModel materiaPrima = (MateriaPrimaModel)e.Data.GetData(typeof(MateriaPrimaModel));
                        if (materiaPrima == null)
                        {
                            return;
                        }
                        elemento = convertiMateriaPrimaInElementoPreventivo(materiaPrima, idElementoPreventivo, idPadre);
                    }
                    else
                    {
                        elemento = convertiFaseInElementoPreventivo(fase, idElementoPreventivo, idPadre);
                    }
                    TreeNode nodoAggiunto = aggungiNodo(padre, elemento);
                    inserisciElementoNellaLista(elemento, padre, idPadre);
                    ElementoPreventivoModel elementoNodeToDropIn = (ElementoPreventivoModel)nodeToDropIn.Tag;
                    elementoNodeToDropIn.IdPadre = idElementoPreventivo;
                    nodoAggiunto.Nodes.Add(nodeToDropIn);
                    padre.ExpandAll();
                }

                RefreshGridView();
            }
        }