TimeSheet.ReadTimesheetList 方法

读取指定的日期范围内的指定资源摘要时间表。

命名空间:  WebSvcTimeSheet
程序集:  ProjectServerServices(位于 ProjectServerServices.dll 中)

语法

声明
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/ReadTimesheetList", RequestNamespace := "https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/",  _
    ResponseNamespace := "https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
Public Function ReadTimesheetList ( _
    resUID As Guid, _
    startDate As DateTime, _
    finishDate As DateTime, _
    select As Integer _
) As TimesheetListDataSet
用法
Dim instance As TimeSheet
Dim resUID As Guid
Dim startDate As DateTime
Dim finishDate As DateTime
Dim select As Integer
Dim returnValue As TimesheetListDataSet

returnValue = instance.ReadTimesheetList(resUID, _
    startDate, finishDate, select)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/ReadTimesheetList", RequestNamespace = "https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/", 
    ResponseNamespace = "https://schemas.microsoft.com/office/project/server/webservices/TimeSheet/", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public TimesheetListDataSet ReadTimesheetList(
    Guid resUID,
    DateTime startDate,
    DateTime finishDate,
    int select
)

参数

  • startDate
    类型:System.DateTime

    要返回最早的时间表的日期。

  • finishDate
    类型:System.DateTime

    要返回的最新的时间表的日期。

返回值

类型:WebSvcTimeSheet.TimesheetListDataSet
DataSet与满足参数的时间表的摘要列表。

备注

使用select参数Microsoft.Office.Project.Server.Library.TimesheetEnum.ListSelect值。您可以将ListSelect值与要筛选的属性的组合OR操作。例如,若要选择所有创建用户正在进行中的时间表, select参数设置为CreatedByMeORInProgress。

返回一段的所有时间表以及空记录其中没有任何时间表,则会将select设TimeSheetEnum.ListSelect.AllPeriods。

ReadTimesheetList忽略resUIDselect的值是否只CreatedByMe。若要获取的由您创建的其他人的时间表列表 — 即,您是代理人时间表 — 传递resUID和select即OR操作CreatedByMe和InProgress、 Submitted、 Acceptable、 Approved、 Rejected或AllExisting之间的值中的其他用户的资源的 GUID。

Project Server 中的有效日期是 1984 年 1 月 1 日到 2049 年 12 月 31)。

此方法使用QueueSystem对象。作业的CorrelationGUID属性等于TS_UID属性的值。

Project Server 权限

权限

说明

非标准

当前用户是时间表所有者,或select的值是CreatedByMe。

ViewResourceTimesheet

允许用户查看资源时间表。仅适用于当前用户不是时间表所有者。全局权限。

示例

下面的代码示例在指定日期内读取所有时间表的用户创建并正在进行的。此示例使用TimeSheetUtils类和ExceptionHandlers类别分开Program类的功能。TimeSheetUtils.GetMyTimeSheetsInProgress方法使用GetCurrentUserUid方法在资源 web 服务返回用户的 GUID。

For information about compiling the sample, see Project 2013 中基于 ASMX 的代码示例的先决条件.

using System;
using System.Net;
using System.Web.Services.Protocols;
using PSLibrary = Microsoft.Office.Project.Server.Library;

namespace Microsoft.SDK.Project.Samples.TestTimesheet
{
   class Program
   {
      private static TimeSheetWebSvc.TimeSheet timesheet =
         new TimeSheetWebSvc.TimeSheet();
      private static ResourceWebSvc.Resource resource =
         new ResourceWebSvc.Resource();

      private static TimeSheetUtils timeSheetUtils = new TimeSheetUtils();
      private static ExceptionHandlers exceptionHandlers = new ExceptionHandlers();

