Search

just show me the code

Friday, January 16, 2009

SOLID Principles with Uncle Bob


Scott talks to Uncle Bob about the the SOLID Principles of Object Oriented Design. This one is an easy listen! http://www.hanselminutes.com/default.aspx?showID=163
S.O.L.I.D.
  • Single responsibility principle,
  • Open/closed principle,
  • Liskov substitution principle,
  • Interface segregation principle, and
  • Dependency inversion principle
other links :
http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod
http://www.lostechies.com/blogs/chad_myers/archive/2008/03/07/pablo-s-topic-of-the-month-march-solid-principles.aspx

Thursday, January 15, 2009

starter master page

thanks to 456bereastreet
here is the final look

    5 <html xmlns="http://www.w3.org/1999/xhtml" >
    6 <head runat="server">
    7
    8     <style type="text/css">    body,
    9         html {
   10             margin:0;
   11             padding:0;
   12             background:#a7a09a;
   13             color:#000;
   14         }
   15         body {
   16             min-width:750px;
   17         }
   18         #wrap {
   19             background:#99c;
   20             margin:0 auto;
   21             width:750px;
   22         }
   23         #header {
   24             background:#ddd;
   25         }
   26         #header h1 {
   27             padding:5px;
   28             margin:0;
   29         }
   30         #nav {
   31             background:#c99;
   32             padding:5px;
   33         }
   34         #nav ul{
   35             margin:0;
   36             padding:0;
   37             list-style:none;
   38         }
   39         #nav li{
   40             display:inline;
   41             margin:0;
   42             padding:0;
   43         }
   44         #main {
   45             background:#9c9;
   46             float:left;
   47             width:500px;
   48         }
   49         #main h2, #main h3, #main p {
   50             padding:0 10px;
   51         }
   52         #sidebar {
   53             background:#99c;
   54             float:right;
   55             width:240px;
   56         }
   57         #sidebar ul {
   58             margin-bottom:0;
   59         }
   60         #sidebar h3, #sidebar p {
   61             padding:0 10px 0 0;
   62         }
   63         #footer {
   64             background:#cc9;
   65             clear:both;
   66         }
   67         #footer p {
   68             padding:5px;
   69             margin:0;
   70         }
   71
   72     </style>
   73     <asp:ContentPlaceHolder ID="head" runat="server">
   74     </asp:ContentPlaceHolder>
   75 </head>
   76 <body>
   77     <form id="form1" runat="server">
   78         <div id="wrap">
   79             <div id="header"><h1>Simple 2 column CSS layout, final layout</h1></div>
   80             <div id="nav">
   81                 <ul>
   82                     <li><a href="#">Option 1</a></li>
   83                     <li><a href="#">Option 2</a></li>
   84                     <li><a href="#">Option 3</a></li>
   85
   86                     <li><a href="#">Option 4</a></li>
   87                     <li><a href="#">Option 5</a></li>
   88                 </ul>
   89             </div>    
   90             <div id="main">         
   91                 <h2>Column 1</h2> 
   92                 <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> 
   93                 </asp:ContentPlaceHolder>  
   94             </div>
   95             <div id="sidebar">
   96                 <h3>Column 2</h3>
   97                 <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Mauris vel magna.</p>
   98                 <ul>
   99                     <li><a href="#">Link 1</a></li>
  100                     <li><a href="#">Link 2</a></li>
  101
  102                     <li><a href="#">Link 3</a></li>
  103                     <li><a href="#">Link 4</a></li>
  104                     <li><a href="#">Link 5</a></li>
  105                     <li><a href="#">Link 6</a></li>
  106                 </ul>
  107             </div> 
  108
  109             <div id="footer">        
  110                 <p>Footer</p>
  111
  112             </div>
  113         </div> 
  114     </form>
  115 </body>
  116 </html>

Wednesday, January 7, 2009

Asp.net Connection Strings

web.config
   21   <connectionStrings configSource="Database.config"/>



Database.config

    1 <connectionStrings>
    2   <clear/> 
    3   <add name="xxxx.xxxx.ConnectionString"
    4        connectionString="Server=xxxx;Initial Catalog=xxxx;Integrated Security=True;"
    5        providerName="System.Data.SqlClient" /> 
    6   <add name="xxxx.xxxx.Membership.ConnectionString"
    7        connectionString="Server=xxxxx;Initial Catalog=xxxx;Integrated Security=True;"
    8        providerName="System.Data.SqlClient" /> 
    9 </connectionStrings>



Database.config with user and password:
    1 <connectionStrings>
    2   <clear/>
    3
    4   <add name="xxxx.xxxx.ConnectionString"
    5        connectionString="Server=xxxx;Initial Catalog=xxxx;User=xxx;Password=xxx;"
    6        providerName="System.Data.SqlClient" /> 
    7   <add name="xxx.xxxx.Membership.ConnectionString"
    8        connectionString="Server=xxx;Initial Catalog=xxx;User=xxx;Password=xxx;"
    9        providerName="System.Data.SqlClient" />
   20 </connectionStrings>

Wednesday, December 10, 2008

Linq to Lambda

I changed a Linq expression to a Lambda expression so I could refactor the filter. Here is the before and after

Before: (Linq expression)
results = from u in ctx.ActiveUsers
          where (u.CompanyID != 1 &&
                   (u.LastName.ToLower().Contains(searchString)
                   || u.Email.ToLower().Contains(searchString)
                   || u.Company.Name.ToLower().Contains(searchString)))
          orderby u.LastName, u.FirstName
          select new Employee
          {
              ID = u.ID,
              FirstName = u.FirstName,
              LastName = u.LastName,
              Email = u.Email,
              CompanyName = u.Company.Name,
              CompanyID = u.CompanyID.ToString()
          };


After: (Lambda expression)
results = ctx.ActiveUsers
    .Where(Employee.GetExpression(searchString))
    .OrderBy(u =>  u.LastName ).ThenBy(u => u.FirstName)
    .Select(u => new Employee {
ID = u.ID
      , FirstName = u.FirstName
, LastName = u.LastName
      , Email = u.Email
, CompanyName = u.Company.Name
      , CompanyID = u.CompanyID.ToString() });


plus this to keep the where expression the same on the count:
private static Expression<Func<User, bool>> GetExpression(string searchString)
{ 
    Expression<Func<User, bool>> p = (u => u.CompanyID != 1 &&
                       (u.LastName.ToLower().Contains(searchString)
                       || u.Email.ToLower().Contains(searchString)
                       || u.Company.Name.ToLower().Contains(searchString)));
    return p;
}

so that GetExpression can be used here to make sure that our count query is the same as the select
public static int GetCustomerCount()
{
    UserContext ctx = new UserContext();
    int totalRecords;
 
    string searchString = SearchString; 
 
    totalRecords = ctx.ActiveUsers.Count(Employee.GetExpression(searchString));
    return totalRecords;
}




Tuesday, December 9, 2008

use your Gmail as a free smtp server

this is what your web.config would look like
<smtp  from="username@gmail.com">
  <network host="smtp.gmail.com"  port="465" userName="username@gmail.com"
        password="password" defaultCredentials="false"/>
</smtp>
thanks to this post for the help.

Monday, December 8, 2008

Linqpad


Linqpad is a nice way to learn how to write linq statements. There is no install required. Check it out here. Thanks Joseph

Thursday, December 4, 2008

pdf files in the sql database


<asp:TemplateField HeaderText="ID" SortExpression="ID"> 
    <ItemTemplate>
        <asp:HyperLink  ID="hl1" runat="server" 
            NavigateUrl='<%# String.Format("readfile.ashx?id={0}", Eval("ID") ) %>' 
            Text='<%# Eval("ID") %>' >
        </asp:HyperLink>
    </ItemTemplate>
</asp:TemplateField>



href="readfile.ashx?id=24"

this is what my handler code looks like

    /// 
    /// Summary description for $codebehindclassname$
    /// 
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class readfile : IHttpHandler
    { 
        public void ProcessRequest(HttpContext context)
        { 
            ReportContext ctxReport = new ReportContext();
            var r = from re in ctxReport.Report
                    where re.ID == Convert.ToInt32(context.Request["id"].ToString()) 
                    select re;
            Report rReport = r.FirstOrDefault<Report>();
 
            context.Response.Clear();
            string t = rReport.ReportType.TypeName;
            context.Response.ContentType = "application/pdf"; 
 
            context.Response.OutputStream.Write( 
                rReport.ReportData.ToArray() , 0
                , Convert.ToInt32(rReport.FileLength));
            context.Response.End(); 
        } 
        public bool IsReusable
        {
            get
            {
                return true;
            }
        } 
    }

Wednesday, December 3, 2008

Rocco


born on Dec 1st 10:22 am CST

Tuesday, December 2, 2008

jQuery Hello Goodbye

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
    $(".notice").fadeOut("slow");
    $("button").click(function () {
        $(".notice").fadeIn("slow");
        $(".notice").fadeOut("slow");
    });    
});
</script>
<style>
html { height: 100%; margin-bottom: 1px; }
.basic, .notice { padding: .8em; margin-bottom: 1em; border: 2px solid #dddddd; }
.notice { background: #FFF6BF; color: #817134; border-color: #FFD324; }
</style>
<div id="main">
    <button>Click Me!</button>
    <div class="basic" style="position:relative; width:550px;height:150px;" >
      <div class="notice" style="position:absolute; top:10px;left:10px;width:450px;">
          <p>Hello</p>
          <p>Goodbye</p>
      </div>
    </div>
    end
</div>
click here to see it in action.

Contributors