Exemple #1
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            SqlCeConnection Connection = DataBaseConnection.Instance.Connection;

            try
            {
                if (First_nameTextBox.Text == "")
                {
                    MessageBox.Show("Unesite ime!");
                }
                else if (Last_nameTextBox.Text == "")
                {
                    MessageBox.Show("Unesite prezime!");
                }
                else if (Access_levelTextBox.Text == "")
                {
                    MessageBox.Show("Unesite nivo pristupa!");
                }


                else
                {
                    bool isUnique = UserRepository.CheckUnique(First_nameTextBox.Text);

                    if (isUnique != true)
                    {
                        UserRepository.InsertUser(First_nameTextBox.Text, First_nameTextBox.Text + Last_nameTextBox.Text);
                        int WorkpeopleId = UserRepository.GetIdByName(First_nameTextBox.Text);

                        SqlCeCommand command = new SqlCeCommand("INSERT INTO Workpeople (First_name, Last_name, Phone_number, Address, Access_level, User_Id) VALUES" + " ('" + First_nameTextBox.Text + "', '" + Last_nameTextBox.Text + "', '" + Phone_numberTextBox.Text + "', '" + AddressTextBox.Text + "', '" + Access_levelTextBox.Text + "', '" + WorkpeopleId + "'); ", Connection);

                        command.ExecuteNonQuery();

                        MessageBox.Show("Unos je uspio!");
                        First_nameTextBox.Clear();
                        Last_nameTextBox.Clear();
                        Phone_numberTextBox.Clear();
                        AddressTextBox.Clear();
                        Access_levelTextBox.Clear();
                        First_nameTextBox.Focus();
                    }
                }
            }

            catch (Exception ee)
            {
                MessageBox.Show("Unos nije uspio! \r Greska: " + ee.Message);
                return;
            }
        }
Exemple #2
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            SqlCeConnection Connection = DataBaseConnection.Instance.Connection;

            try
            {
                if (First_nameTextBox.Text == "")
                {
                    MessageBox.Show("Unesite ime!");
                }
                else if (Last_nameTextBox.Text == "")
                {
                    MessageBox.Show("Unesite prezime!");
                }
                else if (Date_of_birthTextBox.Text == "")
                {
                    MessageBox.Show("Unesite godinu rodjenja!");
                }
                else
                {
                    bool isUnique = UserRepository.CheckUnique(First_nameTextBox.Text);
                    if (isUnique != true)
                    {
                        UserRepository.InsertUser(First_nameTextBox.Text, First_nameTextBox.Text + Last_nameTextBox.Text);
                        int PlayerId = UserRepository.GetIdByName(First_nameTextBox.Text);

                        SqlCeCommand command = new SqlCeCommand("INSERT INTO Player (First_name, Last_name, Date_of_birth, User_Id) VALUES" + " ('" + First_nameTextBox.Text + "', '" + Last_nameTextBox.Text + "', '" + Date_of_birthTextBox.Value.Date.ToString("yyyy-MM-dd") + "', '" + PlayerId + "'); ", Connection);
                        command.ExecuteNonQuery();

                        MessageBox.Show("Unos je uspio!");
                        First_nameTextBox.Clear();
                        Last_nameTextBox.Clear();
                        First_nameTextBox.Focus();
                    }
                }
            }

            catch (Exception ee)
            {
                MessageBox.Show("Unos nije uspio! \r Greska: " + ee.Message);
                return;
            }
        }