Friday, December 16, 2011

DotNetNuke Lesson Learned

There are still modules out there using the old setting style for connection strings:
 <appSettings>  
   <add key="SiteSqlServer" value="Server=(local);Database=DNN;Integrated Security=True" />  
 </appSettings>  
I spent the better part of a day and a half trying to diagnose why all the modules from one particular 3rd party vendor wouldn't work on my box... lesson learned.

References NOT Available Upon Request

After receiving a promising resume for a job request, I scheduled an interview with the candidate. The interview itself was fairly straightforward, having all the standard questions about .NET, C# and SQL Server.

The candidate seemed fairly knowledgeable although I would probably get them to do a technical interview if we decided to move forward.

I thanked the individual for coming in, and asked them to forward me 2 or 3 references.

I was somewhat taken aback by their response. “I prefer to get my jobs on my own. I don’t like to bother my former employers with those details.”

I explained to them that we require references to verify their employment, skills and experience. Again, they responded with “I prefer to get my jobs on my own.”

I wasn’t exactly sure what to say, so I simply told them that it’s standard practice and that we would not be able to consider them for a position without references. Begrudgingly, I was told that they'd be sending an email with some references.

Needless to say, I never received a follow-up email.


The Messy Vacation Request

I've worked as both an employee and as a director, so I know how important it is to be sensitive to people's need to take time off and decompress.  Vacations are an inconvenience of course, because they impact project timelines, but booked far enough in advance and approved prior to scheduling and incurring travel expenses will ensure that the impact is minimized.

That is, until you’ve met a certain character whom I had in my employ. As a senior software developer, in charge of a key component to our system, and like everyone else in the company, this individual was expected to book their vacation well in advance (3 months or more).

I received a vacation request email from the individual around the end of April.  The request was for the first 18 business days of September off, as this individual and their family would be flying to Europe.

I had no problem with the request, and after checking with their PM, I sent an approval email. I also cc:’d HR and entered the time into our timesheet system.

Now, fast forward a couple of months.

It's now mid-August, and this individual had been having some troubles on a particular project they were working on.  Things were definately NOT going well, they were well behind and burning through our budget like there was no tomorrow.

It was a Tuesday afternoon, and we’d just finished having a management meeting to discussed the situation. We felt that if he remained heads down for the next 2 weeks, there was a good possibility we’d be able to meet the required deadline and this individual could enjoy their vacation knowing things were well in hand.

That is, until about 2:30pm, when this individual stopped by my desk to remind me that they were starting their vacation at the end of the day.

At first I was rather puzzled. I remarked that I understood this individual to be taking vacation at the start of September. The response was, “No, I asked to start my vacation end of day today.” Considering the circumstances, I was taken a back somewhat. I reiterated my previous statement and assured them that I had approved the dates, and added them to the timesheet system.

They looked at me rather blank faced for a moment, then said, “Well I’ve already booked the tickets for my family and we leave tomorrow morning so….”

I told them I would have to review things and would get back to  them shortly.  As they went back to their desk, I quickly reviewed my emails, and sure enough, the dates I approved were for the beginning of September for 18 days.

I discussed the matter with both our Senior PM and the department head, both of whom were take aback somewhat.  In the midst of this, the individual came back over and informed us that they'd gotten their dates mixed up and was it all right to take the time off starting end of day today instead.

We discussed the matter, but we pretty much knew we couldn't simply deny this individual the timeoff considering the situation, so the decision was made to adjust the schedule and allow the individual to take the time off.

Fast forward 18 business days.

Monday morning comes around, and this individual is nowhere to be found.  I checked my email, and there’s a message saying “Hi, enjoying my vacation, wow this has been great.” Our plane will be leaving this evening at such and such a time, I’ll see you Tuesday. Funny, I don’t remember approving a 19th vacation day off.

So Tuesday morning comes around, and again, this individual is nowhere to be found.  All day, no emails, no phone calls, nothing. Funny, I don’t recall approving a 20th vacation day off either.

