登陸/註冊介面各功能設計-更新

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;
using System.Data.SqlClient;
using CCWin;
using Leadshine.SMC.IDE.Motion;
using System.Threading;
using System.Drawing.Drawing2D;
using MathNet.Numerics.LinearAlgebra;
using System.IO;
using System.Runtime.InteropServices;

private void button3_Click_1(object sender, EventArgs e)
        {
            註冊介面 mylogin = new 註冊介面();
            mylogin.Show();
        }

private void skinButton1_Click_3(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("osk.exe");
        }

 

 bool random0 =true;//驗證碼判斷標誌
//更換驗證碼
private void txtpwd_TextChanged(object sender, EventArgs e)
        {
            if (random0)
            {
            Random random = new Random();
            int minV = 1234, maxV = 9876;
            checkcode.Text = random.Next(minV, maxV).ToString();
            random0 = !random0;
            }
            
        }

 

//驗證碼更換驗證值 
private void checkcode_Click(object sender, EventArgs e)
        {
             Random random = new Random();
            int minV = 1234, maxV = 9876;
            checkcode.Text = random.Next(minV, maxV).ToString();
        }

//登陸系統,連接SQL資料庫中存儲的帳號和密碼進行確認 
private void skinButton1_Click_1(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(txtname.Text) && !String.IsNullOrEmpty(txtpwd.Text))   //判斷帳號和密碼是否為空
            {
                errorTime = errorTime - 1;
                string username = txtname.Text.Trim();  //取出帳號
                string pwd = txtpwd.Text.Trim();         //取出密碼
                string constr = @"Data Source=LENOVO-PC\SQLEXPRESS02;Initial Catalog=CCClink;Integrated Security=True";
                //連接資料庫字元串
                SqlConnection mysqlcon = new SqlConnection(constr);
                mysqlcon.Open();
                SqlCommand mycom = new SqlCommand(constr, mysqlcon);
                string sql = "select * from 用戶 where 帳號='" + username + "'and 密碼='" + pwd + "'";//編寫SQL命令
                mycom.CommandText = sql;                       //執行SQL命令
                if (null != mycom.ExecuteScalar())
                {
                    if (checkcode.Text == txtvalid.Text)
                    {  
                        this.Hide();
                        系統介面 myform = new 系統介面();
                        myform.Show();
                    }
                    else
                    {
                        MessageBox.Show("驗證碼填寫錯誤");
                        txtvalid.Text = "";
                    }

                }
                else
                {
                    if (errorTime < 100)
                    {
                        MessageBox.Show("用戶名或密碼有錯。請重新輸入!還有" + errorTime.ToString() + "次機會");
                        txtname.Text = "";   //清空帳號
                        txtpwd.Text = "";    //清空密碼?
                        txtvalid.Text = "";  //清空驗證碼
                        txtname.Focus();     //游標設置在帳號上
                    }
                    else
                    {
                        MessageBox.Show("你輸入的用戶名或密碼已達十次? 將退出程式");
                        this.Close();
                    }
                }
            }
        }

 

private void skinButton1_Click(object sender, EventArgs e)
        {
            string userID = userId.Text.Trim();  //取出帳號
            //連接資料庫

            string constr = @"Data Source=LENOVO-PC\SQLEXPRESS02;Initial Catalog=CCClink;Integrated Security=True";
            //連接資料庫字元串
            SqlConnection mysqlcon = new SqlConnection(constr);
            mysqlcon.Open();

            string s1 = "select * from 用戶 where 帳號='" + userID + "'";//編寫SQL命令

            SqlCommand mycom = new SqlCommand(s1, mysqlcon);
            mycom.CommandText = s1;
            if (null != mycom.ExecuteScalar())
            {
                MessageBox.Show("用戶名存在");
                userId.Text = "";
                userPw.Text = "";

                //確認密碼
                if (ensurePw.Text != userPw.Text)
                {
                    ensurePw.Text = "";
                }

                //驗證碼
                if (textCheck.Text != checkcode.Text)
                {
                    textCheck.Text = "";
                }
            }

            //插入數據SQL
            string s = "insert into 用戶(帳號,密碼) values ('" + userId.Text + "','" + userPw.Text + "')";
            SqlCommand cmd = new SqlCommand(s, mysqlcon); //創建執行
            cmd.ExecuteNonQuery();//執行SQL


            if (userId.Text == "" || ensurePw.Text == "" || textCheck.Text == "")
            {
                MessageBox.Show("請將資訊填完整");
            }
            else
            {
                MessageBox.Show("註冊成功");
                this.Close();
            }
        }
//退出系統
 private void skinButton1_Click_2(object sender, EventArgs e)
        {
            Application.Exit();
        }