⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 一个pocketPC 程序
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.IO;

namespace SmartWKN
{
	/// <summary>
	/// Zusammenfassung f黵 Form1.
	/// </summary>
	public class frmMain : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TabControl tabMain;
		private System.Windows.Forms.TabPage tabInfo;
		private System.Windows.Forms.TabPage tabSettings;
		private System.Windows.Forms.VScrollBar scrollInfo;
		private System.Windows.Forms.Panel panelWork;
		private System.Windows.Forms.ListView lsvData;
		private System.Windows.Forms.Panel panelData;
		private System.Windows.Forms.Label lblData;
		private System.Windows.Forms.Panel panelGraph;
		private System.Windows.Forms.Label lblGraph;
		private System.Windows.Forms.PictureBox picGraph;
		private System.Windows.Forms.Label lblTickerSymbol;
		private System.Windows.Forms.TextBox txtTickerSymbol;
		private System.Windows.Forms.TextBox txtGraphURL;
		private System.Windows.Forms.Label lblGraphURL;
		private System.Windows.Forms.Label lblYahooURL;
		private System.Windows.Forms.Button cmdRefresh;
		private System.Windows.Forms.TextBox txtYahooURL;
		private Microsoft.WindowsCE.Forms.InputPanel inputPanel1;
		private System.Windows.Forms.Label lblInfo;
		private System.Windows.Forms.MainMenu mainMenu1;

