This blog will discuss features about .NET, both windows and web development.
You may get an error like the one above appear with a System.Data.UpdateException type. This exception actually comes from the database, and is wrapped by the entity framework library. The error stems from the fact that SQL Server has an entity with a not null datetime (not datetime2, but the "old-school" datetime property), and no date was supplied to the EntityObject entity. In .NET, a default date ignores whatever SQL Server may use as a minimum, and supply a 1/1/0001 date (the value of DateTime.MinValue), a value far short of the minimum value of 1/1/1753 that SQL Server expects.
The easy way to find out is before savechanges() is called, use the watch window to examine all of the properties of the object, and look for the 1/1/0001 date. It's usually pretty easy to find that way..
The latest release of Telerik's RadControls framework for ASP.NET AJAX has a really cool feature: RadCompression. Telerik provides a HTTP module that compresses your JavaScript files, Silverlight applications, and AJAX/web service requests. While it may not work with every request (it doesn't support web service page methods and it doesn't support certain application types), it does work really well in what it does.
We added this to our application in our development environment, and noticed that it did improve the web site speed on our local machine by up to 20% (as a rough estimate from visual tests and not actually performing benchmarking).
It's very easy to add; all you need to do is add the reference to the module in the config file, as documented here:
Looking at the MSDN documentation for the events pertaining to Sys.UI.DataView, I noticed that it lacked in comparison to the CHM file that comes with the MS AJAX 4.0 Preview 5 download. One of these events is the rendered event, which fires at the end of the binding (itemRendered fires for each rendered item). The rendered event is a great way to apply any view-wide operations using JQuery in one single shot.
For instance, if your view renders div elements with a specific class:
<ul .. <li> <span class="HeaderTemplate">Header</span> <div> <!-- related panel --></div> </li></ul>
Using jquery you could write some code to target every instance of this like:
view.add_rendered(function(sender, e) { $("span.HeaderTemplate + div").hide(); $("span.HeaderTemplate").click(function() { $(this).toggle("slide", {direction: "down"}, 500); });});
Note that the use of toggle requires the JQuery UI library. The first statements finds every DIV that occurs after a SPAN.HeaderTemplate element. The hide() method hides this immediately. Following this, the click method adds a click event handler to the header to show/hide the div's below it. This makes for an easy collapsible panel.
I been thinking about when I should differentiate between methods and properties. For instance, suppose that I have the following class:
public class OrderProcessor{ public bool RoundToNearestCent { get; set; } public bool RoundDown { get; set; }}
This class has two boolean properties, and you would use this class like so:
var o = new OrderProcessor();o.RoundToNearestCent = true;o.RoundDown = false;
o.DoSomething();
When designing software, you have to think about the accessibility of a class's members. We have two properties that are accessible at any time and can be changed independently. While this may be a bad example to explain for what I'm going to illustrate, you have to decide whether to allow the properties to be edited independently or not. For instance, if we were to change the class to this:
public class OrderProcessor
{
public bool RoundToNearestCent { get; private set; }
public bool RoundDown { get; private set; }
public void SetRoundingRules(bool nearestCent, bool roundDown) { .. }
}
Now we have a single method that does the work, and will do the work of setting the properties. The consumer will no longer be able to set the properties in this manner. While it may not be the best example, it illustrates how you can constrol the flow of using your components. Instead of potentially setting one of the properties, the user has to call the method and specify all the settings at one time, instead of individually.
This can be more useful when you need to guarantee that a method has been called. For instance, if adding a Process() method, the process method can ensure that the SetRoundingRules method has been called through a variable, as shown below.
public class OrderProcessor
{ private bool _hasSetRoundingRules = false;
public bool RoundToNearestCent { get; private set; }
public bool RoundDown { get; private set; }
public void SetRoundingRules(bool nearestCent, bool roundDown) { _hasSetRoundingRules = true; . .
} public void Process() { if (!_hasSetRoundingRules) throw new Exception(); . . }}
This can also be done using properties, if the properties use the bool? type instead of bool. That way if neither value has a value (is null), an exception can be thrown. Though this type of logic is much easier to implement with a method.
I recently have been thinking about tabular displays and how to make them better. For instance, suppose that your final output of an application looked like the following:
<table id="tbl"> <thead> <tr> <th>One Header</th> <th>Two Header</th> <th>Three Header</th> <th>Four Header</th> <th>Five Header</th> <th>Six Header</th> <th>Seven Header</th> <th>Eight Header</th> </tr> </thead> <tbody> <tr> <td>Value</td> <td>Value</td> <td>Value</td> <td>Value</td> <td>Value</td> <td>Value</td> <td>Value</td> <td>Value</td> </tr> <tr> <td>Value</td> <td>Value</td> <td>Value</td> <td>Value</td> <td>Value</td> <td>Value</td> <td>Value</td> <td>Value</td> </tr> . . . .
</table>
Imagine this is for a form of some sort. Think in reverse of a GridView control in ASP.NET; the GridView control renders a dynamic number of rows; this example is more suited for an application you may build that is columns-based, say to render a comparison between products, or maybe the headers a representative of people, and the rows contains some attributes about them (name, height, weight, and other stats).
So, this example using JavaScript and JQuery is meant to enable a new way of paging columns-based data; however, it could be adapted to page row-based data. Now, if you have a lot of data in the column-based form, it will force a horizontal scrollbar, something that is against standards in most organizations (and is not a preferred approach anyway unless culturally significant). To offset this, the script I'm about to show you will show only 4 columns at a time, allowing the user to page left/right. To do this, I will use a looping construct to loop through the columns and rows to change visibility. The script looks like:
<script type="text/javascript"> var leftColumn = 0; var columnCount = 4;
$(document).ready(function() { var t = $("#tbl"); $("#output").html(t.outerWidth().toString() + ", " + t.outerHeight().toString()); refresh(); }); function refresh() { var table = $("#tbl")[0]; var headerRow = tbl.getElementsByTagName("THEAD")[0].rows[0]; var rightColumn = leftColumn + columnCount; if (leftColumn <= 0) leftColumn = 0; if (leftColumn >= headerRow.cells.length - 3) leftColumn--; for (var r = 0, rlen = table.rows.length; r < rlen; r++) { for (var c = 0, clen = headerRow.cells.length; c < clen; c++) { table.rows[r].cells.style.display = ((leftColumn <= c && c < rightColumn) ? "table-cell" : "none"); } } }</script>
To begin, to figure out which 4 columns to show is determined by the leftColumn variable; it stores the current column index of the far left visible column. The column count stores the number of columns to display, so that is configurable and can be something other than 4 columns. When the document loads (using JQuery's document ready event), the UI initializes to show the 4 columns. The refresh method actually shifts the columns, and it does this using math.
The THEAD definition is special, because that is the easy way to figure out how many columns their are; there isn't any explicit way to figure columns (unless a COLGROUP is specified); so the header easily figures out there are 8 columns available. Two loops take place; first, it loops through each row to show/hide the appropriate cells, while the rest get hidden. It iterates through the rows first, then the columns, and changes the display accordingly.
To page, I included two buttons that will page left/right. You may have notice the if checkes in the previous JS code; it simply ensures the paging isn't out of the valid range of values.
<button id="navleft">Move Left</button><button id="navright">Move Right</button>
JQuery hooks up to the click event, and refreshes the UI after it increments or decrements the left column index.
$("#navleft").click(function() { leftColumn--; refresh(); }); $("#navright").click(function() { leftColumn++; refresh(); });
And that is all that it takes to use JavaScript, and JQuery (even if I don't fully take advantage of it) to create a way to page columns of a table. It works really well and is fast.).
Link to us
All material is copyrighted by its respective authors. Site design and layout
is copyrighted by DotNetSlackers.
Advertising Software by Ban Man Pro