Exemple #1
0
 private void btnSpreComenzi_Click(object sender, EventArgs e)
 {
     using (ComenziF ff = new ComenziF())
     {
         ff.ShowDialog();
     }
 }
 private void furnizoriToolStripMenuItem1_Click(object sender, EventArgs e)
 {
     using (ComenziF comenziFurn = new ComenziF())
     {
         comenziFurn.ShowDialog();
     }
 }
Exemple #3
0
        private void btnSaveComanda_Click(object sender, EventArgs e)
        {
            string           query           = @"INSERT INTO Comenzi_Furnizori (comandaf_id, furnizor_id, angajat_id, datacomanda, datalimita, datalivrare) 
                                VALUES (@codcomanda, @codfurnizor, @codangajat, @datacomanda, @datalimita, @datalivrare)";
            string           query_detalii   = @"INSERT INTO Detalii_ComandaF (comandaf_id, mp_id, pret_unitar, cantitate, unitate_masura, discount, tva, total)
                                    VALUES (@codcomandaf, @mpid, @pretunitar, @cantitate, @unitatemasura, @discount, @tva, @total)";
            NpgsqlConnection conn            = new NpgsqlConnection(conexiune);
            NpgsqlCommand    comanda_detalii = new NpgsqlCommand(query_detalii, conn);
            NpgsqlCommand    comanda         = new NpgsqlCommand(query, conn);

            checkAllFieldsBeforeInsert();
            if (valid == true && gridProduse.Rows.Count > 0)
            {
                try
                {
                    conn.Open();

                    comanda.Parameters.Clear();
                    comanda.Parameters.AddWithValue("@codcomanda", int.Parse(txtNrComanda.Text));
                    comanda.Parameters.AddWithValue("@codfurnizor", genereazaIDFurnizor(cboAlegeFurnizor.SelectedItem.ToString()));
                    comanda.Parameters.AddWithValue("@codangajat", genereazaIDAngajat(cboAlegeAngajat.SelectedItem.ToString()));
                    comanda.Parameters.AddWithValue("@datacomanda", dtDataComanda.Value);
                    comanda.Parameters.AddWithValue("@datalimita", dtDataLimita.Value);
                    if (chkLivrata.Checked == true)
                    {
                        comanda.Parameters.AddWithValue("@datalivrare", dtDataLivrare.Value);
                    }
                    else
                    {
                        comanda.Parameters.AddWithValue("@datalivrare", DBNull.Value);
                    }
                    comanda.CommandType = CommandType.Text;
                    comanda.ExecuteNonQuery();
                    // Detaliile comenzii
                    for (int i = 0; i < gridProduse.Rows.Count - 1; ++i)
                    {
                        comanda_detalii.Parameters.Clear();
                        comanda_detalii.Parameters.AddWithValue("@codcomandaf", int.Parse(txtNrComanda.Text));
                        comanda_detalii.Parameters.AddWithValue("@mpid", genereazaIDMateriePrima(gridProduse[0, i].Value.ToString()));
                        comanda_detalii.Parameters.AddWithValue("@pretunitar", double.Parse(gridProduse[1, i].Value.ToString()));
                        comanda_detalii.Parameters.AddWithValue("@cantitate", double.Parse(gridProduse[2, i].Value.ToString()));
                        comanda_detalii.Parameters.AddWithValue("@unitatemasura", gridProduse[3, i].Value.ToString());
                        comanda_detalii.Parameters.AddWithValue("@discount", double.Parse(gridProduse[4, i].Value.ToString()));
                        comanda_detalii.Parameters.AddWithValue("@tva", double.Parse(gridProduse[5, i].Value.ToString()));
                        comanda_detalii.Parameters.AddWithValue("@total", double.Parse(gridProduse[6, i].Value.ToString()));
                        comanda_detalii.CommandType = CommandType.Text;
                        comanda_detalii.ExecuteNonQuery();
                    }
                    conn.Close();
                    DialogResult dialog = MetroFramework.MetroMessageBox.Show(this, @"Comanda cu nr. " + txtNrComanda.Text +
                                                                              " a fost inregistrata cu succes!\nDoriti sa inregistrati alta comanda?",
                                                                              "Comanda inregistrata", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dialog == DialogResult.Yes)
                    {
                        using (ComenziF comenzif = new ComenziF())
                        {
                            Hide();
                            comenzif.ShowDialog();
                        }
                    }
                    else
                    {
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    MetroFramework.MetroMessageBox.Show(this, "Nu s-a putut realiza inregistrarea comenzii.\n" + ex, "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }