Sei sulla pagina 1di 5

Imports System.IO Imports System.Drawing.Printing Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.

Even tArgs) Handles MyBase.Load Me.Show() LogInForm.ShowDialog() Me.IsMdiContainer = True LogInForm.MdiParent = Me End Sub Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVa l e As System.EventArgs) Handles AboutToolStripMenuItem.Click About.ShowDialog() End Sub Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click If MsgBox("Sure You Wish to Exit Application?", MsgBoxStyle.Question + M sgBoxStyle.YesNo, "Students Registration Form") = MsgBoxResult.Yes Then MsgBox("Students Registration Form" & vbCrLf & vbCrLf & "Programmed By E2, Group III", MsgBoxStyle.Information, "Students Registration Form") End End If End Sub Private Sub refbtt_Click(ByVal sender As System.Object, ByVal e As System.Ev entArgs) Handles refbtt.Click seatxt.Text = " " Dim i As Int16 For i = 0 To Me.ListView1.Items.Count - 1 Me.ListView1.Items(i).Selected = False Next End Sub Private Sub seabtt_Click(ByVal sender As System.Object, ByVal e As System.Ev entArgs) Handles seabtt.Click If Not IsNumeric(seatxt.Text) Then MsgBox("Enter Profile ID", MsgBoxStyle.Exclamation, "Students Regist ration Form") seatxt.SelectAll() seatxt.Focus() Exit Sub End If Dim Pcode As String = seatxt.Text If Pcode = " " Then MessageBox.Show("The field couldn't be empty") End If Dim i As Int16 For i = 0 To Me.ListView1.Items.Count - 1 If Me.ListView1.Items(i).Text = Pcode Then Me.ListView1.Items(i).Selected = True Me.ListView1.Focus() End If Next End Sub Private Sub newbtt_Click(ByVal sender As System.Object, ByVal e As System.Ev entArgs) Handles newbtt.Click With InfoDetailForm '.sidtxt.Text = "201000" '.txtfirstname.Text = "Sovattha" '.txtlastname.Text = "Kao" '.txtmiddlename.Text = "Boy"

'.txtdob.Text = "07071986" '.txtadd.Text = "Chamka Morn, Phnom Penh" '.txtContact.Text = "012 565 523" '.txtfathername.Text = "Mr. Kao Tann" '.txtMothersName.Text = "Ms. Lay Chantha" .ShowDialog() End With End Sub Private Sub updbtt_Click(ByVal sender As System.Object, ByVal e As System.Ev entArgs) Handles updbtt.Click Dim i As Int16 For i = Me.ListView1.Items.Count - 1 To 0 Step -1 If Me.ListView1.Items(i).Selected = True Then updateinfo.sidtxt.Text = Me.ListView1.Items(i).SubItems(0).Text updateinfo.txtfirstname.Text = Me.ListView1.Items(i).SubItems(1) .Text updateinfo.txtlastname.Text = Me.ListView1.Items(i).SubItems(2). Text updateinfo.txtmiddlename.Text = Me.ListView1.Items(i).SubItems(3 ).Text updateinfo.cmbsex.SelectedItem = Me.ListView1.Items(i).SubItems( 4).Text updateinfo.cmbstatus.SelectedItem = Me.ListView1.Items(i).SubIte ms(5).Text updateinfo.txtdob.Text = Me.ListView1.Items(i).SubItems(6).Text updateinfo.cmbreligion.SelectedItem = Me.ListView1.Items(i).SubI tems(7).Text updateinfo.txtadd.Text = Me.ListView1.Items(i).SubItems(8).Text updateinfo.txtContact.Text = Me.ListView1.Items(i).SubItems(9).T ext updateinfo.txtfathername.Text = Me.ListView1.Items(i).SubItems(1 0).Text updateinfo.txtMothersName.Text = Me.ListView1.Items(i).SubItems( 11).Text updateinfo.ShowDialog() MsgBox("The Record to Updated Successfully!", MsgBoxStyle.Inform ation) End If Next End Sub Private Sub delbtt_Click(ByVal sender As System.Object, ByVal e As System.Ev entArgs) Handles delbtt.Click Dim i As Int16 For i = Me.ListView1.Items.Count - 1 To 0 Step -1 If Me.ListView1.Items(i).Selected = True Then Me.ListView1.Items.RemoveAt(i) End If Next End Sub Sub SaveToFileToolStripMenuItem_Click(ByVal sender As System.Object, System.EventArgs) Handles SaveToFileToolStripMenuItem.Click myfile As String = "c:\AssReport.txt" mywriter As New IO.StreamWriter(myfile) Each myitem As ListViewItem In ListView1.Items mywriter.WriteLine(myitem.Text & " " & myitem.SubItems(1).Text & " " & myitem.SubItems(2).Text & " " & myitem.SubItems(3).Text & " " & myitem.SubIte ms(4).Text & " " & myitem.SubItems(5).Text & " " & myitem.SubItems(6).Text & " " & myitem.SubItems(7).Text & " " & myitem.SubItems(8).Text & " " & myitem.SubIte ms(9).Text & " " & myitem.SubItems(10).Text & " " & myitem.SubItems(11).Text) Private ByVal e As Dim Dim For

