Beispiel #1
0
        public object SelectFunctionsByGroup(IDto selectDto)
        {
            #region Format outputed Datatable
            DataTable dtResult = new DataTable();
            dtResult.Columns.Add("FunctionID");
            dtResult.Columns.Add("FunctionName");

            dtResult.Columns.Add("AllMapping", typeof(string));
            dtResult.Columns.Add("AllID", typeof(string));
            dtResult.Columns.Add("AllName", typeof(string));
            dtResult.Columns.Add("All", typeof(bool));

            dtResult.Columns.Add("ViewMapping", typeof(string));
            dtResult.Columns.Add("ViewID", typeof(string));
            dtResult.Columns.Add("ViewName", typeof(string));
            dtResult.Columns.Add("View", typeof(bool));

            dtResult.Columns.Add("AddMapping", typeof(string));
            dtResult.Columns.Add("AddID", typeof(string));
            dtResult.Columns.Add("AddName", typeof(string));
            dtResult.Columns.Add("Add", typeof(bool));

            dtResult.Columns.Add("EditMapping", typeof(string));
            dtResult.Columns.Add("EditID", typeof(string));
            dtResult.Columns.Add("EditName", typeof(string));
            dtResult.Columns.Add("Edit", typeof(bool));

            dtResult.Columns.Add("DeleteMapping", typeof(string));
            dtResult.Columns.Add("DeleteID", typeof(string));
            dtResult.Columns.Add("DeleteName", typeof(string));
            dtResult.Columns.Add("Delete", typeof(bool));

            dtResult.Columns.Add("PrintMapping", typeof(string));
            dtResult.Columns.Add("PrintID", typeof(string));
            dtResult.Columns.Add("PrintName", typeof(string));
            dtResult.Columns.Add("Print", typeof(bool));

            dtResult.Columns.Add("ImportMapping", typeof(string));
            dtResult.Columns.Add("ImportID", typeof(string));
            dtResult.Columns.Add("ImportName", typeof(string));
            dtResult.Columns.Add("Import", typeof(bool));

            dtResult.Columns.Add("ExportMapping", typeof(string));
            dtResult.Columns.Add("ExportID", typeof(string));
            dtResult.Columns.Add("ExportName", typeof(string));
            dtResult.Columns.Add("Export", typeof(bool));

            dtResult.Columns.Add("Other", typeof(bool));
            dtResult.Columns.Add("OtherData", typeof(DataTable));

            #endregion

            //Get all data from sy_function table (FunctionID, FunctionName)
            DataTable dtFunctions = new DataTable();
            CommonBl  commonBl    = new CommonBl();
            commonBl.SelectFunctions(out dtFunctions);

            //GetHashCode data from ms_permissionsAssign table (GroupCode, MappingID)
            //whewe MSUG00UserGroupsDto.Code(selected GroupCode) = ms_permissionsAssign.GroupCode

            //Select permission assign data
            DataTable dtPermissionsAssign = new DataTable();
            SYS_PermissionAssignDao permissionsAssignDao = new SYS_PermissionAssignDao();
            SYS_UserGroupsDto       dto = (SYS_UserGroupsDto)selectDto;
            permissionsAssignDao.SelectDataByGroupCode(dto.Code, out dtPermissionsAssign);

            //Select function mapping data
            DataTable dtFunctionsMapping = new DataTable();
            SYS_FunctionMappingDao functionMappingDao = new SYS_FunctionMappingDao();
            functionMappingDao.SelectMappingInfo(CommonData.StringEmpty, CommonData.StringEmpty, out dtFunctionsMapping);

            foreach (DataRow FunctionRow in dtFunctions.Rows)
            {
                DataTable otherData = new DataTable();
                otherData.Columns.Add("FunctionID");
                otherData.Columns.Add("MappingID");
                otherData.Columns.Add("OperID");
                otherData.Columns.Add("OperName");
                otherData.Columns.Add("IsPermission", typeof(bool));

                DataRow dr = dtResult.NewRow();
                dr["FunctionID"]   = FunctionRow["FunctionID"];
                dr["FunctionName"] = FunctionRow["Name"];

                dr["All"]    = false;
                dr["View"]   = false;
                dr["Add"]    = false;
                dr["Edit"]   = false;
                dr["Delete"] = false;
                dr["Print"]  = false;
                dr["Import"] = false;
                dr["Export"] = false;
                dr["Other"]  = false;


                DataRow[] FunctionsMappingRows = dtFunctionsMapping.Select("FunctionID =" + "'" + FunctionRow["FunctionID"].ParseStrQuery() + "'");
                bool      checkOtherColumn     = false;
                foreach (DataRow FunctionsMappingRow in FunctionsMappingRows)
                {
                    switch (FunctionsMappingRow["OperCode"].ToString())
                    {
                    case CommonData.OperId.View:
                        dr["View"]        = IsPermission(FunctionRow["FunctionID"].ToString(), FunctionsMappingRow["OperCode"].ToString(), dtPermissionsAssign);
                        dr["ViewMapping"] = FunctionsMappingRow["ID"];
                        dr["ViewID"]      = FunctionsMappingRow["OperCode"];
                        dr["ViewName"]    = FunctionsMappingRow["OperName"];
                        break;

                    case CommonData.OperId.Add:
                        dr["Add"]        = IsPermission(FunctionRow["FunctionID"].ToString(), FunctionsMappingRow["OperCode"].ToString(), dtPermissionsAssign);
                        dr["AddMapping"] = FunctionsMappingRow["ID"];
                        dr["AddID"]      = FunctionsMappingRow["OperCode"];
                        dr["AddName"]    = FunctionsMappingRow["OperName"];
                        break;

                    case CommonData.OperId.Edit:
                        dr["Edit"]        = IsPermission(FunctionRow["FunctionID"].ToString(), FunctionsMappingRow["OperCode"].ToString(), dtPermissionsAssign);
                        dr["EditMapping"] = FunctionsMappingRow["ID"];
                        dr["EditID"]      = FunctionsMappingRow["OperCode"];
                        dr["EditName"]    = FunctionsMappingRow["OperName"];
                        break;

                    case CommonData.OperId.Delete:
                        dr["Delete"]        = IsPermission(FunctionRow["FunctionID"].ToString(), FunctionsMappingRow["OperCode"].ToString(), dtPermissionsAssign);
                        dr["DeleteMapping"] = FunctionsMappingRow["ID"];
                        dr["DeleteID"]      = FunctionsMappingRow["OperCode"];
                        dr["DeleteName"]    = FunctionsMappingRow["OperName"];
                        break;

                    case CommonData.OperId.Import:
                        dr["Import"]        = IsPermission(FunctionRow["FunctionID"].ToString(), FunctionsMappingRow["OperCode"].ToString(), dtPermissionsAssign);
                        dr["ImportMapping"] = FunctionsMappingRow["ID"];
                        dr["ImportID"]      = FunctionsMappingRow["OperCode"];
                        dr["ImportName"]    = FunctionsMappingRow["OperName"];
                        break;

                    case CommonData.OperId.Export:
                        dr["Export"]        = IsPermission(FunctionRow["FunctionID"].ToString(), FunctionsMappingRow["OperCode"].ToString(), dtPermissionsAssign);
                        dr["ExportMapping"] = FunctionsMappingRow["ID"];
                        dr["ExportID"]      = FunctionsMappingRow["OperCode"];
                        dr["ExportName"]    = FunctionsMappingRow["OperName"];
                        break;

                    case CommonData.OperId.Print:
                        dr["Print"]        = IsPermission(FunctionRow["FunctionID"].ToString(), FunctionsMappingRow["OperCode"].ToString(), dtPermissionsAssign);
                        dr["PrintMapping"] = FunctionsMappingRow["ID"];
                        dr["PrintID"]      = FunctionsMappingRow["OperCode"];
                        dr["PrintName"]    = FunctionsMappingRow["OperName"];
                        break;

                    case CommonData.OperId.All:
                        dr["All"]        = IsPermission(FunctionRow["FunctionID"].ToString(), FunctionsMappingRow["OperCode"].ToString(), dtPermissionsAssign);
                        dr["AllMapping"] = FunctionsMappingRow["ID"];
                        dr["AllID"]      = FunctionsMappingRow["OperCode"];
                        dr["AllName"]    = FunctionsMappingRow["OperName"];
                        break;

                    default:
                        DataRow othRow = otherData.NewRow();
                        othRow["FunctionID"] = FunctionsMappingRow["FunctionId"];
                        othRow["MappingID"]  = FunctionsMappingRow["ID"];
                        othRow["OperID"]     = FunctionsMappingRow["OperCode"];
                        othRow["OperName"]   = FunctionsMappingRow["OperName"];
                        bool OthPermission = false;
                        OthPermission          = IsPermission(FunctionRow["FunctionID"].ToString(), FunctionsMappingRow["OperCode"].ToString(), dtPermissionsAssign);
                        othRow["IsPermission"] = OthPermission;
                        if (OthPermission == true)
                        {
                            checkOtherColumn = true;
                        }
                        otherData.Rows.Add(othRow);
                        break;
                    }
                }
                dr["OtherData"] = otherData;
                dr["Other"]     = checkOtherColumn;
                dtResult.Rows.Add(dr);
            }
            return(dtResult);
        }
