您的位置:首页 > 其它

Project Web Server PSI 接口一些常用操作

2015-11-14 13:16 861 查看
对Project Web Server进行二次开发,每天都把自己折腾到12点以后才休息,到处都是坑,研究那些烦人的PSI,国内根本查不到PSI相关的资料,对照API文档一点点谷歌资料,全部英文资料,开发终于完成了,总结了个人一些PSI使用心得

尽量能不用PSI就别用,涉及到查询数据直接用SQL查询数据库,调用PSI速度太慢,不稳定,还有烦人的权限问题,不同人对PSI接口权限不一样,有时候会出现一些权限错误

只要涉及到修改数据和添加数据就还是要用PSI的接口,因为Project Web Server2010有四个数据库,调用PSI会自己把数据同步到其它数据库最主要还是报表数据库,最重要是需要注意调用PSI对数据量有一定限制,这是用血换来的经验呀!在测试机机测试了无数次都是没有任何问题,一部署到正式环境就出问题,找原因都几个熬了几个通宵,接口是修改项目下面所有的计划一个属性值,当项目达到了500条以上数据,就出现PSI接口错误。

这点需要注意每个用户对PSI不同接口具有不同权限,这也是血的教训,测试机就那么几个用户来回测试都没有发现什么问题,一部署到正式服务器,有的用户操作出现错误,有的用户又没有问题,无法定位问题原因,通过增加日志功能才发现这个错误,出现多次上线失败,没办法才增加日志功能,也被客户骂了N次。

这点需要注意调用PSI会走队列,队列有延时,当调用PSI创建数据后又马上去查询该数据就会查询不到数据出现错误,这点取决于数据量大小和网络稳定。

实在国内资料太少,所以我把自己知道的资料写到博客中,让有需要的人少走弯路,欢迎大家给我提相关问题,我的QQ307334732。

PSI调用代码如下:

ServiceBase类

using HIGHFARINFO.ZTJC.LookupTableWebSvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HIGHFARINFO.ZTJC.CustomFieldsWebSvc;
using HIGHFARINFO.ZTJC.TimeSheetWebSvc;
using HIGHFARINFO.ZTJC.AdminWebSvc;
using HIGHFARINFO.ZTJC.ResourceWebSvc;
using HIGHFARINFO.ZTJC.ProjectWebSvc;
using HIGHFARINFO.ZTJC.QueueSystemWebSvc;
using HIGHFARINFO.ZTJC.LoginWindowsWebSvc;
using System.Net;
using HIGHFARINFO.ZTJC.StatusingWebSvc;
using HIGHFARINFO.ZTJC.Common;

namespace HIGHFARINFO.ZTJC.ServiceHelper
{
public class ServiceBase
{
private LookupTable _LookupTableSvc = null;
private CustomFields _CustomFieldsSvc = null;
private TimeSheet _TimeSheetSvc = null;
private Admin _AdminSvc = null;
private Resource _ResourceSvc = null;
private Project _ProjectSvc = null;
private QueueSystem _QueueSystemSvc = null;
private LoginWindows _LoginWindowsSvc = null;
private Statusing _StatusingClient = null;

public ServiceBase()
{

}

protected LookupTable LookupTableSvc
{
get
{
if (_LookupTableSvc == null)
{
_LookupTableSvc = new LookupTable();
_LookupTableSvc.Url = ServiceUrl.LookupTableUrl;
_LookupTableSvc.UseDefaultCredentials = true;
//_LookupTableSvc.Credentials = System.Net.CredentialCache.DefaultCredentials;
//_LookupTableSvc.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
}
return _LookupTableSvc;
}
}

protected CustomFields CustomFieldsSvc
{
get
{
if (_CustomFieldsSvc == null)
{
_CustomFieldsSvc = new CustomFields();
_CustomFieldsSvc.Url = ServiceUrl.CustomFieldsUrl;
_CustomFieldsSvc.UseDefaultCredentials = true;
//_CustomFieldsSvc.Credentials = System.Net.CredentialCache.DefaultCredentials;
//_CustomFieldsSvc.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
}
return _CustomFieldsSvc;
}
}

protected TimeSheet TimeSheetSvc
{
get
{
if (_TimeSheetSvc == null)
{
_TimeSheetSvc = new TimeSheet();
_TimeSheetSvc.Url = ServiceUrl.TimeSheetUrl;
_TimeSheetSvc.UseDefaultCredentials = true;
//_TimeSheetSvc.Credentials = System.Net.CredentialCache.DefaultCredentials;
//_TimeSheetSvc.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
}
return _TimeSheetSvc;
}
}

protected Admin AdminSvc
{
get
{
if (_AdminSvc == null)
{
_AdminSvc = new Admin();
_AdminSvc.Url = ServiceUrl.AdminUrl;
_AdminSvc.UseDefaultCredentials = true;
//_AdminSvc.Credentials = System.Net.CredentialCache.DefaultCredentials;
//_AdminSvc.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
}
return _AdminSvc;
}
}

protected Resource ResourceSvc
{
get
{
if (_ResourceSvc == null)
{
_ResourceSvc = new Resource();
_ResourceSvc.Url = ServiceUrl.ResourceUrl;
_ResourceSvc.UseDefaultCredentials = true;
//_ResourceSvc.Credentials = System.Net.CredentialCache.DefaultCredentials;
//_ResourceSvc.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
}
return _ResourceSvc;
}
}

protected Project ProjectSvc
{
get
{
if (_ProjectSvc == null)
{

_ProjectSvc = new Project();
_ProjectSvc.Url = ServiceUrl.ProjectUrl;
_ProjectSvc.UseDefaultCredentials = true;
//_ProjectSvc.Credentials = System.Net.CredentialCache.DefaultCredentials;
//_ProjectSvc.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
}
return _ProjectSvc;
}
}

protected QueueSystem QueueSystemSvc
{
get
{
if (_QueueSystemSvc == null)
{
_QueueSystemSvc = new QueueSystem();
_QueueSystemSvc.Url = ServiceUrl.QueueSystemUrl;
_QueueSystemSvc.UseDefaultCredentials = true;
//_QueueSystemSvc.Credentials = System.Net.CredentialCache.DefaultCredentials;
//_QueueSystemSvc.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
}
return _QueueSystemSvc;
}
}

protected LoginWindows LoginWindowsSvc
{
get
{
if (_LoginWindowsSvc == null)
{
_LoginWindowsSvc = new LoginWindows();
_LoginWindowsSvc.Url = ServiceUrl.LoginWindowsUrl;
_LoginWindowsSvc.UseDefaultCredentials = true;
//_LoginWindowsSvc.Credentials = System.Net.CredentialCache.DefaultCredentials;
//_LoginWindowsSvc.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
}
return _LoginWindowsSvc;
}
}

protected Statusing StatusingClient
{
get
{
if (_StatusingClient == null)
{
_StatusingClient = new Statusing();
_StatusingClient.Url = ServiceUrl.StatusingUrl;
_StatusingClient.UseDefaultCredentials = true;
//_StatusingClient.Credentials = System.Net.CredentialCache.DefaultCredentials;
//_StatusingClient.Credentials = new System.Net.NetworkCredential(SystemConfig.SVC_ADMINUSERNAME, SystemConfig.SVC_ADMINPWD, SystemConfig.SVC_DOMAINNAME);
}
return _StatusingClient;
}
}

/// <summary>
/// 登陆系统
/// </summary>
private void LoginWebService()
{
//CredentialCache credentialCache = new CredentialCache();
//credentialCache.Add(
//    new Uri(Settings.Default.PSI_DataAccess_BaseUri), "NTLM",
//        new NetworkCredential(
//            Settings.Default.PSI_DataAccess_Username,
//            Settings.Default.PSI_DataAccess_Password,
//            Settings.Default.PSI_DataAccess_Domain));
}
}
}


