登录窗体:
using MyWPFTest.bean;
using MyWPFTest.domain;using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows;
using System.Windows.Media;
namespace MyWPFTest
{
/// <summary>
/// LoginWindow.xaml 的交互逻辑
/// </summary>
public partial class LoginWindow : Window
{
SqlConnection con = null;
UserLogin userLogin = null;
private int errorTime = 3; //计时
public LoginWindow()
{
InitializeComponent();
this.WindowStyle = System.Windows.WindowStyle.None;//去掉边框
this.AllowsTransparency = true;//透明
// this.Background = Brushes.Transparent;//背景透明5
}
public LoginWindow(SqlConnection con)
{
InitializeComponent();
this.con = con;
}
public LoginWindow(UserLogin user)
{
InitializeComponent();
this.userLogin = user;
}
//连接db
private DataSet getSql(String sql, String table)
{
string severAddr = "DESKTOP-LLMFC4D";
// String userName = "sa";
//String password = "root";
try{
SqlConnection con = MSSQLDAO.MSSQLDAO.getCon(severAddr, "sa", "root", "123");
if (con != null){
DataSet ds = MSSQLDAO.MSSQLDAO.getDataSet(sql, table, con);
//con.Close();
return ds;
}
else
{
return null;
}
}
catch (Exception ex) {
MessageBox.Show("数据库连接失败!"+ex.ToString());
return null;
}
}
//登录事件处理
private void login_Click(object sender, RoutedEventArgs e)
{
String name = this.user.Text.Trim();
String pwd = this.password.Password.Trim();
try {
if ((name != "") && (pwd != ""))
{
String table = "t_user"; //所要操作的表
string sql = "select userName,userPassword from t_user where userName='" + name + "' and userPassword='" + pwd + "'";
DataSet ds = getSql(sql, table);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
Object o = MessageBox.Show("登录成功!"); //登录成功
//this.Close();
new MainWindow().Show();
this.Close();
}
else {
MessageBox.Show("登录失败,用户名或密码不正确!");
this.password.Password = null;
}
}
else if (name.Equals("admin") || name.Equals("1")) //测试
{
new MainWindow().Show();
this.Close(); ;
}
else
{
MessageBox.Show("登录失败,用户名或者密码不能为空!");
}
} catch (Exception ex) {
MessageBox.Show("登录失败....!"+ex.Message);
}
}
//取消事件处理 ,退出程序
private void cancel_Click(object sender, RoutedEventArgs e)
{
this.Hide();
this.Close();
Application.Current.Shutdown();
// Application.Current.Exit;
}
//登录db
private void admin_Click(object sender, RoutedEventArgs e)
{
User user = new User();
user.SeverAddr = "";
user.UserName = "";
user.Password = "";
user.Database = "123";
this.Hide();
new MainWindow(user).Show();
}
}
}
登录成功窗体--主窗体:
using MyWPFTest.bean;
using MyWPFTest.model;
using MyWPFTest.socket;
using MyWPFTest.view;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows;
using System.Windows.Controls;
namespace MyWPFTest
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
Server server = null; //当前socket服务
SqlConnection con = null;
User user=null;
Customer customer = null;
public MainWindow()
{
InitializeComponent();
}
public delegate void ServerPrint(String info);
public MainWindow(SqlConnection con)
{
this.con = con;
InitializeComponent();
}
public MainWindow(User user)
{
this.user = user;
InitializeComponent();
//this.user = user;
}
//连接db
private DataSet getSql(String sql, String table)
{
string severAddr = "WIN-01801291735\\JUNSQLSERVER";
SqlConnection con = MSSQLDAO.MSSQLDAO.getCon(severAddr, this.user.UserName, this.user.Password, this.user.Database);
DataSet ds = MSSQLDAO.MSSQLDAO.getDataSet(sql, table, con);
con.Close();
return ds;
}
//查询处理
private void query_Click(object sender, RoutedEventArgs e)
{
//String table = "t_user"; //所要操作的表
//String sql = "select userName,userPassword from t_user order by id";
}
/*查询用户缴费信息事件处理---打开查询窗口*/
private void query_exchang_Click(object sender, RoutedEventArgs e)
{
//假如没有开启服务,则开启,否则就可以查询信息
new QueryByInfo().Show();
//把查询结果经过委托事件显示在主窗体
QueryByInfo qbi = new QueryByInfo();
//rtbox_msg.ClearValue(); //清空面板中的数据
qbi.queryPostMsg += Ss_postMsg;
// qbi.Show();
this.customer =qbi.Customer;
if (customer != null)
{
qbi.Close();
}
else {
//qbi.Show();
}
}
//启动service服务--打开socket连接窗口
private void startService_Click(object sender, RoutedEventArgs e)
{
StartService ss = new StartService();
ss.postMsg += Ss_postMsg;
//当当前服务已经启动的时候,显示为停止
if (this.server == null)
{
ss.button_QueryInfo.Content = "启动服务";
}
else {
ss.Server = this.server;
ss.b