Exemplo n.º 1
0
 public MainWindow(UserModel usr)
 {
     InitializeComponent();
     curUser = usr;
     prepareLoad();
     txtLocation.Text = usr.Address;
     txtSalesPerson.Text = usr.FullName;
     txtLocation.IsReadOnly = true;
     txtSalesPerson.IsReadOnly = true;
 }
Exemplo n.º 2
0
        private void checkServerStatus()
        {
            string serverPath = "";
            try
            {
                

                string basePath = AppDomain.CurrentDomain.BaseDirectory;
                string commonPath = basePath.Remove(basePath.Length - @"bin\debug\".Length);
                commonPath += "Config\\hostConfig.dat";
                

                using(StreamReader reader = new StreamReader(commonPath))
                {
                    
                    serverPath = reader.ReadLine();
                    txtPath.Text = serverPath;
                }
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(serverPath);

                client.DefaultRequestHeaders.Accept.Add(
                   new MediaTypeWithQualityHeaderValue("application/json"));
                UserModel usr = new UserModel();
                var response = client.PostAsJsonAsync("api/Users", usr).Result;
                if (response!=null)
                {
                    ServerPath.ServerPathName = txtPath.Text;
                    Login wnd = new Login();
                    wnd.Show();
                    this.Close();
                }
                
            }
            catch(System.Exception ex)
            {
                
                MessageBox.Show("Communication with server failed" + ex.GetType().ToString());
            }

            
        }
Exemplo n.º 3
0
        private void OnLogin(object sender, RoutedEventArgs e)
        {
            try
            {

                HttpClient client = new HttpClient();
                //client.BaseAddress = new Uri("http://localhost:62025/");
                client.BaseAddress = new Uri(ServerPath.ServerPathName);
                client.DefaultRequestHeaders.Accept.Add(
                   new MediaTypeWithQualityHeaderValue("application/json"));

                UserModel usr = new UserModel();
                usr.UserName = txtUserName.Text;
                usr.Password = txtPassword.Password;
                String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(txtUserName.Text + ":" + txtPassword.Password));
                client.DefaultRequestHeaders.Add("Authorization", "Basic " + encoded);
                var response = client.PostAsJsonAsync("api/Users", usr).Result;
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    var user = response.Content.ReadAsAsync<UserModel>().Result;
                    user.Password = txtPassword.Password;
                    MainWindow wnd = new MainWindow(user);
                    wnd.Show();
                    this.Close();
                }
                else
                {
                    if(response.StatusCode==HttpStatusCode.NotFound)
                        MessageBox.Show("Invalid Credentials");
                    txtUserName.Text = "";
                    txtPassword.Password = "";
                }
            }
            catch
            {
                MessageBox.Show("Communication with server failed");
            }
        }