Frm_Login.xaml.cs 4.17 KB
using HHECS;
using HHWCS.Bll;
using HHWCS.Model;
using HHWCS.Model.ClientModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace HHWCSHost.View
{
    /// <summary>
    /// Frm_Login.xaml 的交互逻辑
    /// </summary>
    public partial class Frm_Login : Window
    {
        public Frm_Login()
        {
            InitializeComponent();
        }

        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            //HttpClient httpClient = new HttpClient();
            //HttpContent content = new 
            //httpClient.PostAsync();
            AppCommon.User.UserName = txt_UserName.Text;
            Frm_Main frm_Main = new Frm_Main
            {
                WindowState = WindowState.Maximized
            };
            frm_Main.Show();
            this.Hide();
            //KeyValuePair<string, string> keyValuePair = new KeyValuePair<string, string>("ids", "1");
            //HttpContent content = new FormUrlEncodedContent(new List<KeyValuePair<string, string>>() { keyValuePair });
            //content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/x-www-form-urlencoded");
            //var ret = await AppCommon.Client.PostAsync("/task/task/complete", content);
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Application.Current.Shutdown();
        }

        private async void Btn_Login_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                LoginModel loginModel = new LoginModel()
                {
                    Code = txt_UserName.Text,
                    Password = Password.Password
                };
                //HttpContent content = new StringContent(JsonConvert.SerializeObject(loginModel));
                //content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                //var ret = await AppCommon.Client.PostAsync("/mobile/login", content);
                //if (ret.IsSuccessStatusCode)
                //{
                //    ret.EnsureSuccessStatusCode();
                //    string temp = await ret.Content.ReadAsStringAsync();
                //    var b = JsonConvert.DeserializeObject<ResponseModel<List<WarehouseModel>>>(temp);
                //    if (b.Code == "200")
                //    {
                //        AppCommon.User.UserName = txt_UserName.Text;
                //        Frm_Main frm_Main = new Frm_Main
                //        {
                //            WindowState = WindowState.Maximized
                //        };
                //        frm_Main.Show();
                //        this.Hide();
                //    }
                //    else
                //    {
                //        MessageBox.Show(b.Msg);
                //    }
                //}
                var ret = await AppCommon.Bll.Login(loginModel.Code, loginModel.Password);
                if (ret.Success)
                {
                    var a = AppSession.Bll.GetUserWithRoles("admin", "123456");
                    App.User = a.Data;
                    App.MenuOperations = AppSession.Bll.FindMenuOperation(App.User.Roles).Data;
                    AppCommon.User.UserName = txt_UserName.Text;
                    AppCommon.User.Password = loginModel.Password;
                    Frm_Main frm_Main = new Frm_Main
                    {
                        WindowState = WindowState.Maximized
                    };
                    frm_Main.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show(ret.Msg);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("登录失败:" + ex.Message);
            }
        }
    }
}