Example #1
0
        /// <summary>
        /// create PPartnerBankingDetail records for the FAMILY partner
        /// </summary>
        public static void GenerateBankDetails(XmlNode ACurrentNode, PFamilyRow AFamilyRow, PartnerEditTDS AMainDS,
                                               DataTable ABankKeys)
        {
            if (TXMLParser.HasAttribute(ACurrentNode, "bankaccount_bank"))
            {
                Int32 BankID =
                    Convert.ToInt32(TXMLParser.GetAttribute(ACurrentNode, "bankaccount_bank")) % ABankKeys.Rows.Count;
                long BankPartnerKey = Convert.ToInt64(ABankKeys.Rows[BankID].ItemArray[0]);

                PBankingDetailsRow bankingDetailsRow = AMainDS.PBankingDetails.NewRowTyped();

                bankingDetailsRow.BankingDetailsKey = (AMainDS.PBankingDetails.Rows.Count + 1) * -1;
                bankingDetailsRow.BankKey           = BankPartnerKey;
                bankingDetailsRow.BankAccountNumber = TXMLParser.GetAttribute(ACurrentNode, "bankaccount_account");
                bankingDetailsRow.BankingType       = MPartnerConstants.BANKINGTYPE_BANKACCOUNT;
                bankingDetailsRow.AccountName       = AFamilyRow.FirstName + " " + AFamilyRow.FamilyName;

                AMainDS.PBankingDetails.Rows.Add(bankingDetailsRow);

                PPartnerBankingDetailsRow partnerBankingRow = AMainDS.PPartnerBankingDetails.NewRowTyped();
                partnerBankingRow.PartnerKey        = AFamilyRow.PartnerKey;
                partnerBankingRow.BankingDetailsKey = bankingDetailsRow.BankingDetailsKey;
                AMainDS.PPartnerBankingDetails.Rows.Add(partnerBankingRow);

                PBankingDetailsUsageRow bankingUsageRow = AMainDS.PBankingDetailsUsage.NewRowTyped();
                bankingUsageRow.BankingDetailsKey = bankingDetailsRow.BankingDetailsKey;
                bankingUsageRow.PartnerKey        = AFamilyRow.PartnerKey;
                bankingUsageRow.Type = MPartnerConstants.BANKINGUSAGETYPE_MAIN;
                AMainDS.PBankingDetailsUsage.Rows.Add(bankingUsageRow);
            }
        }
Example #2
0
        /// <summary>
        /// create the radio buttons and the controls that depend on them
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="curNode"></param>
        /// <returns></returns>
        public override StringCollection FindContainedControls(TFormWriter writer, XmlNode curNode)
        {
            StringCollection Controls =
                TYml2Xml.GetElements(TXMLParser.GetChild(curNode, "Controls"));
            string DefaultValue = Controls[0];

            if (TXMLParser.HasAttribute(curNode, "DefaultValue"))
            {
                DefaultValue = TXMLParser.GetAttribute(curNode, "DefaultValue");
            }

            foreach (string controlName in Controls)
            {
                TControlDef radioButton = writer.CodeStorage.GetControl(controlName);

                if (radioButton == null)
                {
                    throw new Exception("cannot find control " + controlName + " used in RadioGroup " + curNode.Name);
                }

                if (StringHelper.IsSame(DefaultValue, controlName))
                {
                    radioButton.SetAttribute("RadioChecked", "true");
                }
            }

            return(Controls);
        }
Example #3
0
        private static string GetMaritalStatusCode(XmlNode ACurrentPartnerNode)
        {
            if (TXMLParser.HasAttribute(ACurrentPartnerNode, MPartnerConstants.PARTNERIMPORT_MARITALSTATUS))
            {
                string maritalStatus = TXMLParser.GetAttribute(ACurrentPartnerNode, MPartnerConstants.PARTNERIMPORT_MARITALSTATUS);

                if (maritalStatus.ToLower() == Catalog.GetString("married").ToLower())
                {
                    return(MPartnerConstants.MARITALSTATUS_MARRIED);
                }
                else if (maritalStatus.ToLower() == Catalog.GetString("engaged").ToLower())
                {
                    return(MPartnerConstants.MARITALSTATUS_ENGAGED);
                }
                else if (maritalStatus.ToLower() == Catalog.GetString("single").ToLower())
                {
                    return(MPartnerConstants.MARITALSTATUS_SINGLE);
                }
                else if (maritalStatus.ToLower() == Catalog.GetString("divorced").ToLower())
                {
                    return(MPartnerConstants.MARITALSTATUS_DIVORCED);
                }
            }

            return(MPartnerConstants.MARITALSTATUS_UNDEFINED);
        }
Example #4
0
        private static string GetMaritalStatusCode(XmlNode ACurrentPartnerNode, TDBTransaction ATransaction)
        {
            if (TXMLParser.HasAttribute(ACurrentPartnerNode, MPartnerConstants.PARTNERIMPORT_MARITALSTATUS))
            {
                string maritalStatus = TXMLParser.GetAttribute(ACurrentPartnerNode, MPartnerConstants.PARTNERIMPORT_MARITALSTATUS);

                // first look for special cases
                if (maritalStatus.ToLower() == Catalog.GetString("married").ToLower())
                {
                    return(MPartnerConstants.MARITALSTATUS_MARRIED);
                }
                else if (maritalStatus.ToLower() == Catalog.GetString("engaged").ToLower())
                {
                    return(MPartnerConstants.MARITALSTATUS_ENGAGED);
                }
                else if (maritalStatus.ToLower() == Catalog.GetString("single").ToLower())
                {
                    return(MPartnerConstants.MARITALSTATUS_SINGLE);
                }
                else if (maritalStatus.ToLower() == Catalog.GetString("divorced").ToLower())
                {
                    return(MPartnerConstants.MARITALSTATUS_DIVORCED);
                }

                // now check for value of marital status in setup table
                if (PtMaritalStatusAccess.Exists(maritalStatus, ATransaction))
                {
                    return(maritalStatus);
                }
            }

            return("");
        }
Example #5
0
        /// <summary>write the code for the designer file where the properties of the control are written</summary>
        public override ProcessTemplate SetControlProperties(TFormWriter writer, TControlDef ctrl)
        {
            ProcessTemplate ctrlSnippet = base.SetControlProperties(writer, ctrl);

            if (TXMLParser.HasAttribute(ctrl.xmlNode, "RadioChecked"))
            {
                ctrlSnippet.SetCodelet("CHECKED", "true");
            }

            ctrlSnippet.SetCodelet("BOXLABEL", ctrlSnippet.FCodelets["LABEL"].ToString());
            ctrlSnippet.SetCodelet("LABEL", "strEmpty");
            ctrlSnippet.SetCodelet("INPUTVALUE", ctrl.controlName.Substring(3));

            return(ctrlSnippet);
        }
Example #6
0
        /// <summary>
        /// create the radio buttons
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="curNode"></param>
        /// <returns></returns>
        public override StringCollection FindContainedControls(TFormWriter writer, XmlNode curNode)
        {
            StringCollection optionalValues =
                TYml2Xml.GetElements(TXMLParser.GetChild(curNode, "OptionalValues"));
            string DefaultValue = optionalValues[0];

            if (TXMLParser.HasAttribute(curNode, "DefaultValue"))
            {
                DefaultValue = TXMLParser.GetAttribute(curNode, "DefaultValue");
            }
            else
            {
                // DefaultValue with = sign before control name
                for (int counter = 0; counter < optionalValues.Count; counter++)
                {
                    if (optionalValues[counter].StartsWith("="))
                    {
                        optionalValues[counter] = optionalValues[counter].Substring(1).Trim();
                        DefaultValue            = optionalValues[counter];
                    }
                }
            }

            // add the radiobuttons on the fly
            StringCollection Controls = new StringCollection();

            foreach (string optionalValue in optionalValues)
            {
                string radioButtonName = "rbt" +
                                         StringHelper.UpperCamelCase(optionalValue.Replace("'", "").Replace(" ",
                                                                                                            "_").Replace("&",
                                                                                                                         ""), false, false);
                TControlDef newCtrl = writer.CodeStorage.FindOrCreateControl(radioButtonName, curNode.Name);
                newCtrl.Label = optionalValue;

                if (StringHelper.IsSame(DefaultValue, optionalValue))
                {
                    newCtrl.SetAttribute("RadioChecked", "true");
                }

                Controls.Add(radioButtonName);
            }

            return(Controls);
        }
