2015年11月19日 星期四

c#資料庫查詢





using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 這行程式碼會將資料載入 'dB4DataSet.工作表1_舊' 資料表。您可以視需要進行移動或移除。
            this.工作表1_舊TableAdapter.Fill(this.dB4DataSet.工作表1_舊);

        }
    }
}






bindsource      連接資料庫

detamember   連接清單








2015年11月5日 星期四

加減乘除

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string b1, b2;
            b1 = textBox1.Text;
            b2 = textBox2.Text;
            float numval1 = float.Parse(b1);
            float numval2 = float.Parse(b2);
            float numsum = numval1 + numval2;
            label2.Text = numsum.ToString();


        }

        private void button2_Click(object sender, EventArgs e)
        {
            string b1, b2;
            b1 = textBox1.Text;
            b2 = textBox2.Text;
            float numval1 = float.Parse(b1);
            float numval2 = float.Parse(b2);
            float numsum = numval1 - numval2;
            label2.Text = numsum.ToString();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string b1, b2;
            b1 = textBox1.Text;
            b2 = textBox2.Text;
            float numval1 = float.Parse(b1);
            float numval2 = float.Parse(b2);
            float numsum = numval1 * numval2;
            label2.Text = numsum.ToString();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            float a = float.Parse(textBox1.Text), b = float.Parse(textBox2.Text);
            string b1, b2;
            b1 = textBox1.Text;
            b2 = textBox2.Text;
            float numval1 = float.Parse(b1);
            float numval2 = float.Parse(b2);
            float numsum = numval1 / numval2;
            label2.Text = numsum.ToString();

            if (b == 0)
            {
                label2.Text = "分母為零";
            }
            else
            {
                label2.Text = (a / b).ToString();

            }
        }
    }
}

2015年10月30日 星期五

按鈕自動跑出加亂數不重複




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public System.Windows.Forms.Button Button1;
Random rand = new Random();
            Button[,] Buttons = new System.Windows.Forms.Button[5, 5];
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
             for (int i = 1; i < 5; i++)
            {
            for (int j = 1; j < 5; j++)
            {
                Buttons[i, j] = new Button();
                Buttons[i, j].Size = new Size(50, 50);
                Buttons[i, j].Location = new Point(i * 50, j * 50);
                this.Controls.Add(Buttons[i, j]);//出現在畫面中
            }
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        int x, y, a;
int[] myarray = {  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16};
for (int i = 15; i > 1; i--)
{

x = rand.Next(0, i);
y = myarray[x];
myarray[x] = myarray[i];
myarray[i] = y;

}
for (int j = 1; j < 5; j++)
{
for (int i = 1; i < 5; i++)
{
a = myarray[(j - 1) * 4 + (i - 1)];
Buttons[i, j].Text = Convert.ToString(a);
this.Controls.Add(Buttons[i, j]);
}
}

}
}
    }
 

2015年10月23日 星期五

9不重複




Namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        int rndmoney1 = 0, rndmoney2 = 0, rndmoney3 = 0, rndmoney4 = 0, rndmoney5 = 0, rndmoney6 = 0, rndmoney7 = 0, rndmoney8 = 0, rndmoney9 = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void button10_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            button2.Enabled = false;
            button3.Enabled = false;
            button4.Enabled = false;
            button5.Enabled = false;
            button6.Enabled = false;
            button7.Enabled = false;
            button8.Enabled = false;
            button9.Enabled = false;

            Random rnd = new Random();
            rndmoney1 = rnd.Next(0, 9); // creates a number between 0 and 9
            rndmoney2 = rnd.Next(0, 9); // creates a number between 0 and 9
            rndmoney3 = rnd.Next(0, 9); // creates a number between 0 and 9
            rndmoney4 = rnd.Next(0, 9); // creates a number between 0 and 9
            rndmoney5 = rnd.Next(0, 9); // creates a number between 0 and 9
            rndmoney6 = rnd.Next(0, 9); // creates a number between 0 and 9
            rndmoney7 = rnd.Next(0, 9); // creates a number between 0 and 9
            rndmoney8 = rnd.Next(0, 9); // creates a number between 0 and 9
            rndmoney9 = rnd.Next(0, 9); // creates a number between 0 and 9

            while (rndmoney1 == rndmoney2 || rndmoney1 == rndmoney3
               || rndmoney1 == rndmoney4 || rndmoney1 == rndmoney5
               || rndmoney1 == rndmoney6 || rndmoney1 == rndmoney7
               || rndmoney1 == rndmoney8 || rndmoney1 == rndmoney9
               || rndmoney2 == rndmoney3 || rndmoney2 == rndmoney4
               || rndmoney2 == rndmoney5 || rndmoney2 == rndmoney6
               || rndmoney2 == rndmoney7 || rndmoney2 == rndmoney8
               || rndmoney2 == rndmoney9 || rndmoney3 == rndmoney4
               || rndmoney3 == rndmoney5 || rndmoney3 == rndmoney6
               || rndmoney3 == rndmoney7 || rndmoney3 == rndmoney8
               || rndmoney3 == rndmoney9 || rndmoney4 == rndmoney5
               || rndmoney4 == rndmoney6 || rndmoney4 == rndmoney7
               || rndmoney4 == rndmoney8 || rndmoney4 == rndmoney9
               || rndmoney5 == rndmoney6 || rndmoney5 == rndmoney7
               || rndmoney5 == rndmoney8 || rndmoney5 == rndmoney9
               || rndmoney6 == rndmoney7 || rndmoney6 == rndmoney8
               || rndmoney6 == rndmoney9 || rndmoney7 == rndmoney8
               || rndmoney7 == rndmoney9 || rndmoney8 == rndmoney9)
            {
                //MessageBox.Show("Dot net perls is awesome")
                rndmoney1 = rnd.Next(0, 9);
                rndmoney2 = rnd.Next(0, 9);
                rndmoney3 = rnd.Next(0, 9);
                rndmoney4 = rnd.Next(0, 9);
                rndmoney5 = rnd.Next(0, 9);
                rndmoney6 = rnd.Next(0, 9);
                rndmoney7 = rnd.Next(0, 9);
                rndmoney8 = rnd.Next(0, 9);
                rndmoney9 = rnd.Next(0, 9);
                button1.Text = rndmoney1.ToString();
                button2.Text = rndmoney2.ToString();
                button3.Text = rndmoney3.ToString();
                button4.Text = rndmoney4.ToString();
                button5.Text = rndmoney5.ToString();
                button6.Text = rndmoney6.ToString();
                button7.Text = rndmoney7.ToString();
                button8.Text = rndmoney8.ToString();
                button9.Text = rndmoney9.ToString();
            }
            button1.Text = rndmoney1.ToString();
            button2.Text = rndmoney2.ToString();
            button3.Text = rndmoney3.ToString();
            button4.Text = rndmoney4.ToString();
            button5.Text = rndmoney5.ToString();
            button6.Text = rndmoney6.ToString();
            button7.Text = rndmoney7.ToString();
            button8.Text = rndmoney8.ToString();
            button9.Text = rndmoney9.ToString();

            //button10.Enabled = false;

            
        }
    }
}

