public void Save(IEntityManager em, Transaction tx, EmployeePrincipal employeePrincipal) { string[] columns = { "ID", "EmployeeId", "EffectiveDate", "PrincipalId", "IsActive" }; object[] values = { Guid.NewGuid(), employeePrincipal.EmployeeId, employeePrincipal.EffectiveDate.ToShortDateString(), employeePrincipal.PrincipalId, employeePrincipal.IsActive == true?1:0 }; var q = new Query().Select(columns).From(tableName).Insert(values); em.ExecuteNonQuery(q.ToSql(), tx); }
public EmployeePrincipal GetPreviousPrincipal(Guid employeeId, int month, int year) { EmployeePrincipal employeePrincipal = new EmployeePrincipal(); using (var em = EntityManagerFactory.CreateInstance(ds)) { string sql = "SELECT TOP 1 ep.*,p.PrincipalName FROM Principal p " + "INNER JOIN EmployeePrincipal ep ON p.ID = ep.PrincipalId " + "WHERE ep.EmployeeId='{" + employeeId + "}' " + "AND month(ep.EffectiveDate) <=" + month + " " + "AND year(ep.EffectiveDate) <=" + year; employeePrincipal = em.ExecuteObject <EmployeePrincipal>(sql, new EmployeePrincipalMapper()); } return(employeePrincipal); }
public void saveEmployeePrincipals(Account account, int[] thisManager) { var depart = _DbContext.departments.FirstOrDefault(b => b.ID == account.departmentID); var departIsNull = depart == null? true : false; depart = depart == null? new Department() { } : depart; if (!departIsNull) { var departAgent = (from a in _DbContext.employeedetails join b in _DbContext.departments on a.accountID equals b.principalID where b.ID == depart.ID && a.agentEnable == true select a.myAgentID).FirstOrDefault(); var downWithUp = new EmployeePrincipal() { employeeID = account.ID, principalID = depart.principalID, principalAgentID = departAgent, lastOperaAccID = account.lastOperaAccID, createTime = definePara.dtNow() }; if (depart.principalID > 0) { _DbContext.employeeprincipals.Add(downWithUp); //所屬部門主管一定會新增 _DbContext.SaveChanges(); } } foreach (var id in thisManager) { if (id > 0 && id != depart.principalID) { var thisAgent = _DbContext.employeedetails.Where(b => b.accountID == id && b.agentEnable == true) .Select(b => b.myAgentID).FirstOrDefault(); var downWithUp02 = new EmployeePrincipal() { employeeID = account.ID, principalID = id, principalAgentID = thisAgent, lastOperaAccID = account.lastOperaAccID, createTime = definePara.dtNow() }; _DbContext.employeeprincipals.Add(downWithUp02); _DbContext.SaveChanges(); } } }