Example #1
0
        public int RemoveArchive()
        {
            if (this.ID < 1)
                return 0;

            int ctr = 0;
            if (mArchivedRecord != null && mArchivedRecord.Data != null) {
                //the trick here is to write the record out	- i guesst this could be moved inline
                //with the regular update logic so we could update an archoved record
                bool SaveHasIdent = mHasIdentity;
                ArchivedData da = mArchivedRecord;
                try {
                    mArchivedRecord = null;
                    mHasIdentity = false;
                    //this is a very nasty hack - cause the write stmt will be messed up a bit
                    mSqlUtil.ExecuteNoResultSetSQLQuery("set IDENTITY_INSERT " + mTableName + " on");
                    this.CreateRecord(true);
                    mSqlUtil.ExecuteNoResultSetSQLQuery("set IDENTITY_INSERT " + mTableName + " off");
                    da.mArchiveControl.ArchiveMethod.Delete(this.ID);
                    ctr++;
                } finally {
                    mHasIdentity = SaveHasIdent;

                }
            }

            if (mArchivedColumn != null && mArchivedColumn.Data != null) {
                //an update deletes the archive - but we need to force the update by assigning
                //one value to itself to the changecount > 0
                Dictionary<string, GenericField>.Enumerator e = mTableDef.GetEnumerator();
                e.MoveNext();
                string FirstField = (string)e.Current.Key;

                object o = this.GetFieldValue(FirstField);
                if (o.ToString() == "g")
                    this.SetFieldValue(FirstField, "a");
                else
                    this.SetFieldValue(FirstField, "g");

                //set it back to it orig value
                this.SetFieldValue(FirstField, o);
                this.UpdateRecord();
                ctr++;
            }

            return ctr;
        }
Example #2
0
        /// <summary>
        /// Shortcut to load data into gt from another database source, such as a select statement.
        /// Rows specified as encrypted in the table definition will be decrypted
        /// </summary>
        /// <param name="r">A row of data from a database</param>
        public void Load(DataRow r, bool UseArchive)
        {
            mDataRow = r;
            mID = DataUtils.LongZeroIfNull(r[mIdColumn]);
            mNewRecord = false;

            //get archived columns and merge in to data row
            if (UseArchive) {
                mArchivedColumn = ArchivedData.ReadColumns(mFullTablePath, this);
                if (mArchivedColumn != null) {
                    foreach (KeyValuePair<string, object> kvp in mArchivedColumn.Data) {
                        r[kvp.Key] = kvp.Value;
                    }
                }
            } else
                mArchivedColumn = null;

            foreach (KeyValuePair<string, GenericField> kvp in mTableDef) {
                string fname = kvp.Key;
                GenericField gf = kvp.Value;
                if (!r.Table.Columns.Contains(fname) && this.IgnoreMissingFields) {
                    mData[fname] = DBNull.Value;
                } else if (gf.mEncrypted == true && r[fname] != DBNull.Value) {
                    this.DecryptCol(r[fname], gf, fname);
                } else {
                    mData[fname] = r[fname];
                }
            }

            this.mChangeList.Clear();
            mLoadTime = DateTimeUtility.ServerDate();
        }
Example #3
0
        public virtual int ReadRecord(long id)
        {
            mChangeList.Clear();
            SqlParameterCollection oParams = (new SqlCommand()).Parameters;
            oParams.AddWithValue("@ID", id);

            string LockHint = mUseRowLock ? " with (UPDLOCK)" : "";
            string ReadStmt = string.Format("select * from {0}{1} where [{2}]=@ID", mTableName, LockHint, mIdColumn);

            DataRow r;
            //we could of checked the archive before the read - however we want the output of
            //of the archived read to be a data row and there was no good way to serialize a
            //data row.  So we do the read up front and if there is no data retunred we can
            //build the data row from the Hash.  We need the  DataTable with no rows in order to
            //insure all the DB info is correct (like column defs)
            //another advatage to reading first is record archive IDs need not be contigious now
            DataTable oTable = mSqlUtil.ExecuteSingleResultSetSQLQuery(ReadStmt, oParams);
            if (oTable.Rows.Count == 0) {
                mArchivedRecord = ArchivedData.ReadRecord(mFullTablePath, id);
                if (mArchivedRecord != null) {
                    r = oTable.NewRow();

                    Dictionary<string, object> h = mArchivedRecord.Data;
                    object v;
                    foreach (DataColumn c in oTable.Columns) {
                        v = h[c.ColumnName];
                        if (v == null)
                            v = System.DBNull.Value;

                        r[c.ColumnName] = v;
                    }

                    r[this.IDColumnName] = id;
                    oTable.Rows.Add(r);
                } else {
                    mID = id;
                    return 0;
                }
            } else {
                r = oTable.Rows[0];
            }

            if (mData == null)
                mData = new Dictionary<string, object>(mTableDef.Count + 3);

            Load(r, true);

            return 1;
        }
