Пример #1
0
        private void GetData()
        {
            if (rozhodnutí)
            {
                string connectionString = "URI=file:Evidence_psu.db";

                // Determin the DataAdapter = CommandText + Connection
                string commandText = @"SELECT * FROM Osoby WHERE Osoba_id =" + contactId;
                // Make a new object
                helper = new dBHelper(connectionString);
                // Load the data
                if (helper.Load(commandText, "") == true)
                {
                    // Show the data in the datagridview
                    dataRow       = helper.DataSet.Tables[0].Rows[0];
                    textBox1.Text = dataRow[0].ToString();
                    textBox2.Text = dataRow[1].ToString();
                    textBox3.Text = dataRow[2].ToString();
                    textBox4.Text = dataRow[3].ToString();
                    textBox5.Text = dataRow[4].ToString();
                    textBox6.Text = dataRow[5].ToString();
                    textBox7.Text = dataRow[6].ToString();
                }
            }
            else
            {
                button1.Location = new Point(150, 185);
                button2.Location = new Point(21, 185);
                textBox4.Enabled = false;
                textBox5.Visible = false;
                textBox6.Visible = false;
                textBox7.Visible = false;
                label1.Text      = "Pes_ID:";
                label2.Text      = "Jmeno:";
                label3.Text      = "Osoba_ID:";
                label4.Text      = "Narozen:";
                label5.Visible   = false;
                label6.Visible   = false;
                label7.Visible   = false;

                string connectionString = "URI=file:Evidence_psu.db";

                // Determin the DataAdapter = CommandText + Connection
                string commandText = @"SELECT * FROM PSI WHERE Pes_id =" + contactId;
                // Make a new object
                helper = new dBHelper(connectionString);
                // Load the data
                if (helper.Load(commandText, "") == true)
                {
                    // Show the data in the datagridview
                    dataRow       = helper.DataSet.Tables[0].Rows[0];
                    textBox1.Text = dataRow[0].ToString();
                    textBox2.Text = dataRow[1].ToString();
                    textBox3.Text = dataRow[2].ToString();
                    textBox4.Text = dataRow[3].ToString();
                }
            }
        }
