五丰称屠宰重客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

109 lines
3.3 KiB

using System;
using System.Data;
using System.IO;
using System.Windows.Forms;
using Forks.JsonRpc.Client;
using Forks.Utils.Data;
using Forks.Utils.IO;
namespace B3ButcherWeightClient {
public partial class Login : Form {
public Login() {
InitializeComponent();
using (TextReader reader = FS.OpenReader(ConfigUtil.ConfigFilePath, true)) {
NutFile nutFile = NutFile.Parse(reader);
txtBUser.Text = nutFile.AsString(ConfigItem.LastUser, "system");
}
}
private void Form1_Load(object sender, EventArgs e) {
}
private void btnLogin_Click(object sender, EventArgs e) {
ConfigUtil.Init();
if (!RpcUtil.IsInited) {
RpcFacade.Init(ConfigUtil.Url, "B3WuFengClient");
RpcUtil.IsInited = true;
}
string loginUser = txtBUser.Text.Trim();
string passWord = txtBPassword.Text.Trim();
string errorInfo;
var success = RpcUtil.Login(loginUser, passWord, out errorInfo);
if (!success)
if (!string.IsNullOrEmpty(errorInfo) && errorInfo != "无法连接到远程服务器") {
MessageBox.Show(errorInfo);
return;
}
Form main = new Main(this);
Hide();
using (var reader = FS.OpenReader(ConfigUtil.ConfigFilePath)) {
var nutFile = NutFile.Parse(reader);
nutFile.SetValue(ConfigItem.LastUser, loginUser);
using (var writer = FS.OpenWriter(ConfigUtil.ConfigFilePath)) {
nutFile.Write(writer);
}
}
main.Show();
}
private void btnSetConStr_Click(object sender, EventArgs e) {
Form setForm = new Setting();
setForm.ShowDialog();
}
private static bool CheckUser(string userName) {
var conStr = ConfigUtil.ConnectionStr;
if (string.IsNullOrEmpty(conStr)) {
MessageBox.Show("未设置本地数据库信息");
return false;
}
var isExist = false;
if (!string.IsNullOrEmpty(userName)) {
string sql = "select PassWord from LoginUser where UserName='" + userName.Trim() + "'";
try {
using (ISqlUtil sqlUtil = new SqlUtil(conStr)) {
DataSet dataSet = sqlUtil.ExecuteSql(sql);
if (dataSet.Tables[0].Rows.Count > 0) {
isExist = true;
}
}
} catch (Exception ex) {
MessageBox.Show(ex.Message);
return false;
}
}
return isExist;
}
private static bool CheckPassword(string userName, string password, out long userID, out string role) {
userID = 0;
role = "";
string conStr = ConfigUtil.ConnectionStr;
bool isRight = false;
string sql = "select top 1 ID,RoleSchema from LoginUser where UserName='" + userName.Trim() + "' and PassWord=cast('" + password.Trim() + "' as binary)";
try {
using (ISqlUtil sqlUtil = new SqlUtil(conStr)) {
DataSet dataSet = sqlUtil.ExecuteSql(sql);
if (dataSet.Tables[0].Rows.Count > 0) {
isRight = true;
userID = (long)dataSet.Tables[0].Rows[0][0];
role = (string)dataSet.Tables[0].Rows[0][1];
}
}
} catch (Exception ex) {
MessageBox.Show(ex.Message);
return false;
}
return isRight;
}
}
}