Wednesday, June 06, 2007

Transform rows to columns


SELECT item_name, item_date,
MAX(DECODE(parameter_id, '81', string_value, NULL)) Ident,
MAX(DECODE(parameter_id, '82', string_value, NULL)) USAGE,
MAX(DECODE(parameter_id, '83', string_value, NULL)) Provenance,
MAX(DECODE(parameter_id, '84', string_value, NULL)) Spec
FROM ITEM_RFRNC, ITEM_PARAMS
WHERE ITEM_PARAMS.item_id= ITEM_RFRNC.Item_id AND
ITEM_RFRNC.item_id IN (
SELECT item_id FROM DATAPOINT WHERE group_master_id = 1661
AND variable_date > TO_DATE('5/9/2007 8:45:33 PM', 'mm/dd/yyyy hh:mi:ss PM')
AND variable_date < TO_DATE('6/1/2007 6:35:07 PM', 'mm/dd/yyyy hh:mi:ss PM')
) GROUP BY item_name, item_date
ORDER BY item_date

Sunday, April 15, 2007

How to use Number Types in c#

If you need fractions: Use decimal when intermediate results need to be rounded to fixed precision - this is almost always limited to calculations involving money. Otherwise use double - you will get the rounding of your calculations wrong, but the extra precision of double will ensure that your results will be good enough. Only use float if you know you have a space issue, and you know the precision implications. If you don't have a PhD in numeric computation you don't qualify. Otherwise: Use int whenever your values can fit in an int, even for values which can never be negative. This is so that subtraction operations don't get you confused. Use long when your values can't fit in an int. Byte, sbyte, short, ushort, uint, and ulong should only ever be used for interop with C code. Otherwise they're not worth the hassle.

Powered by Bleezer

Monday, April 09, 2007

Send Msmq and Xml message

Dim oMq As New MessageQueue(sQName)Dim oMsg As New Message oMsg.Label = DateTime.Now.ToString()oMsg.Body = sBodyoMsg.Formatter = New ActiveXMessageFormatter 'required in order to send xml as-it-isoMsg.Recoverable = True 'recoverable is set so that the message can be saved in disk to recover from server crashoMq.Send(oMsg)

oXmlDoc = New XmlDocument 'builds oXMLRoot = oXmlDoc.CreateElement("Data_Point")oXmlDoc.AppendChild(oXMLRoot)oXMLRoot.SetAttribute("MsgId", "103") 'mandatory oXMLRoot.SetAttribute("Version", "1") 'mandatory oXMLVarNode = oXmlDoc.CreateElement("Variable")oXMLVarsNode.AppendChild(oXMLVarNode)oXMLVarNode.SetAttribute("ID", "var1") 'variable nameoXMLVarNode.SetAttribute("Date", DateTime.Now.ToString()) 'to override item datetime stamp 'builds 334.45oXMLValueNode = oXmlDoc.CreateElement("Value")oXMLVarNode.AppendChild(oXMLValueNode)oXMLValueNode.InnerText = "234.54" 'datapoint value

Powered by Bleezer

How to use Timers in .NET

Excerpts From: http://msdn.microsoft.com/msdnmag/issues/04/02/TimersinNET/default.aspx

There are three different timer classes in the .NET Framework Class Library: System.Windows.Forms.Timer, System.Timers.Timer, and System.Threading.Timer. The first two classes appear in the Visual Studio® .NET toolbox window, allowing you to drag and drop both of these timer controls directly onto a Windows Forms designer or a component class designer. If you're not careful, this is where trouble can begin.

System.Windows.Forms.Timer will not raise events that occur while the UI thread is unable to process them, whereas System.Timers.Timer will queue them to be processes when the UI thread is available.

the instances of System.Threading.Timer are not inherently thread safe, given that it resides in the System.Threading namespace

Powered by Bleezer

Friday, March 30, 2007

How to call asp.net webservice with windows authentication set?

at the server:
1) create webservice using vs.net
2) create proxy.vb using webservice wsdl by issuing the command at vs.prompt:
wsdl /l:vb /o:Service1Proxy.vb http:/localhost/service1.asmx?wsdl

3) compile proxy
vbc /t:library /libpath:x:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\ /r:System.Web.Services.dll /r:System.Xml.dll /r:System.dll Service1Proxy.vb

4) install the webservice with "integrated windows authentication" enabled.

at the client:
1) reference webservice proxy assembly
2) call the web method
3) set webservice url.
obj.Url = "http://xxxx/webservice1/service1.asmx"

