Click here to Skip to main content
12,292,562 members (68,147 online)
Click here to Skip to main content

Stats

77.8K views
3.3K downloads
154 bookmarked
Posted

Equation Calculator with Graphing

, 25 Nov 2010 CPOL
Equation Calculator with Graphing
CommonUtils
bin
Debug
CommonUtils.dll
Color
Equation
GraphicalCanvas
Properties
Themes
Calculator
Calculator
bin
Debug
Calculator.exe
Calculator.vshost.exe
Calculator.vshost.exe.manifest
CommonUtils.dll
Graphing
Properties
Calculator.suo
CommonUtils.dll
Calculator.exe
Calculator.vshost.exe
Calculator.vshost.exe.manifest
CommonUtils.dll
Calculator.suo
Calculator.application
Calculator.exe
Calculator.exe.manifest
Calculator.vshost.application
Calculator.vshost.exe
Calculator.vshost.exe.manifest
CommonUtils.dll
Calculator.csproj.user
Calculator.csproj.vspscc
MSSCCPRJ.SCC
Calculator.suo
Calculator.vssscc
MSSCCPRJ.SCC
CommonUtils.dll
CommonUtils.csproj.vspscc
MSSCCPRJ.SCC
Release
CommonUtils.csproj.vspscc
MSSCCPRJ.SCC
Calculator.application
Calculator.exe
Calculator.exe.manifest
Calculator.vshost.application
Calculator.vshost.exe
Calculator.vshost.exe.manifest
CommonUtils.dll
Calculator.csproj.user
Calculator.csproj.vspscc
MSSCCPRJ.SCC
Calculator.suo
Calculator.vssscc
MSSCCPRJ.SCC
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CommonUtils;
using System.Xml;
using System.Reflection;
using System.IO;

namespace Calculator
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		public CalcConfig Config {get; set;}
		string m_cfgFilename = string.Empty;

		string CfgFilename
		{
			get 
			{ 
				if (m_cfgFilename.Length > 0)
					return m_cfgFilename;
				string product = string.Empty;
				object[] attrs = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(System.Reflection.AssemblyProductAttribute), true);
				if (attrs.Length > 0)
					product = ((System.Reflection.AssemblyProductAttribute)attrs[0]).Product;
				string dir = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), product);
                try
                {
                    if (System.IO.Directory.Exists(dir) == false)
                        System.IO.Directory.CreateDirectory(dir);
                }
                catch (Exception error)
                {
                    Console.WriteLine("error creating path {0}. Error: {1}", dir, error.Message);
                }
				m_cfgFilename = System.IO.Path.Combine(dir, "mycfg.xml");
				return m_cfgFilename;
			}
				
		}
		public MainWindow()
		{
			InitializeComponent();
			EquationUnitTest unit = new EquationUnitTest();
			unit.UnitTest();

			Config = new CalcConfig();
			if (System.IO.File.Exists(CfgFilename))
			{
				try
				{
					XmlDocument doc = new XmlDocument();
					doc.Load(CfgFilename);
					XmlElement root = doc["calcRoot"];
					Config.Read(root);
				}
				catch { }
			}
			m_calculatorCtrl.Config = Config;
			m_graphCtrl.Config = Config;
		}
		protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
		{
			XmlTextWriter wr = new XmlTextWriter(CfgFilename, Encoding.Default);
			wr.Formatting = Formatting.Indented;
			wr.WriteStartElement("calcRoot");
			Config.Write(wr);
			wr.WriteEndElement();
			wr.Close();
			base.OnClosing(e);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

jkristia
Software Developer (Senior)
United States United States
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160518.1 | Last Updated 25 Nov 2010
Article Copyright 2010 by jkristia
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid