コード例 #1
0
        private void SaveWystTrasa()
        {
            string LastMessage;

            try
            {
                if (Kontrah != null && TrasaUpdate != null)
                {
                    IHP_WYSTTRASAKONTRAH wtk = new IHP_WYSTTRASAKONTRAH();
                    wtk.ID_IHP_WYSTTRASAKONTRAH = GetNextNumer(19);
                    wtk.ID_IHP_KONTRAHENT       = Kontrah.ID_IHP_KONTRAHENT;
                    wtk.ID_IHP_TRASY            = TrasaUpdate.ID_IHP_TRASY;
                    context.IHP_WYSTTRASAKONTRAH.Add(wtk);
                    context.SaveChanges();
                    LoadWystColection();
                    TrasaUpdate = null;
                }
            }
            catch (Exception ex)
            {
                LastMessage = ex.ToString();
                if (LastMessage == String.Empty)
                {
                    LastMessage = ex.InnerException.ToString();
                }
                LogManager.WriteLogMessage(LogManager.LogType.Error, LastMessage);
                throw ex;
            }
        }
コード例 #2
0
        private void Save()
        {
            string LastMessage;

            try
            {
                if (_nazwatrasy.Length < 3)
                {
                    return;
                }


                if (isupdate)
                {
                    _trasaupdate.NAZWA = _nazwatrasy;
                    context.IHP_TRASY.Attach(_trasaupdate);
                    context.Entry(_trasaupdate).State = EntityState.Modified;
                    context.SaveChanges();
                    LoadColection();
                    Clear();
                }
                else
                {
                    _trasa = new IHP_TRASY();

                    _trasa.ID_IHP_TRASY = GetNextNumer(18);
                    _trasa.NAZWA        = _nazwatrasy;
                    context.IHP_TRASY.Add(_trasa);
                    context.Entry(_trasa).State = EntityState.Added;
                    context.SaveChanges();
                    context.Entry(_trasa).Reload();
                    LoadColection();
                    Clear();
                }

                isupdate = false;
            }
            catch (Exception ex)
            {
                LastMessage = ex.ToString();
                if (LastMessage == String.Empty)
                {
                    LastMessage = ex.InnerException.ToString();
                }
                LogManager.WriteLogMessage(LogManager.LogType.Error, LastMessage);
                throw ex;
            }
        }
コード例 #3
0
        private void OnMessageTrasy(IHP_TRASY item)
        {
            //if (item != null)
            //{
            //    IHP_TRASY wk1 = new IHP_TRASY();


            //    wk1. = GetNextNumer(19);
            //    wk1.ID_CECHAKART = item.ID_CECHAKART;
            //    wk1.ID_KARTOTEKA = _kartoteka.ID_KARTOTEKA;
            //    wk1.WARTOSC = string.Empty;
            //    context.WYSTCECHKART.Add(wk1);
            //    context.Entry(wk1).State = EntityState.Added;
            //    context.NUMERACJA.Add(numernagl);
            //    context.Entry(numernagl).State = EntityState.Modified;
            //    context.SaveChanges();
            //}

            //LoadColectionTrasy();
        }
コード例 #4
0
 private void Clear()
 {
     _trasaupdate = null;
     NazwaTrasy   = string.Empty;
     isupdate     = false;
 }
コード例 #5
0
 public void OnMessageTrasy(IHP_TRASY Name)
 {
     TrasaUpdate = Name;
     SaveWystTrasa();
 }
コード例 #6
0
        private void DeleteWysTrasaKart()
        {
            string LastMessage;

            try
            {
                if (TrasaSelect != null)
                {
                    //    IHP_WYSTTRASAKART wtk = context.IHP_WYSTTRASAKART?.FirstOrDefault(x => x.ID_IHP_KONTRAHENT.Equals(TrasaSelect.ID_IHP_KONTRAHENT) &&  x.ID_IHP_TRASY.Equals(TrasaSelect.ID_IHP_TRASY));
                    //if(wtk!=null)
                    //    {
                    //       context.IHP_WYSTTRASAKART.Remove(wtk);
                    //       context.SaveChanges();
                    //        Clear();
                    //        LoadWystColection();
                    //        TrasaUpdate = null;
                    //    }
                    IHP_WYSTTRASAKONTRAH wtk = context.IHP_WYSTTRASAKONTRAH.Find(TrasaSelect.ID_IHP_WYSTTRASAKONTRAH);
                    context.Entry(wtk).State = EntityState.Deleted;
                    context.IHP_WYSTTRASAKONTRAH.Remove(wtk);
                    context.SaveChanges();
                    LoadWystColection();
                    TrasaUpdate = null;
                }
            }
            catch (DbUpdateException Ex)
            {
                LogManager.WriteLogMessage(LogManager.LogType.Error, String.Format("DbUpdateException \"{0}\"  :", Ex.InnerException.Message));
                throw Ex;
            }
            catch (SqlException exc)
            {
                //here you might still get some exceptions but not about validation.

                LogManager.WriteLogMessage(LogManager.LogType.Error, String.Format("SqlException \"{0}\"  :", exc.Message));


                //sometimes you may want to throw the exception to upper layers for handle it better over there!
                throw;
            }

            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    LogManager.WriteLogMessage(LogManager.LogType.Error, String.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        LogManager.WriteLogMessage(LogManager.LogType.Error, String.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage));
                    }
                }
                throw;
            }
            catch (Exception ex)
            {
                LastMessage = ex.ToString();
                if (LastMessage == String.Empty)
                {
                    LastMessage = ex.InnerException.ToString();
                }
                LogManager.WriteLogMessage(LogManager.LogType.Error, LastMessage);
                throw ex;
            }
        }