2015年12月25日 星期五

期末考
新增 修改 刪除


amespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        private OleDbConnection connection = new OleDbConnection();

        OleDbDataAdapter dAdapter;
        OleDbCommandBuilder cBuilder;
        DataTable dTable = new DataTable();
        BindingSource bSource;

        private string ID;
        public Form1()
        {
            InitializeComponent();
            connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\student\Desktop\WindowsFormsApplication7\WindowsFormsApplication7\bin\Debug\test1.mdb");
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dAdapter = new OleDbDataAdapter("select * from person where 識別碼  ", connection);

            cBuilder = new OleDbCommandBuilder(dAdapter);
            dAdapter.Fill(dTable);

            bSource = new BindingSource();
            bSource.DataSource = dTable;

            dataGridView1.DataSource = bSource;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            dTable.Clear();

            connection.Open();
            OleDbCommand command = new OleDbCommand();
            command.Connection = connection;




            command.CommandText = "UPDATE person SET name = '" + textBox1.Text + "'WHERE 識別碼 = " + ID;

            command.ExecuteNonQuery();

            dAdapter.Fill(dTable);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            connection.Open();
            dTable.Clear();
            OleDbCommand command2 = new OleDbCommand();
            command2.Connection = connection;

            command2.CommandText = "insert into person (name,stu_no,tel,sex) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')";

            command2.ExecuteNonQuery();

            dAdapter.Fill(dTable);

            connection.Close();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {

                try
                {
                    var Value = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                    Value = dataGridView1.Rows[e.RowIndex].Cells["name"].Value;

                    connection.Open();
                    OleDbCommand command = new OleDbCommand();
                    command.Connection = connection;

                    string query = "select* from person where name='" + Value.ToString() + "'";
                    command.CommandText = query;


                    OleDbDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {

                        ID = reader["識別碼"].ToString();
                        textBox1.Text = reader["name"].ToString();
                        textBox2.Text = reader["stu_no"].ToString();
                        textBox3.Text = reader["sex"].ToString();
                        textBox4.Text = reader["tel"].ToString();


                    }
                    connection.Close();
                }

                catch (Exception ex)
                {
                    MessageBox.Show("ERROR" + ex);
                }
            }

            else if (e.ColumnIndex == 1)
            {
                if (MessageBox.Show("確定刪除此筆資料?", "刪除資料", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    try
                    {
                        var Value = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                        Value = dataGridView1.Rows[e.RowIndex].Cells["name"].Value;

                        connection.Open();
                        OleDbCommand command = new OleDbCommand();
                        command.Connection = connection;



                        command.CommandText = "delete from person WHERE name = '" + Value.ToString() + "'";

                        command.ExecuteNonQuery();
                        dTable.Clear();
                        dAdapter.Fill(dTable);

                        connection.Close();
                        MessageBox.Show("刪除成功");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("ERROR" + ex);
                    }

                }
            }
        }
    }
}

2015年11月19日 星期四

吳宗晏      D0250582



1.先開bindingSource1
2.上傳資料庫
3.再用dataGridView1的bindingSource1

2015年11月5日 星期四

11/6 期中考試
D0250582 吳宗晏




 public partial class Form1 : Form
    {
        int a, b, c,f;
        float d;
        public Form1()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            a = int.Parse(textBox1.Text)+int.Parse(textBox2.Text);
            label2.Text = a.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            b = int.Parse(textBox1.Text) - int.Parse(textBox2.Text);
            label2.Text = b.ToString();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            c = int.Parse(textBox1.Text) * int.Parse(textBox2.Text);
            label2.Text = c.ToString();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            d = float.Parse(textBox1.Text) / float.Parse(textBox2.Text);
            label2.Text = d.ToString();
            textBox2.Text = f.ToString();
            if (f == 0)
            {
                label2.Text = "除數不可以為0";
            }
        }
    }
}

2015年10月30日 星期五

