This is how I tried to solve this in the loading event for the form:
DateTime pubDate = DateTime.Now;
DateTime formDate = DateTime.Now;
XPathNavigator priceBookDate = null;
//First we want to connect to the datasource GetPriceBookDate that only returns the latest publishing
//date for the PriceBook.
try
{
WebServiceConnection wsc = (WebServiceConnection)this.DataSources["GetPriceBookDate"].QueryConnection;
wsc.Execute();
XPathNavigator GetPriceBookDate = this.DataSources["GetPriceBookDate"].CreateNavigator();
priceBookDate = GetPriceBookDate.SelectSingleNode("/dfs:myFields/dfs:dataFields/tns:GetPriceBookDateResponse/tns:GetPriceBookDateResult", this.NamespaceManager);
//Get the date for the latest published pricebook
if (!String.IsNullOrEmpty(priceBookDate.Value))
{
pubDate = Convert.ToDateTime(priceBookDate.Value);
}
}
catch
{
}
//Here we want to work against the cached data for the datasource GetPriceBook that contains the whole PriceBook
//This doesn't work if we are in online mode.
XPathNavigator GetPriceBook = this.DataSources["GetPriceBook"].CreateNavigator();
//Get the cached date.
XPathNavigator formPriceBookDate = GetPriceBook.SelectSingleNode("/dfs:myFields/dfs:dataFields/tns:GetPriceBookResponse/tns:GetPriceBookResult/tns:PublishingDate", this.NamespaceManager);
if (priceBookDate != null)
{
//Get the date for the latest publised pricebook that was cached in the form
if (!String.IsNullOrEmpty(formPriceBookDate.Value))
formDate = Convert.ToDateTime(formPriceBookDate.Value);
//Give the user an option to download a new pricebook if there is a newer version
//published or if the user hasn't a PriceBook cached
if ((formDate < pubDate) || String.IsNullOrEmpty(formPriceBookDate.Value))
{
DialogResult result = MessageBox.Show("There is a new Price Book available. Do you want to download the new Price Book? ", null, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
if (result == DialogResult.Yes)
{
WebServiceConnection wscPB = (WebServiceConnection)this.DataSources["GetPriceBook"].QueryConnection;
wscPB.Timeout = 1000;
wscPB.Execute();
}
}
}