Пример #1
0
        /// create new PM data
        public static PDataLabelTable CreateNewPMData(long AFromPartnerKey, long AToPartnerKey, IndividualDataTDS AMainDS, TDataBase ADataBase = null)
        {
            TDataBase      db          = DBAccess.Connect("CreateNewPMData", ADataBase);
            TDBTransaction Transaction = db.BeginTransaction(IsolationLevel.ReadCommitted);

            // Create a new DataLabel record
            PDataLabelTable AllDataLabelTable = PDataLabelAccess.LoadAll(Transaction);
            PDataLabelTable DataLabelTable    = new PDataLabelTable();
            PDataLabelRow   DataLabelRow      = DataLabelTable.NewRowTyped();

            // Get the first available key, which is our unique primary key field
            Int32 Key = 1;

            while (AllDataLabelTable.Rows.Find(new object[] { Key }) != null)
            {
                Key++;
            }

            DataLabelRow.Key      = Key;
            DataLabelRow.DataType = "char";
            DataLabelTable.Rows.Add(DataLabelRow);

            // Create a new DataLabelValuePartner record
            PDataLabelValuePartnerRow DataLabelValuePartner = AMainDS.PDataLabelValuePartner.NewRowTyped();

            DataLabelValuePartner.PartnerKey   = AFromPartnerKey;
            DataLabelValuePartner.DataLabelKey = DataLabelRow.Key;
            AMainDS.PDataLabelValuePartner.Rows.Add(DataLabelValuePartner);

            // Create a new PassportDetails record
            IndividualDataTDSPmPassportDetailsRow PassportDetails = AMainDS.PmPassportDetails.NewRowTyped();

            PassportDetails.PartnerKey              = AFromPartnerKey;
            PassportDetails.PassportNumber          = "0";
            PassportDetails.PassportNationalityName = "IRELAND";
            AMainDS.PmPassportDetails.Rows.Add(PassportDetails);

            // Create two new PersonalData records
            PmPersonalDataRow FromPersonalData = AMainDS.PmPersonalData.NewRowTyped();

            FromPersonalData.PartnerKey = AFromPartnerKey;
            FromPersonalData.HeightCm   = 175;
            FromPersonalData.WeightKg   = 80;
            AMainDS.PmPersonalData.Rows.Add(FromPersonalData);

            PmPersonalDataRow ToPersonalData = AMainDS.PmPersonalData.NewRowTyped();

            ToPersonalData.PartnerKey = AToPartnerKey;
            ToPersonalData.WeightKg   = 95;
            AMainDS.PmPersonalData.Rows.Add(ToPersonalData);

            Transaction.Rollback();

            return(DataLabelTable);
        }
Пример #2
0
        public TSubmitChangesResult PrepareChangesServerSide(
            DataTable AInspectDT,
            TDBTransaction AReadTransaction)
        {
            TSubmitChangesResult SubmissionResult = TSubmitChangesResult.scrOK;

            // TODO: once we have centrally cached data tables on the server then get the data
            // from there. Until then just load it on the spot here!
            PDataLabelTable DataLabelDT = PDataLabelAccess.LoadAll(AReadTransaction);

            if (AInspectDT != null)
            {
                // Run through all rows of the value table and see if the significant column is empty/null. If so
                // then delete the row from the table (these rows are not needed any longer in order to save space
                // in the database)
                int NumRows = AInspectDT.Rows.Count;

                for (int RowIndex = NumRows - 1; RowIndex >= 0; RowIndex -= 1)
                {
                    DataRow InspectedDataRow = AInspectDT.Rows[RowIndex];

                    // only check modified or added rows because the deleted ones are deleted anyway
                    if ((InspectedDataRow.RowState == DataRowState.Modified) || (InspectedDataRow.RowState == DataRowState.Added))
                    {
                        if (IsRowObsolete(DataLabelDT, InspectedDataRow, (AInspectDT.TableName == PDataLabelValuePartnerTable.GetTableName())))
                        {
                            InspectedDataRow.Delete();
                        }
                    }
                }
            }
            else
            {
                TLogging.LogAtLevel(8, "AInspectDS = null!");
                SubmissionResult = TSubmitChangesResult.scrNothingToBeSaved;
            }

            return(SubmissionResult);
        }