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 System.Data.SqlClient;
using System.Data.Sql;
namespace MyProject
{
    public partial class 主界面 : Form
    {
     
               
        public 主界面()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            bool isValidUser = false;   // 标识是否为合法用户            
            string message = "";            if (ValidateInput())  // 验证输入成功,显示窗体
            {
                // 验证用户是否为合法用户
                isValidUser = ValidateUser(
                    textBox1.Text,
                    textBox2.Text,
                    comboBox1.Text,
                    ref message
                    );                // 如果是合法用户,就转到相应的窗体
                if (isValidUser)
                {
                    // 记录登录用户名和登录类型
                    UserHelper.loginId = textBox1.Text;
                    UserHelper.loginType = comboBox1.Text;
                    switch (comboBox1.Text)
                    {
                        case "单位用户":
                            单位用户主界面 unit = new 单位用户主界面();
                            unit.Show();
                            this.Hide();
                            break;                        case "管理员":
                            管理员主界面 admin = new 管理员主界面();
                            admin.Show();
                            this.Hide();
                            break;
                        case "专家用户":
                            专家用户主界面 expert = new 专家用户主界面(); ;
                            expert.Show();
                            this.Hide();
                            break;
                    }                }
                else  // 验证合法用户失败,给出提示
                {
                    MessageBox.Show(message, "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }        private bool ValidateInput()
        {
            if (textBox1.Text.Trim() == "")
            {
                MessageBox.Show("请输入用户名", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                textBox1.Focus();
                return false;
            }
            else if (textBox2.Text.Trim() == "")
            {
                MessageBox.Show("请输入密码", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                textBox2.Focus();
                return false;
            }
            else if (comboBox1.Text.Trim() == "")
            {
                MessageBox.Show("请选择登录类型", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                comboBox1.Focus();
                return false;
            }
            else
            {
                return true;
            }
        } 
            
       
      
      
       
    
 
        // 验证用户是否合法
        // 传入用户名、密码、登录类型
        // 合法返回 True,不合法返回 False
        // message 参数用来记录验证失败的原因
        private bool ValidateUser(string loginId, string loginPwd, string loginType, ref string message)
        {
            if (loginType == "管理员")
            {
                // 查询字符串
                string sql = string.Format("SELECT COUNT(*) FROM managerInformation where loginId ='{0}' AND loginPwd='{1}'",loginId, loginPwd);                // 测试数据库连接
                try
                {
                   // 创建 Command 对象
                  
                    SqlCommand command = new SqlCommand(sql, DBHelper.Connection);                    // 打开数据库连接
                    DBHelper.Connection.Open();
                    
                    // 验证是否为合法用户
                    int count = (int)command.ExecuteScalar();
                    if (count < 1)
                    {
                        message = "用户名或密码不存在!";
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
               catch (Exception ex)
                {
                    message = "操作数据库出错!";
                    Console.WriteLine(ex.Message);
                    return false;
                }
                finally
                {
                    // 关闭数据库连接
                    DBHelper.Connection.Close();
                   
                }
            }else 
                 if (loginType == "单位用户")
            {
                // 查询字符串
                string sql = string.Format("SELECT * FROM companyInformation where loginId ='{0}' AND loginPwd='{1}'",  loginId, loginPwd);
                DataTable dt = DBHelper.ExecuteDataTable(sql);
                              UserHelper.name = (string)dt.Rows[0]["companyName"];
                // 测试数据库连接
               try
                {
                    // 创建 Command 对象
                    SqlCommand command = new SqlCommand(sql, DBHelper.Connection);                    // 打开数据库连接
                    DBHelper.Connection.Open();                    // 验证是否为合法用户
                    int count = (int)command.ExecuteScalar();
                    if (count < 1)
                    {
                        message = "用户名或密码不存在!";
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
                catch (Exception ex)
                {
                    message = "操作数据库出错!";
                    Console.WriteLine(ex.Message);
                    return false;
                }
                finally
                {
                    // 关闭数据库连接
                    DBHelper.Connection.Close();
                }
            }
                 else if (loginType == "专家用户")
            {
                // 查询字符串
                string sql = string.Format("SELECT COUNT(*) FROM expertInformation where loginId ='{0}' AND loginPwd='{1}'",
                    loginId, loginPwd);                // 测试数据库连接
                try
                {
                    // 创建 Command 对象
                    SqlCommand command = new SqlCommand(sql, DBHelper.Connection);                    // 打开数据库连接
                    DBHelper.Connection.Open();                    // 验证是否为合法用户
                    int count = (int)command.ExecuteScalar();
                    if (count < 1)
                    {
                        message = "用户名或密码不存在!";
                        return false;
                    }
                    else
                    {
                        UserHelper.loginId = loginId;
                        return true;
                    }
                }
                catch (Exception ex)
                {
                    message = "操作数据库出错!";
                    Console.WriteLine(ex.Message);
                    return false;
                }
                finally
                {
                    // 关闭数据库连接
                    DBHelper.Connection.Close();
                }
                
            }
            message = "请选择类型登录";
            return false;
        }        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }      
        private void textBox1_TextChanged(object sender, EventArgs e)
        {        }
    }
}
代码如下。 提示错误错误 1 无法将文件“obj\x86\Debug\MyProject.exe”复制到“bin\Debug\MyProject.exe”。文件“bin\Debug\MyProject.exe”正由另一进程使用,因此该进程无法访问此文件。 MyProject
求帮助