ทำ Access Matrix
This commit is contained in:
@@ -29,6 +29,7 @@ namespace TodoAPI2.Controllers
|
||||
private ILogger<core_permission_listController> _logger;
|
||||
private Icore_permission_listService _repository;
|
||||
private IConfiguration Configuration { get; set; }
|
||||
private Iexternal_employeeService emp;
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
@@ -39,12 +40,18 @@ namespace TodoAPI2.Controllers
|
||||
/// Default constructure for dependency injection
|
||||
/// </summary>
|
||||
/// <param name="repository"></param>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="inemp"></param>
|
||||
/// <param name="logger"></param>
|
||||
public core_permission_listController(ILogger<core_permission_listController> logger, Icore_permission_listService repository, IConfiguration configuration)
|
||||
public core_permission_listController(ILogger<core_permission_listController> logger,
|
||||
Icore_permission_listService repository,
|
||||
IConfiguration configuration,
|
||||
Iexternal_employeeService inemp
|
||||
)
|
||||
{
|
||||
_logger = logger;
|
||||
_repository = repository;
|
||||
emp = inemp;
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
@@ -102,19 +109,46 @@ namespace TodoAPI2.Controllers
|
||||
{
|
||||
excel.Workbook.Worksheets.Add("Sheet1");
|
||||
|
||||
var headerRow = new List<string[]>()
|
||||
{
|
||||
new string[] { "Column Name", "Data Type", "Size", "Primary Key", "FK", "UI", "MultiSelectionTable", "Desc", "Desc EN", "row", "column", "length" }
|
||||
};
|
||||
|
||||
// Determine the header range (e.g. A1:D1)
|
||||
string headerRange = "A1:" + Char.ConvertFromUtf32(headerRow[0].Length + 64) + "1";
|
||||
|
||||
// Target a worksheet
|
||||
var worksheet = excel.Workbook.Worksheets["Sheet1"];
|
||||
|
||||
// Popular header row data
|
||||
worksheet.Cells[headerRange].LoadFromArrays(headerRow);
|
||||
var alluser = emp.GetAllUser();
|
||||
var allmenu = emp.GetAllMenu();
|
||||
|
||||
int i = 2;
|
||||
foreach (var u in alluser)
|
||||
{
|
||||
worksheet.Cells[1, i].Value = u.name;
|
||||
i++;
|
||||
}
|
||||
|
||||
int j = 2;
|
||||
foreach (var m in allmenu)
|
||||
{
|
||||
worksheet.Cells[j, 1].Value = m.display_name;
|
||||
j++;
|
||||
}
|
||||
|
||||
i = 2;
|
||||
j = 2;
|
||||
foreach (var u in alluser)
|
||||
{
|
||||
var user_menu = emp.GetMenuByUser(u.id);
|
||||
j = 2;
|
||||
foreach (var m in allmenu)
|
||||
{
|
||||
var x = (from k in user_menu
|
||||
where k.id == m.id
|
||||
select k).FirstOrDefault();
|
||||
|
||||
if(x != null)
|
||||
{
|
||||
worksheet.Cells[j, i].Value = "X";
|
||||
}
|
||||
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
//convert the excel package to a byte array
|
||||
byte[] bin = excel.GetAsByteArray();
|
||||
|
||||
@@ -16,9 +16,12 @@ namespace TodoAPI2.Models
|
||||
int? GetLeader(int? emp_id);
|
||||
external_employeeViewModel GetEmployeeForLogin(int? user_id);
|
||||
external_employeeWithSelectionViewModel GetBlankItem();
|
||||
|
||||
employee_leaveViewModel GetLeaveOfEmployee(int employee_id, DateTime? start_date, DateTime? end_date);
|
||||
List<external_employeeViewModel> GetAllEmployee();
|
||||
List<external_menu> GetAllMenu();
|
||||
List<external_menu> GetMenuByUser(int? userid);
|
||||
|
||||
List<external_user> GetAllUser();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace TodoAPI2.Models
|
||||
|
||||
public external_employeeService(IMyDatabase mydb)
|
||||
{
|
||||
db = mydb;
|
||||
db = mydb;
|
||||
}
|
||||
|
||||
public int? GetLeader(int? emp_id)
|
||||
@@ -50,15 +50,15 @@ where ha.employee_id = @emp_id and ha.workingstatus = 'สถานะปฏิ
|
||||
|
||||
if (dt.Rows.Count == 1)
|
||||
{
|
||||
if(dt.Rows[0]["chief_id"] == DBNull.Value)
|
||||
if (dt.Rows[0]["chief_id"] == DBNull.Value)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Convert.ToInt32(dt.Rows[0]["chief_id"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -127,7 +127,7 @@ order by he.firstname, he.lastname;
|
||||
i.profile_picture = dr["profile_picture"].ToString();
|
||||
i.position_number = dr["position_number"].ToString();
|
||||
i.position_name = dr["position_name"].ToString();
|
||||
i.fullname= dr["fullname"].ToString();
|
||||
i.fullname = dr["fullname"].ToString();
|
||||
i.halfname = dr["halfname"].ToString();
|
||||
if (dr["employee_type_id"] != DBNull.Value)
|
||||
{
|
||||
@@ -158,16 +158,16 @@ order by he.firstname, he.lastname;
|
||||
i.department_name = dr["department_name"].ToString();
|
||||
i.department_code = dr["department_code"].ToString();
|
||||
}
|
||||
if(dr["employee_no"] != DBNull.Value)
|
||||
if (dr["employee_no"] != DBNull.Value)
|
||||
{
|
||||
i.employee_no = dr["employee_no"].ToString();
|
||||
}
|
||||
if (dr["position_level_id"] != DBNull.Value)
|
||||
{
|
||||
i.position_level_id = Convert.ToInt32(dr["position_level_id"]);
|
||||
i.position_level_text = dr["position_level_name"].ToString();
|
||||
i.position_level_text = dr["position_level_name"].ToString();
|
||||
}
|
||||
if(dr["hpl_position_level_id"] != DBNull.Value)
|
||||
if (dr["hpl_position_level_id"] != DBNull.Value)
|
||||
{
|
||||
i.hpl_position_level_id = Convert.ToInt32(dr["hpl_position_level_id"]);
|
||||
}
|
||||
@@ -197,10 +197,10 @@ order by he.firstname, he.lastname;
|
||||
{
|
||||
i.department_degree_id = Convert.ToInt32(dr["department_degree_id"]);
|
||||
}
|
||||
if(dr["remark_hrm_work_record"] != DBNull.Value)
|
||||
if (dr["remark_hrm_work_record"] != DBNull.Value)
|
||||
{
|
||||
i.remark_hrm_work_record = dr["remark_hrm_work_record"].ToString();
|
||||
}
|
||||
}
|
||||
|
||||
result.Add(i);
|
||||
}
|
||||
@@ -584,6 +584,141 @@ select {0}b{0}.{0}employee_id{0}, (
|
||||
return i;
|
||||
}
|
||||
|
||||
public List<external_menu> GetAllMenu()
|
||||
{
|
||||
var sql = string.Format(@"
|
||||
select cself.icon,cself.id,
|
||||
case
|
||||
when cself.parent_id is null and pmenu.parent_id is null then cself.sort
|
||||
when cself.parent_id is not null and pmenu.parent_id is null then pmenu.sort
|
||||
else pmenu2.sort
|
||||
end as psort,
|
||||
case
|
||||
when cself.parent_id is null and pmenu.parent_id is null then 100000*cself.id
|
||||
when cself.parent_id is not null and pmenu.parent_id is null then 100000*cself.parent_id+1000*cself.id
|
||||
else 100000*pmenu.parent_id+1000*pmenu.id+cself.id
|
||||
end
|
||||
as pid,cself.display_name
|
||||
from core_menu as cself
|
||||
left join core_menu as pmenu on cself.parent_id=pmenu.id
|
||||
left join core_menu as pmenu2 on pmenu.parent_id=pmenu2.id
|
||||
|
||||
where cself.id in (
|
||||
select model_id from model_has_roles
|
||||
where model_type='App\Models\Menu'
|
||||
and role_id in (select id from roles where id in (
|
||||
select role_id from model_has_roles
|
||||
where model_type='App\Models\User'
|
||||
and model_id in (select id from users)
|
||||
order by model_id
|
||||
))
|
||||
) order by
|
||||
|
||||
case
|
||||
when cself.parent_id is null and pmenu.parent_id is null then cself.sort
|
||||
when cself.parent_id is not null and pmenu.parent_id is null then pmenu.sort
|
||||
else pmenu2.sort
|
||||
end,
|
||||
case
|
||||
when cself.parent_id is null and pmenu.parent_id is null then 100000*cself.id
|
||||
when cself.parent_id is not null and pmenu.parent_id is null then 100000*cself.parent_id+1000*cself.id
|
||||
else 100000*pmenu.parent_id+1000*pmenu.id+cself.id
|
||||
end
|
||||
", '"'.ToString());
|
||||
var para = db.GetParameterListNpgsql();
|
||||
DataTable dt = db.ExecuteDataTableNpgsql(sql, para);
|
||||
var result = new List<external_menu>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
var i = new external_menu();
|
||||
i.icon = dr["icon"].ToString();
|
||||
i.id = Convert.ToInt32(dr["id"]);
|
||||
i.psort = Convert.ToInt32(dr["psort"]);
|
||||
i.pid = Convert.ToInt32(dr["pid"]);
|
||||
i.display_name = dr["display_name"].ToString();
|
||||
|
||||
result.Add(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<external_menu> GetMenuByUser(int? userid)
|
||||
{
|
||||
var sql = string.Format(@"
|
||||
select cself.icon,cself.id,
|
||||
case
|
||||
when cself.parent_id is null and pmenu.parent_id is null then cself.sort
|
||||
when cself.parent_id is not null and pmenu.parent_id is null then pmenu.sort
|
||||
else pmenu2.sort
|
||||
end as psort,
|
||||
case
|
||||
when cself.parent_id is null and pmenu.parent_id is null then 100000*cself.id
|
||||
when cself.parent_id is not null and pmenu.parent_id is null then 100000*cself.parent_id+1000*cself.id
|
||||
else 100000*pmenu.parent_id+1000*pmenu.id+cself.id
|
||||
end
|
||||
as pid,cself.display_name
|
||||
from core_menu as cself
|
||||
left join core_menu as pmenu on cself.parent_id=pmenu.id
|
||||
left join core_menu as pmenu2 on pmenu.parent_id=pmenu2.id
|
||||
|
||||
where cself.id in (
|
||||
select model_id from model_has_roles
|
||||
where model_type='App\Models\Menu'
|
||||
and role_id in (select id from roles where id in (
|
||||
select role_id from model_has_roles
|
||||
where model_type='App\Models\User'
|
||||
and model_id in ({1})
|
||||
order by model_id
|
||||
))
|
||||
) order by
|
||||
|
||||
case
|
||||
when cself.parent_id is null and pmenu.parent_id is null then cself.sort
|
||||
when cself.parent_id is not null and pmenu.parent_id is null then pmenu.sort
|
||||
else pmenu2.sort
|
||||
end,
|
||||
case
|
||||
when cself.parent_id is null and pmenu.parent_id is null then 100000*cself.id
|
||||
when cself.parent_id is not null and pmenu.parent_id is null then 100000*cself.parent_id+1000*cself.id
|
||||
else 100000*pmenu.parent_id+1000*pmenu.id+cself.id
|
||||
end
|
||||
", '"'.ToString(), userid.ToString());
|
||||
var para = db.GetParameterListNpgsql();
|
||||
DataTable dt = db.ExecuteDataTableNpgsql(sql, para);
|
||||
var result = new List<external_menu>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
var i = new external_menu();
|
||||
i.icon = dr["icon"].ToString();
|
||||
i.id = Convert.ToInt32(dr["id"]);
|
||||
i.psort = Convert.ToInt32(dr["psort"]);
|
||||
i.pid = Convert.ToInt32(dr["pid"]);
|
||||
i.display_name = dr["display_name"].ToString();
|
||||
|
||||
result.Add(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<external_user> GetAllUser()
|
||||
{
|
||||
var sql = string.Format(@"
|
||||
select id,name from users
|
||||
", '"'.ToString());
|
||||
var para = db.GetParameterListNpgsql();
|
||||
DataTable dt = db.ExecuteDataTableNpgsql(sql, para);
|
||||
var result = new List<external_user>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
var i = new external_user();
|
||||
i.id = Convert.ToInt32(dr["id"]);
|
||||
i.name = dr["name"].ToString();
|
||||
|
||||
result.Add(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public external_employeeWithSelectionViewModel GetBlankItem()
|
||||
{
|
||||
var i = new external_employeeWithSelectionViewModel();
|
||||
@@ -593,5 +728,20 @@ select {0}b{0}.{0}employee_id{0}, (
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
public class external_menu
|
||||
{
|
||||
public string icon { get; set; }
|
||||
public int? id { get; set; }
|
||||
public int? psort { get; set; }
|
||||
public int? pid { get; set; }
|
||||
public string display_name { get; set; }
|
||||
}
|
||||
|
||||
public class external_user
|
||||
{
|
||||
public int? id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,36 +7,35 @@
|
||||
<div class="row page-title">
|
||||
<div class="col-md-5">
|
||||
<div class="page-title">
|
||||
@Configuration["SiteInformation:modulename"]
|
||||
ระบบข้อมูลพื้นฐานและความปลอดภัย
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-7">
|
||||
<ol class="breadcrumb" style="">
|
||||
<li class="breadcrumb-item "><a href="javascript:window_open_from_root('@Configuration["SiteInformation:mainsite"]');">หน้าแรก</a></li>
|
||||
<li class="breadcrumb-item "><a href="javascript:window_open_from_root('@Configuration["SiteInformation:modulesite"]');">@Configuration["SiteInformation:modulename"]</a></li>
|
||||
<li class="breadcrumb-item active">รายงาน core_permission_list</li>
|
||||
<li class="breadcrumb-item "><a href="javascript:window_open_from_root('@Configuration["SiteInformation:modulesite"]');">ระบบข้อมูลพื้นฐานและความปลอดภัย</li></a>
|
||||
<li class="breadcrumb-item active">รายงาน สิทธิการใช้งานระบบ</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section class="wrapper">
|
||||
<div class="title"><div class="line"></div>รายงาน core_permission_list</div>
|
||||
<div class="title"><div class="line"></div>รายงาน สิทธิการใช้งานระบบ</div>
|
||||
<div class="tools">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="row">
|
||||
|
||||
<div class="form-group col-md-3">
|
||||
<div class="form-group col-md-6">
|
||||
<label id='lab_s_core_permission_list_org_id' for='s_core_permission_list_org_id'>หน่วยงาน</label>
|
||||
<select class="form-control" id="s_core_permission_list_org_id" iLabel="หน่วยงาน" iRequire="true" iGroup="s_core_permission_list" title='หน่วยงาน' placeholder='หน่วยงาน'></select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<button class="btn btn-info" onclick="javascript:core_permission_list_DoSearch('xlsx');">ดาวน์โหลดเป็น Excel</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<button class="btn btn-info" onclick="javascript:core_permission_list_DoSearch('pdf');">แสดงรายงาน</button>
|
||||
<button class="btn btn-info" onclick="javascript:core_permission_list_DoSearch('xlsx');">ดาวน์โหลดเป็น Excel</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -23,12 +23,13 @@
|
||||
<response code="400">If the model is invalid</response>
|
||||
<response code="500">Error Occurred</response>
|
||||
</member>
|
||||
<member name="M:TodoAPI2.Controllers.core_permission_listController.#ctor(Microsoft.Extensions.Logging.ILogger{TodoAPI2.Controllers.core_permission_listController},TodoAPI2.Models.Icore_permission_listService,Microsoft.Extensions.Configuration.IConfiguration)">
|
||||
<member name="M:TodoAPI2.Controllers.core_permission_listController.#ctor(Microsoft.Extensions.Logging.ILogger{TodoAPI2.Controllers.core_permission_listController},TodoAPI2.Models.Icore_permission_listService,Microsoft.Extensions.Configuration.IConfiguration,TodoAPI2.Models.Iexternal_employeeService)">
|
||||
<summary>
|
||||
Default constructure for dependency injection
|
||||
</summary>
|
||||
<param name="repository"></param>
|
||||
<param name="configuration"></param>
|
||||
<param name="inemp"></param>
|
||||
<param name="logger"></param>
|
||||
</member>
|
||||
<member name="M:TodoAPI2.Controllers.core_permission_listController.GetBlankItem">
|
||||
|
||||
Reference in New Issue
Block a user