Search

just show me the code

Wednesday, May 13, 2009

Linq Filter by adding Where Clause


  187         public IQueryable<Talent> GetTalents(string searchExpression)
  188         {
  189             IQueryable<Talent> t;
  190             if (string.IsNullOrEmpty(searchExpression))
  191             {
  192                 t = _repository.GetTalents();
  193             } 
  194             else
  195             {
  196                 t = BasicSearch(searchExpression);
  197             }
  198             return t;
  199         }
  200
  201         private static readonly char[] SplitDelimiters = " ".ToCharArray();
  202
  203         // search should come in as  'jon johnny323@yahoo.com rodgers'
  204         private IQueryable<Talent> BasicSearch(string search)
  205         {
  206             // Just replacing "  " with " " wouldn't help with "a      b"
  207             string[] terms = search.Trim()
  208                                    .ToLower()
  209                                    .Split(SplitDelimiters,
  210                                           StringSplitOptions.RemoveEmptyEntries);
  211             IQueryable<Talent> talents = _repository.GetTalents();
  212             foreach (string s in terms)
  213             {
  214                 talents = AddBasicSearch(talents, s);
  215             }
  216             return talents;
  217         }
  218
  219         private IQueryable<Talent> AddBasicSearch(IQueryable<Talent> t, string s)
  220         {
  221             return t.Where(x =>  x.FirstName.ToLower().Contains(s)
  222                     || x.LastName.ToLower().Contains(s) 
  223                     || x.Email.ToLower().Contains(s) 
  224                     || x.LanguagesString.ToLower().Contains(s) 
  225                     );
  226         }

Tuesday, May 12, 2009

jquery validation

 
  127 <asp:Content ID="Content3" ContentPlaceHolderID="javascript" runat="server"> 
  128     <script type="text/javascript">
  129         $.validator.addMethod("lettersonly", function(value, element) {
  130             return this.optional(element)  /^[a-z]+$/i.test(value);
  131         }, "Letters only please");
  132
  133         $(document).ready(function() {
  134             $('form').validate({
  135                 errorLabelContainer: "#errorMessageBox"
  136                 , wrapper: "li"
  137                 , errorClass: "invalid"
  138                 //, submitHandler: function() { alert("Submitted!") }
  139             })
  140             $('#<%=FirstName.ClientID %>').rules("add", {
  141                 minlength: 2
  142                 , required: true
  143                 , lettersonly : true
  144                 , messages: {
  145                     minlength: jQuery.format("At least {0} characters are required for the first name")
  146                     , required: "First name is required"
  147                 }
  148             });
  149             $('#<%=LastName.ClientID %>').rules("add", {
  150                 minlength: 2
  151                 , required: true
  152                 , lettersonly: true
  153                 , messages: {
  154                     minlength: jQuery.format("At least {0} characters are required for the last name")
  155                     , required: "last name is required"
  156                 }
  157             });
  158         });
  159     </script>
  160 </asp:Content>


   19                 <div>
   20                     <ul id="errorMessageBox"></ul>
   21                 </div>
   22                 <div class="clear"></div>
   23                 <label>
   24                     <asp:Label ID="lblFirstName" runat="server"
   25                         Text="<%$ Resources:Resource,LabelFirstName%>"></asp:Label>
   26                 </label>
   27                 <asp:TextBox ID="FirstName" runat="server" class="normal" MaxLength="50"></asp:TextBox><br />
   28                 <label>
   29                     <asp:Label ID="lblLastName" runat="server"
   30                         Text="<%$ Resources:Resource,LabelLastName%>"></asp:Label>
   31                 </label>
   32                 <asp:TextBox ID="LastName" runat="server" class="normal" MaxLength="50"></asp:TextBox><br />


