private void copiaElemento(List <ElementoPreventivoModel> elementiNuovi, ElementoPreventivoModel elemento, decimal nuovoIdPadre, decimal idPreventivouovo, List <ElementoPreventivoModel> elementiDaCopiare)
        {
            ElementoPreventivoModel elementoNuovo = new ElementoPreventivoModel();

            elementoNuovo.IdElementoPreventivo = Articolo.EstraId();
            elementoNuovo.IdPadre           = nuovoIdPadre;
            elementoNuovo.IdPreventivo      = idPreventivouovo;
            elementoNuovo.Codice            = elemento.Codice;
            elementoNuovo.Reparto           = elemento.Reparto;
            elementoNuovo.Ricarico          = elemento.Ricarico;
            elementoNuovo.CostoOrario       = elemento.CostoOrario;
            elementoNuovo.IncludiPreventivo = elemento.IncludiPreventivo;
            elementoNuovo.IdEsterna         = elemento.IdEsterna;
            elementoNuovo.TabellaEsterna    = elemento.TabellaEsterna;
            elementoNuovo.PezziOrari        = elemento.PezziOrari;
            elementoNuovo.Peso        = elemento.Peso;
            elementoNuovo.Superficie  = elemento.Superficie;
            elementoNuovo.Quantita    = elemento.Quantita;
            elementoNuovo.Descrizione = elemento.Descrizione;
            elementoNuovo.Articolo    = elemento.Articolo;
            elementoNuovo.Nota        = elemento.Nota;
            elementiNuovi.Add(elementoNuovo);

            foreach (ElementoPreventivoModel elementoFiglio in elementiDaCopiare.Where(x => x.IdPadre == elemento.IdElementoPreventivo))
            {
                copiaElemento(elementiNuovi, elementoFiglio, elementoNuovo.IdElementoPreventivo, idPreventivouovo, elementiDaCopiare);
            }
        }
Exemplo n.º 2
0
        private TreeNode aggungiNodo(TreeNode nodoRadice, ElementoPreventivoModel elemento)
        {
            TreeNode nodoAggiunto = nodoRadice.Nodes.Add(elemento.IdElementoPreventivo.ToString(), elemento.ToString());

            nodoAggiunto.Tag = elemento;
            return(nodoAggiunto);
        }
Exemplo n.º 3
0
        private void RimuoviElementoSingoloClick(object sender, EventArgs e)
        {
            TreeNode tn = treeView1.SelectedNode;

            if (tn == null)
            {
                return;
            }
            TreeNode padre = tn.Parent;

            if (padre == null)
            {
                return;
            }

            ElementoPreventivoModel elemento = (ElementoPreventivoModel)tn.Tag;

            _elementiPreventivo.Remove(elemento);

            if (tn.Nodes.Count > 0)
            {
                TreeNode[] figli = new TreeNode[tn.Nodes.Count];
                tn.Nodes.CopyTo(figli, 0);
                tn.Remove();
                padre.Nodes.AddRange(figli);
            }
            else
            {
                tn.Remove();
            }

            RefreshGridView();
        }
Exemplo n.º 4
0
        private void aggiungiFiglio(TreeNode nodoPadre, ElementoPreventivoModel elementoDaAggiungere)
        {
            TreeNode nodoAggiunto = aggungiNodo(nodoPadre, elementoDaAggiungere);

            foreach (ElementoPreventivoModel figlio in _elementiPreventivo.Where(x => x.IdPadre == elementoDaAggiungere.IdElementoPreventivo))
            {
                aggiungiFiglio(nodoAggiunto, figlio);
            }
        }
Exemplo n.º 5
0
 private void eliminaElementiFigliDallaLista(TreeNode tn)
 {
     foreach (TreeNode t in tn.Nodes)
     {
         ElementoPreventivoModel elementoFiglio = (ElementoPreventivoModel)t.Tag;
         _elementiPreventivo.Remove(elementoFiglio);
         eliminaElementiFigliDallaLista(t);
     }
 }
Exemplo n.º 6
0
        private void RimuoviRamoClick(object sender, EventArgs e)
        {
            TreeNode tn = treeView1.SelectedNode;

            eliminaElementiFigliDallaLista(tn);
            ElementoPreventivoModel elemento = (ElementoPreventivoModel)tn.Tag;

            _elementiPreventivo.Remove(elemento);

            tn.Remove();
            RefreshGridView();
        }
Exemplo n.º 7
0
        private void inserisciElementoNellaLista(ElementoPreventivoModel elemento, TreeNode nodoPadre, decimal idPadre)
        {
            object padre = nodoPadre.Tag;

            if (idPadre == -1)
            {
                _elementiPreventivo.Add(elemento);
            }
            else
            {
                int indice = _elementiPreventivo.IndexOf(padre as ElementoPreventivoModel);
                _elementiPreventivo.Insert(indice + 1, elemento);
            }
        }
Exemplo n.º 8
0
        private void clonaRamoDaCopiare(TreeNode nodoDaCopiare, TreeNode nodoPadre)
        {
            ElementoPreventivoModel elementoDaClonare = (ElementoPreventivoModel)nodoDaCopiare.Tag;
            decimal idPadre = estraiIdPadre(nodoPadre);
            ElementoPreventivoModel nuovoElemento = creaNuovoElementoModel(elementoDaClonare, idPadre);
            TreeNode nuovoNodo = aggungiNodo(nodoPadre, nuovoElemento);

            inserisciElementoNellaLista(nuovoElemento, nodoPadre, idPadre);

            foreach (TreeNode figlio in nodoDaCopiare.Nodes)
            {
                clonaRamoDaCopiare(figlio, nuovoNodo);
            }
        }
Exemplo n.º 9
0
        private void dgvElementi_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (_disabilitaEdit)
            {
                return;
            }
            try
            {
                _disabilitaEdit = true;

                decimal idElemento = (decimal)dgvElementi.Rows[e.RowIndex].Cells[0].Value;
                if (e.ColumnIndex == 1)
                {
                    TreeNode[] nodi = treeView1.Nodes.Find(idElemento.ToString(), true);
                    if (nodi.Length == 1)
                    {
                        TreeNode nodo = nodi[0];
                        nodo.Text = ((ElementoPreventivoModel)(nodo.Tag)).ToString();
                    }
                }

                if (e.ColumnIndex == dgvElementi.Columns["Processo"].Index)
                {
                    DataGridViewComboBoxCell cella = (DataGridViewComboBoxCell)dgvElementi.Rows[e.RowIndex].Cells[e.ColumnIndex];
                    if (cella == null)
                    {
                        return;
                    }
                    string        descrizioneProcesso = (string)cella.Value;
                    ProcessoModel processoSelezionato = _processiGalvanici.Where(x => x.Descrizione == descrizioneProcesso).FirstOrDefault();
                    if (processoSelezionato == null)
                    {
                        return;
                    }
                    ElementoPreventivoModel elementoPreventivo = _elementiPreventivo.Where(x => x.IdElementoPreventivo == idElemento).FirstOrDefault();
                    elementoPreventivo.TabellaEsterna = "PROCESSI";
                    elementoPreventivo.IdEsterna      = processoSelezionato.IdProcesso;
                    elementoPreventivo.Processo       = descrizioneProcesso;
                }
            }
            catch (Exception ex)
            {
                MostraEccezione("", ex);
            }
            finally
            {
                _disabilitaEdit = false;
            }
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        private ElementoPreventivoModel convertiFaseInElementoPreventivo(FaseModel fase, decimal idElementoPreventivo, decimal idPadre)
        {
            ElementoPreventivoModel elemento = new ElementoPreventivoModel();

            elemento.IdElementoPreventivo = idElementoPreventivo;
            elemento.IdPadre           = idPadre;
            elemento.IdPreventivo      = _preventivoSelezionato.IdPreventivo;
            elemento.Codice            = fase.Codice;
            elemento.Reparto           = fase.Reparto;
            elemento.Ricarico          = fase.Ricarico;
            elemento.CostoOrario       = fase.Costo;
            elemento.IncludiPreventivo = fase.IncludiPreventivo;
            elemento.IdEsterna         = -1;
            elemento.TabellaEsterna    = string.Empty;
            elemento.PezziOrari        = 0;
            elemento.Peso        = 0;
            elemento.Superficie  = 0;
            elemento.Quantita    = 1;
            elemento.Descrizione = fase.Descrizione;
            elemento.Articolo    = string.Empty;
            elemento.Nota        = string.Empty;
            return(elemento);
        }
Exemplo n.º 12
0
        private ElementoPreventivoModel creaNuovoElementoModel(ElementoPreventivoModel elementoModelDaClonare, decimal idPadre)
        {
            ElementoPreventivoModel elemento = new ElementoPreventivoModel();

            elemento.IdElementoPreventivo = MPIntranet.Business.Articolo.EstraId();
            elemento.IdPadre           = idPadre;
            elemento.IdPreventivo      = _preventivoSelezionato.IdPreventivo;
            elemento.Codice            = elementoModelDaClonare.Codice;
            elemento.Reparto           = elementoModelDaClonare.Reparto;
            elemento.Ricarico          = elementoModelDaClonare.Ricarico;
            elemento.CostoOrario       = elementoModelDaClonare.CostoOrario;
            elemento.IncludiPreventivo = elementoModelDaClonare.IncludiPreventivo;
            elemento.IdEsterna         = -1;
            elemento.TabellaEsterna    = string.Empty;
            elemento.PezziOrari        = elementoModelDaClonare.PezziOrari;
            elemento.Peso        = elementoModelDaClonare.Peso;
            elemento.Superficie  = elementoModelDaClonare.Superficie;
            elemento.Quantita    = elementoModelDaClonare.Quantita;
            elemento.Descrizione = elementoModelDaClonare.Descrizione;
            elemento.Articolo    = elementoModelDaClonare.Articolo;
            elemento.Nota        = elementoModelDaClonare.Nota;
            return(elemento);
        }