Example #7
0
        private static string GetTitle(XmlNode ACurrentPartnerNode)
        {
            if (TXMLParser.HasAttribute(ACurrentPartnerNode, MPartnerConstants.PARTNERIMPORT_TITLE))
            {
                return(TXMLParser.GetAttribute(ACurrentPartnerNode, MPartnerConstants.PARTNERIMPORT_TITLE));
            }

            string genderCode = GetGenderCode(ACurrentPartnerNode);

            if (genderCode == MPartnerConstants.GENDER_MALE)
            {
                return(Catalog.GetString("Mr"));
            }
            else if (genderCode == MPartnerConstants.GENDER_FEMALE)
            {
                return(Catalog.GetString("Ms"));
            }

            return("");
        }
Example #8
0
        private static void CreateSpecialNeeds(XmlNode ANode, Int64 APartnerKey, ref PartnerImportExportTDS AMainDS)
        {
            // only create special need record if data exists in import file
            if (TXMLParser.HasAttribute(ANode, MPartnerConstants.PARTNERIMPORT_VEGETARIAN) ||
                TXMLParser.HasAttribute(ANode, MPartnerConstants.PARTNERIMPORT_MEDICALNEEDS))
            {
                PmSpecialNeedRow NewRow = AMainDS.PmSpecialNeed.NewRowTyped();
                NewRow.PartnerKey     = APartnerKey;
                NewRow.MedicalComment = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_MEDICALNEEDS);

                if (TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_VEGETARIAN).ToLower() == "yes")
                {
                    NewRow.VegetarianFlag = true;
                }
                else
                {
                    NewRow.VegetarianFlag = false;
                }

                AMainDS.PmSpecialNeed.Rows.Add(NewRow);
                AddVerificationResult("Special Need Record Created.", TResultSeverity.Resv_Status);
            }
        }
        /// creates a file with enums in Shared and one file per submodule in Server for cached tables
        public static void WriteCachedTables(TDataDefinitionStore AStore,
                                             string ACacheYamlFilename,
                                             string ASharedPath,
                                             string ATemplateDir)
        {
            // Load yaml file with list of tables that should be cached
            TYml2Xml    ymlParser = new TYml2Xml(ACacheYamlFilename);
            XmlDocument xmlDoc    = ymlParser.ParseYML2XML();

            XmlNode module = xmlDoc.DocumentElement.FirstChild.FirstChild;

            while (module != null)
            {
                XmlNode subModule         = module.FirstChild;
                bool    severalSubModules = (subModule != null && subModule.NextSibling != null);

                // write the shared file with the enum definitions
                ProcessTemplate SharedTemplate = new ProcessTemplate(ATemplateDir + Path.DirectorySeparatorChar +
                                                                     "ORM" + Path.DirectorySeparatorChar +
                                                                     "Cacheable.Shared.cs");

                SharedTemplate.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(ATemplateDir));
//                SharedTemplate.SetCodelet("NAMESPACE", "Ict.Petra.Shared.M" + module.Name);
                SharedTemplate.SetCodelet("NAMESPACE", "Ict.Petra.Shared");

                while (subModule != null)
                {
                    List <string> UsingNamespaces = new List <string>();

                    // write the server file for each submodule
                    ProcessTemplate ServerTemplate = new ProcessTemplate(ATemplateDir + Path.DirectorySeparatorChar +
                                                                         "ORM" + Path.DirectorySeparatorChar +
                                                                         "Cacheable.Server.cs");

                    ServerTemplate.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(ATemplateDir));
                    ServerTemplate.SetCodelet("NAMESPACE", "Ict.Petra.Server.M" + module.Name + "." + subModule.Name + ".Cacheable");
                    ServerTemplate.SetCodelet("SUBNAMESPACE", "M" + module.Name + "." + subModule.Name);
                    ServerTemplate.SetCodelet("CACHEABLECLASS", "T" + module.Name + "Cacheable");
                    ServerTemplate.SetCodelet("SUBMODULE", subModule.Name);
                    ServerTemplate.SetCodelet("GETCALCULATEDLISTFROMDB", "");
                    ServerTemplate.SetCodelet("LEDGERGETCACHEABLE", "");
                    ServerTemplate.SetCodelet("LEDGERSAVECACHEABLE", "");

                    if (!severalSubModules)
                    {
                        // for MCommon
                        ServerTemplate.SetCodelet("NAMESPACE", "Ict.Petra.Server.M" + module.Name + ".Cacheable");
                        ServerTemplate.SetCodelet("SUBNAMESPACE", "M" + module.Name);
                        ServerTemplate.SetCodelet("CACHEABLECLASS", "TCacheable");
                    }

                    ProcessTemplate snippetSubmodule = SharedTemplate.GetSnippet("SUBMODULEENUM");
                    snippetSubmodule.SetCodelet("SUBMODULE", subModule.Name);
                    snippetSubmodule.SetCodelet("MODULE", module.Name);

                    ProcessTemplate snippetLedgerGetTable  = null;
                    ProcessTemplate snippetLedgerSaveTable = null;

                    XmlNode TableOrListElement = subModule.FirstChild;

                    while (TableOrListElement != null)
                    {
                        XmlNode enumElement = TableOrListElement.FirstChild;

                        while (enumElement != null)
                        {
                            bool DependsOnLedger = false;

                            if (TYml2Xml.GetAttributeRecursive(enumElement, "DependsOnLedger") == "true")
                            {
                                if (snippetLedgerGetTable == null)
                                {
                                    snippetLedgerGetTable = ServerTemplate.GetSnippet("LEDGERGETCACHEABLE");
                                    snippetLedgerGetTable.SetCodelet("SUBMODULE", subModule.Name);
                                }

                                if ((snippetLedgerSaveTable == null) && (TableOrListElement.Name == "DatabaseTables"))
                                {
                                    snippetLedgerSaveTable = ServerTemplate.GetSnippet("LEDGERSAVECACHEABLE");
                                    snippetLedgerSaveTable.SetCodelet("SUBMODULE", subModule.Name);
                                }

                                DependsOnLedger = true;

                                ServerTemplate.SetCodelet("WITHLEDGER", "true");
                            }

                            ProcessTemplate snippetElement = SharedTemplate.GetSnippet("ENUMELEMENT");

                            if ((enumElement.NextSibling == null) &&
                                ((TableOrListElement.NextSibling == null) || (TableOrListElement.NextSibling.FirstChild == null)))
                            {
                                snippetElement = SharedTemplate.GetSnippet("ENUMELEMENTLAST");
                            }

                            string Comment = TXMLParser.GetAttribute(enumElement, "Comment");

                            if (TableOrListElement.Name == "DatabaseTables")
                            {
                                TTable Table = AStore.GetTable(enumElement.Name);

                                string Namespace = "Ict.Petra.Shared." + TTable.GetNamespace(Table.strGroup) + ".Data";

                                if (!UsingNamespaces.Contains(Namespace))
                                {
                                    UsingNamespaces.Add(Namespace);
                                }

                                Namespace = "Ict.Petra.Server." + TTable.GetNamespace(Table.strGroup) + ".Validation";

                                if (!UsingNamespaces.Contains(Namespace))
                                {
                                    UsingNamespaces.Add(Namespace);
                                }

                                Namespace = "Ict.Petra.Server." + TTable.GetNamespace(Table.strGroup) + ".Data.Access";

                                if (!UsingNamespaces.Contains(Namespace))
                                {
                                    UsingNamespaces.Add(Namespace);
                                }

                                if (Table == null)
                                {
                                    throw new Exception("Error: cannot find table " + enumElement.Name + " for caching in module " + module.Name);
                                }

                                if (Comment.Length == 0)
                                {
                                    Comment = Table.strDescription;
                                }
                            }

                            if (Comment.Length == 0)
                            {
                                Comment = "todoComment";
                            }

                            snippetElement.SetCodelet("ENUMCOMMENT", Comment);

                            string enumName = enumElement.Name;

                            if (TXMLParser.HasAttribute(enumElement, "Enum"))
                            {
                                enumName = TXMLParser.GetAttribute(enumElement, "Enum");
                            }
                            else if (TableOrListElement.Name == "DatabaseTables")
                            {
                                string character2 = enumElement.Name.Substring(1, 1);

                                if (character2.ToLower() == character2)
                                {
                                    // this is a table name that has a 2 digit prefix
                                    enumName = enumElement.Name.Substring(2) + "List";
                                }
                                else
                                {
                                    enumName = enumElement.Name.Substring(1) + "List";
                                }
                            }

                            snippetElement.SetCodelet("ENUMNAME", enumName);
                            snippetElement.SetCodelet("DATATABLENAME", enumElement.Name);

                            snippetSubmodule.InsertSnippet("ENUMELEMENTS", snippetElement);

                            if (TableOrListElement.Name == "DatabaseTables")
                            {
                                ProcessTemplate snippetLoadTable = ServerTemplate.GetSnippet("LOADTABLE");

                                if (DependsOnLedger)
                                {
                                    snippetLoadTable = ServerTemplate.GetSnippet("LOADTABLEVIALEDGER");
                                }

                                snippetLoadTable.SetCodelet("ENUMNAME", enumName);
                                snippetLoadTable.SetCodelet("DATATABLENAME", enumElement.Name);

                                if (DependsOnLedger)
                                {
                                    snippetLedgerGetTable.InsertSnippet("LOADTABLESANDLISTS", snippetLoadTable);
                                }
                                else
                                {
                                    ServerTemplate.InsertSnippet("LOADTABLESANDLISTS", snippetLoadTable);
                                }

                                ProcessTemplate snippetSaveTable = ServerTemplate.GetSnippet("SAVETABLE");
                                snippetSaveTable.SetCodelet("ENUMNAME", enumName);
                                snippetSaveTable.SetCodelet("SUBMODULE", subModule.Name);
                                snippetSaveTable.SetCodelet("DATATABLENAME", enumElement.Name);

                                if (DependsOnLedger)
                                {
                                    snippetLedgerSaveTable.InsertSnippet("SAVETABLE", snippetSaveTable);
                                }
                                else
                                {
                                    ServerTemplate.InsertSnippet("SAVETABLE", snippetSaveTable);
                                }

                                ProcessTemplate snippetDataValidation = ServerTemplate.GetSnippet("DATAVALIDATION");
                                snippetDataValidation.SetCodelet("ENUMNAME", enumName);
                                snippetDataValidation.SetCodelet("DATATABLENAME", enumElement.Name);

                                if (DependsOnLedger)
                                {
                                    snippetLedgerSaveTable.InsertSnippet("DATAVALIDATION", snippetDataValidation);
                                }
                                else
                                {
                                    ServerTemplate.InsertSnippet("DATAVALIDATION", snippetDataValidation);
                                }
                            }
                            else
                            {
                                ProcessTemplate snippetLoadList = ServerTemplate.GetSnippet("LOADCALCULATEDLIST");

                                if (DependsOnLedger)
                                {
                                    snippetLoadList = ServerTemplate.GetSnippet("LOADCALCULATEDLISTFORLEDGER");
                                }

                                snippetLoadList.SetCodelet("ENUMNAME", enumName);
                                snippetLoadList.SetCodelet("CALCULATEDLISTNAME", enumName);

                                if (DependsOnLedger)
                                {
                                    snippetLedgerGetTable.InsertSnippet("LOADTABLESANDLISTS", snippetLoadList);
                                }
                                else
                                {
                                    ServerTemplate.InsertSnippet("LOADTABLESANDLISTS", snippetLoadList);
                                }

                                if (TYml2Xml.GetAttributeRecursive(enumElement, "IsStorableToDBTable") != String.Empty)
                                {
                                    ProcessTemplate snippetSaveTable = ServerTemplate.GetSnippet("SAVETABLE");
                                    snippetSaveTable.SetCodelet("ENUMNAME", enumName);
                                    snippetSaveTable.SetCodelet("SUBMODULE", subModule.Name);
                                    snippetSaveTable.SetCodelet("DATATABLENAME", TYml2Xml.GetAttributeRecursive(enumElement, "IsStorableToDBTable"));

                                    if (DependsOnLedger)
                                    {
                                        snippetLedgerSaveTable.InsertSnippet("SAVETABLE", snippetSaveTable);
                                    }
                                    else
                                    {
                                        ServerTemplate.InsertSnippet("SAVETABLE", snippetSaveTable);
                                    }

                                    ProcessTemplate snippetDataValidation = ServerTemplate.GetSnippet("DATAVALIDATION");
                                    snippetDataValidation.SetCodelet("ENUMNAME", enumName);
                                    snippetDataValidation.SetCodelet("DATATABLENAME",
                                                                     TYml2Xml.GetAttributeRecursive(enumElement, "IsStorableToDBTable"));

                                    if (DependsOnLedger)
                                    {
                                        snippetLedgerSaveTable.InsertSnippet("DATAVALIDATION", snippetDataValidation);
                                    }
                                    else
                                    {
                                        ServerTemplate.InsertSnippet("DATAVALIDATION", snippetDataValidation);
                                    }
                                }
                            }

                            enumElement = enumElement.NextSibling;

                            if (enumElement != null)
                            {
                                snippetSubmodule.AddToCodelet("ENUMELEMENTS", Environment.NewLine);
                            }
                        }

                        TableOrListElement = TableOrListElement.NextSibling;
                    }

                    SharedTemplate.InsertSnippet("ENUMS", snippetSubmodule);

                    if (snippetLedgerGetTable != null)
                    {
                        ServerTemplate.InsertSnippet("LEDGERGETCACHEABLE", snippetLedgerGetTable);
                    }

                    if (snippetLedgerSaveTable != null)
                    {
                        ServerTemplate.InsertSnippet("LEDGERSAVECACHEABLE", snippetLedgerSaveTable);
                    }

                    ServerTemplate.SetCodelet("USINGNAMESPACES", string.Empty);

                    foreach (string UsingNamespace in UsingNamespaces)
                    {
                        ServerTemplate.AddToCodelet("USINGNAMESPACES", "using " + UsingNamespace + ";" + Environment.NewLine);
                    }

                    string path = ASharedPath +
                                  Path.DirectorySeparatorChar + ".." +
                                  Path.DirectorySeparatorChar + "Server" +
                                  Path.DirectorySeparatorChar + "lib" +
                                  Path.DirectorySeparatorChar + "M" + module.Name +
                                  Path.DirectorySeparatorChar;

                    if (File.Exists(path + "Cacheable.ManualCode.cs"))
                    {
                        path += "Cacheable-generated.cs";
                    }
                    else
                    {
                        if (File.Exists(path + "data" + Path.DirectorySeparatorChar + subModule.Name + "." + "Cacheable.ManualCode.cs"))
                        {
                            path += "data" + Path.DirectorySeparatorChar + subModule.Name + "." + "Cacheable-generated.cs";
                        }
                        else if (File.Exists(path + "data" + Path.DirectorySeparatorChar + "Cacheable.ManualCode.cs"))
                        {
                            path += "data" + Path.DirectorySeparatorChar + "Cacheable-generated.cs";
                        }
                        else
                        {
                            path += subModule.Name + "." + "Cacheable-generated.cs";
                        }
                    }

                    ServerTemplate.FinishWriting(path, ".cs", true);

                    subModule = subModule.NextSibling;
                }

                SharedTemplate.FinishWriting(ASharedPath +
                                             Path.DirectorySeparatorChar + "M" + module.Name + ".Cacheable-generated.cs",
                                             ".cs", true);

                module = module.NextSibling;
            }
        }
        /// load transactions from a CSV file into the currently selected batch
        private void CreateBatchFromCSVFile(string ADataFilename,
                                            XmlNode ARootNode,
                                            AJournalRow ARefJournalRow,
                                            Int32 AFirstTransactionRow,
                                            string ADefaultCostCentre,
                                            out DateTime ALatestTransactionDate)
        {
            StreamReader dataFile = new StreamReader(ADataFilename, System.Text.Encoding.Default);

            XmlNode ColumnsNode        = TXMLParser.GetChild(ARootNode, "Columns");
            string  Separator          = TXMLParser.GetAttribute(ARootNode, "Separator");
            string  DateFormat         = TXMLParser.GetAttribute(ARootNode, "DateFormat");
            string  ThousandsSeparator = TXMLParser.GetAttribute(ARootNode, "ThousandsSeparator");
            string  DecimalSeparator   = TXMLParser.GetAttribute(ARootNode, "DecimalSeparator");
            Int32   lineCounter;

            // read headers
            for (lineCounter = 0; lineCounter < AFirstTransactionRow - 1; lineCounter++)
            {
                dataFile.ReadLine();
            }

            decimal sumDebits  = 0.0M;
            decimal sumCredits = 0.0M;

            ALatestTransactionDate = DateTime.MinValue;

            do
            {
                string line = dataFile.ReadLine();
                lineCounter++;

                GLBatchTDSATransactionRow NewTransaction = FMainDS.ATransaction.NewRowTyped(true);
                FMyForm.GetTransactionsControl().NewRowManual(ref NewTransaction, ARefJournalRow);
                FMainDS.ATransaction.Rows.Add(NewTransaction);

                foreach (XmlNode ColumnNode in ColumnsNode.ChildNodes)
                {
                    string Value = StringHelper.GetNextCSV(ref line, Separator);
                    string UseAs = TXMLParser.GetAttribute(ColumnNode, "UseAs");

                    if (UseAs.ToLower() == "reference")
                    {
                        NewTransaction.Reference = Value;
                    }
                    else if (UseAs.ToLower() == "narrative")
                    {
                        NewTransaction.Narrative = Value;
                    }
                    else if (UseAs.ToLower() == "dateeffective")
                    {
                        NewTransaction.SetTransactionDateNull();

                        if (Value.Trim().ToString().Length > 0)
                        {
                            try
                            {
                                NewTransaction.TransactionDate = XmlConvert.ToDateTime(Value, DateFormat);

                                if (NewTransaction.TransactionDate > ALatestTransactionDate)
                                {
                                    ALatestTransactionDate = NewTransaction.TransactionDate;
                                }
                            }
                            catch (Exception exp)
                            {
                                MessageBox.Show(Catalog.GetString("Problem with date in row " + lineCounter.ToString() + " Error: " + exp.Message));
                            }
                        }
                    }
                    else if (UseAs.ToLower() == "account")
                    {
                        if (Value.Length > 0)
                        {
                            if (Value.Contains(" "))
                            {
                                // cut off currency code; should have been defined in the data description file, for the whole batch
                                Value = Value.Substring(0, Value.IndexOf(" ") - 1);
                            }

                            Value = Value.Replace(ThousandsSeparator, "");
                            Value = Value.Replace(DecimalSeparator, ".");

                            NewTransaction.TransactionAmount    = Convert.ToDecimal(Value, System.Globalization.CultureInfo.InvariantCulture);
                            NewTransaction.CostCentreCode       = ADefaultCostCentre;
                            NewTransaction.AccountCode          = ColumnNode.Name;
                            NewTransaction.DebitCreditIndicator = true;

                            if (TXMLParser.HasAttribute(ColumnNode,
                                                        "CreditDebit") && (TXMLParser.GetAttribute(ColumnNode, "CreditDebit").ToLower() == "credit"))
                            {
                                NewTransaction.DebitCreditIndicator = false;
                            }

                            if (NewTransaction.TransactionAmount < 0)
                            {
                                NewTransaction.TransactionAmount   *= -1.0M;
                                NewTransaction.DebitCreditIndicator = !NewTransaction.DebitCreditIndicator;
                            }

                            if (TXMLParser.HasAttribute(ColumnNode, "AccountCode"))
                            {
                                NewTransaction.AccountCode = TXMLParser.GetAttribute(ColumnNode, "AccountCode");
                            }

                            if (NewTransaction.DebitCreditIndicator)
                            {
                                sumDebits += NewTransaction.TransactionAmount;
                            }
                            else if (!NewTransaction.DebitCreditIndicator)
                            {
                                sumCredits += NewTransaction.TransactionAmount;
                            }
                        }
                    }
                }

                if (!NewTransaction.IsTransactionDateNull())
                {
                    NewTransaction.AmountInBaseCurrency = GLRoutines.CurrencyMultiply(NewTransaction.TransactionAmount,
                                                                                      TExchangeRateCache.GetDailyExchangeRate(
                                                                                          ARefJournalRow.TransactionCurrency,
                                                                                          FMainDS.ALedger[0].BaseCurrency,
                                                                                          NewTransaction.TransactionDate,
                                                                                          false));
                    //
                    // The International currency calculation is changed to "Base -> International", because it's likely
                    // we won't have a "Transaction -> International" conversion rate defined.
                    //
                    NewTransaction.AmountInIntlCurrency = GLRoutines.CurrencyMultiply(NewTransaction.AmountInBaseCurrency,
                                                                                      TExchangeRateCache.GetDailyExchangeRate(
                                                                                          FMainDS.ALedger[0].BaseCurrency,
                                                                                          FMainDS.ALedger[0].IntlCurrency,
                                                                                          NewTransaction.TransactionDate,
                                                                                          false));
                }
            } while (!dataFile.EndOfStream);

            // create a balancing transaction; not sure if this is needed at all???
            if (Convert.ToDecimal(sumCredits - sumDebits) != 0)
            {
                GLBatchTDSATransactionRow BalancingTransaction = FMainDS.ATransaction.NewRowTyped(true);
                FMyForm.GetTransactionsControl().NewRowManual(ref BalancingTransaction, ARefJournalRow);
                FMainDS.ATransaction.Rows.Add(BalancingTransaction);

                BalancingTransaction.TransactionDate      = ALatestTransactionDate;
                BalancingTransaction.DebitCreditIndicator = true;
                BalancingTransaction.TransactionAmount    = sumCredits - sumDebits;

                if (BalancingTransaction.TransactionAmount < 0)
                {
                    BalancingTransaction.TransactionAmount   *= -1;
                    BalancingTransaction.DebitCreditIndicator = !BalancingTransaction.DebitCreditIndicator;
                }

                if (BalancingTransaction.DebitCreditIndicator)
                {
                    sumDebits += BalancingTransaction.TransactionAmount;
                }
                else
                {
                    sumCredits += BalancingTransaction.TransactionAmount;
                }

                BalancingTransaction.AmountInIntlCurrency = GLRoutines.CurrencyMultiply(BalancingTransaction.TransactionAmount,
                                                                                        TExchangeRateCache.GetDailyExchangeRate(
                                                                                            ARefJournalRow.TransactionCurrency,
                                                                                            FMainDS.ALedger[0].IntlCurrency,
                                                                                            BalancingTransaction.TransactionDate,
                                                                                            false));
                BalancingTransaction.AmountInBaseCurrency = GLRoutines.CurrencyMultiply(BalancingTransaction.TransactionAmount,
                                                                                        TExchangeRateCache.GetDailyExchangeRate(
                                                                                            ARefJournalRow.TransactionCurrency,
                                                                                            FMainDS.ALedger[0].BaseCurrency,
                                                                                            BalancingTransaction.TransactionDate,
                                                                                            false));
                BalancingTransaction.Narrative      = Catalog.GetString("Automatically generated balancing transaction");
                BalancingTransaction.CostCentreCode = TXMLParser.GetAttribute(ARootNode, "CashCostCentre");
                BalancingTransaction.AccountCode    = TXMLParser.GetAttribute(ARootNode, "CashAccount");
            }

            ARefJournalRow.JournalCreditTotal = sumCredits;
            ARefJournalRow.JournalDebitTotal  = sumDebits;
            ARefJournalRow.JournalDescription = Path.GetFileNameWithoutExtension(ADataFilename);

            ABatchRow RefBatch = (ABatchRow)FMainDS.ABatch.Rows[FMainDS.ABatch.Rows.Count - 1];

            RefBatch.BatchCreditTotal = sumCredits;
            RefBatch.BatchDebitTotal  = sumDebits;
            // todo RefBatch.BatchControlTotal = sumCredits  - sumDebits;
            // csv !
        }
