CEL_Payroll/Payroll.Controls/CustomControls/ctlSetupDetail.cs

276 lines
9.5 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Payroll.BO;
using Ease.CoreV35.Model;
using Payroll.UI;
using System.IO;
using Ease.CoreV35.DataAccess;
namespace Payroll.Controls
{
public partial class ctlSetupDetail : UserControl
{
#region Declarations and Constructors
TabControl tControl = null;
int _nTotalTabPages = 0;
List<string> _sTypes = null;
private SetupManager _manager;
private string _rootTag="";
private string _childTag="";
public ListView lView = new ListView();
private EnumParameterSetup _parameterSetup;
public ctlSetupDetail()
{
InitializeComponent();
// _parameterSetup = EnumParameterSetup.None;
_manager = new SetupManager();
}
public TabControl Tab
{
get
{
return tControl;
}
}
public string RootTag
{
get
{
return _rootTag;
}
set
{
_rootTag =value;
}
}
public string ChildTag
{
get
{
return _childTag;
}
set
{
_childTag= value;
}
}
public EnumParameterSetup SetupFor
{
get
{
return _parameterSetup ;
}
set
{
_parameterSetup = value;
}
}
public ObjectsTemplate<SetupDetail> SelectedSetupDetails
{
get
{
return _manager.SelectedSetupDetails;
}
}
public void RefreshParam(ID setupID, ID suportID)
{
try
{
if (_rootTag == "" || _childTag == "")
throw new ServiceException("root Tag and child tag can't empty:");
string Params = ConfigurationManager.GetStringValue(_rootTag, _childTag, EnumConfigurationType.Logic);
if (Params == "") throw new ServiceException("Configuration file does not contain the tags:" + _rootTag + " child Tag" + _childTag);
//_manager = omanager;
_manager = new SetupManager(this.SetupFor, Params);
_manager.SetParameter(this.SetupFor, Params, setupID, suportID);
_nTotalTabPages = _manager.TotalTypes;
_sTypes = _manager.GetTypes;
this.Controls.Clear();
tControl = new TabControl();
SetupTabControl();
foreach (TabPage page in this.Tab.TabPages)
{
this.Tab.SelectedTab = page;
this.Tab.SelectedTab.Refresh();
this.Tab.SelectedTab.Focus();
}
this.Tab.SelectedIndex = 0;
this.Tab.Refresh();
this.Tab.Enabled = true;
tControl.Visible = true;
tControl.Enabled = true;
this.Enabled = true;
this.Controls.Add(tControl);
this.Refresh();
}
catch (ServiceException ex)
{
throw new ServiceException(ex.Message);
}
catch (Exception ex)
{
throw new ServiceException(ex.Message);
}
}
#endregion
#region Functions
//This Method Creates Main Tab Control
private void SetupTabControl()
{
//this.Height = this.Parent.Height - 20;
tControl = new TabControl();
tControl.Location = new System.Drawing.Point(this.Location.X + 2, this.Location.Y + 2);
tControl.Name = "Setup Details";
tControl.SelectedIndex = 0;
tControl.Size = new System.Drawing.Size(this.Width-10,this.Height-10);
tControl.TabIndex = 3;
SetupTabPages();
tControl.Top = 1;
tControl.Left = 1;
tControl.Height = this.Height;
tControl.Width = this.Width - 10;
tControl.Visible = true;
}
//This Method Creates No of Tab pages into the Tab Control
private void SetupTabPages()
{
TabPage tPage = new TabPage();
foreach (string item in _sTypes)
{
if(item.Contains(EnmSetupManagerTranType.Grade.ToString()))
{
tPage = new TabPage();
tPage = SetupTabPageControl(tPage, EnmSetupManagerTranType.Grade.ToString());
tPage = SetupListView(tPage, EnmSetupManagerTranType.Grade);
}
else if (item.Contains(EnmSetupManagerTranType.Location.ToString()))
{
tPage = new TabPage();
tPage = SetupTabPageControl(tPage, EnmSetupManagerTranType.Location.ToString());
tPage = SetupListView(tPage, EnmSetupManagerTranType.Location);
}
else if (item.Contains(EnmSetupManagerTranType.Designation.ToString()))
{
tPage = new TabPage();
tPage = SetupTabPageControl(tPage, EnmSetupManagerTranType.Designation.ToString());
tPage = SetupListView(tPage, EnmSetupManagerTranType.Designation);
}
else if (item.Contains(EnmSetupManagerTranType.Category.ToString()))
{
tPage = new TabPage();
tPage = SetupTabPageControl(tPage, EnmSetupManagerTranType.Category.ToString());
tPage = SetupListView(tPage, EnmSetupManagerTranType.Category);
}
tPage.Top = 1;
tPage.Left = 1;
tPage.Height = this.Height - 10;
tControl.Controls.Add(tPage);
}
}
//This Method Creates Listview into the respective Tabpage
private TabPage SetupListView(TabPage tPage, EnmSetupManagerTranType nType)
{
#region Setup ListView Controls into Tabpages
lView = new ListView();
ColumnHeader cHeader = new ColumnHeader();
lView.FullRowSelect = true;
lView.GridLines = true;
lView.MultiSelect = false;
lView.View = View.Details;
lView.Scrollable = true;
cHeader = new ColumnHeader("colStatus");
cHeader.Name = "colStatus";
cHeader.Text = "...";
lView.Columns.Add(cHeader);
cHeader = new ColumnHeader("colCode");
cHeader.Name = "colCode";
cHeader.Text = "Code";
lView.Columns.Add(cHeader);
cHeader = new ColumnHeader("colDescription");
cHeader.Name = "colDescription";
cHeader.Text = "Description";
cHeader.Width = 200;
lView.Columns.Add(cHeader);
lView.GridLines = true;
lView.FullRowSelect = true;
lView.CheckBoxes = true;
lView.Location = new System.Drawing.Point(this.Location.X + 2, this.Location.Y + 2);
lView.Name = string.Format("lsv{0}", nType.ToString());
lView.Size = new System.Drawing.Size(this.Width - 20, this.Height - 60);
lView.TabIndex = 0;
lView.UseCompatibleStateImageBehavior = false;
lView.View = System.Windows.Forms.View.Details;
#endregion
int count = 0;
foreach (SetupDetail oDetail in _manager.GetSetupDetails)
{
if (oDetail.TranType == nType)
{
ListViewItem oItem = new ListViewItem();
oItem.SubItems.Add(oDetail.Code);
oItem.SubItems.Add(oDetail.Name);
oItem.Checked = oDetail.IsSelected;
if (_manager.SavedSetupDetails != null)
{
//oItem.Checked = _SavedDetails.IsExit(oDetail);
}
oItem.Tag = oDetail;
lView.Items.Add(oItem);
}
count = count + 1;
}
lView.Scrollable = true;
lView.Top = 1;
lView.Left = 1;
lView.Height = this.Height-20;
lView.ItemChecked += new ItemCheckedEventHandler(lView_ItemChecked);
lView.Refresh();
tPage.Controls.Add(lView);
return tPage;
}
void lView_ItemChecked(object sender, ItemCheckedEventArgs e)
{
ListViewItem item = (ListViewItem)e.Item;
SetupDetail detail =(SetupDetail) item.Tag;
detail.IsSelected = item.Checked;
}
private TabPage SetupTabPageControl(TabPage tPage, string pageName)
{
tPage.Location = new System.Drawing.Point(3, 22);
tPage.Name = string.Format("tbp{0}", pageName);
tPage.Padding = new System.Windows.Forms.Padding(3);
tPage.Size = new System.Drawing.Size(this.Width-10,this.Height-10);
tPage.Text = pageName;
tPage.UseVisualStyleBackColor = true;
return tPage;
}
#endregion
}
}