1

Open XML – OLE Automation Date Issues

Posted by Tim on Jul 26, 2010 in .NET Framework, C#

If you are exporting a date from C# to Excel using 2007, you probably will use the following:

Math.Round(DateTime.Now.ToOADate(), 12).ToString()

This exports the date as a OLE Automation date recognized by Excel 2007. How ever, in Excel 2010 this was causing issues, every time I exported to Excel 2010, it said that it has to repair my document and it never displayed the values correctly as dates.

Because I was using Open XML to generate the markup, Excel 2010 has been support for Open XML. I got around the problem of using:

DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffffffzzz");

This exports the date as a XML Date format.
Hope this helps anyone who has the same problem!

Tags: , , ,

 
0

New Photo – CheckoutChristchurch.co.nz south by the Church of Good Shepard

Posted by Tim on Jul 23, 2010 in News, Uncategorized

CheckoutChristchurch south on Lake Tekapo by the Church of Good Shepard!

Tags:

 
1

PRODUCT OF THE WEEK – CAR FIRST AID KIT

Posted by Tim on Jul 22, 2010 in News, Uncategorized

PRODUCT OF THE WEEK: Car First Aid Kit – Perfect kit for the car for any unexpected accidents on the road! Includes plasters, saline, CPR mask plus more..perfect if you are traveling up the snow this winter!

http://www.medicsafe.co.nz/car-fa-kit-soft-pack

Tags:

 
0

Auckland 2011 Website Hickups!

Posted by Tim on Jul 14, 2010 in News

Auckland 2011 Website isn’t too bad but it has a few design flaws! Can you spot them? This appears across all browsers, look closely where the Visitor Services text is.

 
0

EF Strongly Typed ObjectQuery.Include

Posted by Tim on Jul 13, 2010 in .NET Framework, C#

The problem that I faced was having to put up with “hard coded” strings in the ObjectQuery.Include function to load related objects through POCO objects in the Entity Framework. This faced challenges when I renamed columns in the Model which caused a run-time error when recompiling and re-starting the application. Thanks to David Kiff, we can now change the code from being strings:

using (CommuicationsEntities entities = new CommuicationsEntities())
{
entities.Order.Include("OrderDetails");
}

To a nice strongly typed includes using a IncludeBuilder class.

public class IncludeBuilder
{
private readonly List _propertiesToInclude;

public IncludeBuilder()
{
_propertiesToInclude = new List();
}

public void Add(Expression<Func<T, object>> propertySelector)
{
MemberExpression memberExpression = propertySelector.Body as MemberExpression;
if (memberExpression == null)
throw new ArgumentException("Parameter propertySelector must be a MemberExpression");
_propertiesToInclude.Add(memberExpression.Member.Name);
}

public ObjectQuery Includes(ObjectQuery query)
{
foreach (string include in _propertiesToInclude)
{
query = query.Include(include);
}
return query;
}
}

the following code calls the include builder, includes the relationship and gets a simple list with no tracking on the POCO objects.

IncludeBuilder _include = new IncludeBuilder();
_include.Add(a => a.Orders);
ObjectQuery customers= DataContext.Servers;
return _include.Includes(customers).Execute(MergeOption.NoTracking).ToList();

References:

http://davidkiff.co.uk/post/2009/08/27/EF-Strongly-Typed-ObjectQuery3cT3eInclude%28e2809ce2809d%293b.aspx

Tags: ,

 
0

Fixing the EF Tracing and Caching Provider Wrapper Issue

Posted by Tim on Jul 9, 2010 in .NET Framework, C#

If you have been using the Tracing and Caching Provider Wrappers for the ADO.NET Entity Framework 4.0, you might of come across this error message when creating POCO objects, adding them to a Data Context and commiting them to the database using the Caching Wrapper:

[NotImplementedException: The method or operation is not implemented.]
   EFCachingProvider.EFCachingDataReaderCacheWriter.GetName(Int32 ordinal) in EFCachingProvider\EFCachingDataReaderCacheWriter.cs:109
   System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues) +8118458
   System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter) +267

Line 107:        public override string GetName(int ordinal)
Line 108:        {
Line 109:            throw new NotImplementedException();
Line 110:        }
Line 111:

Basically, the author’s of the code have created a wrapper for the DBDataReader class and have not implement the override methods.   This can be fixed by calling the Wrapper DataReader object methods.  This is what I have modified in the EFCachignDataReaderCacheWriter.cs file:

using System;
using System.Data;
using System.Data.Common;
using EFCachingProvider.Caching;