Пример #2
0
        void EditData(object sender, EventArgs e)
        {
            errorProvider1.Dispose();
            if (Edit)
            {
                if (textBox2.Text == string.Empty || textBox3.Text == string.Empty || textBox4.Text == string.Empty)        //příkaz zjišťující, jestli data označená jako "NotNULL" nejsou prázdná
                {
                    if (textBox2.Text == string.Empty)
                    {
                        errorProvider1.SetError(textBox2, "Kolonka se jménem nesmí být prázdná");
                    }
                    if (textBox3.Text == string.Empty)
                    {
                        errorProvider1.SetError(textBox3, "Kolonka se příjmením nesmí být prázdná");
                    }
                    if (textBox4.Text == string.Empty)
                    {
                        errorProvider1.SetError(textBox4, "Kolonka s obcí nesmí být prázdná");
                    }
                    return;
                }
                string connectionString = "URI=file:Evidence_psu.db";
                string commandText      = @"SELECT * FROM Osoby WHERE Osoba_id =" + contactId;
                helper = new dBHelper(connectionString);
                {
                    if (helper.Load(commandText, "Osoba_id") == true)
                    {
                        // Determin if the row was found
                        if (helper.DataSet.Tables[0].Rows.Count == 1)
                        {
                            // Determin the found row
                            DataRow dataRow = helper.DataSet.Tables[0].Rows[0];

                            // Modify the row
                            dataRow["Jmeno"]    = textBox2.Text;
                            dataRow["Prijmeni"] = textBox3.Text;
                            using (SQLiteConnection con = new SQLiteConnection("URI=file:Evidence_psu.db"))
                            {
                                con.Open();
                                string dotaz;
                                dotaz = "UPDATE Osoby SET Jmeno ='" + textBox2.Text + "' WHERE Osoba_id='" + contactId + "'";
                                SQLiteDataAdapter sda  = new SQLiteDataAdapter(dotaz, con);
                                DataTable         dtbl = new DataTable();
                                DataSet           ds   = new DataSet();
                                sda.Fill(dtbl);
                                dotaz = "UPDATE Osoby SET Prijmeni ='" + textBox3.Text + "' WHERE Osoba_id='" + contactId + "'";
                                sda   = new SQLiteDataAdapter(dotaz, con);
                                dtbl  = new DataTable();
                                ds    = new DataSet();
                                sda.Fill(dtbl);
                                dotaz = "UPDATE Osoby SET Obec ='" + textBox4.Text + "' WHERE Osoba_id='" + contactId + "'";
                                sda   = new SQLiteDataAdapter(dotaz, con);
                                dtbl  = new DataTable();
                                ds    = new DataSet();
                                sda.Fill(dtbl);
                                dotaz = "UPDATE Osoby SET Ulice ='" + textBox5.Text + "' WHERE Osoba_id='" + contactId + "'";
                                sda   = new SQLiteDataAdapter(dotaz, con);
                                dtbl  = new DataTable();
                                ds    = new DataSet();
                                sda.Fill(dtbl);
                                dotaz = "UPDATE Osoby SET cislo_popisne ='" + Convert.ToInt32(textBox6.Text) + "' WHERE Osoba_id='" + contactId + "'";
                                sda   = new SQLiteDataAdapter(dotaz, con);
                                dtbl  = new DataTable();
                                ds    = new DataSet();
                                sda.Fill(dtbl);
                                dotaz = "UPDATE Osoby SET PSC ='" + textBox7.Text + "' WHERE Osoba_id='" + contactId + "'";
                                sda   = new SQLiteDataAdapter(dotaz, con);
                                dtbl  = new DataTable();
                                ds    = new DataSet();
                                sda.Fill(dtbl);
                            }
                            editSucces = true;
                            this.Close();
                            MessageBox.Show("Úprava Dat Byla uspěšná", "Edit", MessageBoxButtons.OK);
                        }
                    }
                }
            }
            else
            {
                if (textBox2.Text == string.Empty || textBox3.Text == string.Empty || textBox4.Text == string.Empty)                //příkaz zjišťující, jestli data označená jako "NotNULL" nejsou prázdná
                {
                    if (textBox2.Text == string.Empty)
                    {
                        errorProvider1.SetError(textBox2, "Kolonka se jménem nesmí být prázdná");
                    }
                    if (textBox3.Text == string.Empty)
                    {
                        errorProvider1.SetError(textBox3, "Kolonka s id Osoby nesmí být prázdná");
                    }
                    return;
                }

                string connectionString = "URI=file:Evidence_psu.db";
                string commandText      = @"SELECT * FROM Psi WHERE Pes_ID =" + contactId;
                helper = new dBHelper(connectionString);

                if (helper.Load(commandText, "Pes_id") == true)
                {
                    // Determin if the row was found
                    if (helper.DataSet.Tables[0].Rows.Count == 1)
                    {
                        // Determin the found row
                        DataRow dataRow = helper.DataSet.Tables[0].Rows[0];

                        // Modify the row
                        dataRow["Jmeno"]    = textBox2.Text;
                        dataRow["Osoba_ID"] = textBox3.Text;
                        using (SQLiteConnection con = new SQLiteConnection("URI=file:Evidence_psu.db"))
                        {
                            con.Open();
                            string dotaz;
                            dotaz = "UPDATE PSI SET Jmeno ='" + textBox2.Text + "' WHERE Pes_ID='" + contactId + "'";
                            SQLiteDataAdapter sda  = new SQLiteDataAdapter(dotaz, con);
                            DataTable         dtbl = new DataTable();
                            DataSet           ds   = new DataSet();
                            sda.Fill(dtbl);
                            dotaz = "UPDATE Psi SET Osoba_ID ='" + Convert.ToInt32(textBox3.Text) + "' WHERE Pes_ID='" + contactId + "'";
                            sda   = new SQLiteDataAdapter(dotaz, con);
                            dtbl  = new DataTable();
                            ds    = new DataSet();
                            sda.Fill(dtbl);
                            dotaz = "UPDATE Psi SET Narozen ='" + textBox3.Text + "' WHERE Pes_ID='" + contactId + "'";
                            sda   = new SQLiteDataAdapter(dotaz, con);
                            dtbl  = new DataTable();
                            ds    = new DataSet();
                            sda.Fill(dtbl);
                        }
                        editSucces = true;
                        this.Close();
                        MessageBox.Show("Úprava Dat Byla uspěšná", "Edit", MessageBoxButtons.OK);
                    }
                }
            }
        }