吳宗晏   d0250582
推盤



 public partial class Form1 : Form
    {
        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 button1_Click(object sender, EventArgs e)
        {
            int pro = 0;
            for (int i = 1; i < 5; i++)
            {
                for (int j = 1; j < 5; j++)
                {
                    pro = i;
                    Buttons[i, 1].Text = pro.ToString();
                    pro = i + j;
                    Buttons[i, 2].Text = pro.ToString();
                    pro = i + 2 * j;
                    Buttons[i, 3].Text = pro.ToString();
                    pro = i + 3 * j;
                    Buttons[i, 4].Text = pro.ToString();

                }



            }
        }

    }
}

2015年10月23日 星期五

吳宗晏  d0250582  推盤
程式設計工藝大師



namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        int r1 = 0;
        int r2 = 0;
        int r3 = 0;
        int r4 = 0;
        int r5 = 0;
        int r6 = 0;
        int r7 = 0;
        int r8 = 0;
        int r9 = 0;
        public Form1()
        {
            InitializeComponent();
            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;
        }

        private void button10_Click(object sender, EventArgs e)
        {
           
            Random rnd = new Random();
            int[] a = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
            for (int i = 0; i < 9; ++i)
            {
                int j = rnd.Next(8);
                int t = a[j];
                a[j] = a[i];
                a[i] = t;
            }
            button1.Text = a[0].ToString();
            button2.Text = a[1].ToString();
            button3.Text = a[2].ToString();
            button4.Text = a[3].ToString();
            button5.Text = a[4].ToString();
            button6.Text = a[5].ToString();
            button7.Text = a[6].ToString();
            button8.Text = a[7].ToString();
            button9.Text = a[8].ToString();
            //button10.Enabled = false;

        }
    }

2015年10月16日 星期五

吳宗晏  d0250582  拉霸
程式設計工藝大師
{
    public partial class Form1 : Form
    {
        int c1 = 0, d1 = 0,c2=0,d2=0,c3=0,d3=0;
        int rndmoney1 = 100;
        int rndmoney2 = 100;
        int rndmoney3 = 100;
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            c1 = c1 + 1;
            d1 = c1 % 10;
            if (c1 >= rndmoney1) timer1.Enabled = false;


            {
             
                if (d1 == 0)
                {
                   // button1.BackColor = System.Drawing.Color.Green;
                }
                else
                {
                    //button1.BackColor = System.Drawing.Color.White;
                }
                if (d1 == 1)
                {
                    //button2.BackColor = System.Drawing.Color.Yellow;
                }
                else
                {
                    //button2.BackColor = System.Drawing.Color.White;
                }
                if (d1 == 2)
                {
                   // button3.BackColor = System.Drawing.Color.Red;
                }
                else
                {
                   // button3.BackColor = System.Drawing.Color.White;
                }
                button1.Text = d1.ToString();
                //button2.Text = d.ToString();
                //button3.Text = d.ToString();
            }
            button1.Text = d1.ToString();
        }

        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);
            rndmoney2 = rnd.Next(1, 101);
            rndmoney3= rnd.Next(1, 101);
            button4.Text = rndmoney1.ToString() + rndmoney2.ToString() + rndmoney3.ToString();
         
     
     
        }

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

            if (c2 >= rndmoney2) timer2.Enabled = false;
            button2.Text = d2.ToString();
        }

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

            if (c3 >= rndmoney3) timer3.Enabled = false;
            button3.Text = d3.ToString();
         
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
private void timer4_Tick(object sender, EventArgs e)
        {
            button4.Text = "start";
            if (d1 == d2 && d2 == d3)
            {
                button5.Text = "win";
            }
            else
            {
                button5.Text = "flaut";
            }


2015年10月2日 星期五

程式設計工藝大師

吳宗晏   D0250582   紅綠燈

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        int c = 0,d=0;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            c = c + 1;
            button1.Text = c.ToString();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

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

        private void button3_Click(object sender, EventArgs e)
        {

        }
    }
}