public void DoRepeaterItem(RepeaterItem item, ArrayList selectedList, ArrayList unselectedList)
    {
        HtmlInputCheckBox         insertSelected = (HtmlInputCheckBox)item.FindControl("SystemFunctionEmailAlertInsert");
        HtmlInputCheckBox         updateSelected = (HtmlInputCheckBox)item.FindControl("SystemFunctionEmailAlertUpdate");
        HtmlInputCheckBox         deleteSelected = (HtmlInputCheckBox)item.FindControl("SystemFunctionEmailAlertDelete");
        ESystemFunctionEmailAlert a = new ESystemFunctionEmailAlert();

        a.FunctionID = int.Parse(insertSelected.Attributes["id"]);
        a.SystemFunctionEmailAlertInsert = insertSelected.Checked;
        a.SystemFunctionEmailAlertUpdate = updateSelected.Checked;
        a.SystemFunctionEmailAlertDelete = deleteSelected.Checked;
        if (a.SystemFunctionEmailAlertInsert || a.SystemFunctionEmailAlertUpdate || a.SystemFunctionEmailAlertDelete)
        {
            selectedList.Add(a);
        }
        else
        {
            unselectedList.Add(a);
        }
    }
    protected void ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        HROne.Common.WebUtility.WebControlsLocalization(this, e.Item.Controls);

        HtmlInputCheckBox insertSelected = (HtmlInputCheckBox)e.Item.FindControl("SystemFunctionEmailAlertInsert");
        HtmlInputCheckBox updateSelected = (HtmlInputCheckBox)e.Item.FindControl("SystemFunctionEmailAlertUpdate");
        HtmlInputCheckBox deleteSelected = (HtmlInputCheckBox)e.Item.FindControl("SystemFunctionEmailAlertDelete");
        int id = (int)((DataRowView)e.Item.DataItem)["FunctionID"];

        insertSelected.Attributes["id"] = id.ToString();

        Label lblFunctionCode = (Label)e.Item.FindControl("FunctionCode");

        if (lblFunctionCode != null)
        {
            lblFunctionCode.Text = (string)((DataRowView)e.Item.DataItem)["FunctionCode"];
        }
        Label lblDescription = (Label)e.Item.FindControl("Description");

        if (lblDescription != null)
        {
            lblDescription.Text = HROne.Common.WebUtility.GetLocalizedStringByCode("FUNCTION_" + (string)((DataRowView)e.Item.DataItem)["FunctionCode"], (string)((DataRowView)e.Item.DataItem)["Description"]);
        }

        if (selectedFunctionList.ContainsKey(id))
        {
            ESystemFunctionEmailAlert o = (ESystemFunctionEmailAlert)selectedFunctionList[id];
            insertSelected.Checked = o.SystemFunctionEmailAlertInsert;
            updateSelected.Checked = o.SystemFunctionEmailAlertUpdate;
            deleteSelected.Checked = o.SystemFunctionEmailAlertDelete;
        }
        //if (WebUtils.IsTrialVersion(Session))
        //{
        //    selected.Checked = true;
        //    selected.Disabled = true;
        //    wselected.Checked = true;
        //    wselected.Disabled = true;
        //}
    }
    protected void Save_Click(object sender, EventArgs e)
    {
        EUserGroup c = new EUserGroup();


        PageErrors errors = PageErrors.getErrors(ESystemFunctionEmailAlert.db, Page.Master);

        errors.clear();



        ArrayList selectedList   = new ArrayList();
        ArrayList unselectedList = new ArrayList();

        foreach (RepeaterItem item in SystemPermissions.Items)
        {
            DoRepeaterItem(item, selectedList, unselectedList);
        }
        foreach (RepeaterItem item in SecurityPermissions.Items)
        {
            DoRepeaterItem(item, selectedList, unselectedList);
        }
        foreach (RepeaterItem item in PersonnelPermissions.Items)
        {
            DoRepeaterItem(item, selectedList, unselectedList);
        }
        foreach (RepeaterItem item in LeavePermissions.Items)
        {
            DoRepeaterItem(item, selectedList, unselectedList);
        }
        foreach (RepeaterItem item in PayrollPermissions.Items)
        {
            DoRepeaterItem(item, selectedList, unselectedList);
        }
        foreach (RepeaterItem item in MPFPermissions.Items)
        {
            DoRepeaterItem(item, selectedList, unselectedList);
        }
        foreach (RepeaterItem item in CostCenterPermissions.Items)
        {
            DoRepeaterItem(item, selectedList, unselectedList);
        }
        foreach (RepeaterItem item in AttendancePermissions.Items)
        {
            DoRepeaterItem(item, selectedList, unselectedList);
        }
        foreach (RepeaterItem item in TaxationPermissions.Items)
        {
            DoRepeaterItem(item, selectedList, unselectedList);
        }
        foreach (RepeaterItem item in TrainingPermissions.Items)
        {
            DoRepeaterItem(item, selectedList, unselectedList);
        }
        //foreach (RepeaterItem item in ReportPermissions.Items)
        //    DoRepeaterItem(item, list);
        //foreach (RepeaterItem item in PersonnelReportsPermissions.Items)
        //    DoRepeaterItem(item, list);
        //foreach (RepeaterItem item in PayrollReportsPermissions.Items)
        //    DoRepeaterItem(item, list);
        //foreach (RepeaterItem item in TaxationReportsPermissions.Items)
        //    DoRepeaterItem(item, list);


        if (!errors.isEmpty())
        {
            return;
        }

        WebUtils.StartFunction(Session, FUNCTION_CODE);

        ESystemParameter.setParameter(dbConn, ESystemParameter.PARAM_CODE_EMAIL_AUDIT_TRAIL_ADDRESS, string.Join(";", txtEMAIL_AUDIT_TRAIL_ADDRESS.Text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)));
        foreach (ESystemFunctionEmailAlert o in selectedList)
        {
            DBFilter filter = new DBFilter();
            filter.add(new Match("FunctionID", o.FunctionID));

            ArrayList alertList = ESystemFunctionEmailAlert.db.select(dbConn, filter);
            if (alertList.Count == 0)
            {
                ESystemFunctionEmailAlert.db.insert(dbConn, o);
            }
            else
            {
                ESystemFunctionEmailAlert oldValue = ((ESystemFunctionEmailAlert)alertList[0]);
                if (oldValue.SystemFunctionEmailAlertDelete != o.SystemFunctionEmailAlertDelete || oldValue.SystemFunctionEmailAlertInsert != o.SystemFunctionEmailAlertInsert || oldValue.SystemFunctionEmailAlertUpdate != o.SystemFunctionEmailAlertUpdate)
                {
                    o.SystemFunctionEmailAlertID = oldValue.SystemFunctionEmailAlertID;
                    ESystemFunctionEmailAlert.db.update(dbConn, o);
                }
            }
        }

        foreach (ESystemFunctionEmailAlert o in unselectedList)
        {
            DBFilter filter = new DBFilter();
            filter.add(new Match("FunctionID", o.FunctionID));

            ArrayList alertList = ESystemFunctionEmailAlert.db.select(dbConn, filter);
            if (alertList.Count != 0)
            {
                foreach (ESystemFunctionEmailAlert alert in alertList)
                {
                    ESystemFunctionEmailAlert.db.delete(dbConn, alert);
                }
            }
        }

        WebUtils.EndFunction(dbConn);
        errors.addError(HROne.Common.WebUtility.GetLocalizedString("Updated Successful"));
    }