Data Checker : TextBox « GUI Windows Form « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » GUI Windows Form » TextBoxScreenshots 
Data Checker
Data Checker

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Threading;


namespace DataChecker
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class DataChecker : System.Windows.Forms.Form
    {
        private System.Windows.Forms.TextBox txtCoffeePrice;
        private System.Windows.Forms.TextBox txtTeaPrice;
        private System.Windows.Forms.TextBox txtGoldPrice;
        private System.Windows.Forms.Label lblCoffeePrice;
        private System.Windows.Forms.Label lblTeaPrice;
        private System.Windows.Forms.Label lblGoldPrice;

        private int lastCoffeePrice = 0;
        private int lastTeaPrice = 0;
        private int lastGoldPrice = 0;
        private int allUpdates = 0;

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;
        private System.Threading.Timer t1 = null;
        private System.Threading.Timer t2 = null;
        private System.Threading.Timer t3 = null;

        public DataChecker()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            t1 = new System.Threading.Timer(new TimerCallback(Timer_Callback)'C'0500);
            t2 = new System.Threading.Timer(new TimerCallback(Timer_Callback)'T'1500);
            t3 = new System.Threading.Timer(new TimerCallback(Timer_Callback)'G'2500);        

            /*WaitOrTimerCallback wotc = new WaitOrTimerCallback(GetData);
            AutoResetEvent are = new AutoResetEvent(false);
            ThreadPool.RegisterWaitForSingleObject(are, new WaitOrTimerCallback(GetData), 'C', 500, false);*/

        }

        protected void Timer_Callback(object state)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback(GetData), state);
        }


        int retVal;
        private void GetData(object type)
        {
            char priceType = (char)type;
            string sql = null;

            sql = "SELECT Price FROM tblPrices WHERE Type='"+priceType.ToString()+"'";

            SqlConnection cn = new SqlConnection("Server=localhost; Database=Prices; Integrated Security=SSPI");
            cn.Open();

            SqlCommand cmd = new SqlCommand(sql, cn);

            
            lock(this)
            {
                retVal = (int)cmd.ExecuteScalar()
                switch(priceType
                {
                    case 'C':
                        lastCoffeePrice = Convert.ToInt32(txtCoffeePrice.Text);
                        txtCoffeePrice.Text = retVal.ToString();
                        break;
                    case 'T':
                        lastTeaPrice = Convert.ToInt32(txtTeaPrice.Text);
                        txtTeaPrice.Text = retVal.ToString();
                        break;
                    case 'G':
                        lastGoldPrice = Convert.ToInt32(txtGoldPrice.Text);
                        txtGoldPrice.Text = retVal.ToString();
                        break;
                }
            }
            

            allUpdates++;
            cn.Close();
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Disposebool disposing )
        {
            ifdisposing )
            {
                if (components != null
                {
                    components.Dispose();
                }
            }
            base.Disposedisposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.txtCoffeePrice = new System.Windows.Forms.TextBox();
            this.txtTeaPrice = new System.Windows.Forms.TextBox();
            this.txtGoldPrice = new System.Windows.Forms.TextBox();
            this.lblCoffeePrice = new System.Windows.Forms.Label();
            this.lblTeaPrice = new System.Windows.Forms.Label();
            this.lblGoldPrice = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // txtCoffeePrice
            // 
            this.txtCoffeePrice.Location = new System.Drawing.Point(7224);
            this.txtCoffeePrice.Name = "txtCoffeePrice";
            this.txtCoffeePrice.TabIndex = 0;
            this.txtCoffeePrice.Text = "0";
            // 
            // txtTeaPrice
            // 
            this.txtTeaPrice.Location = new System.Drawing.Point(19224);
            this.txtTeaPrice.Name = "txtTeaPrice";
            this.txtTeaPrice.TabIndex = 1;
            this.txtTeaPrice.Text = "0";
            // 
            // txtGoldPrice
            // 
            this.txtGoldPrice.Location = new System.Drawing.Point(31224);
            this.txtGoldPrice.Name = "txtGoldPrice";
            this.txtGoldPrice.TabIndex = 2;
            this.txtGoldPrice.Text = "0";
            // 
            // lblCoffeePrice
            // 
            this.lblCoffeePrice.Location = new System.Drawing.Point(720);
            this.lblCoffeePrice.Name = "lblCoffeePrice";
            this.lblCoffeePrice.TabIndex = 3;
            this.lblCoffeePrice.Text = "Coffee Price";
            // 
            // lblTeaPrice
            // 
            this.lblTeaPrice.Location = new System.Drawing.Point(1920);
            this.lblTeaPrice.Name = "lblTeaPrice";
            this.lblTeaPrice.TabIndex = 4;
            this.lblTeaPrice.Text = "Tea Price";
            // 
            // lblGoldPrice
            // 
            this.lblGoldPrice.Location = new System.Drawing.Point(3200);
            this.lblGoldPrice.Name = "lblGoldPrice";
            this.lblGoldPrice.TabIndex = 5;
            this.lblGoldPrice.Text = "Gold Price";
            // 
            // DataChecker
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(513);
            this.ClientSize = new System.Drawing.Size(42454);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.lblGoldPrice,
                                                                          this.lblTeaPrice,
                                                                          this.lblCoffeePrice,
                                                                          this.txtGoldPrice,
                                                                          this.txtTeaPrice,
                                                                          this.txtCoffeePrice});
            this.MaximizeBox = false;
            this.Name = "DataChecker";
            this.Text = "Data Checker";
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new DataChecker());
        }

        
    }
}


           
       
Related examples in the same category
1.Add ScrollBars to TextBox
2.new TextBox(), Localtion, Name, TabIndex, Text
3.TextBox locationTextBox location
4.Keyboard event and TextBox
5.Get value from TextBox
6.Text Changed eventText Changed event
7.A simple text editorA simple text editor
8.Convert TextBox input to double valueConvert TextBox input to double value
9.All cap text textboxAll cap text textbox
10.User EventsUser Events
11.TextBox and button on formTextBox and button on form
12.TextBox and ListBoxTextBox and ListBox
13.Label, TextBox and ButtonLabel, TextBox and Button
14.TextBox DemoTextBox Demo
15.Simple Editor based on TextBox
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.