Tuesday, November 13, 2007

DLP Screen Damage :: How to Fix - Water damage

Problem: My daughter tried cleaning the screen of my Mitsubishi DLP with Windex. She used about 6 ounces of product, so you can imagine the amount of damage to the screen, as well as my state of mind. The product left a visible water line in the screen. Is it possible to fix this type of water damage (Windex)?

How was I going to get this problem fixed? Pay? I called a local TV Repair shop, and they quoted out $650.00. That seemed like a lot of money for this type of damage, so I searched and searched for a different solution.

None. I could pay to get it fixed, or try and fix it myself (damage already done).

I decided to try and fix it myself.

Solution:
I have a camcorder, so I recorded my steps. I am notorious for ending up with "where did this go" parts! Glad to report, I didn't need to review the movie to help put this DLP back together.

The Equipment List.
At least four hours of contiguous time.
Phillips head screw driver ( I call it the plus screw driver to my wife )
Blow Dryer (did not use heat, only for air circulation)
Micro-fiber cloth (3)
Bowl of 1/3 vinegar, 2/3 water
Two (2) people ... Don't try this solo. You may have to blame someone later!

Steps
Remove "screen housing" from DLP. (about 18 screws)

Placed "screen housing" onto a FLAT CLEAN surface.

Removed about 10 more screws to remove plastic screens from "screen housing".

There are two pieces of plastic protected by the "screen housing".

The front piece very hard and firm, and a piece ontop that is more paperish thin.

At the top of the two pieces of plastic, there seems to be a rail of metal connecting the two pieces. I didn't have to mess around that area, my damage was from the middle down.

You could see the WATER trapped between the two pieces of plastic.

Separate the two pieces (Have second person pull back the thin layer of plastic). Be very careful. The thin piece looks very fragile.

DO not pull back hard, you may rinkle the plastic, which would be a bad thing.

With a DAMP micro-fiber cloth, (using vinegar and water solution), start removing windex damage.

Wipe on with solution, with another micro-fiber cloth (water only), remove vinegar solution from hard plastic. Use blow-dryer to "speed up" the air drying process.

I had to repeat this step about 10 times to clean up the damaged plastic.

Now, you must clean the "thin plastic piece" ... be real careful. Repeat cleaning until you are happy with the results.

I used the blow-dryer (air only) for about 20 minutes, making sure I removed all the moisture.

After about 4hrs of cleaning, I decided to put the "screen housing" back together.

I then reattached the "screen housing" to my DLP.

I turned on the TV .... (EXCELLENT)

I just saved myself $650.00

--------------------------
The TV guy warned me before I started, this would invalidate my warranty. I proceeded on my own behalf.

Thursday, August 23, 2007

ASP.Net 2.0 - Web App Disabled

Problem:

How to let users know the web app is down for maintenance?

Solution:

Create a file in the root called: app_offline.htm

The contents of app_offline.htm is information to inform the user the site is down for maintenance.

That's it.

When you are ready to come back online, rename app_offline.htm to something else.

Wednesday, August 22, 2007

Visual Studio 2005 - Recent Projects

Problem:

On the "Start Page" of Visual Studios 2005, their is a section called "Recent Projects." This section will list projects you've worked on previously.

How to remove unwanted projects from this list.

Solution:
1) Load regedit
2) Locate registry entry

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\ProjectMRUList


3) Delete line items as necessay

Thursday, July 26, 2007

ASP.Net Web Form Disable Autocomplete

Problem:

Textbox control tries to auto complete entry.

A List of previously entered values are presented to the user to select.

How do you turn off this feature?


Solution:

<form method="post" autocomplete="off" >
</form>

that's all it takes.

one note. this disables auto complete for the entire form.

Wednesday, July 25, 2007

Visual Studio 2005 .: Go To Definition... I Don't Want The Metadata

Problem:
Programming in Visual Studio 2005.
Have a Web Form with some user controls.
Drop into the code behind of the web form, and then try and right click on a method of a user control. VS2005 will redirect you to some Metadata class object file.

Useless I say, useless. In this file, you will see the definitions for all the controls on the user web control.


Solution:
1) When you start up a new project in visual studio 2005
File -> New Project ->
Project Type :: select c#
Visual Studio Installed Templates: ASP.Net Web Application
2) Build Application
a) make sure bin folder exists
b) build web application

3) Most IMPORTANT STEP
a) open solution explorer
b) right click on "references"
c) click on add reference
d) click on "browse" tab
e) click on solution DLL in Bin folder


Visual Studio 2003 works fine. I guess the programmer who wrote this feature no longer works at Microsoft.

Monday, April 30, 2007

ASP.Net Custom Control accessing Master Page