Example #11
0
        /// <summary>
        /// code for generating typed datasets
        /// </summary>
        /// <param name="AInputXmlfile"></param>
        /// <param name="AOutputPath"></param>
        /// <param name="ANameSpace"></param>
        /// <param name="store"></param>
        /// <param name="groups"></param>
        /// <param name="AFilename"></param>
        public static void CreateTypedDataSets(String AInputXmlfile,
                                               String AOutputPath,
                                               String ANameSpace,
                                               TDataDefinitionStore store,
                                               string[] groups,
                                               string AFilename)
        {
            Console.WriteLine("processing dataset " + ANameSpace);

            string          templateDir = TAppSettingsManager.GetValue("TemplateDir", true);
            ProcessTemplate Template    = new ProcessTemplate(templateDir + Path.DirectorySeparatorChar +
                                                              "ORM" + Path.DirectorySeparatorChar +
                                                              "DataSet.cs");

            Template.AddSnippetsFromOtherFile(templateDir + Path.DirectorySeparatorChar +
                                              "ORM" + Path.DirectorySeparatorChar +
                                              "DataTable.cs");

            DataSetTableIdCounter = Convert.ToInt16(TAppSettingsManager.GetValue("StartTableId"));

            // load default header with license and copyright
            Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(templateDir));

            Template.SetCodelet("NAMESPACE", ANameSpace);

            // if no dataset is defined yet in the xml file, the following variables can be empty
            Template.AddToCodelet("USINGNAMESPACES", "");
            Template.AddToCodelet("CONTENTDATASETSANDTABLESANDROWS", "");

            TXMLParser  parserDataSet = new TXMLParser(AInputXmlfile, false);
            XmlDocument myDoc         = parserDataSet.GetDocument();
            XmlNode     startNode     = myDoc.DocumentElement;

            if (startNode.Name.ToLower() == "petradatasets")
            {
                XmlNode cur = TXMLParser.NextNotBlank(startNode.FirstChild);

                while ((cur != null) && (cur.Name.ToLower() == "importunit"))
                {
                    Template.AddToCodelet("USINGNAMESPACES", "using " + TXMLParser.GetAttribute(cur, "name") + ";" + Environment.NewLine);
                    cur = TXMLParser.GetNextEntity(cur);
                }

                while ((cur != null) && (cur.Name.ToLower() == "dataset"))
                {
                    ProcessTemplate snippetDataset = Template.GetSnippet("TYPEDDATASET");
                    string          datasetname    = TXMLParser.GetAttribute(cur, "name");
                    snippetDataset.SetCodelet("DATASETNAME", datasetname);

                    // INITCONSTRAINTS and INITRELATIONS can be empty
                    snippetDataset.AddToCodelet("INITCONSTRAINTS", "");
                    snippetDataset.AddToCodelet("INITRELATIONS", "");

                    SortedList <string, TDataSetTable> tables = new SortedList <string, TDataSetTable>();

                    XmlNode curChild = cur.FirstChild;

                    while (curChild != null)
                    {
                        if ((curChild.Name.ToLower() == "table") && TXMLParser.HasAttribute(curChild, "sqltable"))
                        {
                            bool   OverloadTable = false;
                            string tabletype     = TTable.NiceTableName(TXMLParser.GetAttribute(curChild, "sqltable"));
                            string variablename  = (TXMLParser.HasAttribute(curChild, "name") ?
                                                    TXMLParser.GetAttribute(curChild, "name") :
                                                    tabletype);

                            TDataSetTable table = new TDataSetTable(
                                TXMLParser.GetAttribute(curChild, "sqltable"),
                                tabletype,
                                variablename,
                                store.GetTable(tabletype));
                            XmlNode tableNodes = curChild.FirstChild;

                            while (tableNodes != null)
                            {
                                if (tableNodes.Name.ToLower() == "customfield")
                                {
                                    // eg. BestAddress in PartnerEditTDS.PPartnerLocation
                                    TTableField customField = new TTableField();
                                    customField.strName        = TXMLParser.GetAttribute(tableNodes, "name");
                                    customField.strTypeDotNet  = TXMLParser.GetAttribute(tableNodes, "type");
                                    customField.strDescription = TXMLParser.GetAttribute(tableNodes, "comment");
                                    customField.strDefault     = TXMLParser.GetAttribute(tableNodes, "initial");
                                    table.grpTableField.Add(customField);

                                    OverloadTable = true;
                                }

                                if (tableNodes.Name.ToLower() == "field")
                                {
                                    // eg. UnitName in PartnerEditTDS.PPerson
                                    TTableField field = new TTableField(store.GetTable(TXMLParser.GetAttribute(tableNodes, "sqltable")).
                                                                        GetField(TXMLParser.GetAttribute(tableNodes, "sqlfield")));

                                    if (TXMLParser.HasAttribute(tableNodes, "name"))
                                    {
                                        field.strNameDotNet = TXMLParser.GetAttribute(tableNodes, "name");
                                    }

                                    if (TXMLParser.HasAttribute(tableNodes, "comment"))
                                    {
                                        field.strDescription = TXMLParser.GetAttribute(tableNodes, "comment");
                                    }

                                    table.grpTableField.Add(field);

                                    OverloadTable = true;
                                }

                                if (tableNodes.Name.ToLower() == "primarykey")
                                {
                                    TConstraint primKeyConstraint = table.GetPrimaryKey();
                                    primKeyConstraint.strThisFields = StringHelper.StrSplit(TXMLParser.GetAttribute(tableNodes,
                                                                                                                    "thisFields"), ",");

                                    OverloadTable = true;
                                }

                                tableNodes = tableNodes.NextSibling;
                            }

                            if (OverloadTable)
                            {
                                tabletype = datasetname + TTable.NiceTableName(table.strName);

                                if (TXMLParser.HasAttribute(curChild, "name"))
                                {
                                    tabletype = datasetname + TXMLParser.GetAttribute(curChild, "name");
                                }

                                table.strDotNetName            = tabletype;
                                table.strVariableNameInDataset = variablename;

                                // set tableid
                                table.iOrder = DataSetTableIdCounter++;

                                // TODO: can we derive from the base table, and just overload a few functions?
                                CodeGenerationTable.InsertTableDefinition(snippetDataset, table, store.GetTable(table.tableorig), "TABLELOOP", true);
                                CodeGenerationTable.InsertRowDefinition(snippetDataset, table, store.GetTable(table.tableorig), "TABLELOOP");
                            }

                            tables.Add(variablename, table);

                            AddTableToDataset(tabletype, variablename,
                                              snippetDataset);
                        }
                        else if ((curChild.Name.ToLower() == "table") && TXMLParser.HasAttribute(curChild, "customtable"))
                        {
                            // this refers to a custom table of another dataset, eg. BestAddressTDSLocation
                            // for the moment, such a table cannot have additional fields
                            if (curChild.HasChildNodes)
                            {
                                throw new Exception(
                                          String.Format(
                                              "CreateTypedDataSets(): At the moment, a custom table referenced from another dataset cannot have additional fields. Dataset: {0}, Table: {1}",
                                              datasetname,
                                              TXMLParser.HasAttribute(curChild, "customtable")));
                            }

                            // customtable has to contain the name of the dataset, eg. BestAddressTDSLocation
                            string tabletype    = TXMLParser.GetAttribute(curChild, "customtable");
                            string variablename = (TXMLParser.HasAttribute(curChild, "name") ?
                                                   TXMLParser.GetAttribute(curChild, "name") :
                                                   tabletype);

                            AddTableToDataset(tabletype, variablename,
                                              snippetDataset);
                        }

                        if (curChild.Name.ToLower() == "customrelation")
                        {
                            ProcessTemplate tempSnippet = Template.GetSnippet("INITRELATIONS");
                            tempSnippet.SetCodelet("RELATIONNAME", TXMLParser.GetAttribute(curChild, "name"));
                            tempSnippet.SetCodelet("TABLEVARIABLENAMEPARENT", TXMLParser.GetAttribute(curChild, "parentTable"));
                            tempSnippet.SetCodelet("TABLEVARIABLENAMECHILD", TXMLParser.GetAttribute(curChild, "childTable"));
                            tempSnippet.SetCodelet("COLUMNNAMESPARENT",
                                                   StringCollectionToValuesFormattedForArray(tables, TXMLParser.GetAttribute(curChild, "parentTable"),
                                                                                             StringHelper.StrSplit(TXMLParser.GetAttribute(curChild, "parentFields"), ",")));
                            tempSnippet.SetCodelet("COLUMNNAMESCHILD",
                                                   StringCollectionToValuesFormattedForArray(tables, TXMLParser.GetAttribute(curChild, "childTable"),
                                                                                             StringHelper.StrSplit(TXMLParser.GetAttribute(curChild, "childFields"), ",")));
                            tempSnippet.SetCodelet("CREATECONSTRAINTS", TXMLParser.GetBoolAttribute(curChild, "createConstraints") ? "true" : "false");
                            snippetDataset.InsertSnippet("INITRELATIONS", tempSnippet);
                        }

                        if (curChild.Name.ToLower() == "customtable")
                        {
                            string variablename = TXMLParser.GetAttribute(curChild, "name");
                            string tabletype    = datasetname + TXMLParser.GetAttribute(curChild, "name");

                            XmlNode       customTableNodes = curChild.FirstChild;
                            TDataSetTable customTable      = new TDataSetTable(
                                tabletype,
                                tabletype,
                                variablename,
                                null);

                            // set TableId
                            customTable.iOrder                   = DataSetTableIdCounter++;
                            customTable.strDescription           = TXMLParser.GetAttribute(curChild, "comment");
                            customTable.strName                  = tabletype;
                            customTable.strDotNetName            = tabletype;
                            customTable.strVariableNameInDataset = variablename;

                            while (customTableNodes != null)
                            {
                                if (customTableNodes.Name.ToLower() == "customfield")
                                {
                                    TTableField customField = new TTableField();
                                    customField.strName        = TXMLParser.GetAttribute(customTableNodes, "name");
                                    customField.strTypeDotNet  = TXMLParser.GetAttribute(customTableNodes, "type");
                                    customField.strDescription = TXMLParser.GetAttribute(customTableNodes, "comment");
                                    customField.strDefault     = TXMLParser.GetAttribute(customTableNodes, "initial");
                                    customTable.grpTableField.Add(customField);
                                }

                                if (customTableNodes.Name.ToLower() == "field")
                                {
                                    // eg. SelectedSiteKey in PartnerEditTDS.MiscellaneousData
                                    TTableField field = new TTableField(store.GetTable(TXMLParser.GetAttribute(customTableNodes, "sqltable")).
                                                                        GetField(TXMLParser.GetAttribute(customTableNodes, "sqlfield")));

                                    if (TXMLParser.HasAttribute(customTableNodes, "name"))
                                    {
                                        field.strNameDotNet = TXMLParser.GetAttribute(customTableNodes, "name");
                                    }

                                    if (TXMLParser.HasAttribute(customTableNodes, "comment"))
                                    {
                                        field.strDescription = TXMLParser.GetAttribute(customTableNodes, "comment");
                                    }

                                    customTable.grpTableField.Add(field);
                                }

                                if (customTableNodes.Name.ToLower() == "primarykey")
                                {
                                    TConstraint primKeyConstraint = new TConstraint();
                                    primKeyConstraint.strName       = "PK";
                                    primKeyConstraint.strType       = "primarykey";
                                    primKeyConstraint.strThisFields = StringHelper.StrSplit(TXMLParser.GetAttribute(customTableNodes,
                                                                                                                    "thisFields"), ",");
                                    customTable.grpConstraint.Add(primKeyConstraint);
                                }

                                customTableNodes = customTableNodes.NextSibling;
                            }

                            tables.Add(tabletype, customTable);

                            AddTableToDataset(tabletype, variablename, snippetDataset);

                            CodeGenerationTable.InsertTableDefinition(snippetDataset, customTable, null, "TABLELOOP", true);
                            CodeGenerationTable.InsertRowDefinition(snippetDataset, customTable, null, "TABLELOOP");
                        }

                        curChild = curChild.NextSibling;
                    }

                    foreach (TDataSetTable table in tables.Values)
                    {
                        // todo? also other constraints, not only from original table?
                        foreach (TConstraint constraint in table.grpConstraint)
                        {
                            if ((constraint.strType == "foreignkey") && tables.ContainsKey(constraint.strOtherTable))
                            {
                                TDataSetTable otherTable = (TDataSetTable)tables[constraint.strOtherTable];

                                ProcessTemplate tempSnippet = Template.GetSnippet("INITCONSTRAINTS");

                                tempSnippet.SetCodelet("TABLEVARIABLENAME1", table.tablealias);
                                tempSnippet.SetCodelet("TABLEVARIABLENAME2", otherTable.tablealias);
                                tempSnippet.SetCodelet("CONSTRAINTNAME", TTable.NiceKeyName(constraint));

                                tempSnippet.SetCodelet("COLUMNNAMES1", StringCollectionToValuesFormattedForArray(constraint.strThisFields));
                                tempSnippet.SetCodelet("COLUMNNAMES2", StringCollectionToValuesFormattedForArray(constraint.strOtherFields));
                                snippetDataset.InsertSnippet("INITCONSTRAINTS", tempSnippet);
                            }
                        }
                    }

                    Template.InsertSnippet("CONTENTDATASETSANDTABLESANDROWS", snippetDataset);

                    cur = TXMLParser.GetNextEntity(cur);
                }
            }

            Template.FinishWriting(AOutputPath + Path.DirectorySeparatorChar + AFilename + "-generated.cs", ".cs", true);
        }
