我有一个在sharepoint 2010中的应用程序。实际上应用程序用户在多个位置在该应用程序中工作..如果一个用户在IST时间(UTC + 5:30)工作了15天,接下来的10天去美国然后他在 CST 或 EST 时区工作......所以我的用户根据他的位置更改他的时区......但现在的问题是......当他去生成他的报告时......它没有显示正确的日期时间字段...... . 如果他正确选择了 IST 时区,那么所有数据都按 IST 时区显示... EST 和 CST 不显示正确,用户也无法分离他的不同 - 2 个时区数据...
实际上我已经提供了 asmx webservices 的报告。请在下面找到我编写的代码。
using System;
using System.Collections;
using System.Text;
using System.Data;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Security.Principal;
using System.Net;
using System.Xml;
public class SharePointActivities
{
[SqlFunction(SystemDataAccess = SystemDataAccessKind.Read, FillRowMethodName = "GetActivitiesItemInfo")]
public static IEnumerable GetActivitiesItems(SqlString url, SqlString listName, SqlString viewName, SqlString Query)
{
DataTable t = new DataTable();
WindowsImpersonationContext ctx = null;
WindowsIdentity id = SqlContext.WindowsIdentity;
try
{
ctx = id.Impersonate();
WSS.Lists svc = new WSS.Lists();
svc.Url = url.ToString();
//svc.Credentials = new NetworkCredential("krishna", "google@123", "WKS10953");
//Or
//svc.Credentials = new System.Net.NetworkCredential("krishna", "google@123", "WKS10953");
//Or
svc.Credentials = CredentialCache.DefaultNetworkCredentials;
//Or
//svc.UseDefaultCredentials = true;
//svc.PreAuthenticate = true;
//Or
//oServices.Credentials = new NetworkCredential("krishna", "google@123", "wks10953");
//Query
XmlDocument xmlDoc = new XmlDocument();
XmlNode query = xmlDoc.CreateElement("Query");
query.InnerXml = Query.ToString();//"<Where><Gt><FieldRef Name=\"ID\" /><Value Type=\"Counter\">3</Value></Gt></Where>";
//ViewFields
XmlElement viewFields = xmlDoc.CreateElement("ViewFields");
viewFields.InnerXml = "";// "<FieldRef Name=\"Title\" />";
//QueryOptions
XmlElement queryOptions = xmlDoc.CreateElement("QueryOptions");
queryOptions.InnerXml = "";
XmlNode node = svc.GetListItems(listName.ToString(), viewName.ToString(), query, viewFields, "500000", queryOptions, null);
XmlTextReader rdr = new XmlTextReader(node.OuterXml,
XmlNodeType.Element, null);
DataSet ds = new DataSet();
ds.ReadXml(rdr);
t = ds.Tables[1];
}
finally
{
if (ctx != null)
ctx.Undo();
}
return t.Rows;
}
public static void GetActivitiesItemInfo(
object obj,
out SqlString ID,
out SqlString Title,
out SqlString RecordDate,
out SqlString ClientVertical,
out SqlString Client,
out SqlString StoreUnits,
out SqlString Process,
out SqlString MainActivity,
out SqlString SubActivity,
out SqlString PeriodStartDate,
out SqlString PeriodEndDate,
out SqlString NoOfPeriod,
out SqlString EntryType,
out SqlString StartTime,
out SqlString StopTime,
out SqlString TimeTaken,
//out SqlString VolumeCount,
//out SqlString InputMode,
//out SqlString Category,
out SqlString Remarks)
{
DataRow r = (DataRow)obj;
ID = new SqlString(Convert.ToString(r["ows_ID"]));
Title = new SqlString(Convert.ToString(r["ows_Title"]));
RecordDate = new SqlString(Convert.ToString(r["ows_RecordDate"]));
ClientVertical = new SqlString(Convert.ToString(r["ows_ClientVertical"]));
Client = new SqlString(Convert.ToString(r["ows_Client"]));
StoreUnits = new SqlString(Convert.ToString(r["ows_StoreUnits"]));
Process = new SqlString(Convert.ToString(r["ows_Process"]));
MainActivity = new SqlString(Convert.ToString(r["ows_MainActivity"]));
SubActivity = new SqlString(Convert.ToString(r["ows_SubActivity"]));
PeriodStartDate = new SqlString(Convert.ToString(r["ows_PeriodStartDate"]));
PeriodEndDate = new SqlString(Convert.ToString(r["ows_PeriodEndDate"]));
NoOfPeriod = new SqlString(Convert.ToString(r["ows_NoOfPeriod"]));
EntryType = new SqlString(Convert.ToString(r["ows_EntryType"]));
StartTime = new SqlString(Convert.ToString(r["ows_StartTime"]));
StopTime = new SqlString(Convert.ToString(r["ows_StopTime"]));
TimeTaken = new SqlString(Convert.ToString(r["ows_TimeTaken"]));
//VolumeCount = new SqlString(Convert.ToString(r["ows_VolumeCount"]));
//InputMode = new SqlString(Convert.ToString(r["ows_InputMode"]));
//Category = new SqlString(Convert.ToString(r["ows_Category"]));
Remarks = new SqlString(Convert.ToString(r["ows_Remarks"]));
}
}
在我的报告的此代码中,从 Recorddate 字段获取参数开始日期和结束日期。但如果用户选择当前 IST 时区。然后 CST 和 EST 记录的数据显示 1 天之前不起作用。
所以我可以知道记录创建的时区和记录数据的 utc 值,以便在每个时区中找到......或任何其他找到实际日期的解决方案......