Next mywriter.Close() End Sub Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click Dim sidtxt, txtfirstname, txtlastname, txtmiddlename, cmbsex, cmbstatus, txtdob, cmbreligion, txtadd, txtcontact, txtfathername, txtmothername As String Try Dim sr As StreamReader 'declaration of filestream to open file Dim fs As FileStream 'clearing listbox data toavoid confusion 'filestream object to open and read file fs = New FileStream(("C:\AssReport.txt"), FileMode.OpenOrCreate) 'stream reader object to read streamed input sr = New StreamReader(fs) Dim itm As Object 'reading line by line itm = sr.ReadLine While Not itm = Nothing Dim split As String() = itm.Split(New [Char]() {" "}) sidtxt = split(0) txtfirstname = split(1) txtlastname = split(2) txtmiddlename = split(3) cmbsex = split(4) cmbstatus = split(5) txtdob = split(6) cmbreligion = split(7) txtadd = split(8) txtcontact = split(9) txtfathername = split(10) txtmothername = split(11) ListView1.Items.Add(sidtxt) ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(txtfirst name) ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(txtlastn ame) ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(txtmiddl ename) ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(cmbsex) ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(cmbstatu s) ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(txtdob) ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(cmbrelig ion) ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(txtadd) ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(txtconta ct) ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(txtfathe rname) ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(txtmothe rname) itm = sr.ReadLine End While sr.Close() fs.Close()

Catch ex As System.Exception End Try End Sub Private Sub PrintPreviewToolStripMenuItem_Click(ByVal sender As System.Objec t, ByVal e As System.EventArgs) Handles PrintPreviewToolStripMenuItem.Click PrintPreviewDialog1.Document = PrintDocument1 PrintPreviewDialog1.ShowDialog() End Sub Dim tableFont, titleFont As Font Dim X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12 As Integer Dim W1, W2, W3 As Integer Dim Y As Integer Dim itm As Integer Private Sub PrintDocument1_PrintPage_1(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPag e PrintDocument1.DefaultPageSettings.Landscape = True PageSetupDialog1.PageSettings = PrintDocument1.PrinterSettings.DefaultPa geSettings titleFont = New Font("Verdana", 8, FontStyle.Bold) tableFont = New Font("Verdana", 8, FontStyle.Regular) X1 = 30 X2 = X1 + 55 X3 = X2 + 65 X4 = X3 + 55 X5 = X4 + 40 X6 = X5 + 55 X7 = X6 + 63 X8 = X7 + 75 X9 = X8 + 65 X10 = X9 + 200 X11 = X10 + 90 X12 = X11 + 90 Dim x() As Integer = {X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12} Y = PrintDocument1.DefaultPageSettings.Margins.Top + 20 e.Graphics.DrawString("Stu ID", titleFont, Brushes.Black, X1, Y) e.Graphics.DrawString("F Name", titleFont, Brushes.Black, X2, Y) e.Graphics.DrawString("L Name", titleFont, Brushes.Black, X3, Y) e.Graphics.DrawString("MiN", titleFont, Brushes.Black, X4, Y) e.Graphics.DrawString("Gender", titleFont, Brushes.Black, X5, Y) e.Graphics.DrawString("C Status", titleFont, Brushes.Black, X6, Y) e.Graphics.DrawString("DOB", titleFont, Brushes.Black, X7, Y) e.Graphics.DrawString("Religion", titleFont, Brushes.Black, X8, Y) e.Graphics.DrawString("Address", titleFont, Brushes.Black, X9, Y) e.Graphics.DrawString("Contact", titleFont, Brushes.Black, X10, Y) e.Graphics.DrawString("Fa Name", titleFont, Brushes.Black, X11, Y) e.Graphics.DrawString("Mo Name", titleFont, Brushes.Black, X12, Y) Y = Y + 30 Dim str As String Dim row As Int32 For row = 0 To ListView1.Items.Count - 1 Dim lines As Integer Dim Yc As Integer Yc = Y For col As Int32 = 0 To ListView1.Columns.Count - 1 str = ListView1.Items(row).SubItems(col).Text e.Graphics.DrawString(str, tableFont, Brushes.Black, x(col), Yc)

Next Yc = Yc + tableFont.Height + 4 Y = Y + lines * tableFont.Height + 7 Y = Math.Max(Y, Yc) With PrintDocument1.DefaultPageSettings e.Graphics.DrawLine(Pens.Black, .Margins.Left, 5, .PaperSize.Hei ght - .Margins.Right, 5) If Y > 700 Then e.HasMorePages = True Exit Sub End If End With Next End Sub Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVa l e As System.EventArgs) Handles PrintToolStripMenuItem.Click PrintDocument1.Print() End Sub End Class

Potrebbero piacerti anche