Example #12
0
        /// <summary>
        /// load the dataset tables
        /// </summary>
        public static SortedList <string, TTable> LoadDatasetTables(string AICTPath, string ADataSetTypeWithNamespace, TCodeStorage ACodeStorage,
                                                                    string APluginPath)
        {
            if (FDatasetTables == null)
            {
                FDatasetTables = new SortedList <string, SortedList <string, TTable> >();
            }

            FCodeStorage = ACodeStorage;

            if (!ADataSetTypeWithNamespace.StartsWith("Ict.Petra.Shared") && !ADataSetTypeWithNamespace.StartsWith("Ict.Petra.Plugins"))
            {
                throw new Exception("the DatasetType must contain the full namespace, starting with Ict.Petra.Shared or Ict.Petra.Plugins");
            }

            if (FDatasetTables.ContainsKey(ADataSetTypeWithNamespace))
            {
                FCurrentDataset = FDatasetTables[ADataSetTypeWithNamespace];

                return(FCurrentDataset);
            }

            string[] datasetTypeSplit = ADataSetTypeWithNamespace.Split(new char[] { '.' });
            string   module           = datasetTypeSplit[3];
            string   datasetName      = datasetTypeSplit[datasetTypeSplit.Length - 1];

            // find the correct xml file for the dataset.
            // look in Ict/Petra/Shared/lib/MODULE/data
            string dataPath = AICTPath + "/Petra/Shared/lib/" + module + "/data/";

            if (ADataSetTypeWithNamespace.StartsWith("Ict.Petra.Plugins"))
            {
                int    start      = "Ict.Petra.Plugins.".Length;
                int    end        = ADataSetTypeWithNamespace.IndexOf(".", start);
                string PluginName = ADataSetTypeWithNamespace.Substring(start, end - start);
                dataPath = AICTPath + "/Petra/Plugins/" + PluginName + "/data/";
            }

            DirectoryInfo directory = new DirectoryInfo(dataPath);

            FileInfo[] xmlFiles    = directory.GetFiles("*.xml");
            XmlNode    datasetNode = null;

            foreach (FileInfo fileinfo in xmlFiles)
            {
                if (datasetNode == null)
                {
                    TXMLParser parser = new TXMLParser(dataPath + "/" + fileinfo.Name, false);
                    datasetNode = parser.GetDocument().SelectSingleNode(String.Format("//DataSet[@name='{0}']", datasetName));
                }
            }

            if ((datasetNode == null) && File.Exists(APluginPath))
            {
                // also check the plugin directory of the yaml file, for plugins can have a file TypedDataSets.xml
                TXMLParser parser = new TXMLParser(APluginPath, false);
                datasetNode = parser.GetDocument().SelectSingleNode(String.Format("//DataSet[@name='{0}']", datasetName));
            }

            if (datasetNode == null)
            {
                throw new Exception("cannot find the xml file for dataset " + ADataSetTypeWithNamespace);
            }

            SortedList <string, TTable> result = new SortedList <string, TTable>();
            XmlNodeList tables = datasetNode.SelectNodes("Table|CustomTable");

            foreach (XmlNode tableNode in tables)
            {
                TTable table = new TTable();
                string tablename;

                if ((tableNode.Name == "Table") && TXMLParser.HasAttribute(tableNode, "sqltable"))
                {
                    tablename = TTable.NiceTableName(tableNode.Attributes["sqltable"].Value);
                    table.Assign(FPetraXMLStore.GetTable(tablename));

                    table.strVariableNameInDataset = TXMLParser.HasAttribute(tableNode, "name") ? tableNode.Attributes["name"].Value : tablename;

                    if ((tableNode.SelectNodes("CustomField").Count > 0) || (tableNode.SelectNodes("Field").Count > 0))
                    {
                        table.strDotNetName = datasetName + tablename;
                    }
                }
                else if ((tableNode.Name == "Table") && TXMLParser.HasAttribute(tableNode, "customtable"))
                {
                    table                          = new TTable();
                    tablename                      = tableNode.Attributes["customtable"].Value;
                    table.strName                  = tablename;
                    table.strDotNetName            = tablename;
                    table.strVariableNameInDataset = TXMLParser.HasAttribute(tableNode, "name") ? tableNode.Attributes["name"].Value : tablename;
                }
                else
                {
                    table                          = new TTable();
                    tablename                      = tableNode.Attributes["name"].Value;
                    table.strName                  = tablename;
                    table.strDotNetName            = datasetName + tablename;
                    table.strVariableNameInDataset = tablename;
                }

                // add the custom fields if there are any
                XmlNodeList customFields = tableNode.SelectNodes("CustomField");

                foreach (XmlNode customField in customFields)
                {
                    TTableField newField = new TTableField();
                    newField.strName        = customField.Attributes["name"].Value;
                    newField.strNameDotNet  = newField.strName;
                    newField.strType        = customField.Attributes["type"].Value;
                    newField.strTypeDotNet  = customField.Attributes["type"].Value;
                    newField.strTableName   = tablename;
                    newField.strDescription = "";
                    newField.bNotNull       =
                        TXMLParser.HasAttribute(customField, "notnull") && TXMLParser.GetAttribute(customField, "notnull").ToLower() == "true";
                    table.grpTableField.Add(newField);
                }

                // add other fields from other tables that are defined in petra.xml
                XmlNodeList otherFields = tableNode.SelectNodes("Field");

                foreach (XmlNode otherField in otherFields)
                {
                    TTable      otherTable = FPetraXMLStore.GetTable(otherField.Attributes["sqltable"].Value);
                    TTableField newField   = new TTableField(otherTable.GetField(otherField.Attributes["sqlfield"].Value));

                    if (TXMLParser.HasAttribute(otherField, "name"))
                    {
                        newField.strNameDotNet = otherField.Attributes["name"].Value;
                    }

                    newField.strTableName = tablename;
                    table.grpTableField.Add(newField);
                }

                result.Add(table.strVariableNameInDataset, table);
            }

            FDatasetTables.Add(ADataSetTypeWithNamespace, result);
            FCurrentDataset = result;
            return(result);
        }
