Ejemplo n.º 1
0
 public static void DeleteClient(Client client)
 {
     var ctx = new RepGenDataContext();
     ctx.Clients.Attach(client);
     ctx.Clients.DeleteOnSubmit(client);
     ctx.SubmitChanges();
 }
Ejemplo n.º 2
0
        public ReportGenerator(Client client)
        {
            // get values from web.config
            // template
            NameValueCollection appSettings = (NameValueCollection)ConfigurationManager.GetSection("appSettings");
            string templateFile = appSettings["TemplateFile"];
            TemplateFile = HttpContext.Current.Server.MapPath(sourceDir + "templates\\" + templateFile);
            //content file
            string contentFile = appSettings["ContentFile"];
            ContentXmlFile = HttpContext.Current.Server.MapPath(sourceDir + contentFile);
            //temp directory
            string tempDir = appSettings["TempDir"];

            if (tempDir != null && Directory.Exists(tempDir))
                TempDir = tempDir;
            else
                TempDir = Environment.GetEnvironmentVariable("temp");

            // source files
            TempContentXmlFile = tempDir + "\\content_temp.xml";
            ReportSpecFile = HttpContext.Current.Server.MapPath(sourceDir + "report-spec.xml");

            // directly fill Content Controls?
            FillContentControls = Boolean.Parse(appSettings["FillContentControls"] ?? "true");

            Client = client;
            Report = new Report(ReportSpecFile) { Client = Client };
        }
Ejemplo n.º 3
0
        public void GenerateTextContent(MainDocumentPart mainPart, Client client, string contentFile)
        {
            GetContent(client, contentFile);
            string customXml = File.ReadAllText(destinationXml);
            replaceCustomXML(mainPart, customXml);
            mainPart.Document.Save();

            //Delete the temp files
            //File.Delete(tempFile);
            //File.Delete(destinationXml);
        }
