Frm_Login.xaml.cs
4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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);
}
}
}
}