Exemplo n.º 1
0
        public static TL_BASEDATA Add(SpareEntities db, string dataType, string oldValue, string newValue, string operName, OperateType operateType)
        {
            var log = new TL_BASEDATA
            {
                OperName = operName,
                LogTime  = DateTime.Now,
                LogType  = operateType.ToString(),
                DataType = dataType,
                OldValue = oldValue,
                NewValue = newValue,
            };

            db.TL_BASEDATA.Add(log);
            return(log);
        }
Exemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bs.EndEdit();
            var         detailList = (List <TA_CONFIG>)bs.DataSource;
            TL_BASEDATA log        = null;

            foreach (TA_CONFIG storeWhse in _db.TA_CONFIG)
            {
                if (detailList.All(p => p.ParamName != storeWhse.ParamName))
                {
                    _db.TA_CONFIG.Remove(storeWhse);
                }

                OperateType logType;
                string      oldValue, newValue;
                DbEntityEntry <TA_CONFIG> entry;

                try
                {
                    entry = _db.Entry(storeWhse);
                }
                catch (Exception ex)
                {
                    MessageHelper.ShowInfo(ex.ToString());
                    _db           = EntitiesFactory.CreateSpareInstance();
                    bs.DataSource = _db.TA_CONFIG.ToList();
                    return;
                }
                var dataType = entry.Entity.GetType().Name;
                switch (entry.State)
                {
                case EntityState.Detached:
                case EntityState.Unchanged:
                case EntityState.Added:
                    continue;

                case EntityState.Deleted:
                    logType  = OperateType.Delete;
                    oldValue = GetValues(entry.OriginalValues);
                    newValue = "";
//                        _db.TA_CONFIG.Remove(storeWhse);
                    break;

                case EntityState.Modified:
                    logType  = OperateType.Update;
                    oldValue = GetValues(entry.OriginalValues);
                    newValue = GetValues(entry.CurrentValues);
//                        _db.TA_CONFIG.Attach(storeWhse);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                log = BaseDataLogController.Add(_db, dataType, oldValue, newValue, "", logType);
            }
            foreach (var detail in detailList.Where(detail => !_db.TA_CONFIG.Any(p => p.ParamName == detail.ParamName)))
            {
                _db.TA_CONFIG.Add(detail);
                var entry    = _db.Entry(detail);
                var dataType = entry.Entity.GetType().Name;
                var logType  = OperateType.Add;
                var oldValue = "";
                var newValue = GetValues(entry.CurrentValues);
                log = BaseDataLogController.Add(_db, dataType, oldValue, newValue, "", logType);
            }
            try
            {
                EntitiesFactory.SaveDb(_db);
                grid.PrimaryGrid.PurgeDeletedRows();
                grid.PrimaryGrid.ClearDirtyRowMarkers();
                MessageHelper.ShowInfo("保存成功!");
            }
            catch (Exception ex)
            {
                MessageHelper.ShowInfo(ex.ToString());
                if (log != null)
                {
                    BaseDataLogController.RemoveLocal(_db, log);
                }
            }
        }
Exemplo n.º 3
0
 public static void RemoveLocal(SpareEntities db, TL_BASEDATA log)
 {
     db.TL_BASEDATA.Local.Remove(log);
 }