Exemple #1
0
        private void setDisableAV(System.Data.Objects.ObjectContext dc, bool value, bool save)
        {
            using (var t = new TransactionScope())
            {
                bool changed = false;
                if (this.AtrybutTowaru != null)
                {
                    if (this.AtrybutTowaru.DisableAVList != value)
                    {
                        this.AtrybutTowaru.DisableAVList = value;
                        changed = true;
                    }
                    if (!value && this.Towar.DisableAVList)
                    {
                        this.Towar.DisableAVList = false;
                        changed = true;
                    }
                }
                else if (this.Towar.DisableAVList != value)
                {
                    this.Towar.DisableAVList = value;
                    changed = true;
                }

                if (changed && save)
                {
                    dc.SaveChanges();
                    dc.Refresh(System.Data.Objects.RefreshMode.StoreWins, this);
                }
                t.Complete();
            }
        }
Exemple #2
0
 /// <summary>
 /// Releases all resources used by the WarrantManagement.DataExtract.Dal.ReportDataBase
 /// </summary>
 /// <param name="disposing">A boolean value indicating whether or not to dispose managed resources</param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_context != null)
         {
             _context.Dispose();
             _context = null;
         }
     }
 }
Exemple #3
0
        public bool SaveChanges(System.Data.Objects.ObjectContext dataContext)
        {
            using (var t = new System.Transactions.TransactionScope())
            {
                dataContext.SaveChanges();
                dataContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, this);
                t.Complete();
            }

            return(true);
        }
