共用方式為


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滿足參數的時程表的摘要清單。

備註

請使用Microsoft.Office.Project.Server.Library.TimesheetEnum.ListSelect值select參數。您可以合併ListSelect值篩選的屬性的組合於OR作業。例如,若要選取所有時程表的使用者在建立正在進行中,將select參數設CreatedByMeORInProgress。

若要傳回的一段的所有時程表加上空白記錄其中有無時程表,設為selectTimeSheetEnum.ListSelect.AllPeriods。

如果select的值是剛剛CreatedByMeReadTimesheetList會略過resUID 。若要取得您所建立的另一個人時程表的清單--也就是說,您會替代時程表 — 傳遞resUID和selectOR作業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 classe 隔開Program類別中的功能。TimeSheetUtils.GetMyTimeSheetsInProgress方法使用的資源 web 服務中GetCurrentUserUid方法,傳回使用者的 GUID。

For information about compiling the sample, see Prerequisites for Reference Code Samples.

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 命名空間