Exemplo n.º 1
0
        private void popisUslugaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormPopisUsluga FormPopisUsluga1 = new FormPopisUsluga();

            FormPopisUsluga1.Show();
        }
Exemplo n.º 2
0
        private void btn_okRezervirajUslugu_Click(object sender, EventArgs e)
        {
            //Nađi ID usluge.
            string ID_usluge = "";

            if (cb_usluga.SelectedIndex != -1)
            {
                try
                {
                    connection = new SqlConnection(connectionstring);
                    connection.Open();
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.ExitThread();
                }

                SqlCommand cmd = new SqlCommand("SELECT Id_usluge,Ime_usluge FROM USLUGE", connection);

                try
                {
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    DataTable      dt  = new DataTable();
                    sda.Fill(dt);

                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr["Ime_usluge"].ToString() == cb_usluga.SelectedItem.ToString())
                        {
                            ID_usluge = dr["Id_usluge"].ToString();
                        }
                    }
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Unesite uslugu za koju želite rezervirati termin.", "Nije unesena usluga", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // Provjeri jesu li sva polja ispunjena.
            if (tb_gostimeusluga.Text == "" || tb_gostprezimeusluga.Text == "" || tb_gostoibusluga.Text == "")
            {
                MessageBox.Show("Sva polja moraju biti popunjena (osim tipa usluge).", "Prazna polja", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                // Izvrši INSERT.
                string query = "INSERT INTO REZERVACIJE_USLUGA VALUES (@id_usluge, @datum_vrijeme, @gost_ime, @gost_prezime, @gost_oib, @placeno)";

                using (connection = new SqlConnection(connectionstring))
                {
                    using (SqlCommand cmd = new SqlCommand(query, connection))
                    {
                        // Oblikuj datum i vrijeme.
                        DateTime datumIVrijeme = DateTime.ParseExact(date_usluga.Text, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                        Console.WriteLine(datumIVrijeme);

                        // Unesi parametre.
                        connection.Open();
                        cmd.Parameters.AddWithValue("@id_usluge", ID_usluge);
                        cmd.Parameters.AddWithValue("@datum_vrijeme", datumIVrijeme);
                        cmd.Parameters.AddWithValue("@gost_ime", tb_gostimeusluga.Text);
                        cmd.Parameters.AddWithValue("@gost_prezime", tb_gostprezimeusluga.Text);
                        cmd.Parameters.AddWithValue("@gost_oib", tb_gostoibusluga.Text);
                        cmd.Parameters.AddWithValue("@placeno", "false");
                        //cmd.ExecuteScalar();
                        cmd.ExecuteNonQuery();
                    }
                }
                FormPopisUsluga natrag = new FormPopisUsluga();
                natrag.Show();
                this.Close();
            }
        }