예제 #1
0
 private void furnizoriToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (Furnizori load_furn = new Furnizori())
     {
         load_furn.ShowDialog();
     }
 }
예제 #2
0
        private void btnSalvare_Click(object sender, EventArgs e)
        {
            string       query = @"INSERT INTO Furnizori (furnizor_id, furnizor_nume, persoana_contact, cui, adresa, oras, regiune, codpostal, tara, telefon, fax, paginaweb, iban, banca) 
                                                    VALUES (@id, @nume, @persoana, @cui, @adresa, @oras, @regiune, @codpostal, @tara, @telefon, @fax, @web, @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(txtCodFurnizor.Text));
                                comanda.Parameters.AddWithValue("@nume", txtDenumireFurnizor.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);
                                }
                                // Pagina web
                                if (txtPaginaWeb.Text.ToString().Length > 0)
                                {
                                    comanda.Parameters.AddWithValue("@web", txtPaginaWeb.Text);
                                }
                                else
                                {
                                    comanda.Parameters.AddWithValue("@web", 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, "Furnizorul " + txtDenumireFurnizor.Text + " a fost inregistrat.\nRealizati alta inregistrare?", "Succes!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (dialog == DialogResult.Yes)
                            {
                                using (Furnizori f = new Furnizori())
                                {
                                    Hide();
                                    f.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 Furnizori SET furnizor_nume=@nume, banca=@banca, persoana_contact=@persoana, adresa=@adresa, oras=@oras,
                                            codpostal=@codpostal, tara=@tara, telefon=@telefon, fax=@fax, 
                                            paginaweb=@pagina WHERE furnizor_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", txtDenumireFurnizor.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("@pagina", txtPaginaWeb.Text);
                                comanda.Parameters.AddWithValue("@id", int.Parse(txtCodFurnizor.Text));
                                comanda.CommandType = CommandType.Text;
                                comanda.ExecuteNonQuery();
                            }
                            dialog = MetroFramework.MetroMessageBox.Show(this, "Datele furnizorului " + txtDenumireFurnizor.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);
                }
            }
        }