Example #1
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);
        }
        /// <summary>add GeneratedReadSetControls</summary>
        public override void ApplyDerivedFunctionality(TFormWriter writer, TControlDef control)
        {
            string paramName = ReportControls.GetParameterName(control.xmlNode);

            if (paramName == null)
            {
                return;
            }

            StringCollection optionalValues =
                TYml2Xml.GetElements(TXMLParser.GetChild(control.xmlNode, "OptionalValues"));

            foreach (string rbtValueText in optionalValues)
            {
                string rbtValue = StringHelper.UpperCamelCase(rbtValueText.Replace("'", "").Replace(" ", "_"), false, false);
                string rbtName  = "rbt" + rbtValue;
                writer.Template.AddToCodelet("READCONTROLS",
                                             "if (" + rbtName + ".Checked) " + Environment.NewLine +
                                             "{" + Environment.NewLine +
                                             "  ACalc.AddParameter(\"" + paramName + "\", \"" + rbtValue + "\");" + Environment.NewLine +
                                             "}" + Environment.NewLine);
                writer.Template.AddToCodelet("SETCONTROLS",
                                             rbtName + ".Checked = " +
                                             "AParameters.Get(\"" + paramName + "\").ToString() == \"" + rbtValue + "\";" +
                                             Environment.NewLine);
            }
        }
Example #3
0
        /// <summary>
        /// get the definition of the control, if it has not been loaded yet from yaml then do it now
        /// </summary>
        /// <param name="AControlName"></param>
        /// <param name="AParentName"></param>
        /// <returns></returns>
        public TControlDef FindOrCreateControl(string AControlName, string AParentName)
        {
            TControlDef result = GetControl(AControlName);

            if (result != null)
            {
                // or should we throw an exception?
                return(result);
            }

            if (AControlName == "pnlEmpty")
            {
                int countEmpty = 1;

                foreach (string name in FControlList.Keys)
                {
                    if (name.StartsWith("pnlEmpty"))
                    {
                        countEmpty++;
                    }
                }

                AControlName += countEmpty.ToString();
            }

            XmlNode collectionNode = GetCorrectCollection(AControlName, AParentName);

            XmlElement newNode = FXmlDocument.CreateElement(AControlName);

            collectionNode.AppendChild(newNode);
            FXmlNodes.Add(AControlName, newNode);
            result            = new TControlDef(newNode, this);
            result.parentName = AParentName;
            FControlList.Add(AControlName, result);
            FSortedControlList.Add(FSortedControlList.Count, result);
            TControlDef parentCtrl = GetControl(AParentName);

            if ((parentCtrl != null) && !AControlName.StartsWith("pnlEmpty"))
            {
                XmlNode parentNode = parentCtrl.xmlNode;
                XmlNode controls   = TXMLParser.GetChild(parentNode, "Controls");

                if (controls == null)
                {
                    controls = FXmlDocument.CreateElement("Controls");
                    parentNode.AppendChild(controls);
                }

                XmlNode      element = FXmlDocument.CreateElement(TYml2Xml.XMLLIST);
                XmlAttribute attr    = FXmlDocument.CreateAttribute("name");
                attr.Value = AControlName;
                element.Attributes.Append(attr);
                controls.AppendChild(element);
            }

            return(result);
        }
        /// <summary>check if the generator fits the given control by checking the prefix and perhaps some of the attributes</summary>
        public override bool ControlFitsNode(XmlNode curNode)
        {
            if (base.ControlFitsNode(curNode))
            {
                return(TXMLParser.GetChild(curNode, "Controls") != null);
            }

            return(false);
        }