Example #4
0
        public virtual void DeleteRecord()
        {
            if (mID < 0) {
                Exception x = new Exception("must set ID");
                throw x;
            }

            if (mDeleteStmt == null)
                mDeleteStmt = "delete from " + mTableName + " where [" + mIdColumn + "]= @ID";

            SqlParameterCollection oParams = (new SqlCommand()).Parameters;
            oParams.AddWithValue("@ID", mID);

            mSqlUtil.ExecuteNoResultSetSQLQuery(mDeleteStmt, oParams);

            //remove from archve also
            if (mArchivedColumn != null)
                mArchivedColumn.Delete();

            if (mArchivedRecord != null)
                mArchivedRecord.Delete();

            mArchivedRecord = null;
            mArchivedColumn = null;
            mNewRecord = true;

            if (AutomaticAuditHistory) {
                AuditFields af = new AuditFields();
                af.Add("delete", null, null);
                CreateAudit(-3, af);
            }
        }
Example #5
0
 public void Clear()
 {
     mID = 0;
     mChangeList.Clear();
     mData.Clear();
     mNewRecord = true;
     mDataRow = null;
     mArchivedRecord = null;
     mArchivedColumn = null;
 }
Example #6
0
        public static ArchivedData ReadColumns(string TablePath, GenericTable rec)
        {
            //to avoid infinite loop - we alway return null for request for the archiove tables themselevs
            TablePath = TablePath.ToLower();
            if (TablePath.IndexOf("archivecon") > 0)
                return null;

            ArchiveConfig cfg = ArchiveConfig.Get(TablePath);
            if (cfg == null)
                return null;

            string Column = cfg.AgeDeterminingColumn;
            if (Column == null)
                return null;

            ArchiveControl a = ArchiveControl.Get(TablePath, (DateTime)rec.DataRow[Column]);
            if (a == null)
                return null;

            ArchivedData ad = new ArchivedData(a, rec.ID);
            if (ad.mData == null)
                return null;

            return ad;
        }
Example #7
0
        /// <summary>
        /// a methid that lets you get at archive comlumn info without a date.  It just checks 
        /// all column archives for this table path
        /// </summary>
        /// <param name="TablePath"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static ArchivedData ScanAllColumnArchives(string TablePath, long id)
        {
            //to avoid infinite loop - we alway return null for request for the archiove tables themselevs
            TablePath = TablePath.ToLower();
            if (TablePath.IndexOf("archivecon") > 0)
                return null;

            ArchiveConfig cfg = ArchiveConfig.Get(TablePath);
            if (cfg == null)
                return null;

            ArchiveControlList l = ArchiveControl.GetControlList(TablePath);
            foreach (ArchiveControl ac in l.mArchiveList) {
                if (ac.ArchiveType != ArchiveControl.ArchiveTypeEnum.Column)
                    continue;

                ArchivedData ad = new ArchivedData(ac, id);
                if (ad.mData != null)
                    return ad;
            }

            return null;
        }
Example #8
0
        public static ArchivedData ReadRecord(string TablePath, long ID)
        {
            //to avoid infinite loop - we alway return null for request for the archiove tables themselevs
            TablePath = TablePath.ToLower();
            if (TablePath.IndexOf("archivecontrol") > 0)
                return null;

            ArchiveControl a = ArchiveControl.Get(TablePath, ID);
            if (a == null)
                return null;

            ArchivedData ad = new ArchivedData(a, ID);
            if (ad.mData == null)
                return null;

            return ad;
        }