private void button3_Click(object sender, EventArgs e)
 {
     if (raportId != 0)
     {
         file.IncarcaHeader();
         file.CreazaBonPdf();
     }
     else
     {
         MessageBox.Show("Selectati o inregistrare pentru a fi printat documentul");
     }
 }
Ejemplo n.º 2
0
        private void buttonPrintTicet_Click(object sender, EventArgs e)
        {
            #region Adaugare Furnizor
            {
                string sqlf = "SELECT COUNT(*) FROM Furnizori WHERE ID_furnizor = '" + textBoxCifF.Text + textBoxAdresaF.Text + "' ";

                SqlCommand cmdf = new SqlCommand(sqlf, con);
                con.Open();

                int valoaref = Convert.ToInt32(cmdf.ExecuteScalar());
                con.Close();

                if (valoaref == 0)
                {
                    f.Nume       = textBoxFurnizor.Text;
                    f.Adresa     = textBoxAdresaF.Text;
                    f.Cod_fiscal = textBoxCifF.Text;

                    bool success1 = fdal.Insert(f, con);
                    if (success1 == true)
                    {
                        MessageBox.Show("Furnizorul  a fost adaugat");
                        autocompleteFurnizori();
                    }
                    else
                    {
                        MessageBox.Show("Nu s a putut adauga furnizor");
                    }
                }
            }
            #endregion

            #region Adaugare Client
            {
                string sqlc = "SELECT COUNT(*) FROM Clienti WHERE ID_client = '" + textBoxCifC.Text + textBoxAdresaC.Text + "' ";

                SqlCommand cmdc = new SqlCommand(sqlc, con);
                con.Open();

                int valoarec = Convert.ToInt32(cmdc.ExecuteScalar());
                con.Close();

                if (valoarec == 0)
                {
                    c.Nume       = textBoxClient.Text;
                    c.Adresa     = textBoxAdresaC.Text;
                    c.Cod_fiscal = textBoxCifC.Text;

                    bool success2 = cdal.Insert(c, con);
                    if (success2 == true)
                    {
                        MessageBox.Show("Clientul a fost adaugat");
                        autocompleteFurnizori();
                    }
                    else
                    {
                        MessageBox.Show("Nu s a putut adauga Client");
                    }
                }
            }
            #endregion

            #region Adaugare Produs
            string sqlp = "SELECT COUNT(*) FROM Produse WHERE ID_produs = '" + textBoxTipProdus.Text + textBoxLot.Text + "' ";

            SqlCommand cmdp = new SqlCommand(sqlp, con);
            con.Open();

            int valoarep = Convert.ToInt32(cmdp.ExecuteScalar());
            con.Close();

            if (valoarep == 0)
            {
                p.Cod          = textBoxCodP.Text;
                p.Nume         = textBoxTipProdus.Text;
                p.Natura       = textBoxProdus.Text;
                p.Lot          = textBoxLot.Text;
                p.DataExpirare = textBoxDataExp.Text;


                bool success4 = pdal.Insert(p, con);
                if (success4 == true)
                {
                    MessageBox.Show("Produsul a fost adaugat");
                    autocompleteProduse();
                }
                else
                {
                    MessageBox.Show("Nu s a putut adauga produs");
                }
            }
            #endregion

            #region Creare raport


            r.Cod_produs    = textBoxTipProdus.Text + textBoxLot.Text;
            r.Cod_client    = textBoxCifC.Text + textBoxAdresaC.Text;
            r.Cod_furnizor  = textBoxCifF.Text + textBoxAdresaF.Text;
            r.Greutate_NET  = float.Parse(textBoxGreutateNet.Text);
            r.DataTimpI     = DateTime.Now;
            file.DataTichet = (DateTime.Now).ToString();
            DataTable dt1;
            dt1 = bdal.Select(con);
            int numar0       = int.Parse(dt1.Rows[0].ItemArray[0].ToString());
            int numar_bonuri = int.Parse(dt1.Rows[0].ItemArray[1].ToString());
            r.Numar_bon = numar0 + numar_bonuri;
            //
            file.NrTichet = (numar0 + numar_bonuri).ToString();
            //
            numar_bonuri++;
            b.Bonuri_printate = numar_bonuri;
            b.Primul_bon      = numar0;
            bool success3 = bdal.Update(b, con);



            #region INSERT IN RAPOARTE
            bool success = rdal.Insert(r, con);

            if (success == true)
            {
                MessageBox.Show("Raport creat cu succes");

                ParseTextBox();
                file.IncarcaHeader();
                file.CreazaBonPdf();
                //de verificat cand o sa printez tichet
                Clear();
            }
            else
            {
                MessageBox.Show("Nu s a putut crea");
            }
            con.Close();
            #endregion
            #endregion
        }