コード例 #1
0
        private int GetChangedRecordCountManual(out string AMessage)
        {
            // For GL Batch we will get some mix of batches, journals and transactions
            // Only check relevant tables.
            List <string> TablesToCheck = new List <string>();

            TablesToCheck.Add(FMainDS.ABatch.TableName);
            TablesToCheck.Add(FMainDS.AJournal.TableName);
            TablesToCheck.Add(FMainDS.ATransaction.TableName);
            TablesToCheck.Add(FMainDS.ATransAnalAttrib.TableName);

            List <Tuple <string, int> > TableAndCountList = new List <Tuple <string, int> >();
            int AllChangesCount = 0;

            if (FMainDS.HasChanges())
            {
                // Work out how many changes in each table
                foreach (DataTable dt in FMainDS.GetChanges().Tables)
                {
                    string currentTableName = dt.TableName;

                    if ((dt != null) &&
                        TablesToCheck.Contains(currentTableName) &&
                        (dt.Rows.Count > 0))
                    {
                        int tableChangesCount = 0;

                        DataTable dtChanges = dt.GetChanges();

                        foreach (DataRow dr in dtChanges.Rows)
                        {
                            if (DataUtilities.DataRowColumnsHaveChanged(dr))
                            {
                                tableChangesCount++;
                                AllChangesCount++;
                            }
                        }

                        if (tableChangesCount > 0)
                        {
                            TableAndCountList.Add(new Tuple <string, int>(currentTableName, tableChangesCount));
                        }
                    }
                }
            }

            // Now build up a sensible message
            AMessage = String.Empty;

            if (TableAndCountList.Count > 0)
            {
                int nBatches      = 0;
                int nJournals     = 0;
                int nTransactions = 0;

                foreach (Tuple <string, int> TableAndCount in TableAndCountList)
                {
                    if (TableAndCount.Item1.Equals(ABatchTable.GetTableName()))
                    {
                        nBatches = TableAndCount.Item2;
                    }
                    else if (TableAndCount.Item1.Equals(AJournalTable.GetTableName()))
                    {
                        nJournals = TableAndCount.Item2;
                    }
                    else if (TableAndCount.Item2 > nTransactions)
                    {
                        nTransactions = TableAndCount.Item2;
                    }
                }

                AMessage = Catalog.GetString("    You have made changes to ");
                string strBatches      = String.Empty;
                string strJournals     = String.Empty;
                string strTransactions = String.Empty;

                if (nBatches > 0)
                {
                    strBatches = String.Format("{0} {1}",
                                               nBatches,
                                               Catalog.GetPluralString("batch", "batches", nBatches));
                }

                if (nJournals > 0)
                {
                    strJournals = String.Format("{0} {1}",
                                                nJournals,
                                                Catalog.GetPluralString("journal", "journals", nJournals));
                }

                if (nTransactions > 0)
                {
                    strTransactions = String.Format("{0} {1}",
                                                    nTransactions,
                                                    Catalog.GetPluralString("transaction", "transactions", nTransactions));
                }

                bool bGotAll = (nBatches > 0) && (nJournals > 0) && (nTransactions > 0);

                if (nBatches > 0)
                {
                    AMessage += strBatches;
                }

                if (nJournals > 0)
                {
                    if (bGotAll)
                    {
                        AMessage += ", ";
                    }
                    else if (nBatches > 0)
                    {
                        AMessage += " and ";
                    }

                    AMessage += strJournals;
                }

                if (nTransactions > 0)
                {
                    if ((nBatches > 0) || (nJournals > 0))
                    {
                        AMessage += " and ";
                    }

                    AMessage += strTransactions;
                }

                AMessage += Environment.NewLine + Catalog.GetString("(some of the changes may include related background items)");
                AMessage += Environment.NewLine;
                AMessage += String.Format(TFrmPetraEditUtils.StrConsequenceIfNotSaved, Environment.NewLine);
            }

            return(AllChangesCount);
        }
コード例 #2
0
        private int GetChangedRecordCountManual(out string AMessage)
        {
            //For Gift Batch we will get a mix of some batches, gifts and gift details.
            // Only check relevant tables.
            List <string> TablesToCheck = new List <string>();

            TablesToCheck.Add(FMainDS.AGiftBatch.TableName);
            TablesToCheck.Add(FMainDS.AGift.TableName);
            TablesToCheck.Add(FMainDS.AGiftDetail.TableName);

            List <Tuple <string, int> > TableAndCountList = new List <Tuple <string, int> >();
            int AllChangesCount = 0;

            if (FMainDS.HasChanges())
            {
                foreach (DataTable dt in FMainDS.GetChanges().Tables)
                {
                    string currentTableName = dt.TableName;

                    if ((dt != null) &&
                        TablesToCheck.Contains(currentTableName) &&
                        (dt.Rows.Count > 0))
                    {
                        int tableChangesCount = 0;

                        DataTable dtChanges = dt.GetChanges();

                        foreach (DataRow dr in dtChanges.Rows)
                        {
                            if (DataUtilities.DataRowColumnsHaveChanged(dr))
                            {
                                tableChangesCount++;
                                AllChangesCount++;
                            }
                        }

                        if (tableChangesCount > 0)
                        {
                            TableAndCountList.Add(new Tuple <string, int>(currentTableName, tableChangesCount));
                        }
                    }
                }
            }

            // Now build up a sensible message
            AMessage = String.Empty;

            if (TableAndCountList.Count > 0)
            {
                if (TableAndCountList.Count == 1)
                {
                    Tuple <string, int> TableAndCount = TableAndCountList[0];

                    string tableName = TableAndCount.Item1;

                    if (TableAndCount.Item1.Equals(AGiftBatchTable.GetTableName()))
                    {
                        AMessage = String.Format(Catalog.GetString("    You have made changes to the details of {0} {1}.{2}"),
                                                 TableAndCount.Item2,
                                                 Catalog.GetPluralString("batch", "batches", TableAndCount.Item2),
                                                 Environment.NewLine);
                    }
                    else if (TableAndCount.Item1.Equals(AGiftTable.GetTableName()))
                    {
                        AMessage = String.Format(Catalog.GetString("    You have made changes to the details of {0} {1}.{2}"),
                                                 TableAndCount.Item2,
                                                 Catalog.GetPluralString("gift", "gifts", TableAndCount.Item2),
                                                 Environment.NewLine);
                    }
                    else //if (TableAndCount.Item1.Equals(AGiftDetailTable.GetTableName()))
                    {
                        AMessage = String.Format(Catalog.GetString("    You have made changes to {0} {1}.{2}"),
                                                 TableAndCount.Item2,
                                                 Catalog.GetPluralString("gift detail", "gift details", TableAndCount.Item2),
                                                 Environment.NewLine);
                    }
                }
                else
                {
                    int nBatches     = 0;
                    int nGifts       = 0;
                    int nGiftDetails = 0;

                    foreach (Tuple <string, int> TableAndCount in TableAndCountList)
                    {
                        if (TableAndCount.Item1.Equals(AGiftBatchTable.GetTableName()))
                        {
                            nBatches = TableAndCount.Item2;
                        }
                        else if (TableAndCount.Item1.Equals(AGiftTable.GetTableName()))
                        {
                            nGifts = TableAndCount.Item2;
                        }
                        else //if (TableAndCount.Item1.Equals(AGiftDetailTable.GetTableName()))
                        {
                            nGiftDetails = TableAndCount.Item2;
                        }
                    }

                    if ((nBatches > 0) && (nGifts > 0) && (nGiftDetails > 0))
                    {
                        AMessage = String.Format(Catalog.GetString("    You have made changes to {0} {1}, {2} {3} and {4} {5}.{6}"),
                                                 nBatches,
                                                 Catalog.GetPluralString("batch", "batches", nBatches),
                                                 nGifts,
                                                 Catalog.GetPluralString("gift", "gifts", nGifts),
                                                 nGiftDetails,
                                                 Catalog.GetPluralString("gift detail", "gift details", nGiftDetails),
                                                 Environment.NewLine);
                    }
                    else if ((nBatches > 0) && (nGifts > 0) && (nGiftDetails == 0))
                    {
                        AMessage = String.Format(Catalog.GetString("    You have made changes to {0} {1} and {2} {3}.{4}"),
                                                 nBatches,
                                                 Catalog.GetPluralString("batch", "batches", nBatches),
                                                 nGifts,
                                                 Catalog.GetPluralString("gift", "gifts", nGifts),
                                                 Environment.NewLine);
                    }
                    else if ((nBatches > 0) && (nGifts == 0) && (nGiftDetails > 0))
                    {
                        AMessage = String.Format(Catalog.GetString("    You have made changes to {0} {1} and {2} {3}.{4}"),
                                                 nBatches,
                                                 Catalog.GetPluralString("batch", "batches", nBatches),
                                                 nGiftDetails,
                                                 Catalog.GetPluralString("gift detail", "gift details", nGiftDetails),
                                                 Environment.NewLine);
                    }
                    else if ((nBatches > 0) && (nGifts == 0) && (nGiftDetails == 0))
                    {
                        AMessage = String.Format(Catalog.GetString("    You have made changes to {0} {1}.{2}"),
                                                 nBatches,
                                                 Catalog.GetPluralString("batch", "batches", nBatches),
                                                 Environment.NewLine);
                    }
                    else if ((nBatches == 0) && (nGifts > 0) && (nGiftDetails > 0))
                    {
                        AMessage = String.Format(Catalog.GetString("    You have made changes to {0} {1} and {2} {3}.{4}"),
                                                 nGifts,
                                                 Catalog.GetPluralString("gift", "gifts", nGifts),
                                                 nGiftDetails,
                                                 Catalog.GetPluralString("gift detail", "gift details", nGiftDetails),
                                                 Environment.NewLine);
                    }
                    else if ((nBatches == 0) && (nGifts > 0) && (nGiftDetails == 0))
                    {
                        AMessage = String.Format(Catalog.GetString("    You have made changes to {0} {1}.{2}"),
                                                 nGifts,
                                                 Catalog.GetPluralString("gift", "gifts", nGiftDetails),
                                                 Environment.NewLine);
                    }
                    else if ((nBatches == 0) && (nGifts == 0) && (nGiftDetails > 0))
                    {
                        AMessage = String.Format(Catalog.GetString("    You have made changes to {0} {1}.{2}"),
                                                 nGiftDetails,
                                                 Catalog.GetPluralString("gift detail", "gift details", nGiftDetails),
                                                 Environment.NewLine);
                    }
                }

                AMessage += Catalog.GetString("(some of the changes may include related background items)");
                AMessage += Environment.NewLine;
                AMessage += String.Format(TFrmPetraEditUtils.StrConsequenceIfNotSaved, Environment.NewLine);
            }

            return(AllChangesCount);
        }