Example #5
0
        /// <summary>check if the generator fits the given control by checking the prefix and perhaps some of the attributes</summary>
        public override bool ControlFitsNode(XmlNode curNode)
        {
            if (base.ControlFitsNode(curNode))
            {
                if (TXMLParser.GetChild(curNode, "OptionalValues") != null)
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>check if the generator fits the given control by checking the prefix and perhaps some of the attributes</summary>
        public override bool ControlFitsNode(XmlNode curNode)
        {
            if (base.ControlFitsNode(curNode))
            {
                if (TXMLParser.GetChild(curNode, "OptionalValues") != null)
                {
                    return(!TYml2Xml.HasAttribute(curNode, "BorderVisible") ||
                           TYml2Xml.GetAttribute(curNode, "BorderVisible").ToLower() != "false");
                }
            }

            return(false);
        }
Example #7
0
        public static bool ValidateIBAN(string AIban, out string ABic, out string ABankName,
                                        out TVerificationResultCollection AVerificationResult)
        {
            AVerificationResult = new TVerificationResultCollection();
            ABic      = String.Empty;
            ABankName = String.Empty;

            if ((AIban == null) || (AIban.Trim() == String.Empty))
            {
                AVerificationResult.Add(new TVerificationResult("error", "The IBAN is invalid", "",
                                                                "MaintainPartners.ErrInvalidIBAN", TResultSeverity.Resv_Critical));
                return(false);
            }

            string IBANCheckURL = TAppSettingsManager.GetValue("IBANCheck.Url", "https://kontocheck.solidcharity.com/?iban=");
            string url          = IBANCheckURL + AIban.Replace(" ", "");
            string result       = THTTPUtils.ReadWebsite(url);

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.LoadXml(result);

                XmlNode IbanCheck = TXMLParser.GetChild(doc.DocumentElement, "iban");
                if (IbanCheck.InnerText == "0")
                {
                    AVerificationResult.Add(new TVerificationResult("error", "The IBAN is invalid", "",
                                                                    "MaintainPartners.ErrInvalidIBAN", TResultSeverity.Resv_Critical));
                    return(false);
                }

                XmlNode BankName = TXMLParser.GetChild(doc.DocumentElement, "bankname");
                XmlNode City     = TXMLParser.GetChild(doc.DocumentElement, "city");
                ABankName = BankName.InnerText + ", " + City.InnerText;
                XmlNode BIC = TXMLParser.GetChild(doc.DocumentElement, "bic");
                ABic = BIC.InnerText;
            }
            catch (Exception)
            {
                TLogging.Log("Error validating IBAN: " + AIban.Replace(" ", ""));
                AVerificationResult.Add(new TVerificationResult("error", "The IBAN is invalid", "",
                                                                "MaintainPartners.ErrInvalidIBAN", TResultSeverity.Resv_Critical));
                return(false);
            }

            return(true);
        }
Example #8
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);
        }
        /// <summary>check if the generator fits the given control by checking the prefix and some of the attributes</summary>
        public override bool ControlFitsNode(XmlNode curNode)
        {
            if (SimplePrefixMatch(curNode))
            {
                if (TYml2Xml.HasAttribute(curNode, "Label"))
                {
                    base.FGenerateLabel = true;
                }

                if (TXMLParser.GetChild(curNode, "Controls") == null)
                {
                    return(TYml2Xml.HasAttribute(curNode, "BorderVisible") &&
                           TYml2Xml.GetAttribute(curNode, "BorderVisible").ToLower() == "false");
                }
            }

            return(false);
        }
