January 21, 2011

Upgrading XP by SP3 on Laptop

Filed under: windows plateform Himanshu @ 7:34 pm

I was trying to apply Windows XP SP3 through windows auto updates.  Auto update repeatedly reported that it couldn’t apply SP3 update. After digging further, I found that update was failing because laptop was not on AC supply.

Two points to note:

  1. On laptop, shouldn’t apply windows update while battery powered
  2. Interesting to understand that either xp auto update do not have way to report correct problem and instead just say “Could not apply following updates”, or maybe SP3 installer is not rightly coded for auto update.

January 20, 2011

Thought, Suggestion, Quote,

Filed under: random thoughts Himanshu @ 2:20 pm

Bad news is better than no communication

January 8, 2011

Aggregation by rolling week

Filed under: tsql Himanshu @ 5:37 pm

In my current project, we had interesting problem, customer wants to see few data aggregation by rolling week and not year week. Rolling week mean say today is ‘Saturday’, data should aggregate by all week ending ‘Saturday’, but if it was ‘Tuesday’, data should aggregate by by all week ending ‘Tuesday’.  When I heard this for first time, I thought this going to end up real big and complex procedure. But to my surprise it’s not:

select customerId, bSaleDate as SaleDate, SUM(Amount) as Amount
from
(
    select distinct
        SaleByCustomerAndDate.customerId,
        SaleSevenDayRange.SaleDate as bSaleDate,
        SaleByCustomerAndDate.SaleDate as aSaleDate,
        SaleByCustomerAndDate.Amount as Amount
    from
    (
        select
            customerId,
            SaleDate,
            SUM(Amount) as Amount
        from
            Sale
        group by
            customerId,
            SaleDate
    )
    as SaleByCustomerAndDate inner join
    (
        select
            customerId,
            SaleDate,
            DATEADD(DAY,-6,SaleDate) as LastSevenDay
        from Sale
    ) as SaleSevenDayRange on SaleByCustomerAndDate.SaleDate
        between
            SaleSevenDayRange.LastSevenDay
            and
            SaleSevenDayRange.SaleDate
    and SaleByCustomerAndDate.customerId = SaleSevenDayRange.customerId
) as c
group by
    customerId,
    bSaleDate
order by customerId, SaleDate

January 5, 2011

ASP.NET Postback on table row click

Filed under: .net,asp.net Himanshu @ 8:34 am

When you need to go back to the server for further processing on clicking of a html element, for example on html table row click, below code may help you provide such functioning in ASP.NET.

Well, actually to allow control to support bubbling of the events, and allow user of the control to specify CommandName and CommandArgument while being used in template controls,  there is some extract effort, essentially will need to implement IButtonControl. Let’s see the code below that I have implemented to provide function of  selecting row when clicked on it.

   1:  [ToolboxData("<{0}:ListViewRowClickCommand  CommandName=\"Select\" runat=\"server\"></{0}:ListViewRowClickCommand>")]
   2:  public class ListViewRowClickCommand : HtmlTableRow, IButtonControl, IPostBackEventHandler
   3:  {
   4:      public bool DisableCommand { get; set; }
   5:      protected override void Render(HtmlTextWriter writer)
   6:      {
   7:          writer.WriteBeginTag("tr");
   8:          if (ID != null)
   9:              writer.WriteAttribute("id", ClientID);
  10:          if (!DesignMode)
  11:          {
  12:              if (!DisableCommand)
  13:                  writer.WriteAttribute("onclick", "javascript:" +
  14:                      Page.ClientScript.GetPostBackEventReference(this, CommandArgument));
  15:          }
  16:          Attributes.Render(writer);
  17:          writer.Write(HtmlTextWriter.TagRightChar);
  18:  
  19:          RenderChildren(writer);
  20:          writer.WriteEndTag("tr");
  21:      }
  22:  
  23:      public bool CausesValidation
  24:      {
  25:          get { return (bool)(ViewState["CausesValidation"] ?? true); }
  26:          set { ViewState["CausesValidation"] = value; }
  27:      }
  28:  
  29:      public string CommandArgument
  30:      {
  31:          get { return (string)ViewState["CommandArgument"]; }
  32:          set { ViewState["CommandArgument"] = value; }
  33:      }
  34:  
  35:      public string CommandName
  36:      {
  37:          get { return (string)ViewState["CommandName"]; }
  38:          set { ViewState["CommandName"] = value; }
  39:      }
  40:  
  41:      public string PostBackUrl
  42:      {
  43:          get { return (string)ViewState["PostBackUrl"]; }
  44:          set { ViewState["PostBackUrl"] = value; }
  45:      }
  46:  
  47:      public string ValidationGroup
  48:      {
  49:          get { return (string)ViewState["ValidationGroup"]; }
  50:          set { ViewState["ValidationGroup"] = value; }
  51:      }
  52:  
  53:      public event EventHandler Click;
  54:      public event CommandEventHandler Command;
  55:  
  56:      public void RaisePostBackEvent(string eventArgument)
  57:      {
  58:          if (CausesValidation)
  59:          {
  60:              if (Page.IsPostBack)
  61:                  Page.Validate();
  62:              if (!Page.IsValid)
  63:                  return;
  64:          }
  65:  
  66:          OnClick(EventArgs.Empty);
  67:          OnCommand(new CommandEventArgs(CommandName, CommandArgument));
  68:      }
  69:  
  70:      protected virtual void OnCommand(CommandEventArgs eventArgs)
  71:      {
  72:          if (Command != null)
  73:              Command(this, eventArgs);
  74:  
  75:          RaiseBubbleEvent(this, eventArgs);
  76:      }
  77:  
  78:      protected virtual void OnClick(EventArgs eventArgs)
  79:      {
  80:          if (Click != null)
  81:              Click(this, eventArgs);
  82:      }
  83:  }

Above control can be used as below:

   1:  ...
   2:  
   3:  <asp:ListView ID="listViewOfSomething" runat="server" OnSelectedIndexChanging="OnSelectedIndexChanging">
   4:      <LayoutTemplate>
   5:          <table id="htmlTableOfSomething" >
   6:              <tbody>
   7:                  <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
   8:              </tbody>
   9:          </table>
  10:      </LayoutTemplate>
  11:      <ItemTemplate>
  12:          <vdd:ListViewRowClickCommand ID="ListViewRowClickCommand" runat="server"
  13:              CommandName="Select" Class="SomeCssClassForRow" >
  14:              <td class="CssClassForColumn">
  15:  
  16:  ...

Feel free to put comments in case if things are not clear.

Powered by WordPress