Exemplo n.º 1
0
        private void add_btn_Click(object sender, EventArgs e)
        {
            DBConnection con = new DBConnection();

            string name       = name_txtbx.Text.ToString();
            string surname    = surname_txtbx.Text.ToString();
            string tc         = tc_txtbx.Text.ToString();
            string address    = address_txtbx.Text.ToString();
            string email      = email_txtbx.Text.ToString();
            string tel        = tel_txtbx.Text.ToString();
            string reg_date   = reg_date_dtp.Text.ToString();
            string sclass     = sclass_combx.Text.ToString();
            string room_id    = room_combx.Text.ToString();
            string department = dep_combx.Text.ToString();
            string dep_id     = con.Reader($"SELECT dep_id FROM department WHERE name = '{department}'", "dep_id");

            if (id != "-1")
            {
                string query = $"UPDATE student SET " +
                               $"name='{name}', " +
                               $"surname='{surname}', " +
                               $"tc='{tc}', " +
                               $"address='{address}', " +
                               $"email='{email}', " +
                               $"tel='{tel}', " +
                               $"reg_date='{reg_date}', " +
                               $"class='{sclass}', " +
                               $"room_id='{room_id}', " +
                               $"dep_id='{dep_id}' " +
                               $"WHERE student_id = '{id_txtbx.Text.ToString()}'";

                if (name_txtbx.Text != "" && surname_txtbx.Text != "" && tc_txtbx.Text != "" &&
                    reg_date_dtp.Text != "" && sclass_combx.SelectedIndex > -1 && room_combx.SelectedIndex > -1 &&
                    dep_combx.SelectedIndex > -1)
                {
                    try
                    {
                        con.Update(query);
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: " + ex);
                    }
                    finally
                    {
                        id_txtbx.Text              = "";
                        name_txtbx.Text            = "";
                        surname_txtbx.Text         = "";
                        tc_txtbx.Text              = "";
                        address_txtbx.Text         = "";
                        email_txtbx.Text           = "";
                        tel_txtbx.Text             = "";
                        sclass_combx.SelectedIndex = -1;
                        room_combx.SelectedIndex   = -1;
                        dep_combx.SelectedIndex    = -1;
                    }
                }
            }
            else
            {
                string query = $"INSERT INTO student(name, surname, tc, address, email, tel, reg_date, class, room_id, dep_id) " +
                               $"VALUES('{name}', '{surname}', '{tc}', '{address}', '{email}', '{tel}', '{reg_date}', '{sclass}', '{room_id}', '{dep_id}')";

                if (name_txtbx.Text != "" && surname_txtbx.Text != "" && tc_txtbx.Text != "" &&
                    reg_date_dtp.Text != "" && sclass_combx.SelectedIndex > -1 && room_combx.SelectedIndex > -1 &&
                    dep_combx.SelectedIndex > -1)
                {
                    try
                    {
                        con.Insert(query);
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: " + ex);
                    }
                    finally
                    {
                        id_txtbx.Text              = "";
                        name_txtbx.Text            = "";
                        surname_txtbx.Text         = "";
                        tc_txtbx.Text              = "";
                        address_txtbx.Text         = "";
                        email_txtbx.Text           = "";
                        tel_txtbx.Text             = "";
                        sclass_combx.SelectedIndex = -1;
                        room_combx.SelectedIndex   = -1;
                        dep_combx.SelectedIndex    = -1;
                    }
                }
                else
                {
                    MessageBox.Show("Missing Data", "Critical Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
Exemplo n.º 2
0
        private void add_btn_Click(object sender, EventArgs e)
        {
            DBConnection con = new DBConnection();

            string name    = name_txtbx.Text.ToString();
            string surname = surname_txtbx.Text.ToString();
            string tc      = tc_txtbx.Text.ToString();
            string address = address_txtbx.Text.ToString();
            string email   = email_txtbx.Text.ToString();
            string tel     = tel_txtbx.Text.ToString();
            string user    = user_txtbx.Text.ToString();
            string pass    = pass_txtbx.Text.ToString();
            string job     = job_combx.Text.ToString();
            string job_id  = con.Reader($"SELECT job_id FROM job WHERE position = '{job}'", "job_id");
            string salary  = salary_txtbx.Text.ToString();
            string sdate   = sdate_dtp.Text.ToString();
            string fdate;

            if (fdate_dtp.Checked == false)
            {
                fdate = "NULL";
            }
            else
            {
                fdate = "'" + fdate_dtp.Text.ToString() + "'";
            }

            string admin;

            if (admin_chkbx.Checked == true)
            {
                admin = "1";
            }
            else
            {
                admin = "0";
            }

            if (id != "-1") // so thats an edit proccess
            {
                string query = $"UPDATE personal SET " +
                               $"name='{name}', " +
                               $"surname='{surname}', " +
                               $"tc='{tc}', " +
                               $"address='{address}', " +
                               $"email='{email}', " +
                               $"tel='{tel}', " +
                               $"pass='******', " +
                               $"start_date='{sdate}', " +
                               $"finish_date={fdate}, " +
                               $"job_id='{job_id}', " +
                               $"admin='{admin}' " +
                               $"WHERE personal_id = '{id_txtbx.Text.ToString()}'";

                if (name_txtbx.Text != "" && surname_txtbx.Text != "" && tc_txtbx.Text != "" &&
                    user_txtbx.Text != "" && pass_txtbx.Text != "" && job_combx.SelectedIndex > -1 &&
                    sdate_dtp.Text != "" && salary_txtbx.Text != "")
                {
                    try
                    {
                        con.Update(query);
                        try
                        {
                            con.Delete("delete_salary", id);
                        }
                        catch (Exception ex) { };
                        //con.Update($"UPDATE salary SET personal_id = '{id}', job_id = '{job_id}', amount = '{salary}'");
                        con.Insert($"INSERT INTO salary(personal_id, job_id, amount) VALUES('{id}', '{job_id}', '{salary}')");
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: " + ex);
                    }
                    finally
                    {
                        id_txtbx.Text           = "";
                        name_txtbx.Text         = "";
                        surname_txtbx.Text      = "";
                        tc_txtbx.Text           = "";
                        address_txtbx.Text      = "";
                        email_txtbx.Text        = "";
                        tel_txtbx.Text          = "";
                        user_txtbx.Text         = "";
                        pass_txtbx.Text         = "";
                        job_combx.SelectedIndex = -1;
                    }
                }
            }
            else
            {
                string query = $"INSERT INTO personal(name, surname, tc, address, email, tel, user, pass, start_date, finish_date, job_id, admin) " +
                               $"VALUES('{name}', '{surname}', '{tc}', '{address}', '{email}', '{tel}', '{user}', '{pass}', '{sdate}', {fdate}, '{job_id}', '{admin}')";

                if (name_txtbx.Text != "" && surname_txtbx.Text != "" && tc_txtbx.Text != "" &&
                    user_txtbx.Text != "" && pass_txtbx.Text != "" && job_combx.SelectedIndex > -1 &&
                    sdate_dtp.Text != "" && salary_txtbx.Text != "")
                {
                    try
                    {
                        con.Insert(query);
                        string personal_id = con.Reader($"SELECT personal_id FROM personal WHERE user = '******'", "personal_id");
                        con.Insert($"INSERT INTO salary(personal_id, job_id, amount) VALUES('{personal_id}', '{job_id}', '{salary}')");
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: " + ex);
                    }
                    finally
                    {
                        id_txtbx.Text           = "";
                        name_txtbx.Text         = "";
                        surname_txtbx.Text      = "";
                        tc_txtbx.Text           = "";
                        address_txtbx.Text      = "";
                        email_txtbx.Text        = "";
                        tel_txtbx.Text          = "";
                        user_txtbx.Text         = "";
                        pass_txtbx.Text         = "";
                        job_combx.SelectedIndex = -1;
                    }
                }
                else
                {
                    MessageBox.Show("Missing Data", "Critical Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }