CEL_Payroll/Payroll.Report/UI/rptRolePermission.cs
2024-09-17 14:30:13 +06:00

152 lines
6.3 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using Payroll.BO;
using Ease.CoreV35.Model;
namespace Payroll.Report
{
public partial class rptRolePermission : Form
{
ObjectsTemplate<RolePermission> _addedRolePermissions = null;
ObjectsTemplate<RolePermission> _removedRolePermissions = null;
ObjectsTemplate<Configaration> _configuratinAtt = null;
ConfigurationManager _Menu = null;
DataTable data1 = null;
DataTable data2 = null;
string sDate = "";
string _type = "";
public rptRolePermission()
{
InitializeComponent();
_configuratinAtt = new ObjectsTemplate<Configaration>();
_Menu = new ConfigurationManager();
_configuratinAtt = Configaration.Get(EnumConfigurationType.Menu);
}
public void ShowDlg(DataTable dt1, DataTable dt2, string sDate1)
{
sDate = sDate1;
data1 = dt1.Copy();
data2 = dt2.Copy();
this.ShowDialog();
}
private void rptRolePermission_Load(object sender, EventArgs e)
{
Payroll.Report.PayrollDataSet.PayrollDataSet.dtRolePermissionDataTable dt1 = new Payroll.Report.PayrollDataSet.PayrollDataSet.dtRolePermissionDataTable();
Payroll.Report.PayrollDataSet.PayrollDataSet.dtRoleInfoDataTable dt2 = new Payroll.Report.PayrollDataSet.PayrollDataSet.dtRoleInfoDataTable();
//dt1 =(Payroll.Report.PayrollDataSet.PayrollDataSet.dtRolePermissionDataTable) data1.Copy();
//dt2 = (Payroll.Report.PayrollDataSet.PayrollDataSet.dtRolePermissionDataTable)data2.Copy();
List<ReportDataSource> dataSource = new List<ReportDataSource>();
string embeddedResource = "Payroll.Report.RDLC.rptRolePermission.rdlc";
string caption = "Role Permission History";
dataSource.Add(new ReportDataSource("PayrollDataSet_dtRolePermission", data1));
dataSource.Add(new ReportDataSource("PayrollDataSet_dtRoleInfo", data2));
Cursor.Current = Cursors.WaitCursor;
fReportViewer fViewer = new fReportViewer();
sDate = "Role permission report for month :" + sDate;
fViewer.PreviewReport2(dataSource, embeddedResource, caption, sDate);
this.Close();
}
public void ShowAddRemovePermissions(int roleID, DataTable dtUser, string _sType)
{
fReportViewer fViewer = new fReportViewer();
_addedRolePermissions = new ObjectsTemplate<RolePermission>();
_removedRolePermissions = new ObjectsTemplate<RolePermission>();
Payroll.Report.PayrollDataSet.PayrollDataSet.dtRolePermissionDataTable dt1 = new Payroll.Report.PayrollDataSet.PayrollDataSet.dtRolePermissionDataTable();
Payroll.Report.PayrollDataSet.PayrollDataSet.dtRoleInfoDataTable dt2 = new Payroll.Report.PayrollDataSet.PayrollDataSet.dtRoleInfoDataTable();
Cursor.Current = Cursors.WaitCursor;
sDate = "Role permission report for month :" + sDate;
string caption = "Role Permission Add Remove History";
DataSet dtAddedPermissions = new DataSet();
DataSet dtRemovedPermissions = new DataSet();
DataRow orow = null;
_type = _sType;
if (_sType != "Web")
{
List<Configaration> values = _Menu.MenuCofiguration.FindAll(delegate(Configaration con) { return FindParentValues(con); });
Configaration conn = values[0];
_sType = conn.ConAttributes[4].Value.ToString();
}
_addedRolePermissions = RolePermission.Get(roleID, EnumStatus.Active);
_removedRolePermissions = RolePermission.GetAll(roleID);
foreach (RolePermission addRole in _addedRolePermissions)
{
orow = dt1.NewRow();
string menuKey = addRole.MenuKey.ToString();
foreach (RolePermission removeRole in _removedRolePermissions)
{
if (removeRole.IsApproved == EnumStatus.Role_Menu_Assigned_And_Waiting_For_Approve || removeRole.IsApproved == EnumStatus.Role_Menu_Modified_And_Waiting_For_Approve)
{
if (menuKey != removeRole.MenuKey)
{
List<Configaration> parents = _Menu.MenuCofiguration.FindAll(delegate(Configaration con) { return IsParent(con); });
foreach (Configaration con in parents)
{
TreeNode node = new TreeNode();
node.Text = con.ConAttributes[1].Value.ToString();
node.Tag = con.ConAttributes[0].Value.ToString();
}
orow["menu"] = menuKey;
orow["date"] = "";
orow["Status"] = "";
}
}
}
}
}
private bool IsParent(Configaration con)
{
if (con.ConAttributes.Count > 4 && con.ConAttributes[3].Value.Length == 0)
{
if (con.ConAttributes[4].Value.ToString().ToLower().Equals(_type.ToLower()))
{
return true;
}
}
return false;
}
private bool FindParentValues(Configaration con)
{
if (con.ConAttributes.Count > 4 && con.ConAttributes[3].Value.Length == 0)
{
if (con.ConAttributes[2].Value.ToString().ToLower().Equals("true") && con.ConAttributes[4].Value.ToString().ToLower() != "web")
{
return true;
}
}
return false;
}
private bool IsChield(Configaration c, Configaration con)
{
if (c.ConAttributes.Count > 4 && c.ConAttributes[3].Value.ToString().ToLower().Equals(con.ConAttributes[0].Value.ToString().ToLower()))
{
{
return true;
}
}
return false;
}
}
}