/// <summary> /// 查询员工数量 /// </summary> /// <param name="employeeSearcher">员工查询对象</param> /// <param name="tran">中间事务对象</param> /// <returns>返回查询到的数量</returns> public long Count(EmployeeSearcher employeeSearcher, ICTransaction tran) { object count = 0; long result = 0; EmployeeSearcher querySearcher = null; MssqlQueryParser queryParser = new MssqlQueryParser(); StringBuilder query = new StringBuilder(); query.AppendLine(@"SELECT "); query.AppendLine(@" COUNT(E.EmployeeId) "); query.AppendLine(@"FROM "); query.AppendLine(@" Employee E "); if (employeeSearcher != null) { querySearcher = (EmployeeSearcher)employeeSearcher.Clone(); querySearcher.TableName = "E"; if (querySearcher.CurrCompany != null) { querySearcher.CurrCompany.TableName = "C"; query.AppendLine(@"LEFT JOIN "); query.AppendLine(@" [Company] C ON(C.CompanyId = E.CompanyId) "); } if (querySearcher.CurrDepartment != null) { querySearcher.CurrDepartment.TableName = "D"; query.AppendLine(@"LEFT JOIN "); query.AppendLine(@" [Department] D ON(D.DepartmentId = E.DepartmentId) "); } if (querySearcher.CurrPosition != null) { querySearcher.CurrPosition.TableName = "P"; query.AppendLine(@"LEFT JOIN "); query.AppendLine(@" [Position] P ON(P.PositionId = E.PositionId) "); } } queryParser.SearcherParse(querySearcher); if (!string.IsNullOrEmpty(queryParser.ConditionString)) { query.AppendLine(@"WHERE "); query.AppendLine(@" " + queryParser.ConditionString); } if (tran != null) { DbTransaction dbTran = ((MssqlTransaction)tran).CurrentTransaction; count = MssqlHelper.ExecuteScalar(dbTran, CommandType.Text, query.ToString(), queryParser.ParamCollection); } else { count = MssqlHelper.ExecuteScalar(this.CurrentConnectionString, CommandType.Text, query.ToString(), queryParser.ParamCollection); } return(long.TryParse(count.ToString(), out result) ? result : 0); }
/// <summary> /// 查询公司数量 /// </summary> /// <param name="companySearcher">公司查询对象</param> /// <param name="tran">中间事务对象</param> /// <returns>返回查询到的数量</returns> public long Count(CompanySearcher companySearcher, ICTransaction tran) { object count = 0; long result = 0; CompanySearcher querySearcher = null; MssqlQueryParser queryParser = new MssqlQueryParser(); StringBuilder query = new StringBuilder(); query.AppendLine(@"SELECT "); query.AppendLine(@" COUNT(C.CompanyId) "); query.AppendLine(@"FROM "); query.AppendLine(@" Company C "); if (companySearcher != null) { querySearcher = (CompanySearcher)companySearcher.Clone(); querySearcher.TableName = "C"; } queryParser.SearcherParse(querySearcher); if (!string.IsNullOrEmpty(queryParser.ConditionString)) { query.AppendLine(@"WHERE "); query.AppendLine(@" " + queryParser.ConditionString); } if (tran != null) { DbTransaction dbTran = ((MssqlTransaction)tran).CurrentTransaction; count = MssqlHelper.ExecuteScalar(dbTran, CommandType.Text, query.ToString(), queryParser.ParamCollection); } else { count = MssqlHelper.ExecuteScalar(this.CurrentConnectionString, CommandType.Text, query.ToString(), queryParser.ParamCollection); } return(long.TryParse(count.ToString(), out result) ? result : 0); }
public static object ExecuteScalar(string storedProcName) { return(mssqlHelper.ExecuteScalar(storedProcName)); }