Saturday, December 15, 2012

Blue Hills Ride

Hi There!  Early this morning, my buddy SC and I rode the 4 or so miles from the neighborhood here to the Blue Hills.  At the Blue Hills SC showed off some great trails.  Thanks SC!

Temps were from 32 to 34 F.   Sunny.  Frosty mud.  With a light wind.  Minus winter boots, I think I have most of my winter riding  gear all set.

SC reported these ride stats:  We did 15.75 miles in about 90 minutes of pedalling time.


Happy Trails!

JT

Friday, December 7, 2012

c sharp enum examples


Using enumeration in your code is a quick way to make your code more readable. 

Declare a new type

 private enum _medTypes { newMed, changeMed, stopMed }; //newMed =0, changedMed = 1, stopMed =2

Declare a variable of your new type

 private _medTypes _medType;



Converting an int to your new type

_medType = (_medTypes)int.Parse(Request.QueryString["medType"]);


Testing your new type

if (_medType == _medTypes.newMed || _medType == _medTypes.changeMed)

switch(_medType)
        {
            case _medTypes.newMed:
                msgSpan.InnerHtml = @"Meds written since ED Reg date default as new. 
" +
                          "To exclude a medication from appearing on the discharge note the user needs to uncheck the new box.";
                medsGridView.Columns[0].Visible = true;
                break;
            case _medTypes.changeMed:
                msgSpan.InnerHtml = @"Medication changes must be made in LMR.";
                medsGridView.Columns[1].Visible = true;
                break;
            case _medTypes.stopMed:
                msgSpan.InnerHtml = @"Meds discontinued since the ED Reg date are displayed below.";
                medsGridView.Columns[2].Visible = true;
                break;
            default:
                break;
        }


Thursday, November 15, 2012

c# Generic List sorting

Here's a quick code snip of sorting a generic list of object, by a DateTime object property in descending order.

1.  Your class has to inherit IComparable
2.  Implement IComparable's CompareTo method
3. After your generic list of objects is built, then call the lists .Sort method.

In this code I needed the LmrMed's serviceDate sorted in descending order.  The Sort method does not create a new list, it changes the order of the nodes in the current list.

I found this article helpful in learning about c# generic list sorting:  http://www.codedigest.com/Articles/CSHARP/84_Sorting_in_Generic_List.aspx


public class LmrMed : IComparable<LmrMed>


    {
        public int recId { get; set; }
        public string medText { get; set; }
        public DateTime? startDate { get; set; }
        public DateTime? endDate { get; set; }
        public DateTime serviceDate { get; set; }

        public LmrMed(int recId, string medText, DateTime startDate, DateTime endDate, DateTime serviceDate)
        {
            this.recId = recId;
            this.medText = medText;
            this.startDate = startDate;
            this.endDate = endDate;
            this.serviceDate = serviceDate;
        }

        public int CompareTo(LmrMed lm)
        {
            return lm.serviceDate.CompareTo(this.serviceDate);
        }



List<LmrMed> lmrMeds = GetMeds(_mrn);
 
            lmrMeds.Sort();

Friday, November 2, 2012

upgrade

I had been thinking about upgrading the stump jumper. This Halloween my wife asked me if I wanted to go to the bike barn. I said sure!  just to look!   Well I ended up getting a 29er Stump Jumper hard tail.
My wife bought it for me. I am a lucky guy!

I was concerned about going to a 29 from a 26. I thought I would feel top heavy.  At the bike barn Kevin took time to explain to me how that's not true. He said I'ts more stable. And it will ride though more stuff than a 26 can. How he explained things was much more detailed and elegant.  

I tried it out in the parking lot, and I wanted the bike that day.  We went home with our new ride.

I took it out on some local trails, and this ride is awesome! I feel I'm riding faster with ease, and I have more balance. Plus I don't feel like I'm inside a bike anymore, it's quite a natural fit.

Thanks to my wonderful wife for such an awesome gift!  Staying fit by mountain biking pays great dividends to all.



Tuesday, October 30, 2012

asp.net Using WebHandler to generate images on Server Side and send to Client




I had to create dynamic 2D Data Matrix bar code images on the server and send to the client for MeadCo printing.  Found out you can do this by using Web Handlers. 

This is a simple example, the value of the bar code is hardcoded.  Since you can pass query strings from the client to the handler, there is the possibility of creating dynamic barcodes.  This I will be doing using this prototype as a framework.   




WebHandler:

<%@ WebHandler Language="C#" Class="ImageHandler" %>

using System;
using System.Web;
using System.IO;
using System.Drawing;

public class ImageHandler : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {

        //NOTE:  You can get parameters from the client using Query Strings
        
        IEC16022Sharp.DataMatrix dm = new IEC16022Sharp.DataMatrix("<00007>");


        context.Response.ContentType = "image/bmp";
        

        using (Bitmap image = dm.Image)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                ms.WriteTo(context.Response.OutputStream);
            }
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}


