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 Payroll.BO; using Ease.CoreV35; using Ease.CoreV35.Model; using System.Configuration; namespace Payroll.Controls { public partial class fOrg : Form { private ObjectsTemplate _employees; Payroll.BO.SystemInformation _sysInfo; OrganogramBasic _oSelectedOrg = null; ObjectsTemplate _oSelectedOrgs = null; ObjectsTemplate _oOrgs = null; string _sRootNode = ""; public fOrg() { InitializeComponent(); } public void Showdlg(bool sts,bool showVN) { this._isMultiple = sts; this._showVacantNode = showVN; this.ShowDialog(); } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } #region Is Multiple private bool _isMultiple; public bool IsMultiple { get { return _isMultiple; } set { _isMultiple = value; } } #endregion #region ShowVacantNode private bool _showVacantNode; public bool ShowVacantNode { get { return _showVacantNode; } set { _showVacantNode = value; } } #endregion public OrganogramBasic SelNode { get { return _oSelectedOrg; } } public ObjectsTemplate SelNodes { get { return _oSelectedOrgs; } } private void fOrg_Load(object sender, EventArgs e) { if (!this.IsMultiple) { trvOrg.CheckBoxes = false; } _oOrgs = new ObjectsTemplate(); //_oOrgs = OrganogramBasic.Get( EnumStatus.Regardless ); //_sysInfo = new Payroll.BO.SystemInformation(); // _sysInfo = Payroll.BO.SystemInformation.Get(); _employees = new ObjectsTemplate(); _employees = Employee.Get(); DrawOrganogram(); } private void DrawOrganogram() { Cursor.Current = Cursors.WaitCursor; trvOrg.Nodes.Clear(); TreeNode baseNode = new TreeNode(); //Payroll.BO.ConfigurationManager omanager = new Payroll.BO.ConfigurationManager(); //Payroll.BO.Configaration oconfig = omanager.GetItem(omanager.LogicConfiguration, "company"); //if (oconfig != null) // baseNode.Text = oconfig.Value; //else baseNode.Text = "Company"; baseNode.Text = "H&M"; baseNode.Tag = null; _sRootNode = baseNode.Text; trvOrg.Nodes.Add(baseNode); //DrawNodes(baseNode); Cursor.Current = Cursors.Default; } private void DrawNodes(TreeNode parentNode) { ObjectsTemplate children = null; if (parentNode.Tag != null) { children = OrganogramBasic.GetByParentId(ID.FromInteger((int)parentNode.Tag),EnumStatus.Regardless); } else { children = OrganogramBasic.GetTopParents(EnumStatus.Regardless); } foreach (OrganogramBasic item in children) { try { TreeNode node = new TreeNode(); node.Text = item.PositionName; node.Tag = item.ID.Integer; if (item.EmployeeAssigned==false) { if (this._showVacantNode) { node.NodeFont = new Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); node.ForeColor = System.Drawing.Color.Red; } } else { if (item.OrganEmployees.Count > 0) { Employee oEmp = _employees.GetItem(item.OrganEmployees[0].Employee); if (oEmp != null) node.Name = oEmp.EmployeeNo.ToString(); } } parentNode.Nodes.Add(node); DrawNodes(node); } catch (Exception ex) { MessageBox.Show(ex.Message, "Falied to load", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void btnSearch_Click(object sender, EventArgs e) { DrawOrganogram(); if (txtID.Text != "") { trvOrg.CollapseAll(); foreach (TreeNode tn in trvOrg.Nodes) { FindNode(tn); } } } private void FindNode(TreeNode tn) { foreach (TreeNode t in tn.Nodes) { if (t.Nodes.Count == 0) { if (t.Name == txtID.Text) { try { TreeNode[] arr = trvOrg.Nodes.Find(t.Name, true); for (int i = 0; i < arr.Length; i++) { trvOrg.SelectedNode = arr[i]; trvOrg.SelectedNode.BackColor = Color.Lavender; } } catch(Exception ex) { MessageBox.Show(ex.Message, "Falied to load", MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } } else { if (t.Name == txtID.Text) { try { TreeNode[] arr = trvOrg.Nodes.Find(t.Name, true); for (int i = 0; i < arr.Length; i++) { trvOrg.SelectedNode = arr[i]; trvOrg.SelectedNode.BackColor = Color.Lavender; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Falied to load", MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } else FindNode(t); } } } private void btnOk_Click(object sender, EventArgs e) { _oOrgs = OrganogramBasic.Get(EnumStatus.Regardless); if (!IsMultiple) { if (trvOrg.SelectedNode != null) { _oSelectedOrg = new OrganogramBasic(); _oSelectedOrg = _oOrgs.Find(delegate(OrganogramBasic oItem) { return oItem.ID.Integer ==(int)trvOrg.SelectedNode.Tag; }); if (_oSelectedOrg.Status != EnumStatus.Active) { MessageBox.Show("The selected node is not active yet." , "Node is not active", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (this._showVacantNode) { if (_oSelectedOrg.OrganEmployees.Count > 0) { MessageBox.Show("Employee [ " + _oSelectedOrg.OrganEmployees[0].Employee.EmployeeNo + " , " + _oSelectedOrg.OrganEmployees[0].Employee.Name + " ] is already assigned.", "Cannot Assign", MessageBoxButtons.OK, MessageBoxIcon.Error); _oSelectedOrg = null; trvOrg.SelectedNode = null; return; } } } } else { _oSelectedOrgs = new ObjectsTemplate(); foreach (TreeNode tn in trvOrg.Nodes) { if (tn.Text == _sRootNode && tn.Checked==true) { MessageBox.Show("Cannot select root node: " + tn.Text); return; } CheckForSelNode(tn); } } this.Close(); } private void CheckForSelNode(TreeNode tn) { foreach (TreeNode t in tn.Nodes) { if (t.Nodes.Count == 0) { if (t.Checked) { try { _oSelectedOrg = new OrganogramBasic(); _oSelectedOrg = _oOrgs.Find(delegate(OrganogramBasic oItem) { return oItem.ID.Integer == (int)t.Tag; }); _oSelectedOrgs.Add(_oSelectedOrg); } catch { } } } else { if (t.Checked) { try { _oSelectedOrg = new OrganogramBasic(); _oSelectedOrg = _oOrgs.Find(delegate(OrganogramBasic oItem) { return oItem.ID.Integer == (int)t.Tag; }); _oSelectedOrgs.Add(_oSelectedOrg); } catch (Exception ex) { MessageBox.Show(ex.Message, "Falied to load", MessageBoxButtons.OK, MessageBoxIcon.Error); } } CheckForSelNode(t); } } } private void trvOrg_DoubleClick(object sender, EventArgs e) { if (!_isMultiple) btnOk_Click(null, null); } private void trvOrg_AfterSelect(object sender, TreeViewEventArgs e) { if (_employees != null && _employees.Count > 0) _employees = Employee.GetAllEmps(); if (trvOrg.SelectedNode.Nodes.Count == 0) DrawNodesForAll(trvOrg.SelectedNode); if (trvOrg.SelectedNode.Tag == null) return; } private void DrawNodesForAll(TreeNode parentNode) { ObjectsTemplate children = null; if (parentNode.Tag != null) children = OrganogramBasic.GetByParentId(ID.FromInteger((int)parentNode.Tag), EnumStatus.Regardless); else children = OrganogramBasic.GetTopParents(EnumStatus.Regardless); foreach (OrganogramBasic item in children) { TreeNode node = new TreeNode(); node.Text = item.PositionName; node.Tag = item.ID.Integer; if (item.EmployeeAssigned == true) { foreach (OrganogramEmployee ogemp in item.OrganEmployees) { Employee oEmp = _employees.GetItem(ogemp.EmployeeID); if (oEmp == null) continue; node.Text = node.Text + "[" + oEmp.EmployeeNo + " " + oEmp.Name + "]"; node.Name = oEmp.EmployeeNo.ToString(); node.ImageIndex = 38; node.SelectedImageIndex = 38; break; } } else { if (this._showVacantNode) { node.NodeFont = new Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); node.ForeColor = System.Drawing.Color.Red; } } if (item.Status == EnumStatus.Inactive) { node.BackColor = Color.LightGray; node.Text = node.Text + " [" + "InActive" + "]"; } parentNode.Nodes.Add(node); //DrawNodesForAll(node); } } } }