No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

匯率修改.vb 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. Option Strict Off
  2. Imports System.Data.SqlClient
  3. Public Class 匯率修改
  4. Dim conn As New SqlConnection : Dim conn1 As New SqlConnection : Dim conn2 As New SqlConnection
  5. Dim da As New SqlDataAdapter : Dim wsx As New SqlDataAdapter : Dim da2 As New SqlDataAdapter
  6. Dim cmd As New SqlCommand : Dim cmd1 As New SqlCommand : Dim cmd2 As New SqlCommand
  7. Dim dr As SqlDataReader : Dim dr1 As SqlDataReader
  8. Dim zaq As New DataSet : Dim ds2 As DataSet
  9. Private Sub Set_grid()
  10. DataGridView4.Columns(0).FillWeight = 60 : DataGridView4.Columns(1).FillWeight = 60
  11. DataGridView4.Columns(2).FillWeight = 60 : DataGridView4.Columns(3).FillWeight = 60
  12. DataGridView4.Columns(4).FillWeight = 60 : DataGridView4.Columns(5).FillWeight = 60
  13. End Sub
  14. Private Sub Set_日期()
  15. TextBox4.Text = Format(DateTimePicker1.Value, "yyyy") : TextBox5.Text = Format(DateTimePicker1.Value, "MM")
  16. End Sub
  17. Private Sub Set_歷史匯率清單()
  18. DataGridView4.DataSource = Nothing : zaq.Clear()
  19. DataGridView4.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  20. DataGridView4.ColumnHeadersHeight = 25
  21. DataGridView4.AllowUserToAddRows = False
  22. If conn2.State = ConnectionState.Closed Then : conn2.ConnectionString = ConString : conn2.Open() : End If
  23. SQL2 = "SELECT 年, 月, 買進匯率, 賣出匯率, 中心匯率, 美金匯率 FROM 歷史匯率表 ORDER BY 年 DESC, 月 DESC"
  24. cmd2.Connection = conn2 : cmd2.CommandText = SQL2 : wsx.SelectCommand = cmd2 : wsx.Fill(zaq) : DataGridView4.DataSource = zaq.Tables(0) : conn2.Close()
  25. End Sub
  26. Private Sub DataGridView4_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView4.CellClick
  27. If e.RowIndex = -1 Then : Else
  28. TextBox2.Text = DataGridView4(2, e.RowIndex).Value.ToString
  29. TextBox3.Text = DataGridView4(3, e.RowIndex).Value.ToString
  30. TextBox1.Text = DataGridView4(4, e.RowIndex).Value.ToString
  31. TextBox6.Text = DataGridView4(5, e.RowIndex).Value.ToString
  32. End If
  33. End Sub
  34. Private Sub Set_日期寫入()
  35. Set_日期()
  36. If conn1.State = ConnectionState.Closed Then : conn1.ConnectionString = ConString : conn1.Open() : End If
  37. SQL1 = "SELECT 買進匯率, 賣出匯率, 中心匯率 FROM 歷史匯率表 WHERE (年 LIKE '" & TextBox4.Text & "%') AND (月 LIKE '" & TextBox5.Text & "%')"
  38. cmd1.Connection = conn1 : cmd1.CommandText = SQL1 : dr1 = cmd1.ExecuteReader
  39. If dr1.Read() Then
  40. If conn.State = ConnectionState.Closed Then : conn.Open() : End If
  41. SQL = "UPDATE 歷史匯率表 SET 買進匯率 = '" & TextBox2.Text & "', 賣出匯率 = '" & TextBox3.Text & "', 中心匯率 = '" & TextBox1.Text & "', 美金匯率 = '" & TextBox6.Text & "'
  42. WHERE (年 LIKE '" & TextBox4.Text & "%') AND (月 LIKE '" & TextBox5.Text & "%')"
  43. cmd.Connection = conn : cmd.CommandText = SQL : cmd.ExecuteNonQuery()
  44. conn.Close()
  45. Else
  46. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  47. SQL = "INSERT INTO 歷史匯率表 (年, 月, 買進匯率, 賣出匯率, 中心匯率, 美金匯率) VALUES ('" & TextBox4.Text & "','" & TextBox5.Text & "
  48. ','" & TextBox2.Text & "', '" & TextBox3.Text & "', '" & TextBox1.Text & "', '" & TextBox6.Text & "')"
  49. cmd.Connection = conn : cmd.CommandText = SQL : cmd.ExecuteNonQuery()
  50. conn.Close()
  51. End If
  52. conn1.Close()
  53. MsgBox("完成")
  54. End Sub
  55. Private Sub 匯率修改_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  56. DateTimePicker1.Value = Today
  57. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  58. SQL = "SELECT 匯率 FROM 匯率表 WHERE (對應 = '人民幣兌台幣')"
  59. cmd.Connection = conn : cmd.CommandText = SQL : dr = cmd.ExecuteReader
  60. If dr.Read() Then : TextBox1.Text = dr("匯率").ToString : End If
  61. If TextBox1.Text = "" Then : TextBox1.Text = "0.00" : End If
  62. conn.Close() : dr.Close()
  63. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  64. SQL = "SELECT 買進匯率, 賣出匯率, 美金匯率 FROM 歷史匯率表 WHERE (年 LIKE '" & TextBox4.Text & "%') AND (月 LIKE '" & TextBox5.Text & "%')"
  65. cmd.Connection = conn : cmd.CommandText = SQL : dr = cmd.ExecuteReader
  66. If dr.Read() Then : TextBox2.Text = dr("買進匯率").ToString : TextBox3.Text = dr("賣出匯率").ToString : TextBox3.Text = dr("美金匯率").ToString : End If
  67. If TextBox1.Text = "" Then : TextBox1.Text = "0.00" : End If
  68. conn.Close() : dr.Close()
  69. Set_歷史匯率清單() : Set_grid() : Set_日期()
  70. End Sub
  71. Private Sub 登入閒置控制_MouseMove(sender As Object, e As EventArgs) Handles MyBase.MouseMove
  72. timeNow = 0
  73. GCM_ERP_SYS.Timer1.Enabled = False
  74. GCM_ERP_SYS.Timer1.Enabled = True
  75. End Sub
  76. Private Sub 登入閒置控制_KeyPress(sender As Object, e As EventArgs) Handles MyBase.KeyPress
  77. timeNow = 0
  78. GCM_ERP_SYS.Timer1.Enabled = False
  79. GCM_ERP_SYS.Timer1.Enabled = True
  80. End Sub
  81. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  82. TextBox1.Enabled = True : TextBox2.Enabled = True : TextBox3.Enabled = True : TextBox6.Enabled = True : Button4.Enabled = True : Button5.Enabled = True
  83. End Sub
  84. Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  85. TextBox1.Enabled = False : TextBox2.Enabled = False : TextBox3.Enabled = False : TextBox6.Enabled = False : Button4.Enabled = False : Button5.Enabled = False
  86. End Sub
  87. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  88. If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
  89. MsgBox("輸入資料有誤")
  90. Else
  91. If CheckBox1.Checked = False Then
  92. DateTimePicker1.Value = Today
  93. Set_日期寫入()
  94. If conn.State = ConnectionState.Closed Then : conn.Open() : End If
  95. SQL = "UPDATE 匯率表 SET 匯率 = '" & TextBox1.Text & "' WHERE (對應 = '人民幣兌台幣')"
  96. cmd.CommandText = SQL : cmd.ExecuteNonQuery()
  97. conn.Close()
  98. conn1.Close() : dr1.Close()
  99. Else
  100. Set_日期寫入()
  101. End If
  102. End If
  103. TextBox1.Enabled = False : TextBox2.Enabled = False : TextBox3.Enabled = False : TextBox6.Enabled = False : Button4.Enabled = False : Button5.Enabled = False
  104. Set_歷史匯率清單() : Set_grid() : Set_日期()
  105. End Sub
  106. Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
  107. If TextBox2.Text <> "" And TextBox3.Text <> "" Then
  108. TextBox1.Text = (Val(TextBox2.Text) + Val(TextBox3.Text)) / 2
  109. End If
  110. End Sub
  111. Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
  112. If TextBox2.Text <> "" And TextBox3.Text <> "" Then
  113. TextBox1.Text = (Val(TextBox2.Text) + Val(TextBox3.Text)) / 2
  114. End If
  115. End Sub
  116. End Class