Tuesday, November 13, 2007

network problem?

Some DOS commands that can help determine network problems:
ping, tracert, nslookup, netstat

C:\Documents and Settings\unplug1.6>ping tttx-inst1.com

Pinging tttx-inst1.com [182.11.110.111] with 32 bytes of data:

Request timed out.
Request timed out.
Request timed out.
Request timed out.

Ping statistics for 182.11.110.111:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),


C:\Documents and Settings\unplug1.6>tracert minn

Tracing route to minn.xx.com [182.11.110.111]
over a maximum of 30 hops:

1 1 ms <1 ms <1 ms 182.11.110.111
2 * * * Request timed out.
3 25 ms 23 ms 24 ms 192.168.16.160
4 24 ms 23 ms 25 ms minn.xx.com [182.11.110.111]

If there were a problem with an ip, you can specify which ip to use in tracert:
tracert -j 180.16.116.116 oh-01.xx.com

Tracing route to oh-01.xx.com [180.16.116.116]
over a maximum of 30 hops:

1 * * * Request timed out.
2 * * * Request timed out.

Trace complete.

C:\Documents and Settings\unplug1.6>nslookup 192.168.16.160
Server: oh-01.xx.com
Address: 182.16.160.16

*** oh-01.xx.com can't find 192.168.16.160: Non-existent domain

Friday, November 9, 2007

C# threading example

This is a simple, but handy multi-thread example. The two "foreach" sections at the end is where the hip happens. All process' will start at the same time and "Main" will not exit until all threads have been joined.

static void Main(string[] args)
{
  ArrayList threads = new ArrayList();

  try
  {
    if(args.Length > 0)
  {

  switch(args[0].ToUpper())
  {
    case "case1" :
    {
      case1Export case1 = new case1Export();
      Thread t1 = new Thread(new ThreadStart(case1.Start));
      threads.Add(t1);
      break;
    }
    case "case2" :
    {
      case2Export case2 = new case2Export();
      Thread t2 = new Thread(new ThreadStart(case2.Start));
      threads.Add(t2);
      break;
    }
    case "case3" :
    {
      case3Export case3 = new case3Export();
      Thread t3 = new Thread(new ThreadStart(case3.Start));
      threads.Add(t3);
      break;
    }
    default :
      break;
    }
  }

  foreach(Thread thread in threads)
  {
    thread.Start();
  }

  foreach(Thread joinThread in threads)
  {
    joinThread.Join();
  }
}

Thursday, October 11, 2007

Print page with simple script

It is simple to add print capabilities to a page. This would be useful if you are opening a page without menu options.

function printpage()
{
  window.print();
}


<input type="button" id="PrintBtn" name="PrintBtn" value="Print" class="Btn" onclick="printpage();">

Wednesday, September 12, 2007

Minutia of a Javascript Checkbox

An overlooked aspect of the Javascript checkbox is, unlike it's asp:checkbox brother, you can group them together with one name and view the values on the server side. In this example, a checkbox is placed in an asp:datagrid. An asp:repeater would work the same way.

This would go in the datagrid/repeater:
<input type="checkbox" name="VALUEChkBx" value='<%#DataBinder.Eval(Container.DataItem, "aValue")%>' onclick="return VALUEChkBx_Click(this, event);">
----------------------------------------------------------------------------
On the page you could add some javascript functionality by taking advantage of the onclick attribute:
function VALUEChkBx_Click(src, e)
{
  var f = src.form;
  f.EmailBtn.disabled = true;

  for (i=0, j=f.length; i<j; i++)
  {
    var ele = f[i];
    if (ele.name == "VALUEChkBx" && ele.checked)
    {
      f.EmailTxt.disabled = false;
      f.EmailBtn.disabled = false;

      break;
    }
  }
}
---------------------------------------------------------------------------
Now for the intricate part, the code behind:
string valueList = Request.Form["VALUEChkBx"];
if (valueList != null && valueList.Length != 0)
{
  string [] aList = valueList.Split(',');

  for(int i=0; i<aList.Length; i++)
  {
    string value = aList[i].ToString();

**Notice that aList holds each individual value of the checkboxes that were checked on the page. Take special note to request the checkbox(s) using the form - Request.Form["VALUEChkBx"]

Thursday, September 6, 2007

Windows XP Cut and Paste not working?

If you find yourself having trouble transferring data using the antiquated cut and paste feature of Windows and find it's not working, you have too many programs running. No, I don't have an MSDN link backing my statement, but if you close some excess programs, your cut and paste will function again.
If anyone has a link explaining this jacked performance, let me know.

Wednesday, August 29, 2007

keyCode table for Unicode standard

The following is a table defining the keyCode for particular key presses
With this table you can catch key presses using Javascript with the following:
//The javascript functions:
function InKeyRange(e, min, max)
{
  if (min == null)
    min = 0;

  if (max == null)
    max = 65000;

  if (max < min)
  {
    var tmp = min;
    min = max;
    max = tmp;
  }

  var keyCode = (is_nav) ? e.which : e.keyCode;
  return ((min <= keyCode) && (keyCode <= max));
}

// test if the keycode of the key pressed is a numeric key 0-9
function IsNumericKey(e)
{
  return InKeyRange(e, 48, 57);
}

//Call javascript functions from within a textbox
<asp:TextBox Runat="server" onkeypress="return IsNumericKey(event);" Width="35" ID="TB1"></asp:TextBox>

If the key pressed is not within the givin value, the textbox won't accept the input.

Now here is the table defining the keyCodes:









a = 97
b = 98
c = 99
d = 100
e = 101
f = 102
g = 103
h = 104
i = 105
j = 106

k = 107
l = 108
m = 109
n = 110
o = 111
p = 112
q = 113
r = 114
s = 115
t = 116

u = 117
v = 118
w = 119
x = 120
y = 121
z = 122
0 = 48
1 = 49
2 = 50
3 = 51

4 = 52
5 = 53
6 = 54
7 = 55
8 = 56
9 = 57
' = 39
, = 44
- = 45
. = 46

/ = 47
: = 58
= = 61
[ = 91
\ = 92
] = 93
` = 96
return = 13
escape = 27
space bar = 32

Tuesday, August 28, 2007

SQL raising errors as part of transaction

Here is an example of a sql stored procedure with a transaction which can raise an error and return if some condition is met, it will also catch an error from any called procedure and roll-back the transaction if necessary.


BEGIN TRAN

EXEC dbo.some_sql_function @variable

IF(some_condition)
BEGIN
  RAISERROR ('this %s doesn''t exist.', 16, 1, @errordesc)
  RETURN
END

IF (@@ERROR = 0)
BEGIN
  COMMIT TRAN
  SELECT 1
END
ELSE
BEGIN
  ROLLBACK TRAN
  SELECT -1
END