		public frmMain()
		{
			//
			// Erforderlich f黵 die Windows Form-Designerunterst黷zung
			//
			InitializeComponent();

			//
			// TODO: Konstruktorcode hinter dem InitializeComponent-Aufruf hinzuf黦en
			//
		}
		/// <summary>
		/// Verwendete Ressourcen bereinigen.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}
		#region Vom Windows Form-Designer generierter Code
		/// <summary>
		/// Erforderliche Methode f黵 die Designerunterst黷zung. 
		/// Der Inhalt der Methode darf nicht mit dem Code-Editor ge鋘dert werden.
		/// </summary>
		private void InitializeComponent()
		{
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.tabMain = new System.Windows.Forms.TabControl();
			this.tabInfo = new System.Windows.Forms.TabPage();
			this.panelWork = new System.Windows.Forms.Panel();
			this.cmdRefresh = new System.Windows.Forms.Button();
			this.picGraph = new System.Windows.Forms.PictureBox();
			this.panelGraph = new System.Windows.Forms.Panel();
			this.lblGraph = new System.Windows.Forms.Label();
			this.panelData = new System.Windows.Forms.Panel();
			this.lblData = new System.Windows.Forms.Label();
			this.lsvData = new System.Windows.Forms.ListView();
			this.scrollInfo = new System.Windows.Forms.VScrollBar();
			this.tabSettings = new System.Windows.Forms.TabPage();
			this.txtYahooURL = new System.Windows.Forms.TextBox();
			this.lblYahooURL = new System.Windows.Forms.Label();
			this.txtGraphURL = new System.Windows.Forms.TextBox();
			this.lblGraphURL = new System.Windows.Forms.Label();
			this.txtTickerSymbol = new System.Windows.Forms.TextBox();
			this.lblTickerSymbol = new System.Windows.Forms.Label();
			this.inputPanel1 = new Microsoft.WindowsCE.Forms.InputPanel();
			this.lblInfo = new System.Windows.Forms.Label();
			// 
			// tabMain
			// 
			this.tabMain.Controls.Add(this.tabInfo);
			this.tabMain.Controls.Add(this.tabSettings);
			this.tabMain.SelectedIndex = 0;
			this.tabMain.Size = new System.Drawing.Size(240, 272);
			// 
			// tabInfo
			// 
			this.tabInfo.Controls.Add(this.panelWork);
			this.tabInfo.Controls.Add(this.scrollInfo);
			this.tabInfo.Location = new System.Drawing.Point(4, 4);
			this.tabInfo.Size = new System.Drawing.Size(232, 246);
			this.tabInfo.Text = "Info";
			// 
			// panelWork
			// 
			this.panelWork.Controls.Add(this.lblInfo);
			this.panelWork.Controls.Add(this.cmdRefresh);
			this.panelWork.Controls.Add(this.picGraph);
			this.panelWork.Controls.Add(this.panelGraph);
			this.panelWork.Controls.Add(this.panelData);
			this.panelWork.Controls.Add(this.lsvData);
			this.panelWork.Size = new System.Drawing.Size(216, 353);
			// 
			// cmdRefresh
			// 
			this.cmdRefresh.Location = new System.Drawing.Point(128, 184);
			this.cmdRefresh.Text = "Refresh";
			this.cmdRefresh.Click += new System.EventHandler(this.cmdRefresh_Click);
			// 
			// picGraph
			// 
			this.picGraph.Location = new System.Drawing.Point(0, 244);
			this.picGraph.Size = new System.Drawing.Size(208, 100);
			// 
			// panelGraph
			// 
			this.panelGraph.BackColor = System.Drawing.Color.DimGray;
			this.panelGraph.Controls.Add(this.lblGraph);
			this.panelGraph.Location = new System.Drawing.Point(0, 216);
			this.panelGraph.Size = new System.Drawing.Size(216, 24);
			// 
			// lblGraph
			// 
			this.lblGraph.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold);
			this.lblGraph.ForeColor = System.Drawing.Color.White;
			this.lblGraph.Location = new System.Drawing.Point(8, 6);
			this.lblGraph.Text = "Graph";
			// 
			// panelData
			// 
			this.panelData.BackColor = System.Drawing.Color.DimGray;
			this.panelData.Controls.Add(this.lblData);
			this.panelData.Size = new System.Drawing.Size(216, 24);
			// 
			// lblData
			// 
			this.lblData.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold);
			this.lblData.ForeColor = System.Drawing.Color.White;
			this.lblData.Location = new System.Drawing.Point(8, 6);
			this.lblData.Text = "Data";
			// 
			// lsvData
			// 
			this.lsvData.Location = new System.Drawing.Point(0, 24);
			this.lsvData.Size = new System.Drawing.Size(208, 152);
			// 
			// scrollInfo
			// 
			this.scrollInfo.Location = new System.Drawing.Point(216, 8);
			this.scrollInfo.Maximum = 91;
			this.scrollInfo.ValueChanged += new System.EventHandler(this.scrollInfo_ValueChanged);
			// 
			// tabSettings
			// 
			this.tabSettings.Controls.Add(this.txtYahooURL);
			this.tabSettings.Controls.Add(this.lblYahooURL);
			this.tabSettings.Controls.Add(this.txtGraphURL);
			this.tabSettings.Controls.Add(this.lblGraphURL);
			this.tabSettings.Controls.Add(this.txtTickerSymbol);
			this.tabSettings.Controls.Add(this.lblTickerSymbol);
			this.tabSettings.Location = new System.Drawing.Point(4, 4);
			this.tabSettings.Size = new System.Drawing.Size(232, 246);
			this.tabSettings.Text = "Settings";
			// 
			// txtYahooURL
			// 
			this.txtYahooURL.Location = new System.Drawing.Point(8, 144);
			this.txtYahooURL.Size = new System.Drawing.Size(208, 20);
			this.txtYahooURL.Text = "";
			// 
			// lblYahooURL
			// 
			this.lblYahooURL.Location = new System.Drawing.Point(8, 120);
			this.lblYahooURL.Text = "Yahoo-URL";
			// 
			// txtGraphURL
			// 
			this.txtGraphURL.Location = new System.Drawing.Point(8, 88);
			this.txtGraphURL.Size = new System.Drawing.Size(208, 20);
			this.txtGraphURL.Text = "";
			// 
			// lblGraphURL
			// 
			this.lblGraphURL.Location = new System.Drawing.Point(8, 64);
			this.lblGraphURL.Text = "Graph-URL";
			// 
			// txtTickerSymbol
			// 
			this.txtTickerSymbol.Location = new System.Drawing.Point(8, 32);
			this.txtTickerSymbol.Size = new System.Drawing.Size(208, 20);
			this.txtTickerSymbol.Text = "";
			// 
			// lblTickerSymbol
			// 
			this.lblTickerSymbol.Location = new System.Drawing.Point(8, 8);
			this.lblTickerSymbol.Text = "Ticker-Symbol";
			// 
			// inputPanel1
			// 
			this.inputPanel1.EnabledChanged += new System.EventHandler(this.inputPanel1_EnabledChanged);
			// 
			// lblInfo
			// 
			this.lblInfo.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular);
			this.lblInfo.ForeColor = System.Drawing.Color.DarkGreen;
			this.lblInfo.Location = new System.Drawing.Point(8, 184);
			this.lblInfo.Size = new System.Drawing.Size(120, 20);
			this.lblInfo.Text = "Info";
			// 
			// frmMain
			// 
			this.Controls.Add(this.tabMain);
			this.Menu = this.mainMenu1;
			this.Text = "WKN";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.Closing += new System.ComponentModel.CancelEventHandler(this.frmMain_Closing);
			this.Load += new System.EventHandler(this.frmMain_Load);

		}
		#endregion

		/// <summary>
		/// Der Haupteinstiegspunkt f黵 die Anwendung.
		/// </summary>

		static void Main() 
		{
			Application.Run(new frmMain());
		}

		private cSettings MySettings = null;

		private void frmMain_Load(object sender, System.EventArgs e)
		{
			// Listview init
			this.lsvData.View = View.Details;
			this.lsvData.Columns.Add("Descr.", 110, HorizontalAlignment.Left);
			this.lsvData.Columns.Add("Value", 98, HorizontalAlignment.Right);
			cGradientListview.SetGradient(this.lsvData);

			// Resizing
			this.panelWork.Width = this.tabMain.TabPages[0].Width - this.scrollInfo.Width;
			this.scrollInfo.Location = new Point(this.tabMain.TabPages[0].Width - this.scrollInfo.Width, 0);
			this.lsvData.Width = this.panelWork.Width;
			this.picGraph.Width = this.panelWork.Width;
			this.panelData.Width = this.tabMain.TabPages[0].Width;
			this.panelGraph.Width = this.tabMain.TabPages[0].Width;
			this.cmdRefresh.Left = this.panelWork.Width - this.cmdRefresh.Width - 10;


			MySettings = new cSettings();
				// Load Settings
			if(MySettings.LoadData(GetAppPath() + @"\WKNSettings.dat") == true)
			{
				this.txtTickerSymbol.Text = MySettings.TickerSymbol;
				this.txtYahooURL.Text = MySettings.YahooURL;
				this.txtGraphURL.Text = MySettings.GraphURL;
			}
			else
			{
				// Default Data
				this.txtTickerSymbol.Text = "MSF.DE";
				this.txtYahooURL.Text = @"http://quote.yahoo.com/d/quotes.csv?s=MSF.DE&f=sl1d1t1c1ohgvj1pp2owern&e=.csv";
				this.txtGraphURL.Text = @"http://de.ichart.yahoo.com/t?s=MSF.DE";
			}

			

			// Scrollbar
			ResizeScrollBar();

		}

		// Check Settings
		private bool ValidateData()
		{
			
			bool retValue = false;

			if((this.txtYahooURL.Text.Length == 0) | (this.txtGraphURL.Text.Length == 0 )
				| (this.txtTickerSymbol.Text.Length == 0))
			{
				MessageBox.Show("Check Settings!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
				this.tabMain.SelectedIndex = 1;
				this.txtTickerSymbol.Focus();
				retValue = false;
			}
			else
			{
				retValue = true;
			}
			return retValue;
		}

		private void cmdRefresh_Click(object sender, System.EventArgs e)
		{
			cDownloadYahooData oDownload = new cDownloadYahooData();

			if (ValidateData() == false) { return; }
			
			try
			{
				Cursor.Current = Cursors.WaitCursor;
				this.lsvData.Items.Clear();
				this.picGraph.Image = null;
				this.lblInfo.Text = "Downloading Data ... ";
				cDownloadYahooData.YahooData data =
					oDownload.GetYahooData(this.txtYahooURL.Text, this.txtGraphURL.Text, GetAppPath() + @"\YahooData.csv", GetAppPath() + @"\Graph.jpg");				
				bool bolSucess = oDownload.Sucess;
				if(bolSucess == true)
				{
					this.lblInfo.Text = "Download completed ... ";					
					// Add data to Listview
					ListViewItem itm = new ListViewItem("WKN");
					itm.SubItems.Add(data.WKN);
					this.lsvData.Items.Add(itm);
					itm = new ListViewItem("Last Price");
					itm.SubItems.Add(data.LastPrice);
					this.lsvData.Items.Add(itm);
					itm = new ListViewItem("Date");
					itm.SubItems.Add(data.Date);
					this.lsvData.Items.Add(itm);
					itm = new ListViewItem("Time");
					itm.SubItems.Add(data.Time);
					this.lsvData.Items.Add(itm);
					itm = new ListViewItem("Change");
					itm.SubItems.Add(data.Change);
					this.lsvData.Items.Add(itm);
					itm = new ListViewItem("Open");
					itm.SubItems.Add(data.Open);
					this.lsvData.Items.Add(itm);
					itm = new ListViewItem("High");
					itm.SubItems.Add(data.High);
					this.lsvData.Items.Add(itm);
					itm = new ListViewItem("Low");
					itm.SubItems.Add(data.Low);
					this.lsvData.Items.Add(itm);
					// Display Graph Image
					Bitmap bmp = new Bitmap(GetAppPath() + @"\Graph.jpg");
					this.picGraph.Image = bmp;
					oDownload = null;
				}
			}
			catch(Exception exc)
			{
				MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
			}
			finally
			{
				Cursor.Current = Cursors.Default;
			}
		}

		// Return the Application Startup Path
		private string GetAppPath()
		{
			string strPath = string.Empty;

			strPath = System.IO.Path.GetDirectoryName(
       System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
			return strPath;
		}

		// Resizing the Scrollbar
		private void ResizeScrollBar()
		{
			int actHeight;
			int actHeightNoSip;
			const int NO_OF_PAGES = 2;


			try
			{
				this.scrollInfo.Location = new Point(this.Width - this.scrollInfo.Width, 0);
				actHeightNoSip = this.tabMain.TabPages[0].Height;
				actHeight = actHeightNoSip - this.inputPanel1.Bounds.Height;

				if(this.inputPanel1.Enabled == true)
				{
					this.scrollInfo.Height = actHeight;
					this.scrollInfo.Maximum = this.panelWork.Height - actHeight;
				}
				else
				{
					this.scrollInfo.Height = actHeightNoSip;
					this.scrollInfo.Maximum = this.panelWork.Height - actHeightNoSip;
				}
				this.scrollInfo.LargeChange = this.scrollInfo.Maximum / (NO_OF_PAGES - 1) + 1;
				this.scrollInfo.Maximum = this.scrollInfo.LargeChange * NO_OF_PAGES - NO_OF_PAGES;
				this.panelWork.Top = this.scrollInfo.Value;

			}
			catch
			{
			}
		}

		private void inputPanel1_EnabledChanged(object sender, System.EventArgs e)
		{
			ResizeScrollBar();
		}

		private void scrollInfo_ValueChanged(object sender, System.EventArgs e)
		{
			this.panelWork.Top = -this.scrollInfo.Value;
		}

		private void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			MySettings.GraphURL = this.txtGraphURL.Text;
			MySettings.TickerSymbol = this.txtTickerSymbol.Text;
			MySettings.YahooURL = this.txtYahooURL.Text;
			MySettings.SaveData(GetAppPath() + @"\WKNSettings.dat");
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -