Is it possible to change CreationDateTime, SentDateTime, etc.????
I`m tring to create/update message. All run fine, but i need to set field ItemType.CreateDateTime with my values (eg. I need to create message that has time creation not today, but year ego).
I have next code:
//Update created item
ItemIdType itemId = new ItemIdType();
itemId.Id = savedMessageId;
itemId.ChangeKey = savedMessageChangeKey;
ItemType setCreateDT = new ItemType();
setCreateDT.DateTimeCreated = new System.DateTime(2000, 10, 10, 12, 12, 12);
setCreateDT.DateTimeCreatedSpecified = true;
SetItemFieldType setItemField = new SetItemFieldType();
setItemField.Item = new PathToUnindexedFieldType();
(setItemField.Item as PathToUnindexedFieldType).FieldURI = UnindexedFieldURIType.itemDateTimeCreated;
setItemField.Item1 = setCreateDT;
UpdateItemType request = new UpdateItemType();
request.ItemChanges = new ItemChangeType[1] { new ItemChangeType() };
request.ItemChanges[0].Item = itemId;
request.ItemChanges[0].Updates = new ItemChangeDescriptionType[1];
request.ItemChanges[0].Updates[0] = setItemField;
request.MessageDisposition = MessageDispositionType.SaveOnly;
request.MessageDispositionSpecified = true;
UpdateItemResponseType updateItemResponse = m_mailbox.UpdateItem(request);
That request return Error: "Set action is invalid for property."
If im tring to change Subject, all run OK.
[UPDATE]
Found next solution, but it doesn`t work.
There is using extended properties and their ids.
PathToExtendedFieldType q = new PathToExtendedFieldType();
q.PropertyId = 3590; //DeliveryTime
q.PropertyType = MapiPropertyTypeType.SystemTime;
q.PropertyIdSpecified = true;
newItem.ExtendedProperty[0] = new ExtendedPropertyType();
newItem.ExtendedProperty[0].ExtendedFieldURI = q;
newItem.ExtendedProperty[0].ExtendedFieldURI.DistinguishedPropertySetIdSpecified = true;
newItem.ExtendedProperty[0].Item = new System.DateTime(2013, 5, 5, 5, 5, 5).ToString("yyyy-MM-ddTHH:mm:ssZ");
...
CreateItemResponseType createItemResponse = m_mailbox.CreateItem(createItemType);
It works fine, but i don`t see any changes..
Second solution is correct, but there are some mistakes.
1) It's better to get access to properties by PropertyTag.
2) You should only set up PropertyTag and PropertyType.
Here is working code:
ItemType newItem = xmlParser.LoadItem(); //info for newItem takes from xml
newItem.ExtendedProperty = new ExtendedPropertyType[1];
PathToExtendedFieldType q = new PathToExtendedFieldType();
q.PropertyTag = "3590"; //DeliveryTime
q.PropertyType = MapiPropertyTypeType.SystemTime;
newItem.ExtendedProperty[0] = new ExtendedPropertyType();
newItem.ExtendedProperty[0].ExtendedFieldURI = q;
newItem.ExtendedProperty[0].Item = new System.DateTime(2014, 5, 5, 5, 5, 5).ToString("yyyy-MM-ddTHH:mm:ssZ");
Related
Below is the code I'm working with to pass multiple line items to create sales order through GP Web service. I can pass single Line Item without any problem , but when I pass multiple Items it is only taking the last one. The array has around 5 Item ID and I'm passing fixed Quantity as 15, Need to make both dynamic. But for the testing purpose I'm trying like this. I know the problem with the creation/initialization of some web service objects. As novice to the entire set of things I couldn't find the exact problem.
C# Code
CompanyKey companyKey;
Context context;
SalesOrder salesOrder;
SalesDocumentTypeKey salesOrderType;
CustomerKey customerKey;
BatchKey batchKey;
// SalesOrderLine salesOrderLine;
ItemKey orderedItem;
Quantity orderedAmount;
Policy salesOrderCreatePolicy;
DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();
wsDynamicsGP.ClientCredentials.Windows.ClientCredential.UserName = "Admin";
wsDynamicsGP.ClientCredentials.Windows.ClientCredential.Password = "pass";
wsDynamicsGP.ClientCredentials.Windows.ClientCredential.Domain = "Gp";
System.ServiceModel.WSHttpBinding binding;
binding = new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None);
context = new Context();
companyKey = new CompanyKey();
companyKey.Id = (1);
context.OrganizationKey = (OrganizationKey)companyKey;
salesOrder = new SalesOrder();
salesOrderType = new SalesDocumentTypeKey();
salesOrderType.Type = SalesDocumentType.Order;
salesOrder.DocumentTypeKey = salesOrderType;
customerKey = new CustomerKey();
customerKey.Id = "121001";
salesOrder.CustomerKey = customerKey;
batchKey = new BatchKey();
batchKey.Id = "RMS";
salesOrder.BatchKey = batchKey;
// SalesOrderLine[] orders = new SalesOrderLine[6];
SalesOrderLine[] lines = { };
for (int i = 1; i < 5; i++)
{
SalesOrderLine salesOrderLine = new SalesOrderLine();
orderedItem = new ItemKey();
orderedItem.Id = Arr[i].ToString();
salesOrderLine.ItemKey = orderedItem;
orderedAmount = new Quantity();
orderedAmount.Value = 15;
salesOrderLine.Quantity = orderedAmount;
lines = new SalesOrderLine[] { salesOrderLine };
MessageBox.Show(lines.Count().ToString());
}
salesOrder.Lines = lines;
//salesOrder.Lines = orders;
salesOrderCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesOrder", context);
wsDynamicsGP.CreateSalesOrder(salesOrder, context, salesOrderCreatePolicy);
if (wsDynamicsGP.State != CommunicationState.Faulted)
{
wsDynamicsGP.Close();
}
MessageBox.Show("Success");
lines = new SalesOrderLine[] { salesOrderLine }; will recreate the lines array object each time meaning you loose any previously added objects. Effectively only the final object in the loop is actually added.
Try using a List<T> like so:
SalesOrderLine[] lines = { }; Becomes List<SalesOrderLine> lines = new List<SalesOrderLine>();
lines = new SalesOrderLine[] { salesOrderLine }; Becomes: lines.Add(salesOrderLine);
If its important you end up with an array as the input:
salesOrder.Lines = lines; Becomes: salesOrder.Lines = lines.ToArray();
My goal here so to make the listing say "Free International Shipping". Trying to set up international options and it said I need to set ShipToLocation I tried the line below:
internationalShippingOptions.ShipToLocation.Add("Worldwide");
But when the program hits it I get this error:
"Object reference not set to an instance of an object"
If you would like to see the full method it is:
static ShippingDetailsType BuildShippingDetails()
{
ShippingDetailsType sd = new ShippingDetailsType();
sd.ApplyShippingDiscount = false;
sd.ShippingType = ShippingTypeCodeType.Flat;
AmountType amount = new AmountType();
amount.Value = 0;
amount.currencyID = CurrencyCodeType.USD;
ShippingServiceOptionsTypeCollection shippingOptions = new ShippingServiceOptionsTypeCollection();
ShippingServiceOptionsType domesticShippingOptions = new ShippingServiceOptionsType();
domesticShippingOptions.ShippingService = ShippingServiceCodeType.EconomyShippingFromOutsideUS.ToString();
domesticShippingOptions.FreeShipping = true;
domesticShippingOptions.ShippingServiceCost = amount;
domesticShippingOptions.ShippingServicePriority = 1;
shippingOptions.Add(domesticShippingOptions);
ShippingServiceOptionsType internationalShippingOptions = new ShippingServiceOptionsType();
InternationalShippingServiceOptionsType internationalShippingOptions = new InternationalShippingServiceOptionsType();
internationalShippingOptions.ShippingService = ShippingServiceCodeType.StandardInternational.ToString();
internationalShippingOptions.ShipToLocation.Add("Worldwide");
internationalShippingOptions.FreeShipping = true;
sd.InternationalShippingServiceOption = new InternationalShippingServiceOptionsTypeCollection(new InternationalShippingServiceOptionsType[] { internationalShippingOptions });
sd.ShippingServiceOptions = shippingOptions;
return sd;
}
Here is the code to make it say "Free Standard Intl Shipping". At first in the sandbox it says "Free Standard Shipping" but if you change the shipping destination in the sandbox it will say "Free Standard Intl Shipping".
static ShippingDetailsType BuildShippingDetails()
{
// Shipping details
ShippingDetailsType sd = new ShippingDetailsType();
sd.ApplyShippingDiscount = true;
sd.PaymentInstructions = "eBay .Net SDK test instruction.";
sd.ShippingRateType = ShippingRateTypeCodeType.StandardList;
// Shipping type and shipping service options
//adding international shipping
InternationalShippingServiceOptionsType internationalShipping1 = new InternationalShippingServiceOptionsType();
internationalShipping1.ShippingService = ShippingServiceCodeType.StandardInternational.ToString();
internationalShipping1.ShippingServiceCost = new AmountType { Value = 0, currencyID = CurrencyCodeType.USD };
internationalShipping1.ShippingServicePriority = 1;
internationalShipping1.ShipToLocation = new StringCollection(new[] { "Worldwide" });
sd.ShippingServiceUsed = ShippingServiceCodeType.StandardInternational.ToString();
sd.InternationalShippingServiceOption = new InternationalShippingServiceOptionsTypeCollection(new[] { internationalShipping1 });
//adding domestic shipping
ShippingServiceOptionsType domesticShipping1 = new ShippingServiceOptionsType();
domesticShipping1.ShippingService = ShippingServiceCodeType.ShippingMethodStandard.ToString();
domesticShipping1.ShippingServiceCost = new AmountType { Value = 0, currencyID = CurrencyCodeType.USD };
domesticShipping1.ShippingInsuranceCost = new AmountType { Value = 0, currencyID = CurrencyCodeType.USD };
domesticShipping1.ShippingServicePriority = 4;
domesticShipping1.LocalPickup = true;
domesticShipping1.FreeShipping = true;
sd.ShippingServiceOptions = new ShippingServiceOptionsTypeCollection(new[] { domesticShipping1 });
sd.ShippingType = ShippingTypeCodeType.Flat;
return sd;
To call the method:
item.ShippingDetails = BuildShippingDetails();
I am using QLNet for american option pricing, but it doesn't work.
i have posted my question on Quantlib forum
my code:
todaysDate & settlementdate = 2012-12-18, maturity = 2013-01-18,
Calendar calendar = new TARGET();
Settings.setEvaluationDate(TodaysDate);
DayCounter dayCounter = new Actual365Fixed();
Handle<Quote> underlyingH = new Handle<Quote>(new SimpleQuote(100));
var flatTermStructure = new Handle<YieldTermStructure>(new FlatForward(SettlementDate, 0.08, dayCounter));
var flatDividendTS = new Handle<YieldTermStructure>(new FlatForward(SettlementDate, 0, dayCounter));
var flatVolTS = new Handle<BlackVolTermStructure>(new BlackConstantVol(SettlementDate, calendar, 0.2, dayCounter));
StrikedTypePayoff payoff = new PlainVanillaPayoff(Call, 101);
var bsmProcess = new BlackScholesMertonProcess(underlyingH, flatDividendTS, flatTermStructure, flatVolTS);
Exercise exerciseEngine = exerciseEngine = new AmericanExercise(SettlementDate, Maturity);
VanillaOption optionEngine = new VanillaOption(payoff, exerciseEngine);
optionEngine.setPricingEngine(new BinomialVanillaEngine<CoxRossRubinstein>(bsmProcess, 801));
//error:
optionEngine.impliedVolatility(optionEngine.NPV(), bsmProcess, 1.0e-4, 100, 1.0e-7, 4.0);
underlying = 100, k=101, i=0.08, vol=0.2,div=0,
todaysDate & settlementdate = 2012-12-18, maturity = 2013-01-18,
In VanillaOption.cs, the code of case Exercise.Type.American is uncomment;
The error message is: An item with the same key has already been added.
at line 111 (results.additionalResults.Add priceCurve, prices_) in FDStepConditionEngine.cs
Thanks for kindly help.
Does anyone know how to do this?
I'm using EPPlus in .Net and have created a pivot table with 2 row fields and one summary datafield:
Dim Pivot As OfficeOpenXml.Table.PivotTable.ExcelPivotTable
Pivot = wksPivot.PivotTables.Add(wksPivot.Cells("A1"), Datarange, "pName")
Pivot.RowFields.Add(Pivot.Fields("Fld1")).Sort = Table.PivotTable.eSortType.Ascending
Pivot.RowFields.Add(Pivot.Fields("Fld2")).Sort = Table.PivotTable.eSortType.Ascending
Dim dtaFld As OfficeOpenXml.Table.PivotTable.ExcelPivotTableDataField
dtaFld = Pivot.DataFields.Add(Pivot.Fields("XYZ"))
dtaFld.Function = Table.PivotTable.DataFieldFunctions.Sum
Everything works great, but I want to have the Pivot Table start off as collapsed when the user opens the workbook (In excel, when you're creating the pivot table, you can right-click in the data element and select "Expand / Collapse" > "Collapse Entire Field"
Hot can I do this via code?? (And I'm willing to use direct OpenXML if EPPlus doesn't support this yet...)
ALSO, is there a way to delete out the Raw data from the workbook so that the pivot table still works? i've tried and when I open the workbook, my pivot table is blank? - My current logic has led me to this question... Any thoughts??
(I do know I wrote this question in VB. but I added both the C# & VB tags to this question - I'm comfortable with code in either language - Thanks!!)
Could make it xlsm and add vba to it. This is probably the worst answer to this solution but it achives full collapse. I have provided a working example, just copy past into a new console app. add the epplus dependency, "F5".
modified/taken from http://epplus.codeplex.com/SourceControl/latest#SampleApp/Sample15.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OfficeOpenXml.Table;
using OfficeOpenXml.Table.PivotTable;
using OfficeOpenXml;
using System.IO;
namespace pTable
{
class Program
{
static void Main(string[] args)
{
//ExcelPackage _pck = new ExcelPackage();
Directory.CreateDirectory(string.Format("Test"));
//ExcelPackage _pck = new ExcelPackage(new FileInfo("Test\\Worksheet.xlsx"));
ExcelPackage _pck = new ExcelPackage(new FileInfo("Test\\Worksheet.xlsm"));
var wsPivot1 = _pck.Workbook.Worksheets.Add("Rows-Data on columns");
var ws = _pck.Workbook.Worksheets.Add("Data");
ws.Cells["K1"].Value = "Item";
ws.Cells["L1"].Value = "Category";
ws.Cells["M1"].Value = "Stock";
ws.Cells["N1"].Value = "Price";
ws.Cells["O1"].Value = "Date for grouping";
ws.Cells["K2"].Value = "Crowbar";
ws.Cells["L2"].Value = "Hardware";
ws.Cells["M2"].Value = 12;
ws.Cells["N2"].Value = 85.2;
ws.Cells["O2"].Value = new DateTime(2010, 1, 31);
ws.Cells["K3"].Value = "Crowbar";
ws.Cells["L3"].Value = "Hardware";
ws.Cells["M3"].Value = 15;
ws.Cells["N3"].Value = 12.2;
ws.Cells["O3"].Value = new DateTime(2010, 2, 28);
ws.Cells["K4"].Value = "Hammer";
ws.Cells["L4"].Value = "Hardware";
ws.Cells["M4"].Value = 550;
ws.Cells["N4"].Value = 72.7;
ws.Cells["O4"].Value = new DateTime(2010, 3, 31);
ws.Cells["K5"].Value = "Hammer";
ws.Cells["L5"].Value = "Hardware";
ws.Cells["M5"].Value = 120;
ws.Cells["N5"].Value = 11.3;
ws.Cells["O5"].Value = new DateTime(2010, 4, 30);
ws.Cells["K6"].Value = "Crowbar";
ws.Cells["L6"].Value = "Hardware";
ws.Cells["M6"].Value = 120;
ws.Cells["N6"].Value = 173.2;
ws.Cells["O6"].Value = new DateTime(2010, 5, 31);
ws.Cells["K7"].Value = "Hammer";
ws.Cells["L7"].Value = "Hardware";
ws.Cells["M7"].Value = 1;
ws.Cells["N7"].Value = 4.2;
ws.Cells["O7"].Value = new DateTime(2010, 6, 30);
ws.Cells["K8"].Value = "Saw";
ws.Cells["L8"].Value = "Hardware";
ws.Cells["M8"].Value = 4;
ws.Cells["N8"].Value = 33.12;
ws.Cells["O8"].Value = new DateTime(2010, 6, 28);
ws.Cells["K9"].Value = "Screwdriver";
ws.Cells["L9"].Value = "Hardware";
ws.Cells["M9"].Value = 1200;
ws.Cells["N9"].Value = 45.2;
ws.Cells["O9"].Value = new DateTime(2010, 8, 31);
ws.Cells["K10"].Value = "Apple";
ws.Cells["L10"].Value = "Groceries";
ws.Cells["M10"].Value = 807;
ws.Cells["N10"].Value = 1.2;
ws.Cells["O10"].Value = new DateTime(2010, 9, 30);
ws.Cells["K11"].Value = "Butter";
ws.Cells["L11"].Value = "Groceries";
ws.Cells["M11"].Value = 52;
ws.Cells["N11"].Value = 7.2;
ws.Cells["O11"].Value = new DateTime(2010, 10, 31);
ws.Cells["O2:O11"].Style.Numberformat.Format = "yyyy-MM-dd";
var pt = wsPivot1.PivotTables.Add(wsPivot1.Cells["A1"], ws.Cells["K1:N11"], "Pivottable1");
pt.Compact = true;
pt.CompactData = true;
pt.GrandTotalCaption = "Total amount";
pt.RowFields.Add(pt.Fields[1]);
pt.RowFields.Add(pt.Fields[0]);
pt.DataFields.Add(pt.Fields[3]);
pt.DataFields.Add(pt.Fields[2]);
pt.DataFields[0].Function = DataFieldFunctions.Product;
pt.DataOnRows = false;
_pck.Workbook.CreateVBAProject();
var sb = new StringBuilder();
sb.AppendLine("Private Sub Workbook_Open()");
sb.AppendLine(" Range(\"A1\").Select");
sb.AppendLine(" ActiveSheet.PivotTables(\"Pivottable1\").PivotFields(\"Category\").PivotItems(\"Hardware\").ShowDetail = False");
sb.AppendLine("End Sub");
_pck.Workbook.CodeModule.Code = sb.ToString();
_pck.Save();
}
}
}
Using EPPlus you could try something like (Taken from this SO post):
(from pf in pivot.Fields
select pf).ToList().ForEach(f =>
{
f.Compact = false;
f.Outline = false;
});
or perhaps more simply, doesn't something like the following work?
pvtTable.Compact = False
pvtTable.CompactData = False
pvtTable.Outline = False
pvtTable.OutlineData = False
pvtTable.ShowDrill = True
Also look at this SO post detailing a nice reverse engineer method for seeing how excel achieves 'things'.
P.S. Can't help you with your other 'also' question sorry.
b2bHotelSOAPService objsoap = new b2bHotelSOAPService();
objsoap.Timeout = 20000;
objsoap.Url = "http://api.hotelspro.com/4.1_test/hotel/b2bHotelSOAP.wsdl";
string apiKey = Connection.AppSettings("APIKey");
string destinationId = "LD6J";
DateTime checkIn = new DateTime(2012, 7, 20);
DateTime checkOut = new DateTime(2012, 7, 22);
string strCurrencyCode = "EUR";
pax[][]rooms=new pax[3][];
rooms[0] = new pax[3];
rooms[0][0] = new pax();
rooms[0][1] = new pax();
rooms[0][2] = new pax();
rooms[0][0].paxType = "Adult";
rooms[0][1].paxType="Adult";
rooms[0][2].paxType="Child";
rooms[0][2].age = "6";
filter[] f = new filter[1];
f[0] = new filter();
f[0].filterType = "hotelStar";
f[0].filterValue = "3";
getAvailableHotelResponse getres = new getAvailableHotelResponse();
getres = objsoap.getAvailableHotel(apiKey, destinationId, checkIn, checkOut, strCurrencyCode, "UK", true, rooms, f);
this code throwing following error :
Client found response content type of 'application/wsdl+xml', but expected 'text/xml'.
The request failed with the error message:
If you open the WSDL in a text editor, you will find the address of the web service that you want to call
<soap:address location="http://api.hotelspro.com/4.1_test/hotel/b2bHotelSOAP.php"/>
So you'll want to change the URL that you're calling.
objsoap.Url = "http://api.hotelspro.com/4.1_test/hotel/b2bHotelSOAP.php";
The .WSDL address that you were calling is what lets .NET figure out the classes to generate, but the actual call is to the web service which is the .PHP address above.