Problem: I have a custom control (.ascx), and want to access a label control on the masterpage.

Default.aspx uses MasterPage.Master
CtrlChild.ascx is embedded into Default.aspx


Solution:
public partial class CtrlChild : System.Web.UI.UserControl
{

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{

MasterPage mp = (MasterPage)this.Parent.Page.Master;
Label lblUN = (Label)mp.FindControl("lbl_master_user_name");

}
}
}

Monday, April 9, 2007

HTML Radio Button - with Javascript

Problem:
How to determine if the selected radio button is the correct choice?

Solution:
First, lets look at the HTML envolved.

<form id="form1">
<input type="radio" name="rad1" value="bear">Bear

<input type="radio" name="rad1" value="pig">Pig

<input type="radio" name="rad1" value="boar">Boar

<input type="button" onclick="javascript:return check('pig');">
</form>

//
Notice the name attribute has the same value. Setting the name attribute to the same value makes a group. The user will only be able to select one value.


Second. Let's look at the javascript function called: check
<script language="javascript">

function check(ans)
{

var x = document.form1.elements["rad1"];

for(i=0; i < x.length; i++)
{
//alert(x[i].value);

if(x[i].checked == true)
{
if(x[i].value==ans)
{
alert('You are so smart');
return(true);
}
}

}
alert('Please try again!');
return(false);

}
</script>

Wednesday, February 21, 2007

C# .Net 2.0 Get MAC Address with WMI

Problem:

Need to get the MAC address from workstation where
software is installed.


Solution:

.Net 2.0
C#

Add Reference: System.Management


private string GetMacAddress()
{
//ManagementObjectSearcher namespace is System.Management
//add .Net reference

ManagementObjectSearcher query = null;
ManagementObjectCollection queryCollection = null;

try
{
query = new
ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration");

queryCollection = query.Get();


foreach (ManagementObject mo in queryCollection)
{
if ((bool)mo["IPEnabled"] == true)
{
//System.Diagnostics.Debug.WriteLine(mo.GetText(TextFormat.Mof));
string mac_address = mo["MacAddress"].ToString();

mo.Dispose();
queryCollection.Dispose();
query.Dispose();

return (mac_address);
}
}

return (string.Empty);

}
catch (System.Exception er)
{
System.Diagnostics.Debug.WriteLine(er.Message.ToString());
return (string.Empty);
}
}

Wednesday, February 7, 2007

C# 2.0 Web.Config read AppSettings ConfigurationManager

Problem:
How to read AppSetting in Web.Config file

<appSettings>
<add key="IsMaximized" value="True"/>
<add key="IsUsed" value="False"/>
</appSettings>

How do you get the value for the key = IsUsed?

Answer
There are three ways.

1) string sGet = ConfigurationManager.AppSettings.Get("IsUsed");

2) string sIndexer = ConfigurationManager.AppSettings["IsUsed"].ToString();

3)
using System.Collections.Specialized;

NameValueCollection nvc = ConfigurationManager.AppSettings;
string sNVC = nvc["IsUsed"];

C# Boxing and UnBoxing

Certification Test Question:

Give an example that demostrates unboxing?


Answer:
Value type to object (boxing)
object back to value type (unboxing)

Example:
object o = 123;
int one2three = (int)o;

----------
object pi = 3.14159265
double dPI = (double)pi;

unboxing is object to ValueType

MSDN:
Unboxing extracts the value type from the object.

Thursday, February 1, 2007

C# Function : Date to Julian

problem:
Function to convert Date into Julian format


solution:

private string Date2Julian(DateTime dt)
{
//julianDate YYYYnnn
// YYYY = 4 digit year
// nnn = number of days since january 1 of YYYY

// Jan 1, 2005 = 2005001
// Dec 31, 2005 = 2005365

//initialize variable
string sJulianDate=string.Empty;


sJulianDate = dt.Year.ToString()+
dt.DayOfYear.ToString().PadLeft(3,'0');

return (sJulianDate);
}

VBA :: ADODB Function to Connect to Access

Problem:
Need function to connect to an Access Database.

--make sure set a reference to ADO object in order to use
ADODB.Connection object

Solution:

Function cnConnectToAccessDB(ByVal sFileName As String) As ADODB.Connection
Dim CN As New ADODB.Connection
Dim sCS As String

'you must have ado 2.x installed on machine
' x = 5|6|7

'open this file in Exclusive mode
'comment this line out if you don't want exclusive connection
CN.Mode = adModeShareExclusive


'build connection string
sCS = "Provider=Microsoft.Jet.OLEDB.4.0;"
sCS = sCS & "Data Source=" & sFileName & ";"

'open connection
CN.Open sCS

'return to calling function
'adodb is an object, so you have to SET
Set cnConnectToAccessDB = CN
End Function

Wednesday, January 31, 2007

Sql Server 2005 - using SqlConnectionStringBuilder

Problem:
Method to connect to sql server 2005


Solution:

class attributes and accessor functions

private SqlConnection dbConn = null;


private string m_username = string.Empty;
private string m_password = string.Empty;
private string m_catalog = string.Empty;
private string m_datasource = string.Empty;
private string m_application = string.Empty;
private string m_version = string.Empty;
private bool m_IntegratedSecurity = false;

///
/// Name of user who has the appropriate connection privilges
///

public string User_Name
{
get { return (m_username); }
set { m_username = value; }
}

///
/// Password of user trying to connect
///

public string User_Password
{
get { return (m_password); }
set { m_password = value; }
}

///
/// Name of the catalog inside of SqlServer
///

public string DB_Catalog
{
get { return (m_catalog); }
set { m_catalog = value; }
}

///
/// Name of Server where SqlServer is installed
/// can use either the Name of the server or
/// the IP address
///

public string DB_Server
{
get { return (m_datasource); }
set { m_datasource = value; }
}

///
/// Name of application connecting to SqlServer
///

public string Application
{
get { return (m_application); }
set { m_application = value; }
}

public string DB_Version
{
get { return (m_version); }
set { m_version = value; }
}

public bool bool_IntegratedSecurity
{
get { return (m_IntegratedSecurity); }
set { m_IntegratedSecurity = value; }
}



public bool Connect()
{


//build new SqlConnectionStringBuilder object
System.Data.SqlClient.SqlConnectionStringBuilder csb =
new SqlConnectionStringBuilder();

try
{
//use Integrated Security
csb.IntegratedSecurity = this.bool_IntegratedSecurity;

if (this.DB_Server.Length > 0)
{
csb.DataSource = this.DB_Server;
}
else
{
this.int_error_level = ErrorLevel.Warning;
this.str_last_message = "Connection Error: You must provide the DataSource";
return (false);
}

if (this.Application.Length > 0)
{
csb.ApplicationName = this.Application;
}
else
{
csb.ApplicationName = "cRESqlServer";
}

if (this.DB_Catalog.Length > 0)
{
csb.InitialCatalog = this.DB_Catalog;
}
else
{
csb.InitialCatalog = "master";
}

csb.ConnectTimeout = 4;


this.dbConn = new SqlConnection();
this.dbConn.ConnectionString = csb.ConnectionString;
this.dbConn.Open();

this.DB_Version = this.dbConn.ServerVersion;


//success
return (true);
}
catch (System.Data.SqlClient.SqlException ex)
{
this.int_error_level = ErrorLevel.SevereError;
this.str_last_message = "Connect Error (SqlException):" + ex.Message.ToString();
this.HandleError();
return (false);
}
catch (System.Exception ex)
{
this.int_error_level = ErrorLevel.SevereError;
this.str_last_message = "Connect Error (Exception):" + ex.Message.ToString();
this.HandleError();
return (false);
}

}


#region ERROR LEVEL and LAST MESSAGE

private string mLastMessage = string.Empty;
private ErrorLevel mErrorLevel = 0;

public string str_last_message
{
get { return (mLastMessage); }
set { mLastMessage = value; }
}
public ErrorLevel int_error_level
{
get { return (mErrorLevel); }
set { mErrorLevel = value; }
}

#endregion

Tuesday, January 30, 2007

Datagrid - ItemTemplate, ToolTip

Problem:
Display a short description or abbreviation in a DataGrid column.

The short description or abbreviation by itself may not be general knowledge. Add the feature of allowing the user to hover over the value and receive a balloon help. The balloon help is a longer description of the abbreviation.



Solution:


<asp:TemplateColumn HeaderText="DataGridHeaderText">
<ItemTemplate>

<acronym title='<%# DataBinder.Eval(Container.DataItem, "FieldNameLongDescription") %> '>
<%# DataBinder.Eval(Container.DataItem, "FieldName") %>
</acronym>

</ItemTemplate>
</asp:TemplateColumn>

Monday, January 29, 2007

Convert Integer to Binary, Binary to Integer

Problem:
Convert integer to binary string

int binary
15 1111



Convert binary string to integer
binary int
1111 15



Solution:

//Convert binary string to an integer
int a_integer = Convert.ToInt32("1111", 2);

//convert an integer to a binary string
string a_binary_string = Convert.ToString(a_integer, 2);


Information:

How does the binary string "1111" equal 15

First, and most important, binary is read "right to left"

Second, each place holder position is 2^(position), zero position based
example:

(2^0)=1

if(a binary digit is 1) add to total

"1111" = (2^3) + (2^2) + (2^1) +(2^0)
^ -----
^
^
^ ------- ---- ---- ----
(2*2*2) (2*2) (2) (1)

8 + 4 + 2 + 1

= 15


"0010" = (0) + (0) + (2^1) + (0)
0 + 0 + 2 + 0

= 2

Convert DataTable to CSV

Problem:
User wants to view data in Excel.
1) Execute query against database.
2) Build DataTable object.
3) Populate Grid Control (DataGrid, GridView...)
4) Export DataTable to CSV file



Solution:
private int Export2CSV(DataTable dt,
string sFullPathAndFileName,
bool bNeedHeaderRow)
{

//usage history initialization
this.int_error_level = 0;
this.str_last_message = string.Empty;

try
{
System.IO.StreamWriter sw = new
System.IO.StreamWriter(sFullPathAndFileName,
false,
System.Text.Encoding.ASCII,
4096);


System.Text.StringBuilder buff = new System.Text.StringBuilder();

if (bNeedHeaderRow == true)
{
//build header
for (int c = 0; c < dt.Columns.Count; c++)
{
buff.Append(dt.Columns[c].ColumnName.ToString().ToUpper());
if (c < (dt.Columns.Count - 1))
{
buff.Append(",");
}
}

sw.WriteLine(buff.ToString());
buff.Length = 0;

}


for (int r = 0; r < dt.Rows.Count; r++)
{
for (int c = 0; c < dt.Columns.Count; c++)
{
switch (dt.Columns[c].DataType.ToString().ToUpper())
{
case "SYSTEM.STRING":
case "SYSTEM.DATETIME":
buff.Append("\"" + dt.Rows[r][c].ToString() + "\"");
break;
default:
buff.Append(dt.Rows[r][c].ToString());
break;
}

if (c < (dt.Columns.Count - 1))
{
buff.Append(",");
}
}

sw.WriteLine(buff);
buff.Length = 0;
}


sw.Flush();
sw.Close();
sw = null;

return (0);
}
catch (System.Exception ex)
{
this.int_error_level = 1;
this.str_last_message = ex.Message.ToString();
return (-1);
}
}

Wednesday, January 24, 2007

Drop Down List - Show Month Name and Year

Problem:
populate ddl with MonthName and Year with the previous 12 months

Solution:
private void InitializeStartDate(System.Web.UI.WebControls.ListControl lc)
{

//clear out list control
lc.Items.Clear();

DateTime start = DateTime.Now;
DateTime workDate = new DateTime(start.Year, start.Month, 1);

int months = 0;
while (months < 12)
{
ListItem li = new ListItem();

//format display {$MonthName} {$Year} i.e January 2006
li.Text = string.Format("{0:MMMM} {1:yyyy}",workDate,workDate);

//get value of display date
li.Value = workDate.ToShortDateString();

//assign ListItem to DropDownList
lc.Items.Add(li);

//decrement workDate by one month
workDate = workDate.AddMonths(-1);

//increment number of items counter
months++;
}
}

Friday, January 19, 2007

Regular Expression : Validate State Abbreviation

Problem:
Validate user input.
State Abbreviations.
Only allow valid input

Solution:

using System.Text.RegularExpressions;

//input from user
string state = this.textBox1.Text.ToString().Trim().ToUpper();

if (Regex.IsMatch(state, "^(?:(A[KLRZ]*|C[AOT]*|D[CE]*|F[L]*|G[A]*|H[I]*|I[ADLN]*|K[SY]*|L[A]*|M[ADEINOST]*|N[CDEHJMVY]*|O[HKR]*|P[AR]*|R[I]*|S[CD]*|T[NX]*|U[T]*|V[AIT]*|W[AIVY]*))$") == true)
{
MessageBox.Show("Valid");
}
else
{
MessageBox.Show("InValid");
}


Results:
Good: A, AK, AZ
Bad: AS, AM

Thursday, January 18, 2007

C# .Net 2.0 - get application name

Problem:
How to console print a program application name?


Solution:


System.Console.WriteLine
("Usage {0}", AppDomain.CurrentDomain.SetupInformation.ApplicationName);

Thursday, January 11, 2007

ASP.Net GridView .Net 2.0

GridView Control.

Problem:
Add HTML to HeaderText

Solution:
Set the attribute HtmlEncode to false

Example:
<asp:BoundField DataField="pk" HeaderText="Primary<br />Key" HtmlEncode="false" />

Comments:
I also found that to add DataFormatString="{0:d}" to work, you'll also have to set the HtmlEncode attribute to false for that given BoundField

Example:
<asp:BoundField DataField="AsOfDate" HeaderText="As Of Date" HtmlEncode="false" DataFormatString="{0:d}">