Beispiel #1
0
        /// <remarks>
        /// For NUnit tests that just try to open the Conference Find screen but which don't instantiate a Main Form
        /// we need to work around the fact that there is no Main Window!
        /// </remarks>
        private void InitGridManually()
        {
            MethodInfo Method = null;

            LoadDataGrid(true);

            grdConferences.DoubleClickCell += new TDoubleClickCellEventHandler(grdConferences_DoubleClickCell);

            // Attempt to obtain conference key from parent form or parent's parent form and use this to focus the currently selected
            // conference in the grid. If no conference key is found then the first conference in the grid will be focused.
            Form MainWindow = FPetraUtilsObject.GetCallerForm();

            // Main Window will not be available if run from within NUnit Test without Main Form instance...
            if (MainWindow != null)
            {
                Method = MainWindow.GetType().GetMethod("GetSelectedConferenceKey");
            }

            if (Method == null)
            {
                // Main Window will not be available if run from within NUnit Test without Main Form instance...
                if (MainWindow != null)
                {
                    Method = MainWindow.GetType().GetMethod("GetPetraUtilsObject");
                }

                if (Method != null)
                {
                    TFrmPetraUtils ParentPetraUtilsObject = (TFrmPetraUtils)Method.Invoke(MainWindow, null);
                    MainWindow = ParentPetraUtilsObject.GetCallerForm();
                    Method     = MainWindow.GetType().GetMethod("GetSelectedConferenceKey");
                }
            }

            if (Method != null)
            {
                FSelectedConferenceKey = Convert.ToInt64(Method.Invoke(MainWindow, null));
                int RowPos = 1;

                foreach (DataRowView rowView in FMainDS.PcConference.DefaultView)
                {
                    PcConferenceRow Row = (PcConferenceRow)rowView.Row;

                    if (Row.ConferenceKey == FSelectedConferenceKey)
                    {
                        break;
                    }

                    RowPos++;
                }

                // automatically select the current conference
                grdConferences.SelectRowInGrid(RowPos, true);
            }
        }
        private void ValidateDataManual(PcConferenceRow ARow)
        {
            PcDiscountTable DiscountTable = FMainDS.PcDiscount;

            TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection;
            TValidationControlsData       ValidationControlsData;
            TScreenVerificationResult     VerificationResult = null;
            DataColumn ValidationColumn;

            List <string> CriteriaCodesUsed = new List <string>();

            foreach (PcDiscountRow Row in DiscountTable.Rows)
            {
                if ((Row.RowState != DataRowState.Deleted) && (Row.DiscountCriteriaCode != "CHILD"))
                {
                    if (Row.Discount > 100)
                    {
                        ValidationColumn = Row.Table.Columns[PcDiscountTable.ColumnDiscountId];

                        // displays a warning message
                        VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(
                                                                                                       PetraErrorCodes.ERR_DISCOUNT_PERCENTAGE_GREATER_THAN_100)),
                                                                           ValidationColumn, ValidationControlsData.ValidationControl);

                        // Handle addition to/removal from TVerificationResultCollection
                        VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn);
                    }

                    if (!CriteriaCodesUsed.Exists(element => element == Row.DiscountCriteriaCode))
                    {
                        CriteriaCodesUsed.Add(Row.DiscountCriteriaCode);
                    }
                }
            }

            string[] CriteriaCodesUsedArray = CriteriaCodesUsed.ToArray();

            if (!TRemote.MConference.Conference.WebConnectors.CheckDiscountCriteriaCodeExists(CriteriaCodesUsedArray))
            {
                ValidationColumn = DiscountTable.Columns[PcDiscountTable.ColumnDiscountCriteriaCodeId];

                // displays a warning message
                VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(
                                                                                               PetraErrorCodes.ERR_DISCOUNT_CRITERIA_CODE_DOES_NOT_EXIST)),
                                                                   ValidationColumn, ValidationControlsData.ValidationControl);

                // Handle addition to/removal from TVerificationResultCollection
                VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn);
            }
        }
        public static void CreateNewConference(long APartnerKey)
        {
            TDBTransaction        Transaction;
            PcConferenceTable     ConferenceTable;
            PUnitTable            UnitTable;
            PPartnerLocationTable PartnerLocationTable;

            Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable);

            try
            {
                ConferenceTable      = PcConferenceAccess.LoadAll(Transaction);
                UnitTable            = PUnitAccess.LoadByPrimaryKey(APartnerKey, Transaction);
                PartnerLocationTable = PPartnerLocationAccess.LoadViaPPartner(APartnerKey, Transaction);

                DateTime Start = new DateTime();
                DateTime End   = new DateTime();

                foreach (PPartnerLocationRow PartnerLocationRow in PartnerLocationTable.Rows)
                {
                    if ((PartnerLocationRow.DateEffective != null) || (PartnerLocationRow.DateGoodUntil != null))
                    {
                        if (PartnerLocationRow.DateEffective != null)
                        {
                            Start = (DateTime)PartnerLocationRow.DateEffective;
                        }

                        if (PartnerLocationRow.DateGoodUntil != null)
                        {
                            End = (DateTime)PartnerLocationRow.DateGoodUntil;
                        }

                        break;
                    }
                }

                // set column values
                PcConferenceRow AddRow = ConferenceTable.NewRowTyped();
                AddRow.ConferenceKey = APartnerKey;

                string OutreachPrefix = ((PUnitRow)UnitTable.Rows[0]).OutreachCode;

                if (OutreachPrefix.Length > 4)
                {
                    AddRow.OutreachPrefix = OutreachPrefix.Substring(0, 5);
                }
                else
                {
                    AddRow.OutreachPrefix = OutreachPrefix;
                }

                if (Start != DateTime.MinValue)
                {
                    AddRow.Start = Start;
                }

                if (End != DateTime.MinValue)
                {
                    AddRow.End = End;
                }

                string CurrencyCode = ((PUnitRow)UnitTable.Rows[0]).OutreachCostCurrencyCode;

                if (!string.IsNullOrEmpty(CurrencyCode))
                {
                    AddRow.CurrencyCode = CurrencyCode;
                }
                else
                {
                    AddRow.CurrencyCode = "USD";
                }

                // add new row to database table
                ConferenceTable.Rows.Add(AddRow);
                PcConferenceAccess.SubmitChanges(ConferenceTable, Transaction);

                DBAccess.GDBAccessObj.CommitTransaction();
                TLogging.LogAtLevel(7, "TConferenceDataReaderWebConnector.CreateNewConference: commit own transaction.");
            }
            catch (Exception Exc)
            {
                TLogging.Log("An Exception occured during the creation of a new Conference:" + Environment.NewLine + Exc.ToString());

                DBAccess.GDBAccessObj.RollbackTransaction();

                throw;
            }
        }
        // get data from screen and ammend/add to dataset
        private void GetDataFromControlsManual(PcConferenceRow ARow)
        {
            PcConferenceRow     ConferenceData      = (PcConferenceRow)FMainDS.PcConference.Rows[0];
            PPartnerLocationRow PartnerLocationData = (PPartnerLocationRow)FMainDS.PPartnerLocation.Rows[0];
            PUnitRow            UnitData            = (PUnitRow)FMainDS.PUnit.Rows[0];

            // do not save currency if it is blank but instead change the combo box to display original value
            if (cmbCurrency.GetSelectedString() != "")
            {
                ConferenceData.CurrencyCode       = cmbCurrency.GetSelectedString();
                UnitData.OutreachCostCurrencyCode = cmbCurrency.GetSelectedString();
            }
            else
            {
                cmbCurrency.SetSelectedString(ConferenceData.CurrencyCode);
            }

            ConferenceData.Start = dtpStartDate.Date;
            ConferenceData.End   = dtpEndDate.Date;
            PartnerLocationData.DateEffective = dtpStartDate.Date;
            PartnerLocationData.DateGoodUntil = dtpEndDate.Date;

            // get data from radio buttons and check button for PcConferenceOption
            string[] OptionTypeCodes =
            {
                "COST_PER_NIGHT", "COST_PER_DAY", "ADD_ACCOMM_COST_FOR_TOTAL"
            };
            Boolean[] OptionSet =
            {
                rbtNight.Checked, rbtDay.Checked, chkAddAccommodationCosts.Checked
            };

            for (int i = 0; i < 3; i++)
            {
                DataRow RowExists = FMainDS.PcConferenceOption.Rows.Find(new object[] { FPartnerKey, OptionTypeCodes[i] });

                // create new row if needed
                if ((RowExists == null) && OptionSet[i])
                {
                    PcConferenceOptionRow RowToAdd = FMainDS.PcConferenceOption.NewRowTyped(true);
                    RowToAdd.ConferenceKey  = FPartnerKey;
                    RowToAdd.OptionTypeCode = OptionTypeCodes[i];
                    RowToAdd.OptionSet      = true;
                    FMainDS.PcConferenceOption.Rows.Add(RowToAdd);
                }
                // update existing record
                else if ((RowExists != null) && OptionSet[i])
                {
                    ((PcConferenceOptionRow)RowExists).OptionSet = true;
                }
                // delete existing record if discount is 0
                else if ((RowExists != null) && !OptionSet[i])
                {
                    RowExists.Delete();
                }
            }

            // reset the Accommodation text boxs to 0 if no longer needed
            if (!chkAddAccommodationCosts.Checked)
            {
                txtSpecialRolePreAccommodation.NumberValueInt      = 0;
                txtVolunteerPreAccommodation.NumberValueInt        = 0;
                txtParticipantPreAccommodation.NumberValueInt      = 0;
                txtSpecialRoleAccommodation.NumberValueInt         = 0;
                txtVolunteerAccommodation.NumberValueInt           = 0;
                txtSpecialRoleCampaignAccommodation.NumberValueInt = 0;
            }

            // get data from discount text boxes for PcDiscount
            string[, ] Discounts =
            {
                { "ROLE",  "CONFERENCE",    "PRE",  txtSpecialRolePreAttendance.Text.TrimEnd(new char[]         { ' ', '%' }) },
                { "VOL",   "CONFERENCE",    "PRE",  txtVolunteerPreAttendance.Text.TrimEnd(new char[]           { ' ', '%' }) },
                { "OTHER", "CONFERENCE",    "PRE",  txtParticipantPreAttendance.Text.TrimEnd(new char[]         { ' ', '%' }) },
                { "ROLE",  "CONFERENCE",    "CONF", txtSpecialRoleAttendance.Text.TrimEnd(new char[]            { ' ', '%' }) },
                { "VOL",   "CONFERENCE",    "CONF", txtVolunteerAttendance.Text.TrimEnd(new char[]              { ' ', '%' }) },
                { "ROLE",  "CONFERENCE",    "POST", txtSpecialRoleCampaignAttendance.Text.TrimEnd(new char[]    { ' ', '%' }) },
                { "ROLE",  "ACCOMMODATION", "PRE",  txtSpecialRolePreAccommodation.Text.TrimEnd(new char[]      { ' ', '%' }) },
                { "VOL",   "ACCOMMODATION", "PRE",  txtVolunteerPreAccommodation.Text.TrimEnd(new char[]        { ' ', '%' }) },
                { "OTHER", "ACCOMMODATION", "PRE",  txtParticipantPreAccommodation.Text.TrimEnd(new char[]      { ' ', '%' }) },
                { "ROLE",  "ACCOMMODATION", "CONF", txtSpecialRoleAccommodation.Text.TrimEnd(new char[]         { ' ', '%' }) },
                { "VOL",   "ACCOMMODATION", "CONF", txtVolunteerAccommodation.Text.TrimEnd(new char[]           { ' ', '%' }) },
                { "ROLE",  "ACCOMMODATION", "POST", txtSpecialRoleCampaignAccommodation.Text.TrimEnd(new char[] { ' ', '%' }) }
            };

            for (int i = 0; i < 12; i++)
            {
                DataRow RowExists = FMainDS.PcDiscount.Rows.Find(new object[] { FPartnerKey, Discounts[i, 0], Discounts[i, 1], Discounts[i, 2], -1 });

                if (Discounts[i, 3] == "")
                {
                    Discounts[i, 3] = "0";
                }

                // create new row if needed
                if ((RowExists == null) && (Convert.ToInt32(Discounts[i, 3]) != 0))
                {
                    PcDiscountRow RowToAdd = FMainDS.PcDiscount.NewRowTyped(true);
                    RowToAdd.ConferenceKey        = FPartnerKey;
                    RowToAdd.DiscountCriteriaCode = Discounts[i, 0];
                    RowToAdd.CostTypeCode         = Discounts[i, 1];
                    RowToAdd.Validity             = Discounts[i, 2];
                    RowToAdd.UpToAge    = -1;
                    RowToAdd.Percentage = true;
                    RowToAdd.Discount   = Convert.ToInt32(Discounts[i, 3]);
                    FMainDS.PcDiscount.Rows.Add(RowToAdd);
                }
                // update existing record
                else if ((RowExists != null) && (Convert.ToInt32(Discounts[i, 3]) != 0))
                {
                    ((PcDiscountRow)RowExists).Discount = Convert.ToInt32(Discounts[i, 3]);
                }
                // delete existing record if discount is 0
                else if ((RowExists != null) && (Convert.ToInt32(Discounts[i, 3]) == 0))
                {
                    RowExists.Delete();
                }
            }
        }
