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

📄 form1.cs

📁 这是一个C#开发的手机管理系统
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Runtime;
using System.Data.SqlClient;

namespace WindowsApplication2
{
    public partial class Form1 : Form
    {
        bool isTrue = false;
        Point myPoint = new Point();
        string[] images = new string[] { "image005", "image007", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9", "xx", "n0", "ee" };
        public Form1()
        {
            InitializeComponent();
        }
        private void fun()
        {
            new Form2().ShowDialog();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string strConstrlName = "";
            int i = 13;
            foreach (Control c in this.Controls)
            {
                if (c is PictureBox)
                {
                    strConstrlName += c.Name.ToString()+",";
                    ((PictureBox)c).Tag = Application.StartupPath + "\\image\\" + images[i];
                    i--;
                }
            }
            getNumber();
     
        }
        private void getNumber()
        {
            this.label1.Text = "";
            Random myRandom = new Random();
            this.label1.Text += myRandom.Next(9).ToString();
            this.label1.Text += myRandom.Next(9).ToString();
            this.label1.Text += myRandom.Next(9).ToString();
            this.label1.Text += myRandom.Next(9).ToString();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            getNumber();
        }

        private void pictureBox14_MouseEnter(object sender, EventArgs e)
        {
            string imageStr = ((PictureBox)sender).Tag.ToString() + "a.gif";
            ((PictureBox)sender).Image = new Bitmap(imageStr);
        }

        private void pictureBox14_MouseLeave(object sender, EventArgs e)
        {
            string imageStr = ((PictureBox)sender).Tag.ToString() + ".gif";
            ((PictureBox)sender).Image = new Bitmap(imageStr);
        }

        private void pictureBox14_Click(object sender, EventArgs e)
        {
            string ConstrlName = ((PictureBox)sender).Name;
            string number = ConstrlName.Split('x')[1];
            int intNum = Convert.ToInt32(number);
            if (intNum < 12)
            {
                this.textBox2.Text += (intNum - 2) + "";
            }
            else
            {
                if (ConstrlName == "pictureBox12")
                {
                    this.textBox2.Text += "*";
                }
                else if (ConstrlName == "pictureBox13")
                {
                    this.textBox2.Text += "0";
                }
                else
                {
                    this.textBox2.Text += "#";
                }
            }
            
            
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            string name = textBox1.Text.Trim();
            string pwd = textBox2.Text.Trim();
            string num = textBox3.Text.Trim();
            string url = @"server=.;database=手机销售管理系统;uid=sa";
            SqlConnection conn = null;
            try
            {
                conn = new SqlConnection(url);
                conn.Open();
                string sql1 = string.Format(
                    "select * from 员工信息表 where 员工姓名='{0}' and 用户密码='{1}'",
                    textBox1.Text, textBox2.Text);
                SqlCommand sc = new SqlCommand();
                sc.CommandText = sql1;
                sc.Connection = conn;
                Console.WriteLine(sql1);
                //第四步  执行
                try
                {
                    int i = (int)sc.ExecuteScalar();
                }
                catch (Exception)
                {
                    MessageBox.Show("用户名或密码错误");
                    return;
                }
                if (num != label1.Text)
                {
                    MessageBox.Show("请输入正确的验证码!!!", "警告", MessageBoxButtons.OK);
                }
                Thread th = new Thread(new ThreadStart(fun));
                th.Start();
                this.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("数据库连接失败!");
            }
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if(e.Button == MouseButtons.Left)
            {
                isTrue = true;
                myPoint = e.Location;
            } 
        }
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (isTrue)
            {
                this.Location = new Point(MousePosition.X - myPoint.X, MousePosition.Y - myPoint.Y);
            }
        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            isTrue = false;
        }

        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                pictureBox1_Click(null, null);
            }
            if (e.KeyCode == Keys.Escape)
            {
                if (MessageBox.Show(this, "是否退出?", "警告", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    this.Close();
                }
            }
        }
    }
}

⌨️ 快捷键说明

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