//-------------------------------------------------------------------- private bool ItemControl_OnLeaveLastControl(object sender, EventArgs args) { CControleEditeValorisationEquipement ctrl = sender as CControleEditeValorisationEquipement; if (ctrl != null) { //Regarde si le dernier item est vide if (m_listeLignes.Items.Count() > 0 && !LockEdition && m_lotValorisation != null) { CCustomizableListItem item = m_listeLignes.Items.ElementAt(m_listeLignes.Items.Count() - 1); CValorisationElement ligne = item != null ? item.Tag as CValorisationElement : null; if (ligne != null && ligne.ElementValorisé != null) { ligne = new CValorisationElement(m_lotValorisation.ContexteDonnee); ligne.CreateNewInCurrentContexte(); ligne.LotValorisation = m_lotValorisation; item = new CCustomizableListItem(); item.Tag = ligne; m_listeLignes.AddItem(item, true); m_listeLignes.CurrentItemIndex = item.Index; return(true); } } } return(false); }
public CResultAErreur MajChamps() { CResultAErreur result = CResultAErreur.True; m_listeLignes.ItemControl.MajChamps(); foreach (CCustomizableListItem item in m_listeLignes.Items) { CValorisationElement valo = item.Tag as CValorisationElement; if (valo != null) { if (valo.ElementValorisé == null) { m_listeLignes.RemoveItem(item, false); valo.Delete(true); } } } m_listeLignes.Refresh(); /*foreach (CControleEditeValorisationEquipement ctrl in ControlesValorisation) * { * result = ctrl.MajChamps(); * if (!result) * return result; * }*/ return(result); }
//------------------------------------------------------------------- public override CResultAErreur TraitementAvantSauvegarde(CContexteDonnee contexte) { CResultAErreur result = base.TraitementAvantSauvegarde(contexte); if (!result) { return(result); } DataTable table = contexte.Tables[CValorisationElement.c_nomTable]; if (table == null) { return(result); } ArrayList lst = new ArrayList(table.Rows); foreach (DataRow row in lst) { if (row.RowState != DataRowState.Unchanged) { ///Cherche les impacts sur les couts CValorisationElement valorisation = new CValorisationElement(row); if (row.RowState == DataRowState.Deleted) { valorisation.VersionToReturn = DataRowVersion.Original; } CLotValorisation lot = valorisation.LotValorisation; if (lot.Row.RowState == DataRowState.Deleted) { lot.VersionToReturn = DataRowVersion.Original; } foreach (CLivraisonLotValorisation livs in lot.RelationsLivraisons) { CLivraisonEquipement livraison = livs.Livraison; if (livraison == null) { continue; } if (livraison.Row.RowState == DataRowState.Deleted) { livraison.VersionToReturn = DataRowVersion.Original; } CCommande commande = livraison.Commande; if (commande == null || commande.Row.RowState == DataRowState.Deleted) { continue;//la commande a été supprimée } CListeObjetsDonnees lignes = commande.Lignes; foreach (CLigneCommande ligne in lignes) { if (ligne.Row.RowState != DataRowState.Deleted) { CUtilElementACout.OnChangeCout(ligne, true, false);//changement du cout réel } } } } } return(result); }
//---------------------------------------------------------------------------------------------- private void UpdateQuantite() { CTypeConsommable tpCons = m_selectTypeEquipement.ElementSelectionne as CTypeConsommable; if (tpCons != null && CurrentItem != null) { CValorisationElement val = CurrentItem.Tag as CValorisationElement; IUnite unite = tpCons.Unite; if (unite != null) { m_txtQuantite.DefaultFormat = unite.LibelleCourt; } m_txtQuantite.UseValueFormat = true; CValeurUnite v = val.QuantiteEtUnite; if (v != null && unite != null) { if (v.IUnite == null || v.IUnite.Classe.GlobalId != unite.Classe.GlobalId) { v = null; } } m_txtQuantite.UnitValue = v; m_txtQuantite.LockEdition = LockEdition; } else { IUnite unite = CGestionnaireUnites.GetUnite(CClasseUniteUnite.c_idUnite); m_txtQuantite.DefaultFormat = unite.LibelleCourt; m_txtQuantite.UnitValue = new CValeurUnite(1, unite.LibelleCourt); m_txtQuantite.LockEdition = true; } }
//------------------------------------------------------------------- public override CResultAErreur VerifieDonnees(CObjetDonnee objet) { CResultAErreur result = CResultAErreur.True; try { CValorisationElement valorisationElement = (CValorisationElement)objet; if (valorisationElement.ElementValorisé == null) { result.EmpileErreur(I.T("Valuation must be linked to an equipment or a consumable type|20171")); } if (valorisationElement.LotValorisation == null) { result.EmpileErreur(I.T("Valuation must be linked to a valuation lot|20172")); } if (valorisationElement.TypeEquipement != null) { CListeObjetsDonnees lstTmp = new CListeObjetDonneeGenerique <CValorisationElement>(objet.ContexteDonnee); lstTmp.Filtre = new CFiltreData( CValorisationElement.c_champId + "<>@1 and " + CTypeEquipement.c_champId + "=@2 and " + CLotValorisation.c_champId + "=@3", valorisationElement.Id, valorisationElement.TypeEquipement.Id, valorisationElement.LotValorisation.Id); lstTmp.InterditLectureInDB = true;//On considère que c'est déjà lu pour optimiser if (lstTmp.Count > 0) { result.EmpileErreur(I.T("Can not have multiple valuation for Equipment type @1 in lot @2|20190", valorisationElement.TypeEquipement.Libelle, valorisationElement.LotValorisation.Libelle)); } } if (valorisationElement.TypeConsommable != null) { CListeObjetsDonnees lstTmp = new CListeObjetDonneeGenerique <CValorisationElement>(objet.ContexteDonnee); lstTmp.Filtre = new CFiltreData( CValorisationElement.c_champId + "<>@1 and " + CTypeConsommable.c_champId + "=@2 and " + CLotValorisation.c_champId + "=@3", valorisationElement.Id, valorisationElement.TypeConsommable.Id, valorisationElement.LotValorisation.Id); lstTmp.InterditLectureInDB = true;//On considère que c'est déjà lu pour optimiser if (lstTmp.Count > 0) { result.EmpileErreur(I.T("Can not have multiple valuation for Consumable type @1 in lot @2|20191", valorisationElement.TypeConsommable.Libelle, valorisationElement.LotValorisation.Libelle)); } } } catch (Exception e) { result.EmpileErreur(new CErreurException(e)); } return(result); }
//------------------------------------------------------------ void ctrl_OnAddLine(object sender, EventArgs e) { if (m_extModeEdition.ModeEdition) { CCustomizableListItem item = new CCustomizableListItem(); CValorisationElement valo = new CValorisationElement(m_lotValorisation.ContexteDonnee); valo.CreateNewInCurrentContexte(); valo.LotValorisation = m_lotValorisation; item.Tag = valo; m_listeLignes.AddItem(item, true); m_listeLignes.CurrentItemIndex = item.Index; } }
protected override CResultAErreur MyInitChamps(CCustomizableListItem item) { CResultAErreur result = CResultAErreur.True; if (item == null) { return(result); } CValorisationElement ligne = item.Tag as CValorisationElement; if (ligne == null || !ligne.IsValide()) { MyInitChamps(null); return(result); } CLotValorisation lot = ligne.LotValorisation; m_selectTypeEquipement.InitMultiple(new CConfigTextBoxFiltreRapide[] { new CConfigTextBoxFiltreRapide( typeof(CTypeEquipement), null, "Libelle"), new CConfigTextBoxFiltreRapide( typeof(CTypeConsommable), null, "Libelle"), new CConfigTextBoxFiltreRapide( typeof(CTypeOperation), null, "Libelle") }, false); m_selectTypeEquipement.ElementSelectionne = ligne.ElementValorisé as CObjetDonnee; if (ligne != null && ligne.EquipementsLies.Count > 0) { m_extModeEdition.SetModeEdition(m_selectTypeEquipement, TypeModeEdition.Autonome); m_selectTypeEquipement.LockEdition = true; } else { m_extModeEdition.SetModeEdition(m_selectTypeEquipement, TypeModeEdition.EnableSurEdition); m_selectTypeEquipement.LockEdition = !m_extModeEdition.ModeEdition; } m_txtValeur.DoubleValue = ligne != null ? (double?)ligne.Valeur : null; if (ligne != null && ligne.IsNew() && ligne.Valeur == 0) { m_txtValeur.DoubleValue = null; } UpdateQuantite(); return(result); }
//---------------------------------------------------------------- protected override CResultAErreur MyMajChamps() { CResultAErreur result = CResultAErreur.True; if (m_extModeEdition.ModeEdition) { CValorisationElement ligne = CurrentItem != null ? CurrentItem.Tag as CValorisationElement : null; if (ligne != null && ligne.IsValide()) { ligne.ElementValorisé = m_selectTypeEquipement.ElementSelectionne as IElementValorisable; ligne.Valeur = m_txtValeur.DoubleValue == null ? 0 : m_txtValeur.DoubleValue.Value; ligne.QuantiteEtUnite = m_txtQuantite.UnitValue; } } return(result); }
public double GetValuationForDate(DateTime dt) { CListeObjetsDonnees lstValOp = Valorisations; CListeObjetsDonnees lstLot = lstValOp.GetDependances("LotValorisation"); if (lstValOp.Count == 0) { return(0); } lstLot.Tri = CLotValorisation.c_champDateLot; CLotValorisation lot = lstLot[0] as CLotValorisation; if (lot != null && lot.DateLot.Date.AddMinutes(-1) > dt)//Premier plus récent->premier { CValorisationElement val = lot.GetValorisation(this); if (val != null) { return(val.Valeur); } return(0); } lstLot.InterditLectureInDB = true; lstLot.Filtre = new CFiltreData(CLotValorisation.c_champDateLot + "<@1", dt.Date.AddDays(1)); lstLot.Tri = CLotValorisation.c_champDateLot; if (lstLot.Count > 0) { lot = lstLot[lstLot.Count - 1] as CLotValorisation; if (lot != null) { CValorisationElement val = lot.GetValorisation(this); if (val != null) { return(val.Valeur); } } } return(0); }
//------------------------------------------------------------ void ctrl_OnDelete(object sender, EventArgs e) { CControleEditeValorisationEquipement ctrl = sender as CControleEditeValorisationEquipement; if (ctrl == null) { return; } CValorisationElement ligne = ctrl.CurrentItem != null ? ctrl.CurrentItem.Tag as CValorisationElement : null; if (ligne != null) { CResultAErreur result = ligne.Delete(true); if (!result) { CFormAlerte.Afficher(result.Erreur); return; } } m_listeLignes.RemoveItem(ctrl.CurrentItem, true); m_listeLignes.CurrentItemIndex = m_listeLignes.CurrentItemIndex; }
//------------------------------------------------------------------------ public double GetValuationForDate(DateTime dt, CValeurUnite quantite) { CListeObjetsDonnees lstValEqpt = Valorisations; CListeObjetsDonnees lstLot = lstValEqpt.GetDependances("LotValorisation"); double fQuantite = 1; if (quantite != null && Unite != null) { if (quantite.IUnite == null) { fQuantite = quantite.Valeur; } else { fQuantite = quantite.ConvertTo(Unite.GlobalId).Valeur; } } if (lstValEqpt.Count == 0) { return(0); } lstLot.Tri = CLotValorisation.c_champDateLot; CLotValorisation lot = lstLot[0] as CLotValorisation; if (lot != null && lot.DateLot.Date.AddMinutes(-1) > dt)//Premier plus récent->premier { CValorisationElement val = lot.GetValorisation(this); if (val != null) { return(val.Valeur * fQuantite); } return(0); } lstLot.InterditLectureInDB = true; lstLot.Filtre = new CFiltreData(CLotValorisation.c_champDateLot + "<@1", dt.Date.AddDays(1)); lstLot.Tri = CLotValorisation.c_champDateLot; if (lstLot.Count > 0) { lot = lstLot[lstLot.Count - 1] as CLotValorisation; if (lot != null) { CValorisationElement val = lot.GetValorisation(this); if (val != null) { CValeurUnite v = val.QuantiteEtUnite; IUnite monUnite = Unite; if (v != null && monUnite != null) { v = v.ConvertTo(monUnite.GlobalId); if (v.Valeur != 0) { return(val.Valeur / v.Valeur * fQuantite); } } return(val.Valeur * fQuantite); } } } return(0); }