Пример #1
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            bool ok = int.TryParse(this.textBoxNumero.Text, out numero) && numero > 0;

            if (ok)
            {
                StructContact contact = persitanceContact.GetContact(numero);
                if (persitanceContact.DeleteContact(contact))
                {
                    MessageBox.Show("Suppression réussie");
                    Trace.TraceInformation(DateTime.Now + " Suppression du contact : " + textBoxNumero.Text + "\n");
                }
                else
                {
                    MessageBox.Show("Contact inexistant", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Trace.Fail(DateTime.Now + " Tentative de suppression du contact inexistant : " + textBoxNumero.Text + "\n");
                }
            }
            else
            {
                MessageBox.Show("Numéro invalide", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Trace.Fail(DateTime.Now + " Tentative de suppression numero invalide : " + textBoxNumero.Text + "\n");
            }
            Trace.Flush();
        }
Пример #2
0
        public int AddContact(StructContact contact)
        {
            if (sqlConnection.State != System.Data.ConnectionState.Open)
            {
                sqlConnection.Open();
            }

            SqlParameter pOut = null;

            try
            {
                SqlCommand sqlCommand = new SqlCommand("CreateContact", sqlConnection);

                sqlCommand.CommandType = CommandType.StoredProcedure;

                pOut           = new SqlParameter("@id", SqlDbType.Int);
                pOut.Direction = ParameterDirection.Output;
                sqlCommand.Parameters.Add(pOut);

                sqlCommand.Parameters.Add(new SqlParameter("@prue_contact", contact.satisfaction));
                sqlCommand.Parameters.Add(new SqlParameter("@pnum_rue_contact", contact.num_rue));
                sqlCommand.Parameters.Add(new SqlParameter("@pnom_contact", contact.num_rue));
                sqlCommand.Parameters.Add(new SqlParameter("@pville_contact", contact.ville));
                sqlCommand.Parameters.Add(new SqlParameter("@pcp_contact", contact.code_postal));
                sqlCommand.Parameters.Add(new SqlParameter("@ppersonne_contact", contact.nom));
                sqlCommand.Parameters.Add(new SqlParameter("@psatisfaction_contact", contact.satisfaction));

                if (sqlCommand.ExecuteNonQuery() == 1)
                {
                    Trace.TraceInformation($"{DateTime.Now} Création du contact {contact.nom}");
                }
                else
                {
                    Trace.TraceError($"{DateTime.Now} Execution échouée de la création du contact {contact.nom}");
                }
            }
            catch (Exception e)
            {
                Trace.TraceError($"{DateTime.Now} Execution échouée de la création d'un contact {e.Message}");
            }

            Trace.Flush();

            if (sqlConnection.State != ConnectionState.Closed)
            {
                sqlConnection.Close();
            }
            return((int)pOut.Value);
        }
Пример #3
0
        public bool UpdateContact(StructContact contact)
        {
            bool success = false;

            if (sqlConnection.State != ConnectionState.Open)
            {
                sqlConnection.Open();
            }

            try
            {
                SqlCommand sqlCommand = new SqlCommand("UpdateContact", sqlConnection);

                sqlCommand.CommandType = CommandType.StoredProcedure;

                sqlCommand.Parameters.Add(new SqlParameter("@pid_contact", contact.id));
                sqlCommand.Parameters.Add(new SqlParameter("@prue_contact", contact.satisfaction));
                sqlCommand.Parameters.Add(new SqlParameter("@pnum_rue_contact", contact.num_rue));
                sqlCommand.Parameters.Add(new SqlParameter("@pnom_contact", contact.num_rue));
                sqlCommand.Parameters.Add(new SqlParameter("@pville_contact", contact.ville));
                sqlCommand.Parameters.Add(new SqlParameter("@pcp_contact", contact.code_postal));
                sqlCommand.Parameters.Add(new SqlParameter("@ppersonne_contact", contact.nom));
                sqlCommand.Parameters.Add(new SqlParameter("@psatisfaction_contact", contact.satisfaction));

                sqlCommand.ExecuteNonQuery();
                success = true;

                Trace.TraceInformation($"{DateTime.Now} Mise à jour du contact {contact.nom}");
            }
            catch (Exception e)
            {
                Trace.TraceError($"{DateTime.Now} Execution échouée de la mise à jour du contact {contact.nom} {e.Message}");
            }

            if (sqlConnection.State != System.Data.ConnectionState.Closed)
            {
                sqlConnection.Close();
            }

            Trace.Flush();

            return(success);
        }
Пример #4
0
        public bool DeleteContact(StructContact contact)
        {
            bool success = false;

            if (sqlConnection.State != System.Data.ConnectionState.Open)
            {
                sqlConnection.Open();
            }

            try
            {
                SqlCommand sqlCommand = new SqlCommand("DeleteContact", sqlConnection);

                sqlCommand.CommandType = CommandType.StoredProcedure;

                sqlCommand.Parameters.Add(new SqlParameter("@pid_contact", contact.id));

                if (sqlCommand.ExecuteNonQuery() == 1)
                {
                    success = true;
                    Trace.TraceInformation($"{DateTime.Now} Suppression du contact {contact.nom}");
                }
            }
            catch (Exception e)
            {
                Trace.TraceError($"{DateTime.Now} Execution échouée de la supression du contact {contact.nom} {e.Message}");
            }

            Trace.Flush();

            if (sqlConnection.State != ConnectionState.Closed)
            {
                sqlConnection.Close();
            }
            return(success);
        }