Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1Test
{
public class Class9
{
static Guid actionTypeId = new Guid("A58EF6A6-138E-4B76-A55B-049E2B0054C9");
static string connString = "Data Source=.;Initial Catalog=ContractManagement;User ID=sa;Password=;Pooling=True;Min Pool Size=1;Max Pool Size=200;TrustServerCertificate=False;Application Name=CM";
static string userName = "测试财务人员";
static void Main() {
List<Guid> list = new List<Guid>();
CanUser(ref list);
if (list !=null && list.Count < 1) {
foreach (string roleName in GetUserInRole()) {
CanRole(ref list, roleName);
}
}
Console.Read();
}
public static string[] GetUserInRole() {
string[] s = new string[2];
s[0] = "财务处";
s[1] = "工程处";
return s;
}
public static List<Guid> CanUser(ref List<Guid> list) {
using (DataClasses1DataContext context = new DataClasses1DataContext(connString))
{
var ds =
(from auth in context.FunctionAuth
where auth.UserName == userName && auth.Allow == true
select auth.FunctionId).Intersect(
from func in context.Function
where func.WorkflowActionTypeId == actionTypeId
select func.FunctionId);
if (ds != null && ds.Count() > 0) {
foreach (Guid id in ds)
{
list.Add(id);
Console.WriteLine(id);
}
}
}
return list;
}
public static List<Guid> CanRole(ref List<Guid> list,string roleName)
{
using (DataClasses1DataContext context = new DataClasses1DataContext(connString))
{
var ds =
(from auth in context.FunctionAuth
where auth.RoleName == roleName && auth.Allow == true
select auth.FunctionId).Intersect(
from func in context.Function
where func.WorkflowActionTypeId == actionTypeId
select func.FunctionId);
if (ds != null && ds.Count() > 0)
{
foreach (Guid id in ds)
{
list.Add(id);
Console.WriteLine(id);
}
}
}
return list;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1Test
{
public class Class9
{
static Guid actionTypeId = new Guid("A58EF6A6-138E-4B76-A55B-049E2B0054C9");
static string connString = "Data Source=.;Initial Catalog=ContractManagement;User ID=sa;Password=;Pooling=True;Min Pool Size=1;Max Pool Size=200;TrustServerCertificate=False;Application Name=CM";
static string userName = "测试财务人员";
static void Main() {
List<Guid> list = new List<Guid>();
CanUser(ref list);
if (list !=null && list.Count < 1) {
foreach (string roleName in GetUserInRole()) {
CanRole(ref list, roleName);
}
}
Console.Read();
}
public static string[] GetUserInRole() {
string[] s = new string[2];
s[0] = "财务处";
s[1] = "工程处";
return s;
}
public static List<Guid> CanUser(ref List<Guid> list) {
using (DataClasses1DataContext context = new DataClasses1DataContext(connString))
{
var ds =
(from auth in context.FunctionAuth
where auth.UserName == userName && auth.Allow == true
select auth.FunctionId).Intersect(
from func in context.Function
where func.WorkflowActionTypeId == actionTypeId
select func.FunctionId);
if (ds != null && ds.Count() > 0) {
foreach (Guid id in ds)
{
list.Add(id);
Console.WriteLine(id);
}
}
}
return list;
}
public static List<Guid> CanRole(ref List<Guid> list,string roleName)
{
using (DataClasses1DataContext context = new DataClasses1DataContext(connString))
{
var ds =
(from auth in context.FunctionAuth
where auth.RoleName == roleName && auth.Allow == true
select auth.FunctionId).Intersect(
from func in context.Function
where func.WorkflowActionTypeId == actionTypeId
select func.FunctionId);
if (ds != null && ds.Count() > 0)
{
foreach (Guid id in ds)
{
list.Add(id);
Console.WriteLine(id);
}
}
}
return list;
}
}
}