Example #10
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);

            string valuesArray = "[";

            List <XmlNode> optionalValues =
                TYml2Xml.GetChildren(TXMLParser.GetChild(ctrl.xmlNode, "OptionalValues"), true);

            // DefaultValue with = sign before control name
            for (int counter = 0; counter < optionalValues.Count; counter++)
            {
                string loopValue = TYml2Xml.GetElementName(optionalValues[counter]);

                if (loopValue.StartsWith("="))
                {
                    loopValue = loopValue.Substring(1).Trim();
                    ctrlSnippet.SetCodelet("VALUE", loopValue);
                }

                if (counter > 0)
                {
                    valuesArray += ", ";
                }

                ((TExtJsFormsWriter)writer).AddResourceString(ctrlSnippet, "OPTION" + counter.ToString(), ctrl, loopValue);

                string strName = "this." + ctrl.controlName + "OPTION" + counter.ToString();

                valuesArray += "['" + loopValue + "', " + strName + "]";
            }

            valuesArray += "]";

            ctrlSnippet.SetCodelet("OPTIONALVALUESARRAY", valuesArray);

            if (ctrl.HasAttribute("width"))
            {
                ctrlSnippet.SetCodelet("WIDTH", ctrl.GetAttribute("width"));
            }

            return(ctrlSnippet);
        }
        /// <summary>
        /// get the radio buttons
        /// </summary>
        public override void ProcessChildren(TFormWriter writer, TControlDef ctrl)
        {
            StringCollection Controls =
                TYml2Xml.GetElements(TXMLParser.GetChild(ctrl.xmlNode, "Controls"));
            string DefaultValue = Controls[0];

            if (TYml2Xml.HasAttribute(ctrl.xmlNode, "DefaultValue"))
            {
                DefaultValue = TYml2Xml.GetAttribute(ctrl.xmlNode, "DefaultValue");
            }

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

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

            base.ProcessChildren(writer, ctrl);
        }
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="properties"></param>
        public EncryptionClientSinkProvider(IDictionary properties)
        {
            // do not use property, but create local symmetric key, and send to the server, encrypted with the public key of the server
            try
            {
                XmlDocument doc = new XmlDocument();

                // get the public key from the server, from a secure site. if the SSL certificate is self signed or not valid, this will fail.
                // publicKeyXml will contain: <RSAKeyValue><Modulus>w7/g+...+sU=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>
                if (properties["HttpsPublicKeyXml"] != null)
                {
                    string publicKeyXml = THTTPUtils.ReadWebsite((string)properties["HttpsPublicKeyXml"]);
                    doc.LoadXml(publicKeyXml);
                }
                else
                {
                    string publicKeyXml = (string)properties["FilePublicKeyXml"];
                    doc.Load(publicKeyXml);
                }

                try
                {
                    FPublicKeyServer          = new RSAParameters();
                    FPublicKeyServer.Modulus  = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "Modulus").InnerText);
                    FPublicKeyServer.Exponent = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "Exponent").InnerText);
                }
                catch
                {
                    throw new Exception("Invalid public key XML file, cannot find Modulus or Exponent");
                }
            }
            catch (Exception)
            {
                TLogging.Log("Cannot get the public key of the OpenPetra server");
                throw;
            }
        }
        private void Init()
        {
            string KeyFile = TAppSettingsManager.GetValue("Server.ChannelEncryption.PrivateKeyfile");

            // read the encryption key from the specified file
            FileInfo fi = new FileInfo(KeyFile);

            if (!fi.Exists)
            {
                throw new RemotingException(
                          String.Format("Specified keyfile {0} does not exist", KeyFile));
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(KeyFile);

            FPrivateKey = new RSAParameters();

            try
            {
                FPrivateKey.D        = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "D").InnerText);
                FPrivateKey.P        = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "P").InnerText);
                FPrivateKey.Q        = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "Q").InnerText);
                FPrivateKey.DP       = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "DP").InnerText);
                FPrivateKey.DQ       = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "DQ").InnerText);
                FPrivateKey.InverseQ = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "InverseQ").InnerText);
                FPrivateKey.Modulus  = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "Modulus").InnerText);
                FPrivateKey.Exponent = Convert.FromBase64String(TXMLParser.GetChild(doc.FirstChild, "Exponent").InnerText);
            }
            catch (Exception)
            {
                throw new RemotingException(
                          String.Format("Problems reading the keyfile {0}. Cannot find all attributes of the key.", KeyFile));
            }
        }
Example #14
0
        private static void ProcessRadioGroupLabels(XmlNode node)
        {
            StringCollection optionalValues =
                TYml2Xml.GetElements(TXMLParser.GetChild(node, "OptionalValues"));

            node.RemoveAll();
            XmlNode OptionalValuesLabel = node.OwnerDocument.CreateElement("LabelsForOptionalValues");

            node.AppendChild(OptionalValuesLabel);

            foreach (string s in optionalValues)
            {
                string label = s;

                if (label.StartsWith("="))
                {
                    label = label.Substring(1).Trim();
                }

                XmlNode LabelNode = node.OwnerDocument.CreateElement(TYml2Xml.XMLLIST);
                OptionalValuesLabel.AppendChild(LabelNode);
                TXMLParser.SetAttribute(LabelNode, "name", Catalog.GetString(label));
            }
        }
