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 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.º 3
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));
            }
        }