using System; using System.Data; using Ease.Core.DataAccess; using HRM.BO; namespace HRM.DA { internal class OrganogramDA { #region Constructor private OrganogramDA() { } #endregion #region Insert function internal static void Insert(TransactionContext tc, OrganogramBasic item) { string Ssql = SQLParser.MakeSQL( "INSERT INTO Organogram(OrganogramID, PositionName, ParentID, Tier, UniqueId," + " PositionNo,CompanyID,DepartmentID,FunctionID," + " GradeID,DesignationID,LocationID,CreatedBy," + " CreationDate, SequenceNo, Status,JDNo,RevisionNo,RevisionDate)" + " VALUES(%n, %s, %n, %n, %n," + " %s, %n, %n,%n," + " %n,%n,%n,%n," + " %d,%n,%n,%s,%s,%d)", item.ID, item.PositionName, item.ParentID, item.Tier, item.UniqueId, item.PositionNo, item.CompanyID, item.DepartmentID, item.FunctionID, item.GradeID, item.DesignationID, item.LocationID, item.CreatedBy, item.CreatedDate, item.Sequence, item.Status, item.JDNo, item.RevisionNo, DataReader.GetNullValue(item.RevisionDate)); tc.ExecuteNonQuery(Ssql); } public static void UpdateFromLifeCycle(TransactionContext tc, EmpLifeCycle item) { string str = "UPDATE Organogram SET "; string cm = ""; if (item.DepartmentID != null) { str = cm + str + " DepartmentID =" + item.DepartmentID.ToString(); cm = ", "; } if (item.GradeID != null) { str = str + cm + " GradeID =" + item.GradeID.ToString(); cm = ", "; } if (item.LocationID != null) { str = str + cm + " LocationID =" + item.LocationID.ToString(); cm = ", "; } if (item.DesignationID != null) { str = str + cm + " DesignationID =" + item.DesignationID.ToString(); cm = ", "; } if(item.DesignationID !=null) { str = str + cm + @" PositionName =( select Name from Designation where DesignationID=" + item.DesignationID.ToString() +")"; cm = ", "; } str = str + " Where OrganogramID =" + item.NodeID.ToString(); if(cm != String.Empty) tc.ExecuteNonQuery(str); } internal static void Insert(TransactionContext tc, OrganogramAuthority item) { tc.ExecuteNonQuery( "INSERT INTO OrganAuthority(OrganAuthorityID, NodeID, AuthorityType, ChildNodeID, EmployeeID)" + " VALUES(%n, %n, %n, %n, %n)", item.ID, item.NodeID, item.AuthorityType, item.ChildNodeID, DataReader.GetNullValue(item.EmployeeID, 0)); } internal static int GetMaxTier(TransactionContext tc) { object minID = tc.ExecuteScalar("SELECT Max(Tier) FROM Organogram"); if (minID == null || minID == DBNull.Value) return 0; else return Convert.ToInt32(minID); } internal static void Insert(TransactionContext tc, OrganogramDelegation item) { tc.ExecuteNonQuery("INSERT INTO OrganDelegation(OrganDelegationID,NodeID,EmployeeID," + " FromDate,ToDate,DelegationType,IsActive,CreatedBy,CreationDate)" + " VALUES(%n,%n,%n," + " %d,%d,%s,%n,%n,%d)", item.ID, item.NodeID, item.EmployeeID, item.FromDate, item.ToDate, item.IsActive, DataReader.GetNullValue(item.CreatedBy, 0), item.CreatedDate); } internal static void Insert(TransactionContext tc, OrganogramJobDesc item) { tc.ExecuteNonQuery("INSERT INTO OrganJobDescription(OrganJobDescID,NodeID,Purpose," + " JobSummery,Experience,Education,CreatedBy,CreationDate)" + " VALUES(%n,%n,%s," + " %s,%s,%s,%n,%d)", item.ID, item.NodeID, item.Purpose, item.JobSummery, item.Experience, item.Education, item.CreatedBy, item.CreatedDate); } internal static void Insert(TransactionContext tc, OrganogramResponsibility item) { //,CreatedBy,CreationDate ,%n,%d ,item.CreatedBy,item.CreatedDate tc.ExecuteNonQuery("INSERT INTO OrganResponsibility(OrganResponsibilityID,NodeID,Responsibility,Isprimary)" + " VALUES(%n,%n,%s,%n)", item.ID, item.NodeID, item.Responsibility, item.IsPrimary); } internal static void Insert(TransactionContext tc, OrganogramSkillLevel item) { //,CreatedBy,CreationDate ,%n,%d ,item.CreatedBy,item.CreatedDate tc.ExecuteNonQuery("INSERT INTO OrganSkillLevel(OrganSkillLevelID,NodeID,LevelID,SkillID)" + " VALUES(%n,%n,%n,%n)", item.ID, item.NodeID, item.LevelID, item.SkillID); } internal static void Insert(TransactionContext tc, OrganogramPosition item) { tc.ExecuteNonQuery("INSERT INTO OrganPosition(OrganPositionID,NodeID,PositionTypeID)" + " VALUES(%n,%n,%n)", item.ID, item.NodeID, item.PositionTypeID); } #endregion #region Update function internal static void Update(TransactionContext tc, OrganogramBasic item) { tc.ExecuteNonQuery("UPDATE Organogram SET PositionName=%s, ParentID=%n, Tier=%n, UniqueId=%n," + " PositionNo=%s,CompanyID=%n,DepartmentID=%n,FunctionID=%n," + " GradeID=%n,DesignationID=%n,LocationID=%n, ModifiedBy=%n," + " ModifiedDate=%d, SequenceNo=%n, Status=%n,JDNo=%s,RevisionNo=%s,RevisionDate=%d" + " WHERE OrganogramID=%n", item.PositionName, item.ParentID, item.Tier, item.UniqueId, item.PositionNo, item.CompanyID, item.DepartmentID,item.FunctionID, item.GradeID, item.DesignationID, item.LocationID, item.ModifiedBy, item.ModifiedDate, item.Sequence, item.Status, item.JDNo, item.RevisionNo, DataReader.GetNullValue(item.RevisionDate), item.ID); } public static void UpdateParentAndTier(TransactionContext tc, OrganogramBasic oItem) { tc.ExecuteNonQuery("UPDATE Organogram SET Tier=%n, ParentID=%n" + " WHERE OrganogramID=%n", oItem.Tier, oItem.ParentID, oItem.ID); } #endregion #region Delete function internal static void Delete(TransactionContext tc, int nodeID) { tc.ExecuteNonQuery("DELETE FROM OrganPosition WHERE NodeID=%n", nodeID); tc.ExecuteNonQuery("DELETE FROM OrganSkillLevel WHERE NodeID=%n", nodeID); tc.ExecuteNonQuery("DELETE FROM OrganResponsibility WHERE NodeID=%n", nodeID); tc.ExecuteNonQuery("DELETE FROM OrganJobDescription WHERE NodeID=%n", nodeID); tc.ExecuteNonQuery("DELETE FROM OrganDelegation WHERE NodeID=%n", nodeID); tc.ExecuteNonQuery("DELETE FROM OrganAuthority WHERE NodeID=%n", nodeID); tc.ExecuteNonQuery("DELETE FROM Organogram WHERE OrganogramID=%n", nodeID); } internal static void DeleteAll(TransactionContext tc) { tc.ExecuteNonQuery("DELETE FROM ORGANEMPLOYEE"); tc.ExecuteNonQuery("DELETE FROM Organogram"); } internal static void DeleteOrganAuthority(TransactionContext tc, int nodeID) { tc.ExecuteNonQuery("DELETE FROM OrganAuthority WHERE NodeID=%n", nodeID); } internal static void DeleteOrganDelegation(TransactionContext tc, int nodeID) { tc.ExecuteNonQuery("DELETE FROM OrganDelegation WHERE NodeID=%n", nodeID); } internal static void DeleteOranJobDesc(TransactionContext tc, int nodeID) { tc.ExecuteNonQuery("DELETE FROM OrganJobDescription WHERE NodeID=%n", nodeID); } internal static void DeleteOrganResponsibility(TransactionContext tc, int nodeID) { tc.ExecuteNonQuery("DELETE FROM OrganResponsibility WHERE NodeID=%n", nodeID); } internal static void DeleteOrganSkilLevel(TransactionContext tc, int nodeID) { tc.ExecuteNonQuery("DELETE FROM OrganSkillLevel WHERE NodeID=%n", nodeID); } internal static void DeleteOrganPosition(TransactionContext tc, int nodeID) { tc.ExecuteNonQuery("DELETE FROM OrganPosition WHERE NodeID=%n", nodeID); } #endregion #region Get Function internal static IDataReader Get(TransactionContext tc, int nID) { return tc.ExecuteReader("SELECT * FROM Organogram WHERE OrganogramID=%n", nID); } internal static IDataReader GetbyEmployeeID(TransactionContext tc, int employeeId) { return tc.ExecuteReader( "SELECT O.* FROM Organogram O, OrganEmployee A WHERE A.NodeID=O.OrganogramID AND A.EmployeeID =%n", employeeId); } internal static IDataReader Get(TransactionContext tc, EnumStatus status) { if (EnumStatus.Active == status || EnumStatus.Inactive == status) { return tc.ExecuteReader("SELECT * FROM Organogram where Status=%n order by OrganogramID", status); } else return tc.ExecuteReader("SELECT * FROM Organogram order by OrganogramID"); } internal static IDataReader GetbyTier(TransactionContext tc, int fromtier, int totier) { return tc.ExecuteReader("SELECT * FROM Organogram where Tier>=%n AND Tier<=%n order by OrganogramID ", fromtier, totier); } internal static IDataReader GetByParentID(TransactionContext tc, int parentID, EnumStatus status) { if (EnumStatus.Active == status || EnumStatus.Inactive == status) { if (parentID > 0) return tc.ExecuteReader("SELECT * FROM Organogram WHERE ParentID=%n AND Status=%n", parentID, status); else return tc.ExecuteReader("SELECT * FROM Organogram WHERE Status=%n AND ParentID is Null", status); } else { if (parentID > 0) return tc.ExecuteReader("SELECT * FROM Organogram WHERE ParentID=%n", parentID); else return tc.ExecuteReader("SELECT * FROM Organogram WHERE ParentID is Null"); } } public static IDataReader GetTopParents(TransactionContext tc, EnumStatus status) { if (EnumStatus.Active == status || EnumStatus.Inactive == status) { return tc.ExecuteReader("SELECT * FROM Organogram WHERE ParentID IS NULL AND Status=%n", status); } else return tc.ExecuteReader("SELECT * FROM Organogram WHERE ParentID IS NULL"); } internal static IDataReader Get4OrganAuthority(TransactionContext tc, int nodeID) { return tc.ExecuteReader("SELECT * FROM OrganAuthority WHERE NodeID=%n", nodeID); } internal static IDataReader Get4OrganDelegation(TransactionContext tc, int nodeID) { return tc.ExecuteReader("SELECT * FROM OrganDelegation WHERE NodeID=%n", nodeID); } internal static IDataReader Get4OrganJobDesc(TransactionContext tc, int nodeID) { return tc.ExecuteReader("SELECT * FROM OrganJobDescription WHERE NodeID=%n", nodeID); } internal static IDataReader Get4OrganResponsibility(TransactionContext tc, int nodeID) { return tc.ExecuteReader("SELECT * FROM OrganResponsibility WHERE NodeID=%n", nodeID); } internal static IDataReader Get4OrganSkilLevel(TransactionContext tc, int nodeID) { return tc.ExecuteReader("SELECT * FROM OrganSkillLevel WHERE NodeID=%n", nodeID); } internal static IDataReader Get4OrganPosition(TransactionContext tc, int nodeID) { return tc.ExecuteReader("SELECT * FROM OrganPosition WHERE NodeID=%n", nodeID); } internal static IDataReader GetAllOrganPosition(TransactionContext tc) { return tc.ExecuteReader("SELECT * FROM OrganPosition"); } internal static IDataReader GetMinNodeIdByDept(TransactionContext tc, int nDeptID) { return tc.ExecuteReader( "select * from Organogram where OrganogramID in (select Min(OrganogramID) from Organogram where DepartmentID =%n)", nDeptID); } internal static IDataReader GetOrganAuthorityByEmp(TransactionContext tc, int EmpID) { return tc.ExecuteReader("SELECT * FROM OrganAuthority WHERE EmployeeID=%n", EmpID); } internal static IDataReader GetbyPositionType(TransactionContext tc, int positionTypeid) { return tc.ExecuteReader( "Select Organogram.* from Organogram, OrganPosition where Organogram.OrganogramID = OrganPosition.NodeID and PositionTypeID =%n", positionTypeid); } internal static DataSet GetOrganogramNodes(TransactionContext tc, int nNodeID) { DataSet ds = new DataSet(); try { ds = tc.ExecuteDataSet("WITH RecursiveCte " + "(" + " SELECT 1 Tier, H1.OrganogramID, H1.ParentId, H1.PositionName FROM Organogram H1" + " WHERE OrganogramID = %n" + " UNION ALL" + " SELECT RCTE.Tier + 1 Tier, H2.OrganogramID, H2.ParentId, H2.PositionName FROM Organogram H2" + " INNER JOIN RecursiveCte RCTE ON H2.ParentId = RCTE.OrganogramID" + " )" + " SELECT a.OrganogramID,a.parentid,'Position : '+a.PositionName PositionName,c.employeeid,c.employeeno,c.employeeno+'('+c.name+')' noname,'Name : '+c.name name,'Designation : '+d.name designation ,c.photopath,c.Gender" + " FROM RecursiveCte a" + " left outer join organemployee b on a.OrganogramID=b.nodeid " + " left outer join employee c on b.employeeid=c.employeeid " + " left outer join designation d on c.designationid=d.designationid", nNodeID); } catch (Exception ex) { throw new Exception(ex.Message); } return ds; } internal static DataSet GetLMOrganogramNodes(TransactionContext tc, int nNodeID) { DataSet ds = new DataSet(); try { ds = tc.ExecuteDataSet( "SELECT a.OrganogramID,a.parentid,'Position : '+a.PositionName PositionName,c.employeeid,c.employeeno,c.employeeno+'('+c.name+')' noname,'Name : '+c.name name,'Designation : '+d.name designation ,c.photopath,c.Gender FROM Organogram a left outer join organemployee b on a.OrganogramID=b.nodeid left outer join employee c on b.employeeid=c.employeeid left outer join designation d on c.designationid=d.designationid where a.organogramid=%n Or parentid=%n", nNodeID, nNodeID); } catch (Exception ex) { throw new Exception(ex.Message); } return ds; } internal static DataSet GetManagers(TransactionContext tc, string sEmpIDs) { DataTable dt = new DataTable(); DataSet ds = new DataSet(); ds.Tables.Add(dt); if (sEmpIDs != "") { string strSQLQuery = SQLParser.MakeSQL( @"select (select name from employee where employeeid=b.employeeid) EmployeeName,org.employeeid ManagerID,(select name from employee where employeeid=org.employeeid)ManagerName from OrganEmployee org, (Select parentid,employeeid From Organogram aa,OrganEmployee bb where Organogramid=nodeid)b where org.nodeid=b.parentid and org.employeeid in(%q)", sEmpIDs); return tc.ExecuteDataSet(strSQLQuery); } return ds; } internal static int MaxTier(TransactionContext tc) { string strSQLQuery = "SELECT max(tier) FROM organogram"; return Convert.ToInt32(tc.ExecuteScalar(strSQLQuery)); } internal static IDataReader GetAllOrganAuthority(TransactionContext tc) { return tc.ExecuteReader("SELECT * FROM OrganAuthority"); } #endregion } }