Client code:
The code below shows embedded html being generated (This is used for printing).  The option is there just to place an img element within the html document and set it’s src attribute to the name of your handler.




Friday, October 19, 2012

GridView: Getting access to it's datasource properties via DataKeyNames


Client:
<asp:GridView ID="followUpAppointments" CssClass="Report" runat="server" AutoGenerateColumns="false" Width="270"  AllowPaging="false" AlternatingRowStyle-CssClass="DataAlternateRow" CellPadding="1" CellSpacing="1" HeaderStyle-HorizontalAlign="Center" EmptyDataText="No Results."             DataKeyNames="Id,Name,Description,FollowUpList" >
                <Columns>
                    <asp:TemplateField ItemStyle-Width="10">
                        <ItemTemplate>
                            <center>
                                <asp:CheckBox ID="selectedRowCb" runat="server" />
                            </center>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="Name" HeaderText="Follow Up Appointments" ItemStyle-Width="250"
                        ItemStyle-Wrap="true" />                    
                </Columns>
            </asp:GridView>


Class:
public class FollowUp
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public bool FollowUpList { get; set; }
 
        public FollowUp(int id, string name, string description, bool followUpList)
        {
            this.Id = id;
            this.Name = name;
            this.Description = description;
            this.FollowUpList = followUpList;
        }
    }



Accessing on Server side:

for (int i = 0; i < followUpAppointments.Rows.Count; i++)
        {
            GridViewRow row = followUpAppointments.Rows[i];
            bool isChecked = ((CheckBox)row.FindControl("selectedRowCb")).Checked;
 
            if (isChecked)
            {
                int id = (Int32)followUpAppointments.DataKeys[i]["Id"];
                string name = followUpAppointments.DataKeys[i]["Name"].ToString();
                string description = followUpAppointments.DataKeys[i]["Description"].ToString();
                bool followup = (bool)followUpAppointments.DataKeys[i]["FollowUpList"];
 
                _selectedServices.Add(new FollowUp(id,name,description,followup));
            }
 
 
        }


Wednesday, October 17, 2012

JSON serialize with c# deserialize with javascript via pop up window

I created a modal window pop up that shows search results in a gridview. In this gridview there is a checkbox for each row returned. The user can select any rows they want by checking the associated checkbox. One way to send the user's selected data back to the parent window is to use JSON.  Below are code snips on how to to do this.

The c# code serializes the generic list of Icd9 objects into a JSON string.  This new JSON string is sent to a hidden input on the client side. Upon unload of this child window, the window return value is set to the value of the hidden input that was populated on server side. The parent window client code then evals the returned window value.  Once this has been done the value is copied to collection of Icd9 objects.  I for loop my way though this collection accessing the Name and Code properties.



Note:  This works in IE.  I think IE is only browser that supports showModalDialog
           This should work in other browsers if you use winodow.open etc.


Class:
public class Icd9
    {
        public string Name { get; set; }
        public string Code { get; set; }

        public Icd9(string name, string code)
        {
            this.Code = code;
            this.Name = name;
        }

    }


Child Window:
Server side:
using System.Web.Script.Serialization;
 
...
List<CommonTasks.Icd9> selectedCodes = new List<CommonTasks.Icd9>();
 
        for (int i = 0; i < icdGridView.Rows.Count; i++)
        {
            GridViewRow row = icdGridView.Rows[i];
            bool isChecked = ((CheckBox)row.FindControl("selectedRowCb")).Checked;
 
            if (isChecked)
            {
 
                selectedCodes.Add(new CommonTasks.Icd9(icdGridView.Rows[i].Cells[2].Text, icdGridView.Rows[i].Cells[1].Text));
            }
 
 
        }
 
        JavaScriptSerializer js = new JavaScriptSerializer();
        string str = js.Serialize(selectedCodes);
 
        hdnIcd.Value = str;
 
...
 


Client:
 function setWindow_return() {
            var selectedCodes = document.getElementById("hdnIcd");
            window.returnValue = selectedCodes.value;          
        }


Parent Window:
Client:
function GetIcd9()
  {     
    var searchText = document.getElementById("f129").value;
    var url = "Icd.aspx?searchText=" + searchText;
        
    if (searchText.length==0)
        alert(" no value retrieved ");
    else {
          var results = 
           window.showModalDialog(url,"","center:yes;dialogWidth:775px;dialogHeight:480px;resizable:no;status:no;;help:no");
           if(results.length > 0)
           {
             var data = eval(results); 
           
             if(data.length > 0)
             {   
               var icd9Text = "";
               var icd9Code = "";
 
               for(i=0; i < data.length; i++)
               {               
                 icd9Text += data[i].Name + " ";
                 icd9Code += data[i].Code + ",";     
               }
 
               document.getElementById("petsText").value += icd9Text;
               document.getElementById("hidIcd9Code").value += icd9Code;
 
             }
           }
 
         }
  }