private TreeNode aggungiNodo(TreeNode nodoRadice, ElementoCostoPreventivoModel elemento) { TreeNode nodoAggiunto = nodoRadice.Nodes.Add(elemento.IdElementoCosto.ToString(), elemento.ToString()); nodoAggiunto.Tag = elemento; return(nodoAggiunto); }
private List <ElementoCostoPreventivoModel> creaElementiCostoPreventivo(decimal idPreventivoCosto) { Articolo a = new Articolo(); List <ElementoCostoPreventivoModel> lista = new List <ElementoCostoPreventivoModel>(); List <ElementoPreventivoModel> elementiPreventivo = a.CreaListaElementoPreventivoModel(_preventivoModel.IdPreventivo); foreach (ElementoPreventivoModel elemento in elementiPreventivo) { ElementoCostoPreventivoModel elementoCosto = new ElementoCostoPreventivoModel(); elementoCosto.IdElementoCosto = Articolo.EstraId(); elementoCosto.ElementoPreventivo = elemento; elementoCosto.IdPreventivoCosto = idPreventivoCosto; elementoCosto.Ricarico = elemento.Ricarico; elementoCosto.CostoOrario = elemento.CostoOrario; elementoCosto.IncludiPreventivo = elemento.IncludiPreventivo; elementoCosto.IdEsterna = elemento.IdEsterna; elementoCosto.TabellaEsterna = elemento.TabellaEsterna; elementoCosto.PezziOrari = elemento.PezziOrari; elementoCosto.Quantita = elemento.Quantita; decimal costoPezzo = elemento.PezziOrari == 0 ? 0 : elemento.CostoOrario / elemento.PezziOrari; elementoCosto.CostoArticolo = (1 + elemento.Ricarico / 100) * costoPezzo; elementoCosto.CostoFigli = 0; elementoCosto.CostoCompleto = 0; lista.Add(elementoCosto); } Articolo.RicalcolaCostoFigliListaElementiCostoPreventiviModel(lista); return(lista); }
private void aggiungiFiglio(TreeNode nodoPadre, ElementoCostoPreventivoModel elementoDaAggiungere) { TreeNode nodoAggiunto = aggungiNodo(nodoPadre, elementoDaAggiungere); foreach (ElementoCostoPreventivoModel figlio in _elementiCostoPreventivo.Where(x => x.ElementoPreventivo.IdPadre == elementoDaAggiungere.ElementoPreventivo.IdElementoPreventivo)) { aggiungiFiglio(nodoAggiunto, figlio); } }
private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtDescrizione.Text)) { lblMessaggio.Text = "La descrizione è obbligaoria"; return; } if (chkCopiaPrecedente.Checked && ddlVersionePrecedente.SelectedIndex == -1) { lblMessaggio.Text = "Selezionare la versione precedente da copiare"; return; } lblMessaggio.Text = string.Empty; Articolo articolo = new Articolo(string.Empty); lblMessaggio.Text = articolo.CreaPreventivoCosto(_versioni, txtDescrizione.Text, _preventivoModel.IdPreventivo, txtNota.Text, _account); List <PreventivoCostoModel> lista = articolo.CreaListaPreventivoCostiModel(_preventivoModel.IdPreventivo); PreventivoCostoModel preventivoCreato = lista.Where(x => x.Preventvo.IdPreventivo == _preventivoModel.IdPreventivo && x.Versione == _versioni).FirstOrDefault(); List <ElementoCostoPreventivoModel> elementiNuovi = creaElementiCostoPreventivo(preventivoCreato.IdPreventivoCosto); if (chkCopiaPrecedente.Checked) { PreventivoCostoModel preventivoDaCopiare = (PreventivoCostoModel)ddlVersionePrecedente.SelectedItem; List <ElementoCostoPreventivoModel> elementiDaCopiare = articolo.CreaListaElementoCostoPreventivoModel(preventivoDaCopiare.IdPreventivoCosto); foreach (ElementoCostoPreventivoModel elemento in elementiDaCopiare) { ElementoCostoPreventivoModel elementoNuovo = new ElementoCostoPreventivoModel(); elementoNuovo.IdElementoCosto = Articolo.EstraId(); elementoNuovo.ElementoPreventivo = elemento.ElementoPreventivo; elementoNuovo.IdPreventivoCosto = preventivoCreato.IdPreventivoCosto; 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.Quantita = elemento.Quantita; elementoNuovo.CostoArticolo = elemento.CostoArticolo; elementoNuovo.CostoCompleto = elemento.CostoCompleto; elementoNuovo.CostoFigli = elemento.CostoFigli; elementiNuovi.Add(elementoNuovo); } } articolo.SalvaElementiCostoPreventivo(elementiNuovi, preventivoCreato.IdPreventivoCosto, _account); }
private void dgvElementi_CellValidated(object sender, DataGridViewCellEventArgs e) { try { _disabilitaEdit = true; if (e.RowIndex > -1) { decimal idElementoCosto = (decimal)dgvElementi.Rows[e.RowIndex].Cells[IdElementoCosto.Index].Value; ElementoCostoPreventivoModel elementoCosto = _elementiCostoPreventivo.Where(x => x.IdElementoCosto == idElementoCosto).FirstOrDefault(); if (elementoCosto == null) { return; } RepartoModel reparto = elementoCosto.ElementoPreventivo.Reparto; if (reparto == null || reparto.Codice == Reparti.Galvanica) { return; } if (e.ColumnIndex == PezziOrari.Index || e.ColumnIndex == Costo.Index || e.ColumnIndex == Ricarico.Index) { decimal margine = (decimal)dgvElementi.Rows[e.RowIndex].Cells[Ricarico.Index].Value; decimal costoOrario = (decimal)dgvElementi.Rows[e.RowIndex].Cells[Costo.Index].Value; decimal pezziOrari = (decimal)dgvElementi.Rows[e.RowIndex].Cells[PezziOrari.Index].Value; decimal costoPezzo = pezziOrari == 0 ? 0 : costoOrario / pezziOrari; decimal costoArticolo = (1 + margine / 100) * costoPezzo; dgvElementi.Rows[e.RowIndex].Cells[colCostoArticolo.Index].Value = costoArticolo; MPIntranet.Business.Articolo.RicalcolaCostoFigliListaElementiCostoPreventiviModel(_elementiCostoPreventivo); RefreshGridViewElementi(); } List <ElementoCostoPreventivoModel> radici = _elementiCostoPreventivo.Where(x => x.ElementoPreventivo.IdPadre == -1).ToList(); if (radici.Count == 1) { ElementoCostoPreventivoModel prodottofinito = radici[0]; txtCostoProdottoFinito.Text = prodottofinito.CostoCompleto.ToString(); } } } finally { _disabilitaEdit = false; } }
private void dgvElementi_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) { if (dgvElementi.Rows[e.RowIndex].Cells[IdElementoCosto.Index].Value == null) { return; } decimal idElementoCosto = (decimal)dgvElementi.Rows[e.RowIndex].Cells[IdElementoCosto.Index].Value; ElementoCostoPreventivoModel elementoCosto = _elementiCostoPreventivo.Where(x => x.IdElementoCosto == idElementoCosto).FirstOrDefault(); if (elementoCosto == null) { return; } dgvElementi.Rows[e.RowIndex].Cells[Articolo.Index].Value = elementoCosto.ElementoPreventivo.Articolo; dgvElementi.Rows[e.RowIndex].Cells[Codice.Index].Value = elementoCosto.ElementoPreventivo.Codice; dgvElementi.Rows[e.RowIndex].Cells[Descrizione.Index].Value = elementoCosto.ElementoPreventivo.Descrizione; dgvElementi.Rows[e.RowIndex].Cells[Processo.Index].Value = elementoCosto.ElementoPreventivo.Processo; dgvElementi.Rows[e.RowIndex].Cells[Peso.Index].Value = elementoCosto.ElementoPreventivo.Peso; dgvElementi.Rows[e.RowIndex].Cells[Superficie.Index].Value = elementoCosto.ElementoPreventivo.Superficie; dgvElementi.Rows[e.RowIndex].Cells[Quantita.Index].Value = elementoCosto.ElementoPreventivo.Quantita; RepartoModel reparto = elementoCosto.ElementoPreventivo.Reparto; dgvElementi.Rows[e.RowIndex].Cells[Reparto.Index].Value = elementoCosto.ElementoPreventivo.Reparto; //if (reparto == null) return; //if (reparto.Codice == Reparti.Galvanica) //{ // dgvElementi.Rows[e.RowIndex].Cells[11].ReadOnly = true; // dgvElementi.Rows[e.RowIndex].Cells[12].ReadOnly = true; // dgvElementi.Rows[e.RowIndex].Cells[13].ReadOnly = true; //} //if (reparto == null) return; //GruppoRepartoModel grm = _gruppiRepartiModel.Where(x => x.Reparto.IdReparto == reparto.IdReparto).FirstOrDefault(); //if (grm == null) return; //dgvElementi.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.FromName(grm.Gruppo.Colore); //dgvElementi.Rows[e.RowIndex].Cells[6].Value = grm.Gruppo.Codice; }
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (_disabilitaEdit) { return; } try { if (e.Node.Tag is ProdottoFinitoModel) { return; } ElementoCostoPreventivoModel elemento = (ElementoCostoPreventivoModel)e.Node.Tag; decimal idElementoCosto = elemento.IdElementoCosto; dgvElementi.ClearSelection(); foreach (DataGridViewRow riga in dgvElementi.Rows) { decimal idCella = (decimal)riga.Cells[IdElementoCosto.Index].Value; if (idCella == idElementoCosto) { riga.Selected = true; return; } } } catch (Exception ex) { MostraEccezione("", ex); } finally { _disabilitaEdit = false; } }