using BO.Utils; using BWP.WinFormControl; using Forks.JsonRpc.Client; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace ButcherManageClient { public partial class Login : Form { bool rpcFacadeInited = false; void IniteRpcFacade() { if (rpcFacadeInited) return; if (string.IsNullOrEmpty(ButcherAppContext.Context.UrlConfig.ServerUrl)) throw new Exception("请先设置服务器地址"); RpcFacade.Init(ButcherAppContext.Context.UrlConfig.ServerUrl, "B3ButcherManageClient"); rpcFacadeInited = true; } public Login() { InitializeComponent(); userNameTxt.Text = ButcherAppContext.Context.UserConfig.UserName; pwdTxt.Text = "123"; } private void settingBtn_Click(object sender, EventArgs e) { var f = new SettingForm(rpcFacadeInited); f.ShowDialog(); } private async void loginBtn_Click(object sender, EventArgs e) { var username = userNameTxt.Text.Trim(); var pwd = pwdTxt.Text; if (string.IsNullOrEmpty(username)) throw new Exception("请输入用户名"); IniteRpcFacade(); await Task.Factory.StartNew(() => RpcFacade.Login(username, pwd)); LoginRpcUtil.FillUserEmpInfo(username, ButcherAppContext.Context.UserConfig); ButcherAppContext.Context.Save(); var form = AfterLoginUtil.CreateForm(ButcherAppContext.Context.UserConfig.Role); if (form == null) throw new Exception("权限不符"); form.FormClosing += delegate { SubFormClosing(); }; form.Show(); Hide(); } void SubFormClosing() { foreach (Form form in Application.OpenForms) { if (form is Login) { form.Show(); return; } } } private void closeBtn_Click(object sender, EventArgs e) { Application.Exit(); } private void userNameTxt_Click(object sender, EventArgs e) { IniteRpcFacade(); var keyBoard = new NumberPad(); if (keyBoard.ShowDialog() == true) { string errorInfo; userNameTxt.Text = LoginRpcUtil.GetUserNameByCode(keyBoard.Result, out errorInfo); if (string.IsNullOrEmpty(userNameTxt.Text)) throw new Exception("工号输入错误"); if (!string.IsNullOrEmpty(errorInfo)) MessageBox.Show(errorInfo); } } private void pwdTxt_Click(object sender, EventArgs e) { var keyBoard = new VirtualKeyPad(); if (keyBoard.ShowDialog() == true) pwdTxt.Text = keyBoard.Result; } private void AutoUpdate() { if (!File.Exists("AutoUpdate.exe")) return; var version = string.Empty; if (File.Exists("Version.txt")) { version = File.ReadAllText("Version.txt"); } IniteRpcFacade(); var files = LoginRpcUtil.CheckVersion(version); if (string.IsNullOrEmpty(files)) return; var serverUrl = ButcherAppContext.Context.UrlConfig.ServerUrl.Replace("Rest.aspx", ""); if (!serverUrl.EndsWith("/")) serverUrl += "/"; serverUrl += "ClientVersion/"; System.Diagnostics.Process.Start(Path.Combine(Application.StartupPath, "AutoUpdate.exe"), serverUrl + "|" + files); Application.Exit(); } private void Login_Load(object sender, EventArgs e) { AutoUpdate(); } } }