Example #15
0
        /// <summary>
        /// main function for creating a control
        /// </summary>
        /// <param name="ACtrl"></param>
        /// <param name="ATemplate"></param>
        /// <param name="AItemsPlaceholder"></param>
        /// <param name="ANodeName"></param>
        /// <param name="AWriter"></param>
        public static void InsertControl(TControlDef ACtrl,
                                         ProcessTemplate ATemplate,
                                         string AItemsPlaceholder,
                                         string ANodeName,
                                         TFormWriter AWriter)
        {
            XmlNode controlsNode = TXMLParser.GetChild(ACtrl.xmlNode, ANodeName);

            List <XmlNode> childNodes = TYml2Xml.GetChildren(controlsNode, true);

            if ((childNodes.Count > 0) && childNodes[0].Name.StartsWith("Row"))
            {
                foreach (XmlNode row in TYml2Xml.GetChildren(controlsNode, true))
                {
                    ProcessTemplate snippetRowDefinition = AWriter.FTemplate.GetSnippet("ROWDEFINITION");

                    StringCollection children = TYml2Xml.GetElements(controlsNode, row.Name);

                    foreach (string child in children)
                    {
                        TControlDef       childCtrl             = AWriter.FCodeStorage.FindOrCreateControl(child, ACtrl.controlName);
                        IControlGenerator ctrlGen               = AWriter.FindControlGenerator(childCtrl);
                        ProcessTemplate   ctrlSnippet           = ctrlGen.SetControlProperties(AWriter, childCtrl);
                        ProcessTemplate   snippetCellDefinition = AWriter.FTemplate.GetSnippet("CELLDEFINITION");

                        LayoutCellInForm(childCtrl, children.Count, ctrlSnippet, snippetCellDefinition);

                        if ((children.Count == 1) && ctrlGen is RadioGroupSimpleGenerator)
                        {
                            // do not use the ROWDEFINITION, but insert control directly
                            // this helps with aligning the label for the group radio buttons
                            snippetRowDefinition.InsertSnippet("ITEMS", ctrlSnippet, ",");
                        }
                        else
                        {
                            snippetCellDefinition.InsertSnippet("ITEM", ctrlSnippet);
                            snippetRowDefinition.InsertSnippet("ITEMS", snippetCellDefinition, ",");
                        }
                    }

                    ATemplate.InsertSnippet(AItemsPlaceholder, snippetRowDefinition, ",");
                }
            }
            else
            {
                foreach (XmlNode childNode in childNodes)
                {
                    string      child     = TYml2Xml.GetElementName(childNode);
                    TControlDef childCtrl = AWriter.FCodeStorage.FindOrCreateControl(child, ACtrl.controlName);

                    if ((ANodeName != "HiddenValues") && (childCtrl.controlTypePrefix == "hid"))
                    {
                        // somehow, hidden values get into the controls list as well. we don't want them there
                        continue;
                    }

                    IControlGenerator ctrlGen = AWriter.FindControlGenerator(childCtrl);

                    if (ctrlGen is FieldSetGenerator)
                    {
                        InsertControl(AWriter.FCodeStorage.FindOrCreateControl(child,
                                                                               ACtrl.controlName), ATemplate, AItemsPlaceholder, ANodeName, AWriter);
                    }
                    else
                    {
                        ProcessTemplate ctrlSnippet           = ctrlGen.SetControlProperties(AWriter, childCtrl);
                        ProcessTemplate snippetCellDefinition = AWriter.FTemplate.GetSnippet("CELLDEFINITION");

                        LayoutCellInForm(childCtrl, -1, ctrlSnippet, snippetCellDefinition);

                        ATemplate.InsertSnippet(AItemsPlaceholder, ctrlSnippet, ",");
                    }
                }
            }
        }
        /// 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 #17
0
        private static void AdjustLabel(XmlNode node, TCodeStorage CodeStorage, XmlDocument AOrigLocalisedYaml)
        {
            XmlNode TranslatedNode  = TXMLParser.FindNodeRecursive(AOrigLocalisedYaml, node.Name);
            string  TranslatedLabel = string.Empty;

            if (TranslatedNode != null)
            {
                TranslatedLabel = TXMLParser.GetAttribute(TranslatedNode, "Label");
            }

            TControlDef ctrlDef = new TControlDef(node, CodeStorage);
            string      Label   = ctrlDef.Label;

            if ((ctrlDef.GetAttribute("NoLabel") == "true") || (ctrlDef.controlTypePrefix == "pnl") ||
                (TXMLParser.FindNodeRecursive(node.OwnerDocument, "act" + ctrlDef.controlName.Substring(ctrlDef.controlTypePrefix.Length)) != null) ||
                ctrlDef.GetAttribute("Action").StartsWith("act"))
            {
                Label = string.Empty;
            }

            if ((ctrlDef.controlTypePrefix == "rgr") && (TXMLParser.GetChild(node, "OptionalValues") != null))
            {
                ProcessRadioGroupLabels(node);
            }
            else if (ctrlDef.controlTypePrefix == "mni")
            {
                // drop all attributes
                node.Attributes.RemoveAll();

                foreach (XmlNode menu in node.ChildNodes)
                {
                    if (menu.Name.Contains("Separator"))
                    {
                        continue;
                    }

                    AdjustLabel(menu, CodeStorage, AOrigLocalisedYaml);
                }
            }
            else
            {
                // drop all attributes and children nodes
                node.RemoveAll();
            }

            if (Label.Length > 0)
            {
                if ((TranslatedLabel != Label) && (TranslatedLabel != Catalog.GetString(Label)) && (TranslatedLabel.Length > 0))
                {
                    // add to po file
                    if (!NewTranslations.ContainsKey(Label))
                    {
                        NewTranslations.Add(Label, TranslatedLabel);
                    }

                    TXMLParser.SetAttribute(node, "Label", TranslatedLabel);
                }
                else
                {
                    TXMLParser.SetAttribute(node, "Label", Catalog.GetString(Label));
                }
            }
        }
