//Ok 18-400MS /// <summary> /// get json with a list with DB data /// </summary> /// <param name="_inObject">typeForAskForBDEntry</param> /// <returns></returns> public static string getDataFromDB(object _inObject) { try { string wertkWel = JsonConvert.SerializeObject(_inObject); TypeAskDBEntry inObject = JsonConvert.DeserializeObject <TypeAskDBEntry>(wertkWel); SqlCommand command = new SqlCommand(); if (inObject.dontUseWhereGetAll) { if (inObject.getProfileImag) { command.CommandText = "SELECT id,voorNaam,achterNaam,profileImage FROM " + settings.studentBDTableName; } else { command.CommandText = "SELECT id,voorNaam,achterNaam FROM " + settings.studentBDTableName; } } else { if (inObject.getProfileImag) { command.Parameters.AddWithValue("@where", inObject.whereIdIs); command.CommandText = "SELECT id,voorNaam,achterNaam,profileImage FROM " + settings.studentBDTableName + " WHERE id = @where"; } else { command.Parameters.AddWithValue("@where", inObject.whereIdIs); command.CommandText = "SELECT id,voorNaam,achterNaam FROM " + settings.studentBDTableName + " WHERE id = @where"; } } DataTable queryResult = SqlAndWeb.SQLQuery(settings.connectionString, command); List <TypeReturnDBEntry> returnList = new List <TypeReturnDBEntry>(); foreach (DataRow row in queryResult.Rows) { TypeReturnDBEntry entry = new TypeReturnDBEntry(); entry.ID = (int)row["id"]; entry.voorNaam = (string)row["voorNaam"]; entry.achterNaam = (string)row["achterNaam"]; returnList.Add(entry); if (inObject.getProfileImag) { entry.base64profileImage = (string)row["profileImage"]; } } return(JsonConvert.SerializeObject(returnList)); } catch (Exception ex) { TypeReturnError typeForError = new TypeReturnError(); typeForError.why = "(getDataFromDB)" + ex.Message; return(JsonConvert.SerializeObject(typeForError)); } }
private void Button_Refresh_Click(object sender, EventArgs e) { File.WriteAllText("serverAdr.txt", textBox_ServerAddress.Text); button_EditEntry.Enabled = false; button_DeleteEntry.Enabled = false; listBox1.Items.Clear(); _AllNamesList.Clear(); TypeAskDBEntry reques = new TypeAskDBEntry(); reques.dontUseWhereGetAll = true; reques.getProfileImag = false; _AllNamesList = SqlAndWeb.httpPostWithErrorCheckAndPassword <List <TypeReturnDBEntry> >(reques, textBox_ServerAddress.Text, _Password); foreach (var x in _AllNamesList) { string guyToAdd = x.ID.ToString() + " " + x.voorNaam + " " + x.achterNaam; listBox1.Items.Add(guyToAdd); } }
/// <summary> /// get db entry with this id and fill in UI /// </summary> /// <param name="_ID"></param> private void updateUIWithID(int _ID) { try { TypeAskDBEntry request = new TypeAskDBEntry(); request.whereIdIs = _ID.ToString(); request.getProfileImag = true; request.dontUseWhereGetAll = false; List <TypeReturnDBEntry> awnser = SqlAndWeb.httpPostWithErrorCheckAndPassword <List <TypeReturnDBEntry> >(request, textBox_ServerAddress.Text, _Password); try { _TheImage = (Bitmap)Conversion.base64ToImage(awnser[0].base64profileImage); } catch { _TheImage = null; } pictureBox_ProfileImage.Image = _TheImage; textBox_ID.Text = awnser[0].ID.ToString(); textBox_Voornaam.Text = awnser[0].voorNaam; textBox_Achternaam.Text = awnser[0].achterNaam; } catch { pictureBox_ProfileImage.Image = null; textBox_ID.Text = "server connection failed"; textBox_Voornaam.Text = "server connection failed"; textBox_Achternaam.Text = "server connection failed"; } }