Example #13
0
        /// <summary>
        /// Create new partner, family, location and PartnerLocation records in MainDS
        /// </summary>
        private static Int64 CreateNewFamily(XmlNode ANode, out int ALocationKey, ref PartnerImportExportTDS AMainDS)
        {
            PPartnerRow newPartner = AMainDS.PPartner.NewRowTyped();

            AMainDS.PPartner.Rows.Add(newPartner);

            newPartner.PartnerKey   = (AMainDS.PPartner.Rows.Count + 1) * -1;
            newPartner.PartnerClass = MPartnerConstants.PARTNERCLASS_FAMILY;
            newPartner.StatusCode   = MPartnerConstants.PARTNERSTATUS_ACTIVE;
            newPartner.Comment      = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_NOTESFAMILY);

            String AcquisitionCode = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_AQUISITION);

            newPartner.AcquisitionCode = (AcquisitionCode.Length > 0) ? AcquisitionCode : MPartnerConstants.PARTNERIMPORT_AQUISITION_DEFAULT;

            newPartner.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_DEFAULT;

            if (TXMLParser.HasAttribute(ANode, MPartnerConstants.PARTNERIMPORT_ADDRESSEE_TYPE))
            {
                newPartner.AddresseeTypeCode = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_ADDRESSEE_TYPE);
            }
            else
            {
                string gender = GetGenderCode(ANode);

                if (gender == MPartnerConstants.GENDER_MALE)
                {
                    newPartner.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_MALE;
                }
                else if (gender == MPartnerConstants.GENDER_FEMALE)
                {
                    newPartner.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_FEMALE;
                }
            }

            if (TXMLParser.HasAttribute(ANode, MPartnerConstants.PARTNERIMPORT_LANGUAGE))
            {
                newPartner.LanguageCode = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_LANGUAGE);
            }
            else if (TUserDefaults.HasDefault(MSysManConstants.PARTNER_LANGUAGECODE))
            {
                newPartner.LanguageCode = TUserDefaults.GetStringDefault(MSysManConstants.PARTNER_LANGUAGECODE);
            }

            string[] giftReceiptingDefaults = TSystemDefaults.GetSystemDefault("GiftReceiptingDefaults", ",no").Split(new char[] { ',' });
            newPartner.ReceiptLetterFrequency = giftReceiptingDefaults[0];
            newPartner.ReceiptEachGift        = giftReceiptingDefaults[1] == "YES" || giftReceiptingDefaults[1] == "TRUE";


            PFamilyRow newFamily = AMainDS.PFamily.NewRowTyped();

            AMainDS.PFamily.Rows.Add(newFamily);

            newFamily.PartnerKey    = newPartner.PartnerKey;
            newFamily.FirstName     = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_FIRSTNAME);
            newFamily.FamilyName    = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_FAMILYNAME);
            newFamily.MaritalStatus = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_MARITALSTATUS);
            newFamily.Title         = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_TITLE);
            newFamily.MaritalStatus = GetMaritalStatusCode(ANode);

            newPartner.PartnerShortName = Calculations.DeterminePartnerShortName(newFamily.FamilyName, newFamily.Title, newFamily.FirstName);
            PLocationRow newLocation = AMainDS.PLocation.NewRowTyped(true);

            AMainDS.PLocation.Rows.Add(newLocation);
            newLocation.LocationKey = TPartnerImportCSV.FLocationKey;
            newLocation.Locality    = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_LOCALITY);
            newLocation.StreetName  = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_STREETNAME);
            newLocation.Address3    = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_ADDRESS);
            newLocation.PostalCode  = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_POSTALCODE);
            newLocation.City        = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_CITY);
            newLocation.County      = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_COUNTY);
            newLocation.CountryCode = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_COUNTRYCODE);

            PPartnerLocationRow partnerlocation = AMainDS.PPartnerLocation.NewRowTyped(true);

            partnerlocation.LocationKey     = TPartnerImportCSV.FLocationKey;
            partnerlocation.SiteKey         = 0;
            partnerlocation.PartnerKey      = newPartner.PartnerKey;
            partnerlocation.DateEffective   = DateTime.Now;
            partnerlocation.LocationType    = MPartnerConstants.LOCATIONTYPE_HOME;
            partnerlocation.SendMail        = true;
            partnerlocation.EmailAddress    = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_EMAIL);
            partnerlocation.TelephoneNumber = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_PHONE);
            partnerlocation.MobileNumber    = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_MOBILEPHONE);
            AMainDS.PPartnerLocation.Rows.Add(partnerlocation);

            ALocationKey = TPartnerImportCSV.FLocationKey;
            TPartnerImportCSV.FLocationKey--;
            return(newPartner.PartnerKey);
        }