namespace EFCachingProvider
{
///
/// Implementation of the  which reads the results of another data reader
/// and stores a copy in the cache.
///
internal class EFCachingDataReaderCacheWriter : EFCachingDataReaderBase
{
private DbQueryResults queryResults = new DbQueryResults();
private DbDataReader wrappedReader;
private int maxRows;
private Action addToCache;

///
/// Initializes a new instance of the EFCachingDataReaderCacheWriter class.
///
///
<span> </span>The wrapped reader.         ///
<span> </span>The maximum number of rows which can be cached.         ///
The delegate used to add the result to the cache when the reader finishes.         public EFCachingDataReaderCacheWriter(DbDataReader wrappedReader, int maxRows, Action addToCache)
{
this.wrappedReader = wrappedReader;
this.addToCache = addToCache;
this.maxRows = maxRows;
}

///
/// Gets a value that indicates whether this  contains one or more rows.
///
///
/// true if the  contains one or more rows; otherwise false.
///
public override bool HasRows
{
get { return this.wrappedReader.HasRows; }
}

///
/// Gets the number of rows changed, inserted, or deleted by execution of the SQL statement.
///
///
///
/// The number of rows changed, inserted, or deleted. -1 for SELECT statements; 0 if no rows were affected or the statement failed.
///
public override int RecordsAffected
{
//get { throw new NotImplementedException(); }
get { return this.wrappedReader.RecordsAffected; }
}

///
/// Gets a value indicating whether the  is closed.
///
///
/// true if the  is closed; otherwise false.
///
public override bool IsClosed
{
//get { throw new NotImplementedException(); }
get { return this.wrappedReader.IsClosed; }
}

///
/// Gets a value indicating the depth of nesting for the current row.
///
///
///
/// The depth of nesting for the current row.
///
public override int Depth
{
//get { throw new NotImplementedException(); }
get { return this.wrappedReader.Depth; }
}

///
/// Gets name of the data type of the specified column.
///
///
The zero-based column ordinal.         ///
/// A string representing the name of the data type.
///
public override string GetDataTypeName(int ordinal)
{
//throw new NotImplementedException();
return this.wrappedReader.GetDataTypeName(ordinal);
}

///
/// Gets the data type of the specified column.
///
///
The zero-based column ordinal.         /// The data type of the specified column.
public override Type GetFieldType(int ordinal)
{
return this.wrappedReader.GetFieldType(ordinal);
}

///
/// Gets the name of the column, given the zero-based column ordinal.
///
///
The zero-based column ordinal.         /// The name of the specified column.
public override string GetName(int ordinal)
{
return this.wrappedReader.GetName(ordinal);
}

///
/// Gets the column ordinal given the name of the column.
///
///
The name of the column.         /// The zero-based column ordinal.
///
/// The name specified is not a valid column name.
///
public override int GetOrdinal(string name)
{
return this.wrappedReader.GetOrdinal(name);
}

///
/// Returns a  that describes the column metadata of the .
///
///
/// A  that describes the column metadata.
///
public override DataTable GetSchemaTable()
{
return this.wrappedReader.GetSchemaTable();
}

///
/// Advances the reader to the next result when reading the results of a batch of statements.
///
///
/// true if there are more result sets; otherwise false.
///
public override bool NextResult()
{
if (this.wrappedReader.NextResult())
{
this.queryResults = null;
return true;
}
else
{
return false;
}
}

///
/// Closes the  object.
///
public override void Close()
{
this.wrappedReader.Close();

if (this.queryResults != null)
{
this.addToCache(this.queryResults);
}
}

///
/// Advances the reader to the next record in a result set.
///
///
/// true if there are more rows; otherwise false.
///
public override bool Read()
{
if (this.wrappedReader.Read())
{
object[] values = new object[this.wrappedReader.FieldCount];

this.wrappedReader.GetValues(values);
SetValues(values);
if (this.queryResults != null)
{
this.queryResults.Rows.Add(values);
if (this.queryResults.Rows.Count &gt; this.maxRows)
{
this.queryResults = null;
}
}

return true;
}
else
{
return false;
}
}
}
}

Tags: , ,

 
0

CheckoutChristchurch – What not to check out??

Posted by Tim on Jul 4, 2010 in News

Here is a picture that was taken from outside Timaru..perhaps this picture has failed?

www.checkoutchristchurch.co.nz

Tags:

 
0

CheckoutChristchurch has a new pic! Clock Tower

Posted by Tim on Jul 1, 2010 in News

Visit http://www.checkoutchristchurch.co.nz to see the Victoria Street Clock Tower in Christchurch!

www.checkoutchristchurch.co.nz is powered by jquery, flickr and a twitter feed!

Tags:

 
1

Detect when a session has ended ASP.NET

Posted by Tim on Jun 30, 2010 in .NET Framework, ASP.NET, Visual Basic

A problem that I have had in the past is trying to find out when a session has expired within ASP.NET and how to deal with the expired session.   One solution is to add the following code into the Page_Init event.   You can add this event into a class that inherits the Page class so that you can reuse on more than one page or all pages if needed.

If Not Context.Session Is Nothing Then
If Session.IsNewSession Then
Dim szCookieHeader As String = Request.Headers("Cookie")
If Not String.IsNullOrEmpty(szCookieHeader) And szCookieHeader.IndexOf("ASP.NET_SessionId") &gt;= 0 Then
Response.Redirect("/sessiontimeoutpage.aspx")
End If
End If
End If

This code checks if a new session has been created and if the header has a ASP.NET Session id.   This makes sure that we are checking for a session that has just been created.

Tags: ,

 
0

Techxplosion.net is live!

Posted by Tim on Jun 24, 2010 in News, Uncategorized

A group of us have been working on creating a new tech, geek, gadget site which includes news on the latest trends of all types of technology including mobile devices, smart phones, computers and a whole lot more!   A special thanks to Andy at GT Solutions (www.ghozali.net), Seruni at Madcow Solutions and all the guys who put the effort into making this site great!

Check it out today!

Copyright © 2008-2010 Tim's CodeLab Blog All rights reserved.
Desk Mess Mirrored v1.6 theme from BuyNowShop.com.