CEL_Payroll/Payroll.Controls/CustomControls/ctlDpanel.cs
2024-09-17 14:30:13 +06:00

104 lines
3.0 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Payroll.BO;
using System.Reflection;
using Ease.CoreV35;
using Ease.CoreV35.Model;
namespace Payroll.Controls.CustomControls
{
public partial class ctlDpanel : Panel
{
private int _SequenceNo = 0;
public int SequenceNO
{
get
{
return _SequenceNo;
}
set
{
_SequenceNo = value;
}
}
public ctlDpanel()
{
InitializeComponent();
}
private void UpdateConfig()
{
ConfigurationManager manager = new ConfigurationManager();
ObjectsTemplate<Configaration> items = manager.GetChilds(this.Tag.ToString(), EnumConfigurationType.Logic);
if (items == null || items.Count ==0) return;
foreach (Control ctl in this.Controls)
{
ctlDpanel dPanel = ctl as ctlDpanel;
if (dPanel!=null)
{
//Tag contain empty string, it means it is not under configuration
if (dPanel.Tag.ToString() == "") continue;
dPanel.Visible = false;
Configaration ownConfigure = manager.GetItem(items, dPanel.Tag.ToString());
if(ownConfigure==null)continue;
bool valid = (ownConfigure.Value.ToUpper() =="YES")?true:false;
dPanel.Visible = valid;
}
}
}
public void RefreshMe()
{
// UpdateConfig();
int totalVisiblePanel = 0;
int selfHeight = 0;
foreach (Control ctl in this.Controls)
{
if (ctl is ctlDpanel && ctl.Visible ==true)
{
totalVisiblePanel++;
selfHeight = ctl.Height > selfHeight ? ctl.Height : selfHeight;
}
}
if(totalVisiblePanel==0)return;
int[] nTops = new int[totalVisiblePanel];
int nFreeSpace = (this.Height - selfHeight * totalVisiblePanel) / (totalVisiblePanel + 1);
int ntop = nFreeSpace;
for (int i = 0; i < totalVisiblePanel; i++)
{
nTops[i] = ntop;
ntop = ntop + nFreeSpace + selfHeight;
}
for (int i = 1, j = 0; i <= totalVisiblePanel; i++)
{
foreach (Control ctl in this.Controls)
{
ctlDpanel dPanel =ctl as ctlDpanel;
if (dPanel != null && dPanel.Visible == true)
{
if (dPanel.SequenceNO == i)
{
ctl.Top = nTops[j];
j++;
}
}
}
}
}
}
}