private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                string uname = tbUsername.Text.Trim();
                string passwd = tbPassword.Text.Trim();

                if (uname == "" || passwd == "")
                {
                    MessageBox.Show("PLEASE INPUT USERNAME AND/OR PASSWORD", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    tbPassword.Clear();
                    tbUsername.Focus();
                }
                else
                {
                    Admin A = new Admin();
                    string[] values = A.Authentication(uname, passwd);

                    string dbUname = values[0];
                    string dbPsswd = values[1];
                    string dbLevel = values[2];

                    if (uname == dbUname && passwd == dbPsswd)
                    {
                        if (dbLevel == "Yes")
                        {
                            MessageBox.Show("WELCOME, " + uname + "", "WELCOME TO IHRIS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            FormMainMenuMaster MMM = new FormMainMenuMaster(uname);
                            this.Hide();
                            MMM.Show();
                        }
                        else
                        {
                            MessageBox.Show("WELCOME, " + uname + "", "WELCOME TO IHRIS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            FormUserMainMenu MM = new FormUserMainMenu(uname);
                            this.Hide();
                            MM.Show();
                        }
                    }
                    else
                    {
                        MessageBox.Show("INCORRECT USERNAME AND/OR PASSWORD", "INCORRECT LOGIN", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        tbPassword.Clear();
                        tbUsername.Focus();
                    }
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void RefreshDGV()
        {
            Admin Show = new Admin();
            dgDivision.DataSource = Show.DivisionDGV();
            dgDivision.DataMember = "Division";

            dgPosition.DataSource = Show.PositionDGV();
            dgPosition.DataMember = "Position";

            dgSearchEmpPayroll.DataSource = Show.PayrollEmpDGV();
            dgSearchEmpPayroll.DataMember = "Employee";

            dgAddPayroll.DataSource = Show.PayrollEmpDGV();
            dgAddPayroll.DataMember = "Employee";
        }
        public void RefreshDG()
        {
            Admin Auto = new Admin();
            tbItemNumber.Text = Auto.InventoryAutoGenerateID();

            Admin Show = new Admin();
            dgAllItem.DataSource = Show.InventoryDGV();
            dgAllItem.DataMember = "Inventory";

            dgSearchItem.DataSource = Show.InventoryDGV();
            dgSearchItem.DataMember = "Inventory";

            dgEditItem.DataSource = Show.InventoryDGV();
            dgEditItem.DataMember = "Inventory";

            tbEditAddStock.Enabled = false;
        }
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     try
     {
         DialogResult dialogResult = MessageBox.Show("MAKE SURE YOUR PASSWORD IS EASY TO REMEMBER", "UPDATE PASSWORD?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
         if (dialogResult == DialogResult.Yes)
         {
             if (tbPassword.Text == "" || tbRepeat.Text == "")
             {
                 MessageBox.Show("PLEASE INPUT PASSWORD AND/OR REPEAT THE PASSWORD", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 tbPassword.Clear();
                 tbRepeat.Clear();
             }
             else
             {
                 if (tbPassword.Text == tbRepeat.Text)
                 {
                     Admin A = new Admin();
                     A.UpdatePassword(tbRepeat.Text, lblUsername.Text);
                     MessageBox.Show("PASSWORD UPDATED", "UPDATED", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     tbPassword.Clear();
                     tbRepeat.Clear();
                 }
                 else
                 {
                     tbPassword.Clear();
                     tbRepeat.Clear();
                     MessageBox.Show("PASSWORD MISSMATCH", "FAILED TO UPDATE", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     tbPassword.Focus();
                 }
             }
         }
     }
     catch (SqlException)
     {
         MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (InvalidOperationException)
     {
         MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        public void BindCBDivision()
        {
            Admin A = new Admin();
            ArrayList data_division = A.BindCBDivision();

            if (data_division.Count == 0)
            {
                MessageBox.Show("NO DATA MATCH WITH DATABASE RECORDS", "NO DATA FOUND", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                for (int i = 0; i < data_division.Count; i = i + 2)
                {
                    string DivID = (string)data_division[i];
                    string DivName = (string)data_division[i+1];

                    cbPositionDivision.Items.Add(DivID+". "+DivName);
                }
            }
        }
        public void BindPositionComboBoxEditForm()
        {
            Admin AP = new Admin();
            ArrayList data_position = AP.BindCBPosition(cbEditEmpDivision.Text.Substring(0, 1));

            if (data_position.Count == 0)
            {
                MessageBox.Show("NO DATA MATCH WITH DATABASE RECORDS", "NO DATA FOUND", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                for (int i = 0; i < data_position.Count; i = i + 2)
                {
                    string PosID = (string)data_position[i];
                    string PosName = (string)data_position[i + 1];

                    cbEditEmpPosition.Items.Add(PosID + ". " + PosName);
                }
            }
        }
        public void RefreshDG()
        {
            Admin Show = new Admin();
            dgvAllContract.DataSource = Show.ContractDGV();
            dgvAllContract.DataMember = "Contracts";

            dgOngoing.DataSource = Show.GetOngoingContractDGV();
            dgOngoing.DataMember = "OngoingContracts";

            dgCompleted.DataSource = Show.GetCompletedContractDGV();
            dgCompleted.DataMember = "CompletedContracts";

            dgExtended.DataSource = Show.GetExtendedContractDGV();
            dgExtended.DataMember = "ExtendedContracts";

            dgSearchContract.DataSource = Show.GetSearchContractDGV();
            dgSearchContract.DataMember = "SearchContracts";

            dgEditContract.DataSource = Show.GetEditContractDGV();
            dgEditContract.DataMember = "EditContracts";
        }
        private void dgSearchEmp_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                string str = dgSearchEmp.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();

                Admin Bind = new Admin();
                ArrayList data_emp = Bind.BindEmpDetails(str);

                if (data_emp.Count == 0)
                {
                    MessageBox.Show("NO DATA MATCH WITH DATABASE RECORDS", "NO DATA FOUND", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    for (int i = 0; i < data_emp.Count; i = i + 8)
                    {
                        string EmpNIP = (string)data_emp[i];
                        string EmpName = (string)data_emp[i + 1];
                        string EmpGender = (string)data_emp[i + 2];
                        string EmpDOB = (string)data_emp[i + 3];
                        string EmpEmail = (string)data_emp[i + 4];
                        string EmpPhone = (string)data_emp[i + 5];
                        string DivID = (string)data_emp[i + 6];
                        string PosID = (string)data_emp[i + 7];

                        tbSearchEmpNIP.Text = EmpNIP;
                        tbSearchEmpName.Text = EmpName;
                        tbSearchEmpGender.Text = EmpGender;
                        tbSearchEmpDOB.Text = EmpDOB;
                        tbSearchEmpEmail.Text = EmpEmail;
                        tbSearchEmpPhone.Text = EmpPhone;

                        Admin BindSingleDiv = new Admin();
                        ArrayList data_singleDiv = BindSingleDiv.BindCBDivisionForEditAndSearchEmployeeForm(DivID);
                        for (int iD = 0; iD < data_singleDiv.Count; iD = iD + 2)
                        {
                            string CompletedDivID = (string)data_singleDiv[iD];
                            string CompletedDivName = (string)data_singleDiv[iD + 1];

                            tbSearchEmpDivision.Text = CompletedDivID + ". " + CompletedDivName;
                        }

                        Admin BindSinglePos = new Admin();
                        ArrayList data_singlePos = BindSingleDiv.BindCBPositionForEditAndSearchEmployeeForm(PosID);
                        for (int iP = 0; iP < data_singlePos.Count; iP = iP + 2)
                        {
                            string CompletedPosID = (string)data_singlePos[iP];
                            string CompletedPosName = (string)data_singlePos[iP + 1];

                            tbSearchEmpPosition.Text = CompletedPosID + ". " + CompletedPosName;
                        }
                    }
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dialogResult = MessageBox.Show("SAVE DATA? \nMAKE SURE ALL THE FORM FIELDS FILLED CORRECTLY", "DATA ENTRY", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (dialogResult == DialogResult.Yes)
                {
                    if (tbEmpPassword.Text != tbEmpRepeatPassword.Text)
                    {
                        MessageBox.Show("PASSWORD MISSMATCH", "INCORECT PASSWORD", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        tbEmpPassword.Clear();
                        tbEmpRepeatPassword.Clear();
                        tbEmpPassword.Focus();
                    }
                    else
                    {
                        if (tbEmpNIP.Text == "" || tbEmpName.Text == "" || tbEmpEmail.Text == "" || tbEmpPhone.Text == "" || tbEmpPhoto.Text == "" || dtpEmpDOB.Text == DateTime.Today.ToShortDateString() || cbEmpGender.Text == "-----SELECT GENDER-----" || cbEmpDivision.Text == "-----SELECT DIVISION-----" || cbEmpPosition.Text == "-----SELECT POSITION-----")
                        {
                            MessageBox.Show("FORM FIELD(S) CAN NOT BE LEFT EMPTY. PLEASE COMPLETE THE FORM TO SAVE DATA", "DATA ENTRY ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            tbEmpNIP.Focus();
                        }
                        else
                        {
                            string EmployeeNIP = tbEmpNIP.Text;
                            string EmployeePassword = tbEmpRepeatPassword.Text;
                            string EmployeeName = tbEmpName.Text;
                            string EmployeeGender = cbEmpGender.Text;
                            string EmployeeDOB = dtpEmpDOB.Text;
                            string EmployeeEmail = tbEmpEmail.Text;
                            string EmployeePhone = tbEmpPhone.Text;
                            string EmployeePhoto = tbEmpPhoto.Text;
                            string DivisionID = cbEmpDivision.Text.Substring(0, 1);
                            string PositionID = cbEmpPosition.Text.Substring(0, 1);

                            Admin A = new Admin();
                            A.AddEmployee(EmployeeNIP, EmployeePassword, EmployeeName, EmployeeGender, EmployeeDOB, EmployeeEmail, EmployeePhone, EmployeePhoto, DivisionID, PositionID);

                            tbEmpNIP.Clear();
                            tbEmpName.Clear();
                            cbEmpGender.Text = "-----SELECT GENDER-----";
                            dtpEmpDOB.Text = DateTime.Today.ToShortDateString();
                            tbEmpEmail.Clear();
                            tbEmpPhone.Clear();
                            tbEmpPhoto.Clear();
                            cbEmpDivision.Text = "-----SELECT DIVISION-----";
                            cbEmpPosition.Text = "-----SELECT POSITION-----";
                            tbEmpPassword.Clear();
                            tbEmpRepeatPassword.Clear();

                            MessageBox.Show("DATA SAVED", "ENTRY DATA SUCCESSFUL", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            RefreshFormEmployee();
                        }
                    }
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dialogResult = MessageBox.Show("DO YOU WANT TO EDIT THIS EMPLOYEE DATA?", "EDIT EMPLOYEE DETAILS", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Yes)
                {
                    if (tbEditEmpNIP.Text == "" || tbEditEmpName.Text == "" || tbEditEmpEmail.Text == "" || tbEditEmpPhone.Text == "" || dtpEditEmpDOB.Text == DateTime.Today.ToShortDateString() || cbEditEmpGender.Text == "-----SELECT GENDER-----" || cbEditEmpDivision.Text == "-----SELECT DIVISION-----" || cbEditEmpPosition.Text == "-----SELECT POSITION-----")
                    {
                        MessageBox.Show("FORM FIELD(S) CAN NOT BE LEFT EMPTY. PLEASE COMPLETE THE FORM TO EDIT DATA", "DATA UPDATION ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        tbEditEmpEmail.Focus();
                    }
                    else
                    {
                        string EmployeeNIP = tbEditEmpNIP.Text;
                        string EmployeeName = tbEditEmpName.Text;
                        string EmployeeGender = cbEditEmpGender.Text;
                        string EmployeeDOB = dtpEditEmpDOB.Text;
                        string EmployeeEmail = tbEditEmpEmail.Text;
                        string EmployeePhone = tbEditEmpPhone.Text;
                        string DivisionID = cbEditEmpDivision.Text.Substring(0, 1);
                        string PositionID = cbEditEmpPosition.Text.Substring(0, 1);

                        Admin A = new Admin();
                        A.EditEmployee(EmployeeNIP, EmployeeName, EmployeeGender, EmployeeDOB, EmployeeEmail, EmployeePhone, DivisionID, PositionID);

                        tbEditEmpNIP.Clear();
                        tbEditEmpName.Clear();
                        cbEditEmpGender.Text = "-----SELECT GENDER-----";
                        dtpEditEmpDOB.Text = DateTime.Today.ToShortDateString();
                        tbEditEmpEmail.Clear();
                        tbEditEmpPhone.Clear();
                        cbEditEmpDivision.Text = "-----SELECT DIVISION-----";
                        cbEditEmpPosition.Text = "-----SELECT POSITION-----";

                        MessageBox.Show("DATA UPDATED", "UPDATE DATA SUCCESSFUL", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        RefreshFormEmployee();
                    }
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void RefreshFormEmployee()
        {
            dtpEmpDOB.Text = DateTime.Today.ToShortDateString();
            dtpEditEmpDOB.Text = DateTime.Today.ToShortDateString();

            Admin Show = new Admin();
            dgAllEmployee.DataSource = Show.EmployeeDGV();
            dgAllEmployee.DataMember = "Employee";

            dgEditEmp.DataSource = Show.EmployeeDGV();
            dgEditEmp.DataMember = "Employee";

            dgSearchEmp.DataSource = Show.EmployeeDGV();
            dgSearchEmp.DataMember = "Employee";

            if (tbEditEmpNIP.Text == "" || tbEditEmpName.Text == "")
            {
                btnEdit.Visible = false;
                btnCancelEdit.Visible = false;
            }

            if (tbEmpNIP.Text == "" || tbEditEmpName.Text == "")
            {
                btnSave.Visible = false;
                btnCancel.Visible = false;
            }
        }
        private void dgSearchContract_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                string str = dgSearchContract.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();

                Admin Bind = new Admin();
                ArrayList data_contract = Bind.BindAllContractDetails(str);

                if (data_contract.Count == 0)
                {
                    MessageBox.Show("NO DATA MATCH WITH DATABASE RECORDS", "NO DATA FOUND", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    for (int i = 0; i < data_contract.Count; i = i + 8)
                    {
                        string ContractNumber = (string)data_contract[i];
                        string ContractName = (string)data_contract[i + 1];
                        string ContractDescription = (string)data_contract[i + 2];
                        string ContractTimePeriod = (string)data_contract[i + 3];
                        DateTime ContractStartDate = (DateTime)data_contract[i + 4];
                        DateTime ContractEndDate = (DateTime)data_contract[i + 5];
                        string ContractStatus = (string)data_contract[i + 6];
                        string ContractInfo = (string)data_contract[i + 7];

                        tbSearchContractNumber.Text = ContractNumber;
                        tbSearchContractName.Text = ContractName;
                        tbSearchContractDescription.Text = ContractDescription;
                        tbSearchContractTime.Text = ContractTimePeriod;
                        tbSearchContractStartDate.Text = ContractStartDate.ToShortDateString();
                        tbSearchContractEndDate.Text = ContractEndDate.ToShortDateString();
                        tbSearchContractStatus.Text = ContractStatus;
                        tbSearchContractInfo.Text = ContractInfo;
                    }
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void dgSearchEmpPayroll_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                string str = dgSearchEmpPayroll.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();

                Admin Bind = new Admin();
                ArrayList data_payroll = Bind.BindPayrollDetails(str);

                if (data_payroll.Count == 0)
                {
                    MessageBox.Show("NO DATA MATCH WITH DATABASE RECORDS", "NO DATA FOUND", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    for (int i = 0; i < data_payroll.Count; i = i + 8)
                    {
                        string EmpNIP = (string)data_payroll[i];
                        string PayrollBase = (string)data_payroll[i + 1];
                        string PayrollPositionAllowanceTotal = (string)data_payroll[i + 2];
                        string PayrollTransportationAllowanceTotal = (string)data_payroll[i + 3];
                        string PayrollHouseAllowanceTotal = (string)data_payroll[i + 4];
                        string PayrollAnotherAllowanceTotal = (string)data_payroll[i + 5];
                        string PayrollReductionTotal = (string)data_payroll[i + 6];
                        string PayrollTotal = (string)data_payroll[i + 7];

                        tbSearchPayrollEmpNIP.Text = EmpNIP;
                        tbSearchPayrollBase.Text = PayrollBase;
                        tbSearchPayrollPosition.Text = PayrollPositionAllowanceTotal;
                        tbSearchPayrollTransportation.Text = PayrollTransportationAllowanceTotal;
                        tbSearchPayrollHouse.Text = PayrollHouseAllowanceTotal;
                        tbSearchPayrollAnother.Text = PayrollAnotherAllowanceTotal;
                        tbSearchPayrollReduction.Text = PayrollReductionTotal;
                        tbSearchTotalPayroll.Text = PayrollReductionTotal;
                    }
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private List<string> StatusKerja()
        {
            Admin A = new Admin();
            ArrayList data_att = A.GetAttendanceTime();
            List<string> statusKerjaList = null;
            for (int ar = 0; ar <= data_att.Count; ar = ar + 2)
            {
                string statusKerja;
                DateTime AttIn = (DateTime)data_att[ar];
                DateTime AttOut = (DateTime)data_att[ar + 1];

                TimeSpan rawTotalHoursWorked = AttOut - AttIn;

                var masuk = TimeSpan.Parse("08:00:00");
                var lembur = TimeSpan.Parse("09:00:00");

                if (rawTotalHoursWorked >= lembur)
                {
                    statusKerja = "Lembur";
                }
                else if (rawTotalHoursWorked >= masuk && rawTotalHoursWorked < lembur)
                {
                    statusKerja = "Masuk";
                }
                else
                {
                    statusKerja = "Setengah Hari";
                }

                statusKerjaList.Add(statusKerja);
            }
            return statusKerjaList;
        }
        private void btnUpdateContract_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dialogResult = MessageBox.Show("UPDATE CONTRACT STATUS TO COMPLETED?", "UPDATE CONTRACT STATUS", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Yes)
                {
                    if (tbEditContractNumber.Text == "" || tbEditContractName.Text == "" || tbEditContractTimePeriod.Text == "" || tbEditContractEndDate.Text == "" || tbEditContractStatus.Text == "")
                    {
                        MessageBox.Show("PLEASE SELECT CONTRACT TO COMPLETE FIRST", "ERROR UPDATING CONTRACT STATUS", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {

                        string TodayDate = DateTime.Today.ToShortDateString();
                        string OneDayAfter = DateTime.Today.AddDays(-1).ToShortDateString();
                        string TwoDayAfter = DateTime.Today.AddDays(-2).ToShortDateString();
                        string ThreeDayAfter = DateTime.Today.AddDays(-3).ToShortDateString();
                        string FourDayAfter = DateTime.Today.AddDays(-4).ToShortDateString();
                        string FiveDayAfter = DateTime.Today.AddDays(-5).ToShortDateString();
                        string SixDayAfter = DateTime.Today.AddDays(-6).ToShortDateString();
                        string SevenDayAfter = DateTime.Today.AddDays(-7).ToShortDateString();

                        if(tbEditContractEndDate.Text == TodayDate || tbEditContractEndDate.Text == OneDayAfter || tbEditContractEndDate.Text == TwoDayAfter || tbEditContractEndDate.Text == ThreeDayAfter || tbEditContractEndDate.Text == FourDayAfter || tbEditContractEndDate.Text == FiveDayAfter || tbEditContractEndDate.Text == SixDayAfter || tbEditContractEndDate.Text == SevenDayAfter)
                        {
                            string ContractNumber = tbEditContractNumber.Text;
                            Admin A = new Admin();
                            A.UpdateContractStatus(ContractNumber);

                            MessageBox.Show("CONTRACT STATUS UPDATED", "CONTRACT DONE", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            tbEditContractNumber.Clear();
                            tbEditContractName.Clear();
                            tbEditContractTimePeriod.Clear();
                            tbEditContractEndDate.Clear();
                            tbEditContractStatus.Clear();

                            RefreshDG();
                        }
                        else
                        {
                            MessageBox.Show("CONTRACT IS NOT DONE YET, CAN'T UPDATE CONTRACT STATUS", "CONTRACT STILL ONGOING", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void BindDetails()
        {
            try
            {
                string str = lblUser.Text;

                Admin Bind = new Admin();
                ArrayList data_emp = Bind.UserBindEmpDetails(str);

                if (data_emp.Count == 0)
                {
                    MessageBox.Show("NO DATA MATCH WITH DATABASE RECORDS", "NO DATA FOUND", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    for (int i = 0; i < data_emp.Count; i = i + 9)
                    {
                        string EmpNIP = (string)data_emp[i];
                        string EmpName = (string)data_emp[i + 1];
                        string EmpGender = (string)data_emp[i + 2];
                        string EmpDOB = (string)data_emp[i + 3];
                        string EmpEmail = (string)data_emp[i + 4];
                        string EmpPhone = (string)data_emp[i + 5];
                        string EmpPhoto = (string)data_emp[i + 6];
                        string DivID = (string)data_emp[i + 7];
                        string PosID = (string)data_emp[i + 8];

                        lblEmpNIP.Text = EmpNIP;
                        lblEmpName.Text = EmpName;
                        lblEmpGender.Text = EmpGender;
                        lblEmpDOB.Text = EmpDOB;
                        lblEmpEmail.Text = EmpEmail;
                        lblEmpPhone.Text = EmpPhone;

                        pbEmpPhoto.Image = Image.FromFile(@"D:\Important\Clients\PT Bahtera Adhiguna\Misc\Employee Photo\"+EmpPhoto+"");
                        pbEmpPhoto.SizeMode = PictureBoxSizeMode.StretchImage;
                        pbEmpPhoto.BorderStyle = BorderStyle.Fixed3D;

                        Admin BindSingleDiv = new Admin();
                        ArrayList data_singleDiv = BindSingleDiv.BindCBDivisionForEditAndSearchEmployeeForm(DivID);
                        for (int iD = 0; iD < data_singleDiv.Count; iD = iD + 2)
                        {
                            string CompletedDivID = (string)data_singleDiv[iD];
                            string CompletedDivName = (string)data_singleDiv[iD + 1];

                            lblEmpDivision.Text = CompletedDivID + ". " + CompletedDivName;
                        }

                        Admin BindSinglePos = new Admin();
                        ArrayList data_singlePos = BindSingleDiv.BindCBPositionForEditAndSearchEmployeeForm(PosID);
                        for (int iP = 0; iP < data_singlePos.Count; iP = iP + 2)
                        {
                            string CompletedPosID = (string)data_singlePos[iP];
                            string CompletedPosName = (string)data_singlePos[iP + 1];

                            lblEmpPosition.Text = CompletedPosID + ". " + CompletedPosName;
                        }
                    }
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnChangePhoto_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dialogResult = MessageBox.Show("UPDATE YOUR PROFILE PHOTO?", "UPDATE PROFILE PICTURE?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Yes)
                {
                    if (tbEmpPhoto.Text == "")
                    {
                        MessageBox.Show("PLEASE SELECT THE PHOTO FIRST", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        btnBrowse.Focus();
                    }
                    else
                    {
                        Admin A = new Admin();
                        A.UserUpdatePhoto(tbEmpPhoto.Text, lblUser.Text);

                        MessageBox.Show("PROFILE PHOTO UPDATED", "UPDATE PHOTO SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        BindDetails();
                    }
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void FormMainMenuMaster_Load(object sender, EventArgs e)
        {
            lblUser.Text = dataPassing;
            lblDate.Text = DateTime.Now.ToShortDateString();
            lblTime.Text = DateTime.Now.ToLongTimeString();

            Admin CheckContract = new Admin();

            ArrayList data_contract = CheckContract.CheckContractExpiration();

            for (int i = 0; i < data_contract.Count; i = i + 2)
            {
                string ContractNumber = (string)data_contract[i];
                string ContractEndDate = (string)data_contract[i + 1];

                string TodayDate = DateTime.Today.ToShortDateString();
                string Date1 = DateTime.Today.AddDays(-1).ToShortDateString();
                string Date2 = DateTime.Today.AddDays(-2).ToShortDateString();
                string Date3 = DateTime.Today.AddDays(-3).ToShortDateString();
                string Date4 = DateTime.Today.AddDays(-4).ToShortDateString();
                string Date5 = DateTime.Today.AddDays(-5).ToShortDateString();
                string Date6 = DateTime.Today.AddDays(-6).ToShortDateString();
                string Date7 = DateTime.Today.AddDays(-7).ToShortDateString();
                string Date8 = DateTime.Today.AddDays(-8).ToShortDateString();
                string Date9 = DateTime.Today.AddDays(-9).ToShortDateString();
                string Date10 = DateTime.Today.AddDays(-10).ToShortDateString();
                string Date11 = DateTime.Today.AddDays(-11).ToShortDateString();
                string Date12 = DateTime.Today.AddDays(-12).ToShortDateString();
                string Date13 = DateTime.Today.AddDays(-13).ToShortDateString();
                string Date14 = DateTime.Today.AddDays(-14).ToShortDateString();
                string Date15 = DateTime.Today.AddDays(-15).ToShortDateString();
                string Date16 = DateTime.Today.AddDays(-16).ToShortDateString();
                string Date17 = DateTime.Today.AddDays(-17).ToShortDateString();
                string Date18 = DateTime.Today.AddDays(-18).ToShortDateString();
                string Date19 = DateTime.Today.AddDays(-19).ToShortDateString();
                string Date20 = DateTime.Today.AddDays(-20).ToShortDateString();
                string Date21 = DateTime.Today.AddDays(-21).ToShortDateString();
                string Date22 = DateTime.Today.AddDays(-22).ToShortDateString();
                string Date23 = DateTime.Today.AddDays(-23).ToShortDateString();
                string Date24 = DateTime.Today.AddDays(-24).ToShortDateString();
                string Date25 = DateTime.Today.AddDays(-25).ToShortDateString();
                string Date26 = DateTime.Today.AddDays(-26).ToShortDateString();
                string Date27 = DateTime.Today.AddDays(-27).ToShortDateString();
                string Date28 = DateTime.Today.AddDays(-28).ToShortDateString();
                string Date29 = DateTime.Today.AddDays(-29).ToShortDateString();
                string Date30 = DateTime.Today.AddDays(-30).ToShortDateString();
                string Date31 = DateTime.Today.AddDays(-31).ToShortDateString();

                if (ContractEndDate == TodayDate || ContractEndDate == Date1 || ContractEndDate == Date2 || ContractEndDate == Date3 || ContractEndDate == Date4 || ContractEndDate == Date5 || ContractEndDate == Date6 || ContractEndDate == Date7 || ContractEndDate == Date8 || ContractEndDate == Date9 || ContractEndDate == Date10 || ContractEndDate == Date11 || ContractEndDate == Date12 || ContractEndDate == Date13 || ContractEndDate == Date14 || ContractEndDate == Date15 || ContractEndDate == Date16 || ContractEndDate == Date17 || ContractEndDate == Date18 || ContractEndDate == Date19 || ContractEndDate == Date20 || ContractEndDate == Date21 || ContractEndDate == Date22 || ContractEndDate == Date23 || ContractEndDate == Date24 || ContractEndDate == Date25 || ContractEndDate == Date26 || ContractEndDate == Date27 || ContractEndDate == Date28 || ContractEndDate == Date29 || ContractEndDate == Date30 || ContractEndDate == Date31)
                {
                    Console.Beep();
                    Console.Beep();
                    Console.Beep();
                    Console.Beep();

                    notifyContract.Text = "Contract Expired";
                    notifyContract.Visible = true;
                    notifyContract.BalloonTipTitle = "Contract Expired";
                    notifyContract.BalloonTipText = "Click Here to see details";
                    notifyContract.ShowBalloonTip(300000000);
                }
            }
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dialogResult = MessageBox.Show("DO YOU WANT TO EDIT THIS DATA CONTRACT?", "EDIT CONTRACT DETAILS", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Yes)
                {
                    if (tbUpdateContractNumber.Text == "" || tbUpdateContractName.Text == "" || rtbUpdateContractDescription.Text == "" || dtpUpdateContractStartDate.Text == "" || dtpUpdateContractEndDate.Text == "" || cbUpdateContractTime.SelectedIndex == -1 || tbUpdateContractStatus.Text == "" || tbUpdateContractInfo.Text == "")
                    {
                        MessageBox.Show("FORM FIELD(S) CAN NOT BE LEFT EMPTY. PLEASE COMPLETE THE FORM TO EDIT DATA", "DATA UPDATE ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {

                        string ContractNumber = tbUpdateContractNumber.Text;
                        string ContractName = tbUpdateContractName.Text;
                        string ContractDescription = rtbUpdateContractDescription.Text;
                        string ContractStartDate = dtpUpdateContractStartDate.Text;
                        string ContractPeriod = lblStartDate.Text + " EXTENDED " + cbUpdateContractTime.Text;
                        string ContractEndDate = dtpUpdateContractEndDate.Text;
                        string ContractInfo = tbUpdateContractInfo.Text;

                        Admin A = new Admin();
                        A.EditContractDetails(ContractNumber, ContractName, ContractDescription, ContractPeriod, ContractStartDate, ContractEndDate, ContractInfo);

                        MessageBox.Show("CONTRACT DETAILS UPDATED", "CONTRACT UPDATED", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        tbUpdateContractNumber.Clear();
                        tbUpdateContractName.Clear();
                        rtbUpdateContractDescription.Clear();
                        tbUpdateContractStatus.Clear();
                        cbUpdateContractTime.Text = "-----SELECT TIME-----";
                        tbUpdateContractInfo.Clear();

                        dtpStartDate.Text = DateTime.Today.ToShortDateString();
                        dtpEndDate.Text = DateTime.Today.ToShortDateString();
                        dtpUpdateContractStartDate.Text = DateTime.Today.ToShortDateString();
                        dtpUpdateContractEndDate.Text = DateTime.Today.ToShortDateString();

                        RefreshDG();
                    }
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void FormLogin_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F1)
            {
                MessageBox.Show("1. MASUKAN USERNAME DAN PASSWORD ANDA" +
                                            "\n    SESUAI DENGAN DATA DI DATABASE" +
                                            "\n2. USERNAME MAKSIMAL 10 KARAKTER" +
                                            "\n3. PASSWORD MAKSIMAL 10 KARAKTER" +
                                            "\n4. FORM INI CASE-SENSITIVE" +
                                            "\n5. JIKA ERROR TERJADI, HARAP LAPORKAN KE:" +
                                            "\n    [email protected] / 0811 940 90 65"
                                            , "HELP", MessageBoxButtons.OK, MessageBoxIcon.Question);
            }

            if (e.KeyCode == Keys.Enter)
            {
                try
                {
                    string uname = tbUsername.Text.Trim();
                    string passwd = tbPassword.Text.Trim();

                    if (uname == "" || passwd == "")
                    {
                        MessageBox.Show("PLEASE INPUT USERNAME AND/OR PASSWORD", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        tbPassword.Clear();
                        tbUsername.Focus();
                    }
                    else
                    {
                        Admin A = new Admin();
                        string[] values = A.Authentication(uname, passwd);

                        string dbUname = values[0];
                        string dbPsswd = values[1];
                        string dbLevel = values[2];

                        if (uname == dbUname && passwd == dbPsswd)
                        {
                            if (dbLevel == "Yes")
                            {
                                MessageBox.Show("WELCOME, " + uname + "", "WELCOME TO IHRIS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                FormMainMenuMaster MMM = new FormMainMenuMaster(uname);
                                this.Hide();
                                MMM.Show();
                            }
                            else
                            {
                                MessageBox.Show("WELCOME, " + uname + "", "WELCOME TO IHRIS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                FormUserMainMenu MM = new FormUserMainMenu(uname);
                                this.Hide();
                                MM.Show();
                            }
                        }
                        else
                        {
                            MessageBox.Show("INCORRECT USERNAME AND/OR PASSWORD", "INCORRECT LOGIN", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            tbPassword.Clear();
                            tbUsername.Focus();
                        }
                    }
                }
                catch (SqlException)
                {
                    MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (InvalidOperationException)
                {
                    MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                if (e.KeyCode == Keys.Escape)
                {
                    DialogResult dialogResult = MessageBox.Show("ARE YOU SURE WANT TO QUIT?", "QUIT", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (dialogResult == DialogResult.Yes)
                    {
                        this.Close();
                        Application.Exit();
                    }
                }
            }
        }
        private void btnSavePosition_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dialogResult = MessageBox.Show("SAVE DATA? \nMAKE SURE ALL THE FORM FIELDS FILLED CORRECTLY", "DATA ENTRY", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (dialogResult == DialogResult.Yes)
                {
                    if (cbPositionDivision.Text == "-----SELECT DIVISION-----" || tbPositionName.Text == "" || tbPayrollBase.Text == "")
                    {
                        MessageBox.Show("FORM FIELD(S) CAN NOT BE LEFT EMPTY. PLEASE COMPLETE THE FORM TO SAVE DATA", "DATA ENTRY ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        tbDivisionName.Focus();
                    }
                    else
                    {
                        string PositionName = tbPositionName.Text.Trim();
                        string DivisionID = cbPositionDivision.Text.Substring(0, 1).Trim(); ;
                        string PayrollBase = tbPayrollBase.Text.Trim();

                        Admin A = new Admin();
                        A.AddPosition(PositionName, PayrollBase, DivisionID);

                        tbPositionName.Clear();
                        cbPositionDivision.Text = "-----SELECT DIVISION-----";
                        tbPayrollBase.Clear();

                        MessageBox.Show("DATA SAVED", "ENTRY DATA SUCCESSFUL", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        RefreshDGV();

                    }
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void dgAddPayroll_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                string str = dgAddPayroll.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();

                Admin Bind = new Admin();
                ArrayList data_payroll = Bind.BindAddPayrollDetails(str);

                if (data_payroll.Count == 0)
                {
                    MessageBox.Show("NO DATA MATCH WITH DATABASE RECORDS", "NO DATA FOUND", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    for (int i = 0; i < data_payroll.Count; i = i + 2)
                    {
                        string EmpNIP = (string)data_payroll[i];
                        string PayrollBase = (string)data_payroll[i + 1];

                        tbSaveEmpNIP.Text = EmpNIP;
                        tbSaveEmpPayrollBase.Text = PayrollBase;
                    }
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void dgSearchItem_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                string str = dgSearchItem.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();

                Admin Bind = new Admin();
                ArrayList data_contract = Bind.BindAllItemDetails(str);

                if (data_contract.Count == 0)
                {
                    MessageBox.Show("NO DATA MATCH WITH DATABASE RECORDS", "NO DATA FOUND", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    for (int i = 0; i < data_contract.Count; i = i + 5)
                    {
                        string ItemNumber = (string)data_contract[i];
                        string ItemName = (string)data_contract[i + 1];
                        string ItemDescription = (string)data_contract[i + 2];
                        string ItemCategory = (string)data_contract[i + 3];
                        Int64 ItemStock = (Int64)data_contract[i + 4];

                        tbSearchItemNumber.Text = ItemNumber;
                        tbSearchItemName.Text = ItemName;
                        tbSearchItemDescription.Text = ItemDescription;
                        tbSearchItemCategory.Text = ItemCategory;
                        tbSearchItemStock.Text = ItemStock.ToString();
                    }
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dialogResult = MessageBox.Show("SAVE DATA? \nMAKE SURE ALL THE FORM FIELDS FILLED CORRECTLY", "DATA ENTRY", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (dialogResult == DialogResult.Yes)
                {
                    if (tbItemNumber.Text == "" || tbItemName.Text == "" || tbItemDescription.Text == "" || tbItemCategory.Text == "" || tbItemStock.Text == "")
                    {
                        MessageBox.Show("FORM FIELD(S) CAN NOT BE LEFT EMPTY. PLEASE COMPLETE THE FORM TO SAVE DATA", "DATA ENTRY ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        tbItemName.Focus();
                    }
                    else
                    {
                        string ItemNumber = tbItemNumber.Text;
                        string ItemName = tbItemName.Text;
                        string ItemDescription = tbItemDescription.Text;
                        string ItemCategory = tbItemCategory.Text;
                        string ItemStock = tbItemStock.Text;

                        Admin Save = new Admin();
                        Save.AddInventory(ItemNumber, ItemName, ItemDescription, ItemCategory, ItemStock);

                        MessageBox.Show("DATA SAVED", "ENTRY DATA SUCCESSFUL", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        tbItemName.Clear();
                        tbItemDescription.Clear();
                        tbItemCategory.Clear();
                        tbItemStock.Value = 0;

                        RefreshDG();

                    }
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dialogResult = MessageBox.Show("SAVE DATA? \nMAKE SURE ALL THE FORM FIELDS FILLED CORRECTLY", "DATA ENTRY", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (dialogResult == DialogResult.Yes)
                {
                    if (tbContractNumber.Text == "" || tbContractName.Text == "" || tbContractDescription.Text == "" || cbTime.SelectedIndex == -1 || tbContractInfo.Text == "")
                    {
                        MessageBox.Show("FORM FIELD(S) CAN NOT BE LEFT EMPTY. PLEASE COMPLETE THE FORM TO SAVE DATA", "DATA ENTRY ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        tbContractNumber.Focus();
                    }
                    else
                    {
                        string ContractNumber = tbContractNumber.Text;
                        string ContractName = tbContractName.Text;
                        string ContractDescription = tbContractDescription.Text;
                        string ContractTimePeriod = cbTime.Text;
                        string ContractStartDate = dtpStartDate.Text;
                        string ContractEndDate = dtpEndDate.Text;
                        string ContractInfo = tbContractInfo.Text;
                        string EmployeeNIP = lblUser.Text;

                        Admin Save = new Admin();
                        Save.AddContract(ContractNumber, ContractName, ContractDescription, ContractTimePeriod, ContractStartDate, ContractEndDate, ContractInfo, EmployeeNIP);

                        MessageBox.Show("DATA SAVED", "ENTRY DATA SUCCESSFUL", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        RefreshDG();

                        tbContractNumber.Clear();
                        tbContractName.Clear();
                        tbContractDescription.Clear();
                        cbTime.Text = "-----SELECT TIME-----";
                        dtpStartDate.Text = DateTime.Today.ToShortDateString();
                        dtpEndDate.Text = DateTime.Today.ToShortDateString();
                        dtpUpdateContractStartDate.Text = DateTime.Today.ToShortDateString();
                        dtpUpdateContractEndDate.Text = DateTime.Today.ToShortDateString();
                        tbContractInfo.Clear();
                    }
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dialogResult = MessageBox.Show("DO YOU WANT UPDATE STOCK?", "STOCK UPDATION", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (dialogResult == DialogResult.Yes)
                {
                    if (tbEditAddStock.Value == 0 || tbEditFinalStock.Text == "" || tbEditItemName.Text == "" || tbEditItemCategory.Text == "" || tbEditItemStock.Text == "" || tbEditItemDescription.Text == "" || tbEditItemNumber.Text == "")
                    {
                        MessageBox.Show("FORM FIELD(S) CAN NOT BE LEFT EMPTY. PLEASE COMPLETE THE FORM TO EDIT DATA", "DATA UPDATE ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        tbEditAddStock.Focus();
                    }
                    else
                    {
                        string InventoryNumber = tbEditItemNumber.Text;
                        string InventoryName = tbEditItemName.Text;
                        string InventoryDescription = tbEditItemDescription.Text;
                        string InventoryCategory = tbEditItemCategory.Text;
                        string ItemStock = tbEditFinalStock.Text;

                        Admin Update = new Admin();
                        Update.UpdateStock(InventoryNumber, InventoryName, InventoryDescription, InventoryCategory, ItemStock);

                        MessageBox.Show("STOCK UPDATED", "ITEM STOCK UPDATED", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        tbEditAddStock.Value = 0;

                        tbEditItemNumber.Clear();
                        tbEditItemName.Clear();
                        tbEditItemDescription.Clear();
                        tbEditItemCategory.Clear();
                        tbEditFinalStock.Clear();
                        tbEditItemStock.Clear();

                        RefreshDG();
                    }
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void InsertStatus()
        {
            //buat list baru yang akan dimasukkan status yang ada
            List<string> status = StatusKerja();

            for (int i = 0; i < status.Count; i++)
            {
                Admin A = new Admin();
                A.UpdateStatusAttendance(status);
            }
        }