here is the css ...   


   95 /*validation part*/
   96 label.invalid { float: none; text-align: left; width: 100%; color:#ee3333; font-weight:normal; padding: 3px 0px; }
   97 input.invalid { background-color:#FFeeee; color:#ee3333; }
   98 select.invalid { background-color:#FFeeee; border:3px double #ff9999; color:#ee3333; }
   99 #errorMessageBox { margin-bottom: 15px;  }
  100 #errorMessageBox li { margin: 0px 40px 0px 40px; padding: 5px 20px; color:#ee3333; background: #FFeeee;
101 text-transform: none; list-style-type: disc; list-style-position: inside;}
  102 #errorMessageBox label { text-transform: none; }

Monday, May 11, 2009

Random Objects should be static

thanks to help from dotnetperls.

static Random _r = new Random();
static void F()
{
    // Use class-level Random so that when this
    // method is called many times, it still has
    // good Randoms.
    int n = _r.Next(12);
    // If this declared a local Random, it would
    // repeat itself.
    System.Console.WriteLine(n);
}

using jquery tips

http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx

tip #1

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>



http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js
http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.js

http://code.google.com/apis/ajaxlibs/documentation/index.html#jqueryUI

google.load("jquery", "1.3.2");
google.load("jqueryui", "1.7.1");
google.load("prototype", "1.6.0.3");
google.load("scriptaculous", "1.8.2");
google.load("mootools", "1.2.2");
google.load("dojo", "1.3.1");
google.load("swfobject", "2.1");
google.load("yui", "2.7.0");

Thursday, May 7, 2009

using System.Xml.Linq

using System.Xml.Linq;
protected void Button1_Click(object sender, EventArgs e)
{
  XDocument doc = new XDocument();
  XElement projectElement = new XElement("Project"
     , new XAttribute("ProjectName", "xxx")
     , new XAttribute("ProjectDescription", "xxx")
     , new XAttribute("DateStart", "xxx")
     , new XAttribute("DateEnd", "xxx") );
  doc.Add(projectElement);
  for (int i = 0; i < 5; i++)
  {
    projectElement.Add(new XElement("Property"
      , new XAttribute("PropertyName", "PropertyName" + i)
      , new XAttribute("PropertyValue", "PropertyValue" + i) ));
  }
  this.lbl.Text = Server.HtmlEncode(doc.ToString());
  this.lbl.DataBind();
}



will produce xml that looks like this




<Project ProjectName="xxx" ProjectDescription="xxx" DateStart="xxx" DateEnd="xxx" >
  <Property PropertyName="PropertyName0" PropertyValue="PropertyValue0" />
  <Property PropertyName="PropertyName1" PropertyValue="PropertyValue1" />
  <Property PropertyName="PropertyName2" PropertyValue="PropertyValue2" />
  <Property PropertyName="PropertyName3" PropertyValue="PropertyValue3" />
  <Property PropertyName="PropertyName4" PropertyValue="PropertyValue4" />
</Project>





 

Tuesday, May 5, 2009

popup and print

the javascript 
 
  136 <script language="javascript">
  137     $(document).ready(function() {
  138         $('#<%=Submit.ClientID %>').click( function() {
  139             popitup('../Public/PrintRegister.aspx');
  140             return true;
  141         }); 
  142     }); 
  143     function popitup(url) {
  144         newwindow = window.open(url, 'name', 'height=600,width=750');
  145         if (window.focus) { newwindow.focus() }
  146         return false;
  147     }
  148 </script>

the button


  110 <asp:ImageButton ID="Submit" runat="server" 
  111  ImageUrl="<%$ Resources:Resource,ImageSubmitPrint %>"
  112  AlternateText="<%$ Resources:Resource,ImageSubmitPrintAltText%>" 
  113  OnClick="Submit_Click" />

 


PrintRegister.aspx


    9 <body class="" onLoad="self.print()"> 
   10     <form id="form1" runat="server">
   11     <div>
   12       Print stuff here
   13     </div>
   14     </form>
   15 </body>

Friday, April 24, 2009

My jQuery Date Range

using jQuery UI Datepickers.
Notice when you select a start date it becomes the min end date
and when you select an end date it becomes the max start date.

<!doctype html>

<html lang="en">
<head>
 <title>jQuery UI Datepicker - Restrict date range</title>
 <link type="text/css" href="../../themes/base/ui.all.css" rel="stylesheet" />
 <script type="text/javascript" src="../../jquery-1.3.2.js"></script>
 <script type="text/javascript" src="../../ui/ui.core.js"></script>
 <script type="text/javascript" src="../../ui/ui.datepicker.js"></script>
 <script type="text/javascript" src="http://www.mattkruse.com/javascript/date/compact/date.js"></script>

 <link type="text/css" href="../demos.css" rel="stylesheet" />
 <script type="text/javascript">
 $(function() {
  $(".startDatepicker").datepicker({
   showOn: 'button',
   buttonImage: 'images/calendar.gif',
   buttonImageOnly: true,
   dateFormat: "mm/dd/y" ,
   onSelect: function(dateText) {
    //alert(dateText);
    var d = parseDate(dateText);
    alert(d);
    $(".endDatepicker").datepicker('option', 'minDate', d);
   }
  });
  $(".endDatepicker").datepicker({
   showOn: 'button',
   buttonImage: 'images/calendar.gif',
   buttonImageOnly: true,
   dateFormat: "mm/dd/y" ,
   onSelect: function(dateText) { 
    //alert(dateText);
    var d = parseDate(dateText);
    alert(d);
    $(".startDatepicker").datepicker('option', 'maxDate', d);
   }
  });
 
 });
 </script>
</head>
<body>
<div class="demo">

<p>Start Date: <input type="text" id="startDatepicker"   class="startDatepicker"   ></p>
<p>End Date: <input type="text" id="endDatepicker" class="endDatepicker"></p>
</div><!-- End demo -->
</body>
</html>

Thursday, April 23, 2009

TFS Fail a build AND create a work item when unit test fails

thanks to http://social.msdn.microsoft.com/forums/en-US/tfsbuild/thread/b6fa6aa8-1861-4cd0-b9bb-4eeb64432651/




  229   <Target Name="AfterTest">
  230     <!-- Refresh the build properties. -->
  231     <GetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
  232                         BuildUri="$(BuildUri)"
  233                         Condition=" '$(IsDesktopBuild)' != 'true' ">
  234       <Output TaskParameter="TestSuccess"
  235               PropertyName="TestSuccess" />
  236     </GetBuildProperties>

  237 
  238     <!-- Set CompilationStatus to Failed if TestSuccess is false. -->
  239     <SetBuildProperties TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
  240                         BuildUri="$(BuildUri)"
  241                         CompilationStatus="Failed"
  242                         Condition=" '$(IsDesktopBuild)' != 'true' and '$(TestSuccess)' != 'true' ">
  243     </SetBuildProperties>
  244     <CreateNewWorkItem
  245       BuildNumber="$(BuildNumber)"
  246       BuildURi="$(BuildURI)"
  247       Description="The CreateNewWorkItem task created this bug."
  248       TeamProject="$(TeamProject)"
  249       TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
  250       Title="Unit Test Failure in $(BuildNumber)"
  251       WorkItemFieldValues="$(WorkItemFieldValues)"
  252       WorkItemType="$(WorkItemType)"
  253       Condition=" '$(IsDesktopBuild)' != 'true' and '$(TestSuccess)' != 'true' ">
  254     </CreateNewWorkItem>
  255   </Target>

Tuesday, April 14, 2009

Let me google that for you

http://lmgtfy.com/?q=dry+code+wiki

This is funny. don't let anyone hassle you

Wednesday, April 1, 2009

sweet regular expression tester site

I finally found a sweet regular expression tester. http://regexpal.com/

here is my test for phone number validation which will allow user to enter (xxx)xxx-xxxx or xxx-xxx-xxxx or xxxxxxxxxx

^((((\(\d{3}\)?)|(\d{3}-))?\d{3}-\d{4})|(\d{10}))

234-432-2342
(324)432-0909
(324)6we-0909
(324)63a-0909
234-432-2342
(234)324-5444
3424324234
234-432-2342
2311212321
asdf323243
1231321
1564344445

thanks regexpal

Contributors