Пример #3
0
        void PřidatData(object sender, EventArgs e)
        {
            if (rozhodnutí)
            {
                int i = 0;
                if (textBox7.Text != string.Empty)
                {
                    i = Convert.ToInt32(textBox7.Text);
                }
                if (textBox1.Text == string.Empty || textBox2.Text == string.Empty || textBox3.Text == string.Empty) //příkaz zjišťující, jestli data označená jako "NotNULL" nejsou prázdná
                {
                    if (textBox1.Text == string.Empty)
                    {
                        errorProvider1.SetError(textBox1, "Kolonka se jménem nesmí být prázdná");
                    }
                    if (textBox2.Text == string.Empty)
                    {
                        errorProvider1.SetError(textBox2, "Kolonka se příjmením nesmí být prázdná");
                    }
                    if (textBox3.Text == string.Empty)
                    {
                        errorProvider1.SetError(textBox3, "Kolonka s obcí nesmí být prázdná");
                    }
                    return;
                }
                if (textBox1.Text == string.Empty || textBox2.Text == string.Empty) //příkaz zjišťující, jestli data označená jako "NotNULL" nejsou prázdná
                {
                    if (textBox1.Text == string.Empty)
                    {
                        errorProvider1.SetError(textBox1, "Kolonka se jménem nesmí být prázdná");
                    }
                    if (textBox2.Text == string.Empty)
                    {
                        errorProvider1.SetError(textBox2, "Kolonka ID Osoby nesmí být prázdná");
                    }
                    return;
                }
                string connectionString = "URI=file:Evidence_psu.db";

                // Determin the DataAdapter = CommandText + Connection
                string commandText = "SELECT * FROM Osoby WHERE 1=0";
                // Make a new object
                helper = new dBHelper(connectionString);
                {
                    // Load Data
                    if (helper.Load(commandText, "osoba_id") == true)
                    {
                        // Add a row and determin the row
                        helper.DataSet.Tables[0].Rows.Add(helper.DataSet.Tables[0].NewRow());
                        DataRow dataRow = helper.DataSet.Tables[0].Rows[0];

                        // Enter the given values
                        dataRow["Jmeno"]    = textBox1.Text;
                        dataRow["Prijmeni"] = textBox2.Text;
                        dataRow["Obec"]     = textBox3.Text;
                        dataRow["Ulice"]    = textBox4.Text;
                        if (textBox5.Text == String.Empty)
                        {
                            dataRow["Cislo_popisne"] = null;
                        }
                        else
                        {
                            dataRow["Cislo_popisne"] = Convert.ToInt64(textBox5.Text);
                        }
                        dataRow["PSC"] = textBox6.Text;

                        try
                        {
                            // Save -> determin succes
                            if (helper.Save() == true)
                            {
                                textBox7.Text = dataRow["osoba_id"].ToString();
                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show("Error during Insertion");
                            }
                        }
                        catch (Exception ex)
                        {
                            // Show the Exception --> Dubbel ContactId/Name ?
                            MessageBox.Show(ex.Message);
                        }
                    }
                    this.Close();
                    MessageBox.Show("Data Byla uspěšně přidána", "Edit", MessageBoxButtons.OK);
                }
            }
            else
            {
                int i = 0;
                if (textBox7.Text != string.Empty)
                {
                    i = Convert.ToInt32(textBox7.Text);
                }
                string connectionString = "URI=file:Evidence_psu.db";

                // Determin the DataAdapter = CommandText + Connection
                string commandText = "SELECT * FROM PSI WHERE 1=0";
                // Make a new object
                helper = new dBHelper(connectionString);
                {
                    // Load Data
                    if (helper.Load(commandText, "pes_id") == true)
                    {
                        // Add a row and determin the row
                        helper.DataSet.Tables[0].Rows.Add(helper.DataSet.Tables[0].NewRow());
                        DataRow dataRow = helper.DataSet.Tables[0].Rows[0];

                        // Enter the given values
                        dataRow["Jmeno"]    = textBox1.Text;
                        dataRow["Osoba_ID"] = Convert.ToInt64(textBox2.Text);
                        dataRow["Narozen"]  = textBox3.Text;

                        try
                        {
                            // Save -> determin succes
                            if (helper.Save() == true)
                            {
                                textBox7.Text = dataRow["Pes_id"].ToString();
                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show("Error during Insertion");
                            }
                        }
                        catch (Exception ex)
                        {
                            // Show the Exception --> Dubbel ContactId/Name ?
                            MessageBox.Show(ex.Message);
                        }
                    }
                    MessageBox.Show("Data Byla uspěšně přidána", "Edit", MessageBoxButtons.OK);
                    this.Close();
                }
            }
        }
