private void InitialiseBudgetList(ABudgetTable ABdgTable)
        {
            string CheckedMember = "CHECKED";
            string AccountDBN    = ABudgetTable.GetAccountCodeDBName();
            string CostCentreDBN = ABudgetTable.GetCostCentreCodeDBName();
            string BudgetSeqDBN  = ABudgetTable.GetBudgetSequenceDBName();
            string CCAccDesc     = "CostCentreAccountDescription";
            string BudgetSeqKey  = "BudgetSequenceKey";

            //Calculate the longest Cost Centre to calculate padding amount
            ABudgetRow BudgetRow;
            int        CostCentreCodeLength = 0;

            if (ABdgTable != null)
            {
                if (ABdgTable.Count > 0)
                {
                    FBudgetsExist = true;

                    for (int i = 0; i < ABdgTable.Count; i++)
                    {
                        BudgetRow            = (ABudgetRow)ABdgTable.Rows[i];
                        CostCentreCodeLength = BudgetRow.CostCentreCode.Length;

                        if (CostCentreCodeLength > CostCentrePadding)
                        {
                            CostCentrePadding = CostCentreCodeLength;
                        }
                    }

                    BudgetRow = null;

                    // add empty row so that SetSelectedString for invalid string will not result in undefined behaviour (selecting the first cost centre etc)
                    //ABudgetRow emptyRow = (ABudgetRow)ABdgTable.NewRow();

                    DataView view = new DataView(ABdgTable);
                    view.RowFilter = String.Format("{0}={1}",
                                                   ABudgetTable.GetLedgerNumberDBName(),
                                                   FLedgerNumber);
                    DataTable ABdgTable2 = view.ToTable(true, new string[] { BudgetSeqDBN, AccountDBN, CostCentreDBN });

                    ABdgTable2.Columns.Add(new DataColumn(CheckedMember, typeof(bool)));
                    ABdgTable2.Columns.Add(new DataColumn(BudgetSeqKey, typeof(string), BudgetSeqDBN));
                    ABdgTable2.Columns.Add(new DataColumn(CCAccDesc, typeof(string),
                                                          CostCentreDBN.PadRight(CostCentrePadding + 2, ' ') + " + '-' + " + AccountDBN));

                    clbCostCentreAccountCodes.Columns.Clear();
                    clbCostCentreAccountCodes.AddCheckBoxColumn("", ABdgTable2.Columns[CheckedMember], 17, false);
                    clbCostCentreAccountCodes.AddTextColumn("Key", ABdgTable2.Columns[BudgetSeqKey], 0);
                    clbCostCentreAccountCodes.AddTextColumn("Cost Centre-Account", ABdgTable2.Columns[CCAccDesc], 200);
                    clbCostCentreAccountCodes.DataBindGrid(ABdgTable2, BudgetSeqKey, CheckedMember, BudgetSeqKey, false, true, false);

                    clbCostCentreAccountCodes.SetCheckedStringList("");
                }
            }

            btnOK.Enabled = FBudgetsExist;
            btnSelectAllBudgets.Enabled   = FBudgetsExist;
            btnUnselectAllBudgets.Enabled = FBudgetsExist;
        }
        private void InitialiseBudgetList(ABudgetTable ABdgTable)
        {
            string CheckedMember = "CHECKED";
            string AccountDBN    = ABudgetTable.GetAccountCodeDBName();
            string CostCentreDBN = ABudgetTable.GetCostCentreCodeDBName();
            string BudgetSeqDBN  = ABudgetTable.GetBudgetSequenceDBName();
            string CCAccDesc     = "CostCentreAccountDescription";
            string BudgetSeqKey  = "BudgetSequenceKey";

            //Calculate the longest Cost Centre to calculate padding amount
            ABudgetRow BudgetRow;
            int        CostCentreCodeLength = 0;

            if (ABdgTable != null)
            {
                if (ABdgTable.Count > 0)
                {
                    FBudgetsExist = true;

                    for (int i = 0; i < ABdgTable.Count; i++)
                    {
                        BudgetRow            = (ABudgetRow)ABdgTable.Rows[i];
                        CostCentreCodeLength = BudgetRow.CostCentreCode.Length;

                        if (CostCentreCodeLength > CostCentrePadding)
                        {
                            CostCentrePadding = CostCentreCodeLength;
                        }
                    }

                    BudgetRow = null;

                    // add empty row so that SetSelectedString for invalid string will not result in undefined behaviour (selecting the first cost centre etc)
                    //ABudgetRow emptyRow = (ABudgetRow)ABdgTable.NewRow();

                    // We create a copy of the ABudget table but this time only with three columns and ensuring we get didtinct rows.
                    // This caters for having multiple budget revisions by 'filtering' them out.
                    // We already have a specific ledger and year from the server in ABdgTable.
                    DataTable ABdgTable2 = ABdgTable.DefaultView.ToTable(true, new string[] { BudgetSeqDBN, AccountDBN, CostCentreDBN });

                    ABdgTable2.Columns.Add(new DataColumn(CheckedMember, typeof(bool)));
                    ABdgTable2.Columns.Add(new DataColumn(BudgetSeqKey, typeof(string), BudgetSeqDBN));
                    ABdgTable2.Columns.Add(new DataColumn(CCAccDesc, typeof(string),
                                                          CostCentreDBN.PadRight(CostCentrePadding + 2, ' ') + " + '-' + " + AccountDBN));

                    clbCostCentreAccountCodes.Columns.Clear();
                    clbCostCentreAccountCodes.AddCheckBoxColumn("", ABdgTable2.Columns[CheckedMember], 17, false);
                    clbCostCentreAccountCodes.AddTextColumn("Key", ABdgTable2.Columns[BudgetSeqKey], 0);
                    clbCostCentreAccountCodes.AddTextColumn("Cost Centre-Account", ABdgTable2.Columns[CCAccDesc]);
                    clbCostCentreAccountCodes.DataBindGrid(ABdgTable2, CCAccDesc, CheckedMember, BudgetSeqKey, false, true, false);

                    clbCostCentreAccountCodes.SetCheckedStringList("");
                }
            }

            btnOK.Enabled = FBudgetsExist;
            btnSelectAllBudgets.Enabled   = FBudgetsExist;
            btnUnselectAllBudgets.Enabled = FBudgetsExist;
        }
