private void btnDLSql_Click(object sender, RoutedEventArgs e) { List <tBan> tempList = getBanListFromController(); Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.FileName = "a3bans"; dlg.DefaultExt = ".text"; dlg.Filter = "Text documents (.txt)|*.txt"; dlg.CreatePrompt = true; dlg.OverwritePrompt = true; Nullable <bool> result = dlg.ShowDialog(); if (result == true) { // Save document string filename = dlg.FileName; } System.IO.StreamWriter file = new System.IO.StreamWriter(dlg.FileName, false); for (int i = 0; i < tempList.Count; i++) { tBan newBan = new tBan(); file.Write(newBan.GuidOrIP = tempList[i].GuidOrIP.ToString()); file.Write(" "); file.Write(newBan.BanTime = tempList[i].BanTime.ToString()); file.Write(" "); file.WriteLine(newBan.BanReason = tempList[i].BanReason.ToString()); } file.Close(); }
private void btnSearch_Click(object sender, RoutedEventArgs e) { Classes.tBan bans = new tBan(); using (var client = new HttpClient()) { //client.BaseAddress = new Uri("http://192.223.30.108:55071/"); client.BaseAddress = new Uri("http://localhost:55071/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = null; try { tBan ban = new Classes.tBan(); ban.GuidOrIP = schGUID.Text; string serializedBan = JsonConvert.SerializeObject(ban); StringContent content = new StringContent(serializedBan, Encoding.UTF8, "application/json"); response = client.PostAsync("A3Bans/SearchBan", content).Result; } catch (Exception ex) { MessageBox.Show("Player ban does not exist"); } if (response.IsSuccessStatusCode) { string strResponse = response.Content.ReadAsStringAsync().Result; try { banReponse = JsonConvert.DeserializeObject <Classes.tBan>(strResponse); } catch (Exception ex) { MessageBox.Show(ex.Message); } } // banReponse.BanReason = schReason.Text; //ID OWNER GUID REASON PROOF schBanID.Text = banReponse.BanID; schGUID.Text = banReponse.GuidOrIP; schReason.Text = banReponse.BanReason; schProof.Text = banReponse.Proof; //schOwnerID.Text = banReponse.OwnerID; } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { { Login SqlLogin = new Login(); SqlLogin.ShowDialog(); { tAuthenticationResponse authenticationResult = new Classes.tAuthenticationResponse(); using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:55071/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); tCredential credential = new Classes.tCredential(); credential.Username = SqlLogin.txtSqlUserName.Text; credential.Password = SqlLogin.txtSqlPassword.Password; string serializedBan = JsonConvert.SerializeObject(credential); StringContent content = new StringContent(serializedBan, Encoding.UTF8, "application/json"); HttpResponseMessage response = client.PostAsync("A3Bans/LogIn", content).Result; if (response.IsSuccessStatusCode) { string strResponse = response.Content.ReadAsStringAsync().Result; authenticationResult = JsonConvert.DeserializeObject <tAuthenticationResponse>(strResponse); } } if (authenticationResult.AuthenticationSuccess) { this.Hide(); Classes.tBan bans = new tBan(); using (var client = new HttpClient()) { //client.BaseAddress = new Uri("http://192.223.30.108:55071/"); client.BaseAddress = new Uri("http://localhost:55071/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = null; try { tBan ban = new Classes.tBan(); ban.GuidOrIP = schGUID.Text; string serializedBan = JsonConvert.SerializeObject(ban); StringContent content = new StringContent(serializedBan, Encoding.UTF8, "application/json"); response = client.PostAsync("A3Bans/deleteBan", content).Result; } catch (Exception ex) { MessageBox.Show("Player ban does not exist"); } if (response.IsSuccessStatusCode) { string strResponse = response.Content.ReadAsStringAsync().Result; try { banReponse = JsonConvert.DeserializeObject <Classes.tBan>(strResponse); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } else { MessageBox.Show(authenticationResult.Message); } } } }