설명 없음
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 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. Option Strict Off
  2. Imports System.Data.SqlClient
  3. Public Class 營運成本收支單申請
  4. ReadOnly conn As New SqlConnection
  5. ReadOnly da As New SqlDataAdapter
  6. ReadOnly cmd As New SqlCommand
  7. ReadOnly ds As New DataSet : ReadOnly ds1 As New DataSet
  8. Dim dr As SqlDataReader
  9. Dim DTP As String : Dim DTP1 As String : Dim 新項次 As String : Dim WWEE As String : Dim 新流水1 As String : Dim 新流水2 As String
  10. Dim NUM1 As Integer : Dim 匯率1 As Double
  11. Private Sub Set_清單1()
  12. DataGridView2.DataSource = Nothing : ds1.Clear()
  13. DataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  14. DataGridView2.ColumnHeadersHeight = 25
  15. DataGridView2.AllowUserToAddRows = False
  16. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  17. If RadioButton1.Checked = True And RadioButton2.Checked = False And RadioButton3.Checked = False Then
  18. WWEE = "WHERE (審核人 LIKE '') "
  19. ElseIf RadioButton1.Checked = False And RadioButton2.Checked = True And RadioButton3.Checked = False Then
  20. WWEE = "WHERE (審核人 LIKE '作廢%') "
  21. ElseIf RadioButton1.Checked = False And RadioButton2.Checked = False And RadioButton3.Checked = True Then
  22. WWEE = "WHERE (審核人 NOT LIKE '作廢%') AND (審核人 NOT LIKE '') "
  23. End If
  24. SQL1 = "SELECT 支付單號 AS 收支單號, 申請日期, 審核日期, 申請人 FROM 公帳控制表 " & WWEE & " ORDER BY 申請日期 DESC"
  25. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds1) : DataGridView2.DataSource = ds1.Tables(0) : conn.Close()
  26. DataGridView2.Columns(0).FillWeight = 160 : DataGridView2.Columns(1).FillWeight = 100 : DataGridView2.Columns(2).FillWeight = 100 : DataGridView2.Columns(3).Visible = False
  27. End Sub
  28. Private Sub Set_費用清單()
  29. DataGridView1.DataSource = Nothing : ds.Clear()
  30. DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
  31. DataGridView1.ColumnHeadersHeight = 25
  32. DataGridView1.AllowUserToAddRows = False
  33. DataGridView1.RowTemplate.Height = 35
  34. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  35. SQL1 = "SELECT 公帳流水帳.支付單號, 公帳流水帳.項次, 會計科目.會計科目, 公帳流水帳.明細 AS 用途,
  36. 公帳流水帳.零用金, 公帳流水帳.支票數 AS 支票, Cast(公帳流水帳.收入 AS money) AS 現金,
  37. Cast(公帳流水帳.支出 AS money) AS 支出, 公帳流水帳.備註 AS 票期, 公帳流水帳.匯率, 公帳流水帳.銀行 AS 幣別, 公帳流水帳.類別, 公帳流水帳.流水號
  38. FROM 公帳流水帳 INNER JOIN
  39. 會計科目 ON 公帳流水帳.類別 = 會計科目.編號
  40. WHERE (公帳流水帳.支付單號 LIKE '" & TextBox1.Text & "')
  41. ORDER BY 公帳流水帳.項次"
  42. cmd.Connection = conn : cmd.CommandText = SQL1 : da.SelectCommand = cmd : da.Fill(ds) : DataGridView1.DataSource = ds.Tables(0) : conn.Close()
  43. DataGridView1.Columns(0).Visible = False : DataGridView1.Columns(1).FillWeight = 80 : DataGridView1.Columns(2).FillWeight = 300 : DataGridView1.Columns(3).FillWeight = 500
  44. DataGridView1.Columns(4).FillWeight = 140 : DataGridView1.Columns(5).FillWeight = 140 : DataGridView1.Columns(6).FillWeight = 140 : DataGridView1.Columns(7).FillWeight = 140
  45. DataGridView1.Columns(8).FillWeight = 140 : DataGridView1.Columns(9).FillWeight = 140 : DataGridView1.Columns(10).FillWeight = 140 : DataGridView1.Columns(11).Visible = False
  46. DataGridView1.Columns(12).Visible = False
  47. DataGridView1.Columns(1).ReadOnly = True : DataGridView1.Columns(2).ReadOnly = True : DataGridView1.Columns(9).ReadOnly = True : DataGridView1.Columns(10).ReadOnly = True
  48. DataGridView1.Columns(4).DefaultCellStyle.Format = "#,##0.00" : DataGridView1.Columns(5).DefaultCellStyle.Format = "#,##0.00" : DataGridView1.Columns(6).DefaultCellStyle.Format = "#,##0.00"
  49. DataGridView1.Columns(7).DefaultCellStyle.Format = "#,##0.00" : DataGridView1.Columns(8).DefaultCellStyle.Format = "#,##0.00"
  50. DataGridView1.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView1.Columns(4).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
  51. DataGridView1.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView1.Columns(5).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
  52. DataGridView1.Columns(6).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView1.Columns(6).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
  53. DataGridView1.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight : DataGridView1.Columns(7).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
  54. DataGridView1.Columns(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(9).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  55. DataGridView1.Columns(10).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(10).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  56. DataGridView1.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter : DataGridView1.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
  57. DataGridView1.EditMode = DataGridViewEditMode.EditOnEnter
  58. TextBox5.Text = "0.00" : TextBox2.Text = "0.00" : TextBox6.Text = "0.00" : TextBox7.Text = "0" : TextBox8.Text = "0.00"
  59. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  60. TextBox5.Text = Val(TextBox5.Text) + Val(DataGridView1.Rows(i).Cells("現金").Value) : TextBox2.Text = Val(TextBox2.Text) + Val(DataGridView1.Rows(i).Cells("支出").Value)
  61. TextBox7.Text = Val(TextBox7.Text) + DataGridView1.Rows(i).Cells("零用金").Value : TextBox8.Text = Val(TextBox8.Text) + DataGridView1.Rows(i).Cells("支票").Value
  62. Next i
  63. TextBox6.Text = Val(TextBox7.Text) + Val(TextBox5.Text) - Val(TextBox2.Text)
  64. If Val(TextBox6.Text) > 0 Then : TextBox6.ForeColor = Color.Blue : Else : TextBox6.ForeColor = Color.Red : End If
  65. TextBox5.Text = Format(Val(TextBox5.Text), "#,##0.00") : TextBox2.Text = Format(Val(TextBox2.Text), "#,##0.00") : TextBox6.Text = Format(Val(TextBox6.Text), "#,##0.00")
  66. TextBox7.Text = Format(Val(TextBox7.Text), "#,##0.00") : TextBox8.Text = Format(Val(TextBox8.Text), "#,##0.00")
  67. End Sub
  68. Private Sub ComboBox1下拉表單資料載入()
  69. conn.Close()
  70. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  71. SQL1 = "SELECT 會計科目, 編號 FROM 會計科目 WHERE (LEFT(編號, 7) LIKE N'" & ComboBox4.Text & "') AND (停用 = 0) AND (統制科目 = 0) ORDER BY 編號"
  72. cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader : ComboBox1.Items.Clear() : ComboBox6.Items.Clear()
  73. While (dr.Read()) : ComboBox1.Items.Add(dr("會計科目")) : ComboBox6.Items.Add(dr("編號")) : End While : conn.Close()
  74. If ComboBox1.Items.Count <> 0 Then : ComboBox1.SelectedIndex = 0 : End If
  75. End Sub
  76. Private Sub ComboBox2下拉表單資料載入()
  77. conn.Close()
  78. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  79. SQL1 = "SELECT 第一階, LEFT(編號, 4) AS 編號 FROM 會計科目 WHERE (停用 = 0) GROUP BY 第一階, LEFT(編號, 4) ORDER BY 編號"
  80. cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader : ComboBox5.Items.Clear() : ComboBox2.Items.Clear() : ComboBox5.Text = "" : ComboBox2.Text = ""
  81. While (dr.Read()) : ComboBox5.Items.Add(dr("第一階")) : ComboBox2.Items.Add(dr("編號")) : End While : conn.Close()
  82. End Sub
  83. Private Sub ComboBox3下拉表單資料載入()
  84. conn.Close()
  85. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  86. SQL1 = "SELECT LEFT(編號, 7) AS 編號, 第二階, 層級 FROM 會計科目 WHERE (LEFT(編號, 4) LIKE N'" & ComboBox2.Text & "') AND (層級 NOT LIKE '3') AND (停用 = 0)
  87. GROUP BY LEFT(編號, 7), 第二階, 層級 ORDER BY 編號"
  88. cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader : ComboBox3.Items.Clear() : ComboBox4.Items.Clear() : ComboBox3.Text = "" : ComboBox4.Text = ""
  89. While (dr.Read()) : ComboBox3.Items.Add(dr("第二階")) : ComboBox4.Items.Add(dr("編號")) : End While : conn.Close()
  90. End Sub
  91. Private Sub 匯率()
  92. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  93. SQL1 = "SELECT 中心匯率, 美金匯率 FROM 歷史匯率表
  94. WHERE (年 LIKE '" & Strings.Left(Format(DateTimePicker1.Value, "yyyyMMdd"), 4) & "%') AND (月 LIKE '" & Strings.Mid(Format(DateTimePicker1.Value, "yyyyMMdd"), 5, 2) & "%')"
  95. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  96. If dr.Read() Then
  97. 人民幣匯率_tb.Text = dr("中心匯率").ToString : 美金匯率_tb.Text = dr("美金匯率").ToString : conn.Close() : dr.Close()
  98. Else
  99. conn.Close() : dr.Close() : 匯率修改.Close() : 匯率修改.Show() : 匯率修改.BringToFront()
  100. End If
  101. End Sub
  102. Private Sub 營運成本支付申請_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  103. Me.MdiParent = GCM_ERP_SYS : Me.WindowState = 2 : Me.AutoScroll = True
  104. RadioButton1.Checked = True : DateTimePicker2.Visible = False : 複製單據開單ToolStripMenuItem.Enabled = False : ComboBox6.Visible = False
  105. DataGridView2.Visible = True : Set_清單1() : ComboBox2下拉表單資料載入()
  106. 匯率()
  107. End Sub
  108. Private Sub ComboBox5_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox5.TextChanged
  109. ComboBox2.SelectedIndex = ComboBox5.SelectedIndex : TextBox9.Text = "" : ComboBox3下拉表單資料載入() : ComboBox1下拉表單資料載入()
  110. End Sub
  111. Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.TextChanged
  112. ComboBox5.SelectedIndex = ComboBox2.SelectedIndex : ComboBox3下拉表單資料載入() : ComboBox1下拉表單資料載入()
  113. End Sub
  114. Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.TextChanged
  115. ComboBox4.SelectedIndex = ComboBox3.SelectedIndex : ComboBox1下拉表單資料載入()
  116. End Sub
  117. Private Sub ComboBox4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox4.TextChanged
  118. ComboBox3.SelectedIndex = ComboBox4.SelectedIndex : ComboBox1下拉表單資料載入()
  119. End Sub
  120. Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
  121. ComboBox6.SelectedIndex = ComboBox1.SelectedIndex
  122. End Sub
  123. Private Sub ComboBox6_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox6.SelectedIndexChanged
  124. ComboBox1.SelectedIndex = ComboBox6.SelectedIndex
  125. End Sub
  126. Private Sub TextBox9_TextChanged(sender As Object, e As EventArgs) Handles TextBox9.TextChanged
  127. conn.Close()
  128. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  129. SQL1 = "SELECT 會計科目, 編號 FROM 會計科目 WHERE (會計科目 LIKE N'%" & TextBox9.Text & "%') AND (停用 = 0) AND (統制科目 = 0) ORDER BY 編號"
  130. cmd.CommandText = SQL1 : cmd.Connection = conn : dr = cmd.ExecuteReader : ComboBox1.Items.Clear() : ComboBox6.Items.Clear()
  131. While (dr.Read()) : ComboBox1.Items.Add(dr("會計科目")) : ComboBox6.Items.Add(dr("編號")) : End While : conn.Close()
  132. If ComboBox1.Items.Count <> 0 Then : ComboBox1.SelectedIndex = 0 : End If
  133. End Sub
  134. Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  135. If Label62.Visible = True Then : Label62.Visible = False : Else : Label62.Visible = True : End If
  136. End Sub
  137. Private Sub DataGridView1_CellContentCl(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
  138. TextBox5.Text = "0" : TextBox2.Text = "0" : TextBox6.Text = "0" : TextBox7.Text = "0" : TextBox8.Text = "0"
  139. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  140. TextBox5.Text = Val(TextBox5.Text) + DataGridView1.Rows(i).Cells("現金").Value : TextBox2.Text = Val(TextBox2.Text) + DataGridView1.Rows(i).Cells("支出").Value
  141. TextBox7.Text = Val(TextBox7.Text) + DataGridView1.Rows(i).Cells("零用金").Value : TextBox8.Text = Val(TextBox8.Text) + DataGridView1.Rows(i).Cells("支票").Value
  142. Next i
  143. TextBox6.Text = Val(TextBox7.Text) + Val(TextBox5.Text) - Val(TextBox2.Text)
  144. If Val(TextBox6.Text) > 0 Then : TextBox6.ForeColor = Color.Blue : Else : TextBox6.ForeColor = Color.Red : End If
  145. TextBox5.Text = Format(Val(TextBox5.Text), "#,##0") : TextBox2.Text = Format(Val(TextBox2.Text), "#,##0") : TextBox6.Text = Format(Val(TextBox6.Text), "#,##0")
  146. TextBox7.Text = Format(Val(TextBox7.Text), "#,##0") : TextBox8.Text = Format(Val(TextBox8.Text), "#,##0")
  147. Dim EU As String
  148. EU = DataGridView1("票期", e.RowIndex).Value.ToString
  149. If EU = "" Then
  150. Else
  151. DateTimePicker2.Text = EU
  152. DataGridView1.Rows(e.RowIndex).Cells("票期").Value = Format(DateTimePicker2.Value, "yyyy/MM/dd")
  153. End If
  154. End Sub
  155. Private Sub DataGridView2_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.CellClick
  156. If e.RowIndex = -1 Then : Else
  157. TextBox1.Text = DataGridView2(0, e.RowIndex).Value.ToString : DateTimePicker1.Value = DataGridView2(1, e.RowIndex).Value.ToString : Set_費用清單()
  158. TextBox3.Text = DataGridView2(3, e.RowIndex).Value.ToString
  159. End If
  160. End Sub
  161. Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  162. If e.RowIndex = -1 Then : Else
  163. TextBox4.Text = DataGridView1(1, e.RowIndex).Value.ToString
  164. End If
  165. End Sub
  166. Private Sub Set_切換格式()
  167. DataGridView1.DataSource = Nothing : ds.Clear() : TextBox1.Text = "" : TextBox3.Text = "" : TextBox4.Text = "" : TextBox5.Text = "" : TextBox2.Text = "" : TextBox6.Text = ""
  168. TextBox7.Text = "" : TextBox8.Text = "" : ComboBox1下拉表單資料載入() : Set_清單1()
  169. End Sub
  170. Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.Click
  171. RadioButton1.Checked = True : RadioButton2.Checked = False : RadioButton3.Checked = False : 申請完成ToolStripMenuItem.Enabled = True : 複製單據開單ToolStripMenuItem.Enabled = False
  172. 開立零用金支付單ToolStripMenuItem.Enabled = True : Button2.Enabled = True : 新增一筆資料ToolStripMenuItem.Enabled = True
  173. 刪除支付單中選中的資料ToolStripMenuItem.Enabled = True : 刪除選中的零用金支付單ToolStripMenuItem.Enabled = True : Set_切換格式()
  174. End Sub
  175. Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.Click
  176. RadioButton1.Checked = False : RadioButton2.Checked = True : RadioButton3.Checked = False : 申請完成ToolStripMenuItem.Enabled = False : 複製單據開單ToolStripMenuItem.Enabled = False
  177. 開立零用金支付單ToolStripMenuItem.Enabled = False : Button2.Enabled = False : 新增一筆資料ToolStripMenuItem.Enabled = False
  178. 刪除支付單中選中的資料ToolStripMenuItem.Enabled = False : 刪除選中的零用金支付單ToolStripMenuItem.Enabled = False : Set_切換格式()
  179. End Sub
  180. Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.Click
  181. If CC(28) = False Then
  182. RadioButton1.Checked = False : RadioButton2.Checked = False : RadioButton3.Checked = True : 申請完成ToolStripMenuItem.Enabled = False : 複製單據開單ToolStripMenuItem.Enabled = True
  183. 開立零用金支付單ToolStripMenuItem.Enabled = False : Button2.Enabled = False : 新增一筆資料ToolStripMenuItem.Enabled = False
  184. 刪除支付單中選中的資料ToolStripMenuItem.Enabled = False : 刪除選中的零用金支付單ToolStripMenuItem.Enabled = False : Set_切換格式()
  185. Else
  186. RadioButton1.Checked = False : RadioButton2.Checked = False : RadioButton3.Checked = True : 申請完成ToolStripMenuItem.Enabled = True : 複製單據開單ToolStripMenuItem.Enabled = True
  187. 開立零用金支付單ToolStripMenuItem.Enabled = True : Button2.Enabled = True : 新增一筆資料ToolStripMenuItem.Enabled = True
  188. 刪除支付單中選中的資料ToolStripMenuItem.Enabled = True : 刪除選中的零用金支付單ToolStripMenuItem.Enabled = True : Set_切換格式()
  189. End If
  190. End Sub
  191. Private Sub 存檔()
  192. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  193. 資料數 = DataGridView1.Rows.Count : MyMoule.進度條()
  194. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  195. SQL1 = "UPDATE 公帳流水帳 SET 明細 = N'" & DataGridView1.Rows(i).Cells("用途").Value & "', 支出 = N'" & DataGridView1.Rows(i).Cells("支出").Value &
  196. "', 備註 = N'" & DataGridView1.Rows(i).Cells("票期").Value & "' , 類別 = N'" & DataGridView1.Rows(i).Cells("類別").Value &
  197. "', 收入 = N'" & DataGridView1.Rows(i).Cells("現金").Value & "', 零用金 = N'" & DataGridView1.Rows(i).Cells("零用金").Value &
  198. "', 支票數 = N'" & DataGridView1.Rows(i).Cells("支票").Value & "', 匯率 = N'" & DataGridView1.Rows(i).Cells("匯率").Value & "'
  199. WHERE (支付單號 LIKE '" & TextBox1.Text & "' AND 項次 LIKE '" & DataGridView1.Rows(i).Cells("項次").Value & "')"
  200. cmd.CommandText = SQL1 : cmd.ExecuteNonQuery() : conn.Close()
  201. Next
  202. ProgressBar1.Value = 0 : 最終數 = 0
  203. End Sub
  204. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  205. Timer1.Enabled = False : Label62.Visible = False
  206. 開立零用金支付單ToolStripMenuItem.Enabled = True : RadioButton1.Enabled = True : RadioButton2.Enabled = True : DataGridView2.Enabled = True : RadioButton3.Enabled = True
  207. 存檔() : Set_清單1()
  208. MsgBox("申請完成,請通知主管審核。")
  209. End Sub
  210. Private Sub Set_日期格式轉換()
  211. If CheckBox1.Checked = False Then
  212. DTP = Format(Today(), "yyyy/MM/dd") : DTP1 = Format(Today(), "yyyyMMdd")
  213. Else
  214. DTP1 = Format(DateTimePicker1.Value, "yyyyMMdd") : DTP = Format(DateTimePicker1.Value, "yyyy/MM/dd")
  215. End If
  216. End Sub
  217. Private Sub Set_流水號()
  218. conn.Close() : dr.Close()
  219. Dim NUM1 As Integer
  220. For NUM1 = 0 To 99
  221. Dim d As String : Dim f As String : Dim g As Integer = 1
  222. If Month(Now) < 10 Then : d = "0" & CStr(Month(Now))
  223. Else : d = CStr(Month(Now))
  224. End If
  225. If Now.Day() < 10 Then : f = "0" & CStr(Now.Day())
  226. Else : f = CStr(Now.Day())
  227. End If
  228. If NUM1 < 10 Then : 新流水1 = "B" & Microsoft.VisualBasic.Right(CStr(Year(Now)), 2) & d & f & "0" & NUM1
  229. Else : 新流水1 = "B" & Microsoft.VisualBasic.Right(CStr(Year(Now)), 2) & d & f & NUM1
  230. End If
  231. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  232. SQL1 = "SELECT 流水號 FROM 公帳流水帳 WHERE (流水號 ='" & 新流水1 & "')"
  233. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  234. If dr.Read() Then : conn.Close() : Else : conn.Close() : NUM1 = 99 : End If
  235. Next
  236. End Sub
  237. Private Sub 開立零用金支付單()
  238. Dim NUM1 As Integer : Timer1.Enabled = True
  239. Set_日期格式轉換()
  240. For i As Integer = 1 To 999
  241. NUM1 = 0 + i
  242. If NUM1 < 10 Then : TextBox1.Text = "OE-" & DTP1 & "-00" & NUM1
  243. ElseIf NUM1 > 9 And NUM1 < 100 Then : TextBox1.Text = "OE-" & DTP1 & "-0" & NUM1
  244. ElseIf NUM1 > 99 Then : TextBox1.Text = "OE-" & DTP1 & "-" & NUM1
  245. End If
  246. conn.Close()
  247. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  248. SQL1 = "SELECT TOP (1) 支付單號 FROM 公帳控制表 WHERE ( 支付單號 LIKE '" & TextBox1.Text & "')"
  249. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  250. If dr.Read() Then : Else : i = 999 : conn.Close() : End If : conn.Close()
  251. Next
  252. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  253. SQL1 = "INSERT INTO 公帳控制表 (支付單號, 申請人, 申請日期, 審核人, 審核日期, 會計, 作帳日期, 出納, 出納日期, 備註, 公司編號) " &
  254. "VALUES (N'" & TextBox1.Text & "', N'" & gUserName & "', N'" & DTP & "', N'', N'', N'', N'', N'', N'', N'', N'工巧明')"
  255. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
  256. TextBox3.Text = gUserName
  257. End Sub
  258. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  259. 開立零用金支付單() : 開立零用金支付單ToolStripMenuItem.Enabled = False : RadioButton1.Enabled = False : RadioButton2.Enabled = False : RadioButton3.Enabled = False
  260. DataGridView2.Enabled = False : RadioButton1.Checked = True : RadioButton2.Checked = False : RadioButton3.Checked = False : 申請完成ToolStripMenuItem.Enabled = True
  261. 複製單據開單ToolStripMenuItem.Enabled = False : 開立零用金支付單ToolStripMenuItem.Enabled = True : Button2.Enabled = True : 新增一筆資料ToolStripMenuItem.Enabled = True
  262. 刪除支付單中選中的資料ToolStripMenuItem.Enabled = True : 刪除選中的零用金支付單ToolStripMenuItem.Enabled = True
  263. Set_清單1()
  264. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  265. Set_流水號()
  266. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  267. SQL1 = "INSERT INTO 公帳流水帳 (流水號, 銀行, 日期, 類別, 收入, 支出, 明細, 人員, 支付單號, 項次, 會計, 出納, 現金, 備用金, 公帳, 支票,
  268. 出納日期, 零用金, 支票數, 匯率, 備註)
  269. VALUES (N'" & 新流水1 & "', N'" & DataGridView1.Rows(i).Cells("幣別").Value & "'', N'" & DTP & "', N'" & DataGridView1.Rows(i).Cells("類別").Value &
  270. "', N'" & DataGridView1.Rows(i).Cells("現金").Value & "', N'" & DataGridView1.Rows(i).Cells("支出").Value & "', N'" & DataGridView1.Rows(i).Cells("用途").Value &
  271. "', N'', N'" & gUserName & "', N'" & TextBox1.Text & "', N'" & DataGridView1.Rows(i).Cells("項次").Value & "', N'1', N'0', N'0', N'0', N'0', N'0', N'" & DTP &
  272. "', N'" & DataGridView1.Rows(i).Cells("零用金").Value & "', N'" & DataGridView1.Rows(i).Cells("支票").Value & "', N'" & DataGridView1.Rows(i).Cells("匯率").Value &
  273. "', N'" & DataGridView1.Rows(i).Cells("票期").Value & "')"
  274. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
  275. Next
  276. Set_費用清單() : MsgBox("複製單據開立完成。")
  277. End Sub
  278. Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged
  279. 匯率()
  280. End Sub
  281. '----------------------滑鼠右鍵--------------------------------------------------------------------------------------------------------------------------------------------------------------------
  282. Private Sub 重新讀取ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 重新讀取ToolStripMenuItem.Click
  283. Set_清單1()
  284. End Sub
  285. Private Sub 開立零用金支付單ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 開立零用金支付單ToolStripMenuItem.Click
  286. 開立零用金支付單() : 開立零用金支付單ToolStripMenuItem.Enabled = False : RadioButton1.Enabled = False : RadioButton2.Enabled = False : RadioButton3.Enabled = False : DataGridView2.Enabled = False
  287. DataGridView1.DataSource = Nothing : ds.Clear() : conn.Close()
  288. Set_清單1()
  289. End Sub
  290. Private Sub 刪除選中的零用金支付單ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 刪除選中的零用金支付單ToolStripMenuItem.Click
  291. Dim aa As MsgBoxResult
  292. aa = MsgBox("確定要刪除該筆資料?", MsgBoxStyle.OkCancel)
  293. If aa = MsgBoxResult.Ok Then
  294. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  295. SQL1 = "DELETE FROM 公帳控制表 WHERE (支付單號 LIKE '" & TextBox1.Text & "')"
  296. cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close()
  297. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  298. SQL1 = "DELETE FROM 公帳流水帳 WHERE (支付單號 LIKE '" & TextBox1.Text & "')"
  299. cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close()
  300. TextBox1.Text = "" : TextBox3.Text = "" : TextBox4.Text = ""
  301. DataGridView1.DataSource = Nothing : ds.Clear()
  302. Set_清單1()
  303. End If
  304. End Sub
  305. Private Sub 刪除支付單中選中的資料ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 刪除支付單中選中的資料ToolStripMenuItem.Click
  306. If TextBox4.Text = "" Then
  307. MsgBox("未選擇需要刪除的資料。")
  308. Else
  309. 存檔()
  310. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  311. SQL1 = "DELETE FROM 公帳流水帳 WHERE (支付單號 LIKE '" & TextBox1.Text & "' AND 項次 LIKE '" & TextBox4.Text & "')"
  312. cmd.CommandText = SQL1 : cmd.Connection = conn : cmd.ExecuteNonQuery() : conn.Close()
  313. Set_費用清單()
  314. Dim NUM1 As Integer = 0
  315. For i As Integer = 0 To DataGridView1.Rows.Count - 1
  316. NUM1 += 1 : If NUM1 < 10 Then : 新項次 = "0" & NUM1 : ElseIf NUM1 > 9 And NUM1 < 100 Then : 新項次 = NUM1 : End If
  317. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  318. SQL1 = "UPDATE 公帳流水帳 SET 項次 = N'" & 新項次 & "' WHERE (支付單號 LIKE '" & TextBox1.Text & "' AND 項次 LIKE '" & DataGridView1.Rows(i).Cells("項次").Value & "')"
  319. cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
  320. conn.Close()
  321. Next
  322. Set_費用清單()
  323. End If
  324. End Sub
  325. Private Sub 新增一筆資料ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 新增一筆資料ToolStripMenuItem.Click
  326. If ComboBox6.Text = "" Or 幣別_cb.Text = "" Then
  327. MsgBox("沒有選擇會計科目或幣別。")
  328. Else
  329. If TextBox1.Text = "" Then
  330. 開立零用金支付單()
  331. End If
  332. Set_日期格式轉換() : Set_流水號()
  333. 存檔()
  334. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  335. SQL1 = "SELECT TOP(1) 項次 FROM 公帳流水帳 WHERE 支付單號 LIKE '" & TextBox1.Text & "' ORDER BY 項次 DESC"
  336. cmd.Connection = conn : cmd.CommandText = SQL1 : dr = cmd.ExecuteReader
  337. If dr.Read() Then : 新項次 = dr("項次") : Else : 新項次 = "00" : End If : conn.Close()
  338. NUM1 = Double.Parse(新項次) + 1
  339. If NUM1 < 10 Then : 新項次 = "0" & NUM1
  340. ElseIf NUM1 > 9 And NUM1 < 100 Then : 新項次 = NUM1
  341. End If
  342. If conn.State = ConnectionState.Closed Then : conn.ConnectionString = ConString : conn.Open() : End If
  343. If 幣別_cb.Text = "台幣現金" Then
  344. 匯率1 = 1
  345. ElseIf 幣別_cb.Text = "人民幣現金" Then
  346. 匯率1 = 人民幣匯率_tb.Text
  347. ElseIf 幣別_cb.Text = "美金" Then
  348. 匯率1 = 美金匯率_tb.Text
  349. End If
  350. SQL1 = "INSERT INTO 公帳流水帳 (流水號, 銀行, 日期, 類別, 收入, 支出, 明細, 人員, 支付單號, 項次, 會計, 出納, 現金, 備用金, 公帳, 支票,
  351. 出納日期, 零用金, 支票數, 匯率, 備註) " &
  352. "VALUES (N'" & 新流水1 & "', N'" & 幣別_cb.Text & "', N'" & DTP & "', N'" & ComboBox6.Text & "', N'0', N'0', N'', N'" & gUserName & "', N'" & TextBox1.Text & "', N'" & 新項次 &
  353. "', N'0', N'0', N'0', N'0', N'0', N'0', N'" & DTP & "', N'0', N'0', N'" & 匯率1 & "', N'')"
  354. cmd.Connection = conn : cmd.CommandText = SQL1 : cmd.ExecuteNonQuery()
  355. Set_費用清單()
  356. End If
  357. End Sub
  358. Private Sub 申請完成ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 申請完成ToolStripMenuItem.Click
  359. Me.Button2.PerformClick()
  360. End Sub
  361. Private Sub 複製單據開單ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles 複製單據開單ToolStripMenuItem.Click
  362. Me.Button1.PerformClick()
  363. End Sub
  364. End Class