Пример #4
0
        void Button1Click(object sender, EventArgs e)
        {
            if (rozhodnutí)
            {
                string connectionString = "URI=file:Evidence_psu.db";

                // Determin the DataAdapter = CommandText + Connection
                string commandText = "SELECT * FROM Osoby WHERE osoba_id=" + contactId;

                // Make a new object
                helper = new dBHelper(connectionString);
                {
                    // Load Data
                    if (helper.Load(commandText, "osoba_id") == true)
                    {
                        DialogResult dialogResult = MessageBox.Show("Opravdu chcete smazat data ?", "Upozornění", MessageBoxButtons.YesNo);
                        if (dialogResult == DialogResult.Yes)
                        {
                            using (SQLiteConnection con = new SQLiteConnection("URI=file:Evidence_psu.db"))
                            {
                                con.Open();
                                string dotaz;
                                dotaz = "DELETE FROM Osoby WHERE Osoba_id='" + contactId + "'";
                                SQLiteDataAdapter sda  = new SQLiteDataAdapter(dotaz, con);
                                DataTable         dtbl = new DataTable();
                                DataSet           ds   = new DataSet();
                                sda.Fill(dtbl);
                                con.Close();
                            }
                        }
                        else if (dialogResult == DialogResult.No)
                        {
                            return;
                        }
                    }
                }
            }
            else
            {
                string connectionString = "URI=file:Evidence_psu.db";

                // Determin the DataAdapter = CommandText + Connection
                string commandText = "SELECT * FROM PSI WHERE pes_id=" + contactId;

                // Make a new object
                helper = new dBHelper(connectionString);
                {
                    // Load Data
                    if (helper.Load(commandText, "pes_id") == true)
                    {
                        //helper.DataSet.Tables[0].Rows[0].Delete();
                        DialogResult dialogResult = MessageBox.Show("Opravdu chcete smazat data ?", "Upozornění", MessageBoxButtons.YesNo);
                        if (dialogResult == DialogResult.Yes)
                        {
                            using (SQLiteConnection con = new SQLiteConnection("URI=file:Evidence_psu.db"))
                            {
                                con.Open();
                                string dotaz;
                                dotaz = "DELETE FROM Psi WHERE pes_id='" + contactId + "'";
                                SQLiteDataAdapter sda  = new SQLiteDataAdapter(dotaz, con);
                                DataTable         dtbl = new DataTable();
                                DataSet           ds   = new DataSet();
                                sda.Fill(dtbl);
                                con.Close();
                            }
                        }
                        else if (dialogResult == DialogResult.No)
                        {
                            return;
                        }
                    }
                }
            }
            this.Close();
            MessageBox.Show("Data Byla uspěšně smazána", "MessageBox", MessageBoxButtons.OK);
        }