public static void Main(string[] args) { var env = new Env <Transaction>(); Fattura f = new Fattura(env); RigaFattura rf1 = new RigaFattura(env); RigaFattura rf2 = new RigaFattura(env); RigaFattura rf3 = new RigaFattura(env); f.Commit(); rf1.Commit(); rf2.Commit(); rf3.Commit(); f.AggregationRigaFattura.Add(rf1); f.AggregationRigaFattura.Add(rf2); f.AggregationRigaFattura.Add(rf3); f.Commit(); f.AggregationRigaFattura.Remove(rf2); f.Commit(); f.StampaRighe(1, 3); env.FailsafeTransactionalCommit(); }
internal void Init(Vendita vendita, Fattura fattura) { m_Vendita = this.unitOfWork1.GetObjectByKey <Vendita>(vendita.Oid); m_Struttura = m_Vendita.Struttura; if (m_Struttura.Oid != Program.Postazione.Struttura.Oid && !Program.UtenteCollegato.Amministratore) { throw new Exception("non autorizzato"); } if (fattura != null) { m_Fattura = this.unitOfWork1.GetObjectByKey <Fattura>(fattura.Oid); this.textEditFatturaNumero.Text = m_Fattura.Codice; Lock(true); } else { m_IsNewInvoice = true; m_Fattura = new Fattura(this.unitOfWork1); m_Fattura.Vendita = m_Vendita; m_Fattura.Struttura = m_Struttura; m_Fattura.DataContabile = m_Vendita.DataContabile; m_Fattura.Codice = m_Struttura.SiglaFattura; m_Fattura.Anno = m_Fattura.DataContabile.Year; if (string.IsNullOrEmpty(m_Fattura.Codice)) { throw new Exception("Nessuna SiglaFattura associata alla struttura " + m_Struttura.Descrizione); } var prog = this.unitOfWork1.FindObject <Progressivo>(new GroupOperator(new CriteriaOperator[] { new BinaryOperator("Codice", m_Fattura.Codice), new BinaryOperator("Anno", m_Fattura.Anno) })); if (prog == null) { m_Fattura.Numero = 1; } else { m_Fattura.Numero = prog.UltimoNumero + 1; } m_Fattura.CodiceCompleto = string.Format("{0}/{1}/{2}", m_Fattura.Numero, m_Fattura.Codice, m_Fattura.Anno); m_Fattura.IntestazioneRiga1 = "Spett.le "; m_Fattura.IntestazioneRiga4 = "C.F. : "; m_Fattura.Note = "Pagamento effettuato in contante"; m_Fattura.Utente = this.unitOfWork1.GetObjectByKey <Utente>(Program.UtenteCollegato.Oid); m_Fattura.Postazione = this.unitOfWork1.GetObjectByKey <Postazione>(Program.Postazione.Oid); foreach (var rv in m_Vendita.RigheVenditaVariante) { if (rv.PrezzoTotale > 0) { if (rv.Variante.TipologiaTre == EnumTipologiaTre.CardMyFE) { if (rv.Variante.MyFeComune()) { var mrr = new RigaFattura(this.unitOfWork1); mrr.Fattura = m_Fattura; mrr.DescrizioneRiga = rv.Variante.Descrizione; mrr.PrezzoUnitario = Card.PrezzoCard(rv.Card.TipologiaCard); mrr.Quantita = rv.Quantita; mrr.PrezzoTotale = mrr.PrezzoUnitario * rv.Quantita; m_Fattura.RigheFattura.Add(mrr); } } else { var mrr = new RigaFattura(this.unitOfWork1); mrr.Fattura = m_Fattura; mrr.DescrizioneRiga = rv.Variante.Descrizione; mrr.PrezzoUnitario = rv.PrezzoUnitario; mrr.Quantita = rv.Quantita; mrr.PrezzoTotale = rv.PrezzoTotale; m_Fattura.RigheFattura.Add(mrr); } } } Lock(false); } this.textEditFatturaNumero.Text = m_Fattura.CodiceCompleto; this.textEditFatturaData.DateTime = m_Fattura.DataContabile; this.textEditIntestazione1.Text = m_Fattura.IntestazioneRiga1; this.textEditIntestazione2.Text = m_Fattura.IntestazioneRiga2; this.textEditIntestazione3.Text = m_Fattura.IntestazioneRiga3; this.textEditIntestazione4.Text = m_Fattura.IntestazioneRiga4; this.textEditNote.Text = m_Fattura.Note; this.gridControl1.DataSource = m_Fattura.RigheFattura; this.gridView1.BestFitColumns(); }
/// <summary> /// Deep Loads the <see cref="IEntity"/> object with criteria based of the child /// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>. /// </summary> /// <remarks> /// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph. /// </remarks> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="entity">The <see cref="GenTest.Entities.Fattura"/> object to load.</param> /// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param> /// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param> /// <param name="childTypes">GenTest.Entities.Fattura Property Collection Type Array To Include or Exclude from Load</param> /// <param name="innerList">A collection of child types for easy access.</param> /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception> /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception> internal override void DeepLoad(TransactionManager transactionManager, GenTest.Entities.Fattura entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList) { if (entity == null) { return; } #region ComposedRigaFatturaIDSource if (CanDeepLoad(entity, "RigaFattura|ComposedRigaFatturaIDSource", deepLoadType, innerList) && entity.ComposedRigaFatturaIDSource == null) { object[] pkItems = new object[1]; pkItems[0] = (entity.ComposedRigaFatturaID ?? (int)0); RigaFattura tmpEntity = EntityManager.LocateEntity <RigaFattura>(EntityLocator.ConstructKeyFromPkItems(typeof(RigaFattura), pkItems), DataRepository.Provider.EnableEntityTracking); if (tmpEntity != null) { entity.ComposedRigaFatturaIDSource = tmpEntity; } else { entity.ComposedRigaFatturaIDSource = DataRepository.RigaFatturaProvider.GetByID(transactionManager, (entity.ComposedRigaFatturaID ?? (int)0)); } #if NETTIERS_DEBUG System.Diagnostics.Debug.WriteLine("- property 'ComposedRigaFatturaIDSource' loaded. key " + entity.EntityTrackingKey); #endif if (deep && entity.ComposedRigaFatturaIDSource != null) { innerList.SkipChildren = true; DataRepository.RigaFatturaProvider.DeepLoad(transactionManager, entity.ComposedRigaFatturaIDSource, deep, deepLoadType, childTypes, innerList); innerList.SkipChildren = false; } } #endregion ComposedRigaFatturaIDSource #region AggregatedRigaFatturaIDSource if (CanDeepLoad(entity, "RigaFattura|AggregatedRigaFatturaIDSource", deepLoadType, innerList) && entity.AggregatedRigaFatturaIDSource == null) { object[] pkItems = new object[1]; pkItems[0] = (entity.AggregatedRigaFatturaID ?? (int)0); RigaFattura tmpEntity = EntityManager.LocateEntity <RigaFattura>(EntityLocator.ConstructKeyFromPkItems(typeof(RigaFattura), pkItems), DataRepository.Provider.EnableEntityTracking); if (tmpEntity != null) { entity.AggregatedRigaFatturaIDSource = tmpEntity; } else { entity.AggregatedRigaFatturaIDSource = DataRepository.RigaFatturaProvider.GetByID(transactionManager, (entity.AggregatedRigaFatturaID ?? (int)0)); } #if NETTIERS_DEBUG System.Diagnostics.Debug.WriteLine("- property 'AggregatedRigaFatturaIDSource' loaded. key " + entity.EntityTrackingKey); #endif if (deep && entity.AggregatedRigaFatturaIDSource != null) { innerList.SkipChildren = true; DataRepository.RigaFatturaProvider.DeepLoad(transactionManager, entity.AggregatedRigaFatturaIDSource, deep, deepLoadType, childTypes, innerList); innerList.SkipChildren = false; } } #endregion AggregatedRigaFatturaIDSource #region AssociatedRigaFatturaIDSource if (CanDeepLoad(entity, "RigaFattura|AssociatedRigaFatturaIDSource", deepLoadType, innerList) && entity.AssociatedRigaFatturaIDSource == null) { object[] pkItems = new object[1]; pkItems[0] = (entity.AssociatedRigaFatturaID ?? (int)0); RigaFattura tmpEntity = EntityManager.LocateEntity <RigaFattura>(EntityLocator.ConstructKeyFromPkItems(typeof(RigaFattura), pkItems), DataRepository.Provider.EnableEntityTracking); if (tmpEntity != null) { entity.AssociatedRigaFatturaIDSource = tmpEntity; } else { entity.AssociatedRigaFatturaIDSource = DataRepository.RigaFatturaProvider.GetByID(transactionManager, (entity.AssociatedRigaFatturaID ?? (int)0)); } #if NETTIERS_DEBUG System.Diagnostics.Debug.WriteLine("- property 'AssociatedRigaFatturaIDSource' loaded. key " + entity.EntityTrackingKey); #endif if (deep && entity.AssociatedRigaFatturaIDSource != null) { innerList.SkipChildren = true; DataRepository.RigaFatturaProvider.DeepLoad(transactionManager, entity.AssociatedRigaFatturaIDSource, deep, deepLoadType, childTypes, innerList); innerList.SkipChildren = false; } } #endregion AssociatedRigaFatturaIDSource //used to hold DeepLoad method delegates and fire after all the local children have been loaded. Dictionary <string, KeyValuePair <Delegate, object> > deepHandles = new Dictionary <string, KeyValuePair <Delegate, object> >(); // Deep load child collections - Call GetByID methods when available #region RigaFattura // RelationshipType.OneToOne if (CanDeepLoad(entity, "RigaFattura|RigaFattura", deepLoadType, innerList)) { entity.RigaFattura = DataRepository.RigaFatturaProvider.GetByAssociatedFatturaID(transactionManager, entity.ID); #if NETTIERS_DEBUG System.Diagnostics.Debug.WriteLine("- property 'RigaFattura' loaded. key " + entity.EntityTrackingKey); #endif if (deep && entity.RigaFattura != null) { deepHandles.Add("RigaFattura", new KeyValuePair <Delegate, object>((DeepLoadSingleHandle <RigaFattura>)DataRepository.RigaFatturaProvider.DeepLoad, new object[] { transactionManager, entity.RigaFattura, deep, deepLoadType, childTypes, innerList } )); } } #endregion #region RigaFatturaCollectionGetByComposedFatturaID //Relationship Type One : Many if (CanDeepLoad(entity, "List<RigaFattura>|RigaFatturaCollectionGetByComposedFatturaID", deepLoadType, innerList)) { #if NETTIERS_DEBUG System.Diagnostics.Debug.WriteLine("- property 'RigaFatturaCollectionGetByComposedFatturaID' loaded. key " + entity.EntityTrackingKey); #endif entity.RigaFatturaCollectionGetByComposedFatturaID = DataRepository.RigaFatturaProvider.GetByComposedFatturaID(transactionManager, entity.ID); if (deep && entity.RigaFatturaCollectionGetByComposedFatturaID.Count > 0) { deepHandles.Add("RigaFatturaCollectionGetByComposedFatturaID", new KeyValuePair <Delegate, object>((DeepLoadHandle <RigaFattura>)DataRepository.RigaFatturaProvider.DeepLoad, new object[] { transactionManager, entity.RigaFatturaCollectionGetByComposedFatturaID, deep, deepLoadType, childTypes, innerList } )); } } #endregion #region RigaFatturaCollectionGetByAggregatedFatturaID //Relationship Type One : Many if (CanDeepLoad(entity, "List<RigaFattura>|RigaFatturaCollectionGetByAggregatedFatturaID", deepLoadType, innerList)) { #if NETTIERS_DEBUG System.Diagnostics.Debug.WriteLine("- property 'RigaFatturaCollectionGetByAggregatedFatturaID' loaded. key " + entity.EntityTrackingKey); #endif entity.RigaFatturaCollectionGetByAggregatedFatturaID = DataRepository.RigaFatturaProvider.GetByAggregatedFatturaID(transactionManager, entity.ID); if (deep && entity.RigaFatturaCollectionGetByAggregatedFatturaID.Count > 0) { deepHandles.Add("RigaFatturaCollectionGetByAggregatedFatturaID", new KeyValuePair <Delegate, object>((DeepLoadHandle <RigaFattura>)DataRepository.RigaFatturaProvider.DeepLoad, new object[] { transactionManager, entity.RigaFatturaCollectionGetByAggregatedFatturaID, deep, deepLoadType, childTypes, innerList } )); } } #endregion //Fire all DeepLoad Items foreach (KeyValuePair <Delegate, object> pair in deepHandles.Values) { pair.Key.DynamicInvoke((object[])pair.Value); } deepHandles = null; }