Exemple #4
0
 private void setVisibleAV(System.Data.Objects.ObjectContext dc, bool value, bool save)
 {
     try
     {
         dc.ExecuteStoreCommand("EXEC dbo.SetZasobyDoSprawdzenia {0},{1},{2}", this.TowarID, this.AtrybutTowaruID, value);
         dc.Refresh(RefreshMode.StoreWins, this);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #5
0
 private void setBlokada(System.Data.Objects.ObjectContext dc, bool value)
 {
     try
     {
         if (dc != null)
         {
             dc.ExecuteStoreCommand("EXEC dbo.SetZasobyBlokada {0},{1},{2}", this.TowarID, this.AtrybutTowaruID, value);
             dc.Refresh(RefreshMode.StoreWins, this);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #6
0
        public bool SaveChanges(System.Data.Objects.ObjectContext dataContext)
        {
            var dc = (EnovaContext)dataContext;

            if (this.EntityState == EntityState.Detached || this.EntityState == EntityState.Added)
            {
                if (this.EntityState == EntityState.Detached)
                {
                    dc.AddToFeatureDefs(this);
                }

                Operator op = null;
                if (!string.IsNullOrEmpty(Enova.Business.Old.DB.Web.User.LoginedUser.EnovaOperatorLogin))
                {
                    op = dc.OperatorByName(Enova.Business.Old.DB.Web.User.LoginedUser.EnovaOperatorLogin);
                }
                else
                {
                    op = dc.OperatorByName(Enova.Business.Old.DB.Web.User.LoginedUser.Login);
                }

                if (op != null)
                {
                    ChangeInfo ci = new ChangeInfo()
                    {
                        Operator    = op,
                        SourceGuid  = this.Guid,
                        SourceTable = "FeatureDefs",
                        Type        = 1,
                        Time        = DateTime.Now,
                        Info        = string.Empty
                    };

                    dc.AddToChangeInfos(ci);
                }
            }

            dc.SaveChanges();

            return(true);
        }
Exemple #7
0
        public bool SaveChanges(System.Data.Objects.ObjectContext dataContext)
        {
            var dc = (Enova.Business.Old.DB.EnovaContext)dataContext;

            if (this.EntityState == EntityState.Detached)
            {
                if (Enova.Business.Old.DB.Web.User.LoginedUser.CheckPerissions(true, null))
                {
                    Operator op = null;
                    if (!string.IsNullOrEmpty(Enova.Business.Old.DB.Web.User.LoginedUser.EnovaOperatorLogin))
                    {
                        op = dc.OperatorByName(Enova.Business.Old.DB.Web.User.LoginedUser.EnovaOperatorLogin);
                    }
                    else
                    {
                        op = dc.OperatorByName(Enova.Business.Old.DB.Web.User.LoginedUser.EnovaOperatorLogin);
                    }

                    dc.AddToKontrahenci(this);
                    //dc.SaveChanges();
                    dc.OptimisticSaveChanges();
                    this.Adres.Host = this.ID;
                    this.AdresKorespondencyjny.Host = this.ID;
                    dc.AddToAdresy(this.Adres);
                    dc.AddToAdresy(this.AdresKorespondencyjny);
                    if (this.przedstawiciel != null && this.przedstawiciel.EntityState == EntityState.Detached)
                    {
                        this.przedstawiciel.Parent = this.ID;
                        dc.AddToFeatures(this.przedstawiciel);
                    }

                    //dc.SaveChanges();
                    dc.OptimisticSaveChanges();

                    if (op != null)
                    {
                        ChangeInfo ci = new ChangeInfo()
                        {
                            Operator    = op,
                            SourceTable = "Kontrahenci",
                            SourceGuid  = this.Guid,
                            Type        = (int)Enova.Business.Old.Types.ChangeInfoType.Created,
                            Time        = DateTime.Now,
                            Info        = string.Empty,
                            WebUser     = null,
                            Data        = null
                        };

                        dc.AddToChangeInfos(ci);
                    }

                    foreach (var k in KontaktyOsoby)
                    {
                        k.Kontrahent = this;
                        //                           if (k.EntityState == EntityState.Detached)
                        //                               ContextManager.DataContext.AddToKontaktyOsoby(k);
                    }

                    //dc.SaveChanges();
                    dc.OptimisticSaveChanges();
                }
            }
            else
            {
                if (Adres.EntityState == EntityState.Detached)
                {
                    ContextManager.DataContext.AddToAdresy(this.Adres);
                }

                if (AdresKorespondencyjny.EntityState == EntityState.Detached)
                {
                    ContextManager.DataContext.AddToAdresy(AdresKorespondencyjny);
                }

                if (windykacjaChanged)
                {
                    string str = CreateWindykacjaStr();

                    Feature feature = Features.Where(f => f.Name == "WINDYKACJA").FirstOrDefault();
                    if (feature == null)
                    {
                        if (!string.IsNullOrEmpty(str))
                        {
                            feature = new Feature()
                            {
                                ParentType = "Kontrahenci",
                                Parent     = ID,
                                Name       = "WINDYKACJA",
                                Lp         = 0,
                                DataKey    = str.Length <= 30 ? str : str.Substring(0, 30),
                                Data       = str
                            };
                            dc.AddToFeatures(feature);
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(str))
                        {
                            feature.DataKey = str.Length <= 30 ? str : str.Substring(0, 30);
                            feature.Data    = str;
                        }
                        else
                        {
                            dc.DeleteObject(feature);
                        }
                    }
                }
                if (ZakończenieWindykacjiChanged)
                {
                    Feature feature = Features.Where(f => f.Name == "ZAKONCZENIE_WINDYKACJI").FirstOrDefault();
                    if (feature == null)
                    {
                        if (!string.IsNullOrEmpty(zakończenieWindykacji))
                        {
                            feature = new Feature()
                            {
                                ParentType = "Kontrahenci",
                                Parent     = ID,
                                Name       = "ZAKONCZENIE_WINDYKACJI",
                                Lp         = 0,
                                DataKey    = zakończenieWindykacji.Length <= 30 ? zakończenieWindykacji : zakończenieWindykacji.Substring(0, 30),
                                Data       = zakończenieWindykacji
                            };
                            dc.AddToFeatures(feature);
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(zakończenieWindykacji))
                        {
                            feature.DataKey = zakończenieWindykacji.Length <= 30 ? zakończenieWindykacji : zakończenieWindykacji.Substring(0, 30);
                            feature.Data    = zakończenieWindykacji;
                        }
                        else
                        {
                            dc.DeleteObject(feature);
                        }
                    }
                }


                //dc.SaveChanges();
                dc.OptimisticSaveChanges();

                foreach (var k in KontaktyOsoby)
                {
                    k.Kontrahent = this;
                    //if (k.EntityState == EntityState.Detached)
                    //  ContextManager.DataContext.AddToKontaktyOsoby(k);
                }

                //dc.SaveChanges();
                dc.OptimisticSaveChanges();
            }

            return(true);
        }
 public ObjectContext(System.Data.Objects.ObjectContext objectContext)
 {
     EFContext = objectContext;
 }
Exemple #9
0
 /// <summary>
 /// Initializes a new instance of the GenericRepository class
 /// </summary>
 /// <param name="context">The Entity Framework ObjectContext</param>
 public GenericRepository(System.Data.Objects.ObjectContext context)
 {
     _context   = context;
     _objectSet = _context.CreateObjectSet <T>();
 }
Exemple #10
0
        private static void SaveMyChanges(System.Data.Objects.ObjectContext context)
        {
            if (_persistedEntriesList == null)
            {
                _persistedEntriesList = new List <PersistedStateEntry>();
            }
            try
            {
                context.SaveChanges();
            }
            catch (OptimisticConcurrencyException ex)
            {
                var stateentries = ex.StateEntries;
                ObjectStateEntry conflictEntry = ex.StateEntries[0];
                string           errorMessage  = null;
                if (ex.InnerException != null)
                {
                    errorMessage = ex.Message + System.Environment.NewLine + ex.InnerException.Message;
                }
                else
                {
                    errorMessage = ex.Message;
                }
                if (!conflictEntry.IsRelationship)
                {
                    //persist the entityentry
                    var pEntry = new PersistedStateEntry(conflictEntry.EntityKey, conflictEntry.CurrentValues.DataRecordInfo, (IExtendedDataRecord)conflictEntry.OriginalValues, conflictEntry.Entity, ex.Message);
                    //don't forget relatoinships, need to do this before detaching entity
                    if (ex.StateEntries.Count > 1)
                    {
                        for (var i = 1; i < ex.StateEntries.Count; i++)
                        {
                            //ignore Unchanged relatoinship entries
                            if (ex.StateEntries[i].State != EntityState.Unchanged)
                            {
                                pEntry.AddRelationships(ex.StateEntries[i]);
                            }
                        }
                    }

                    context.Detach(conflictEntry.Entity);
                    _persistedEntriesList.Add(pEntry);


                    //If TypeOf conflictEntry.Entity Is Contact Then
                    //  ContactRefresh(conflictEntry, context)
                    //ElseIf TypeOf conflictEntry.Entity Is Payment Then
                    //  PaymentRefresh(conflictEntry, context)
                    //Else
                    //  context.Refresh(RefreshMode.ClientWins, conflictEntry)
                    //End If


                    //Dim detailstring = conflictEntry.EntryDetails(context)

                    //  context.Refresh(RefreshMode.ClientWins, conflictEntry.Entity)
                }
                //handle concurrency exception here
                //then try again
                SaveMyChanges(context);
            }
            catch (System.Data.EntityCommandCompilationException ex)
            {
            }
            catch (System.Data.EntityCommandExecutionException ex)
            {
            }
            catch (System.Data.EntitySqlException ex)
            {
            }
            catch (Exception ex)
            {
                //handle other exceptions
            }
        }
Exemple #11
0
 private void setAktywny(System.Data.Objects.ObjectContext dc, bool value, bool save)
 {
     setBlokada(dc, !value);
 }