Example #14
0
        /// <summary>
        /// main function for generating access methods for typed data sets
        /// </summary>
        /// <param name="AInputXmlfile"></param>
        /// <param name="AOutputPath"></param>
        /// <param name="ANameSpace"></param>
        /// <param name="store"></param>
        /// <param name="groups"></param>
        /// <param name="AFilename"></param>
        public static void CreateTypedDataSets(String AInputXmlfile,
                                               String AOutputPath,
                                               String ANameSpace,
                                               TDataDefinitionStore store,
                                               string[] groups,
                                               string AFilename)
        {
            Console.WriteLine("processing dataset " + ANameSpace);

            string          templateDir = TAppSettingsManager.GetValue("TemplateDir", true);
            ProcessTemplate Template    = new ProcessTemplate(templateDir + Path.DirectorySeparatorChar +
                                                              "ORM" + Path.DirectorySeparatorChar +
                                                              "DataSetAccess.cs");

            // load default header with license and copyright
            Template.SetCodelet("GPLFILEHEADER", ProcessTemplate.LoadEmptyFileComment(templateDir));

            Template.SetCodelet("NAMESPACE", ANameSpace);

            // if no dataset is defined yet in the xml file, the following variables can be empty
            Template.AddToCodelet("USINGNAMESPACES", "");
            Template.AddToCodelet("CONTENTDATASETSANDTABLESANDROWS", "");

            Template.AddToCodelet("USINGNAMESPACES", "using " + ANameSpace.Replace(".Server.", ".Shared.") + ";" + Environment.NewLine, false);

            TXMLParser  parserDataSet = new TXMLParser(AInputXmlfile, false);
            XmlDocument myDoc         = parserDataSet.GetDocument();
            XmlNode     startNode     = myDoc.DocumentElement;

            if (startNode.Name.ToLower() == "petradatasets")
            {
                XmlNode cur = TXMLParser.NextNotBlank(startNode.FirstChild);

                while ((cur != null) && (cur.Name.ToLower() == "importunit"))
                {
                    Template.AddToCodelet("USINGNAMESPACES", "using " + TXMLParser.GetAttribute(cur, "name") + ";" + Environment.NewLine, false);
                    Template.AddToCodelet("USINGNAMESPACES", "using " + TXMLParser.GetAttribute(cur, "name").Replace(".Shared.",
                                                                                                                     ".Server.") + ".Access;" + Environment.NewLine, false);
                    cur = TXMLParser.GetNextEntity(cur);
                }

                while ((cur != null) && (cur.Name.ToLower() == "dataset"))
                {
                    ProcessTemplate snippetDataset = Template.GetSnippet("TYPEDDATASET");
                    string          datasetname    = TXMLParser.GetAttribute(cur, "name");
                    snippetDataset.SetCodelet("DATASETNAME", datasetname);

                    ProcessTemplate snippetSubmitChanges = snippetDataset.GetSnippet("SUBMITCHANGESFUNCTION");
                    snippetSubmitChanges.AddToCodelet("DATASETNAME", datasetname);

                    List <TDataSetTable> tables = new List <TDataSetTable>();

                    XmlNode curChild = cur.FirstChild;

                    // first collect the tables
                    while (curChild != null)
                    {
                        if (curChild.Name.ToLower() == "table")
                        {
                            string tabletype    = TTable.NiceTableName(TXMLParser.GetAttribute(curChild, "sqltable"));
                            string variablename = (TXMLParser.HasAttribute(curChild, "name") ?
                                                   TXMLParser.GetAttribute(curChild, "name") :
                                                   tabletype);

                            TDataSetTable table = new TDataSetTable(
                                TXMLParser.GetAttribute(curChild, "sqltable"),
                                tabletype,
                                variablename,
                                store.GetTable(tabletype));

                            tables.Add(table);
                        }

                        curChild = curChild.NextSibling;
                    }

                    foreach (TDataSetTable table in tables)
                    {
                        AddTableToDataset(tables,
                                          store.GetTable(table.tableorig),
                                          table.tablename,
                                          table.tablealias,
                                          snippetDataset,
                                          snippetSubmitChanges);
                    }

                    // there is one codelet for the dataset name.
                    // only add the full submitchanges function if there are any table to submit
                    if (snippetSubmitChanges.FCodelets.Count > 1)
                    {
                        snippetDataset.InsertSnippet("SUBMITCHANGESFUNCTION", snippetSubmitChanges);
                    }
                    else
                    {
                        snippetDataset.AddToCodelet("SUBMITCHANGESFUNCTION", "");
                    }

                    Template.InsertSnippet("CONTENTDATASETSANDTABLESANDROWS", snippetDataset);

                    cur = TXMLParser.GetNextEntity(cur);
                }
            }

            Template.FinishWriting(AOutputPath + Path.DirectorySeparatorChar + AFilename + "-generated.cs", ".cs", true);
        }