Пример #1
0
        private void btnIspis_Click(object sender, EventArgs e)
        {
            Racun_ispis ispis = new Racun_ispis();

            ispis.Show();
        }
Пример #2
0
        private void btnZakljuci_Click(object sender, EventArgs e)
        {
            //Unos stavaka sa dgv u bazu
            if (cboxKupci.Text != "")
            {
                try
                {
                    string          config = "datasource=localhost;port=3306;username=racuni;password=pass123;charset=utf8;";
                    MySqlConnection con    = new MySqlConnection(config);
                    string          query  = "INSERT INTO racuni.stavke(id_racun, id_usluge, kolicina, cijena, iznos)" +
                                             "VALUES (@id_racun, @id_usluge, @kolicina, @cijena, @iznos);";

                    MySqlCommand cmd = new MySqlCommand(query, con);
                    con.Open();

                    for (int row = 0; row < dataGridView1.Rows.Count; row++)
                    {
                        cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue(
                            "@id_racun", brRac);
                        cmd.Parameters.AddWithValue(
                            "@kolicina", int.Parse(dataGridView1.Rows[row].Cells[2].Value.ToString()));
                        cmd.Parameters.AddWithValue(
                            "@cijena", double.Parse(dataGridView1.Rows[row].Cells[3].Value.ToString()));
                        cmd.Parameters.AddWithValue(
                            "@iznos", double.Parse(dataGridView1.Rows[row].Cells[4].Value.ToString()));
                        cmd.Parameters.AddWithValue(
                            "@id_usluge", double.Parse(dataGridView1.Rows[row].Cells[5].Value.ToString()));

                        cmd.ExecuteNonQuery();
                    }
                    //reset za novi racun
                    brojacStavke = 0;
                    con.Close();
                    dataGridView1.Rows.Clear();
                    dataGridView1.Refresh();
                    txtKolicina.Clear();
                    cboxKupci.ResetText();
                    cboxUsluge.ResetText();
                }
                catch (MySqlException er)
                {
                    MessageBox.Show("Error:" + er.ToString());
                }


                //unos računa u bazu
                lblDatum.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                double iznosRacuna = double.Parse(labIznosRn.Text);
                double pdvRacuna   = double.Parse(labPdvRn.Text);
                double ukupanIznos = double.Parse(lblUkRn.Text);
                try
                {
                    string constring = "datasource=localhost;port=3306;username=racuni;password=pass123;charset=utf8;";
                    string upit      = "INSERT INTO racuni.racun (broj, iznos, pdv, ukupno, datum, id_kupac) " +
                                       "VALUES (@broj, @iznos, @pdv, @ukupno, @datum, @id_kupac);";
                    MySqlConnection bazaspoj = new MySqlConnection(constring);
                    MySqlCommand    cmd2     = new MySqlCommand(upit, bazaspoj);
                    bazaspoj.Open();

                    cmd2.Parameters.Clear();
                    cmd2.Parameters.AddWithValue(
                        "@broj", brRac.ToString() + "/1/1");
                    cmd2.Parameters.AddWithValue(
                        "@iznos", iznosRacuna);
                    cmd2.Parameters.AddWithValue(
                        "@pdv", pdvRacuna);
                    cmd2.Parameters.AddWithValue(
                        "@ukupno", ukupanIznos);
                    cmd2.Parameters.AddWithValue(
                        "@datum", lblDatum.Text);
                    cmd2.Parameters.AddWithValue(
                        "@id_kupac", txtSifraKupca.Text);
                    cmd2.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                MessageBox.Show("Zaključeno");
                //reset ostatka forme za novi racun
                iznos            = 0;
                pdv              = 0;
                ukupno           = 0;
                txtBrRacuna.Text = (brRac += 1).ToString() + "/1/1";//uvecaj broj rn za 1 kod uspjesnog unosa
                lblUkRn.Text     = "";
                labIznosRn.Text  = "";
                labPdvRn.Text    = "";
                labAdresa.Text   = "";
                labOib.Text      = "";
                labTelefon.Text  = "";
                lblDatum.Text    = DateTime.Now.ToString("yyyy-MM-dd");
                Racun_ispis ispis = new Racun_ispis();
                ispis.Show();
            }
            else
            {
                MessageBox.Show("Odaberi kupca.");
            }
        }