So now we’re on to Wednesday… you keeping up? Around noon, I get an email: “Hey there, we’re in Seattle and I’ll be in tomorrow.” Funny thing was, the email message didn’t come from this person's private email account like it had previously, instead it came from their company account. We didn't have webmail, and the only way it’s accessible from the outside is through our VPN... hmmm.  Well, maybe the person brought their laptop to Europe with them, or maybe they were already at home?

Okay, this is no longer funny, I definately did NOT approve a 21st vacation day off.  This individual  finally made it into work on Thursday. Four full weeks (plus a day) since they last graced us with their presence. Needless to say, their tenure at our organization did not last too many weeks longer.


Thursday, December 1, 2011

Creating an Editable GridView inside a ListView in XAML

So it's been a while since I posted last, but recently I had the opportunity to do some serious XAML binding stuff, which I thought I'd share with you. If you've ever wanted an easy way to create an editable gridview inside a listview, it can seem like a pretty daunting task, but actually, it's really not that tough. You can setup a binding scenario that will do 80% of the work for you. Try the following out for size: First, the XAML code:
 <Window x:Class="EditableGridViewExample.Window1"  
     xmlns:local="clr-namespace:EditableGridViewExample"  
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
     Title="Window1">  
  <Window.Resources>  
   <local:BoolToVisibilityConverter x:Key="b2v" />  
   <Style TargetType="{x:Type TextBlock}" x:Key="TextBlockStyle">  
    <Setter Property="Visibility">  
     <Setter.Value>  
      <MultiBinding Converter="{StaticResource b2v}" ConverterParameter="False" >  
       <Binding ElementName="EditModeCheckBox" Path="IsChecked" />  
       <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}" Path="IsSelected" />  
      </MultiBinding>  
     </Setter.Value>  
    </Setter>  
    <Setter Property="VerticalAlignment" Value="Center" />  
   </Style>  
   <Style TargetType="{x:Type TextBox}" x:Key="TextBoxStyle">  
    <Setter Property="Visibility">  
     <Setter.Value>  
      <MultiBinding Converter="{StaticResource b2v}" ConverterParameter="True" >  
       <Binding ElementName="EditModeCheckBox" Path="IsChecked" />  
       <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}" Path="IsSelected" />  
      </MultiBinding>  
     </Setter.Value>  
    </Setter>  
    <Setter Property="VerticalAlignment" Value="Center" />  
   </Style>  
  </Window.Resources>  
  <Grid>  
   <Grid.RowDefinitions>  
    <RowDefinition Height="Auto" />  
    <RowDefinition Height="*" />  
   </Grid.RowDefinitions>  
   <CheckBox x:Name="EditModeCheckBox" Content="Edit Mode" />  
   <ListView Grid.Row="1" x:Name="WindowListView" ItemsSource="{Binding}">  
    <ListView.View>  
     <GridView>  
      <GridViewColumn>  
       <GridViewColumnHeader Tag="ColumnA" Content="Object" />  
       <GridViewColumn.CellTemplate>  
        <DataTemplate>  
         <Grid>  
          <TextBlock Text="{Binding Path=ColumnA}" Style="{StaticResource TextBlockStyle}" />  
          <TextBox Text="{Binding Path=ColumnA}" Style="{StaticResource TextBoxStyle}" />  
         </Grid>  
        </DataTemplate>  
       </GridViewColumn.CellTemplate>  
      </GridViewColumn>  
      <GridViewColumn>  
       <GridViewColumnHeader Tag="ColumnB" Content="Type" />  
       <GridViewColumn.CellTemplate>  
        <DataTemplate>  
         <Grid>  
          <TextBlock Text="{Binding Path=ColumnB}" Style="{StaticResource TextBlockStyle}"/>  
          <TextBox Text="{Binding Path=ColumnB}" Style="{StaticResource TextBoxStyle}" />  
         </Grid>  
        </DataTemplate>  
       </GridViewColumn.CellTemplate>  
      </GridViewColumn>  
     </GridView>  
    </ListView.View>  
   </ListView>  
  </Grid>  
 </Window>  
