protected void modalBtnSubmit_Command(object sender, CommandEventArgs e)
        {
            //if (modalChkBoxUpdateRate.Checked == true) //Checks if starttime and endtime is in correct format
            //{
            //    TimeSpan starttime = new TimeSpan();
            //    TimeSpan endtime = new TimeSpan();
            //    if (TimeSpan.TryParse(modalTxtBoxStartTime.Text, out starttime))
            //    {

            //    }
            //    else
            //    {
            //        modalLabelError.Text = "Start Time not in valid format.";
            //        modalLabelError.Visible = true;
            //    }
            //    if (TimeSpan.TryParse(modalTxtBoxEndTime.Text, out endtime))
            //    {

            //    }
            //    else
            //    {
            //        modalLabelError.Text = "End Time not in valid format.";
            //        modalLabelError.Visible = true;
            //    }
            //}
            if (modalLabelError.Visible == true)
                this.programmaticModalPopup.Show();
            else
            {
                int userid = Convert.ToInt32(Session["UserId"]);
                User user = new User();
                if (modalLabelUserId.Text.Trim() != "") //Update
                {
                    user = user.GetUser(Convert.ToInt32(modalLabelUserId.Text));
                }
                user.Firstname = modalTxtBoxFirstname.Text.Trim();
                user.Lastname = modalTxtBoxLastname.Text.Trim();
                user.RoleId = Convert.ToInt32(modalDropDownRole.SelectedItem.Value);
                user.DepartmentId = Convert.ToInt32(modalDropDownDepartment.SelectedItem.Value);
                user.Username = modalTxtBoxUsername.Text.Trim();
                user.Password = modalTxtBoxPassword.Text.Trim();
                user.Email = modalTxtBoxEmail.Text.Trim();
                user.Phone = modalTxtBoxPhone.Text.Trim();
                user.Fax = modalTxtBoxFax.Text.Trim();
                user.Mobile = modalTxtBoxMobile.Text.Trim();
                user.LastUpdatedBy = userid;
                user.LastUpdateDate = DateTime.Now;
                user.EmployeeNumber = Convert.ToInt32(modalTxtBoxEmployeeNo.Text);
                user.Status = modalDropDownStatus.SelectedItem.Value;
                //user.Shift = modalRadBtnListShift.SelectedItem.Value.Trim();
                if (e.CommandArgument.ToString().Trim() == "Add")
                {
                    user.CreateDate = DateTime.Now;
                    user.CreatedBy = userid;
                    user.Insert(user);
                    user = user.GetLastInsertedUser(); //assign newly created user to variable user
                }
                else if (e.CommandArgument.ToString().Trim() == "Update")
                {
                    user.Update(user);
                }
                if (modalChkBoxUpdateRate.Checked == true) //User intends to update salary rate
                {
                    UserRateSchedule userRateSchedule = new UserRateSchedule();
                    userRateSchedule = userRateSchedule.GetUserScheduleRateByUserIdStartDate(user.Id, DateTime.Today); //Checks if there is already a schedule date with the same start date
                    if (userRateSchedule != null)
                    {
                        userRateSchedule.StartTime = modalTxtBoxStartTime.Text.Trim();
                        userRateSchedule.EndTime = modalTxtBoxEndTime.Text.Trim();
                        userRateSchedule.OffDay = Convert.ToInt32(modalDropDownOffDay.SelectedItem.Value);
                        userRateSchedule.SpecialOffDay = Convert.ToInt32(modalDropDownSpecialOffDay.SelectedItem.Value);
                        userRateSchedule.NoOTPay = modalChckBoxNoOTPay.Checked;
                        userRateSchedule.Update(userRateSchedule);
                        userRateSchedule.IsOfficeWorker = modalChckBoxOfficeWorker.Checked;
                        userRateSchedule.MinsBreak = Convert.ToInt32(modalTxtBoxBreakTimeMin.Text);
                    }
                    else
                    {
                        userRateSchedule = new UserRateSchedule();
                        UserRateSchedule prevUserRateSchedule = userRateSchedule.GetPreviousUserScheduleRateByUserIdLastUpdateDate(user.Id, DateTime.Today);
                        userRateSchedule.StartTime = modalTxtBoxStartTime.Text.Trim();
                        userRateSchedule.EndTime = modalTxtBoxEndTime.Text.Trim();
                        userRateSchedule.UserId = user.Id;
                        userRateSchedule.OffDay = Convert.ToInt32(modalDropDownOffDay.SelectedItem.Value);
                        userRateSchedule.SpecialOffDay = Convert.ToInt32(modalDropDownSpecialOffDay.SelectedItem.Value);
                        userRateSchedule.NoOTPay = modalChckBoxNoOTPay.Checked;
                        userRateSchedule.IsOfficeWorker = modalChckBoxOfficeWorker.Checked;
                        userRateSchedule.MinsBreak = Convert.ToInt32(modalTxtBoxBreakTimeMin.Text);
                        userRateSchedule.StartDate = DateTime.Today;
                        userRateSchedule.IsCurrentRate = true;

                        if (prevUserRateSchedule != null)
                        {
                            prevUserRateSchedule.EndDate = Convert.ToDateTime(DateTime.Today.AddDays(-1).ToString("dd MMM yyyy") + " 23:59:59");

                            prevUserRateSchedule.IsCurrentRate = false;
                            prevUserRateSchedule.Update(prevUserRateSchedule);
                        }

                        userRateSchedule.Insert(userRateSchedule);
                    }
                }
                InitializeGridUser();
                this.programmaticModalPopup.Hide();
            }
        }
        protected void modalUserlinkBtnSubmit_Command(object sender, CommandEventArgs e)
        {
            bool haserror = false;
            int userid = Convert.ToInt32(Session["UserId"]);
            User user = new User();
            user = user.GetUser(userid);

            if (modalUserlinkChkBoxUpdate.Checked == true)
            {
                if (modalUserlinkTxtBoxOldPassword.Text.Trim() != user.Password.Trim())
                {
                    modalUserlinkLabelError.Text = "Invalid Old Password.";
                    modalUserlinkLabelError.Visible = true;
                    haserror = true;
                }
                else if (modalUserlinkTxtBoxPassword.Text.Trim() != modalUserlinkTxtBoxRetypePassword.Text.Trim())
                {
                    modalUserlinkLabelError.Text = "New password and retype-password does not match.";
                    modalUserlinkLabelError.Visible = true;
                    haserror = true;
                }
                if (haserror == false)
                {
                    user.Username = modalUserlinkTxtBoxUsername.Text.Trim();
                    user.Password = modalUserlinkTxtBoxPassword.Text.Trim();
                }
            }
            if (haserror == false)
            {
                user.Firstname = modalUserlinkTxtBoxFirstname.Text.Trim();
                user.Lastname = modalUserlinkTxtBoxLastname.Text.Trim();
                user.Email = modalUserlinkTxtBoxEmail.Text.Trim();
                user.Phone = modalUserlinkTxtBoxPhone.Text.Trim();
                user.Fax = modalUserlinkTxtBoxFax.Text.Trim();
                user.Mobile = modalUserlinkTxtBoxMobile.Text.Trim();
                user.LastUpdatedBy = userid;
                user.LastUpdateDate = DateTime.Now;
                user.Update(user);
            }
            else
            {
                this.programmaticUserlinkModalPopup.Show();
            }
        }