ServiceUrl类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace HIGHFARINFO.ZTJC.ServiceHelper
{
public class ServiceUrl
{
private const string ADMIN_SERVICE_PATH = "/_vti_bin/psi/Admin.asmx";
private const string CUSTOMFIELDS_SERVICE_PATH = "/_vti_bin/psi/CustomFields.asmx";
private const string LOGINWINDOWS_SERVICE_PATH = "/_vti_bin/psi/LoginWindows.asmx";
private const string LOOKUPTABLE_SERVICE_PATH = "/_vti_bin/psi/LookupTable.asmx";
private const string PROJECT_SERVICE_PATH = "/_vti_bin/psi/Project.asmx";
private const string QUEUESYSTEM_SERVICE_PATH = "/_vti_bin/psi/QueueSystem.asmx";
private const string RESOURCE_SERVICE_PATH = "/_vti_bin/psi/Resource.asmx";
private const string STATUSING_SERVICE_PATH = "/_vti_bin/psi/Statusing.asmx";
private const string TIMESHEET_SERVICE_PATH = "/_vti_bin/PSI/TimeSheet.asmx";
private static string PROJECT_SERVER_URI = "http://localhost:8243/PWA";

public static string AdminUrl
{
get { return PROJECT_SERVER_URI + ADMIN_SERVICE_PATH; }
}

public static string CustomFieldsUrl
{
get { return PROJECT_SERVER_URI + CUSTOMFIELDS_SERVICE_PATH; }
}

public static string LoginWindowsUrl
{
get { return PROJECT_SERVER_URI + LOGINWINDOWS_SERVICE_PATH; }
}

public static string LookupTableUrl
{
get { return PROJECT_SERVER_URI + LOOKUPTABLE_SERVICE_PATH; }
}

public static string ProjectUrl
{
get { return PROJECT_SERVER_URI + PROJECT_SERVICE_PATH; }
}

public static string QueueSystemUrl
{
get { return PROJECT_SERVER_URI + QUEUESYSTEM_SERVICE_PATH; }
}

public static string ResourceUrl
{
get { return PROJECT_SERVER_URI + RESOURCE_SERVICE_PATH; }
}

public static string StatusingUrl
{
get { return PROJECT_SERVER_URI + STATUSING_SERVICE_PATH; }
}

public static string TimeSheetUrl
{
get { return PROJECT_SERVER_URI + TIMESHEET_SERVICE_PATH; }
}
}
}


时间表操作类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HIGHFARINFO.ZTJC.TimeSheetWebSvc;
using HIGHFARINFO.ZTJC.AdminWebSvc;
using System.Data;
using Microsoft.Office.Project.Server.Library;
using HIGHFARINFO.ZTJC.Common;

