Exemple #1
0
 //Ok
 /// <summary>
 /// voeg iemand to aan de DB
 /// </summary>
 /// <param name="_inObject"></param>
 /// <returns></returns>
 public static string newEntryToDB(object _inObject)
 {
     try {
         string             wertkWel  = JsonConvert.SerializeObject(_inObject);
         TypeSendNewDBEntry entryData = JsonConvert.DeserializeObject <TypeSendNewDBEntry>(wertkWel);
         SqlCommand         command   = new SqlCommand();
         command.Parameters.AddWithValue("@voorNaam", entryData.VoorNaam);
         command.Parameters.AddWithValue("@achterNaam", entryData.AchterNaam);
         command.Parameters.AddWithValue("@profileImage", entryData.Base64ProfileImage);
         command.Parameters.AddWithValue("@fingerprintTemplate", entryData.Base64FingerprintTemplate);
         command.CommandText = "INSERT INTO " + settings.studentBDTableName + " (voorNaam, achterNaam, profileImage, fingerprintTemplate) VALUES (@voorNaam,@achterNaam,@profileImage,@fingerprintTemplate)";
         TypeReturnDBChanged returnType = new TypeReturnDBChanged();
         returnType.linesAffected = SqlAndWeb.SQLNonQuery(settings.connectionString, command);
         //now get id of new entry
         SqlCommand comond = new SqlCommand();
         comond.CommandText = "select top 1 ID from " + settings.studentBDTableName + " order by ID desc";
         DataTable queryResult = SqlAndWeb.SQLQuery(settings.connectionString, comond);
         returnType.idOfNewDBEntry = (int)queryResult.Rows[0]["ID"];
         return(JsonConvert.SerializeObject(returnType));
     } catch (Exception ex) {
         TypeReturnError typeForError = new TypeReturnError();
         typeForError.why = "(newEntryToDB)" + ex.Message;
         return(JsonConvert.SerializeObject(typeForError));
     }
 }
        private void button4_Click(object sender, EventArgs e)
        {
            try {
                TypeSendNewDBEntry newEntry = new TypeSendNewDBEntry();
                newEntry.VoorNaam   = textBox_voornaam.Text;
                newEntry.AchterNaam = textBox_achternaam.Text;
                if (pictureBox4.Image != null)
                {
                    newEntry.Base64ProfileImage = Conversion.imageToBase64String((Bitmap)pictureBox4.Image);
                }
                else
                {
                    newEntry.Base64ProfileImage = "nietz";
                }

                if (checkBox_IM1_useThisOne.Checked)
                {
                    newEntry.Base64FingerprintTemplate = Convert.ToBase64String(Conversion.fingerprintImageToFingerprintTemplate((Bitmap)pictureBox1.Image));
                }
                else
                {
                    if (checkBox_IM2_useThisOne.Checked)
                    {
                        newEntry.Base64FingerprintTemplate = Convert.ToBase64String(Conversion.fingerprintImageToFingerprintTemplate((Bitmap)pictureBox2.Image));
                    }
                    else
                    {
                        if (checkBox_IM3_useThisOne.Checked)
                        {
                            newEntry.Base64FingerprintTemplate = Convert.ToBase64String(Conversion.fingerprintImageToFingerprintTemplate((Bitmap)pictureBox3.Image));
                        }
                        else
                        {
                            MessageBox.Show("select a fingerprint image to use", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                TypeReturnDBChanged resp = SqlAndWeb.httpPostWithErrorCheckAndPassword <TypeReturnDBChanged>(newEntry, _serverAdress, _password);
                MessageBox.Show("linesAfected=" + resp.linesAffected + " id of new person= " + resp.idOfNewDBEntry, "db update info");
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }