tag:blogger.com,1999:blog-16997153966739092292024-03-11T21:52:20.957-07:00CodefuciusCodefuciushttp://www.blogger.com/profile/13637371019628237927noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-1699715396673909229.post-29113041418535958922016-11-26T06:19:00.004-08:002016-11-26T06:38:21.605-08:00How to create an A0 VM instance on AzureSo I played with Azure hosting today.<br />
You can currently get a free trial and e.g. £125 of credit.<br />
<br />
But I thought I would try a really cheap server £9->£10/month server to play around with - i.e. the "A0" instance, to see what was possible on a low spec vm.<br />
<br />
But, when you create a new VM, the A0 build doesn't seem to be an option.<br />
<br />
So I selected the cheapest option they gave me and tried to resize it.<br />
But that gave an error saying something about it not being available due to premium storage.<br />
<br />
So, what I had to do was delete that VM and all the associated resources. Then:<br />
<br />
1. create a new VM, but make sure you choose "HDD" and not "SSD" for the non-premium storage.<br />
2. choose the A1 size (not the A0 size at this point, that wouldn't come up).<br />
3. wait for it to finish deploying and enter the running state<br />
4. click on the VM and stop it, then wait for it to enter the deallocated state<br />
5. click on "size" for the VN and resize it A0<br />
<br />
Obvious huh?<br />
<br />
An A0 instance is very low spec, so I wouldn't recommend running windows on it due to the UI-heavy interface of windows for administration. Better to run linux, or perhaps try the windows nano server.<br />
Also, be careful of additional costs like storage, you may want to resize them down too, and with all these cloud services, there are plenty of other costs/limits for bandwidth etc. so take a look at your billing daily until you know what's what.<br />
<div>
Currently, if you are on a free trial, then according to an MS post "<span style="background-color: white; color: #292c33; font-family: "segoe ui" , "helveticaneue" , "helvetica" , "tahoma" , "garuda" , "arial" , sans-serif; font-size: 13px;"> </span><span style="background-color: white; color: #292c33; font-family: "segoe ui" , "helveticaneue" , "helvetica" , "tahoma" , "garuda" , "arial" , sans-serif; font-size: 13px;">you will not be charged for your free trial at any point unless you explicitly take the action of upgrading to a paid subscription. If you do nothing, the trial will just end without charging your card." </span></div>
Codefuciushttp://www.blogger.com/profile/13637371019628237927noreply@blogger.com2tag:blogger.com,1999:blog-1699715396673909229.post-24158434352519767432016-06-12T10:20:00.001-07:002016-06-12T10:29:11.119-07:00Route planning, GPX file import, mobile/phone - Tyre and Osmand<b>this is quick, unformatted reminder for me, and hopefully helpful to bikers/car enthusiasts/cyclists and other route planning types.</b><br />
<b><br /></b>
<b>i was struggling for a while to find a combination of a decent GPS route planning/mapping tool and a sat nav phone app that could read it.</b><br />
<b><br />the route planning tools were a pain, including google maps which only lets you set urm 8 waypoints atm? <br /><br />the sat nav apps that supported gpx files, e.g. copilot insisted on changing the route on me and bypassing waypoints i had set.</b><br />
<b><br /></b>
<b>anyway, long story short, i found that the best combination so far seems to be "Tyre" on the PC and "Osmand" on the mobile.</b><br />
<b><br /></b>
<b>1. download Tyre, note - windows only and must have a later version of IE installed. </b><br />
<b><a href="http://www.tyretotravel.com/download-tyre/download-tyre-basic/">http://www.tyretotravel.com/download-tyre/download-tyre-basic/</a></b><br />
<b>alternatively if you don't have a PC, try e.g. <a href="https://www.motogoloco.com/">https://www.motogoloco.com</a></b><br />
<b>tyre is better than anything online atm though</b>
<b>2. </b><br />
<b>a.in tyre, right click on a road, and choose "add new waypoint (immediately)" repeatedly until you have built your route.</b><br />
<b>b. save this in the standard format (better for re-editing in case it doesn't like the gpx).</b><br />
<b>c. now save this in gpx format.</b><br />
<b><br /></b>
<b>3. install Osmand on your device, the following instructions relate to android, but it is available for iphone<br /><br />from one of these:<br /><a href="https://play.google.com/store/apps/details?id=net.osmand.plus">https://play.google.com/store/apps/details?id=net.osmand.plus</a><br /><a href="https://itunes.apple.com/app/apple-store/id934850257">https://itunes.apple.com/app/apple-store/id934850257</a><br /><a href="https://www.amazon.com/OsmAnd-Maps-Navigation/dp/B00D0SEGMC">https://www.amazon.com/OsmAnd-Maps-Navigation/dp/B00D0SEGMC</a></b><br />
<b><br /></b>
<b>4. connect your phone to your windows PC, enable file browsing on your phone (click the usb message popup on the phone)</b><br />
<b><br /></b>
<b>5. </b><br />
<b>a. using windows explorer, browse to your phone storage and create a folder e.g. /OSMAND or /sdcard/OSMAND</b><br />
<b>b. now create a folder called tracks</b><br />
<b>c. copy the gpx file you created from your computer into the tracks folder</b><br />
<b><br /></b>
<b>6. in the Osmand app go to menu/settings/general settings and click on data storage folder - change this folder to the folder that you created at 5a. </b><br />
<b>e.g. /OSMAND or /sdcard/OSMAND</b><br />
<b><br /></b>
<b>(the main point in 5+6 is to ensure that windows will be have permission to see the Osmand data folder without messing about with permissions. </b><b>you can also e.g. email gpx files to yourself and open gpx files directly on your phone and osmand will import them)</b><br />
<b><br /></b>
<b>7. </b><br />
<b>a. in Osmand app, download the base (or overview) world map, and also the regional map covering your route, e.g. europe/uk/england. </b><br />
<b>b. once those 2 maps are completely downloaded, go to menu/configure map/gpx track... then select the track that you want, and select current track <br />(if you load another track later, you may wish to deselect current track then).</b><br />
<b><br /></b>
<b><br /></b><b>so that's just a quick run down. mostly for me for when i lose my phone and don't remember how to set all this up )</b><br />
<b><br /></b>
<b>hopefully i didn't miss anything. </b><br />
<b>when i am planning a route on tyre, i also have google earth/streetview up on the other screen so i can check out the roads.</b><br />
<b><br /></b>
<b>don't forget to backup your routes to e.g. dropbox </b><br />
<b><br /></b>
<b><br /></b>
Codefuciushttp://www.blogger.com/profile/13637371019628237927noreply@blogger.com7tag:blogger.com,1999:blog-1699715396673909229.post-75588817856093131462014-03-16T12:51:00.001-07:002014-03-22T02:08:35.125-07:00Getting a Dell C1760nw Color Printer up and running on Linux Mint / UbuntuI'm not so great at Linux, so I'm trying to use it as my home PC to get more familiar.<br />
<br />
The biggest problem with Linux still seems to be getting the manufacturers to create drivers.<br />
<br />
On the Dell support pages, there are no linux drivers for the C1760nw.<br />
<br />
I found a post somewhere (I forget) that mentioned that C1760nw is basically a rebadaged Xerox Phaser 6000B.<br />
<br />
So, I tried downloading the Xerox DEB driver, but that didn't work for me. (Edit: a few people have said they had no problems with the DEB driver - see comments <a href="http://www.amazon.co.uk/review/R1TEL0ZJYUR174" target="_blank">here</a>, so try that first!) So I downloaded the RPM print driver <a href="http://www.support.xerox.com/support/phaser-6000/downloads/engb.html?operatingSystem=linux&fileLanguage=en_GB" target="_blank">here</a> (filename 6000_6010_rpm_1.01_20110222.zip)<br />
<br />
I then opened the zip, extracted the contained Xerox_Phaser_6000B.ppd.gz to my home directory - as i am the only user. Which gives you the pdd file. <br />
Then I extracted the contents of the RPM and found they contained a usr folder.<br />
As root user, I then copied/merged the usr folder contents to /usr.<br />
<br />
I then went to the linux printer setup at <a href="http://localhost:631/">http://localhost:631</a><br />
and added the printer:<br />
Other network printers - Internet Printing Protocol (ipp)<br />
Connection socket://192.168.0.100 (where 192.168.0.100 is my printer IP address)<br />
Name - Dell<br />
Provide a PDD file - browsed to and selected the ppd file I extracted earlier<br />
And clicked Add Printer<br />
<br />
I then fired up the printer gui with system-config-printer, clicked properties and tried to print a test page.<br />
<br />
At which point, I got a printer status like this:<br />
File /usr/lib/cups/filter/... has insecure permissions<br />
<br />
(which was obviously the files I had extracted).<br />
<br />
A bit of googling revealed I had to set the permissions up on the cups file in question, but being the only user, I just did the directory:<br />
<br />
sudo chmod 755 -R /usr/lib/cups/filter<br />
sudo chown -R root /usr/lib/cups/filter<br />
<br />
So, I tried another test page, things went a bit further, and then I got this status:<br />
Idle - "Rendering completed"<br />
<br />
More googling revealed that I was missing some libraries:<br />
<br />
sudo apt-get install ia32-libs<br />
<br />
Another attempt and the print test finally page popped out!<br />
<br />
30 mins to install a printer :c( <br />
<br />
Let's hope my Linux experience gets better. I do like Mint though, gotta say.<br />
<br />
These replacement cartridges look cheap: <a href="http://www.amazon.co.uk/Compatible-Cartridges-1350cnw-C1765nfw-printers/dp/B007JTRJK4/ref=sr_1_1?ie=UTF8&qid=1394999785&sr=8-1&keywords=C1760nw+toner" target="_blank">amazon</a>Codefuciushttp://www.blogger.com/profile/13637371019628237927noreply@blogger.com129tag:blogger.com,1999:blog-1699715396673909229.post-20086063163547532712012-11-29T05:04:00.000-08:002012-12-03T05:13:30.100-08:00Advanced jqGrid Search Functionality with LINQ (and EntityFramework) and ASP.NET MVC.<br />
Note: there is a new version of jqGrid built specifically
for MVC, but it's a commercial version which I am unfamiliar with. This article
relates to the standard, free version.<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Disclaimer: this code is not yet in production, and so is yet
to be thoroughly tested. There may also be a much simpler, entirely different approach - if so, I'd love to know.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Special thanks to the jqGrid expert Oleg @ <a href="http://www.ok-soft-gmbh.com/"><span style="background: white; border: none windowtext 1.0pt; color: #4a6b82; font-family: Arial; font-size: 11.0pt; mso-border-alt: none windowtext 0cm; padding: 0cm;">ok-soft-gmbh.com</span></a> for the fundamental groupOp/filter code.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Ok, so you have built your jqGrid, and all is well, but:</div>
<div class="MsoNormal">
<br /></div>
<ol start="1" style="margin-top: 0cm;" type="1">
<li class="MsoNormal">You
need to add search functionality. </li>
<li class="MsoNormal">You
need to have full search functionality because you are using the jqGrid
options<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> multipleSearch: <span style="color: blue;">true</span>,
and multipleGroup: <span style="color: blue;">true</span>, so you will be and/or-ing multiple search clauses.</span><o:p></o:p></li>
<li class="MsoNormal">You
don't want to code a specific search code for every jqGrid in your site,
you want some simple shared functionality for the search that can be
re-used.</li>
<li class="MsoNormal">You want to be able to handle any text field name and value to support (3).</li>
<li class="MsoNormal">You
are using MVC and LINQ.</li>
</ol>
<div class="MsoNormal">
<br />
The most fundamental problem here is that LINQ will only
allow type-safe queries. Out-of-the-box, this means that you cannot dynamically
construct queries on the fly.</div>
<div class="MsoNormal">
This is a problem for jqGrid searches from multiple sources, as you do not know
the types (or names) for the where clause until run-time, or even the parameter value.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
For example, normally in linq, you would write:</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
...where customer.id = 5</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
But we need something more like:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
...where "customer.id = 5"</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The most direct solution to this problem would probably be
with expression trees. However, expression trees are rather complex, hard to
read, and would become more involved to handle every possible where clause
scenario.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Fortunately,
there is a solution to this, the system.linq.dynamic class. This isn't part of
the standard framework, but you can download and compile it yourself under the
Microsoft Public Licence. For more information, see ScottGu's blog:</div>
<div class="MsoNormal">
<span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"><a href="http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx">http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx</a><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Ok, assuming you have built that dll, and added a reference in
your project and a using statement in your controller, how are we going to
build our where clause from what jqGrid provides us?</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Well first we'll create some jqGrid support classes to
provide plumbing (I will refer to this file later as the jqGrid support classes file):</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">JqSearchIn</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span> sidx { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span> sord { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">int</span> page { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">int</span> rows { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">bool</span> _search {
<span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span>
searchField { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>;
}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span>
searchOper { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>;
}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span>
searchString { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>;
}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span> filters
{ <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: green;">// ignore this for now... all will become clear</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: #2b91af;">WhereClause</span>
GenerateWhereClause(<span style="color: #2b91af;">Type</span> targetSearchType)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">return</span> <span style="color: blue;">new</span> <span style="color: #2b91af;">WhereClauseGenerator</span>().Generate(_search, filters,
targetSearchType);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">JqGridSearchOut</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">int</span> total { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">int</span> page { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">int</span> records { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: #2b91af;">Array</span> rows
{ <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">JqGridFilter</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: #2b91af;">GroupOp</span>
groupOp { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>;
}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">JqGridRule</span>> rules { <span style="color: blue;">get</span>;
<span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">JqGridFilter</span>> groups { <span style="color: blue;">get</span>;
<span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">JqGridRule</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span> field {
<span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: #2b91af;">Operations</span>
op { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>;
}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span> data { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">enum</span> <span style="color: #2b91af;">GroupOp</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> AND,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> OR<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">enum</span> <span style="color: #2b91af;">Operations</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> eq, <span style="color: green;">// "equal"</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> ne, <span style="color: green;">// "not equal"</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> lt, <span style="color: green;">// "less"</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> le, <span style="color: green;">// "less or equal"</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> gt, <span style="color: green;">// "greater"</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> ge, <span style="color: green;">// "greater or equal"</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> bw, <span style="color: green;">// "begins with"</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> bn, <span style="color: green;">// "does not begin with"</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> ew, <span style="color: green;">// "ends with"</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> en, <span style="color: green;">// "does not end with"</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> cn, <span style="color: green;">// "contains"</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> nc <span style="color: green;">// "does not
contain"</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: green;">//in, // "in"</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: green;">//ni // "not in"</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Having done that, we can now create the signature for
our controller, so assuming your jqGrid has an <st1:city>Ajax</st1:city>
call in it's setup, like this:</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> grid.jqGrid({<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> height:
300,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> url:
ajxGetJqGridCustomers, <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> ...<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Then the controller signature would look like this:</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #2b91af;">JsonResult</span> GetJqGridCustomers (<span style="color: #2b91af;">JqSearchIn</span> si)<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
(Ideally this should have a [HttpPost] above it, but I'll
leave that up to you once you have everything else working).</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Note that in MVC, the JqSearchIn parameter will auto-magically
map correctly to populate the class.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Ok, having got that far, we can now start thinking about how
to generate an appropriate where clause for all that search information the
JqSearchIn has been populated with. Fundamentally, we want to do something like this (note the type
being passed in, which is explained later):</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">var</span><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> wc =
si.GenerateWhereClause(<span style="color: blue;">typeof</span>(<span style="color: #2b91af;">Customer</span>));<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">// I'm using
entity framework here, but it could just as well <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: green; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">// be straight linq
(i.e. forget the .db part)</span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">customers = db.Customers.Where(wc);<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
But we're going to have to use parameters (remember our code
must still be converted so it is (a) type-safe, and (b) parameterised against
injection), so we're going to rewrite that like this:</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">customers = db.Customers.Where(wc.Clause,
wc.FormatObjects);<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
We will add the object class to the jqGrid support classes file:</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">WhereClause</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span> Clause
{ <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">object</span>[]
FormatObjects { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>;
}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
We can now create the clause generator and other associated methods (again I would
suggest using the same jqGrid support classes file):</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: green;">// if you make this static, then consider concurrency
issues </span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">WhereClauseGenerator</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">private</span> <span style="color: #2b91af;">List</span><<span style="color: blue;">object</span>> _formatObjects;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: #2b91af;">WhereClause</span>
Generate(<span style="color: blue;">bool</span> _search, <span style="color: blue;">string</span>
filters, <span style="color: #2b91af;">Type</span> targetSearchType )<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
_formatObjects = <span style="color: blue;">new</span> <span style="color: #2b91af;">List</span><<span style="color: blue;">object</span>>();<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">return</span> <span style="color: blue;">new</span> <span style="color: #2b91af;">WhereClause</span>()<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> Clause = _search
&& !<span style="color: #2b91af;">String</span>.IsNullOrEmpty(filters) ? <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> ParseFilter(<span style="color: blue;">new</span>
<span style="color: #2b91af;">JavaScriptSerializer</span>()<br /> .Deserialize<<span style="color: #2b91af;">JqGridFilter</span>>(filters),targetSearchType).ToString()
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> : <span style="color: #2b91af;">String</span>.Empty,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> FormatObjects =
_formatObjects.ToArray()<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">private</span> <span style="color: blue;">readonly</span> <span style="color: blue;">string</span>[] FormatMapping = {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: green;">// 0 = field name, </span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: green;">// 1 = total no of formats/params so far - 1</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: green;">// F = replaced by fmAdd</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0} = @{1}{F})"</span>, <span style="color: green;">//
"eq" - equal</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0} <> @{1}{F})"</span>, <span style="color: green;">//
"ne" - not equal</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0} < @{1}{F})"</span>, <span style="color: green;">//
"lt" - less than</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0} <= @{1}{F})"</span>, <span style="color: green;">//
"le" - less than or equal to</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0} > @{1}{F})"</span>, <span style="color: green;">//
"gt" - greater than</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0} >= @{1}{F})"</span>, <span style="color: green;">//
"ge" - greater than or equal to</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0}.StartsWith(@{1}){F})"</span>, <span style="color: green;">//
"bw" - begins with</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"(!{0}.StartsWith(@{1}){F})"</span>, <span style="color: green;">// "bn"
- does not begin with</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0}.EndsWith(@{1}){F})"</span>, <span style="color: green;">//
"ew" - ends with</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"(!{0}.EndsWith(@{1}){F})"</span>, <span style="color: green;">//
"en" - does not end with</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0}.Contains(@{1}){F})"</span>, <span style="color: green;">//
"cn" - contains</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"(!{0}.Contains(@{1}){F})"</span> <span style="color: green;">//
"nc" - does not contain</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">private</span> <span style="color: blue;">readonly</span> <span style="color: blue;">string</span>[] NullValueFormatMapping = {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: green;">// 0 = field name</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0} = NULL)"</span>, <span style="color: green;">//
"eq" - equal</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0} != NULL)"</span>, <span style="color: green;">// "ne"
- not equal</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"(1=0)"</span>, <span style="color: green;">//
"lt" - less than</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"(1=1)"</span>, <span style="color: green;">//
"le" - less than or equal to</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0} != NULL)"</span>, <span style="color: green;">// "gt"
- greater than</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"(1=1)"</span>, <span style="color: green;">//
"ge" - greater than or equal to</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0} != NULL)"</span>, <span style="color: green;">// "bw"
- begins with</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0} != NULL)"</span>, <span style="color: green;">// "bn"
- does not begin with</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0} != NULL)"</span>, <span style="color: green;">// "ew"
- ends with</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0} != NULL)"</span>, <span style="color: green;">// "en"
- does not end with</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0} != NULL)"</span>, <span style="color: green;">// "cn"
- contains</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">"({0} !=
NULL)"</span> <span style="color: green;">// "nc" - does not contain</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">private</span> <span style="color: #2b91af;">StringBuilder</span>
ParseRule(<span style="color: #2b91af;">ICollection</span><<span style="color: #2b91af;">JqGridRule</span>> rules, <span style="color: #2b91af;">GroupOp</span>
groupOp, <span style="color: #2b91af;">Type</span> targetSearchType)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">if</span> (rules == <span style="color: blue;">null</span> ||
rules.Count == 0)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">return</span> <span style="color: blue;">null</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">var</span> sb = <span style="color: blue;">new</span> <span style="color: #2b91af;">StringBuilder</span>();<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">bool</span> firstRule = <span style="color: blue;">true</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">var</span> props =
targetSearchType.GetProperties().ToDictionary(p => p.Name, p =>
p.PropertyType);<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">foreach</span> (<span style="color: blue;">var</span> rule <span style="color: blue;">in</span> rules)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">if</span> (!firstRule)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: green;">// skip groupOp before the first rule</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
sb.Append(groupOp);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">else</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
firstRule = <span style="color: blue;">false</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: green;">// get the object type of the rule</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #2b91af;">Type</span>
ruleParseType;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">bool</span> emptyNullable = <span style="color: blue;">false</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">try</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: #2b91af;">Type</span> ruleType = ruleParseType =
props[rule.field];<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: blue;">if</span> (ruleType.IsGenericType &&
ruleType.GetGenericTypeDefinition() == <span style="color: blue;">typeof</span>(<span style="color: #2b91af;">Nullable</span><>))<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: blue;">if</span> (rule.data == <span style="color: #a31515;">""</span>)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> emptyNullable = <span style="color: blue;">true</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
ruleParseType = <span style="color: #2b91af;">Nullable</span>.GetUnderlyingType(ruleType);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">catch</span>(<span style="color: #2b91af;">KeyNotFoundException</span>)
{<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: blue;">throw</span> <span style="color: blue;">new</span>
<span style="color: #2b91af;">ArgumentOutOfRangeException</span>(rule.field + <span style="color: #a31515;">" is not a property of type "</span> <br /> +
targetSearchType);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: green;">// parse it in as the correct object type</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">var</span> fmAdd = <span style="color: #a31515;">""</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">if</span> (ruleParseType == <span style="color: blue;">typeof</span>(<span style="color: blue;">string</span>))<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
_formatObjects.Add(rule.data);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: blue;">if</span> (rule.data == <span style="color: #a31515;">""</span>) <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
fmAdd = <span style="color: #a31515;">" OR {0} = NULL"</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">else</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: blue;">if</span> (emptyNullable)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
_formatObjects.Add(<span style="color: blue;">null</span>); <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: blue;">else</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: blue;">var</span> parseMethod =
ruleParseType.GetMethod(<span style="color: #a31515;">"Parse"</span>, <span style="color: blue;">new</span>[] {<span style="color: blue;">typeof</span> (<span style="color: blue;">string</span>)});<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: blue;">if</span> (parseMethod != <span style="color: blue;">null</span>)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
_formatObjects.Add(parseMethod.Invoke(props[rule.field], <span style="color: blue;">new</span> <span style="color: blue;">object</span>[]
{rule.data}));<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: blue;">else</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">throw</span> <span style="color: blue;">new</span> <span style="color: #2b91af;">ArgumentOutOfRangeException</span>(rule.field +<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #a31515;">" is not a string and cannot be parsed
either!!"</span>);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">string</span> fm = emptyNullable ? NullValueFormatMapping[(<span style="color: blue;">int</span>) rule.op] <br /> : FormatMapping[(<span style="color: blue;">int</span>) rule.op].Replace(<span style="color: #a31515;">"{F}"</span>,fmAdd);<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
sb.AppendFormat(fm, rule.field, _formatObjects.Count-1);<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">return</span> sb.Length > 0 ? sb : <span style="color: blue;">null</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">private</span> <span style="color: blue;">void</span>
AppendWithBrackets(<span style="color: #2b91af;">StringBuilder</span> dest, <span style="color: #2b91af;">StringBuilder</span> src)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">if</span> (src == <span style="color: blue;">null</span> ||
src.Length == 0)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">return</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">if</span> (src.Length > 2 && src[0] != <span style="color: #a31515;">'('</span> && src[src.Length - 1] != <span style="color: #a31515;">')'</span>)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
dest.Append(<span style="color: #a31515;">'('</span>);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
dest.Append(src);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
dest.Append(<span style="color: #a31515;">')'</span>);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">else</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: green;">// verify that no other '(' and ')' exist in the b. so that</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: green;">// we have no case like src = "(x < 0) OR (y >
0)"</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">for</span> (<span style="color: blue;">int</span> i = 1; i
< src.Length - 1; i++)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: blue;">if</span> (src[i] != <span style="color: #a31515;">'('</span>
&& src[i] != <span style="color: #a31515;">')'</span>) <span style="color: blue;">continue</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
dest.Append(<span style="color: #a31515;">'('</span>);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
dest.Append(src);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
dest.Append(<span style="color: #a31515;">')'</span>);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: blue;">return</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
dest.Append(src);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">private</span> <span style="color: #2b91af;">StringBuilder</span>
ParseFilter(<span style="color: #2b91af;">ICollection</span><<span style="color: #2b91af;">JqGridFilter</span>> groups, <span style="color: #2b91af;">GroupOp</span>
groupOp, <span style="color: #2b91af;">Type</span> targetSearchType)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">if</span> (groups == <span style="color: blue;">null</span> ||
groups.Count == 0)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">return</span> <span style="color: blue;">null</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">var</span> sb = <span style="color: blue;">new</span> <span style="color: #2b91af;">StringBuilder</span>();<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">bool</span> firstGroup = <span style="color: blue;">true</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">foreach</span> (<span style="color: blue;">var</span> group <span style="color: blue;">in</span> groups)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">var</span> sbGroup = ParseFilter(group, targetSearchType);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">if</span> (sbGroup == <span style="color: blue;">null</span>
|| sbGroup.Length == 0)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: blue;">continue</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">if</span> (!firstGroup)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: green;">// skip groupOp before the first group</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
sb.Append(groupOp);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">else</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
firstGroup = <span style="color: blue;">false</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
sb.EnsureCapacity(sb.Length + sbGroup.Length + 2);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
AppendWithBrackets(sb, sbGroup);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">return</span> sb;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">private</span> <span style="color: #2b91af;">StringBuilder</span>
ParseFilter(<span style="color: #2b91af;">JqGridFilter</span> filters, <span style="color: #2b91af;">Type</span> targetSearchType)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">var</span>
parsedRules = ParseRule(filters.rules, filters.groupOp, targetSearchType);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">var</span> parsedGroups = ParseFilter(filters.groups,
filters.groupOp, targetSearchType);<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">if</span> (parsedRules != <span style="color: blue;">null</span>
&& parsedRules.Length > 0)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">if</span>
(parsedGroups != <span style="color: blue;">null</span> &&
parsedGroups.Length > 0)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: blue;">var</span> groupOpStr =
filters.groupOp.ToString();<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: blue;">var</span> sb = <span style="color: blue;">new</span>
<span style="color: #2b91af;">StringBuilder</span>(parsedRules.Length +
parsedGroups.Length + groupOpStr.Length + 4);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
AppendWithBrackets(sb, parsedRules);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
sb.Append(groupOpStr);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
AppendWithBrackets(sb, parsedGroups);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: blue;">return</span> sb;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">return</span> parsedRules;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">return</span> parsedGroups;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
You'll notice several things in the above listing:</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
1. Most obviously, as expected, there is some recursion to build the
clause (remember we are supporting multiple group and/ors). Note - for security you should never allow jgGrid's built-in showquery option string to be passed into your query.</div>
<div class="MsoNormal">
2. There are various format objects for the parameters to
ensure the where clause parameter list is built appropriately.</div>
<div class="MsoNormal">
3. Most importantly, a targetSearchType is passed in. This
is the most interesting part.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
As you recall, the initial call from the controller is as
follows:</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">si.GenerateWhereClause(<span style="color: blue;">typeof</span>(<span style="color: #2b91af;">Customer</span>));<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Which further down the stack becomes gets passed in to
ParseRule:</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">private</span><span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: #2b91af;">StringBuilder</span> ParseRule(<span style="color: #2b91af;">ICollection</span><<span style="color: #2b91af;">JqGridRule</span>> rules, <span style="color: #2b91af;">GroupOp</span>
groupOp, <span style="color: #2b91af;">Type</span> targetSearchType)<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
ParseRule then uses Reflection to get the underlying type of
each property being searched against in the entity/class, in this case
Customer. It also uses reflection to get the correct parse method for the type.
This means that we can parse in the correct type and value to build the where
clause. Or in other words, we can keep dynamic linq happy.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
One last bit of plumbing is to add a view model for the
output:</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">CustomerItemsJqGridRowOut</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">int</span> Id { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span>
FirstName { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>;
}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span> LastName
{ <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Ok, having done the tricky parts, all that remains is to head
back to the controller and finish off by adding paging and the rest of the code:</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">public</span> JsonResult GetJqGridCustomers(JqSearchIn si)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">int</span> totalRecords;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">int</span> startRow = (si.page * si.rows) + 1;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">int</span> skip = (si.page > 0 ? si.page - 1 : 0) *
si.rows;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: green;">// note - these queries require "using
System.Dynamic.Linq" library </span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
IQueryable<Customer> customers;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">if</span> (si._search && !<span style="color: #2b91af;">String</span>.IsNullOrEmpty(si.filters))<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">var</span> wc = si.GenerateWhereClause(<span style="color: blue;">typeof</span>(Customer));<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
customers = db.Customers.Where(wc.Clause, wc.FormatObjects);<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> totalRecords = customers.Count();<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
customers = customers<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
.OrderBy(si.sidx + <span style="color: #a31515;">" "</span> +
si.sord)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
.Skip(skip)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
.Take(si.rows);<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">else</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
customers = db.Customers;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
totalRecords = customers.Count();<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
customers = customers<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
.OrderBy(si.sidx + <span style="color: #a31515;">" "</span> +
si.sord)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
.Skip(skip)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
.Take(si.rows);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">var</span> customersList = customers.ToList();<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">var</span> totalPages = (<span style="color: blue;">int</span>)<span style="color: #2b91af;">Math</span>.Ceiling((<span style="color: blue;">float</span>)totalRecords
/ si.rows);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> <span style="color: blue;">var</span> grid = <span style="color: blue;">new</span>
JqGridSearchOut<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> total = totalPages,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
page = si.page,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
records = totalRecords,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
rows = (<span style="color: blue;">from</span> cst <span style="color: blue;">in</span> customersList<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
<span style="color: blue;">select</span> <span style="color: blue;">new</span>
CustomerItemsJqGridRowOut()<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
Id = cst.Id,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> FirstName =
cst.FirstName,<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> LastName =
cst.LastName<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;">
}).ToArray()<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">return</span> <o:p></o:p></span><span style="font-family: Consolas; font-size: 13px;">Json(grid);</span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; mso-bidi-font-family: Consolas; mso-font-kerning: 0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Hopefully this should be of use to someone out there.</div>
<div class="MsoNormal">
<br />
Edit - I should probably do something about the OrderBy() clause as that part is obviously not parameterised, and could be injection attacked. </div>
<div class="MsoNormal">
<br /></div>
Codefuciushttp://www.blogger.com/profile/13637371019628237927noreply@blogger.com7tag:blogger.com,1999:blog-1699715396673909229.post-4074044239281039392012-11-14T10:03:00.001-08:002012-11-30T01:44:50.505-08:00Entity Framework FunI had an interesting problem today with EntityFramework. (I'm using the EF 5.x DbContext Generator for my POCOs, but I doubt it matters which POCO generator you use).<br />
<br />
I have a SQL view that has some calculated columns, like this. <br />
<br />
(X * Y) As MyCol<br />
<br />
where both X and Y are decimal types.<br />
<br />
I have been using the view for a while just fine, but then today it stopped working.<br />
<br />
The error I was getting was:<br />
<br />
"The property on ... could not be set to a 'Decimal' value. You must set this property to a non-null value of type 'Double'."<br />
<br />
I thought this was odd, seeing as the code is auto-generated.<br />
<br />
I subsequently discovered that the underlying data types in the tables used in the view (and the view below it) had been
extended to increase accuracy, from decimal(18,2) to decimal (30,15). It then dawned on me that because the column datatype is not actually specified in the view but rather inferred from a calculated column, the auto-generated code might not really know the correct data type to use, and sure enough it was generating a nullable double not a nullable decimal.<br />
<br />
The problem was fixed by going to the view and changing the column output to a known type, i.e.<br />
<br />
cast((X * Y) as decimal(30,15)) As MyCol<br />
<br />
I then removed everything from the .edmx and re-added it to re-generate the code.<br />
<br />
The auto-generated code then picked up the correct data type (decimal instead of double) and all is well.<br />
<br />Codefuciushttp://www.blogger.com/profile/13637371019628237927noreply@blogger.com0tag:blogger.com,1999:blog-1699715396673909229.post-5743785484290045882012-02-26T04:24:00.007-08:002012-02-26T04:39:39.114-08:00Setting Modified Date/Time on TrueCrypt files on ReadyNAS shares so they BackupFurther to my last post regarding offsite backups. I've noticed that backup solutions can have a hard time with TrueCrypt containers, as they do not by default change the modified date on the file, which means that the backup program then has to scan a big fat file for byte level differences or a CRC check or some such (and that's assuming your backup program is clever enough to do anything other than a modified date check).<br />
<br />
The general solution for this is to change a setting in TrueCrypt - disable "Preserve modification timestamp on file containers".<br />
<br />
This probably won't work if your TrueCrypt file is stored on a ReadyNAS network share though - it didn't for me anyway.<br />
<br />
A simple solution (on Windows 7) is to run a batch script that uses PowerShell to modify the date/time before your backup runs (either as a step in the backup software itself, or just as a daily scheduled task).<br />
<br />
The ChangeTCModifiedDate.bat file would look something like this:<br />
<br />
powershell $(get-item \\ReadyNASBox\myfolder\mytruecryptfile.fil).lastwritetime=$(get-date)<br />
<br />
Of course, this ReadyNAS problem isn't restricted to just TrueCrypt, see here:<br />
<a href="http://forums.truecrypt.org/viewtopic.php?p=99934#99934">http://forums.truecrypt.org/viewtopic.php?p=99934#99934</a>Codefuciushttp://www.blogger.com/profile/13637371019628237927noreply@blogger.com0tag:blogger.com,1999:blog-1699715396673909229.post-33106715848338228182012-02-26T03:32:00.017-08:002012-04-30T01:07:31.606-07:00Online (Offsite) Backup Solutions - A Brief TestI wanted to do some offsite backups and I have about 85GB to backup. I tested out some of the popular solutions (I'm based in the UK, and of course YMMV):<br />
<br />
Carbonite = v.slow uploads ~300kbit/s - price £3.49/month for unlimited storage*<br />
CrashPlan = v.slow uploads ~340kbit/s - price £1.89/month for unlimited storage<br />
SpiderOak = slow uploads ~700kbit/s - price £6.30/month for 100GB<br />
GoDaddy = fast uploads ~5Mbit/s - price £1.59/month for 100GB<br />
Mozy = very fast uploads ~8Mbit/s (uk server) - price £7.99/month for 125GB ** <br />
iDrive - fast uploads ~6Mbit/s - price £3.20/month for 150GB <br />
OpenDrive - max file size is only 1GB for cheapest plan, so didn't test it.<br />
<br />
* Note that it seemed to mysteriously slow down to 300kbit/sec only after I had exceeded 3GB of storage, before that it was much faster.<br />
** Mozy may actually be faster than that even, as my upload connection maxes out at ~8Mbit/sec.<br />
<br />
Prices are obviously subject to change - correct at the time of posting.<br />
<br />
Some backup solutions have versioning - but that will just use up your storage space, and you should be doing that with your local backup solution, not your offsite solution.<br />
<br />
I found that some of the software was exaggerating/misreporting its real upload speed. So I had to use a "desktop gadget" called Network Meter to monitor activity.<br />
<br />
Unsurprisingly, I've gone with GoDaddy for now due to the solid upload speed/price combination.<i> (No I haven't - see update at the bottom!)</i> The downside is that it's not quite as quick as Mozy, and the backup software is very basic.<br />
<br />
Generally I have noticed that when it comes to online storage of any kind (backups/photos/ftp/web/email) - the web hosting companies are always some of the cheapest.<br />
<br />
Now if I could just find a UK webhost that was cheaper than GoDaddy and and had a better software client. There's always room for improvement.<br />
<br />
I should say though, that despite the GoDaddy client being very basic, it puts hardly any stress on the system while I am using it, which is worth a lot to me. The other clients tend to do advanced file-diff comparisons to "save you space" which stress your CPU. In reality, a simple modified date/time check is all most users need, and its not really to save you space as much as save them bandwidth by only uploading file differences at the byte level (or some such). Your CPU time costs nothing to them, but you have to pay the power bill for it. So all round, I'm quite liking the GoDaddy solution atm, but it's early days.<br />
<br />
What's interesting about the Mozy client is that it seems to detect if a file you are uploading already exists on their servers in someone else's backup, and if so, it doesn't upload your file, but just creates a reference. This is clever, but... it still counts against your usage allowance!! Cheeky.<br />
<br />
UPDATE: since I wrote this, I have discovered that the maximum file upload size for GoDaddy online storage is 1GB (<i>despite the fact that it says file size is Unlimited on their product page!</i>). Some of my files are bigger than that, so I've switched to iDrive, and I've got to say I'm pretty happy with it. I upload several gigs/day to iDrive with no problems.Codefuciushttp://www.blogger.com/profile/13637371019628237927noreply@blogger.com0tag:blogger.com,1999:blog-1699715396673909229.post-72476999950096994452010-10-27T01:59:00.000-07:002010-10-27T02:01:44.405-07:00Contractors' HandbookI've recently got my hands on the "Contractors' Handbook". It's a great book for anyone new to contracting, and even seasoned contractors may learn a thing or two.Codefuciushttp://www.blogger.com/profile/13637371019628237927noreply@blogger.com1tag:blogger.com,1999:blog-1699715396673909229.post-924926684406889292010-10-14T12:10:00.000-07:002010-10-14T12:10:23.963-07:00The Case of the UnexplainedI was having a little trouble with a PC today that kept doing it's own thing, rather than what I wanted it to do. So I went to download Process Explorer, and while I was there, I found a link to this little gem - a presentation by Mark Russinovich of Winternals fame:<br />
<a href="http://www.msteched.com/2010/NorthAmerica/WCL315">http://www.msteched.com/2010/NorthAmerica/WCL315</a>Codefuciushttp://www.blogger.com/profile/13637371019628237927noreply@blogger.com1tag:blogger.com,1999:blog-1699715396673909229.post-75422710984646317732010-10-07T09:11:00.000-07:002010-10-08T08:45:34.731-07:00Kindle, Reader, MSDN, iPhone and some VAT tooBeing a computer geek, I have a fair few gadgets. Recently I acquired a Kindle (and I already have a Sony Reader). The Kindle and Sony are really very similar, but recently there are a few books/magazines I have not been able to get outside of Kindle format.<br />
<br />
What's interesting to me is the different way these devices handle PDFs. Because PDF text is generally too small on these devices, you have to zoom in. The Sony will actually resize the font and re-paginate the text, which is clever, but the carriage returns get messed up and so do the images. The zoom feature on the Kindle literally just zooms and you have to scroll around the screen to read, this seems horrible at first, but the trick is to zoom to 150% and go into landscape mode, then you can just read downwards using the normal page turn buttons. The problem on the Kindle is that it then remembers this mode when you leave the book, which is annoying. The Kindle badly needs to remember zoom settings specific to the book - hopefullly this will be in a future firmware update. I think both devices could really do with a bigger screen, preferably a touch screen (iPad style) to give more screen space and get rid of the buttons, then maybe you wouldn't need to zoom in the first place. They could also both use an accelerometer for portrait/landscape mode and a backlit display that you can turn on and off, but they can't give you everything at once or you wouldn't buy version 3.0 (actually Sony have brought out a backlit model now).<br />
<br />
Despite it's naughty proprietary "buy everything from amazon" nature, the Kindle does have 3 things going for it:<br />
i) it's cheap,<br />
ii) you don't have to use the horrible Sony Reader Library software to transfer files (you just use windows explorer), and<br />
iii) it's got wifi (3g on the expensive one).<br />
<br />
At any rate, this brings me on to a couple of things:<br />
<br />
1. I'm probably very slow on the uptake here, but today I discovered that you can download MSDN Magazine for free in PDF format from here: <a href="http://msdn.microsoft.com/en-us/magazine/ee412244.aspx">http://msdn.microsoft.com/en-us/magazine/ee412244.aspx </a> (Some of the older ones are in .chm format though).<br />
<br />
2. I really dislike proprietary formats. They are anti-competitive and try to tie you into a device or service. This is why I regret buying an iPhone instead of an Android, and why I will buy as few books as possible in Kindle format. I guess you can convert Kindle format to PDF with some third party tool if you have to, but in most cases if you go to the publisher's website you can buy the PDF/ePub version direct from them (at least in the case of technical books).<br />
<br />
In terms of proprietary formats/software, Apple is by far the worst offender. How on earth Apple has managed to get away with so many propietary tie-ins when Microsoft has been consistently dragged through the courts is beyond me. Their spate with Adobe over Flash on iPhones is hilarious too. I'm on Adobe's side on that one, but only because they opened up the PDF format ;c)<br />
<br />
I originally bought my iPhone to play with some iPhone development, but the proprietary dev tools and Objective-C language seemed totally archaic compared with the Microsoft development world. On the plus side, they have subsequently relented and allowed other developer tools (<a href="http://gizmodo.com/5633721/">http://gizmodo.com/5633721/</a>).<br />
<br />
One last thought. Computer books are quite frequently huge (1500+ pages). Books don't attract VAT, but electronic books do. Aside from this strange philosophical approach to tax, the UK government isn't really saving trees on this one is it? Computer books go out of date fast too, so it's not like 20 people will read the same book.<br />
<br />
Edit: By strange coincidence, just 5 mins after I was writing this, I got a phonecall from one of my brothers. He told me he had just got an Android phone. I asked him why he had chosen it over the iPhone. He said his IT friends would never have forgiven him for buying such a proprietary device! Oh, he also said that iTunes is one of the worst pieces of software ever written. I'm not sure that's true, but when you consider the money invested in it and the flagship nature of the product, yes, it really is awful to use, especially from a company known for their user-friendly operating system. At the end of the day though, the iPhone is a lovely piece of hardware, nobody buys it for the software. I know plenty of iPod users that stay away from iTunes altogether. Personally, I hate iTunes, so my contacts are sync'd with Google and my music is sync'd with MediaMonkey (which I recommend). So, just because iTunes is horrible isn't a solid reason not to buy an iPhone, you can just avoid using it altogether (except for firmware updates).Codefuciushttp://www.blogger.com/profile/13637371019628237927noreply@blogger.com1tag:blogger.com,1999:blog-1699715396673909229.post-85193021271159366582010-09-30T09:21:00.000-07:002010-09-30T09:24:17.134-07:00Little Problem Today with a NetbookI'm not a sysadmin, I'm a developer, but today I was given a netbook (Samsung N110 with XP) for use off-site, and was told it had a slow startup problem. Having established there was no data on the PC that the previous user wanted to keep, I elected to just use the restore function on the notebook to get the machine back to health.<br />
<br />
Sure enough it booted like the proverbial lightning after the restore. Good I thought, just stick the windows updates and ms office on there and we're good to go.<br />
<br />
The first set of updates (80 or so) went on ok and the system was fine. So I installed office, which resulted in a load more updates on the machine (another 40 or so). After this round of updates, the PC became painfully slow between the welcome screen and the desktop - taking about 3 mins to be usable.<br />
<br />
I didn't want to trawl through uninstalling updates, so I resorted to good ole' msconfig. This determined the root of the problem to be something called the Marvell Yukon service (relating to the network card). I disabled this and everything was great again...<br />
<br />
So I head on over to the Marvell support site and download their latest XP/x86 software for the card (88E8040), and install it. Then before I reboot, I go in to the services.msc to re-enable the (presumably updated) service...<br />
<br />
However, when I look in the services panel, I find that the new software install actually deletes the old service! Well, I guess that's one way for them to fix the problem.<br />
<br />
The netbook itself? It's nice, cute, and (now) surprisingly quick. It also has a long battery life (up to 8/9 hours allegedly). However, the keyboard is pretty horrible to use and the backslash key is on the right-hand side of the keyboard, which is a big no-no for a computer professional used to a full size uk keyboard.Codefuciushttp://www.blogger.com/profile/13637371019628237927noreply@blogger.com0tag:blogger.com,1999:blog-1699715396673909229.post-29984689857026983722010-09-29T03:28:00.000-07:002010-09-29T03:31:14.078-07:00The Demise of XmarksHopping from one workplace to another can mean using a lot of different PCs. One of the things that always eased the transition for me was Xmarks - a cross-browser bookmark sync tool. Sadly it looks like they are shutting down their operation in Jan 2011. Their blog post makes for an interesting read: <a href="http://blog.xmarks.com/?p=1886">http://blog.xmarks.com/?p=1886</a>Codefuciushttp://www.blogger.com/profile/13637371019628237927noreply@blogger.com1