Beispiel #2
0
        /// <summary>
        /// Check Operation is existing in Function or not
        /// </summary>
        /// <param name="functionId">
        /// ID of Function
        /// </param>
        /// <param name="operId">
        /// ID of Operation
        /// </param>
        /// <returns>
        /// Ture: is existing
        /// others: not existing
        /// </returns>
        public CommonData.IsAuthority CheckAuthority(string functionId, string operId)
        {
            try
            {
                #region Variables

                //This DataRow using to check the same GroupCode between 2 table
                DataRow[] drResult;
                //This DataTable contain data select from table ms_groupassign
                DataTable dtUserGroupForUser = new DataTable();
                //This DataTable contain data select from table ms_permissionassign
                DataTable dtUserGroupForFunction = new DataTable();
                //This DataTable contain data select from table sy_functionmapping
                DataTable dtFunctionMapping = new DataTable();
                //This Hashtable contain condition to select data from table ms_groupassign
                //Hashtable htGroupAssign = new Hashtable();
                //This Hashtable contain condition to select data from table sy_functionmapping
                //Hashtable htFunctionMapping = new Hashtable();
                //This Hashtable contain condition to select data from table ms_permissionassign
                //Hashtable htPermissionAssign = new Hashtable();
                //Object of GroupAssignDao
                SYS_GroupsAssignDao groupAssignDao = new SYS_GroupsAssignDao();
                //Object of FunctionMappingDao
                SYS_FunctionMappingDao functionMappingDao = new SYS_FunctionMappingDao();
                //Object of PermissionAssignDao
                SYS_PermissionAssignDao permissionAssignDao = new SYS_PermissionAssignDao();

                #endregion Variables

                //htGroupAssign.Add(CommonKey.UserCode, UserSession.UserCode);
                //htFunctionMapping.Add(CommonKey.FunctionId, functionId);
                //htFunctionMapping.Add(CommonKey.OperId, operId);

                //Select data from ms_groupassign
                groupAssignDao.SelectGroupByUserId(UserSession.UserCode, out dtUserGroupForUser);
                //Select data from sy_functionmapping
                functionMappingDao.SelectMappingInfo(functionId, operId, out dtFunctionMapping);
                if (dtFunctionMapping.Rows.Count > 0)
                {
                    //htPermissionAssign.Add(CommonKey.MappingId, dtFunctionMapping.Rows[0][CommonKey.Id].ToString());
                    //Select data from ms_permissionassign
                    permissionAssignDao.SelectGroupByMapping(CommonMethod.ParseInt(dtFunctionMapping.Rows[0][CommonKey.Id].ToString()), out dtUserGroupForFunction);

                    //Check 2 datatable have the same GroupCode or not
                    foreach (DataRow row in dtUserGroupForUser.Rows)
                    {
                        if (dtUserGroupForFunction.Rows.Count != 0)
                        {
                            drResult = dtUserGroupForFunction.Select(CommonKey.GroupCode + " = '" + row[CommonKey.GroupCode].ParseStrQuery() + "'");

                            if (drResult.Length > 0)
                            {
                                return(CommonData.IsAuthority.Allow);
                            }
                        }
                    }
                }
                return(CommonData.IsAuthority.Deny);
            }
            catch (Exception ex)
            {
                return(CommonData.IsAuthority.Deny);
            }
        }