拉霸




 public partial class Form1 : Form
    {
        int c1 = 0, d1 = 0;
        int c2 = 0, d2 = 0;
        int c3 = 0, d3 = 0;
        int rndmoney1 = 100;
        int rndmoney2 = 100;
        int rndmoney3 = 100;
        public Form1()
        {
            InitializeComponent();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
            c1 = 0;
            c2 = 0;
            c3 = 0;
            timer1.Enabled = true;
            timer2.Enabled = true;
            timer3.Enabled = true;
            Random rnd = new Random();
            rndmoney1 = rnd.Next(1, 101); // creates a number between 1 and 12
            rndmoney2 = rnd.Next(1, 101); // creates a number between 1 and 12
            rndmoney3 = rnd.Next(1, 101); // creates a number between 1 and 12
            button4.Text = rndmoney1.ToString() + rndmoney2.ToString() + rndmoney3.ToString();

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            c1 = c1 + 1;
            d1 = c1 % 2;



            if (c1 >= rndmoney1) timer1.Enabled = false;

            if (d1 == 0)
            {
                //button1.BackColor = Color.Green;
            }
            else if (d1 == 1)
            {
                //button1.BackColor = Color.Black;
            }
            else if (d1 == 2)
            {
                //button1.BackColor = Color.Black;
            }
            button1.Text = d1.ToString();
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            c2 = c2 + 1;
            d2 = c2 % 2;

            if (c2 >= rndmoney2) timer2.Enabled = false;

            if (d2 == 0)
            {
                //button1.BackColor = Color.Green;
            }
            else if (d2 == 1)
            {
                //button1.BackColor = Color.Black;
            }
            else if (d2 == 2)
            {
                //button1.BackColor = Color.Black;
            }
            button2.Text = d2.ToString();
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            c3 = c3 + 1;
            d3 = c3 % 2;

            if (c3 >= rndmoney3) timer3.Enabled = false;

            if (d3 == 0)
            {
                //button1.BackColor = Color.Green;
            }
            else if (d3 == 1)
            {
                //button1.BackColor = Color.Black;
            }
            else if (d3 == 2)
            {
                //button1.BackColor = Color.Black;
            }
            button3.Text = d3.ToString();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            
            


        }
    }

2015年10月2日 星期五

程式工藝大師
物件導向設計
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        int c=0,d=0;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
          
       }

        private void timer1_Tick(object sender, EventArgs e)
        {
          c = c + 1;
          d = c % 3;
          if (d == 1)
          {
              button1.BackColor = System.Drawing.Color.Red;
            button2.BackColor = System.Drawing.Color.Black;
            button3.BackColor = System.Drawing.Color.Black;
        }
            else if (d==2)
            {
            button2.BackColor = System.Drawing.Color.Yellow;
            button1.BackColor = System.Drawing.Color.Black;
            button3.BackColor = System.Drawing.Color.Black;
            }
                else if(d==0)
          {   button3.BackColor = System.Drawing.Color.Green;
            button2.BackColor = System.Drawing.Color.Black;
            button1.BackColor = System.Drawing.Color.Black;
            
            button1.Text = c.ToString();
        }
  
        }

        private void button3_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }
    }
}