2012年12月24日 星期一
主子資料表的新增
'新增資料到訂貨主檔
'儲存資料後,超連結到顯示訂單的網頁
Dim connstr As String = "Data Source=120.xxx.xx.xxx;UID=xx;PWD=xx;Database=北風貿易"
Dim sqlconn As SqlConnection = New SqlConnection(connstr)
Dim sqlcmdstr As String = "insert into 訂貨主檔(客戶編號, 員工編號, 訂單日期, 要貨日期, 送貨方式) values(@客戶編號, @員工編號, @訂單日期, @要貨日期, @送貨方式);select @@IDENTITY"
Dim sqlcmd As New SqlCommand(sqlcmdstr, sqlconn)
sqlcmd.Parameters.AddWithValue("@客戶編號", Me.TextBox1.Text)
sqlcmd.Parameters.AddWithValue("@員工編號", Me.TextBox6.Text)
sqlcmd.Parameters.AddWithValue("@訂單日期", Me.TextBox2.Text)
sqlcmd.Parameters.AddWithValue("@要貨日期", Me.TextBox4.Text)
sqlcmd.Parameters.AddWithValue("@送貨方式", Me.TextBox5.Text)
'sqlcmd.Parameters.AddWithValue("@newid", Me.TextBox7.Text)
'sqlcmd.Parameters.AddWithValue("@訂單日期", Me.TextBox2.Text)
sqlconn.Open()
Dim result As SqlDataReader
result = sqlcmd.ExecuteReader
If result.HasRows Then
Do While result.Read()
'Response.Write(result(0).ToString)
Me.Label1.Text = result(0).ToString
Me.TextBox3.Text = result(0).ToString
Loop
Else
Response.Write("No rows returned.")
End If
result.Close()
'result.Read()
sqlconn.Close()
'Response.Write(result.ToString)
'Response.Redirect("gridview.aspx")
Me.GridView1.DataBind()
Protected Sub FormView1_ItemInserted(sender As Object, e As System.Web.UI.WebControls.FormViewInsertedEventArgs) Handles FormView1.ItemInserted
'當子資料表有新項目新增時, 更新下方的訂單明細gridview1
Me.GridView1.DataBind()
End Sub
Protected Sub FormView1_PreRender(sender As Object, e As EventArgs) Handles FormView1.PreRender
'當formview重新整理時,將訂單號碼填進去
Dim orderid As TextBox = CType(Me.FormView1.FindControl("訂單號碼TextBox"), TextBox)
orderid.Text = Me.TextBox3.Text
End Sub
Private Sub Calendar2_DayRender(sender As Object, e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar2.DayRender
'限制只能在7天以後開放選取交期
e.Day.IsSelectable = e.Day.Date > Now.AddDays(7).ToShortDateString
End Sub
Protected Sub Calendar2_SelectionChanged(sender As Object, e As EventArgs) Handles Calendar2.SelectionChanged
'輸入交期
Me.TextBox4.Text = Me.Calendar2.SelectedDate
End Sub
'更新產品編號
Protected Sub DropDownList4_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim productid As TextBox = CType(Me.FormView1.FindControl("產品編號TextBox"), TextBox)
Dim drop_product As DropDownList = CType(Me.FormView1.FindControl("DropDownList4"), DropDownList)
productid.Text = drop_product.SelectedValue.ToString
'Dim ds As DataSet = SqlDataSource1.Select
Dim connstr As String = "Data Source=xxx.xx.xx.xx;UID=xx;PWD=xx;Database=北風貿易"
Dim sqlconn As SqlConnection = New SqlConnection(connstr)
Dim cmd As New SqlCommand("select 單價 from 產品資料 where 產品編號 = @prodid", sqlconn)
cmd.Parameters.AddWithValue("@prodid", Int(drop_product.SelectedValue))
Dim reader As SqlDataReader
sqlconn.Open()
reader = cmd.ExecuteReader
If reader.Read Then
Dim price_text As TextBox = CType(Me.FormView1.FindControl("單價TextBox"), TextBox)
price_text.Text = reader(0).ToString
End If
sqlconn.Close()
End Sub
If Me.TextBox3.Text <> "" Then
Dim connstr As String = "Data Source=xxx.xxx.xx.xx;UID=xx;PWD=xx;Database=北風貿易"
Dim sqlconn As SqlConnection = New SqlConnection(connstr)
Dim cmd As SqlCommand
cmd = New SqlCommand("delete 訂貨主檔 where 訂單號碼='" & Me.TextBox3.Text & "'", sqlconn)
Dim result As Integer
sqlconn.Open()
result = cmd.ExecuteNonQuery
Response.Write(result)
sqlconn.Close()
'If result = -1 Then
Me.TextBox3.Text = ""
Dim orderid As TextBox = CType(Me.FormView1.FindControl("訂單號碼TextBox"), TextBox)
orderid.Text = ""
Me.TextBox4.Text = ""
'End If
End If
2012年12月18日 星期二
在visual studio 2010 aspx網頁webform複製改名(重新命名)後產生的錯誤
上網找了一陣子,終於找到當aspx網頁檔名被修改後發生錯誤的解法,參考自
為了避免此網頁以後找不到,因此把重點摘錄如下
2012年12月8日 星期六
網頁產生一二維條碼
因為教學需要,所以放上網路上找到的一二維條碼產生DLL
一維條碼 128碼 DLL(方法1),先下載以下DLL,並加入參考
https://docs.google.com/open?id=0Bxaw7Z2hq9CFWG1iRzJacFN1aGM
以下所產生的一維條碼會顯示在另一個瀏覽器,並不方便
'一維條碼 128碼 呼叫程式碼
Dim b As BarcodeLib.Barcode = New BarcodeLib.Barcode()
'支援39, 128, EAN, UPC等
Dim type As BarcodeLib.TYPE = BarcodeLib.TYPE.CODE128
Try
'Me.Image1.Image = b.Encode(type, TextBox1.Text.Trim)
Dim data As String = Me.TextBox1.Text
Dim image As New System.Drawing.Bitmap(200, 200)
image = b.Encode(type, TextBox1.Text.Trim)
image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif)
Catch ex As Exception
'MessageBox.Show(ex.Message)
End Try
一維條碼 128碼 DLL(方法2),也是下載DLL,並加入參考
將編碼的圖片寫在另外一個.ashx 泛型處理常式中
Imports System.Web
Imports System.Web.Services
Imports System.Web.SessionState ' 要使用 Session 必需加入此命名空間
Imports System.IO
Imports System.Drawing.Imaging
Public Class barcode
Implements System.Web.IHttpHandler, IRequiresSessionState
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim encodestr As String = ""
'context.Request("encodestr") 是從傳過來的網址中抓取問號後面encoderstr的變數值
'例如 http://barcode.ashx?encodestr="123" 則會抓取123
If context.Session("encodestr") IsNot Nothing Then
'利用TryParse函數判斷使用者輸入的是數字或是文字
'If Integer.TryParse(context.Request("scid").Trim(), encoderstr) Then
'End If
encodestr = context.Session("encodestr").ToString
Dim b As BarcodeLib.Barcode = New BarcodeLib.Barcode()
Try
Dim image As New System.Drawing.Bitmap(200, 200)
'支援39, 128, EAN, UPC等,目前是將encodestr編成128碼
Dim type As BarcodeLib.TYPE = BarcodeLib.TYPE.CODE128
image = b.Encode(type, encodestr.ToString)
context.Response.ContentType = "Image/Gif"
context.Response.Clear()
image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif)
Catch ex As Exception
'MessageBox.Show(ex.Message)
End Try
Else
context.Response.Write("sessioin error")
End If
End Sub
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
二維條碼 qr code DLL
https://docs.google.com/open?id=0Bxaw7Z2hq9CFa0t4dkVkMEZCOFU
'二維條碼 呼叫程式碼
Dim encoder As New ByCase.Lib.QRCode.Codec.QRCodeEncoder
'編碼有3種,分別是byte, alphanumeric, numeric
encoder.QRCodeEncodeMode = ByCase.Lib.QRCode.Codec.QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC
'(image pixels per QRCode pixel): 1, 2, 3, 4, 5, 10, 15, 30. ( in pixels )
encoder.QRCodeScale = 5
'二维码所能包含的字符信息量是由QrcodeVersion的设置值来决定的。将QrcodeVersion设置到20的时候,就已经可以容乃到300多个字节
encoder.QRCodeVersion = 20
'ByCase.Lib.QRCode.Codec.QRCodeEncoder.ERROR_CORRECTION.H L M Q
encoder.QRCodeErrorCorrect = ByCase.Lib.QRCode.Codec.QRCodeEncoder.ERROR_CORRECTION.H
'只能大寫英文, 數字, 空格+-*/冒號,不可以小寫、不可底線不可特殊符號
Dim data As String = Me.TextBox1.Text.ToUpper
Dim image As New System.Drawing.Bitmap(200, 200)
image = encoder.Encode(data)
Image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif)
二維條碼(方法2)
Google charts提供非常方便的API,可以產生QR Code圖片。
http://code.google.com/apis/chart/docs/gallery/qr_codes.html(API說明)
以下面URL為例,紅色部份為關鍵參數
https://chart.googleapis.com/chart?chs=120x120&cht=qr&chl=陳錫川&choe=UTF-8&chld=M|2
其中:
chs: QR code 圖片大小
cht: 圖片類型,google charts用這個參數產生各種圖片,這裡當然就填qr
chl: 要藏在QR code裡的文字,必須編成punycode(urlencode)。
choe: 編碼。請注意只支援iso-8859-1, sjis, utf8。詳見API說明網頁。
chld: 其他參數。M是錯誤修正層次,有L, M, Q, H等四級;後面的數字是QR code周圍白邊的寬度。
在webform放置textbox1與button,接著在button中撰寫以下程式即可
Dim imgsrc As String = "http://chart.apis.google.com/chart?chs=" & "400x400" & "&chl=" & Me.TextBox1.Text & "&choe=UTF-8&cht=qr"
Image1.ImageUrl = imgsrc
一維條碼 128碼 DLL(方法1),先下載以下DLL,並加入參考
https://docs.google.com/open?id=0Bxaw7Z2hq9CFWG1iRzJacFN1aGM
以下所產生的一維條碼會顯示在另一個瀏覽器,並不方便
'一維條碼 128碼 呼叫程式碼
Dim b As BarcodeLib.Barcode = New BarcodeLib.Barcode()
'支援39, 128, EAN, UPC等
Dim type As BarcodeLib.TYPE = BarcodeLib.TYPE.CODE128
Try
'Me.Image1.Image = b.Encode(type, TextBox1.Text.Trim)
Dim data As String = Me.TextBox1.Text
Dim image As New System.Drawing.Bitmap(200, 200)
image = b.Encode(type, TextBox1.Text.Trim)
image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif)
Catch ex As Exception
'MessageBox.Show(ex.Message)
End Try
一維條碼 128碼 DLL(方法2),也是下載DLL,並加入參考
將編碼的圖片寫在另外一個.ashx 泛型處理常式中
Imports System.Web
Imports System.Web.Services
Imports System.Web.SessionState ' 要使用 Session 必需加入此命名空間
Imports System.IO
Imports System.Drawing.Imaging
Public Class barcode
Implements System.Web.IHttpHandler, IRequiresSessionState
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim encodestr As String = ""
'context.Request("encodestr") 是從傳過來的網址中抓取問號後面encoderstr的變數值
'例如 http://barcode.ashx?encodestr="123" 則會抓取123
If context.Session("encodestr") IsNot Nothing Then
'利用TryParse函數判斷使用者輸入的是數字或是文字
'If Integer.TryParse(context.Request("scid").Trim(), encoderstr) Then
'End If
encodestr = context.Session("encodestr").ToString
Dim b As BarcodeLib.Barcode = New BarcodeLib.Barcode()
Try
Dim image As New System.Drawing.Bitmap(200, 200)
'支援39, 128, EAN, UPC等,目前是將encodestr編成128碼
Dim type As BarcodeLib.TYPE = BarcodeLib.TYPE.CODE128
image = b.Encode(type, encodestr.ToString)
context.Response.ContentType = "Image/Gif"
context.Response.Clear()
image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif)
Catch ex As Exception
'MessageBox.Show(ex.Message)
End Try
Else
context.Response.Write("sessioin error")
End If
End Sub
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
二維條碼 qr code DLL
https://docs.google.com/open?id=0Bxaw7Z2hq9CFa0t4dkVkMEZCOFU
'二維條碼 呼叫程式碼
Dim encoder As New ByCase.Lib.QRCode.Codec.QRCodeEncoder
'編碼有3種,分別是byte, alphanumeric, numeric
encoder.QRCodeEncodeMode = ByCase.Lib.QRCode.Codec.QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC
'(image pixels per QRCode pixel): 1, 2, 3, 4, 5, 10, 15, 30. ( in pixels )
encoder.QRCodeScale = 5
'二维码所能包含的字符信息量是由QrcodeVersion的设置值来决定的。将QrcodeVersion设置到20的时候,就已经可以容乃到300多个字节
encoder.QRCodeVersion = 20
'ByCase.Lib.QRCode.Codec.QRCodeEncoder.ERROR_CORRECTION.H L M Q
encoder.QRCodeErrorCorrect = ByCase.Lib.QRCode.Codec.QRCodeEncoder.ERROR_CORRECTION.H
'只能大寫英文, 數字, 空格+-*/冒號,不可以小寫、不可底線不可特殊符號
Dim data As String = Me.TextBox1.Text.ToUpper
Dim image As New System.Drawing.Bitmap(200, 200)
image = encoder.Encode(data)
Image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif)
二維條碼(方法2)
Google charts提供非常方便的API,可以產生QR Code圖片。
http://code.google.com/apis/chart/docs/gallery/qr_codes.html(API說明)
以下面URL為例,紅色部份為關鍵參數
https://chart.googleapis.com/chart?chs=120x120&cht=qr&chl=陳錫川&choe=UTF-8&chld=M|2
其中:
chs: QR code 圖片大小
cht: 圖片類型,google charts用這個參數產生各種圖片,這裡當然就填qr
chl: 要藏在QR code裡的文字,必須編成punycode(urlencode)。
choe: 編碼。請注意只支援iso-8859-1, sjis, utf8。詳見API說明網頁。
chld: 其他參數。M是錯誤修正層次,有L, M, Q, H等四級;後面的數字是QR code周圍白邊的寬度。
在webform放置textbox1與button,接著在button中撰寫以下程式即可
Dim imgsrc As String = "http://chart.apis.google.com/chart?chs=" & "400x400" & "&chl=" & Me.TextBox1.Text & "&choe=UTF-8&cht=qr"
Image1.ImageUrl = imgsrc
2012年12月6日 星期四
手機取消插播
最近手機電話中竟然有嘟嘟嘟的聲音,我心想是設了插播,打電話到中華電信卻說我的門號沒有設定這項功能,可能是手機自己的設定,原來
取消插播是 #43# 撥出
開啟插播是 *43# 撥出
趕緊記載blogger中
取消插播是 #43# 撥出
開啟插播是 *43# 撥出
趕緊記載blogger中
訂閱:
文章 (Atom)