Sei sulla pagina 1di 5

-------Set URL Query String-------------------------------------

url = "index.aspx?"
url &= "email=" & TempUser & "&" & "password=" & TempPass & "&" & "name=" &
TempName
----------------------------------------------------------------
------Get Query String------------------------------------------

TempUser = Request.QueryString("email")

----------------------------------------------------------------
----------validator---------------------------------------------
1. Username minimal 4 karakter
If txt_username.Text.Length < 3 Then
penanda = 1

End If
If penanda = 1 Then
args.IsValid = False
Else
args.IsValid = True
End If
2. Harus Huruf dan angka - Pake Regular Expression Validator
Validator Expression = ^(\d+\p{L}+|\p{L}+\d+)+$
3. Tanggal harus (DD/MM/YYYY) - Pake Regular Expression Validator
Validator Expression = (((0|1)[0-9]|2[0-9]|3[0-1])\/(0[1-9]|1[0-2])\/((19|
20)\d\d))$
4. Hanya Boleh angka - Pake Regular Expression Validator
Validator Expression = ^[0-9]*$
----------------------------------------------------------------
----------Mengdeteksi apakah page di refresh atau tidak---------
If Not Page.IsPostBack Then
---Expression
End If
----------------------------------------------------------------
------Mengambil data dari database ke gridview------------------
Try
conn.Close()
conn.Open()
Dim cmd As New SqlCommand
cmd.Connection = conn
cmd.CommandText = "SELECT M.NAMA,MP.HP FROM MAHASISWA M ,MHS_HP MP
WHERE M.NRP = MP.NRP AND M.NRP = @NRP"
cmd.Parameters.AddWithValue("@NRP", ListBox1.SelectedItem.ToString)
Dim adapter As New SqlDataAdapter(cmd)
Dim ds As New DataSet
adapter.Fill(ds)
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
----------------------------------------------------------------
------Mengambil data dari XML ke gridview-----------------------

dt.Columns.Add(New DataColumn("City", GetType(String)))


dt.Columns.Add(New DataColumn("Province", GetType(String)))
dt.ReadXml(Server.MapPath("citylist.xml"))
ViewState("city") = dt
GridView1.DataSource = dt
GridView1.DataBind()

----------------------------------------------------------------
------Mengambil data dari XML ke Combobox-----------------------
dt.Columns.Add(New DataColumn("City", GetType(String)))
dt.Columns.Add(New DataColumn("Province", GetType(String)))
dt.ReadXml(Server.MapPath("citylist.xml"))
DropDownList1.DataSource = dt
DropDownList1.DataValueField = "City"
DropDownList1.DataBind()
----------------------------------------------------------------
-------------Send Email-----------------------------------------
Imports System.Net.Mail
Imports System.Net
Dim msg As String = "<html><html>"
Try
Dim pesan As New MailMessage
pesan.Subject = "Electronic Store"
pesan.To.Add("riandysulaiman09@gmail.com") 'email tujuan
pesan.From = New MailAddress("riandysulaiman10@gmail.com") 'email kita
pesan.IsBodyHtml = True
pesan.Body = msg
Dim SMTP As New SmtpClient("smtp.gmail.com")
SMTP.EnableSsl = True
SMTP.Credentials = New
System.Net.NetworkCredential("riandysulaiman10@gmail.com", "ri04andy0896") 'isi
dengan email,password
SMTP.Port = "587"
SMTP.Send(pesan)
Catch ex As Exception
MsgBox(ex.Message)
End Try
----------------------------------------------------------------
------Upload Gambar Ke gridview---------------------------------
Try
conn.Close()
conn.Open()
Dim query As String = "insert into barang
values(@id_brg,@nama_brg,@harga_beli,@harga_jual,@stok,@url1,@url2,@url3,@kategori,
@deskripsi)"
Dim cmd As SqlCommand = New SqlCommand(query, conn)
cmd.Parameters.AddWithValue("@url1", fileToUpload.FileBytes)
cmd.Parameters.AddWithValue("@url2", fileUpload2.FileBytes)
cmd.Parameters.AddWithValue("@url3", fileUpload3.FileBytes)
cmd.ExecuteNonQuery()

