C#、mysql链接、非顶级窗口

本文介绍了C#中如何连接MySQL数据库,并提供了连接字符串的创建方式。此外,文章提到了窗口布局的设计,包括登录、注册、主窗口和非顶级窗口。虽然查询功能和非顶级窗口的参数传递未详细展开,但提供了登录窗口中图片控件的动态效果实现。
摘要由CSDN通过智能技术生成

解决方案:https://download.csdn.net/download/qq_44840449/20106390

写的乱,希望多多体谅,有些功能还没实现,MySQL简单写个触发器,可以自行百度,非顶级窗口的传参这里没写,以后写,感谢

一:窗口的布局

(1)登录窗口- 这里有两个time控件,用于登录时候移动图片控件

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;
using System.Data.Common;
//using MySql.Data.MySqlClient;//添加mysql.dll MySQl数据库处理

namespace loge
{
    public partial class Form1 : Form
    {
        Form2 f2 = new Form2();
        maincs main = new maincs();
        public Form1()
        { 
            InitializeComponent();
          //  this.f2=f2;
            pictureBox1.Hide();//图片默认隐藏
            pictureBox2.Hide();
         
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //获取用户输入信息
            string uname = textBox1.Text.Trim();//去除null
            string upaw = textBox2.Text.Trim();
           
           
            //判断输入是否为空
            if(string.IsNullOrEmpty(uname)||string.IsNullOrEmpty(upaw))
            {
                MessageBox.Show("请检测账号或者密码输入格式是否正确","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
                textBox1.Focus();//设置为焦点
                return;
            }
            //与数据库通信,判断是否一致

            
            {

               
                sqlhelp cmd = new sqlhelp();
                string sql = "select count(1) from home where name='" + uname + "' and psw='" + upaw + "'";
                string connString = zfc.connn();     
                object o = cmd.ExecuteScalar(sql);//返回第一行第一列,例如我们在计算总条数的时候会使用到此方法

               
                try//尝试,假如里面的语句出错就跳出
                {
                    if (o==null || o==DBNull.Value || int.Parse(o.ToString())==0)
                    {

                        MessageBox.Show("请检测账号或者密码是否正确", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        textBox1.Focus();//设置为焦点
                        return;
                    }

                    else
                    {
                        //跳转到time,然后登录,设置两个time函数,一种超级用户,一种普通用户,        time1为root
                        if (uname == "root" || uname=="a" || uname=="admin")
                        {
                            pictureBox1.Show();
                            timer1.Start();
                        }

                        else
                        {
                            pictureBox2.Show();
                            timer2.Start();

                        }
                        textBox1.Hide();
                        textBox2.Hide();
                        label1.Hide();
                        label2.Hide();
                        label3.Hide();
                        button1.Hide();
                        button2.Hide();

                        
                     
                    }
                }

                catch
                {
                    MessageBox.Show("数据库判断尝试失败","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    return;
                }
               

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            pictureBox1.Hide();
            textBox1.Text = "";
            textBox2.Text = "";
            textBox1.Focus();
        }

        private void label3_Click(object sender, EventArgs e)
        {
            Form3 f3 = new Form3();
            f3.Show();
            this.Hide();
            label3.ForeColor = Color.Red;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {

            DialogResult dr = MessageBox.Show("是否退出?", "提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

            if (dr == DialogResult.OK)   //如果单击“是”按钮
            {
                System.Environment.Exit(0);     //退出全部线程
            }
            else if (dr == DialogResult.C
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值