Cast OData Date to Standard Javascript Date Time
Posted by rangerwez in Uncategorized on March 26, 2013
Thank you to Rajeev Pentyala for this solution (link)
The CRM DateTime value is returned from an OData call as a Edm.DateTime … which is of format “/Date(1314763200000)/” … that’s really not of use to me in Javascript.
The following code (Rajeev developed) converts this really nicely;
var dt = THE_EDM_DATETIME; dt = dt.replace(“/Date(“, “”); dt = dt.replace(“)/”, “”); var dateValue = new Date(parseInt(dt, 10));
Adding a Custom Font Face on Your Website
Posted by rangerwez in Uncategorized on January 18, 2013
One of the things on the web for quite some time is being limited to the fonts available.
Just a few basics fonts are available:
From http://www.ampsoft.net/webdesign-l/WindowsMacFonts.html
| Normal style | Bold style |
|---|---|
| Arial, Arial, Helvetica, sans-serif | Arial, Arial, Helvetica, sans-serif |
| Arial Black, Arial Black, Gadget, sans-serif | Arial Black, Arial Black, Gadget, sans-serif |
| Comic Sans MS, Comic Sans MS5, cursive | Comic Sans MS, Comic Sans MS5, cursive |
| Courier New, Courier New, monospace | Courier New, Courier New, monospace |
| Georgia1, Georgia, serif | Georgia1, Georgia, serif |
| Impact, Impact5, Charcoal6, sans-serif | Impact, Impact5, Charcoal6, sans-serif |
| Lucida Console, Monaco5, monospace | Lucida Console, Monaco5, monospace |
| Lucida Sans Unicode, Lucida Grande, sans-serif | Lucida Sans Unicode, Lucida Grande, sans-serif |
| Palatino Linotype, Book Antiqua3, Palatino, serif | Palatino Linotype, Book Antiqua3, Palatino, serif |
| Tahoma, Geneva, sans-serif | Tahoma, Geneva, sans-serif |
| Times New Roman, Times New Roman, Times, serif | Times New Roman, Times New Roman, Times, serif |
| Trebuchet MS1, Trebuchet MS, sans-serif | Trebuchet MS1, Trebuchet MS, sans-serif |
| Verdana, Verdana, Geneva, sans-serif | Verdana, Verdana, Geneva, sans-serif |
| Symbol, Symbol (Symbol2, Symbol2) | Symbol, Symbol (Symbol2, Symbol2) |
| Webdings, Webdings (Webdings2, Webdings2) | Webdings, Webdings (Webdings2, Webdings2) |
| Wingdings, Zapf Dingbats (Wingdings2, Zapf Dingbats2) | Wingdings, Zapf Dingbats (Wingdings2, Zapf Dingbats2) |
| MS Sans Serif4, Geneva, sans-serif | MS Sans Serif4, Geneva, sans-serif |
| MS Serif4, New York6, serif | MS Serif4, New York6, serif |
There may not be a font that you want to use … easy enough to help with that.
You can use a site like Font Squirrel and download a font face to use.
@charset 'utf-8';
@font-face
{
font-family: {name of font};
src: url({location of font});
}
body
{
font-family: {name of font};
}
Or you can use a site link Google Fonts. Google provides multiple ways to include the font into your page via standard text/css stylesheet, @import to your stylesheet, or via Javasscript directly.
Stored Procedure Parsing
Posted by rangerwez in Uncategorized on January 16, 2013
“Find all the stored procedures that contain cursors”
“Do any of the stored procedures have temporary tables”
“Have you used function xyz in any of the procedures”
This is a difficult; I have a site that has over 600 stored procedures, and I recently needed to change a type of a major field in a table. I need to find all the stored procedures that access this field and make sure that the type is correct.
In SQL Server, use the following command filling in MY_SEARCH appropriately. This will return to you all the stored procedures that contain your search terms.
For shorter than 4000 character stored procedures, this is fine
SELECT ROUTINE_NAME, ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%MY_SEARCH%'
AND ROUTINE_TYPE='PROCEDURE'
This route is better and removes the 4000 character limitation
SELECT OBJECT_NAME(object_id), OBJECT_DEFINITION(object_id) FROM sys.procedures WHERE OBJECT_DEFINITION(object_id) LIKE '%MY_SEARCH%'
Quick reminder on how to create an XML file in C#
Posted by rangerwez in Uncategorized on December 27, 2012
1) Declare the XML document
XmlDocument xmlDoc = new XmlDocument();
2) Add the XML Declaration Statement
XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0","utf-8",null);
xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
3) Create the Root Elements can be done in two different ways
- First way utilites the CreateElement function
XmlElement rootNode = xmlDoc.CreateElement("Family");
xmlDoc.AppendChild(rootNode);
- Second way is more gritty with a string
string documentStart = "<Family></Family>"; xmlDocument.Load(new StringReader(documentStart));
4) Create Parent and Child Elements
XmlElement parentNode = xmlDoc.CreateElement("Parent");
XmlElement childNode = xmlDoc.CreateElement("Child");
parentNode.AppendChild(childName);
Timing T-SQL
Posted by rangerwez in Uncategorized on December 20, 2012
So my client asked me to remove all the stored procedure and temp table calls from my code to move toward just using functions (which I wanted to use in the first place but they hadn’t give me “create function” rights).
After converting my code to use just functions, it made me wonder which was faster, and I didn’t want to pull out SQL Profiler … I wondered if I could do it in SQL Management Studio directly writing some T-SQL and I came across this website:
http://sqlserver2000.databases.aspfaq.com/how-do-i-time-my-t-sql-code.html
That was nice and simple … exactly what I needed
DECLARE @a DATETIME, @b DATETIME
SET @a = CURRENT_TIMESTAMP
{MY CODE}
SET @b = CURRENT_TIMESTAMP
SELECT DATEDIFF(MS, @a, @b)
It just so happened that most of the time the stored procedure route was actually faster … but added additional querying steps and unnecessary added tables that they didn’t want to do. And they thought it looked messier … the client is always right (so they say) … so functions it is.
C# Bubbling Events
Posted by rangerwez in Uncategorized on December 18, 2012
I need to bubble an event up from one control to another or a top level page in my ASP.NET app … hmmm … how do I do that again.
Way 1: Standard Event
public class MyClass
{
public event EventHandler MyEvent;
}
Way 2: Custom EventArgs
public class MyClass
{
public delegate void MyCustomEventHandler(object sender, MyCustomEventArgs e);
public event MyCustomEventHandler MyEvent;
protected virtual void OnMyCustomEventHandler(object sender, MyCustomEventArgs e)
{
MyCustomEventHandler handler = MyEvent;
if (handler != null) { handler (this, e); }
}
}
// Custom Event Args
public class MyCustomEventArgs : System.EventArgs
{
public string item1 = "";
public string item2 = "";
public MyCustomEventArgs(string i1, string i2)
{
item1 = i1;
item2 = i2;
}
}
jQuery and Telerik RadControls
Posted by rangerwez in Uncategorized on December 17, 2012
We ran into quite an odd issue today at work. We’ve built this webpage that is all AJAX-iffied and such, and found out that any time we would select a drop down list, our help link buttons stopped working.
All the help link buttons are little jQuery elements that are extremely simple:
$('.showHelp').click(function (e) {
e.preventDefault();
ShowHelp();
}
We determined that every time we would cause a postback (albeit a partial one), we would lose the onClick event of the .showHelp classes … found out that neither the UpdatePanel nor Telerik’s RadPanels do this automatically. I figured that something wasn’t initializing on the postback, so after searching for some time I came across the following:
http://encosia.com/document-ready-and-pageload-are-not-the-same/
We ended up with the following:
// Loads on Window Load
$(window).load(function () {
pageLoad();
})
// Loads on Postback
function pageLoad()
{
$('.showHelp').click(function (e)
{
e.preventDefault();
ShowHelp();
}
}
Works perfectly now.