Example #1
0
        /*
         * private void delete_btn_Click(object sender, EventArgs e)
         * {
         *  DBConnection con = new DBConnection();
         *  string delQuery = $"DELETE FROM personal WHERE personal_id = '{id}'";
         *  try
         *  {
         *      DialogResult result = MessageBox.Show("Are you Sure LAN", "Important Question", MessageBoxButtons.YesNo);
         *      if (result == DialogResult.Yes)
         *      {
         *          con.Delete(delQuery);
         *          refresh();
         *          id = this.data_dgv.Rows[0].Cells[0].Value.ToString();
         *      }
         *  }
         *  catch (Exception ex)
         *  {
         *      MessageBox.Show("Error :" + ex);
         *  }
         *  finally
         *  {
         *      search_txtbx.Text = "";
         *      by_combx.SelectedIndex = -1;
         *  }
         * }
         */

        private void delete_btn_Click(object sender, EventArgs e)
        {
            DBConnection con      = new DBConnection();
            string       delQuery = "delete_personal";

            if (id != "1")
            {
                try
                {
                    DialogResult result = MessageBox.Show("Are you Sure?", "Important Question", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        con.Delete(delQuery, id);
                        refresh();
                        id = this.data_dgv.Rows[0].Cells[0].Value.ToString();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error :" + ex);
                }
                finally
                {
                    search_txtbx.Text      = "";
                    by_combx.SelectedIndex = -1;
                }
            }
            else
            {
                MessageBox.Show("Cannont Delete This Entry");
            }
        }
Example #2
0
        /*
         * private void delete_btn_Click(object sender, EventArgs e)
         * {
         *  DBConnection con = new DBConnection();
         *  string delQuery = $"DELETE FROM personal WHERE personal_id = '{id}'";
         *  try
         *  {
         *      DialogResult result = MessageBox.Show("Are you Sure LAN", "Important Question", MessageBoxButtons.YesNo);
         *      if (result == DialogResult.Yes)
         *      {
         *          con.Delete(delQuery);
         *          refresh();
         *          id = this.data_dgv.Rows[0].Cells[0].Value.ToString();
         *      }
         *  }
         *  catch (Exception ex)
         *  {
         *      MessageBox.Show("Error :" + ex);
         *  }
         *  finally
         *  {
         *      search_txtbx.Text = "";
         *      by_combx.SelectedIndex = -1;
         *  }
         * }
         */

        private void delete_btn_Click(object sender, EventArgs e)
        {
            DBConnection con      = new DBConnection();
            string       delQuery = "delete_student";

            try
            {
                DialogResult result = MessageBox.Show("Are you Sure?", "Important Question", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    con.Delete(delQuery, id);
                    refresh();
                    try
                    {
                        id = this.data_dgv.Rows[0].Cells[0].Value.ToString();
                    }
                    catch (Exception ex)
                    {
Start:
                        DialogResult addNewStudent = MessageBox.Show("There is no Registered Students, Add a new student?", "Important Question", MessageBoxButtons.YesNo);
                        if (addNewStudent == DialogResult.Yes)
                        {
                            student_mod myform = new student_mod("-1");
                            myform.ShowDialog();
                            refresh();
                            try
                            {
                                id = this.data_dgv.Rows[0].Cells[0].Value.ToString();
                            }
                            catch (Exception ex2)
                            {
                                goto Start;
                            }
                        }
                        else
                        {
                            DialogResult Exit = MessageBox.Show("Close Application", "Important Question", MessageBoxButtons.YesNo);
                            if (Exit == DialogResult.Yes)
                            {
                                Application.Exit();
                            }
                            else
                            {
                                goto Start;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error :" + ex);
            }
            finally
            {
                search_txtbx.Text      = "";
                by_combx.SelectedIndex = -1;
            }
        }
Example #3
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);
                }
            }
        }