Pages

Thursday, May 19, 2011

HTML #8: Styles

<html>
<body style="background-color:PowderBlue;">

<h2 style="background-color:red;">This is a heading</h2><p style="font-size:30px;">This text is 30 pixels high</p>
<h1 style="text-align:center;">Center-aligned heading</h1></body>
</html>

HTML #7: Fonts

<h1 style="font-family:verdana"
style="font-size:110%"
style="color:blue">
This is a heading</h1>


<p style="font-family:verdana;font-size:110%;color:red">
This is a paragraph with some text in it.</p>


This is a heading

This is a paragraph with some text in it.

Monday, May 16, 2011

HTML #6: Formattting

<html>
<body>

<p><b>This text is bold</b></p>
<p><strong>This text is strong</strong></p>
<p><big>This text is big</big></p>
<p><i>This text is italic</i></p>
<p><em>This text is emphasized</em></p>
<p><code>This is computer output</code></p>
<p>This is<sub> subscript</sub> and <sup>superscript</sup></p>


<pre>
This is
preformatted text.
It preserves      both spaces
and line breaks.
</pre>


<address>
Written by W3Schools.com<br />
<a href="
mailto:us@example.org">Email us</a><br />
Address: Box 564, Disneyland<br />
Phone: +12 34 56 78
</address>


<p>The <abbr title="World Health Organization">WHO</abbr> was founded in 1948.</p>
<p>The title attribute is used to show the spelled-out version when holding the mouse pointer over the acronym or abbreviation.</p>

<bdo dir="rtl">
Here is some Hebrew text
</bdo>


A long quotation:
<blockquote>
This is a long quotation. This is a long quotation. This is a long quotation. This is a long quotation. This is a long quotation.
</blockquote>

<p><b>Note:</b> The browser inserts white space before and after a blockquote element. It also inserts margins.</p>
A short quotation:
<q>This is a short quotation</q>

<p><b>Note:<b> The browser inserts quotation marks around the short quotation.</p>

<p>My favorite color is <del>blue</del> <ins>red</ins>!</p>
<p>Notice that browsers will strikethrough deleted text and underline inserted text.</p>
</body>
</html>


This text is bold
This text is strong
This text is big
This text is italic
This text is emphasized
This is computer output
This is subscript and superscript

This is
preformatted text.
It preserves      both spaces
and line breaks.
Written by W3Schools.com
Email us
Address: Box 564, Disneyland
Phone: +12 34 56 78

The WHO was founded in 1948.
The title attribute is used to show the spelled-out version when holding the mouse pointer over the acronym or abbreviation.

txet werbeH emos si ereH

A long quotation:
This is a long quotation. This is a long quotation. This is a long quotation. This is a long quotation. This is a long quotation.
Note: The browser inserts white space before and after a blockquote element. It also inserts margins.
A short quotation: This is a short quotation
Note: The browser inserts quotation marks around the short quotation.

My favorite color is blue red!
Notice that browsers will strikethrough deleted text and underline inserted text.

Sunday, May 15, 2011

HTML #5: Line Breaks

Use the <br /> tag if you want a line break (a new line) without starting a new paragraph:

<p>This is<br />a para<br />graph with line breaks</p>

This is
a para
graph with line breaks

HTML #4: How to View HTML Source

Have you ever seen a Web page and wondered "Hey! How did they do that?"

To find out, right-click in the page and select "View Source" (IE) or "View Page Source" (Firefox), or similar for other browsers. This will open a window containing the HTML code of the page.

HTML #3: Comments

Comments can be inserted into the HTML code to make it more readable and understandable. Comments are ignored by the browser and are not displayed.

<!-- This is a comment -->

HTML #2: HTML Lines

The <hr /> tag creates a horizontal line in an HTML page.

<html>
<body>
<p>The hr tag defines a horizontal rule:</p>
<hr />
</body>
</html>


The hr tag defines a horizontal rule:

HTML #1: Basic

HTML headings:  [h1-h6]

<h1>This is a heading</h1>
HTML  Paragraphs:
<p>This is a paragraph.</p>
HTML links:

<a href="http://www.w3schools.com">This is a link</a>
HTML images:
<img src="w3schools.jpg" width="104" height="142" />

Save as: *.htm or *html

<html>
<body>

<h1>This is my Main Page</h1>
<p>This is some text.</p>
<p><a href="page1.htm">This is a link to Page 1</a></p>
<p><a href="page2.htm">This is a link to Page 2</a></p>

</body>
</html>

Wednesday, April 13, 2011

C# 10: Controls at runtime

GroupBox1.Controls.Add ()
                                .AddRange()
                                .Clear()
                                .Remove()
                                .RemoveAt()
                                .ToString()
                                .GetEnumerator()

Wednesday, April 6, 2011

C# 9: Dialog Result

DialogResult userResponse = openFileDialog1.ShowDialog();
MessageBox.Show("The search is complete", "My Application", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
if (userResponse == DialogResult.Cancel)
{

MessageBox.Show("user said cancel", "My Response", MessageBoxButtons.OKCancel, MessageBoxIcon.Hand);
}

Monday, April 4, 2011

C# 8: DialogBox

private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();

}

Add OpenFileDialog in App Design

For Dialog Message:
MessageBox.Show("The search is complete", "My Application", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);

To set initial directory:
openFileDialog1.initialdirectory = Application.StartupPath;

To set filter:
openFileDialog1.initialdirectory = "Text Files (*.txt)|*.txt"

or you may set this in the open dialog properties

     

C# 7: Toolbar

private void mainToolBarClicked(Object sender,
                        ToolBarButtonClickEventArgs e)
{
    switch (mainToolBar.Buttons.IndexOf(e.Button))
    {
        case 0:
            MessageBox.Show("Add New file code here");
            break;
        case 1:
            OpenFileDialog openDlg = new OpenFileDialog();
            if (DialogResult.OK == openDlg.ShowDialog())
            {
                string fileName = openDlg.FileName;
                MessageBox.Show(fileName);
            }
            break;
        case 2:
            SaveFileDialog saveDlg = new SaveFileDialog();
            if (DialogResult.OK == saveDlg.ShowDialog())
            {
                string fileName = saveDlg.FileName;
                MessageBox.Show(fileName);
            }
            break;
        case 3:
            PrintDialog printDlg = new PrintDialog();
            printDlg.ShowDialog();  
            break;
        case 4:
            this.Close();  
            break;
    }
}


To show tool tips edit in the properties
ToolTipText.text = "Cut"

Monday, March 21, 2011

C# 6: ListBox


MultiColumn = True
- Listbox display in multiple columns and a horizaontal toolbar

MultiColumn = False
- Listbox display in single column and vertical toolbar

listBox1.SelectionMode = SelectionMode.MultiExtended;
listBox1.SelectionMode = SelectionMode.MultiSimple;
listBox1.SelectionMode = SelectionMode.None;
listBox1.SelectionMode = SelectionMode.One;

http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.selectedindex(VS.71).aspx

.Datasource
.DisplayMember

Sunday, March 20, 2011

C# 5: Status Strip



toolStripProgressBar1.Value = 10;

C# 4: Parent and Child Form


private void windowToolStripMenuItem_Click(object sender, EventArgs e)
{
Form3 newform3 = new Form3();
newform3.Show();
}

Thursday, March 17, 2011

C# 3: MDI Application



private void form2ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 newmdichild = new Form2();
newmdichild.MdiParent = this;
newmdichild.Show();
}

Set IsMdiParent = True

Tuesday, March 15, 2011

Wednesday, February 2, 2011

Access DBase

 Inherits System.Windows.Forms.Form
    Dim myConnection As SqlConnection
    Dim myCommand As SqlCommand
    Dim dr As SqlDataReader
   
    myConnection = New SqlConnection("server=<server_name>;uid=<username>;pwd=<password>")
        Try
            myConnection.Open()
            myCommand = New SqlCommand("Select * from Mal", myConnection)
            dr = myCommand.ExecuteReader()
            Do
                While dr.Read()
                    MessageBox.Show("ID:" & dr(0).ToString())
                   
                End While
            Loop While dr.NextResult
            dr.Close()
            myConnection.Close()
        Catch ex As Exception

        End Try
    End Sub

Winzip commandline

Include wzunzip.exe in debug folder

wzunzip -s<zip password> D:\0322090029.zip \\c01\d$\v\VSample1\0903261001\VSamples\Generic\Samples 0903261001\VSamples\Generic\Samples\00167043523009bce27d5a85a3716314

Convert CSV file to Excel File

 Public Sub ConvertCSVtoXL(ByVal strCSVPath As String)
        Try
            Dim xlsApp = New Excel.Application
            Dim xlsBook = xlsApp.Workbooks.Open(Filename:=strCSVPath, UpdateLinks:=False, ReadOnly:=False)
            xlsBook.SaveAs(FileName:=C:\Reject", FileFormat:=Excel.XlFileFormat.xlExcel9795)

            xlsApp.quit()
        Catch ex As Exception
            System.Console.WriteLine("Converting to Excel File Error: " + ex.Message)
        End Try

    End Sub

Command Line Arguments

Set Application Type to Console Application


'[CONS withspyware] TopXPrepare.exe - cons -spy
        Try
            '----Parsing the Commandline to tag if BETA of CONS
            Dim args() As String = System.Environment.GetCommandLineArgs()

            For i As Integer = 0 To args.Length - 1
                If i = 1 Then
                    If args(i) = "-beta"
                        Parameter = "BETA"

                        If args(i + 1) = "-spy"
                            SParameter = "SPY"
                           
                        ElseIf args(i + 1) = "-nospy"
                            SParameter = "NOSPY"
                           
                        End If

                    ElseIf args(i) = "-cons"
                        Parameter = "CONS"

                        If args(i + 1) = "-spy"
                            SParameter = "SPY"
                           
                        ElseIf args(i + 1) = "-nospy"
                            SParameter = "NOSPY"
                          
                        End If
                    
                    Else
               
                    End If
                End If
            Next

            Console.ReadKey()
    
        Catch ex As Exception
           
        End Try

Traverse Directory Files and Get Files

Dim
filename, filename2 As FileInfo
Dim myDirectoryInfo As DirectoryInfo
          '----location where the pattern sources are being stored
          myDirectoryInfo = New DirectoryInfo(C:\Duplicates")

Dim myDir As IO.DirectoryInfo

Dim filesInfo() As FileInfo
Dim fileInfo As FileInfo


        Try

            filesInfo = myDirectoryInfo.GetFiles()

            For Each fileInfo In filesInfo
                'Filenames will have the files under a directory
                Filenames = fileInfo.FullName
            Next


        Try
                myDirectoryInfos = myDirectoryInfo.GetDirectories()
                For Each myDir In myDirectoryInfos
                 'del_folder will have the files under a directory
                    del_folder = (myDir.FullName)
         Next


        Catch ex As Exception
          
        End Try

Monday, January 31, 2011

Copy FTP File

 Private Function GetFtpServerCopy(ByVal ftpServer As String, ByVal username As String, _
                                           ByVal password As String, ByVal filepath As String) As Date
        Dim ftpFile As String
        If Not ftpServer.EndsWith("/") Then
            ftpServer &= "/"
        End If
        ftpFile = filepath + "/Logs/scanReport.csv"
        Dim dateStr As String = String.Empty

        Dim request As System.Net.FtpWebRequest = System.Net.FtpWebRequest.Create(ftpFile)
        Dim creds As New System.Net.NetworkCredential(username, password)
        request.Credentials = creds
        request.Method = System.Net.WebRequestMethods.Ftp.DownloadFile

        Dim response As System.Net.FtpWebResponse = request.GetResponse
     

        Using responseStream As IO.Stream = response.GetResponseStream
            'loop to read & write to file
            Using fs As New IO.FileStream("D:\copy.csv", IO.FileMode.Create)
                Dim buffer(2047) As Byte
                Dim read As Integer = 0
                Do
                    read = responseStream.Read(buffer, 0, buffer.Length)
                    fs.Write(buffer, 0, read)
                Loop Until read = 0 'see Note(1)
                responseStream.Close()
                fs.Flush()
                fs.Close()
            End Using
            responseStream.Close()
        End Using

        response.Close()
    End Function

Get FTP Server Time

http://social.msdn.microsoft.com/Forums/en/vblanguage/thread/56137d13-9bf5-4f35-9358-88b5009709fa

Private Function GetFtpServerDateTime(ByVal ftpServer As String, ByVal username As String, _
                                      ByVal password As String) As Date
        Dim ftpFile As String
        If Not ftpServer.EndsWith("/") Then
            ftpServer &= "/"
        End If
        ftpFile = String.Concat(ftpServer, "tmptimecheck.zero")
        Dim dateStr As String = String.Empty
        Dim request As System.Net.FtpWebRequest = System.Net.FtpWebRequest.Create(ftpFile)
        Dim creds As New System.Net.NetworkCredential(username, password)
        request.Credentials = creds
        request.Method = System.Net.WebRequestMethods.Ftp.UploadFile
        Dim response As System.Net.FtpWebResponse = request.GetResponse
        If response.StatusCode = Net.FtpStatusCode.ClosingData Then
            response.Close()
            request = System.Net.FtpWebRequest.Create(ftpFile)
            request.Credentials = creds
            request.Method = System.Net.WebRequestMethods.Ftp.GetDateTimestamp
            response = request.GetResponse
            If response.StatusCode = Net.FtpStatusCode.FileStatus Then
                dateStr = response.StatusDescription
                response.Close()
                request = System.Net.FtpWebRequest.Create(ftpFile)
                request.Credentials = creds
                request.Method = System.Net.WebRequestMethods.Ftp.DeleteFile
                response = request.GetResponse
            End If
            response.Close()
        End If
        response.Close()
        If dateStr.Length = 20 Then
            dateStr = dateStr.Substring(4)
            Dim year As Integer = CInt(dateStr.Substring(0, 4))
            Dim month As Integer = CInt(dateStr.Substring(4, 2))
            Dim day As Integer = CInt(dateStr.Substring(6, 2))
            Dim hour As Integer = CInt(dateStr.Substring(8, 2))
            Dim minute As Integer = CInt(dateStr.Substring(10, 2))
            Dim second As Integer = CInt(dateStr.Substring(12, 2))
            Return New Date(year, month, day, hour, minute, second)
        Else
            Throw New Exception("Error while attempting to infer date from server")
        End If
End Function

Traverse FTP Folder

    Dim fwr As FtpWebRequest = FtpWebRequest.Create("ftp://xx.xx.xxx.xxx/")
        fwr.Credentials = New NetworkCredential("user", "password")
        fwr.Method = WebRequestMethods.Ftp.ListDirectory

        Dim sr As New StreamReader(fwr.GetResponse().GetResponseStream())
        Dim str As String = sr.ReadLine()
        While Not str Is Nothing
          
            str = sr.ReadLine() 'hold the traverse file

       End While
        sr.Close()
        sr = Nothing
        fwr = Nothing

Sunday, January 30, 2011

Get File Size

     Dim fileDetail As IO.FileInfo

           fileDetail = My.Computer.FileSystem.GetFileInfo(Application.StartupPath + "\FILE.LOG")

           If fileDetail.Length < 1500 Then '1500 bytes
                'code here
           End If

Check for Existing Process Name

 While (True)

 localByName = Process.GetProcessesByName("notepad")

    If localByName.Length = 0 Then
     Exit While
    End If

End While

Shell and Wait

 ShellandWait("cmd.exe", "/c " + Application.StartupPath + "\Engines\" + temp_Ctr.ToString + "crossparse.bat") 
======================================================
Public Sub ShellandWait(ByVal ProcessPath As String, ByVal Param As String)
   Dim objProcess As System.Diagnostics.Process

        Try
            objProcess = New System.Diagnostics.Process()
            objProcess.StartInfo.FileName = ProcessPath
            objProcess.StartInfo.Arguments = Param
            objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
            objProcess.Start()
            'Wait until the process passes back an exit code
            objProcess.WaitForExit()
            'Free resources associated with this process
            objProcess.Close()
        Catch
            MessageBox.Show("Could not start process " & ProcessPath, "Error")
        End Try
    End Sub

Check for File Lock

 Private Function IsFileLocked(ByVal filePath As String) As Boolean

        Dim fs As FileStream = Nothing
        Dim result As Boolean = False
    
        Try
             File.Copy(filePath, POLL_PATH + "\Processing\" + temp(bound) + "~scanReport.csv")
             result = False
      
        Catch ex As Exception
            'file lock - still copying
            result = True
          
        End Try

        Return result

End Function

File Watcher

Set Properties:
 Try
          
            FileSystemWatcher1.Path = POLL_IN
            FileSystemWatcher1.NotifyFilter = (NotifyFilters.CreationTime Or _
                                            NotifyFilters.FileName Or _
                                            NotifyFilters.LastAccess Or _
                                            NotifyFilters.LastWrite Or _
                                            NotifyFilters.Size)
            FileSystemWatcher1.IncludeSubdirectories = True
            FileSystemWatcher1.Filter = "*.*"
            AddHandler Me.FileSystemWatcher1.Changed, AddressOf MoveFile
            AddHandler Me.FileSystemWatcher1.Created, AddressOf MoveFile
            FileSystemWatcher1.EnableRaisingEvents = True
     
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

========================================================
Adding Handler:
   Private Sub MoveFile(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
     'for Change Types: Created/Renamed/Deleted/Changed

        If e.ChangeType = WatcherChangeTypes.Created Then
            While IsFileLocked(process_Folder) = True
                System.Threading.Thread.Sleep(1000)
            End While
        End If
    End Sub
========================================================
Set Events Handled:


Private Sub FileSystemWatcher1_Created(ByVal sender As System.Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Created, FileSystemWatcher1.Changed
       
 Try
         'code here for file system watch trigger during change and create
Catch ex As Exception
            MsgBox(ex.Message)
End Try

End Sub

Write to Text File

Try
           
            File.WriteAllText(POLL_PATH + "\OUT\" + folder + "\832Cross.LOG", "")
            Dim fsStream8 As New FileStream(POLL_PATH + "\OUT\" + folder + "\832Cross.LOG", FileMode.Open, FileAccess.ReadWrite)
            Dim srWriter As New StreamWriter(fsStream8)

            srWriter.WriteLine("write here")
            srWriter.Close()

Catch ex As Exception
    MsgBox(ex.Message)
End Try

Read Text File

Try

            If File.Exists(Application.StartupPath + "\config.ini") Then

                Dim fsStream7 As New FileStream(Application.StartupPath + "\config.ini", FileMode.Open, FileAccess.Read)
                Dim srReader7 As New StreamReader(fsStream7)
                Dim readline1 As String

                srReader7.BaseStream.Seek(0, SeekOrigin.Begin)
                While srReader7.Peek() > -1
                    readline1 = (srReader7.ReadLine())

                 End While

                srReader7.Close()

            Else
                MessageBox.Show("Unable to locate " + Application.StartupPath + "\config.ini")
                Me.Close()
            End If


Catch ex As Exception
    MsgBox(ex.Message)
End Try

Imports

Imports System.Diagnostics.Process
Imports System.IO
Imports System.Text
Imports System.Net
Imports System


'Excel
Imports System.Data
Imports System.Windows.Forms


'DB
Imports System.Console
Imports System.Data.SqlClient


'Server-Client
Imports System.Text.RegularExpressions
Imports System.Net.Sockets
Imports System.Threading
Imports Microsoft.Win32

Add Seconds

Dim date1 As DateTime

date1 = System.DateTime.Now.ToLongTimeString
date1 = date1.AddSeconds(30)

Sunday, January 23, 2011

C# 1: Forms

Set Properties:
AcceptButton - for Enter key
CancelButton - for ESC key

Exit - this.close();