Пример #3
0
        public static BudgetTDS LoadBudgetForAutoGenerate(Int32 ALedgerNumber)
        {
            BudgetTDS FMainDS = new BudgetTDS();

            TDBTransaction Transaction = new TDBTransaction();
            TDataBase      db          = DBAccess.Connect("LoadBudgetForAutoGenerate");

            db.ReadTransaction(
                ref Transaction,
                delegate
            {
                ALedgerAccess.LoadByPrimaryKey(FMainDS, ALedgerNumber, Transaction);

                #region Validate Data

                if ((FMainDS.ALedger == null) || (FMainDS.ALedger.Count == 0))
                {
                    throw new EFinanceSystemDataTableReturnedNoDataException(String.Format(Catalog.GetString(
                                                                                               "Function:{0} - Ledger data for Ledger number {1} does not exist or could not be accessed!"),
                                                                                           Utilities.GetMethodName(true),
                                                                                           ALedgerNumber));
                }

                #endregion Validate Data

                int CurrentFinancialYear = FMainDS.ALedger[0].CurrentFinancialYear;

                //Load all by Ledger/Year but none may exist
                ABudgetTable BudgetTable = new ABudgetTable();
                ABudgetRow TemplateRow   = (ABudgetRow)BudgetTable.NewRow();

                TemplateRow.LedgerNumber = ALedgerNumber;
                TemplateRow.Year         = CurrentFinancialYear;

                StringCollection Operators = StringHelper.InitStrArr(new string[] { "=", "=" });
                StringCollection OrderList = new StringCollection();

                OrderList.Add("ORDER BY");
                OrderList.Add(ABudgetTable.GetCostCentreCodeDBName() + " ASC");
                OrderList.Add(ABudgetTable.GetAccountCodeDBName() + " ASC");

                ABudgetAccess.LoadUsingTemplate(FMainDS, TemplateRow, Operators, null, Transaction, OrderList, 0, 0);
                ABudgetPeriodAccess.LoadViaABudgetTemplate(FMainDS, TemplateRow, Operators, null, Transaction, OrderList, 0, 0);

                ABudgetRevisionAccess.LoadByPrimaryKey(FMainDS, ALedgerNumber, CurrentFinancialYear, 0, Transaction);

                ABudgetTypeAccess.LoadAll(FMainDS, Transaction);
            });

            // Accept row changes here so that the Client gets 'unmodified' rows
            FMainDS.AcceptChanges();

            // Remove all Tables that were not filled with data before remoting them.
            FMainDS.RemoveEmptyTables();

            return(FMainDS);
        }