Now, the codebehind (I put everything in one file to make it easy to use):
 using System;  
 using System.Collections.ObjectModel;  
 using System.Windows;  
 using System.Windows.Data;  
   
 namespace EditableGridViewExample  
 {  
  public class ListItems : ObservableCollection<ListData>  
  {  
   /// <summary>  
   /// Initializes a new instance of the <see cref="ListItems"/> class.  
   /// </summary>  
   public ListItems()  
   {  
    this.Add(new ListData() { ColumnA = "apple", ColumnB = "fruit" });  
    this.Add(new ListData() { ColumnA = "jaguar", ColumnB = "animal" });  
    this.Add(new ListData() { ColumnA = "lullaby", ColumnB = "music" });  
    this.Add(new ListData() { ColumnA = "monkey", ColumnB = "animal" });  
    this.Add(new ListData() { ColumnA = "orange", ColumnB = "fruit" });  
    this.Add(new ListData() { ColumnA = "whale", ColumnB = "mammal" });  
    this.Add(new ListData() { ColumnA = "coathanger", ColumnB = "other" });  
   }  
  }  
   
  public class BoolToVisibilityConverter : IMultiValueConverter  
  {  
   /// <summary>  
   /// Converts source values to a value for the binding target. The data binding engine calls this method when it propagates the values from source bindings to the binding target.  
   /// </summary>  
   /// <param name="values">The array of values that the source bindings in the <see cref="T:System.Windows.Data.MultiBinding"/> produces. The value <see cref="F:System.Windows.DependencyProperty.UnsetValue"/> indicates that the source binding has no value to provide for conversion.</param>  
   /// <param name="targetType">The type of the binding target property.</param>  
   /// <param name="parameter">The converter parameter to use.</param>  
   /// <param name="culture">The culture to use in the converter.</param>  
   /// <returns>  
   /// A converted value.If the method returns null, the valid null value is used.A return value of <see cref="T:System.Windows.DependencyProperty"/>.<see cref="F:System.Windows.DependencyProperty.UnsetValue"/> indicates that the converter did not produce a value, and that the binding will use the <see cref="P:System.Windows.Data.BindingBase.FallbackValue"/> if it is available, or else will use the default value.A return value of <see cref="T:System.Windows.Data.Binding"/>.<see cref="F:System.Windows.Data.Binding.DoNothing"/> indicates that the binding does not transfer the value or use the <see cref="P:System.Windows.Data.BindingBase.FallbackValue"/> or the default value.  
   /// </returns>  
   public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)  
   {  
    bool param = bool.Parse(parameter as string);  
    bool combined = true;  
    foreach (bool val in values) combined &= val;  
    return combined == param ? Visibility.Visible : Visibility.Hidden;  
   }  
   
   public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)  
   {  
    throw new NotImplementedException();  
   }  
  }  
   
  public class ListData : DependencyObject  
  {  
   public static readonly DependencyProperty ColumnAProperty =  
    DependencyProperty.Register("ColumnAProperty", typeof(string),  
    typeof(ListData), new UIPropertyMetadata(null));  
   
   public static readonly DependencyProperty ColumnBProperty =  
    DependencyProperty.Register("ColumnBProperty", typeof(string),  
    typeof(ListData), new UIPropertyMetadata(null));  
   
   /// <summary>  
   /// Gets or sets the column A.  
   /// </summary>  
   /// <value>  
   /// The column A.  
   /// </value>  
   public string ColumnA  
   {  
    get { return (string)GetValue(ColumnAProperty); }  
    set { SetValue(ColumnAProperty, value); }  
   }  
   
   /// <summary>  
   /// Gets or sets the column B.  
   /// </summary>  
   /// <value>  
   /// The column B.  
   /// </value>  
   public string ColumnB  
   {  
    get { return (string)GetValue(ColumnBProperty); }  
    set { SetValue(ColumnBProperty, value); }  
   }  
  }  
   
  public partial class Window1 : Window  
  {  
   /// <summary>  
   /// Initializes a new instance of the <see cref="MainWindow"/> class.  
   /// </summary>  
   public Window1()  
   {  
    InitializeComponent();  
   
    // bind datacontext of the list view to a new listitems observable collection  
    this.WindowListView.DataContext = new ListItems();  
   }  
  }  
 }  
   
Oh, and if you're wondering how I got it to format so nicely, I'm using this the following blogspot source code formatting tool.