Catch ex As Exception
MsgBox(ex.Message)
End Try
----------------------------------------------------------------
----------Tampilkan gambar ke gridview-------------------------
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
>DI gridview
Data Image URL String = harus berdasarkan nama field Primary key di database
Data Image URL Format String = blob.aspx?id={0}
Pake Image Field di gridview tapi jng di jadikan templete
>Di blop.aspx
Try
conn.Close()
conn.Open()
' MsgBox("database connected")
Dim sqlcommand As New SqlCommand("select url1 from barang where id_brg
= @id_brg", conn)
sqlcommand.Parameters.AddWithValue("@id_brg",
Request.QueryString("id"))
Dim result As Object = sqlcommand.ExecuteScalar

Dim blob As Byte() = result


Dim bmp1 As New Bitmap(New MemoryStream(blob))
Dim bmp2 As New Bitmap(bmp1, 100, 100)
Dim stream As New MemoryStream
bmp2.Save(stream, ImageFormat.Jpeg)
Response.ContentType = "image/jpeg"
Response.BinaryWrite(stream.GetBuffer)

Catch ex As Exception
MsgBox(ex.Message)
End Try
---------------------------------------------------------------------
---------Ambil data dari gridview masuk ke textbox-------------------
Dim kolom As Integer = Integer.Parse(e.CommandArgument)
kode = GridView1.Rows(kolom).Cells(0).Text
txtNama.Text = GridView1.Rows(kolom).Cells(1).Text
txtHargaB.Text = GridView1.Rows(kolom).Cells(2).Text
----------------------------------------------------------------------
----------------Generate report PDF-----------------------------------
Imports iTextSharp
Imports iTextSharp.text.pdf
Imports iTextSharp.text
Imports System.Data
Imports System.Data.SqlClient
Imports System.Net
Imports System.Configuration.ConfigurationSettings
Dim doc = New Document()
PdfWriter.GetInstance(doc, New System.IO.FileStream(Server.MapPath("~/") &
"test8.pdf", System.IO.FileMode.Create))
doc.Open()
'begin of logo sejajar
Dim table1 As PdfPTable = New PdfPTable(2)
Dim table2 As PdfPTable = New PdfPTable(2)

Dim cell2 As PdfPCell = New PdfPCell()


Dim cell3 As PdfPCell = New PdfPCell()
cell2.HorizontalAlignment = 1
Dim width1() As Integer = {150, 400}
table2.SetWidths(width1)

doc.Add(New Paragraph("PT.ABC", New Font(Font.FontFamily.HELVETICA, 16,


Font.BOLD, BaseColor.BLACK)))
cell3 = New PdfPCell(New Phrase("PT. ABC"))
cell3.BorderColor = BaseColor.WHITE
table2.AddCell(cell3)
doc.Add(table2)

Dim table As PdfPTable = New PdfPTable(3)


Dim cell As PdfPCell = New PdfPCell()
cell.HorizontalAlignment = 1 '0=left,1=center,2=right
Dim widths() As Integer = {100, 150, 300}
table.SetWidths(widths)
table.DefaultCell.Border = Rectangle.NO_BORDER
table.AddCell("Id Barang")
table.AddCell("Nama Barang")
table.AddCell("Harga")
doc.Add(New Paragraph(" "))

conn.Open()
Dim sqlcommand As New SqlCommand("select id_brg,nama_brg,harga_jual from
barang", conn)
Dim result As Object = sqlcommand.ExecuteReader
Dim cell1 As PdfPCell = New PdfPCell()

While result.read
Dim tFont As New Font(Font.FontFamily.HELVETICA, 16)
cell1 = New PdfPCell
table.AddCell(New PdfPCell(New Paragraph(result("id_brg"),
FontFactory.GetFont("Arial", 9, iTextSharp.text.BaseColor.BLACK))))
table.AddCell(New PdfPCell(New Paragraph(result("nama_brg"),
FontFactory.GetFont("Arial", 9, iTextSharp.text.BaseColor.BLACK))))
table.AddCell(New PdfPCell(New Paragraph(result("harga_jual"),
FontFactory.GetFont("Arial", 9, iTextSharp.text.BaseColor.BLACK))))
End While
doc.Add(table)
doc.Close()

Dim path As String = Server.MapPath("~/") & "test8.pdf"


Dim client As New WebClient()
Dim buffer As Byte() = client.DownloadData(path)
If buffer IsNot Nothing Then
Response.ContentType = "application/pdf"
Response.AddHeader("content-length", buffer.Length.ToString())
Response.BinaryWrite(buffer)
End If
----------------------------------------------------------
--------Ajax Pake JQUERY----------------------------------
function getCheckout() {
var request = {
id: document.getElementById("lbl_idPembelian").innerText
}
var strrequest = JSON.stringify(request);
$.ajax({
type: "POST",
url: "checkout.aspx/load_data",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: strrequest,
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Request: " + XMLHttpRequest.toString() + "\n\nStatus: " +
textStatus + "\n\nError: " + errorThrown);
},
success: function (result) {

$(".loadCheckout").html(result.d);
}
});
}

<System.Web.Services.WebMethod()>
Public Shared Function autogen() As Integer
Dim email As String = HttpContext.Current.Session("email").ToString
Return a
End Function
-------------------------------------------------------------

Potrebbero piacerti anche