Example #18
0
        /// <summary>add GeneratedReadSetControls, and all dependent controls</summary>
        public override void ApplyDerivedFunctionality(TFormWriter writer, TControlDef control)
        {
            string paramName = ReportControls.GetParameterName(control.xmlNode);

            if (paramName == null)
            {
                return;
            }

            StringCollection Controls =
                TYml2Xml.GetElements(TXMLParser.GetChild(control.xmlNode, "Controls"));

            foreach (string controlName in Controls)
            {
                TControlDef rbtCtrl  = writer.CodeStorage.GetControl(controlName);
                string      rbtValue = rbtCtrl.Label;
                rbtValue = StringHelper.UpperCamelCase(rbtValue.Replace("'", "").Replace(" ", "_"), false, false);

                if (rbtCtrl.HasAttribute("ParameterValue"))
                {
                    rbtValue = rbtCtrl.GetAttribute("ParameterValue");
                }

                string rbtName = "rbt" + controlName.Substring(3);

                if (controlName.StartsWith("layoutPanel"))
                {
                    // the table layouts of sub controls for each radio button need to be skipped
                    continue;
                }

                ProcessTemplate RadioButtonReadControlsSnippet = writer.Template.GetSnippet("RADIOBUTTONREADCONTROLS");
                RadioButtonReadControlsSnippet.SetCodelet("RBTNAME", rbtName);
                RadioButtonReadControlsSnippet.SetCodelet("PARAMNAME", paramName);
                RadioButtonReadControlsSnippet.SetCodelet("RBTVALUE", rbtValue);
                RadioButtonReadControlsSnippet.SetCodelet("READCONTROLS", "");

                XmlNode childControls = TXMLParser.GetChild(rbtCtrl.xmlNode, "Controls");

                // only assign variables that make sense
                if (childControls != null)
                {
                    StringCollection childControlNames = TYml2Xml.GetElements(childControls);

                    foreach (string childName in childControlNames)
                    {
                        if (childName.StartsWith("layoutPanel"))
                        {
                            continue;
                        }

                        TControlDef       childCtrl = writer.CodeStorage.GetControl(childName);
                        IControlGenerator generator = writer.FindControlGenerator(childCtrl);

                        // make sure we ignore Button etc
                        if (generator.GetType().ToString().EndsWith("ReportGenerator"))
                        {
                            childCtrl.SetAttribute("DependsOnRadioButton", "");
                            ReportControls.GenerateReadSetControls(writer,
                                                                   childCtrl.xmlNode,
                                                                   RadioButtonReadControlsSnippet,
                                                                   generator.TemplateSnippetName);
                            childCtrl.SetAttribute("DependsOnRadioButton", "true");
                        }
                    }
                }

                writer.Template.InsertSnippet("READCONTROLS", RadioButtonReadControlsSnippet);

                ProcessTemplate RadioButtonSetControlsSnippet = writer.Template.GetSnippet("RADIOBUTTONSETCONTROLS");
                RadioButtonSetControlsSnippet.SetCodelet("RBTNAME", rbtName);
                RadioButtonSetControlsSnippet.SetCodelet("PARAMNAME", paramName);
                RadioButtonSetControlsSnippet.SetCodelet("RBTVALUE", rbtValue);

                // only assign variables that make sense
                if (childControls != null)
                {
                    StringCollection childControlNames = TYml2Xml.GetElements(childControls);

                    foreach (string childName in childControlNames)
                    {
                        if (childName.StartsWith("layoutPanel"))
                        {
                            continue;
                        }

                        TControlDef       childCtrl = writer.CodeStorage.GetControl(childName);
                        IControlGenerator generator = writer.FindControlGenerator(childCtrl);

                        // make sure we ignore Button etc
                        if (generator.GetType().ToString().EndsWith("ReportGenerator"))
                        {
                            childCtrl.SetAttribute("DependsOnRadioButton", "");
                            ReportControls.GenerateReadSetControls(writer,
                                                                   childCtrl.xmlNode,
                                                                   RadioButtonSetControlsSnippet,
                                                                   generator.TemplateSnippetName);
                            childCtrl.SetAttribute("DependsOnRadioButton", "true");
                        }
                    }
                }

                writer.Template.InsertSnippet("SETCONTROLS", RadioButtonSetControlsSnippet);
            }
        }
        /// <summary>
        /// get the radio buttons
        /// </summary>
        public override void ProcessChildren(TFormWriter writer, TControlDef ctrl)
        {
            StringCollection optionalValues =
                TYml2Xml.GetElements(TXMLParser.GetChild(ctrl.xmlNode, "OptionalValues"));
            string DefaultValue;

            if ((TYml2Xml.HasAttribute(ctrl.xmlNode, "NoDefaultValue") &&
                 ((TYml2Xml.GetAttribute(ctrl.xmlNode, "NoDefaultValue")) == "true")))
            {
                DefaultValue    = String.Empty;
                FNoDefaultValue = true;
            }
            else
            {
                DefaultValue = optionalValues[0];
            }

            if (TYml2Xml.HasAttribute(ctrl.xmlNode, "DefaultValue"))
            {
                DefaultValue = TYml2Xml.GetAttribute(ctrl.xmlNode, "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];
                    }
                }
            }

            StringCollection optionalValuesLabels =
                TYml2Xml.GetElements(TYml2Xml.GetChild(ctrl.xmlNode, "LabelsForOptionalValues"));
            StringCollection optionalValuesConstants =
                TYml2Xml.GetElements(TYml2Xml.GetChild(ctrl.xmlNode, "OptionalValuesConstants"));

            // add the radiobuttons on the fly
            int count = 0;

            foreach (string optionalValue in optionalValues)
            {
                string radioButtonName = "rbt" +
                                         StringHelper.UpperCamelCase(optionalValue.Replace("'", "").Replace(" ",
                                                                                                            "_").Replace("&",
                                                                                                                         ""), false, false);
                TControlDef newCtrl = writer.CodeStorage.FindOrCreateControl(radioButtonName, ctrl.controlName);
                newCtrl.Label = optionalValuesLabels.Count > 0 ? optionalValuesLabels[count] : optionalValue;

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

                if (TYml2Xml.HasAttribute(ctrl.xmlNode, "SuppressChangeDetection"))
                {
                    newCtrl.SetAttribute("SuppressChangeDetection", TYml2Xml.GetAttribute(ctrl.xmlNode, "SuppressChangeDetection"));
                }

                if (TYml2Xml.HasAttribute(ctrl.xmlNode, "OnChange"))
                {
                    newCtrl.SetAttribute("OnChange", TYml2Xml.GetAttribute(ctrl.xmlNode, "OnChange"));
                }

                if (optionalValuesConstants.Count > count)
                {
                    newCtrl.SetAttribute("ConstantValue", optionalValuesConstants[count]);
                }

                ctrl.Children.Add(newCtrl);
                count++;
            }

            base.ProcessChildren(writer, ctrl);
        }
