예제 #1
0
        private void DeleteLeave_Click(object sender, EventArgs e)
        {
            try
            {
                string query = "";
                if (SttafIdText.Text.Trim() == "")
                {
                    MessageBox.Show("Please Enter Staff ID");
                    SttafIdText.Focus();
                    return;
                }
                query = "DELETE FROM Leave_Info WHERE StaffID = " + stfID;

                if (DbAccess.ExecuteToDB(query))
                {
                    if (stfID != 0)
                    {
                        MessageBox.Show("Delete Successfully!!!");
                    }
                    else
                    {
                        MessageBox.Show("Failed To Delete!!!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection Error!!!");
            }
            finally
            {
                Reset();
            }
        }
예제 #2
0
        private void SaveLeave_Click(object sender, EventArgs e)
        {
            string query = "";

            if (SttafIdText.Text.Trim() == "")
            {
                MessageBox.Show("Please Enter Employee ID");
                SttafIdText.Focus();
                return;
            }



            if (CasualLeave.Text.Trim() == "")
            {
                MessageBox.Show("Please Enter The Number");
                CasualLeave.Focus();
                return;
            }

            if (Sickleave.Text.Trim() == "")
            {
                MessageBox.Show("Please Enter The Number");
                Sickleave.Focus();
                return;
            }
            if (MaternityLeave.Text.Trim() == "")
            {
                MessageBox.Show("Please Enter Password");
                MaternityLeave.Focus();
                return;
            }
            if (EarnedLeave.Text.Trim() == "")
            {
                MessageBox.Show("Please Enter Number");
                EarnedLeave.Focus();
                return;
            }
            query = "SELECT COUNT(*) AS Count FROM Leave_Info WHERE StaffID = " + SttafIdText.Text + "";
            if (stfID == 0)
            {
                if (DbAccess.NumberOfRecords(query) > 0)
                {
                    MessageBox.Show("This username already exists! Please try another ID!");
                    SttafIdText.Focus();
                    return;
                }
            }
            else
            {
                if (DbAccess.NumberOfRecords(query) > 1)
                {
                    MessageBox.Show("This username already exists! Please try another ID!");
                    SttafIdText.Focus();
                    return;
                }
            }
            try
            {
                if (stfID == 0)
                {
                    query = "INSERT INTO Leave_Info(StaffID,CasualLeave,SickLeave,MaternityLeave,EarnedLeave) VALUES(" + Convert.ToInt32(SttafIdText.Text) + ", '" + Convert.ToInt32(CasualLeave.Text) + "',  '" + Convert.ToInt32(Sickleave.Text) + "', '" + Convert.ToInt32(MaternityLeave.Text) + "', '" + Convert.ToInt32(EarnedLeave.Text) + "' )";
                }


                else
                {
                    query = "UPDATE Leave_Info SET  CasualLeave = '" + Convert.ToInt32(CasualLeave.Text) + "', SickLeave = '" + Convert.ToInt32(Sickleave.Text) + "',MaternityLeave= '" + Convert.ToInt32(MaternityLeave.Text) + "',EarnedLeave = '" + Convert.ToInt32(EarnedLeave.Text) + "' WHERE StaffID = " + stfID;
                }

                if (DbAccess.ExecuteToDB(query))
                {
                    if (stfID == 0)
                    {
                        MessageBox.Show("Saved Successfully!!!");
                    }
                    else
                    {
                        MessageBox.Show("Update Successfully!!!");
                    }
                }
                else
                {
                    MessageBox.Show("Failed To Save!!!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection Error!!!");
            }
            finally
            {
                Reset();
            }
        }