4) this will pass windows identity to web service.
add in web.config file of the asp.net page calling a web service.

5) if you wish to pass userid/pass directly from the client to webservice use this:
Dim cache As New CredentialCache
Dim cred As New NetworkCredential("userid", "pass", "domain")
cache.Add(New Uri(obj.Url), "NTLM", cred)
obj.Credentials = cache


6) do async call (so as no to tie up threads from the pool)
Dim res As IAsyncResult = obj.BeginHelloWorld(Nothing, Nothing)
Response.Write(obj.EndHelloWorld(res))

* also try Async HTTPHANDLER

Thursday, March 29, 2007

How to view all webparts in Sharepoint 2003?


http://xxx/siteurl/default.aspx?contents=1 (add ?contents=1 at the end)

you will see all the webparts available in the website

Tuesday, November 21, 2006

How to restart machine from a terminal session?


write the following in shut.vbs file and double-click it to run.
--
set x=CREATEOBJECT("shell.application")
x.ShutdownWindows()
---
This brings up the Shutdown Windows dialog from which one can choose to Restart, Stand By, Shut Down, etc

Monday, September 04, 2006

How to use JavaScript to highlight the active textbox by handling the onfocus and onblur client-side events, and dynamically changing the control appearance attributes or CSS style class.


When your data entry Web forms contain several textboxes, highlighting the textbox that has the input focus can significantly improve the user's experience. This technique is especially effective if your layout doesnbt make immediately clear what the tab order sequence is. For example, if you have multiple columns of textboxes, are they ordered horizontally or vertically? With a few lines of client-side JavaScript code you can easily change the background and foreground color of the active textbox, and thus give immediate feedback about the field that receives the user input. DHTML makes it possible to change the HTML elementsb style (font, colors, position) by means of the controlbs style property and its sub-properties. The following HTML code renders a textbox control that handles the onfocus client-side event to change its background and foreground colors, and the onblur event to restore the original colors when the control loses the focus:



id="txtFirstName"
onfocus= "this.style.backgroundColor='Yellow'; this.style.color = 'Blue';"
onblur="this.style.backgroundColor='Window'; this.style.color='WindowText';"
/>

Letbs see how you can dynamically add highlighting support to all ASP.NET server-side controls, instead of hard-coding it manually. All controls that inherit from WebControl have an Attributes collection to which you can add one or more attributename=value pairs; at render-time these pairs are embedded in the standard HTML code that the control generates. The listing below shows the VB.NET and C# methods that dynamically build a piece of JavaScript code that changes the backcolor/forecolor to the specified colors:



Sub SetInputControlColors(ByVal ctl As _
WebControl, ByVal backColor As Color, _
ByVal foreColor As Color, _
ByVal focusBackColor As Color, _
ByVal focusForeColor As Color)

Dim jsOnFocus As String = String.Format( _
"this.style.backgroundColor = '{0}';" _
& "this.style.color = '{1}';", _
focusBackColor.Name, focusForeColor.Name)
Dim jsOnBlur As String = String.Format( _
"this.style.backgroundColor = '{0}';" _
& "this.style.color = '{1}';", _
backColor.Name, foreColor.Name)
ctl.Attributes.Add("onfocus", jsOnFocus)
ctl.Attributes.Add("onblur", jsOnBlur)
End Sub





void SetInputControlColors(WebControl ctl,
Color backColor, Color foreColor,
Color focusBackColor, Color focusForeColor)
{
string jsOnFocus = string.Format(
"this.style.backgroundColor = '{0}';" +
"this.style.color = '{1}';",
focusBackColor.Name, focusForeColor.Name);
string jsOnBlur = string.Format(
"this.style.backgroundColor = '{0}';" +
"this.style.color = '{1}';",
backColor.Name, foreColor.Name);
ctl.Attributes.Add("onfocus", jsOnFocus);
ctl.Attributes.Add("onblur", jsOnBlur);
}


Using the SetInputControlColors method is trivial:



SetInputControlColors(txtFirstName, _
SystemColors.Window, _
SystemColors.WindowText, _
Color.Yellow, Color.Blue)





SetInputControlColors(txtFirstName,
SystemColors.Window,
SystemColors.WindowText,
Color.Yellow, Color.Blue);


Instead of manually calling SetInputControlColors for all the input controls on the form, you can use the SetAllInputControlsColors method shown below to change the onfocus/onblur styles for all the TextBox, ListBox and DropDownList controls in the form.



Sub SetAllInputControlsColors(ByVal parent As _
Control, ByVal backColor As Color, _
ByVal foreColor As Color, _
ByVal focusBackColor As Color, _
ByVal focusForeColor As Color)

For Each ctl As Control In parent.Controls
If TypeOf ctl Is TextBox OrElse _
TypeOf ctl Is ListBox OrElse _
TypeOf ctl Is DropDownList Then
SetInputControlColors(DirectCast( _
ctl, WebControl), _
backColor, foreColor, _
focusBackColor, _
focusForeColor)
Else
SetAllInputControlsColors(ctl, _
backColor, foreColor, _
focusBackColor, _
focusForeColor)
End If
Next
End Sub





void SetAllInputControlsColors(Control parent,
Color backColor, Color foreColor,
Color focusBackColor, Color focusForeColor)
{
foreach (Control ctl in parent.Controls)
{
if (ctl is TextBox || ctl is ListBox ||
ctl is DropDownList)
{
SetInputControlColors(
ctl as WebControl, backColor,
foreColor, focusBackColor,
focusForeColor);
}
else
{
SetAllInputControlsColors(ctl,
backColor, foreColor,
focusBackColor,
focusForeColor);
}
}
}


This method is recursive and affects also the controls nested in control containers. All you need to do now is putting the following code in the handler of the Page.Load event:



SetAllIputControlsColors(Me, _
SystemColors.Window, SystemColors.WindowText, _
Color.Yellow, Color.Blue)





SetAllIputControlsColors(this,
SystemColors.Window, SystemColors.WindowText,
Color.Yellow, Color.Blue);


The figure below shows the result in Internet Explorer.



Using client-side JavaScript isn't the only technique you can adopt to change the style of the active control. In fact, the approach just described works well only if the form contains a small number of fields. When the form has many controls, the amount of JavaScript generated for each control bloats the page's size and indirectly slows down its rendering. In such cases it is recommended that you define the normal and focus style by means of a Cascading Style Sheet (CSS) class in a separate stylesheet file, and write a shorter JavaScript code that just sets the control's className property when the control gets or loses the focus. Say that you define the following class in a .css file:


.ActiveInputControl
{
background-color: Red;
color: Yellow;
font-weight: bold;
}

You can call the SetAllInputControlsClassName method (defined at the end of the article) as shown here:



SetAllInputControlsClassName(Me, "", _
"ActiveInputControl")





SetAllInputControlsClassName(this, "",
"ActiveInputControl");


And the resulting HTML for a single control would be as follows:



onfocus="this.className = 'ActiveTextBox';"
onblur="this.className = '';"
/>

(Notice that when the control does not have the focus it just has no specific style class, and therefore it has the default style.) Not only is this technique faster when a form contains many fields, it is also more easily maintainable, because you can later change the focus style by simply providing a different CSS, without recompiling the ASP.NET application.



Sub SetInputControlClassName(ByVal ctl As _
WebControl, ByVal className As String, _
ByVal focusClassName As String)
Dim jsOnFocus As String = String.Format( _
"this.className = '{0}';", focusClassName)
Dim jsOnBlur As String = String.Format( _
"this.className = '{0}';", className)
ctl.Attributes.Add("onfocus", jsOnFocus)
ctl.Attributes.Add("onblur", jsOnBlur)
End Sub

Sub SetAllInputControlsClassName(ByVal parent _
As Control, ByVal className As String, _
ByVal focusClassName As String)
For Each ctl As Control In parent.Controls
If TypeOf ctl Is TextBox OrElse _
TypeOf ctl Is ListBox OrElse TypeOf
ctl Is DropDownList Then
SetInputControlClassName( _
DirectCast(ctl, WebControl),_
className, focusClassName)
Else
SetAllInputControlsClassName(ctl, _
className, focusClassName)
End If
Next
End Sub





void SetInputControlClassName(WebControl ctl,
string className, string focusClassName)
{
string jsOnFocus = String.Format(
"this.className = '{0}';", focusClassName);
string jsOnBlur = String.Format(
"this.className = '{0}';", className);
ctl.Attributes.Add("onfocus", jsOnFocus);
ctl.Attributes.Add("onblur", jsOnBlur);
}

void SetAllInputControlsClassName(Control parent,
string className, string focusClassName)
{
foreach (Control ctl in parent.Controls)
{
if (ctl is TextBox || ctl is ListBox ||
ctl is DropDownList)
{
SetInputControlClassName(
ctl as WebControl,
className, focusClassName);
}
else
{
SetAllInputControlsClassName(ctl,
className, focusClassName);
}

}
}