Example #20
0
        /// <summary>
        /// this function should be used for any collection of controls: on a TabPage, in a table, in a groupbox, radio button list etc.
        /// </summary>
        /// <returns>the layout control that still needs to be added to the parent</returns>
        public void CreateLayout(TFormWriter writer, TControlDef parentContainer, TControlDef layoutPanel, Int32 ANewWidth, Int32 ANewHeight)
        {
            if (layoutPanel == null)
            {
                layoutPanel = parentContainer;
            }

            // first check if the table layout has already been defined in the container with sets of rows?
            XmlNode containerNode = parentContainer.xmlNode;
            XmlNode controlsNode  = TXMLParser.GetChild(containerNode, "Controls");

            if (controlsNode != null)
            {
                FTabOrder = TYml2Xml.GetAttribute(controlsNode, "TabOrder");
            }

            List <XmlNode> childNodes = TYml2Xml.GetChildren(controlsNode, true);

            if ((childNodes.Count > 0) && TYml2Xml.GetElementName(childNodes[0]).StartsWith("Row"))
            {
                // create a layout using the defined rows in Controls
                // create TableLayoutPanel that has as many columns (including the labels) and rows as needed
                FOrientation   = eOrientation.TableLayout;
                FCurrentRow    = 0;
                FCurrentColumn = 0;
                FColumnCount   = 2;

                // determine maximum number of columns
                foreach (XmlNode row in TYml2Xml.GetChildren(controlsNode, true))
                {
                    // one other column for the label; will be cleaned up in WriteTableLayout
                    int columnCount = 2 * TYml2Xml.GetElements(row).Count;

                    if (columnCount > FColumnCount)
                    {
                        FColumnCount = columnCount;
                    }
                }

                FRowCount = TYml2Xml.GetChildren(controlsNode, true).Count;

                InitTableLayoutGrid();

                foreach (TControlDef childctrl in parentContainer.Children)
                {
                    childctrl.parentName = layoutPanel.controlName;
                }
            }
            else
            {
                // create TableLayoutPanel that has a column for the labels and as many rows as needed
                FCurrentRow    = 0;
                FCurrentColumn = 0;

                if (FOrientation == eOrientation.Vertical)
                {
                    FColumnCount = 2;
                    FRowCount    = parentContainer.Children.Count;
                }
                else if (FOrientation == eOrientation.Horizontal)
                {
                    // horizontal: label and control, all controls in one row
                    FColumnCount = parentContainer.Children.Count * 2;
                    FRowCount    = 1;
                }

                InitTableLayoutGrid();

                foreach (TControlDef childControl in parentContainer.Children)
                {
                    childControl.parentName = layoutPanel.controlName;
                }
            }

            #region Custom Column Widths and custom Row Heights

            /*
             * Record custom Column Widths, if specified.
             */
            XmlNode colWidthsNode = TXMLParser.GetChild(containerNode, "ColWidths");

            StringCollection ColWidths = TYml2Xml.GetElements(colWidthsNode);

            if (ColWidths.Count > 0)
            {
                FColWidths = new Dictionary <int, string>();

                foreach (string colWidth in ColWidths)
                {
//                    Console.WriteLine(containerNode.Name + ".colWidth: " + colWidth + "    " + String.Format("FColWidths: {0}  /   {1})",
//                            colWidth.Substring(0, colWidth.IndexOf('=')),
//                            colWidth.Substring(colWidth.IndexOf('=') + 1)));

                    FColWidths.Add(Convert.ToInt32(colWidth.Substring(0, colWidth.IndexOf('='))),
                                   colWidth.Substring(colWidth.IndexOf('=') + 1));
                }
            }

            /*
             * Record custom Row Heights, if specified.
             */
            XmlNode colHeightsNode = TXMLParser.GetChild(containerNode, "RowHeights");

            StringCollection RowHeights = TYml2Xml.GetElements(colHeightsNode);

            if (RowHeights.Count > 0)
            {
                FRowHeights = new Dictionary <int, string>();

                foreach (string rowHeight in RowHeights)
                {
//                    Console.WriteLine(containerNode.Name + ".rowHeight: " + rowHeight + "    " + String.Format("FRowHeights: {0}  /   {1})",
//                            rowHeight.Substring(0, rowHeight.IndexOf('=')),
//                            rowHeight.Substring(rowHeight.IndexOf('=') + 1)));

                    FRowHeights.Add(Convert.ToInt32(rowHeight.Substring(0, rowHeight.IndexOf('='))),
                                    rowHeight.Substring(rowHeight.IndexOf('=') + 1));
                }
            }

            #endregion
        }
