Example #1
0
 private void clientiToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (Clienti clienti = new Clienti())
     {
         clienti.ShowDialog();
     }
 }
Example #2
0
        private void btnSalvare_Click(object sender, EventArgs e)
        {
            string       query = @"INSERT INTO Clienti 
                                (client_id, client_nume, persoana_contact, cui, adresa, oras, regiune, codpostal, tara, telefon, fax, iban, banca) 
                                                    VALUES (@id, @nume, @persoana, @cui, @adresa, @oras, @regiune, @codpostal, @tara, @telefon, @fax, @iban, @banca)";
            DialogResult dialog;

            // Adaugare
            if (mod_adaugare == true)
            {
                try
                {
                    checkBeforeAdd();
                    if (ok_to_add == true)
                    {
                        using (conn = new NpgsqlConnection(conexiune))
                        {
                            conn.Open();
                            using (NpgsqlCommand comanda = new NpgsqlCommand(query, conn))
                            {
                                comanda.Parameters.AddWithValue("@id", int.Parse(txtCodClient.Text));
                                comanda.Parameters.AddWithValue("@nume", txtDenumireClient.Text);
                                comanda.Parameters.AddWithValue("@persoana", txtPersContact.Text);
                                comanda.Parameters.AddWithValue("@cui", long.Parse(txtCUI.Text));
                                comanda.Parameters.AddWithValue("@adresa", txtAdresa.Text);
                                comanda.Parameters.AddWithValue("@oras", cboOras.SelectedItem.ToString());
                                comanda.Parameters.AddWithValue("@regiune", txtRegiune.Text);
                                // Cod postal
                                if (txtCodPostal.Text.ToString().Length > 0)
                                {
                                    comanda.Parameters.AddWithValue("@codpostal", int.Parse(txtCodPostal.Text));
                                }
                                else
                                {
                                    comanda.Parameters.AddWithValue("@codpostal", DBNull.Value);
                                }
                                // Tara
                                comanda.Parameters.AddWithValue("@tara", txtTara.Text);
                                // Telefon
                                if (txtTelefon.Text.ToString().Length > 0)
                                {
                                    comanda.Parameters.AddWithValue("@telefon", txtTelefon.Text);
                                }
                                else
                                {
                                    comanda.Parameters.AddWithValue("@telefon", DBNull.Value);
                                }
                                // Faxul
                                if (txtFax.Text.ToString().Length > 0)
                                {
                                    comanda.Parameters.AddWithValue("@fax", txtFax.Text);
                                }
                                else
                                {
                                    comanda.Parameters.AddWithValue("@fax", DBNull.Value);
                                }
                                // Iban si Banca
                                comanda.Parameters.AddWithValue("@iban", txtIBAN.Text);
                                comanda.Parameters.AddWithValue("@banca", cboBanca.SelectedItem.ToString());
                                comanda.CommandType = CommandType.Text;
                                comanda.ExecuteNonQuery();
                            }
                            dialog = MetroFramework.MetroMessageBox.Show(this, "Clientul " + txtDenumireClient.Text + " a fost inregistrat.\nRealizati alta inregistrare?", "Succes!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (dialog == DialogResult.Yes)
                            {
                                using (Clienti c = new Clienti())
                                {
                                    Hide();
                                    c.ShowDialog();
                                }
                            }
                            else
                            {
                                Close();
                            }
                        }
                    }
                }
                catch (NpgsqlException ex)
                {
                    MetroFramework.MetroMessageBox.Show(this, "Nu se poate adauga.\nMotiv:\n" + ex, "Atentie!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            // Ne ocupam de modificare acum
            string query_edit = @"UPDATE Clienti SET client_nume=@nume, banca=@banca, persoana_contact=@persoana, adresa=@adresa, oras=@oras,
                                            codpostal=@codpostal, tara=@tara, telefon=@telefon, fax=@fax
                                            WHERE client_id=@id";

            if (mod_editare == true)
            {
                try
                {
                    checkBeforeEdit();
                    if (ok_to_edit == true)
                    {
                        using (conn = new NpgsqlConnection(conexiune))
                        {
                            conn.Open();
                            using (NpgsqlCommand comanda = new NpgsqlCommand(query_edit, conn))
                            {
                                comanda.Parameters.AddWithValue("@nume", txtDenumireClient.Text);
                                comanda.Parameters.AddWithValue("@banca", cboBanca.SelectedItem.ToString());
                                comanda.Parameters.AddWithValue("@persoana", txtPersContact.Text);
                                comanda.Parameters.AddWithValue("@adresa", txtAdresa.Text);
                                comanda.Parameters.AddWithValue("@oras", cboOras.SelectedItem.ToString());
                                comanda.Parameters.AddWithValue("@codpostal", int.Parse(txtCodPostal.Text));
                                comanda.Parameters.AddWithValue("@tara", txtTara.Text);
                                comanda.Parameters.AddWithValue("@telefon", txtTelefon.Text);
                                comanda.Parameters.AddWithValue("@fax", txtFax.Text);
                                comanda.Parameters.AddWithValue("@id", int.Parse(txtCodClient.Text));
                                comanda.CommandType = CommandType.Text;
                                comanda.ExecuteNonQuery();
                            }
                            dialog = MetroFramework.MetroMessageBox.Show(this, "Datele clientului " + txtDenumireClient.Text + " au fost modificate.", "Succes!", MessageBoxButtons.OK, MessageBoxIcon.Question);
                            resetAfterEdit();
                        }
                    }
                }
                catch (NpgsqlException ex)
                {
                    MetroFramework.MetroMessageBox.Show(this, "Nu se poate edita.\nMotiv:\n" + ex, "Atentie!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }