Exemplo n.º 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 button_DeleteEntry_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Sure?", "Delete DB Entry", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dialogResult == DialogResult.Yes)
            {
                TypeSendDBUpdate instruc = new TypeSendDBUpdate();
                instruc.WhereIDIs    = Convert.ToInt32(textBox_ID.Text);
                instruc.deleteFromDB = true;
                TypeReturnDBChanged answer = SqlAndWeb.httpPostWithErrorCheckAndPassword <TypeReturnDBChanged>(instruc, textBox_ServerAddress.Text, _Password);
                MessageBox.Show("Lines Affected=" + answer.linesAffected, "DB Change Info");
            }
        }
        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);
            }
        }
        private void button_SaveChanges_Click(object sender, EventArgs e)
        {
            TypeSendDBUpdate instruc = new TypeSendDBUpdate();

            instruc.WhereIDIs     = Convert.ToInt32(textBox_ID.Text);
            instruc.newVoorNaam   = textBox_Voornaam.Text;
            instruc.newAchterNaam = textBox_Achternaam.Text;
            if (_TheImage != null)
            {
                instruc.newBase64ProfileImage = Conversion.imageToBase64String(_TheImage);
            }
            else
            {
                instruc.newBase64ProfileImage = "GeenPlaatje";
            }
            TypeReturnDBChanged answer = SqlAndWeb.httpPostWithErrorCheckAndPassword <TypeReturnDBChanged>(instruc, textBox_ServerAddress.Text, _Password);

            MessageBox.Show("Lines Affected=" + answer.linesAffected, "DB Change Info");
            button_CancelChanges_Click(null, null); // disable buttons
        }
Exemplo n.º 5
0
        //Ok 10-40MS
        /// <summary>
        /// update DB return affected lines ( ja dat is handig )
        /// </summary>
        /// <param name="_inObject"></param>
        /// <returns></returns>
        public static string editDataFromDB(object _inObject)
        {
            try {
                string           wertkWel = JsonConvert.SerializeObject(_inObject);
                TypeSendDBUpdate inObject = JsonConvert.DeserializeObject <TypeSendDBUpdate>(wertkWel);

                SqlCommand command = new SqlCommand();
                command.Parameters.AddWithValue("@whereID", inObject.WhereIDIs);
                if (inObject.deleteFromDB)
                {
                    command.CommandText = ("DELETE FROM " + settings.studentBDTableName + " WHERE id = @whereID");
                }
                else
                {
                    command.Parameters.AddWithValue("@voorNaam", inObject.newVoorNaam);
                    command.Parameters.AddWithValue("@achterNaam", inObject.newAchterNaam);
                    command.Parameters.AddWithValue("@profileImage", inObject.newBase64ProfileImage);
                    if (inObject.updateFingerprintTemplate)
                    {
                        command.Parameters.AddWithValue("@fingerprintTemplate", inObject.newBase64FingerprintTemplate);
                        command.CommandText = "UPDATE " + settings.studentBDTableName + " SET voorNaam=@voorNaam, achterNaam=@achterNaam, profileImage=@profileImage, fingerprintTemplate=@fingerprintTemplate WHERE ID=@whereID";
                    }
                    else
                    {
                        command.CommandText = "UPDATE " + settings.studentBDTableName + " SET voorNaam=@voorNaam, achterNaam=@achterNaam, profileImage=@profileImage WHERE ID=@whereID";
                    }
                }
                TypeReturnDBChanged response = new TypeReturnDBChanged();
                response.linesAffected = SqlAndWeb.SQLNonQuery(settings.connectionString, command);
                return(JsonConvert.SerializeObject(response));
            } catch (Exception ex) {
                TypeReturnError typeForError = new TypeReturnError();
                typeForError.why = "(editDataFromDB)" + ex.Message;
                return(JsonConvert.SerializeObject(typeForError));
            }
        }