Ejemplo n.º 4
0
        protected void GetContent(Client client, string sourceXml)
        {
            // get content from database
            string assets = (client.ExistingAssets ? "existing-assets" : "no-existing-assets");
            var ctx = new RepGenDataContext();
            var contents = ctx.Contents;
            var match = from c in contents
                        where (c.StrategyID.Equals(client.StrategyID) || c.StrategyID.Equals(null)) &&
                          (c.Category.Equals(assets) || c.Category.Equals(null))
                        select c;
            var content = match.ToList();

            // create temp content file
            createTempXmlFile(sourceXml, destinationXml);

            XmlDocument doc = new XmlDocument();
            doc.Load(destinationXml);

            // Create an XmlNamespaceManager to resolve the default namespace.
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
            nsmgr.AddNamespace("wmr", @"http://rmtenon.com/2010/wealth-management-report");

            XmlNode xmlnode;
            XmlElement root = doc.DocumentElement;

            // Client
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:client", nsmgr);

            XmlAttribute xmlattr;

            // existing-assets?
            xmlattr = doc.CreateAttribute("existing-assets");
            xmlattr.Value = client.ExistingAssets ? "true" : "false";
            xmlnode.Attributes.Append(xmlattr);

            // client.name
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:client/wmr:name", nsmgr);
            xmlnode.InnerText = client.Name;

            // client.meeting-date
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:client/wmr:meeting-date", nsmgr);
            xmlnode.InnerText = client.DateIssued.ToString("dd MMMM yyyy");

            // client.time-horizon
            int clientHorizon = client.TimeHorizon;
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:client/wmr:time-horizon", nsmgr);
            xmlnode.InnerText = Enum.GetName(typeof(TimeHorizon), clientHorizon);

            // client.reporting-frequency
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:client/wmr:reporting-frequency", nsmgr);
            xmlnode.InnerText = client.ReportingFrequency;

            // Strategy
            // get strategy object
            Strategy strategy = client.Strategy;

            // Strategy properties
            // strategy.name-lower
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:name-lower", nsmgr);
            xmlnode.InnerText = strategy.Name.ToLower(); ;

            // strategy.name-proper
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:name-proper", nsmgr);
            xmlnode.InnerText = strategy.Name; ;

            // strategy.performance.return-over-base
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:performance/wmr:return-over-base", nsmgr);
            xmlnode.InnerText = ((double)strategy.ReturnOverBase / 100).ToString("0%");

            // strategy.time-horizon
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:time-horizon", nsmgr);
            xmlnode.InnerText = Enum.GetName(typeof(TimeHorizon), strategy.TimeHorizon);

            // strategy.performance.rolling-return
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:performance/wmr:rolling-return", nsmgr);
            xmlnode.InnerText = (strategy.RollingReturn / 100).ToString("0.0%");

            // strategy.cost
            //xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:cost", nsmgr);
            //xmlnode.InnerText = strategy.Cost.ToString("£#,##0");

            // Look up
            // strategy.aim
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:aim", nsmgr);
            xmlnode.InnerText = content.Single(c => c.ContentID == "strategy.aim").Text;

            // strategy.asset-classes
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:asset-classes", nsmgr);
            xmlnode.InnerText = content.Single(c => c.ContentID == "strategy.asset-classes").Text;

            // strategy.investor-focus
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:investor-focus", nsmgr);
            xmlnode.InnerText = content.Single(c => c.ContentID == "strategy.investor-focus").Text;

            // strategy.comparison-chart-header
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:charts/wmr:comparison/wmr:header", nsmgr);
            xmlnode.InnerText = content.Single(c => c.ContentID == "strategy.comparison-chart-header").Text;

            // strategy.income-note1
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:income-note1", nsmgr);
            xmlnode.InnerText = content.Single(c => c.ContentID == "strategy.income-note1").Text;

            // strategy.income-note2
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:income-note2", nsmgr);
            xmlnode.InnerText = content.Single(c => c.ContentID == "strategy.income-note2").Text;

            // Cash or Assets
            string allocationHeader;
            string allocationCaption;
            string weightingText = null;
            string stressCrashHeader = null;
            string stressCrashText = null;
            string stressRiseText = null;

            if (client.ExistingAssets) {
                allocationHeader = content.Single(c => c.ContentID == "charts.allocation.header").Text;
                allocationCaption = content.Single(c => c.ContentID == "charts.allocation.caption").Text;
                weightingText = content.Single(c => c.ContentID == "charts.allocation.weighting-text").Text;
                stressCrashHeader = content.Single(c => c.ContentID == "charts.stress-crash.header").Text;
                stressCrashText = String.Format(
            content.Single(c => c.ContentID == "charts.stress-crash.text" && c.StrategyID == strategy.ID).Text, strategy.Name);
                // TODO: add to text database
                stressRiseText = content.Single(c => c.ContentID == "charts.stress-rise.text").Text;
            } else {
                allocationHeader = String.Format(content.Single(c => c.ContentID == "charts.allocation.header").Text, strategy.Name);
                allocationCaption = String.Format(content.Single(c => c.ContentID == "charts.allocation.caption").Text, strategy.Name);
            }

            // charts.allocation.header [BOTH]
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:charts/wmr:allocation/wmr:header", nsmgr);
            xmlnode.InnerText = allocationHeader;

            // charts.allocation.caption [BOTH]
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:charts/wmr:allocation/wmr:caption", nsmgr);
            xmlnode.InnerText = allocationCaption;

            // charts.allocation.weighting-text [ASSETS]
            if (weightingText != null) {
                xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:charts/wmr:allocation/wmr:weighting-text", nsmgr);
                xmlnode.InnerText = weightingText;
            }

            // charts.stress-crash.header [ASSETS]
            if (stressCrashHeader != null) {
                xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:charts/wmr:stress-crash/wmr:header", nsmgr);
                xmlnode.InnerText = stressCrashHeader;
            }

            // charts.stress-crash.text [ASSETS]
            if (stressCrashText != null) {
                xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:charts/wmr:stress-crash/wmr:text", nsmgr);
                xmlnode.InnerText = stressCrashText;
            }

            // charts.stress-rise.text [ASSETS]
            if (stressRiseText != null) {
                xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:charts/wmr:stress-rise/wmr:text", nsmgr);
                xmlnode.InnerText = stressRiseText;
            }

            // charts.drawdown.text
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:charts/wmr:drawdown/wmr:text", nsmgr);
            xmlnode.InnerText = content.Single(c => c.ContentID == "charts.drawdown.text").Text;

            // Calculation
            // strategy.performance.return
            double modelReturn = calculateModelReturn(client.Strategy);
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:performance/wmr:return", nsmgr);
            xmlnode.InnerText = modelReturn.ToString("0.0%");

            doc.Save(destinationXml);
        }
Ejemplo n.º 5
0
 public void UpdateClient(Client client)
 {
     var ctx = new RepGenDataContext();
     ctx.Clients.Attach(client, true);
     ctx.SubmitChanges();
 }
Ejemplo n.º 6
0
 public static void UpdateClient(Client client, Client original_client)
 {
     var ctx = new RepGenDataContext();
     ctx.Clients.Attach(client, original_client);
     ctx.SubmitChanges();
 }
Ejemplo n.º 7
0
        public static Guid InsertClient(Client client)
        {
            var ctx = new RepGenDataContext();
            ctx.Clients.InsertOnSubmit(client);
            ctx.SubmitChanges();

            return client.GUID;
        }
Ejemplo n.º 8
0
        protected void GetContent(Client client, string sourceXml, Stream outputXml, List<Content> contents)
        {
            string category = (client.ExistingAssets ? "existing-assets" : "no-existing-assets");

            XmlDocument doc = new XmlDocument();
            outputXml.Position = 0;
            doc.Load(outputXml);

            // Create an XmlNamespaceManager to resolve the default namespace.
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
            nsmgr.AddNamespace("wmr", @"http://rmstenon.com/2010/wealth-management-report");

            XmlNode xmlnode;
            XmlElement root = doc.DocumentElement;

            // Client
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:client", nsmgr);

            XmlAttribute xmlattr;

            // existing-assets?
            xmlattr = doc.CreateAttribute("existing-assets");
            xmlattr.Value = client.ExistingAssets ? "true" : "false";
            xmlnode.Attributes.Append(xmlattr);

            // client.name
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:client/wmr:name", nsmgr);
            xmlnode.InnerText = client.Name;

            // client.date-issued
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:client/wmr:date-issued", nsmgr);
            xmlnode.InnerText = client.DateIssued.ToString(dateFormat);

            // client.time-horizon
            int clientHorizon = client.TimeHorizon;
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:client/wmr:time-horizon", nsmgr);
            xmlnode.InnerText = Enum.GetName(typeof(TimeHorizon), clientHorizon);

            // client.reporting-frequency
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:client/wmr:reporting-frequency", nsmgr);
            xmlnode.InnerText = client.ReportingFrequency;

            // Strategy
            // get strategy object
            Strategy strategy = client.Strategy;

            // Strategy properties
            // strategy.name-lower
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:name-lower", nsmgr);
            xmlnode.InnerText = strategy.Name.ToLower();

            // strategy.name-proper
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:name-proper", nsmgr);
            xmlnode.InnerText = strategy.Name;

            // strategy.performance.return-over-base
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:performance/wmr:return-over-base", nsmgr);
            xmlnode.InnerText = strategy.ReturnOverBase.ToString("0\\%");

            // strategy.time-horizon
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:time-horizon", nsmgr);
            xmlnode.InnerText = Enum.GetName(typeof(TimeHorizon), strategy.TimeHorizon);

            // strategy.performance.rolling-return
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:performance/wmr:rolling-return", nsmgr);
            xmlnode.InnerText = strategy.RollingReturn.ToString("0.0\\%");

            // strategy.aggregate-charge
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:aggregate-charge", nsmgr);
            xmlnode.InnerText = strategy.AggregateCharge.ToString("0.00\\%");

            // strategy.cost
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:cost", nsmgr);
            decimal cost = Model.GetModelCost(strategy.ID, Client.HighNetWorth);
            xmlnode.InnerText = cost.ToString("C0");

            // Look up in tblContent
            foreach (var item in contents) {
                setTextNode(root, nsmgr, item);
            }

            // Calculation
            // strategy.performance.return
            double modelReturn = Report.CalculateModelReturn();
            xmlnode = root.SelectSingleNode("/wmr:repgen/wmr:strategy/wmr:performance/wmr:return", nsmgr);
            xmlnode.InnerText = modelReturn.ToString("0.0%");

            // write file
            outputXml.Position = 0;
            StreamWriter sw = new StreamWriter(outputXml, Encoding.UTF8);

            doc.Save(sw);
            outputXml.Position = 0;
        }