namespace HIGHFARINFO.ZTJC.ServiceHelper
{
/// <summary>
/// 时间表TimeSheet服务操作类
/// </summary>
public class TimeSheetUtils : ServiceBase
{
private AdminUtils adminutils = null;
private QueueSystemUtils queuesystemutils = null;
/// <summary>
/// 初始化构造器
/// </summary>
public TimeSheetUtils()
{
adminutils = new AdminUtils();
queuesystemutils = new QueueSystemUtils();
}

/// <summary>
/// 获取用户当前时间表UID
/// </summary>
/// <param name="date">日期</param>
/// <returns></returns>
public Guid GetTimesheetUidByDate(DateTime datetime)
{
TimesheetDataSet timesheetDs = GetTimesheetByDate(datetime);
if (timesheetDs.Headers.Count < 0)
throw new Exception();
return timesheetDs.Headers[0].TS_UID;
}

/// <summary>
/// 获取时间表TimesheetDataSet对象
/// </summary>
/// <param name="tsUid">时间表UID</param>
/// <returns></returns>
public TimesheetDataSet GetTimeSheetByUid(Guid tsUid)
{
return TimeSheetSvc.ReadTimesheet(tsUid);
}

/// <summary>
/// 获取时间表TimesheetDataSet对象
/// </summary>
/// <param name="datetime">日期</param>
/// <returns></returns>
public TimesheetDataSet GetTimesheetByDate(DateTime datetime)
{
Guid periodUid = adminutils.GetTimePeriodUidByDate(datetime);
return GetTimesheetByPeriodUID(periodUid);
}

/// <summary>
/// 获取时间表TimesheetDataSet对象
/// </summary>
/// <param name="perioduid">周期UID</param>
/// <returns></returns>
public TimesheetDataSet GetTimesheetByPeriodUID(Guid perioduid)
{
Guid myUid = new ResourceUtils().CurrentUserUID;
return TimeSheetSvc.ReadTimesheetByPeriod(myUid, perioduid, TimeSheetWebSvc.Navigation.Current);
}

/// <summary>
/// 判断日期是否属于当前周期或历史周期
/// </summary>
/// <param name="date"></param>
public bool IsOldCurrenCycles(DateTime datetime)
{
DateTime currendatetime = DateTime.Now;
if (datetime > currendatetime)
{
return adminutils.GetTimePeriodUidByDate(datetime) == adminutils.GetTimePeriodUidByDate(currendatetime);
}
return true;
}

/// <summary>
/// 删除时间表
/// </summary>
/// <param name="tsUid"></param>
/// <returns></returns>
public bool DeleteTimeSheet(Guid tsUid)
{
Guid jobUid = Guid.NewGuid();
TimeSheetSvc.QueueDeleteTimesheet(jobUid, tsUid);
return queuesystemutils.WaitForQueue(jobUid);
}

/// <summary>
/// 创建时间表
/// </summary>
/// <param name="resUid"></param>
/// <param name="periodUid"></param>
/// <returns></returns>
public Guid CreateTimeSheet(Guid resUid, Guid periodUid)
{
Guid tsUid = Guid.NewGuid();
TimeSheetWebSvc.TimesheetDataSet tempTimesheetDs = new TimeSheetWebSvc.TimesheetDataSet();
TimeSheetWebSvc.TimesheetDataSet.HeadersRow headersRow = tempTimesheetDs.Headers.NewHeadersRow();
headersRow.RES_UID = resUid;
headersRow.TS_UID = tsUid;
headersRow.WPRD_UID = periodUid;
headersRow.TS_CREATOR_RES_UID = resUid;
headersRow.TS_NAME = "我的时间表 ";
headersRow.TS_ENTRY_MODE_ENUM = (byte)TimesheetEnum.EntryMode.Daily;
tempTimesheetDs.Headers.AddHeadersRow(headersRow);
TimeSheetSvc.CreateTimesheet(tempTimesheetDs, TimeSheetWebSvc.PreloadType.Default);
return tsUid;
}

/// <summary>
/// 同步时间表,将删除前时间表填写的实际实际时间,同步到创建后时间表
/// </summary>
/// <param name="oldTimeSheetDst">删除之前TimesheetDataSet对象</param>
/// <param name="newTimeSheetDst">新创建TimesheetDataSet对象</param>
/// <returns></returns>
public bool TimeSheetSyntonization(TimesheetDataSet oldTimeSheetDst, TimesheetDataSet newTimeSheetDst)
{
//更新时间表中的时间实际时间
foreach (TimeSheetWebSvc.TimesheetDataSet.LinesRow newLinesRow in newTimeSheetDst.Lines)
{
DataRow[] oldLineRows = (oldTimeSheetDst.Lines.AsEnumerable().Where((a) => (a as TimeSheetWebSvc.TimesheetDataSet.LinesRow).ASSN_UID == newLinesRow.ASSN_UID)).ToArray();
if (oldLineRows.Count() > 0)
{
TimeSheetWebSvc.TimesheetDataSet.ActualsRow[] newActualsRows = newLinesRow.GetActualsRows();
TimeSheetWebSvc.TimesheetDataSet.LinesRow oldLineRow = oldLineRows.First() as TimeSheetWebSvc.TimesheetDataSet.LinesRow;
TimesheetDataSet.ActualsRow[] oldActualsRows = oldLineRow.GetActualsRows();
if (newLinesRow["TS_LINE_CLASS_TYPE"].ToString() == "0")//标准任务(项目任务)
{
foreach (var newActualsRow in newActualsRows)
{
TimeSheetWebSvc.TimesheetDataSet.ActualsRow[] oldActualsRow = oldLineRow.GetActualsRows().AsEnumerable().Where(a =>
(a as TimeSheetWebSvc.TimesheetDataSet.ActualsRow).TS_ACT_START_DATE == newActualsRow.TS_ACT_START_DATE
&& (a as TimeSheetWebSvc.TimesheetDataSet.ActualsRow).TS_ACT_FINISH_DATE == newActualsRow.TS_ACT_FINISH_DATE
&& (a as TimeSheetWebSvc.TimesheetDataSet.ActualsRow).TS_ACT_VALUE != newActualsRow.TS_ACT_VALUE).ToArray();
if (oldActualsRow.Count() > 0)
{
newActualsRow.TS_ACT_VALUE = oldActualsRow.First().TS_ACT_VALUE;
}
}
}
else//非标准任务(管理任务)
{
foreach (TimesheetDataSet.ActualsRow item in oldActualsRows)
{
if (item.TS_ACT_VALUE != 0 || item.TS_ACT_PLAN_VALUE != 0)
{
AddActualsRow(newTimeSheetDst, newLinesRow.TS_LINE_UID, item.TS_ACT_START_DATE, item.TS_ACT_FINISH_DATE, item.TS_ACT_PLAN_VALUE, item.TS_ACT_VALUE);
}
}
}
}
}
//1、个人任务
//2、如果项目任务锁定,当创建时间表任务时候是不会创建任务的,必须把之前任务同步过来
foreach (TimeSheetWebSvc.TimesheetDataSet.LinesRow oldLinesRow in oldTimeSheetDst.Lines)
{
DataRow[] newLineRows = (newTimeSheetDst.Lines.AsEnumerable().Where((a) => (a as TimeSheetWebSvc.TimesheetDataSet.LinesRow).TASK_UID == oldLinesRow.TASK_UID)).ToArray();
//if (newLineRows.Count() < 1 && oldLinesRow.TS_LINE_CACHED_PROJ_NAME == "个人任务")
if (newLineRows.Count() < 1)
{
Guid lineuid = AddTimeSheetLine(newTimeSheetDst.Headers[0].TS_UID, newTimeSheetDst, oldLinesRow);
TimesheetDataSet.ActualsRow[] oldActualsRows = oldLinesRow.GetActualsRows();
foreach (TimesheetDataSet.ActualsRow item in oldActualsRows)
{
if ((int)item.TS_ACT_VALUE != 0)
{
AddActualsRow(newTimeSheetDst, lineuid, item.TS_ACT_START_DATE, item.TS_ACT_FINISH_DATE, item.TS_ACT_PLAN_VALUE, item.TS_ACT_VALUE);
}
}
}
}

//删除无用管理任务
List<Guid> lineuidlist = DeleteOtherTask.GetDeleteLineUIDList(newTimeSheetDst);
if (lineuidlist.Count > 0)
{
foreach (TimeSheetWebSvc.TimesheetDataSet.LinesRow newLinesRow in newTimeSheetDst.Lines)
{
if (lineuidlist.Contains(newLinesRow.TS_LINE_UID))
{
newLinesRow.Delete();
}
}
}

Guid tsuids = newTimeSheetDst.Headers[0].TS_UID;
Guid jobUid = Guid.NewGuid();
TimesheetDataSet changedst = (TimeSheetWebSvc.TimesheetDataSet)newTimeSheetDst.GetChanges();
bool result = true;
if (changedst != null)
{
TimeSheetSvc.QueueUpdateTimesheet(jobUid, tsuids, changedst);
result = queuesystemutils.WaitForQueue(jobUid);
}
return result;
}

/// <summary>
/// 添加ActualsRow
/// </summary>
/// <param name="timeSheetDst">需要添加ActualsRow的TimesheetDataSet</param>
/// <param name="tsUid">TimeSheet的UID</param>
/// <param name="startDate">开始时间</param>
/// <param name="finishDate">结束时间</param>
/// <param name="planValue">计划工时</param>
/// <param name="actValue">实际工时</param>
private void AddActualsRow(TimesheetDataSet timeSheetDst, Guid tsUid, DateTime startDate, DateTime finishDate, decimal planValue, decimal actValue)
{
TimesheetDataSet.ActualsRow actualsrow = timeSheetDst.Actuals.NewActualsRow();
actualsrow.TS_ACT_FINISH_DATE = finishDate;
actualsrow.TS_ACT_PLAN_VALUE = planValue;
actualsrow.TS_ACT_START_DATE = startDate;
actualsrow.TS_ACT_VALUE = actValue;
actualsrow.TS_LINE_UID = tsUid;
timeSheetDst.Actuals.AddActualsRow(actualsrow);
}

/// <summary>
/// 添加时间表个人任务
/// </summary>
/// <param name="TS_UID">时间表UID</param>
/// <param name="timeSheetDst"></param>
/// <param name="newlinerow"></param>
/// <returns></returns>
private Guid AddTimeSheetLine(Guid TS_UID, TimesheetDataSet timeSheetDst, TimeSheetWebSvc.TimesheetDataSet.LinesRow newlinerow)
{
Guid lineuid = Guid.NewGuid();
TimeSheetWebSvc.TimesheetDataSet.LinesRow line = timeSheetDst.Lines.NewLinesRow();
line.TS_UID = TS_UID;
line.TS_LINE_UID = lineuid;
line.TS_LINE_CLASS_UID = newlinerow.TS_LINE_CLASS_UID;
line.TS_LINE_COMMENT = newlinerow.TS_LINE_COMMENT;
line.TS_LINE_STATUS = newlinerow.TS_LINE_STATUS;
line.TS_LINE_VALIDATION_TYPE = (byte)(TimesheetEnum.ValidationType.Unverified); //newlinerow.TS_LINE_VALIDATION_TYPE;
line.TS_LINE_CACHED_ASSIGN_NAME = newlinerow.TS_LINE_CACHED_ASSIGN_NAME;
line.ASSN_UID = newlinerow.ASSN_UID;
line.TASK_UID = newlinerow.TASK_UID;
//line.PROJ_UID = newlinerow.PROJ_UID;
line.TS_LINE_CACHED_PROJ_NAME = newlinerow.TS_LINE_CACHED_PROJ_NAME;
timeSheetDst.Lines.AddLinesRow(line);
return lineuid;
}
}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using HIGHFARINFO.ZTJC.AdminWebSvc;

namespace HIGHFARINFO.ZTJC.ServiceHelper
{
/// <summary>
/// Admin服务操作类
/// </summary>
public class AdminUtils : ServiceBase
{
private  TimePeriodDataSet _TimePerDst = null;

public TimePeriodDataSet TimePeriodDataSet
{
get { return _TimePerDst; }
}

/// <summary>
/// 初始化构造器
/// </summary>
public AdminUtils()
{
if (_TimePerDst == null)
{
_TimePerDst = AdminSvc.ReadPeriods(PeriodState.Open);
}
}

/// <summary>
/// 根据时间获取当前周期UID
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public Guid GetTimePeriodUidByDate(DateTime date)
{
var q = TimePeriodDataSet.TimePeriods.AsEnumerable().
Where(a => (a as AdminWebSvc.TimePeriodDataSet.TimePeriodsRow).WPRD_START_DATE <= date
&& (a as AdminWebSvc.TimePeriodDataSet.TimePeriodsRow).WPRD_FINISH_DATE >= date);
if (q.Count() > 0)
{
TimePeriodDataSet.TimePeriodsRow currenttimeper = (TimePeriodDataSet.TimePeriodsRow)q.First();
return currenttimeper.WPRD_UID;
}
return Guid.Empty;
}

/// <summary>
/// 根据时间表UID获取时间表的开始时间
/// </summary>
/// <param name="periodsuid">根据时间表UID</param>
/// <returns></returns>
public DateTime GetPeriodStartDateByPerioduid(Guid periodsuid)
{
TimePeriodDataSet dst = AdminSvc.ReadPeriods(PeriodState.All);
TimePeriodDataSet.TimePeriodsRow timerow = dst.TimePeriods.FindByWPRD_UID(periodsuid);
DateTime start = timerow.WPRD_START_DATE;
return start;
}

/// <summary>
/// 根据时间表UID获取时间表
/// </summary>
/// <param name="periodsuid">根据时间表UID</param>
/// <returns></returns>
public TimePeriodDataSet.TimePeriodsRow GetPeriodByPerioduid(Guid periodsuid)
{
TimePeriodDataSet dst = AdminSvc.ReadPeriods(PeriodState.All);
TimePeriodDataSet.TimePeriodsRow timerow = dst.TimePeriods.FindByWPRD_UID(periodsuid);
return timerow;
}

/// <summary>
/// 根据时间表UID获取时间表的开始时间
/// </summary>
/// <param name="periodsuid">根据时间表UID</param>
/// <param name="start">时间表开始时间</param>
/// <param name="end">时间表结束时间</param>
public void GetPeriodStartDateByPerioduid(Guid periodsuid, ref DateTime start, ref DateTime end)
{
TimePeriodDataSet dst = AdminSvc.ReadPeriods(PeriodState.All);
TimePeriodDataSet.TimePeriodsRow timerow = dst.TimePeriods.FindByWPRD_UID(periodsuid);
start = timerow.WPRD_START_DATE;
end = timerow.WPRD_FINISH_DATE;
}
}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HIGHFARINFO.ZTJC.CustomFieldsWebSvc;
using Microsoft.Office.Project.Server.Library;

namespace HIGHFARINFO.ZTJC.ServiceHelper
{
/// <summary>
/// 自定义域CustomFields服务操作类
/// </summary>
public class CustomFieldsUtils : ServiceBase
{
/// <summary>
/// 初始化构造器
/// </summary>
public CustomFieldsUtils()
{
}

/// <summary>
/// 根据自定义域名称获取UID
/// </summary>
/// <param name="fieldName"></param>
/// <param name="entityType"></param>
/// <returns></returns>
public Guid GetCustomFieldUID(String fieldName, CustomFieldsEntityType entityType)
{
return GetCustomField(fieldName, entityType).MD_PROP_UID;
}

/// <summary>
/// 根据自定义域名称获取CustomFieldsRow对象
/// </summary>
/// <param name="fieldName">自定义域名称</param>
/// <param name="entityType">CustomFieldsEntityType对象类型</param>
/// <returns></returns>
public CustomFieldDataSet.CustomFieldsRow GetCustomField(String fieldName, CustomFieldsEntityType entityType)
{
string typeuid = string.Empty;
switch (entityType)
{
case CustomFieldsEntityType.PROTYPE:
typeuid = EntityCollection.Entities.ProjectEntity.UniqueId;
break;
case CustomFieldsEntityType.RESTYPE:
typeuid = EntityCollection.Entities.ResourceEntity.UniqueId;
break;
case CustomFieldsEntityType.TASKTYPE:
typeuid = EntityCollection.Entities.TaskEntity.UniqueId;
break;
}
Guid entityTypeUid = new Guid(typeuid);
using (CustomFieldDataSet filterDS = new CustomFieldDataSet())
{
string filterxml = GetFilterXml(fieldName, entityTypeUid);

using (CustomFieldDataSet customFieldDS = CustomFieldsSvc.ReadCustomFields(filterxml, false))
{
if (customFieldDS.CustomFields == null || customFieldDS.CustomFields.Count == 0)
{
throw new Exception();
}
if (customFieldDS.CustomFields.Count > 1)
{
throw new Exception();
}
return customFieldDS.CustomFields[0];
}
}

}

/// <summary>
/// 根据名称和类型生成Filter xml
/// </summary>
/// <param name="fieldName">自定义域名称</param>
/// <param name="entityType">类型UID</param>
/// <returns></returns>
private string GetFilterXml(string fieldName, Guid entityType)
{
using (CustomFieldDataSet filterDS = new CustomFieldDataSet())
{
String tableName = filterDS.CustomFields.TableName;
String uidColumn = filterDS.CustomFields.MD_PROP_UIDColumn.ColumnName;
String secUidColumn = filterDS.CustomFields.MD_PROP_ID_SECONDARYColumn.ColumnName;
String nameColumn = filterDS.CustomFields.MD_PROP_NAMEColumn.ColumnName;
String entityUidColumn = filterDS.CustomFields.MD_ENT_TYPE_UIDColumn.ColumnName;
Filter filter = new Filter();
filter.FilterTableName = tableName;
filter.Fields.Add(new Filter.Field(tableName, uidColumn));
filter.Fields.Add(new Filter.Field(secUidColumn));
filter.Fields.Add(new Filter.Field(nameColumn));
filter.Fields.Add(new Filter.Field(entityUidColumn));
filter.Criteria = new Filter.LogicalOperator(
Filter.LogicalOperationType.And,
new Filter.FieldOperator(Filter.FieldOperationType.Equal, entityUidColumn, entityType),
new Filter.FieldOperator(Filter.FieldOperationType.Equal, nameColumn, fieldName));
return filter.GetXml();
}
}
}

/// <summary>
/// 自定义域枚举类型
/// </summary>
public enum CustomFieldsEntityType
{
/// <summary>
/// 项目类型
/// </summary>
PROTYPE,
/// <summary>
/// 资源类型
/// </summary>
RESTYPE,
/// <summary>
/// 任务类型
/// </summary>
TASKTYPE
}
}


using HIGHFARINFO.ZTJC.LookupTableWebSvc;
using Microsoft.Office.Project.Server.Library;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Web.Services.Protocols;
using System.Data;

namespace HIGHFARINFO.ZTJC.ServiceHelper
{
/// <summary>
/// 查阅表格LookupTable服务操作类
/// </summary>
public class LookupTableUtils : ServiceBase
{
/// <summary>
/// 初始化构造器
/// </summary>
public LookupTableUtils()
{

}

/// <summary>
/// 根据查阅表格名称获取LookupTableDataSet对象
/// </summary>
/// <param name="lookupTableName">查阅表格名称</param>
/// <returns></returns>
public LookupTableDataSet GetLookupTable(String lookupTableName)
{
string filterxml = GetFilterXml(lookupTableName);
using (LookupTableMultiLangDataSet lookupTableDS = LookupTableSvc.ReadLookupTablesMultiLang(filterxml, false))
{
if (lookupTableDS.LookupTables == null || lookupTableDS.LookupTables.Count == 0)
{
throw new Exception();
}
if (lookupTableDS.LookupTables.Count > 1)
{
throw new Exception();
}
return ReadLookupTablesByUID(new Guid[] { lookupTableDS.LookupTables[0].LT_UID });
}
}

/// <summary>
/// 根据查阅表格的ValueUid获取ValueText
/// </summary>
/// <param name="valueUid">表格中行UID</param>
/// <param name="lookupdst"></param>
/// <returns></returns>
public string GetValueTextByValueUid(Guid valueUid, LookupTableDataSet lookupdst)
{
LookupTableWebSvc.LookupTableDataSet.LookupTableTreesRow lookrow = (LookupTableWebSvc.LookupTableDataSet.LookupTableTreesRow)lookupdst.LookupTableTrees.AsEnumerable().Single(
a => (a as LookupTableWebSvc.LookupTableDataSet.LookupTableTreesRow).LT_STRUCT_UID == valueUid);
return lookrow.LT_VALUE_TEXT;
}

/// <summary>
/// 根据查阅表格的ValueText获取ValueUid
/// </summary>
/// <param name="valuetext">表格中行文本值</param>
/// <param name="lookupdst"></param>
/// <returns></returns>
public Guid GetValueUidByValueText(string valuetext, LookupTableDataSet lookupdst)
{
LookupTableDataSet.LookupTableTreesRow tablevaluesrow = lookupdst.LookupTableTrees.AsEnumerable().Single(
a => (a as LookupTableDataSet.LookupTableTreesRow).LT_VALUE_TEXT == valuetext)
as LookupTableDataSet.LookupTableTreesRow;
return tablevaluesrow.LT_STRUCT_UID;
}

#region
/// <summary>
/// 根据表格名称生成Filter XML
/// </summary>
/// <param name="lookupTableName">表格名称</param>
/// <returns></returns>
private string GetFilterXml(string lookupTableName)
{
using (LookupTableDataSet filterDS = new LookupTableDataSet())
{
String tableName = filterDS.LookupTables.TableName;
String uidColumn = filterDS.LookupTables.LT_UIDColumn.ColumnName;
String nameColumn = filterDS.LookupTables.LT_NAMEColumn.ColumnName;
Filter filter = new Filter();
filter.FilterTableName = tableName;
filter.Fields.Add(new Filter.Field(tableName, uidColumn));
filter.Fields.Add(new Filter.Field(tableName, nameColumn));
filter.Criteria = new Filter.FieldOperator(Filter.FieldOperationType.Equal, "LT_NAME", new String[] { lookupTableName });
return filter.GetXml();
}
}

/// <summary>
/// 根据表格的UID获取LookupTableDataSet对象
/// </summary>
/// <param name="uidList">表格UID</param>
/// <returns></returns>
private LookupTableDataSet ReadLookupTablesByUID(Guid[] uidList)
{
try
{
return LookupTableSvc.ReadLookupTablesByUids(uidList, false, 0);
}
catch (SoapException ex)
{
throw ex;
}
catch (WebException ex)
{
throw ex;
}
}
#endregion
}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HIGHFARINFO.ZTJC.ProjectWebSvc;
using System.Data;
using HIGHFARINFO.ZTJC.Common;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint;
using System.Collections.Specialized;

namespace HIGHFARINFO.ZTJC.ServiceHelper
{
/// <summary>
/// 项目Project服务操作类
/// </summary>
public class ProjectUtils : ServiceBase
{
/// <summary>
/// 初始化构造器
/// </summary>
public ProjectUtils()
{
}

/// <summary>
/// 根据项目UID获取ProjectDataSet对象
/// </summary>
/// <param name="projectUid">项目UID</param>
/// <returns></returns>
public ProjectDataSet GetProjectByUid(Guid projectUid)
{
return ProjectSvc.ReadProject(projectUid, DataStoreEnum.WorkingStore);
}

/// <summary>
/// 根据自定义域的UID获取ProjectCustomFieldsRow对象
/// </summary>
/// <param name="customFieldUid">项目类型的自定义域UID</param>
/// <param name="projectDst">ProjectDataSet对象</param>
/// <returns></returns>
public ProjectDataSet.ProjectCustomFieldsRow ProjectCustomFieldsByUid(Guid customFieldUid, ProjectDataSet projectDst)
{
var q = projectDst.ProjectCustomFields.AsEnumerable().Where(a => (a as ProjectWebSvc.ProjectDataSet.ProjectCustomFieldsRow).MD_PROP_UID == customFieldUid);
if (q.Count() > 0)
{
return (ProjectDataSet.ProjectCustomFieldsRow)q.First();
}
return null;
}

/// <summary>
/// 根据自定义域的UID获取TaskCustomFieldsRow对象
/// </summary>
/// <param name="customFieldUid">项目类型的自定义域UID</param>
/// <param name="projectDst">ProjectDataSet对象</param>
/// <returns></returns>
public List<ProjectDataSet.TaskCustomFieldsRow> ProjectTaskCustomFieldsByUid(Guid customFieldUid, ProjectDataSet projectDst)
{
List<ProjectDataSet.TaskCustomFieldsRow> taskcusrowslist = new List<ProjectDataSet.TaskCustomFieldsRow>();
var q = projectDst.TaskCustomFields.AsEnumerable().Where(a => (a as ProjectDataSet.TaskCustomFieldsRow).MD_PROP_UID == customFieldUid);
//foreach (ProjectDataSet.TaskRow taskrow in projectDst.Task.Rows)
//{
foreach (ProjectDataSet.TaskCustomFieldsRow item in q)
{
//if (item.TASK_UID == taskrow.TASK_UID)
//{
taskcusrowslist.Add(item);
//}
}
//}
return taskcusrowslist;
}

/// <summary>
/// 更新项目
/// </summary>
/// <param name="changeProjectDst">变动的ProjectDataSet对象</param>
/// <param name="projectUid">项目UID</param>
/// <returns></returns>
public bool UpdateProject(ProjectDataSet changeProjectDst, Guid projectUid, Guid sessionUid)
{
QueueSystemUtils queuesystemutils = new QueueSystemUtils();
Guid jobUid = Guid.NewGuid();
try
{
jobUid = Guid.NewGuid();
ProjectSvc.QueueUpdateProject(jobUid, sessionUid, changeProjectDst, false);
bool res = queuesystemutils.WaitForQueue(jobUid);
return res;
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
}

/// <summary>
/// 嵌出项目
/// </summary>
/// <param name="projectUid"></param>
public void CheckOutProject(Guid projectUid, Guid sessionUid)
{
QueueSystemUtils queuesystemutils = new QueueSystemUtils();
string session_desc = "Sample utility";
//Guid sessionUid = Guid.NewGuid();
Guid jobUid = Guid.NewGuid();
try
{
ProjectSvc.CheckOutProject(projectUid, sessionUid, session_desc);
}
catch
{
ProjectSvc.QueueCheckInProject(jobUid, projectUid, true, sessionUid, session_desc);
bool temps = queuesystemutils.WaitForQueue(jobUid);
ProjectSvc.CheckOutProject(projectUid, sessionUid, session_desc);
}
}

/// <summary>
/// 嵌入并发布项目
/// </summary>
/// <param name="projectUid"></param>
public void ChreckInPublishProject(Guid projectUid, Guid sessionUid)
{
try
{
//QueueSystemUtils queuesystemutils = new QueueSystemUtils();
//string session_desc = "Sample utility";
////Guid sessionUid = Guid.NewGuid();
//Guid jobUid = Guid.NewGuid();
//ProjectSvc.QueueCheckInProject(jobUid, projectUid, true, sessionUid, session_desc);
//bool result = queuesystemutils.WaitForQueue(jobUid);
//jobUid = Guid.NewGuid();
//ProjectSvc.QueuePublish(jobUid, projectUid, true, string.Empty);
//bool ddd = queuesystemutils.WaitForQueue(jobUid);

QueueSystemUtils queuesystemutils = new QueueSystemUtils();
string session_desc = "Sample utility";
//Guid sessionUid = Guid.NewGuid();
Guid jobUid = Guid.NewGuid();
ProjectSvc.QueueCheckInProject(jobUid, projectUid, true, sessionUid, session_desc);
bool result = queuesystemutils.WaitForQueue(jobUid);
jobUid = Guid.NewGuid();
ProjectSvc.QueuePublish(jobUid, projectUid, false, string.Empty);
bool ddd = queuesystemutils.WaitForQueue(jobUid);
}
catch (Exception ex)
{
new LogHelper().WriteLine(ex.ToString());
}
}

/// <summary>
/// 获取项目中所有资源者的邮箱
/// </summary>
/// <param name="projectdataset">ProjectDataSet对象</param>
/// <returns></returns>
public string[] GetProjectTaskAllUserGuid(ProjectDataSet projectdataset)
{
List<string> resemaillist = new List<string>();
ResourceUtils resourceutils = new ResourceUtils();
ProjectDataSet.ProjectResourceDataTable resourcedt = projectdataset.ProjectResource;
foreach (ProjectDataSet.ProjectResourceRow resourcerow in resourcedt)
{
try
{
if (!string.IsNullOrEmpty(resourcerow.WRES_EMAIL) && !resemaillist.Contains(resourcerow.WRES_EMAIL))
{
resemaillist.Add(resourcerow.WRES_EMAIL);
}
}
catch { }
}
return resemaillist.ToArray();
}

/// <summary>
/// 项目打开或关闭想用户发送邮件通知
/// </summary>
/// <param name="projectdataset"></param>
/// <returns></returns>
public bool ProjectCloseOrOpenSendEmail(SPWeb web, ProjectDataSet projectdataset, bool CloseOrOpen)
{
try
{
string[] mailtoarray = GetProjectTaskAllUserGuid(projectdataset);
if (mailtoarray.Count() > 0)
{
string projectname = projectdataset.Project[0].PROJ_NAME;
string subject = string.Empty;
string mailbody = string.Empty;
bool send_result = false;
if (CloseOrOpen)
{
subject = string.Format("《{0}》项目已打开", projectname);
mailbody = string.Format("你好,《{0}》项目已打开,请知悉,谢谢!", projectname);
}
else
{
subject = string.Format("《{0}》项目已关闭", projectname);
mailbody = string.Format("你好,请注意《{0}》项目已关闭,请知悉,谢谢!", projectname);
}
foreach (string touser in mailtoarray)
{
bool result = SPUtility.SendEmail(web, false, false, touser, subject, mailbody);
if (result)
send_result = true;
}
if (send_result)
new LogHelper().WriteLine(subject + ",并且邮件发送成功");
else
new LogHelper().WriteLine(subject + ",但是邮件发送失败");
return send_result;
}
return false;
}
catch
{
return false;
}
}
}
}


using HIGHFARINFO.ZTJC.QueueSystemWebSvc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Xml;
using HIGHFARINFO.ZTJC.Common;

namespace HIGHFARINFO.ZTJC.ServiceHelper
{
public class QueueSystemUtils : ServiceBase
{
// Wait 2 seconds between each check for job completion.
private const int INCREMENTALSLEEPTIME = 2;

public QueueSystemUtils()
{
}

public bool WaitForQueue(Guid jobId)
{
int timeOut = 2;
int wait;                            // Number of seconds to wait
string xmlError;                     // XML error output from the queue
bool firstPass = true;               // First iteration through the while statement.
int timeSlept = 0;                   // Total time slept (seconds).
bool jobIsDone = false;              // The queue job completed successfully, if true.
bool stopWait = false;               // Abort the wait, if true.
QueueSystemWebSvc.JobState jobState; // Status of the queue job.
while (true)
{
if (firstPass)
{
wait = QueueSystemSvc.GetJobWaitTime(jobId);
if (timeOut < INCREMENTALSLEEPTIME) wait = timeOut;
else wait = INCREMENTALSLEEPTIME;
firstPass = false;
}
else
{
wait = INCREMENTALSLEEPTIME;
}
Thread.Sleep(wait * 1000);
timeSlept += wait;
jobState = QueueSystemSvc.GetJobCompletionState(jobId, out xmlError);
while (jobState == QueueSystemWebSvc.JobState.Processing)
{
Thread.Sleep(1000);
jobState = QueueSystemSvc.GetJobCompletionState(jobId, out xmlError);
if (jobState == QueueSystemWebSvc.JobState.Success) { break; }
}
if (jobState == QueueSystemWebSvc.JobState.Success)
{
jobIsDone = true;
}
else if (jobState == QueueSystemWebSvc.JobState.Unknown
|| jobState == QueueSystemWebSvc.JobState.Failed
|| jobState == QueueSystemWebSvc.JobState.FailedNotBlocking
|| jobState == QueueSystemWebSvc.JobState.CorrelationBlocked
|| jobState == QueueSystemWebSvc.JobState.Canceled)
{
stopWait = true;
}
if (!jobIsDone && timeSlept >= timeOut)
{
new LogHelper().WriteLine(xmlError);
QueueSystemSvc.CancelJobSimple(jobId);
stopWait = true;
}
if (jobIsDone || stopWait)
{
break;
}
}
return jobIsDone;
}

public bool WaitForQueue(int timeOut, Guid jobId, out String statusOut)
{
int wait;                 // Number of seconds to wait
decimal seconds;          // for reporting wait time in decimal format.
string xmlError;          // XML error output from the queue
string queueStatus;       // Outer XML of xmlError string.
string status = "";       // Summary status report for output.
bool firstPass = true;    // First iteration through the while statement.
int timeSlept = 0;        // Total time slept (seconds).
bool jobIsDone = false;   // The queue job completed successfully, if true.
bool stopWait = false;    // Abort the wait, if true.
QueueSystemWebSvc.JobState jobState; // Status of the queue job.
while (true)
{
// On the first iteration, wait the incremental sleep time
// or the maximum requested timeout.
if (firstPass)
{
// Get the estimated time to wait for the queue to process the job.
// The output from GetJobWaitTime is in seconds.
wait = QueueSystemSvc.GetJobWaitTime(jobId);

status = string.Format("Estimated job wait time: {0} seconds", wait);

if (timeOut < INCREMENTALSLEEPTIME) wait = timeOut;
else wait = INCREMENTALSLEEPTIME;

firstPass = false;
}
else
{
// If job is not done, wait the incremental sleep time.
wait = INCREMENTALSLEEPTIME;
}

Thread.Sleep(wait * 1000); // Milliseconds

timeSlept += wait;

// Check job state.
jobState = QueueSystemSvc.GetJobCompletionState(jobId, out xmlError);

// Add the XML error output to the status.
StringReader sr = new StringReader(xmlError);
using (XmlReader reader = XmlReader.Create(sr))
{
reader.MoveToContent();
queueStatus = reader.ReadOuterXml();
}
// Don't add an empty <errinfo> element.
if (queueStatus != "<errinfo />") status += "\n\n" + queueStatus;

if (jobState == QueueSystemWebSvc.JobState.Success)
{
jobIsDone = true;
}
else if (jobState == QueueSystemWebSvc.JobState.Unknown
|| jobState == QueueSystemWebSvc.JobState.Failed
|| jobState == QueueSystemWebSvc.JobState.FailedNotBlocking
|| jobState == QueueSystemWebSvc.JobState.CorrelationBlocked
|| jobState == QueueSystemWebSvc.JobState.Canceled)
{
stopWait = true;
}

if (!jobIsDone && timeSlept >= timeOut)
{
// Cancel the job, otherwise the queue keeps processing it until it is complete.
QueueSystemSvc.CancelJobSimple(jobId);
stopWait = true;
status += string.Format("\n\nExceeded timeout of {0} seconds", timeOut);
}

if (jobIsDone || stopWait)
{
// Check jobState again, might be cancelled.
seconds = Convert.ToDecimal(timeSlept);
status += string.Format(
"\n\nJobState: {0:G}\n\nTotal time slept: {1:N} seconds",
jobState, seconds);
break;
}
}
statusOut = status;
return jobIsDone;
}
}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HIGHFARINFO.ZTJC.ResourceWebSvc;
using System.Data;
using Microsoft.SharePoint;
using HIGHFARINFO.ZTJC.Common;

namespace HIGHFARINFO.ZTJC.ServiceHelper
{
public class ResourceUtils : ServiceBase
{
private Guid _CurrentUserUID = Guid.Empty;

public ResourceUtils()
{
}

public Guid CurrentUserUID
{
get
{
try
{
return ResourceSvc.GetCurrentUserUid();
}
catch (Exception ex)//如果没有资源中心权限则直接用sql获取用户信息
{
string username = SPContext.Current.Web.CurrentUser.LoginName;
return new ProjectSQLMethod().GetCurrentUserResUID(username);
}
}
}

public string CurrentUserName
{
get
{
try
{
ResourceDataSet resdst = ResourceSvc.ReadResource(CurrentUserUID);
if (resdst.Resources.Count > 0)
{
return resdst.Resources[0].RES_NAME;
}
return "";
}
catch (Exception ex)
{
return SPContext.Current.Web.CurrentUser.LoginName;
}
}
}

public Guid GetAdminUserUID
{
get { return ResourceSvc.GetCurrentUserUid(); }
}

/// <summary>
/// 获取当前用户资源ResourceDataSet对象
/// </summary>
/// <returns></returns>
public ResourceDataSet ReadCurrentUserResource()
{
return ResourceSvc.ReadResource(CurrentUserUID);
}

/// <summary>
/// 获取指定用户资源ResourceDataSet对象
/// </summary>
/// <param name="userUid">用户UID</param>
/// <returns></returns>
public ResourceDataSet ReadUserResourceByUid(Guid userUid)
{
return ResourceSvc.ReadResource(userUid);
}

/// <summary>
/// 获取当前用户某个自定义属性对象
/// </summary>
/// <param name="customFieldUid"></param>
/// <returns></returns>
public ResourceDataSet.ResourceCustomFieldsRow GetResourceCustomFieldByUid(Guid customFieldUid)
{
ResourceDataSet resdst = ReadCurrentUserResource();
if (resdst.ResourceCustomFields.Count > 0)
{
var resourceitem = resdst.ResourceCustomFields.AsEnumerable().Where(
a => (a as ResourceWebSvc.ResourceDataSet.ResourceCustomFieldsRow).MD_PROP_UID == customFieldUid).ToList();
if (resourceitem.Count > 0)
return resourceitem.First() as ResourceDataSet.ResourceCustomFieldsRow;
}
return null;
}

/// <summary>
/// 获取指定用户某个自定义属性对象
/// </summary>
/// <param name="resourceDst">ResourceDataSet对象</param>
/// <param name="customFieldUid"></param>
/// <returns></returns>
public ResourceDataSet.ResourceCustomFieldsRow GetResourceCustomFieldByUid(ResourceDataSet resourceDst, Guid customFieldUid)
{
if (resourceDst.ResourceCustomFields.Count > 0)
{
var resourceitem = resourceDst.ResourceCustomFields.AsEnumerable().Single(
a => (a as ResourceWebSvc.ResourceDataSet.ResourceCustomFieldsRow).MD_PROP_UID == customFieldUid);
return resourceitem as ResourceDataSet.ResourceCustomFieldsRow;
}
return null;
}

/// <summary>
/// 获取用户邮箱
/// </summary>
/// <param name="resourceuid">用户UID</param>
/// <returns></returns>
public string GetResourceEmail(Guid resourceuid)
{
try
{
ResourceDataSet resourceds = ResourceSvc.ReadResource(resourceuid);
if (null != resourceds)
{
ResourceDataSet.ResourcesRow resourceRow = (ResourceDataSet.ResourcesRow)resourceds.Resources.Rows[0];
string resourceName = resourceRow.RES_NAME;
string resourceEmail = resourceRow.WRES_EMAIL;
return resourceEmail;
}
}
catch { }
return "";
}
}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HIGHFARINFO.ZTJC.StatusingWebSvc;

namespace HIGHFARINFO.ZTJC.ServiceHelper
{
public class StatusingUtils : ServiceBase
{

public StatusingWebSvc.Statusing StatusingClientsvc
{
get
{
return StatusingClient;
}
}

public StatusingUtils() { }

public StatusingDataSet GetAssignments(DateTime start, DateTime end)
{
StatusingDataSet dst = StatusingClient.ReadStatus(Guid.Empty, start, end);
return dst;
}

public StatusingAssignmentsDataSet GetAssignments(Guid[] assnuidarray)
{
StatusingAssignmentsDataSet dst = StatusingClient.ReadAssignments(assnuidarray);
return dst;
}

public StatusingDataSet GetAssignments(Guid resuid, DateTime start, DateTime end)
{
StatusingDataSet dst = StatusingClient.ReadStatusForResource(resuid, Guid.Empty, start, end);
return dst;
}

public void insertinto(Guid perguid)
{
StatusingClient.ImportTimesheet(perguid);
StatusingWebSvc.ImportTimesheetDataSet importTimeSheetDs = StatusingClient.ReadImportTimesheetData(perguid);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: