Programalama > ASP.NET

Etiketler: font, kullanmadan, barkod, çizin

Ort. 0
Puan ver:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
---HTML Kodu ---
 
        <form id="Form1" method="post" runat="server">
            <asp:textbox id="txtBarkod" style="Z-INDEX: 106; LEFT: 220px; POSITION: absolute; TOP: 145px"
                runat="server" MaxLength="13" AutoPostBack="True"></asp:textbox>
            <asp:image id="imgBarkod" style="Z-INDEX: 102; LEFT: 220px; POSITION: absolute; TOP: 205px"
                runat="server" Visible="False" Width="120px" ImageUrl="../Images/NoBarcode.jpg" ImageAlign="AbsMiddle"
                Height="60px"></asp:image>
            <asp:label id="Label21" style="Z-INDEX: 103; LEFT: 125px; POSITION: absolute; TOP: 150px" runat="server"
                Font-Bold="True" Font-Size="11px" Font-Names="Verdana">EAN Barcode :</asp:label>
            <asp:Button id="btnTestDraw" style="Z-INDEX: 104; LEFT: 375px; POSITION: absolute; TOP: 145px"
                runat="server" Text="Test & Draw Barcode"></asp:Button>
            <asp:Label id="lblMessage" style="Z-INDEX: 105; LEFT: 220px; POSITION: absolute; TOP: 180px"
                runat="server" Font-Bold="True" Font-Size="12px" Font-Names="Verdana" ForeColor="Red"></asp:Label>
 
        </form>
 