Example #21
0
        /// <summary>
        /// create the code
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="ctrl"></param>
        public void InsertControl(TFormWriter writer, TControlDef ctrl)
        {
            IControlGenerator ctrlGenerator = writer.FindControlGenerator(ctrl);

            string controlName = ctrl.controlName;

            if (FOrientation == eOrientation.TableLayout)
            {
                if (FCurrentRow != ctrl.rowNumber)
                {
                    FCurrentColumn = 0;
                    FCurrentRow    = ctrl.rowNumber;
                }
            }

/* this does not work yet; creates endless loop/recursion
 *          if (ctrl.HasAttribute("LabelUnit"))
 *          {
 *              // we need another label after the control
 *              LabelGenerator lblGenerator = new LabelGenerator();
 *              string lblName = lblGenerator.CalculateName(controlName) + "Unit";
 *              TControlDef unitLabel = writer.CodeStorage.FindOrCreateControl(lblName, controlName);
 *              unitLabel.Label = ctrl.GetAttribute("LabelUnit");
 *
 *              TableLayoutPanelGenerator TlpGenerator = new TableLayoutPanelGenerator();
 *              ctrl.SetAttribute("ControlsOrientation", "horizontal");
 *              TlpGenerator.SetOrientation(ctrl);
 *              StringCollection childControls = new StringCollection();
 *              childControls.Add(controlName);
 *              childControls.Add(lblName);
 *              string subTlpControlName = TlpGenerator.CreateLayout(writer, FTlpName, childControls);
 *
 *              TlpGenerator.CreateCode(writer, ctrl);
 *              TlpGenerator.CreateCode(writer, unitLabel);
 *
 *              if (FOrientation == eOrientation.Vertical)
 *              {
 *                  AddControl(writer, FTlpName, subTlpControlName, 1, FCurrentRow);
 *              }
 *              else
 *              {
 *                  AddControl(writer, FTlpName, subTlpControlName, FCurrentColumn * 2 + 1, 0);
 *              }
 *          }
 *          else
 */
            if (ctrl.HasAttribute("GenerateWithOtherControls"))
            {
                // add the checkbox/radiobutton first
                if (FOrientation == eOrientation.Vertical)
                {
                    AddControl(ctrl, 0, FCurrentRow);
                }
                else if (FOrientation == eOrientation.Horizontal)
                {
                    AddControl(ctrl, FCurrentColumn * 2, 0);
                }
                else if (FOrientation == eOrientation.TableLayout)
                {
                    AddControl(ctrl, FCurrentColumn, FCurrentRow);
                }

                StringCollection childControls = TYml2Xml.GetElements(TXMLParser.GetChild(ctrl.xmlNode, "Controls"));

                if (childControls.Count > 1)
                {
                    // we need another tablelayout to arrange all the controls
                    PanelLayoutGenerator TlpGenerator = new PanelLayoutGenerator();
                    TlpGenerator.SetOrientation(ctrl);

                    Int32 NewHeight = -1;
                    Int32 NewWidth  = -1;

                    if (ctrl.HasAttribute("Height"))
                    {
                        NewHeight = Convert.ToInt32(ctrl.GetAttribute("Height"));
                        ctrl.ClearAttribute("Height");
                    }

                    if (ctrl.HasAttribute("Width"))
                    {
                        NewWidth = Convert.ToInt32(ctrl.GetAttribute("Width"));
                        ctrl.ClearAttribute("Width");
                    }

                    TControlDef subTlpControl = TlpGenerator.CreateNewPanel(writer, ctrl);
                    TlpGenerator.CreateLayout(writer, ctrl, subTlpControl, NewWidth, NewHeight);

                    foreach (string ChildControlName in childControls)
                    {
                        TControlDef ChildControl = ctrl.FCodeStorage.GetControl(ChildControlName);
                        TlpGenerator.InsertControl(writer, ChildControl);
                    }

                    TlpGenerator.WriteTableLayout(writer, subTlpControl);

                    if (FOrientation == eOrientation.Vertical)
                    {
                        AddControl(subTlpControl, 1, FCurrentRow);
                    }
                    else if (FOrientation == eOrientation.Horizontal)
                    {
                        AddControl(subTlpControl, FCurrentColumn * 2 + 1, 0);
                    }
                    else if (FOrientation == eOrientation.TableLayout)
                    {
                        AddControl(subTlpControl, FCurrentColumn + 1, FCurrentRow);
                    }
                }
                else if (childControls.Count == 1)
                {
                    // we don't need to add another table layout for just one other control
                    TControlDef       ChildCtrl      = ctrl.FCodeStorage.GetControl(childControls[0]);
                    IControlGenerator ChildGenerator = writer.FindControlGenerator(ChildCtrl);
                    ChildGenerator.GenerateControl(writer, ChildCtrl);

                    if (FOrientation == eOrientation.Vertical)
                    {
                        AddControl(ChildCtrl, 1, FCurrentRow);
                    }
                    else if (FOrientation == eOrientation.Horizontal)
                    {
                        AddControl(ChildCtrl, FCurrentColumn * 2 + 1, 0);
                    }
                    else if (FOrientation == eOrientation.TableLayout)
                    {
                        AddControl(ChildCtrl, FCurrentColumn + 1, FCurrentRow);
                    }
                }
            }
            else if (ctrl.controlName.StartsWith("pnlEmpty"))
            {
                // don't do anything here!
            }
            else if (ctrlGenerator.GenerateLabel(ctrl))
            {
                // add label
                LabelGenerator lblGenerator = new LabelGenerator();
                string         lblName      = lblGenerator.CalculateName(controlName);
                TControlDef    newLabel     = writer.CodeStorage.FindOrCreateControl(lblName, ctrl.controlName);
                newLabel.Label = ctrl.Label;

                if (ctrl.HasAttribute("LabelWidth"))
                {
                    newLabel.SetAttribute("Width", ctrl.GetAttribute("LabelWidth"));
                }

                if (ctrl.HasAttribute("LabelUnit"))
                {
                    // alternative implementation above does not work: add another label control after the input control
                    newLabel.Label = newLabel.Label + " (in " + ctrl.GetAttribute("LabelUnit") + ")";
                }

                lblGenerator.GenerateDeclaration(writer, newLabel);
                lblGenerator.RightAlign = true;
                lblGenerator.SetControlProperties(writer, newLabel);

                AddControl(newLabel,
                           FCurrentColumn * 2,
                           FCurrentRow);
                AddControl(ctrl,
                           FCurrentColumn * 2 + 1,
                           FCurrentRow);
            }
            else
            {
                AddControl(ctrl,
                           FCurrentColumn * 2,
                           FCurrentRow);
            }

            if (FOrientation == eOrientation.Vertical)
            {
                FCurrentRow++;
                FCurrentColumn = 0;
            }
            else if (FOrientation == eOrientation.Horizontal)
            {
                FCurrentColumn++;
            }
            else if (FOrientation == eOrientation.TableLayout)
            {
                FCurrentColumn += ctrl.colSpan;
            }
        }