|
@@ -1,9 +1,20 @@
|
1
|
1
|
Option Strict Off
|
2
|
2
|
Imports System.IO
|
3
|
3
|
Imports System.Net
|
|
4
|
+Imports Microsoft.Office.Interop.Excel.XlUnderlineStyle
|
|
5
|
+Imports Microsoft.Office.Interop.Excel.Constants
|
|
6
|
+Imports Microsoft.Office.Interop.Excel.XlBordersIndex
|
|
7
|
+Imports Microsoft.Office.Interop.Excel.XlLineStyle
|
|
8
|
+Imports Microsoft.Office.Interop.Excel.XlBorderWeight
|
|
9
|
+Imports Microsoft.Office.Interop.Excel.XlThemeFont
|
|
10
|
+Imports Microsoft.Office.Interop.Excel.XlThemeColor
|
|
11
|
+Imports Microsoft.Office.Interop.Excel.XlWindowState
|
4
|
12
|
Public Class 物料資料庫
|
5
|
13
|
ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet : ReadOnly ds2 As New DataSet
|
6
|
|
- Dim EDR As Integer = 0 : Dim ESTR As String
|
|
14
|
+ Dim EDR, N As Integer : Dim ESTR, file_name As String
|
|
15
|
+ Dim xlApp As Microsoft.Office.Interop.Excel.Application
|
|
16
|
+ Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
|
|
17
|
+ Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
|
7
|
18
|
Private Sub Set_DGV1開始()
|
8
|
19
|
物料清單_dgv.DataSource = Nothing : ds.Clear()
|
9
|
20
|
物料清單_dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
|
|
@@ -71,7 +82,7 @@ Public Class 物料資料庫
|
71
|
82
|
Target1 = Target & AA(1) & "/"
|
72
|
83
|
FTP資料夾_wb.Url = New Uri(Target1)
|
73
|
84
|
End Sub
|
74
|
|
- Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles 物料清單_dgv.CellClick
|
|
85
|
+ Private Sub 物料清單_dgv_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles 物料清單_dgv.CellClick
|
75
|
86
|
If e.RowIndex = -1 Then : Else
|
76
|
87
|
料號_tb.Text = 物料清單_dgv.Rows(e.RowIndex).Cells("料號").Value.ToString : 頁碼_tb.Text = 物料清單_dgv.Rows(e.RowIndex).Cells("頁碼").Value.ToString
|
77
|
88
|
品名_tb.Text = 物料清單_dgv.Rows(e.RowIndex).Cells("品名").Value.ToString : 成本_nud.Value = 物料清單_dgv.Rows(e.RowIndex).Cells("成本").Value.ToString
|
|
@@ -178,7 +189,7 @@ Public Class 物料資料庫
|
178
|
189
|
If 圖片編碼_tb.Text = "" Then : MsgBox("所選擇的資料沒有圖片檔案,無法下載。")
|
179
|
190
|
Else
|
180
|
191
|
With SaveFileDialog1 : .Filter = "所有文件(*.jpg)|*.jpg" : End With
|
181
|
|
- SaveFileDialog1.FileName = 圖片編碼_tb.Text & "-" & Format(Today(), "yyyyMMdd") & ".jpg"
|
|
192
|
+ SaveFileDialog1.FileName = 圖片編碼_tb.Text & "-" & Strings.Format(Today(), "yyyyMMdd") & ".jpg"
|
182
|
193
|
|
183
|
194
|
SaveFileDialog1.ShowDialog() : 下載檔名_tb.Text = SaveFileDialog1.FileName
|
184
|
195
|
ds2.Clear() : SQL_物料圖庫_圖片下載() : da.Fill(ds2) : conn.Close()
|
|
@@ -313,4 +324,233 @@ Public Class 物料資料庫
|
313
|
324
|
MsgBox("刪除完成") : Set_物料清單() : Set_未配置圖片的物料清單() : PA = ""
|
314
|
325
|
End If
|
315
|
326
|
End Sub
|
|
327
|
+
|
|
328
|
+ Private Sub 批量修改_ch_CheckedChanged(sender As Object, e As EventArgs) Handles 批量修改_ch.CheckedChanged
|
|
329
|
+
|
|
330
|
+ End Sub
|
|
331
|
+
|
|
332
|
+ Private Sub 導出EXCEL_bt_Click_1(sender As Object, e As EventArgs) Handles 導出EXCEL_bt.Click
|
|
333
|
+ xlApp = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
|
|
334
|
+ xlBook = xlApp.Workbooks.Add
|
|
335
|
+ xlApp.DisplayAlerts = True
|
|
336
|
+ xlBook.Activate()
|
|
337
|
+ xlSheet = NewMethod(xlBook)
|
|
338
|
+ xlSheet.Activate()
|
|
339
|
+ xlApp.Visible = True
|
|
340
|
+ xlApp.Application.WindowState = xlMaximized
|
|
341
|
+
|
|
342
|
+ xlSheet.Cells(1, 1) = "系統物料資料庫總表"
|
|
343
|
+ xlSheet.Cells(2, 1) = "請注意,料號欄位為系統主要參考項目,請勿修改,如有新增品項的需求,清直接新增在EXCEL資料表最下方,從新導入時系統會自動新增品項到資料庫中。"
|
|
344
|
+ xlSheet.Cells(3, 1) = "料號"
|
|
345
|
+ xlSheet.Cells(3, 2) = "頁碼"
|
|
346
|
+ xlSheet.Cells(3, 3) = "品名"
|
|
347
|
+ xlSheet.Cells(3, 4) = "成本"
|
|
348
|
+ xlSheet.Cells(3, 5) = "售價"
|
|
349
|
+ xlSheet.Cells(3, 6) = "件數"
|
|
350
|
+ xlSheet.Cells(3, 7) = "尺寸"
|
|
351
|
+ xlSheet.Cells(3, 8) = "材質"
|
|
352
|
+ xlSheet.Cells(3, 9) = "備註"
|
|
353
|
+ xlSheet.Cells(3, 10) = "最低庫存量"
|
|
354
|
+
|
|
355
|
+ For i As Integer = 0 To 物料清單_dgv.Rows.Count - 1
|
|
356
|
+ xlSheet.Cells(i + 4, 1) = 物料清單_dgv.Rows(i).Cells("料號").Value
|
|
357
|
+ xlSheet.Cells(i + 4, 2) = 物料清單_dgv.Rows(i).Cells("頁碼").Value
|
|
358
|
+ xlSheet.Cells(i + 4, 3) = 物料清單_dgv.Rows(i).Cells("品名").Value
|
|
359
|
+ xlSheet.Cells(i + 4, 4) = 物料清單_dgv.Rows(i).Cells("成本").Value
|
|
360
|
+ xlSheet.Cells(i + 4, 5) = 物料清單_dgv.Rows(i).Cells("售價").Value
|
|
361
|
+ xlSheet.Cells(i + 4, 6) = 物料清單_dgv.Rows(i).Cells("件數").Value
|
|
362
|
+ xlSheet.Cells(i + 4, 7) = 物料清單_dgv.Rows(i).Cells("尺寸").Value
|
|
363
|
+ xlSheet.Cells(i + 4, 8) = 物料清單_dgv.Rows(i).Cells("材質").Value
|
|
364
|
+ xlSheet.Cells(i + 4, 9) = 物料清單_dgv.Rows(i).Cells("備註").Value
|
|
365
|
+ xlSheet.Cells(i + 4, 10) = 物料清單_dgv.Rows(i).Cells("最低庫存量").Value
|
|
366
|
+ With xlApp.Selection
|
|
367
|
+ .Font.Bold = True
|
|
368
|
+ End With
|
|
369
|
+ N = i + 4
|
|
370
|
+ Next i
|
|
371
|
+ BB(xlApp, xlSheet)
|
|
372
|
+ xlSheet.PageSetup.PrintArea = ""
|
|
373
|
+ xlApp.Cells.Select()
|
|
374
|
+ xlSheet.Range("B1").Select()
|
|
375
|
+ xlApp.Application.WindowState = xlMinimized
|
|
376
|
+ MsgBox("列印完成")
|
|
377
|
+ End Sub
|
|
378
|
+ Private Shared Function NewMethod(xlBook As Microsoft.Office.Interop.Excel.Workbook) As Microsoft.Office.Interop.Excel.Worksheet
|
|
379
|
+ Return CType(xlBook.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet)
|
|
380
|
+ End Function
|
|
381
|
+ Private Sub BB(ByVal myExcel As Microsoft.Office.Interop.Excel.Application, ByVal xlSheet As Microsoft.Office.Interop.Excel.Worksheet)
|
|
382
|
+ xlSheet.Cells.Select()
|
|
383
|
+ With myExcel.Selection.Font
|
|
384
|
+ .Name = "微軟正黑體" : .Size = 12
|
|
385
|
+ .Strikethrough = False : .Superscript = False : .Subscript = False
|
|
386
|
+ .OutlineFont = False : .Shadow = False
|
|
387
|
+ .Underline = xlUnderlineStyleNone : .ThemeColor = xlThemeColorLight1
|
|
388
|
+ .TintAndShade = 0 : .ThemeFont = xlThemeFontNone
|
|
389
|
+ End With
|
|
390
|
+
|
|
391
|
+ xlSheet.Columns("A:A").Select : myExcel.Selection.ColumnWidth = 12
|
|
392
|
+ xlSheet.Columns("B:B").Select : myExcel.Selection.ColumnWidth = 10
|
|
393
|
+ xlSheet.Columns("C:C").Select : myExcel.Selection.ColumnWidth = 35
|
|
394
|
+ xlSheet.Columns("G:G").Select : myExcel.Selection.ColumnWidth = 30
|
|
395
|
+ xlSheet.Columns("H:H").Select : myExcel.Selection.ColumnWidth = 30
|
|
396
|
+ xlSheet.Columns("I:I").Select : myExcel.Selection.ColumnWidth = 30
|
|
397
|
+ xlSheet.Range("A1:J1").Select()
|
|
398
|
+ With myExcel.Selection
|
|
399
|
+ .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False : .Orientation = 0
|
|
400
|
+ .AddIndent = False : .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
|
|
401
|
+ End With
|
|
402
|
+ myExcel.Selection.Merge
|
|
403
|
+
|
|
404
|
+ xlSheet.Range("A2:J2").Select()
|
|
405
|
+ With myExcel.Selection
|
|
406
|
+ .HorizontalAlignment = xlCenter : .VerticalAlignment = xlCenter : .WrapText = False
|
|
407
|
+ .Orientation = 0 : .AddIndent = False : .IndentLevel = 0
|
|
408
|
+ .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
|
|
409
|
+ End With
|
|
410
|
+ myExcel.Selection.Merge
|
|
411
|
+
|
|
412
|
+ xlSheet.Range("A2:J2").Select()
|
|
413
|
+ With myExcel.Selection.Font
|
|
414
|
+ .Color = -16776961 : .TintAndShade = 0
|
|
415
|
+ End With
|
|
416
|
+
|
|
417
|
+ xlSheet.Range("A1:J1").Select()
|
|
418
|
+ With myExcel.Selection.Font
|
|
419
|
+ .Name = "微軟正黑體" : .Size = 18
|
|
420
|
+ .Strikethrough = False : .Superscript = False
|
|
421
|
+ .Subscript = False : .OutlineFont = False
|
|
422
|
+ .Shadow = False : .Underline = xlUnderlineStyleNone
|
|
423
|
+ .ThemeColor = xlThemeColorLight1 : .TintAndShade = 0
|
|
424
|
+ .ThemeFont = xlThemeFontNone
|
|
425
|
+ End With
|
|
426
|
+
|
|
427
|
+ xlSheet.Range("A1:J3").Select()
|
|
428
|
+ myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
|
|
429
|
+ myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
|
|
430
|
+ With myExcel.Selection.Borders(xlEdgeLeft)
|
|
431
|
+ .LineStyle = xlContinuous : .ColorIndex = 0
|
|
432
|
+ .TintAndShade = 0 : .Weight = xlThin
|
|
433
|
+ End With
|
|
434
|
+ With myExcel.Selection.Borders(xlEdgeTop)
|
|
435
|
+ .LineStyle = xlContinuous : .ColorIndex = 0
|
|
436
|
+ .TintAndShade = 0 : .Weight = xlThin
|
|
437
|
+ End With
|
|
438
|
+ With myExcel.Selection.Borders(xlEdgeBottom)
|
|
439
|
+ .LineStyle = xlContinuous
|
|
440
|
+ .ColorIndex = 0 : .TintAndShade = 0 : .Weight = xlThin
|
|
441
|
+ End With
|
|
442
|
+ With myExcel.Selection.Borders(xlEdgeRight)
|
|
443
|
+ .LineStyle = xlContinuous : .ColorIndex = 0
|
|
444
|
+ .TintAndShade = 0 : .Weight = xlThin
|
|
445
|
+ End With
|
|
446
|
+ With myExcel.Selection.Borders(xlInsideVertical)
|
|
447
|
+ .LineStyle = xlContinuous : .ColorIndex = 0
|
|
448
|
+ .TintAndShade = 0 : .Weight = xlThin
|
|
449
|
+ End With
|
|
450
|
+ With myExcel.Selection.Borders(xlInsideHorizontal)
|
|
451
|
+ .LineStyle = xlContinuous : .ColorIndex = 0
|
|
452
|
+ .TintAndShade = 0 : .Weight = xlThin
|
|
453
|
+ End With
|
|
454
|
+
|
|
455
|
+ xlSheet.Range("A4:J" & N).Select()
|
|
456
|
+ myExcel.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
|
|
457
|
+ myExcel.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
|
|
458
|
+ With myExcel.Selection.Borders(xlEdgeLeft)
|
|
459
|
+ .LineStyle = xlContinuous : .ColorIndex = 0
|
|
460
|
+ .TintAndShade = 0 : .Weight = xlThin
|
|
461
|
+ End With
|
|
462
|
+ With myExcel.Selection.Borders(xlEdgeTop)
|
|
463
|
+ .LineStyle = xlContinuous : .ColorIndex = 0
|
|
464
|
+ .TintAndShade = 0 : .Weight = xlThin
|
|
465
|
+ End With
|
|
466
|
+ With myExcel.Selection.Borders(xlEdgeBottom)
|
|
467
|
+ .LineStyle = xlContinuous : .ColorIndex = 0
|
|
468
|
+ .TintAndShade = 0 : .Weight = xlThin
|
|
469
|
+ End With
|
|
470
|
+ With myExcel.Selection.Borders(xlEdgeRight)
|
|
471
|
+ .LineStyle = xlContinuous : .ColorIndex = 0
|
|
472
|
+ .TintAndShade = 0 : .Weight = xlThin
|
|
473
|
+ End With
|
|
474
|
+ With myExcel.Selection.Borders(xlInsideVertical)
|
|
475
|
+ .LineStyle = xlContinuous : .ColorIndex = 0
|
|
476
|
+ .TintAndShade = 0 : .Weight = xlThin
|
|
477
|
+ End With
|
|
478
|
+ With myExcel.Selection.Borders(xlInsideHorizontal)
|
|
479
|
+ .LineStyle = xlContinuous : .ColorIndex = 0
|
|
480
|
+ .TintAndShade = 0 : .Weight = xlThin
|
|
481
|
+ End With
|
|
482
|
+
|
|
483
|
+ xlSheet.Rows("3:3").Select
|
|
484
|
+ myExcel.Selection.RowHeight = 35
|
|
485
|
+ With myExcel.Selection
|
|
486
|
+ .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlCenter
|
|
487
|
+ .WrapText = True : .Orientation = 0 : .AddIndent = False
|
|
488
|
+ .IndentLevel = 0 : .ShrinkToFit = False : .ReadingOrder = xlContext : .MergeCells = False
|
|
489
|
+ End With
|
|
490
|
+ With myExcel.Selection
|
|
491
|
+ .HorizontalAlignment = xlGeneral : .VerticalAlignment = xlTop
|
|
492
|
+ .WrapText = True : .Orientation = 0 : .AddIndent = False
|
|
493
|
+ .IndentLevel = 0 : .ShrinkToFit = False
|
|
494
|
+ .ReadingOrder = xlContext : .MergeCells = False
|
|
495
|
+ End With
|
|
496
|
+
|
|
497
|
+ xlSheet.Rows("4:4").Select : myExcel.ActiveWindow.FreezePanes = False
|
|
498
|
+ xlSheet.Rows("4:4").Select : myExcel.ActiveWindow.FreezePanes = True
|
|
499
|
+ xlSheet.Rows("3:3").Select : myExcel.Selection.AutoFilter
|
|
500
|
+ myExcel.ActiveWindow.DisplayGridlines = False
|
|
501
|
+
|
|
502
|
+ End Sub
|
|
503
|
+ Private Sub 導入EXCEL_bt_Click(sender As Object, e As EventArgs) Handles 導入EXCEL_bt.Click
|
|
504
|
+ If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
|
|
505
|
+ file_name = OpenFileDialog1.FileName
|
|
506
|
+ xlApp = CreateObject("Excel.Application")
|
|
507
|
+ xlApp.DisplayAlerts = False
|
|
508
|
+ xlApp.Visible = True
|
|
509
|
+ xlApp.Workbooks.Open(file_name)
|
|
510
|
+ xlSheet = xlApp.Worksheets(1)
|
|
511
|
+ xlSheet.Activate()
|
|
512
|
+ xlApp.Visible = False
|
|
513
|
+ Dim 次數 As Integer = 0
|
|
514
|
+ For YY As Integer = 1 To 3000
|
|
515
|
+ 資料數 = 3000 : MyModule1.進度條()
|
|
516
|
+ If IsNothing(xlSheet.Cells(YY + 3, 3).value) Then
|
|
517
|
+ Exit For
|
|
518
|
+ End If
|
|
519
|
+ If IsNothing(xlSheet.Cells(YY + 3, 1).value) Then
|
|
520
|
+ '----------------------自动生成流水号-------------------------------------------------------------------------
|
|
521
|
+ SQL_物料圖庫流水號最後一筆()
|
|
522
|
+ If dr.Read() Then : EDR = Double.Parse(Strings.Right(dr("料號").ToString, 8)) : Else : EDR = 0 : End If : conn.Close() : EDR += 1
|
|
523
|
+ If EDR < 10 Then : ESTR = "PR" & "0000000" & EDR
|
|
524
|
+ ElseIf EDR > 9 And EDR < 100 Then : ESTR = "PR" & "000000" & EDR
|
|
525
|
+ ElseIf EDR > 99 And EDR < 1000 Then : ESTR = "PR" & "00000" & EDR
|
|
526
|
+ ElseIf EDR > 999 And EDR < 10000 Then : ESTR = "PR" & "0000" & EDR
|
|
527
|
+ ElseIf EDR > 9999 And EDR < 100000 Then : ESTR = "PR" & "000" & EDR
|
|
528
|
+ ElseIf EDR > 99999 And EDR < 100000 Then : ESTR = "PR" & "00" & EDR
|
|
529
|
+ ElseIf EDR > 999999 And EDR < 1000000 Then : ESTR = "PR" & "0" & EDR
|
|
530
|
+ ElseIf EDR > 9999999 Then : ESTR = "PR" & EDR : End If
|
|
531
|
+ ConnOpen()
|
|
532
|
+ SQL1 = "INSERT INTO 物料資料庫 (料號, 頁碼, 品名, 成本, 售價, 件數, 尺寸, 材質, 圖片編碼, 備註, 停用, 最低庫存量)
|
|
533
|
+ VALUES (N'" & ESTR & "', N'" & xlSheet.Cells(YY + 3, 2).value & "', N'" & xlSheet.Cells(YY + 3, 3).value & "',
|
|
534
|
+ N'" & xlSheet.Cells(YY + 3, 4).value & "', N'" & xlSheet.Cells(YY + 3, 5).value & "', N'" & xlSheet.Cells(YY + 3, 6).value & "',
|
|
535
|
+ N'" & xlSheet.Cells(YY + 3, 7).value & "', N'" & xlSheet.Cells(YY + 3, 8).value & "', '', N'" & xlSheet.Cells(YY + 3, 9).value & "',
|
|
536
|
+ '0', N'" & xlSheet.Cells(YY + 3, 10).value & "')"
|
|
537
|
+ CmdSet_For_dr() : conn.Close()
|
|
538
|
+ 次數 += 1
|
|
539
|
+ Else
|
|
540
|
+ ConnOpen()
|
|
541
|
+ SQL1 = "UPDATE 物料資料庫 SET 頁碼 = N'" & xlSheet.Cells(YY + 3, 2).value & "', 品名 = N'" & xlSheet.Cells(YY + 3, 3).value & "',
|
|
542
|
+ 成本 = N'" & xlSheet.Cells(YY + 3, 4).value & "', 售價 = N'" & xlSheet.Cells(YY + 3, 5).value & "',
|
|
543
|
+ 件數 = N'" & xlSheet.Cells(YY + 3, 6).value & "', 尺寸 = N'" & xlSheet.Cells(YY + 3, 7).value & "',
|
|
544
|
+ 材質 = N'" & xlSheet.Cells(YY + 3, 8).value & "', 備註 = N'" & xlSheet.Cells(YY + 3, 9).value & "',
|
|
545
|
+ 最低庫存量 = N'" & xlSheet.Cells(YY + 3, 10).value & "'
|
|
546
|
+ WHERE 料號 LIKE N'" & xlSheet.Cells(YY + 3, 1).value & "'"
|
|
547
|
+ CmdSet_For_dr() : conn.Close()
|
|
548
|
+ 次數 += 1
|
|
549
|
+ End If
|
|
550
|
+ Next : MAOJI_ERP_SYS.ToolStripProgressBar1.Value = 0 : 最終數 = 0
|
|
551
|
+ MsgBox("已修改 " & 次數 & " 次!")
|
|
552
|
+ xlApp.Quit() : xlApp = Nothing
|
|
553
|
+ ElseIf OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.No Then
|
|
554
|
+ End If : Set_物料清單()
|
|
555
|
+ End Sub
|
316
|
556
|
End Class
|