private short bindAuthority(string partCode)
        {
            try
            {
                string moduleCode = ConfigurationSettings.AppSettings["Emp_Module"];
                int userId = Convert.ToInt32(Session["UserId"]);
                cls_Module_Authority_Employee aEmp = new cls_Module_Authority_Employee();
                aEmp.EmployeeId = userId;

                DataTable dt = aEmp.SelectAuthority(moduleCode);

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (partCode == "Information")
                    {
                        //Chi quyen Employee Full moi co quyen dieu chuyen nhan su
                        if (dt.Rows[i]["AuthorityCode"].ToString() == ConfigurationSettings.AppSettings["Emp_FullAuthority"])
                            empAuthorityCode = dt.Rows[i]["AuthorityCode"].ToString();

                        if ((dt.Rows[i]["AuthorityCode"].ToString() == ConfigurationSettings.AppSettings["Emp_PartAuthority"]) &&
                            (empAuthorityCode.Length <= 0))
                            empAuthorityCode = dt.Rows[i]["AuthorityCode"].ToString();

                        if ((dt.Rows[i]["AuthorityCode"].ToString() == ConfigurationSettings.AppSettings["Emp_LeaderAuthority"]) &&
                           (empAuthorityCode.Length <= 0))
                            empAuthorityCode = dt.Rows[i]["AuthorityCode"].ToString();
                    }
                    else
                    {
                        if (dt.Rows[i]["AuthorityCode"].ToString() == ConfigurationSettings.AppSettings["SalaryAuthority"])
                            empAuthorityCode = dt.Rows[i]["AuthorityCode"].ToString();
                    }
                }
                short canView = 0;

                if (empAuthorityCode.Length > 0)
                {
                    if (partCode == "Information")
                    {
                        aEmp = new cls_Module_Authority_Employee();
                        aEmp.EmployeeId = userId;

                        int eId;
                        eId = Convert.ToInt32(Request["E_Id"]);
                        short canChange = aEmp.Check_EAuthority(eId, empAuthorityCode,
                                        ConfigurationSettings.AppSettings["Basic_EmpM"], out canView);
                    }
                    else canView = 1;
                }

                return canView;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int iUser = Session["UserId"] == null ? 0 : Convert.ToInt32(Session["UserId"].ToString());
                if (Request["A_Id"] != null)
                {
                    cls_Module_Authority_Employee aEmp = new cls_Module_Authority_Employee();
                    aEmp.EmployeeId = iUser;
                    aEmp.AuthorityId = Convert.ToInt16(Request["A_Id"]);

                    DataTable _dt = aEmp.GetCompanyByAuthorityId();
                    DataTable dtDepartment = aEmp.GetDepartmentByAuthorityId();

                    StringBuilder sb = new StringBuilder();

                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        sb.Append("<TABLE WIDTH='520' align='center' BORDER='0' CELLSPACING='1' CELLPADDING='0'>" +
                                    "<tr class='PortalTR'><td colspan='2' height='26'>" +
                                    "   <img src='../images/NhanSu/icon_portal.gif' border='0' align='absmiddle' hspace='2'><b>"+_dt.Rows[i]["ComName"].ToString()+"</b></td></tr><tr><td colspan='2' bgcolor='#CCCCCC'></td></tr>" +
                                    "<tr><td colspan='2' bgcolor='gray'></td></tr>");

                        DataRow[] _row = dtDepartment.Select("CompanyId=" + _dt.Rows[i]["Id"].ToString());
                        if (_row.Count() > 0)
                        {
                            for(int j=0; j< _row.Count(); j++)
                            {
                                sb.Append("<tr bgcolor='#DDDDDD' ><td width='20'><SPAN CLASS='Normal' STYLE='width:20;overflow:hidden;'>" +
                                            "<INPUT  id='chkGroupId' type=\"checkbox\"  name='chkGroupId' value='" + _row[j]["Id"].ToString() + ":" + _row[j]["DepartName"].ToString() + "'></SPAN></td>" +
                                            "<td width='450' style='margin-left: 5' NOWRAP ONCLICK=\"flipFlop('SessionP" + _row[j]["Id"].ToString() + ":G" + _row[j]["Id"].ToString() + "')\">" +
                                            "<img src=\"../images/Treeview/ix_book.gif\" align='absmiddle'><span class='NormalBold'> " + _row[j]["DepartName"].ToString() + "</span>" +
                                            "<input type='hidden' name='hddChildCountSessionP" + _row[j]["Id"].ToString() + ":G" + _row[j]["Id"].ToString() + "'  Id='hddChildCountSessionP" + _row[j]["Id"].ToString() + ":G" + _row[j]["Id"].ToString() + "' value='0'></td></tr>");
                            }
                        }

                        sb.Append("</TABLE>");
                    }
                    ltlListDepartment.Text = sb.ToString();
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int iUser = Session["UserId"] == null ? 0 : Convert.ToInt32(Session["UserId"].ToString());
                if (Request["A_Id"] == null)
                {
                    _dt = new cls_Catalog_Company().Select((short)1, iUser);

                    StringBuilder sb = new StringBuilder();

                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        sb.Append("<tr class='normalbold' style='background:#DDDDDD' height='23'>" +
                                  "      <td><input type='checkbox' id='chkPortalId_" + (i + 1).ToString() + "' name='chkPortalId_" + (i + 1).ToString() + "' value='" + _dt.Rows[i]["Id"].ToString() + ":" + _dt.Rows[i]["ComName"].ToString() + "'></td>" +
                                  "      <td><img src='../images/NhanSu/icon_portal.gif' border='0' align='absmiddle' hspace='2'>" + _dt.Rows[i]["ComName"].ToString() + "</td>" +
                                  "</tr>");
                    }
                    ltlListCompany.Text = sb.ToString();
                }
                else
                {
                    cls_Module_Authority_Employee aEmp = new cls_Module_Authority_Employee();
                    aEmp.EmployeeId = iUser;
                    aEmp.AuthorityId = Convert.ToInt16(Request["A_Id"]);

                    _dt = aEmp.GetCompanyByAuthorityId();
                    StringBuilder sb = new StringBuilder();

                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        sb.Append("<tr class='normalbold' style='background:#DDDDDD' height='23'>" +
                                  "      <td><input type='checkbox' id='chkPortalId_" + (i + 1).ToString() + "' name='chkPortalId_" + (i + 1).ToString() + "' value='" + _dt.Rows[i]["Id"].ToString() + ":" + _dt.Rows[i]["ComName"].ToString() + "'></td>" +
                                  "      <td><img src='../images/NhanSu/icon_portal.gif' border='0' align='absmiddle' hspace='2'>" + _dt.Rows[i]["ComName"].ToString() + "</td>" +
                                  "</tr>");
                    }
                    ltlListCompany.Text = sb.ToString();
                }
            }
        }
        private void bindAuthority()
        {
            try
            {
                bool isExist = false;
                string moduleCode = ConfigurationSettings.AppSettings["Emp_Module"];
                int userId = Convert.ToInt32(Session["UserId"]);
                cls_Module_Authority_Employee aEmp = new cls_Module_Authority_Employee();
                aEmp.EmployeeId = userId;

                DataTable dt = aEmp.SelectAuthority(moduleCode);
                StringBuilder sb = new StringBuilder();
                sb.Append("<tr>" +
                          "  <td background=\"../images/NhanSu/MenuTab_Bg.gif\" height=\"40\" valign=\"bottom\" colspan=\"3\">" +
                          "  <link href=\"../CSS/Modules/Nhan_Su/TabMenu.css\" rel=\"stylesheet\" type=\"text/css\" />" +
                          "  <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">" +
                          "  <tbody><tr><td background=\"../images/NhanSu/tbar_lcap_on.gif\" width=\"5\"><img src=\"../images/1x1.gif\" border=\"0\" height=\"1\" width=\"5\"></td>" +
                          "  <td align=\"right\" background=\"../images/NhanSu/tbar_bg_on.gif\" nowrap=\"nowrap\" valign=\"middle\" width=\"190\"><img src=\"../images/1x1.gif\" border=\"0\" height=\"1\" width=\"188\"></td>" +
                          "  <td background=\"../images/NhanSu/tbar_bg_on.gif\" valign=\"middle\">" +
                          "  <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody><tr>" +
                          "  <td id=\"tspacer\"><img src=\"../images/1x1.gif\" height=\"1\" width=\"1\"></td>");

                sb.Append("<td class=\"ltab_off\"><img src=\"../images/1x1.gif\" height=\"27\" width=\"7\"></td>" +
                                  "  <td class=\"mainlevel-top\" nowrap=\"nowrap\"><a href=\"List.aspx\">Nhân sự</a></td>" +
                                  "  <td class=\"rtab_off\"><img src=\"../images/1x1.gif\" height=\"26\" width=\"7\"></td>" +
                                  "  <td id=\"tspacer\"><img src=\"../images/1x1.gif\" height=\"1\" width=\"1\"></td>");

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["AuthorityCode"].ToString() == ConfigurationSettings.AppSettings["PermissionAuthority"])
                    {
                        empAuthorityCode = dt.Rows[i]["AuthorityCode"].ToString();
                        sb.Append("<td class=\"ltab_on\"><img src=\"../images/1x1.gif\" height=\"26\" width=\"7\"></td>" +
                                  "  <td class=\"mainlevel-top-selected\" nowrap=\"nowrap\"><a href=\"\">Phân quyền</a></td>" +
                                  "  <td class=\"rtab_on\"><img src=\"../images/1x1.gif\" height=\"26\" width=\"7\"></td>" +
                                  "  <td id=\"tspacer\"><img src=\"../images/1x1.gif\" height=\"1\" width=\"1\"></td>");

                    }

                    if (dt.Rows[i]["AuthorityCode"].ToString() == ConfigurationSettings.AppSettings["SalaryAuthority"])
                    {
                        sb.Append("<td class=\"ltab_off\"><img src=\"../images/1x1.gif\" height=\"27\" width=\"7\"></td>" +
                                  "  <td class=\"mainlevel-top\" nowrap=\"nowrap\"><a href=\"../N_Su/Calculate_Salary.aspx\">Tiền Lương</a></td>" +
                                  "  <td class=\"rtab_off\"><img src=\"../images/1x1.gif\" height=\"26\" width=\"7\"></td>" +
                                  "  <td id=\"tspacer\"><img src=\"../images/1x1.gif\" height=\"1\" width=\"1\"></td>");
                    }

                    if (dt.Rows[i]["AuthorityCode"].ToString() == ConfigurationSettings.AppSettings["ManageAuthority"])
                    {
                        sb.Append("<td class=\"ltab_off\"><img src=\"../images/1x1.gif\" height=\"27\" width=\"7\"></td>" +
                                  "  <td class=\"mainlevel-top\" nowrap=\"nowrap\"><a href=\"../DanhMuc/Company.aspx\">Quản Trị</a></td>" +
                                  "  <td class=\"rtab_off\"><img src=\"../images/1x1.gif\" height=\"26\" width=\"7\"></td>" +
                                  "  <td id=\"tspacer\"><img src=\"../images/1x1.gif\" height=\"1\" width=\"1\"></td>");
                    }

                    if ((dt.Rows[i]["AuthorityCode"].ToString() == ConfigurationSettings.AppSettings["Emp_FullAuthority"]) &&
                        (isExist == false))
                    {
                        isExist = true;
                        sb.Append("<td class=\"ltab_off\"><img src=\"../images/1x1.gif\" height=\"27\" width=\"7\"></td>" +
                                  "  <td class=\"mainlevel-top\" nowrap=\"nowrap\"><a href=\"Attendance_Tracking.aspx\">Chấm công</a></td>" +
                                  "  <td class=\"rtab_off\"><img src=\"../images/1x1.gif\" height=\"26\" width=\"7\"></td>" +
                                  "  <td id=\"tspacer\"><img src=\"../images/1x1.gif\" height=\"1\" width=\"1\"></td>");
                    }

                    if ((dt.Rows[i]["AuthorityCode"].ToString() == ConfigurationSettings.AppSettings["Emp_PartAuthority"]) &&
                        (isExist == false))
                    {
                        isExist = true;
                        sb.Append("<td class=\"ltab_off\"><img src=\"../images/1x1.gif\" height=\"27\" width=\"7\"></td>" +
                                  "  <td class=\"mainlevel-top\" nowrap=\"nowrap\"><a href=\"Attendance_Tracking.aspx\">Chấm công</a></td>" +
                                  "  <td class=\"rtab_off\"><img src=\"../images/1x1.gif\" height=\"26\" width=\"7\"></td>" +
                                  "  <td id=\"tspacer\"><img src=\"../images/1x1.gif\" height=\"1\" width=\"1\"></td>");
                    }
                }
                sb.Append("<td class=\"ltab_off\"><img src=\"../images/1x1.gif\" height=\"27\" width=\"7\"></td>" +
                                  "  <td class=\"mainlevel-top\" nowrap=\"nowrap\"><a href=\"PageReport.aspx\">Báo cáo</a></td>" +
                                  "  <td class=\"rtab_off\"><img src=\"../images/1x1.gif\" height=\"26\" width=\"7\"></td>" +
                                  "  <td id=\"tspacer\"><img src=\"../images/1x1.gif\" height=\"1\" width=\"1\"></td>");

                sb.Append("         </tr></tbody></table>" +
                          "          </td><td align=\"left\" background=\"../images/NhanSu/tbar_bg_on.gif\" valign=\"middle\" width=\"100%\"><img src=\"/images/tabs/rtabs.gif\" border=\"0\" height=\"27\" width=\"1\"></td><td background=\"../images/NhanSu/tbar_rcap_on.gif\" width=\"5\"><img src=\"../images/pixel.gif\" border=\"0\" height=\"1\" width=\"5\"></td>" +
                          "          </tr></tbody></table>" +
                          "      </td>" +
                          "  </tr>");

                ltlAuthorityList.Text = sb.ToString();
            }
            catch (Exception ex)
            {
            }
        }
        private void bindCompanyList()
        {
            try
            {
                cls_Module_Authority_Employee aEmp = new cls_Module_Authority_Employee();
                aEmp.EmployeeId = Convert.ToInt32(Session["UserId"]);

                DataTable dtCom = aEmp.GetWorkingCompany(ConfigurationSettings.AppSettings["Emp_Module"], empAuthorityCode);
                ddlCompany.DataSource = dtCom;
                ddlCompany.DataBind();

                DataRow drow = dtCom.NewRow();
                drow["Id"] = 0;
                drow["ComName"] = "-- Lựa chọn --";
                dtCom.Rows.InsertAt(drow, 0);

                ddlBelongCompany.DataSource = dtCom;
                ddlBelongCompany.DataBind();

                if (Request["C_Id"] != null)
                {
                    ddlCompany.SelectedValue = Request["C_Id"].ToString();
                    ddlBelongCompany.SelectedValue = Request["C_Id"].ToString();
                }
            }
            catch (Exception ex)
            {
            }
        }
        private List<cls_Module_Authority_Employee> getList(DataTable dt, short moduleId)
        {
            try
            {
                List<cls_Module_Authority_Employee> list = new List<cls_Module_Authority_Employee>();

                cls_Module_Authority_Employee aEmp = new cls_Module_Authority_Employee();
                aEmp.EmployeeId = Convert.ToInt32(Session["UserId"]);
                DataTable dtAuthority = aEmp.GetByModuleCode(ConfigurationSettings.AppSettings["Emp_Module"]);

                for (int i = 0; i < dtAuthority.Rows.Count; i++)
                {
                    aEmp = new cls_Module_Authority_Employee();
                    aEmp.Company = "";
                    aEmp.Department = "";

                    DataRow[] _Row = dt.Select("AuthorityId=" + dtAuthority.Rows[i]["Id"].ToString());
                    for (int j = 0; j < _Row.Count(); j++)
                    {
                        aEmp.Company += _Row[j]["CompanyId"].ToString() + ";";
                        aEmp.Department += _Row[j]["DepartmentId"].ToString() + ";";
                    }
                    aEmp.Company = aEmp.Company.Substring(0, aEmp.Company.Length - 1);
                    aEmp.Department = aEmp.Department.Substring(0, aEmp.Department.Length - 1);
                    if (aEmp.Company == "0") aEmp.Company = "";
                    if (aEmp.Department == "0") aEmp.Department = "";

                    aEmp.AuthorityId = Convert.ToInt16(_Row[0]["AuthorityId"]);
                    aEmp.AuthorityName = _Row[0]["AuthorityName"].ToString();
                    aEmp.ModuleId = moduleId;
                    aEmp.IsUse = Convert.ToInt16(_Row[0]["IsUse"]);
                    aEmp.UseDepartment = Convert.ToInt16(_Row[0]["UseDepartment"]);

                    list.Add(aEmp);
                }
                return list;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
        private void bindRepeaterG(int gId)
        {
            try
            {
                //LAY DANH SACH CONG TY
                cls_Module_Authority_Employee aEmp = new cls_Module_Authority_Employee();
                aEmp.EmployeeId = Convert.ToInt32(Session["UserId"]);

                DataTable dt = aEmp.GetCompanyByAuthorityCode(ConfigurationSettings.AppSettings["PermissionAuthority"]);
                ddlCompanySelect1.DataSource = dt;
                ddlCompanySelect1.DataBind();
                ViewState["DT_COMPANY"] = dt;
                ViewState["DT_DEPARTMENT"] = new cls_DepartmentInformation().SelectList(0);

                bindGroupList(gId);

                short moduleId;
                isChange = true;
                dt = new cls_Module_Authority_Group().SelectByGId(Convert.ToInt32(Session["UserId"]), ConfigurationSettings.AppSettings["Emp_Module"],
                                                            ConfigurationSettings.AppSettings["PermissionAuthority"], gId, out moduleId);

                List<cls_Module_Authority_Employee> list = getList(dt, moduleId);
                ViewState["DT_GAUTHORITY"] = dt;

                rptData1.DataSource = list;
                rptData1.DataBind();
            }
            catch (Exception ex)
            {
            }
        }
        private void bindRepeaterE(int empId)
        {
            try
            {
                //LAY DANH SACH CONG TY
                cls_Module_Authority_Employee aEmp = new cls_Module_Authority_Employee();
                aEmp.EmployeeId = Convert.ToInt32(Session["UserId"]);

                DataTable dt = aEmp.GetCompanyByAuthorityCode(ConfigurationSettings.AppSettings["PermissionAuthority"]);
                ddlCompanySelect.DataSource = dt;
                ddlCompanySelect.DataBind();
                ViewState["DT_COMPANY"] = dt;
                ViewState["DT_DEPARTMENT"] = new cls_DepartmentInformation().SelectList(0);

                bindCboEmployee(empId);

                short moduleId, isAdmin;
                dt = aEmp.SelectByEId(ConfigurationSettings.AppSettings["Emp_Module"], ConfigurationSettings.AppSettings["PermissionAuthority"],
                                        empId, out moduleId, out isAdmin);

                if (isAdmin > 0)
                    btnESave.Enabled = isChange = false;
                else
                    btnESave.Enabled = isChange = true;

                List<cls_Module_Authority_Employee> list = getList(dt, moduleId);
                ViewState["DT_EAUTHORITY"] = dt;

                rptData.DataSource = list;
                rptData.DataBind();
            }
            catch (Exception ex)
            {
            }
        }
        private void bindPermissionList()
        {
            try
            {
                // --- BIND CAC NHOM DA DUOC PHAN QUYEN ---
                // --- LAY DANH SACH CAC QUYEN CUA NGUOI DUNG HIEN TAI DUOC PHAN ---

                cls_Module_Authority_Employee aEmp = new cls_Module_Authority_Employee();
                aEmp.EmployeeId = Convert.ToInt32(Session["UserId"]);
                DataTable dtAuthority = aEmp.GetByModuleCode(ConfigurationSettings.AppSettings["Emp_Module"]);

                StringBuilder sb = new StringBuilder();
                sb.Append(" <table class=\"basic-table\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">" +
                             "  <tbody><tr>" +
                             "      <td>" +
                             "          <table class=\"form-table\" border=\"0\" cellpadding=\"4\"><tbody>" +
                             "              <tr class=\"gray\">" +
                             "                  <td colspan=\"" + dtAuthority.Rows.Count.ToString() + "\">PHÂN QUYỀN NHÓM NGƯỜI DÙNG</td>" +
                             "                  <td align=\"right\" colspan=\"2\"><a href=\"Permission.aspx?P_action=2\">+Bổ sung</a></td>" +
                             "              </tr>" +
                             "              <tr bgcolor=\"whitesmoke\">" +
                             "                  <td class=\"Normal\" width=\"180px\"> <u>Nhóm đã phân quyền </u></td>");
                for (int i = 0; i < dtAuthority.Rows.Count; i++)
                {
                    sb.Append("                  <td class=\"NormalBold\" align=\"center\">Quyền " + dtAuthority.Rows[i]["AuthorityName"].ToString() + "</td>");
                }
                sb.Append("                  <td class=\"normal\">Cập nhật</td>" +
                          "              </tr>");

                cls_Module_Authority_Group aGroup = new cls_Module_Authority_Group();
                aGroup.CompanyId = Convert.ToInt16(ddlCompany.SelectedValue);
                DataTable dtGroup = aGroup.SelectGroupByCompany(ConfigurationSettings.AppSettings["Emp_Module"]);

                if (dtGroup.Rows.Count > 0)
                {
                    DataTable dtGAuthority = aGroup.SelectByCompany(ConfigurationSettings.AppSettings["Emp_Module"], Convert.ToInt32(Session["UserId"]));

                    for (int i = 0; i < dtGroup.Rows.Count; i++)
                    {
                        DataRow[] _Row = dtGAuthority.Select("GroupId=" + dtGroup.Rows[i]["GroupId"].ToString(), "AuthorityCode asc");

                        sb.Append("<tr>" +
                                  "     <td class=\"NormalBold\"><img src=\"../images/Message/user-group.png\" /> " + _Row[0]["GroupName"].ToString() + "</td>");

                        for (int j = 0; j < _Row.Count(); j++)
                        {
                            if (_Row[j]["IsUse"].ToString() == "1")
                                sb.Append("     <Td class=\"normal\" align=\"center\"><img src=\"../images/Update.gif\" align=\"absmiddle\"> </td>");
                            else
                                sb.Append("     <Td class=\"normal\" align=\"center\">&nbsp;</td>");
                        }

                        sb.Append("     <td class=\"normal\" align=\"center\"><a href=\"Permission.aspx?P_action=2&G_Id=" + dtGroup.Rows[i]["GroupId"].ToString() + "\">Sửa</a></td>" +
                                  "</tr>");
                    }
                }
                else
                {
                    sb.Append("<tr><td class=\"NormalBold\" align=\"center\" colspan=\"" + (dtAuthority.Rows.Count + 2).ToString() + "\"><i>Hiện chưa có nhóm nào được phân quyền.</i></td></tr>");
                }
                sb.Append("              </tbody>" +
                          "          </table>" +
                          "      </td>" +
                          "  </tr>" +
                        "</tbody></table>");
                ltlListGroup.Text = sb.ToString();

                // --- BIND CAC NGUOI DUNG DA DUOC PHAN QUYEN ---
                sb = new StringBuilder();
                sb.Append(" <table class=\"basic-table\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">" +
                             "  <tbody><tr>" +
                             "      <td>" +
                             "          <table class=\"form-table\" border=\"0\" cellpadding=\"4\"><tbody>" +
                             "              <tr class=\"gray\">" +
                             "                  <td colspan=\"" + dtAuthority.Rows.Count.ToString() + "\">PHÂN QUYỀN NGƯỜI DÙNG</td>" +
                             "                  <td align=\"right\" colspan=\"2\"><a href=\"Permission.aspx?P_action=3\">+Bổ sung</a></td>" +
                             "              </tr>" +
                             "              <tr bgcolor=\"whitesmoke\">" +
                             "                  <td class=\"Normal\" width=\"180px\"><u>Người dùng đã phân quyền </u></td>");
                for (int i = 0; i < dtAuthority.Rows.Count; i++)
                {
                    sb.Append("                  <td class=\"NormalBold\" align=\"center\">Quyền " + dtAuthority.Rows[i]["AuthorityName"].ToString() + "</td>");
                }
                sb.Append("                  <td class=\"normal\">Cập nhật</td>" +
                          "              </tr>");

                aEmp = new cls_Module_Authority_Employee();
                aEmp.EmployeeId = Convert.ToInt32(Session["UserId"]);
                aEmp.CompanyId = Convert.ToInt16(ddlCompany.SelectedValue);

                DataTable dtEmp = aEmp.SelectEmpByCompany(ConfigurationSettings.AppSettings["Emp_Module"]);

                if (dtEmp.Rows.Count > 0)
                {
                    DataTable dtEAuthority = aEmp.SelectByCompany(ConfigurationSettings.AppSettings["Emp_Module"]);

                    for (int i = 0; i < dtEmp.Rows.Count; i++)
                    {
                        DataRow[] _Row = dtEAuthority.Select("EmployeeId=" + dtEmp.Rows[i]["EmployeeId"].ToString(), "AuthorityCode asc");

                        sb.Append("<tr>" +
                                  "     <td class=\"NormalBold\"><img src=\"../images/MRoom/user.gif\" /> " + _Row[0]["EmployName"].ToString() + "</td>");

                        for (int j = 0; j < _Row.Count(); j++)
                        {
                            if (_Row[j]["IsUse"].ToString() == "1")
                                sb.Append("     <Td class=\"normal\" align=\"center\"><img src=\"../images/Update.gif\" align=\"absmiddle\"> </td>");
                            else
                                sb.Append("     <Td class=\"normal\" align=\"center\">&nbsp;</td>");
                        }

                        sb.Append("     <td class=\"normal\" align=\"center\"><a href=\"Permission.aspx?P_action=3&E_Id=" + dtEmp.Rows[i]["EmployeeId"].ToString() + "\">Sửa</a></td>" +
                                  "</tr>");
                    }
                }
                else
                {
                    sb.Append("<tr><td class=\"NormalBold\" align=\"center\" colspan=\"" + (dtAuthority.Rows.Count + 2).ToString() + "\"><i>Hiện chưa có người dùng nào được phân quyền.</i></td></tr>");
                }
                sb.Append("              </tbody>" +
                          "          </table>" +
                          "      </td>" +
                          "  </tr>" +
                        "</tbody></table>");
                ltlListEmployee.Text = sb.ToString();

            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 10
0
        private void bindData()
        {
            try
            {
                //LAY DANH SACH CONG TY
                cls_Module_Authority_Employee aEmp = new cls_Module_Authority_Employee();
                aEmp.EmployeeId = Convert.ToInt32(Session["UserId"]);

                DataTable dt = aEmp.GetCompanyByAuthorityCode(ConfigurationSettings.AppSettings["PermissionAuthority"]);
                ddlCompany.DataSource = dt;
                ddlCompany.DataBind();

                bindPermissionList();
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 11
0
        protected void btnESave_Click(object sender, EventArgs e)
        {
            try
            {
                DataTable dtCompany = (DataTable)ViewState["DT_COMPANY"];
                DataTable dtDepartment = (DataTable)ViewState["DT_DEPARTMENT"];
                DataTable dtOld = (DataTable)ViewState["DT_EAUTHORITY"];

                DataTable dtEAuthority = new DataTable();
                dtEAuthority.Columns.Add("Id", typeof(int));
                dtEAuthority.Columns.Add("ModuleId");
                dtEAuthority.Columns.Add("AuthorityId");
                dtEAuthority.Columns.Add("EmployeeId");
                dtEAuthority.Columns.Add("CompanyId");
                dtEAuthority.Columns.Add("DepartmentId");
                dtEAuthority.Columns.Add("CreatedTime");

                int e_id;
                short mId = 0;
                e_id = Convert.ToInt32(cboEmployee.SelectedValue);

                if (e_id == 0)
                {
                    ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(),
                                    "MyScript", "alert('Bạn phải chọn Nhân viên cần phân quyền trước !');", true);
                    cboEmployee.Focus();
                    return;
                }

                for (int i = 0; i < rptData.Items.Count; i++)
                {
                    RepeaterItem item = rptData.Items[i];

                    var chkSelectA = (CheckBox)item.FindControl("chkSelectA");
                    var lblAuthorityId = (Label)item.FindControl("lblAuthorityId");
                    var lblModuleId = (Label)item.FindControl("lblModuleId");
                    mId = Convert.ToInt16(lblModuleId.Text);
                    var lbAuthorityName = (Label)item.FindControl("lbAuthorityName");

                    var txtComName = (TextBox)item.FindControl("txtComName");
                    var txtDepartName = (TextBox)item.FindControl("txtDepartName");

                    if (chkSelectA.Checked == true)
                    {
                        if (txtComName.Text.Length <= 0)
                        {
                            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(),
                                    "MyScript", "alert('Bạn phải chọn Công ty cho Quyền \"" + lbAuthorityName.Text + "\" !');", true);
                            txtComName.Focus();
                            return;
                        }
                        if (txtDepartName.Visible == true && txtDepartName.Text.Length <= 0)
                        {
                            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(),
                                    "MyScript", "alert('Bạn phải chọn Phòng/Ban cho Quyền \"" + lbAuthorityName.Text + "\" !');", true);
                            txtDepartName.Focus();
                            return;
                        }

                        if (txtDepartName.Visible == true)
                        {
                            DataTable dtDepartmentId = getDepartmentIdList(txtDepartName.Text, dtDepartment);

                            for (int j = 0; j < dtDepartmentId.Rows.Count; j++)
                            {
                                DataRow dRow = dtEAuthority.NewRow();
                                DataRow[] _Row = dtOld.Select("AuthorityId=" + lblAuthorityId.Text + " AND DepartmentId=" + dtDepartmentId.Rows[j]["Id"].ToString());

                                if (_Row.Count() > 0)
                                    dRow["Id"] = _Row[0]["Id"];
                                else
                                    dRow["Id"] = "0";

                                dRow["ModuleId"] = lblModuleId.Text;
                                dRow["AuthorityId"] = lblAuthorityId.Text;
                                dRow["EmployeeId"] = e_id;
                                dRow["CompanyId"] = dtDepartmentId.Rows[j]["CompanyId"];
                                dRow["DepartmentId"] = dtDepartmentId.Rows[j]["Id"];
                                dRow["CreatedTime"] = DateTime.Now;

                                dtEAuthority.Rows.Add(dRow);
                            }
                        }
                        else
                        {
                            DataTable dtCompanyId = getCompanyIdList(txtComName.Text, dtCompany);

                            for (int j = 0; j < dtCompanyId.Rows.Count; j++)
                            {
                                DataRow dRow = dtEAuthority.NewRow();
                                DataRow[] _Row = dtOld.Select("AuthorityId=" + lblAuthorityId.Text + " AND CompanyId=" + dtCompanyId.Rows[j]["Id"].ToString());

                                if (_Row.Count() > 0)
                                    dRow["Id"] = _Row[0]["Id"];
                                else
                                    dRow["Id"] = "0";

                                dRow["ModuleId"] = lblModuleId.Text;
                                dRow["AuthorityId"] = lblAuthorityId.Text;
                                dRow["EmployeeId"] = e_id;
                                dRow["CompanyId"] = dtCompanyId.Rows[j]["Id"];
                                dRow["DepartmentId"] = 0;
                                dRow["CreatedTime"] = DateTime.Now;

                                dtEAuthority.Rows.Add(dRow);
                            }
                        }
                    }
                }
                int resultUpdate = new cls_Module_Authority_Employee().ExecuteUpdateByPId(dtEAuthority, e_id, mId);

                if (resultUpdate > 0)
                {
                    ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(),
                        "MyScript", "alert('Cập nhật phân quyền thao tác cho Nhân sự thành công!');", true);
                    Response.Redirect("Permission.aspx");
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(),
                        "MyScript", "alert('Có lỗi trong quá trình cập nhật, vui lòng thử lại !!!');", true);
                }
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 12
0
        protected void cboEmployee_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            int empId = Convert.ToInt32(cboEmployee.SelectedValue);

            if (empId > 0)
            {
                short moduleId, isAdmin;
                cls_Module_Authority_Employee aEmp = new cls_Module_Authority_Employee();
                aEmp.EmployeeId = Convert.ToInt32(Session["UserId"]);

                DataTable dt = aEmp.SelectByEId(ConfigurationSettings.AppSettings["Emp_Module"], ConfigurationSettings.AppSettings["PermissionAuthority"],
                                                    empId, out moduleId, out isAdmin);

                if (isAdmin > 0)
                    btnESave.Enabled = isChange = false;
                else
                    btnESave.Enabled = isChange = true;

                List<cls_Module_Authority_Employee> list = getList(dt, moduleId);
                ViewState["DT_EAUTHORITY"] = dt;

                rptData.DataSource = list;
                rptData.DataBind();
            }
        }