Beispiel #5
0
        public static SelectConferenceTDS GetConferences(String AConferenceName, String APrefix)
        {
            SelectConferenceTDS ResultTable = new SelectConferenceTDS();

            PcConferenceTable ConferenceTable = new PcConferenceTable();
            PcConferenceRow   TemplateRow     = (PcConferenceRow)ConferenceTable.NewRow();

            TDBTransaction ReadTransaction;
            Boolean        NewTransaction = false;

            if (APrefix == "*")
            {
                APrefix = "";
            }

            if (AConferenceName == "*")
            {
                AConferenceName = "";
            }
            else if (AConferenceName.EndsWith("*"))
            {
                AConferenceName = AConferenceName.Substring(0, AConferenceName.Length - 1);
            }

            TLogging.LogAtLevel(9, "TConferenceOptions.GetConferences called!");

            TDataBase db = DBAccess.Connect("GetConferences");

            ReadTransaction = db.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead,
                                                             out NewTransaction);

            try
            {
                /* Load data */

                if (APrefix.Length > 0)
                {
                    APrefix = APrefix.Replace('*', '%') + "%";
                    TemplateRow.OutreachPrefix = APrefix;

                    StringCollection Operators = new StringCollection();
                    Operators.Add("LIKE");

                    ConferenceTable = PcConferenceAccess.LoadUsingTemplate(TemplateRow, Operators, null, ReadTransaction);
                }
                else
                {
                    ConferenceTable = PcConferenceAccess.LoadAll(ReadTransaction);
                }
            }
            finally
            {
                if (NewTransaction)
                {
                    ReadTransaction.Commit();
                    TLogging.LogAtLevel(7, "TConferenceOptions.GetConferences: committed own transaction.");
                }
            }

            String        ShortName;
            TPartnerClass PartnerClass;

            foreach (PcConferenceRow ConferenceRow in ConferenceTable.Rows)
            {
                TPartnerServerLookups.GetPartnerShortName(ConferenceRow.ConferenceKey, out ShortName, out PartnerClass);

                if ((AConferenceName.Length > 0) &&
                    (!ShortName.StartsWith(AConferenceName, true, null)))
                {
                    continue;
                }

                ResultTable.PcConference.ImportRow(ConferenceRow);

                DataRow NewRow = ResultTable.PPartner.NewRow();
                NewRow[PPartnerTable.GetPartnerShortNameDBName()] = ShortName;
                NewRow[PPartnerTable.GetPartnerKeyDBName()]       = ConferenceRow.ConferenceKey;

                ResultTable.PPartner.Rows.Add(NewRow);
            }

            return(ResultTable);
        }
        private void ValidateDataManual(PcConferenceRow ARow)
        {
            PcDiscountTable DiscountTable = FMainDS.PcDiscount;

            TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection;
            TValidationControlsData ValidationControlsData;
            TScreenVerificationResult VerificationResult = null;
            DataColumn ValidationColumn;

            List <string>CriteriaCodesUsed = new List <string>();

            foreach (PcDiscountRow Row in DiscountTable.Rows)
            {
                if ((Row.RowState != DataRowState.Deleted) && (Row.DiscountCriteriaCode != "CHILD"))
                {
                    if (Row.Discount > 100)
                    {
                        ValidationColumn = Row.Table.Columns[PcDiscountTable.ColumnDiscountId];

                        // displays a warning message
                        VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(
                                    PetraErrorCodes.ERR_DISCOUNT_PERCENTAGE_GREATER_THAN_100)),
                            ValidationColumn, ValidationControlsData.ValidationControl);

                        // Handle addition to/removal from TVerificationResultCollection
                        VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn);
                    }

                    if (!CriteriaCodesUsed.Exists(element => element == Row.DiscountCriteriaCode))
                    {
                        CriteriaCodesUsed.Add(Row.DiscountCriteriaCode);
                    }
                }
            }

            string[] CriteriaCodesUsedArray = CriteriaCodesUsed.ToArray();

            if (!TRemote.MConference.Conference.WebConnectors.CheckDiscountCriteriaCodeExists(CriteriaCodesUsedArray))
            {
                ValidationColumn = DiscountTable.Columns[PcDiscountTable.ColumnDiscountCriteriaCodeId];

                // displays a warning message
                VerificationResult = new TScreenVerificationResult(new TVerificationResult(this, ErrorCodes.GetErrorInfo(
                            PetraErrorCodes.ERR_DISCOUNT_CRITERIA_CODE_DOES_NOT_EXIST)),
                    ValidationColumn, ValidationControlsData.ValidationControl);

                // Handle addition to/removal from TVerificationResultCollection
                VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn);
            }
        }
        // get data from screen and ammend/add to dataset
        private void GetDataFromControlsManual(PcConferenceRow ARow)
        {
            PcConferenceRow ConferenceData = (PcConferenceRow)FMainDS.PcConference.Rows[0];
            PPartnerLocationRow PartnerLocationData = (PPartnerLocationRow)FMainDS.PPartnerLocation.Rows[0];
            PUnitRow UnitData = (PUnitRow)FMainDS.PUnit.Rows[0];

            // do not save currency if it is blank but instead change the combo box to display original value
            if (cmbCurrency.GetSelectedString() != "")
            {
                ConferenceData.CurrencyCode = cmbCurrency.GetSelectedString();
                UnitData.OutreachCostCurrencyCode = cmbCurrency.GetSelectedString();
            }
            else
            {
                cmbCurrency.SetSelectedString(ConferenceData.CurrencyCode);
            }

            ConferenceData.Start = dtpStartDate.Date;
            ConferenceData.End = dtpEndDate.Date;
            PartnerLocationData.DateEffective = dtpStartDate.Date;
            PartnerLocationData.DateGoodUntil = dtpEndDate.Date;

            // get data from radio buttons and check button for PcConferenceOption
            string[] OptionTypeCodes =
            {
                "COST_PER_NIGHT", "COST_PER_DAY", "ADD_ACCOMM_COST_FOR_TOTAL"
            };
            Boolean[] OptionSet =
            {
                rbtNight.Checked, rbtDay.Checked, chkAddAccommodationCosts.Checked
            };

            for (int i = 0; i < 3; i++)
            {
                DataRow RowExists = FMainDS.PcConferenceOption.Rows.Find(new object[] { FPartnerKey, OptionTypeCodes[i] });

                // create new row if needed
                if ((RowExists == null) && OptionSet[i])
                {
                    PcConferenceOptionRow RowToAdd = FMainDS.PcConferenceOption.NewRowTyped(true);
                    RowToAdd.ConferenceKey = FPartnerKey;
                    RowToAdd.OptionTypeCode = OptionTypeCodes[i];
                    RowToAdd.OptionSet = true;
                    FMainDS.PcConferenceOption.Rows.Add(RowToAdd);
                }
                // update existing record
                else if ((RowExists != null) && OptionSet[i])
                {
                    ((PcConferenceOptionRow)RowExists).OptionSet = true;
                }
                // delete existing record if discount is 0
                else if ((RowExists != null) && !OptionSet[i])
                {
                    RowExists.Delete();
                }
            }

            // reset the Accommodation text boxs to 0 if no longer needed
            if (!chkAddAccommodationCosts.Checked)
            {
                txtSpecialRolePreAccommodation.NumberValueInt = 0;
                txtVolunteerPreAccommodation.NumberValueInt = 0;
                txtParticipantPreAccommodation.NumberValueInt = 0;
                txtSpecialRoleAccommodation.NumberValueInt = 0;
                txtVolunteerAccommodation.NumberValueInt = 0;
                txtSpecialRoleCampaignAccommodation.NumberValueInt = 0;
            }

            // get data from discount text boxes for PcDiscount
            string[, ] Discounts =
            {
                { "ROLE", "CONFERENCE", "PRE", txtSpecialRolePreAttendance.Text.TrimEnd(new char[] { ' ', '%' }) },
                { "VOL", "CONFERENCE", "PRE", txtVolunteerPreAttendance.Text.TrimEnd(new char[] { ' ', '%' }) },
                { "OTHER", "CONFERENCE", "PRE", txtParticipantPreAttendance.Text.TrimEnd(new char[] { ' ', '%' }) },
                { "ROLE", "CONFERENCE", "CONF", txtSpecialRoleAttendance.Text.TrimEnd(new char[] { ' ', '%' }) },
                { "VOL", "CONFERENCE", "CONF", txtVolunteerAttendance.Text.TrimEnd(new char[] { ' ', '%' }) },
                { "ROLE", "CONFERENCE", "POST", txtSpecialRoleCampaignAttendance.Text.TrimEnd(new char[] { ' ', '%' }) },
                { "ROLE", "ACCOMMODATION", "PRE", txtSpecialRolePreAccommodation.Text.TrimEnd(new char[] { ' ', '%' }) },
                { "VOL", "ACCOMMODATION", "PRE", txtVolunteerPreAccommodation.Text.TrimEnd(new char[] { ' ', '%' }) },
                { "OTHER", "ACCOMMODATION", "PRE", txtParticipantPreAccommodation.Text.TrimEnd(new char[] { ' ', '%' }) },
                { "ROLE", "ACCOMMODATION", "CONF", txtSpecialRoleAccommodation.Text.TrimEnd(new char[] { ' ', '%' }) },
                { "VOL", "ACCOMMODATION", "CONF", txtVolunteerAccommodation.Text.TrimEnd(new char[] { ' ', '%' }) },
                { "ROLE", "ACCOMMODATION", "POST", txtSpecialRoleCampaignAccommodation.Text.TrimEnd(new char[] { ' ', '%' }) }
            };

            for (int i = 0; i < 12; i++)
            {
                DataRow RowExists = FMainDS.PcDiscount.Rows.Find(new object[] { FPartnerKey, Discounts[i, 0], Discounts[i, 1], Discounts[i, 2], -1 });

                if (Discounts[i, 3] == "")
                {
                    Discounts[i, 3] = "0";
                }

                // create new row if needed
                if ((RowExists == null) && (Convert.ToInt32(Discounts[i, 3]) != 0))
                {
                    PcDiscountRow RowToAdd = FMainDS.PcDiscount.NewRowTyped(true);
                    RowToAdd.ConferenceKey = FPartnerKey;
                    RowToAdd.DiscountCriteriaCode = Discounts[i, 0];
                    RowToAdd.CostTypeCode = Discounts[i, 1];
                    RowToAdd.Validity = Discounts[i, 2];
                    RowToAdd.UpToAge = -1;
                    RowToAdd.Percentage = true;
                    RowToAdd.Discount = Convert.ToInt32(Discounts[i, 3]);
                    FMainDS.PcDiscount.Rows.Add(RowToAdd);
                }
                // update existing record
                else if ((RowExists != null) && (Convert.ToInt32(Discounts[i, 3]) != 0))
                {
                    ((PcDiscountRow)RowExists).Discount = Convert.ToInt32(Discounts[i, 3]);
                }
                // delete existing record if discount is 0
                else if ((RowExists != null) && (Convert.ToInt32(Discounts[i, 3]) == 0))
                {
                    RowExists.Delete();
                }
            }
        }
        public static void CreateNewConference(long APartnerKey)
        {
            TDBTransaction Transaction  = new TDBTransaction();
            TDataBase      db           = DBAccess.Connect("CreateNewConference");
            bool           SubmissionOK = false;

            PcConferenceTable     ConferenceTable;
            PUnitTable            UnitTable;
            PPartnerLocationTable PartnerLocationTable;

            db.WriteTransaction(ref Transaction, ref SubmissionOK,
                                delegate
            {
                try
                {
                    ConferenceTable      = PcConferenceAccess.LoadAll(Transaction);
                    UnitTable            = PUnitAccess.LoadByPrimaryKey(APartnerKey, Transaction);
                    PartnerLocationTable = PPartnerLocationAccess.LoadViaPPartner(APartnerKey, Transaction);

                    DateTime Start = new DateTime();
                    DateTime End   = new DateTime();

                    foreach (PPartnerLocationRow PartnerLocationRow in PartnerLocationTable.Rows)
                    {
                        if ((PartnerLocationRow.DateEffective != null) || (PartnerLocationRow.DateGoodUntil != null))
                        {
                            if (PartnerLocationRow.DateEffective != null)
                            {
                                Start = (DateTime)PartnerLocationRow.DateEffective;
                            }

                            if (PartnerLocationRow.DateGoodUntil != null)
                            {
                                End = (DateTime)PartnerLocationRow.DateGoodUntil;
                            }

                            break;
                        }
                    }

                    // set column values
                    PcConferenceRow AddRow = ConferenceTable.NewRowTyped();
                    AddRow.ConferenceKey   = APartnerKey;

                    string OutreachPrefix = ((PUnitRow)UnitTable.Rows[0]).OutreachCode;

                    if (OutreachPrefix.Length > 4)
                    {
                        AddRow.OutreachPrefix = OutreachPrefix.Substring(0, 5);
                    }
                    else
                    {
                        AddRow.OutreachPrefix = OutreachPrefix;
                    }

                    if (Start != DateTime.MinValue)
                    {
                        AddRow.Start = Start;
                    }

                    if (End != DateTime.MinValue)
                    {
                        AddRow.End = End;
                    }

                    string CurrencyCode = ((PUnitRow)UnitTable.Rows[0]).OutreachCostCurrencyCode;

                    if (!string.IsNullOrEmpty(CurrencyCode))
                    {
                        AddRow.CurrencyCode = CurrencyCode;
                    }
                    else
                    {
                        AddRow.CurrencyCode = "USD";
                    }

                    // add new row to database table
                    ConferenceTable.Rows.Add(AddRow);
                    PcConferenceAccess.SubmitChanges(ConferenceTable, Transaction);

                    SubmissionOK = true;
                }
                catch (Exception Exc)
                {
                    TLogging.Log("An Exception occured during the creation of a new Conference:" + Environment.NewLine + Exc.ToString());
                }
            });
        }