Exemplo n.º 13
0
        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (_disabilitaEdit)
            {
                return;
            }
            try
            {
                if (e.Node.Tag is ProdottoFinitoModel)
                {
                    return;
                }
                ElementoPreventivoModel elemento = (ElementoPreventivoModel)e.Node.Tag;
                decimal idElemento = elemento.IdElementoPreventivo;

                dgvElementi.ClearSelection();

                foreach (DataGridViewRow riga in dgvElementi.Rows)
                {
                    decimal idCella = (decimal)riga.Cells[0].Value;
                    if (idCella == idElemento)
                    {
                        riga.Selected = true;
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                MostraEccezione("", ex);
            }
            finally
            {
                _disabilitaEdit = false;
            }
        }
Exemplo n.º 14
0
 private void eliminaElementoDallaLista(ElementoPreventivoModel elemento)
 {
     _elementiPreventivo.Remove(elemento);
 }
Exemplo n.º 15
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();
            }
        }
Exemplo n.º 16
0
        private void calcolaCostiGalvanica()
        {
            List <ElementoGrigliaCostoGalvanica> elementiCostiGalvanica = new List <ElementoGrigliaCostoGalvanica>();

            List <ElementoCostoPreventivoModel> elementiGalvanici = _elementiCostoPreventivo.Where(x => x.ElementoPreventivo.Reparto != null && x.ElementoPreventivo.Reparto.Codice == Reparti.Galvanica).ToList();

            if (elementiGalvanici.Count == 0)
            {
                MessageBox.Show("Non sono presenti elementi associati al reparto galvanica GALVA", "ATTENZIONE", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            Anagrafica a = new Anagrafica();
            List <PrezzoMaterialeModel> prezzi = a.CreaListaPrezzoMaterialeModel();

            foreach (ElementoCostoPreventivoModel elementoGalvanico in elementiGalvanici)
            {
                decimal dm2    = 0.1M * 0.1M;
                decimal micron = (1M / 1000) * (1M / 1000);
                ElementoPreventivoModel elementoPreventivo = elementoGalvanico.ElementoPreventivo;
                if (elementoPreventivo.IdEsterna == ElementiVuoti.ProcessoGalvanicoVuoto)
                {
                    continue;
                }
                ProcessoModel processoGalvanico = _processi.Where(x => x.IdProcesso == elementoPreventivo.IdEsterna).FirstOrDefault();  //  _preventivoCostoSelezionato.Preventvo.Processo;
                decimal       costo             = 0;
                foreach (FaseProcessoModel fase in processoGalvanico.Fasi)
                {
                    if (fase.Vasca.AbilitaStrato)
                    {
                        if (fase.Vasca.Materiale.IdMateriale == ElementiVuoti.NessunMateriale)
                        {
                            continue;
                        }
                        ElementoGrigliaCostoGalvanica elementoCostoGalvanica = new ElementoGrigliaCostoGalvanica();
                        elementiCostiGalvanica.Add(elementoCostoGalvanica);
                        elementoCostoGalvanica.Articolo      = elementoPreventivo.Articolo;
                        elementoCostoGalvanica.Elemento      = elementoPreventivo.Codice;
                        elementoCostoGalvanica.Superficie    = elementoPreventivo.Superficie;
                        elementoCostoGalvanica.Materiale     = fase.Vasca.Materiale.Descrizione;
                        elementoCostoGalvanica.Spessore      = fase.SpessoreNominale;
                        elementoCostoGalvanica.PesoSpecifico = fase.Vasca.Materiale.PesoSpecifico;

                        decimal volumeMetriCubi     = (elementoPreventivo.Superficie * dm2) * (fase.SpessoreNominale * micron);
                        decimal volumeDecimetriCubi = volumeMetriCubi * 1000;
                        elementoCostoGalvanica.Volume = volumeDecimetriCubi;
                        decimal pesoInKg = volumeDecimetriCubi * fase.Vasca.Materiale.PesoSpecifico;// peso speficifico espresso in kg/dm3
                        decimal pesoInGr = pesoInKg * 1000;
                        elementoCostoGalvanica.Peso = pesoInGr;
                        decimal prezzoGrammo        = 0;
                        PrezzoMaterialeModel prezzo = prezzi.Where(x => x.Materiale.IdMateriale == fase.Vasca.Materiale.IdMateriale).FirstOrDefault();
                        if (prezzo == null)
                        {
                            string messaggio = string.Format("Prezzo materiale {0} non presente. Il prezzo sarà pre-impostato a zero", fase.Vasca.Materiale);
                            MessageBox.Show(messaggio, "ATTENZIONE", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else
                        {
                            prezzoGrammo = prezzo.Prezzo;
                        }
                        elementoCostoGalvanica.PrezzoGrammo = prezzoGrammo;
                        decimal costoFase = Math.Round(prezzoGrammo * pesoInGr, 4);
                        costo += costoFase;
                        elementoCostoGalvanica.Costo = costoFase;
                    }
                }
                elementoGalvanico.CostoOrario   = costo;
                elementoGalvanico.CostoArticolo = costo * (1 + elementoGalvanico.Ricarico / 100);
            }

            dgvCostiGalvanica.DataSource = elementiCostiGalvanica;
            RefreshGridViewElementi();
        }