---VB Kodu---
 
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Text
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D
 
    Public EANimgUrl As String
 
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        EANimgUrl = "EAN/"
 
        If Me.IsPostBack = True Then
            DrawCommand()
        End If
 
    End Sub
 
    Private Sub DrawCommand()
 
        Dim strEANCode, imgUrl As String
 
        strEANCode = txtBarkod.Text
        imgUrl = EANimgUrl & strEANCode & ".jpg"
 
        'Check exists EAN image file
        If Not File.Exists(Server.MapPath(imgUrl)) Then
 
            'Check Digit Control
            If CheckDigit(strEANCode) = True Then
                DrawEANBarCode(strEANCode, imgBarkod.Width.Value, imgBarkod.Height.Value)
                lblMessage.Text = ""
                imgBarkod.Visible = True
                imgBarkod.ImageUrl = imgUrl
            Else
                lblMessage.Text = "Invalid EAN Code!.."
                imgBarkod.Visible = False
            End If
 
        Else
 
            lblMessage.Text = ""
            imgBarkod.Visible = True
            imgBarkod.ImageUrl = imgUrl
 
        End If
 
    End Sub
 
    Public Sub DrawEANBarCode(ByVal strEANCode As String, _
                       ByVal imgWidth As Integer, _
                       ByVal imgHeight As Integer)
 
        Dim oGraphics As Graphics
        Dim oBitmap As Bitmap
        Dim K As Single
        Dim PosX As Single
        Dim PosY As Single
        Dim ScaleX As Single
        Dim strEANBin As String
        Dim strFormat As New StringFormat
 
        Dim FontForText As Font = New Font("Courier New", 10)
 
        strEANBin = EAN2Bin(strEANCode)
 
        Dim X1 As Single = 0
        Dim Y1 As Single = 0
        Dim X2 As Single = imgWidth
        Dim Y2 As Single = imgHeight
 
        PosX = X1
        PosY = Y2 - CSng(1.2 * FontForText.Height)
 
        'Draw new bitmap and clear area with white color
        oBitmap = New Bitmap(imgWidth, imgHeight, PixelFormat.Format24bppRgb)
        oGraphics = Graphics.FromImage(oBitmap)
        oGraphics.Clear(Color.White)
 
        ScaleX = (X2 - X1) / strEANBin.Length
 
        'Draw the BarCode lines
        For K = 1 To Len(strEANBin)
            If Mid(strEANBin, K, 1) = "1" Then
                oGraphics.FillRectangle(New System.Drawing.SolidBrush(Color.Black), PosX, Y1, ScaleX, PosY)
            End If
            PosX = X1 + (K * ScaleX)
        Next K
 
        'Draw strEAN Code text
        strFormat.Alignment = StringAlignment.Center
        strFormat.FormatFlags = StringFormatFlags.NoWrap
        oGraphics.DrawString(strEANCode, FontForText, New System.Drawing.SolidBrush(Color.Black), CSng((X2 - X1) / 2), CSng(Y2 - FontForText.Height), strFormat)
 
        'Save Bitmap to jpeg file
        oBitmap.Save(Server.MapPath(EANimgUrl & strEANCode & ".jpg"))
 
        'If u don't want to save image file use this line
        'oBitmap.Save(Response.OutputStream, ImageFormat.Jpeg)
 
        'Kill objects
        FontForText.Dispose()
        oGraphics.Dispose()
        oBitmap.Dispose()
 
    End Sub
 
    Public Function CheckDigit(ByVal strEANCode As String) As Boolean
 
        Dim Nums(12), i, k As Integer
        Dim ck As String = Right(strEANCode, 1)
        Dim realCK As String
 
        'If not is numeric EAN code Return False
        If Not IsNumeric(strEANCode) Then Return False
 
        i = 1
        If strEANCode.Length = 8 Then
            'Check Digit For EAN 8
            Do While i < 8
                Nums(i) = CType(Mid(strEANCode, i, 1), Integer)
                i += 1
            Loop
 
            k = (Nums(7) * 3)
            k += (Nums(6) * 1)
            k += (Nums(5) * 3)
            k += (Nums(4) * 1)
            k += (Nums(3) * 3)
            k += (Nums(2) * 1)
            k += (Nums(1) * 3)
            k = k Mod 10
            k = 10 - k
 
            realCK = k.ToString
 
        ElseIf strEANCode.Length = 13 Then
            'Check Digit For EAN 13
            Do While i < 13
                Nums(i) = CType(Mid(strEANCode, i, 1), Integer)
                i += 1
            Loop
 
            k = (Nums(12) * 3)
            k += (Nums(11) * 1)
            k += (Nums(10) * 3)
            k += (Nums(9) * 1)
            k += (Nums(8) * 3)
            k += (Nums(7) * 1)
            k += (Nums(6) * 3)
            k += (Nums(5) * 1)
            k += (Nums(4) * 3)
            k += (Nums(3) * 1)
            k += (Nums(2) * 3)
            k += (Nums(1) * 1)
            k = k Mod 10
            k = 10 - k
 
            realCK = k.ToString
 
        Else
            'Nothing EAN 8 or EAN 13 Code
            Return False
 
        End If
 
        If ck = realCK Then
            Return True
        Else
            Return False
        End If
 
    End Function
 
    Public Function EAN2Bin(ByVal strEANCode As String) As String
 
        Dim K As Integer
        Dim strAux As String
        Dim strExit As String
        Dim strCode As String
 
        strEANCode = Trim(strEANCode)
        strAux = strEANCode
 
        'Check EAN code (EAN8 or EAN13)
        If (strAux.Length <> 13) And (strAux.Length <> 8) Then
            Err.Raise(5, "EAN2Bin", "Invalid EAN Code!..")
        End If
 
        'Check numbers only
        For K = 0 To strEANCode.Length - 1
            Select Case (strAux.Chars(K).ToString)
                Case Is < "0", Is > "9"
                    Err.Raise(5, "EAN2Bin", "Please don't use any number characters!..")
            End Select
        Next
 
        'For EAN13
        If (strAux.Length = 13) Then
 
            strAux = Mid(strAux, 2)
 
            Select Case CInt(Left(strEANCode, 1))
                Case 0
                    strCode = "000000"
                Case 1
                    strCode = "001011"
                Case 2
                    strCode = "001101"
                Case 3
                    strCode = "001110"
                Case 4
                    strCode = "010011"
                Case 5
                    strCode = "011001"
                Case 6
                    strCode = "011100"
                Case 7
                    strCode = "010101"
                Case 8
                    strCode = "010110"
                Case 9
                    strCode = "011010"
            End Select
        Else 'For EAN8
            strCode = "0000"
        End If
 
        strExit = "000101"
 
        For K = 1 To Len(strAux) \ 2
            Select Case CInt(Mid(strAux, K, 1))
                Case 0
                    strExit &= IIf(Mid(strCode, K, 1) = "0", "0001101", "0100111")
                Case 1
                    strExit &= IIf(Mid(strCode, K, 1) = "0", "0011001", "0110011")
                Case 2
                    strExit &= IIf(Mid(strCode, K, 1) = "0", "0010011", "0011011")
                Case 3
                    strExit &= IIf(Mid(strCode, K, 1) = "0", "0111101", "0100001")
                Case 4
                    strExit &= IIf(Mid(strCode, K, 1) = "0", "0100011", "0011101")
                Case 5
                    strExit &= IIf(Mid(strCode, K, 1) = "0", "0110001", "0111001")
                Case 6
                    strExit &= IIf(Mid(strCode, K, 1) = "0", "0101111", "0000101")
                Case 7
                    strExit &= IIf(Mid(strCode, K, 1) = "0", "0111011", "0010001")
                Case 8
                    strExit &= IIf(Mid(strCode, K, 1) = "0", "0110111", "0001001")
                Case 9
                    strExit &= IIf(Mid(strCode, K, 1) = "0", "0001011", "0010111")
            End Select
        Next K
 
        strExit &= "01010"
 
        For K = Len(strAux) \ 2 + 1 To Len(strAux)
            Select Case CInt(Mid(strAux, K, 1))
                Case 0
                    strExit &= "1110010"
                Case 1
                    strExit &= "1100110"
                Case 2
                    strExit &= "1101100"
                Case 3
                    strExit &= "1000010"
                Case 4
                    strExit &= "1011100"
                Case 5
                    strExit &= "1001110"
                Case 6
                    strExit &= "1010000"
                Case 7
                    strExit &= "1000100"
                Case 8
                    strExit &= "1001000"
                Case 9
                    strExit &= "1110100"
            End Select
        Next K
 
        strExit &= "101000"
 
        EAN2Bin = strExit
 
    End Function


Yorumlar                 Yorum Yaz
Bu hazır kod'a ilk yorumu siz yapın!
KATEGORİLER
ASP - 240
ASP.NET - 24
C# - 75
C++ - 174
CGI - 8
DELPHI - 247
FLASH - 49
HTML - 536
PASCAL - 246
PERL - 11
PHP - 160
WML - 9
XML - 2
Copyright © 2002 - 2025 Hazır Kod - Tüm Hakları Saklıdır.
Siteden yararlanırken gizlilik ilkelerini okumanızı tavsiye ederiz.
hazirkod.com bir İSOBİL projesidir.