      [STAThread]
      static void Main()
      {
         try
         {
            const string PROJECT_SERVER_URI = "http:// ServerName/ProjectServerName/";
            const string RESOURCE_SERVICE_PATH = "_vti_bin/psi/resource.asmx";
            const string TIMESHEET_SERVICE_PATH = "_vti_bin/psi/timesheet.asmx";

            // Set up the web service objects.
            resource.Url = PROJECT_SERVER_URI + RESOURCE_SERVICE_PATH;
            resource.Credentials = CredentialCache.DefaultCredentials;

            timesheet.Url = PROJECT_SERVER_URI + TIMESHEET_SERVICE_PATH;
            timesheet.Credentials = CredentialCache.DefaultCredentials;

            // Get timesheet information for the specified dates.
            DateTime startDate = new DateTime(2006, 11, 27);
            DateTime finishDate = new DateTime(2006, 12, 1);
            Guid resUid;

            TimeSheetWebSvc.TimesheetListDataSet dsTimeSheetList = 
               timeSheetUtils.GetMyTimeSheetsInProgress(
                  timesheet, resource, startDate, finishDate, out resUid);

            Console.WriteLine("Active timesheets for resource: " + resUid.ToString());
            Console.WriteLine(string.Format("\tStart date: {0}\r\n\tFinish date: {1}", 
               startDate.ToString(), finishDate.ToString()));

            for (int i = 0; i < dsTimeSheetList.Timesheets.Count; i++)
            {
               Console.WriteLine(dsTimeSheetList.Timesheets[i].TS_UID.ToString(), 
                  dsTimeSheetList.Timesheets[i].TS_NAME);
            }
         }
         catch (SoapException ex)
         { exceptionHandlers.HandleSoapException(ex); }
         catch (WebException ex)
         { exceptionHandlers.HandleWebException(ex); }
         catch (Exception ex)
         { exceptionHandlers.HandleException(ex); }
         finally
         { exceptionHandlers.ResetConsole(); }
      }
   }

   class TimeSheetUtils
   {
      public TimeSheetUtils()
      {
      }

      // Get a list of timesheets that were created by the user and that are in progress.
      public TimeSheetWebSvc.TimesheetListDataSet GetMyTimeSheetsInProgress(
          TimeSheetWebSvc.TimeSheet timesheet,
          ResourceWebSvc.Resource resource,
          DateTime startDate,
          DateTime finishDate,
         out Guid resUid)
      {
         int select = Convert.ToInt32(
                         PSLibrary.TimesheetEnum.ListSelect.CreatedByMe
                       | PSLibrary.TimesheetEnum.ListSelect.InProgress);

         resUid = resource.GetCurrentUserUid();
         return timesheet.ReadTimesheetList(resUid, startDate, finishDate, select);
      }
   }

   class ExceptionHandlers
   {
      public ExceptionHandlers()
      {
      }

      public void HandleSoapException(SoapException ex)
      {
         PSLibrary.PSClientError error = new PSLibrary.PSClientError(ex);
         PSLibrary.PSErrorInfo[] errors = error.GetAllErrors();
         string errMess = "==============================\r\nError: \r\n";
         for (int i = 0; i < errors.Length; i++)
         {
            errMess += "\n" + ex.Message.ToString() + "\r\n";
            errMess += "".PadRight(30, '=') + "\r\nPSCLientError Output:\r\n \r\n";
            errMess += errors[i].ErrId.ToString() + "\n";

            for (int j = 0; j < errors[i].ErrorAttributes.Length; j++)
            {
               errMess += "\r\n\t" + errors[i].ErrorAttributeNames()[j] + ": "
                  + errors[i].ErrorAttributes[j];
            }
            errMess += "\r\n".PadRight(30, '=');
         }
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine(errMess);
      }

      public void HandleWebException(WebException ex)
      {
         string errMess = ex.Message.ToString() +
            "\n\nLog on, or check the Project Server Queuing Service";
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("Error: " + errMess);
      }

      public void HandleException(Exception ex)
      {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("Error: " + ex.Message);
      }

      public void ResetConsole()
      {
         Console.ResetColor();
         Console.WriteLine("\r\n\r\nPress any key...");
         Console.ReadKey();
      }
   }
}

另请参阅

引用

TimeSheet 类

TimeSheet 成员

WebSvcTimeSheet 命名空间