Example #1
0
        /// <summary>
        /// This function saves the changes from the table record models to the database
        ///
        /// These changes need to be made persistent by calling TDB.Save(). usually you don't
        /// call this function directly. Instead call EditorModel.Save() which will
        /// do it all for you.
        /// </summary>
        public void Save()
        {
            List <TableRecordModel> listToUse = null;

            for (int j = 0; j < 2; j++)
            {
                if (j == 0)
                {
                    listToUse = recordList;
                }
                else
                {
                    listToUse = deletedRecordList;
                }
                foreach (TableRecordModel record in listToUse)
                {
                    if (record.Dirty)
                    {
                        // Need to reverse tablename to find the correct table since we reversed them to begin with
                        // when first reading them in to make them compatible with the editor.
                        if (BigEndian)
                        {
                            tablename = ConvertBE(Name);
                        }
                        else
                        {
                            tablename = Name;
                        }

                        //First check to see if this record is going to be deleted
                        if (record.Deleted)
                        {
                            Trace.Write("About to mark for deletion record " + record.RecNo);
                            // Mark record for deletion in DB
                            // s68 - not sure why 'record remove was commented out and changed to 'change deleted' , that doesnt remove the record
                            // will leave it here in case there was some kind of problem with using record remove.
                            // TDB.TDBTableRecordChangeDeleted(dbIndex, tablename, record.RecNo, false);

                            TDB.TDBTableRecordRemove(dbIndex, tablename, record.RecNo);
                            continue;
                        }

                        string[] keyArray         = null;
                        int[]    valueArray       = null;
                        float[]  floatArray       = null;
                        string[] stringValueArray = null;

                        #region Int Fields
                        record.GetChangedIntFields(ref keyArray, ref valueArray);

                        for (int i = 0; i < keyArray.Length; i++)
                        {
                            TDB.TDBFieldSetValueAsInteger(dbIndex, tablename, keyArray[i], record.RecNo, valueArray[i]);
                        }
                        #endregion

                        #region String Fields
                        keyArray = null;
                        record.GetChangedStringFields(ref keyArray, ref stringValueArray);

                        for (int i = 0; i < keyArray.Length; i++)
                        {
                            TDB.TDBFieldSetValueAsString(dbIndex, tablename, keyArray[i], record.RecNo, stringValueArray[i]);
                        }
                        #endregion

                        #region Float Fields
                        keyArray = null;
                        record.GetChangedFloatFields(ref keyArray, ref floatArray);
                        for (int i = 0; i < keyArray.Length; i++)
                        {
                            TDB.TDBFieldSetValueAsFloat(dbIndex, tablename, keyArray[i], record.RecNo, floatArray[i]);
                        }
                        #endregion

                        record.DiscardBackups();
                    }
                }
            }

            //TDB.TDBDatabaseCompact(dbIndex);
            //TDB.TDBSave(dbIndex);
        }
Example #2
0
        /// <summary>
        /// This function saves the changes from the table record models to the database
        ///
        /// These changes need to be made persistent by calling TDB.Save(). usually you don't
        /// call this function directly. Instead call EditorModel.Save() which will
        /// do it all for you.
        /// </summary>
        public void Save()
        {
            List <TableRecordModel> listToUse = null;

            for (int j = 0; j < 2; j++)
            {
                if (j == 0)
                {
                    listToUse = recordList;
                }
                else
                {
                    listToUse = deletedRecordList;
                }
                foreach (TableRecordModel record in listToUse)
                {
                    if (record.Dirty)
                    {
                        //First check to see if this record is going to be deleted
                        if (record.Deleted)
                        {
                            Trace.Write("About to mark for deletion record " + record.RecNo);
                            //Mark record for deletion in DB

                            TDB.TDBTableRecordChangeDeleted(dbIndex, name, record.RecNo, false);
                            //TDB.TDBTableRecordRemove(dbIndex, name, record.RecNo);
                            continue;
                        }

                        string[] keyArray         = null;
                        int[]    valueArray       = null;
                        float[]  floatArray       = null;
                        string[] stringValueArray = null;

                        record.GetChangedIntFields(ref keyArray, ref valueArray);

                        for (int i = 0; i < keyArray.Length; i++)
                        {
                            TDB.TDBFieldSetValueAsInteger(dbIndex, name, keyArray[i], record.RecNo, valueArray[i]);
                        }

                        keyArray = null;
                        record.GetChangedStringFields(ref keyArray, ref stringValueArray);

                        for (int i = 0; i < keyArray.Length; i++)
                        {
                            TDB.TDBFieldSetValueAsString(dbIndex, name, keyArray[i], record.RecNo, stringValueArray[i]);
                        }

                        keyArray = null;
                        record.GetChangedFloatFields(ref keyArray, ref floatArray);
                        for (int i = 0; i < keyArray.Length; i++)
                        {
                            TDB.TDBFieldSetValueAsFloat(dbIndex, name, keyArray[i], record.RecNo, floatArray[i]);
                        }

                        record.DiscardBackups();
                    }
                }
            }

            //TDB.TDBDatabaseCompact(dbIndex);
            //TDB.TDBSave(dbIndex);
        }