ชุมชนคนรักภาษาเบสิค - Visual Basic Community

 ลืมรหัสผ่าน
 ลงทะเบียน
ค้นหา
ดู: 11316|ตอบกลับ: 7

แจกฟรีทั้งโค้ด และโปรแกรมการพิมพ์ใบแจ้งค่าใช้จ่าย สำหรับหอพัก ห้องเช่า อพาร์ทเมนท์ แบบกระดาษครึ่ง A4 (VB.NET เวอร์ชั่น II)

[คัดลอกลิงก์]

308

กระทู้

498

โพสต์

5971

เครดิต

ผู้ดูแลระบบ

ทองก้อน ทับทิมกรอบ

Rank: 9Rank: 9Rank: 9

เครดิต
5971



มาภาคต่อเป็นเวอร์ชั่น II กันครับ ... เวอร์ชั่นใหม่นี้จะปรับเพิ่มให้มีจำนวนหน่วย (Unit) เข้ามาใหม่ จากนั้นนำไปคูณเข้ากับราคาต่อหน่วย เป็นการแจกแจงรายละเอียดต่อผู้เช่าห้องได้ดียิ่งขึ้น ...
สำหรับท่านที่ต้องการใช้งานโปรแกรมเท่านั้น สามารถดาวน์โหลดได้แบบไม่ต้องติดตั้งโปรแกรม (คลิ๊กดาวน์โหลดที่นี่) เมื่อดาวน์โหลดไปแล้วให้ทำการแตกไฟล์ออกมา แล้วสั่งรันโปรแกรมที่มีชื่อว่า RoomPayment.exe (รูปไอคอนเป็นที่เก็บแฟ้มสีน้ำเงิน) หรือหากต้องการดูเวอร์ชั่นแรก (คลิ๊กดาวน์โหลดที่นี่)

ปัญหาที่อาจจะเกิดขึ้น กรณีที่ไม่ได้ติดตั้ง Access DataBase Engine รุ่น 32 บิต ...

คลิ๊กดาวน์โหลดไฟล์ตัวนี้ฟรี เพื่อติดตั้งแก้ไขให้โปรแกรมสามารถทำงานได้ ...

สำหรับนักพัฒนาโปรแกรมสายพันธุ์ VB6 สามารถดูรายละเอียดของโค้ดได้จากที่นี่ แจกฟรีโค้ดการพิมพ์ใบแจ้งค่าใช้จ่าย แบบกระดาษครึ่ง A4 ด้วย FarPoint Spread และ ActiveReports 2.0 ...

สำหรับนักพัฒนาโปรแกรมสายพันธุ์ VB.NET สามารถดูรายละเอียดของโค้ดในเวอร์ชั่นแรกได้จากที่นี่ แจกฟรีโค้ดการพิมพ์ใบแจ้งค่าใช้จ่าย สำหรับหอพัก ห้องเช่า อพาร์ทเมนท์ แบบกระดาษครึ่ง A4 (ActiveReports.NET) ...

ในเวอร์ชั่นใหม่นี้ ใช้วิธีการจับคู่หลักในการพิมพ์ ดังนั้นหากมีการเพิ่มเติมใดๆก็ควรทำตามดังภาพเอาไว้น่ะครับ โดยในไฟล์โค้ดโปรแกรมฉบับเต็ม แอดมินได้ทำตัวอย่างเอาไว้ให้ด้วย ช่วงนี้แอดมินมีงานเต็มมือ จึงไม่พร้อมที่จะมาอธิบายรายละเอียดให้ได้ ก็คงต้องศึกษาเอาเองจากโค้ดที่ได้ไปนั่นแหละข่ะรับ หรือ กลับไปอ่านจากเวอร์ชั่นแรกก่อน แต่ถ้าหากติดขัดปัญหาก็สามารถถามไถ่กันเข้ามาได้ครับ ...



มาดูโค้ดกันเถอะ ... ในส่วนของฟอร์มหลัก  
  1. ' / ----------------------------------------------------------------
  2. ' / Developer : Mr.Surapon Yodsanga (Thongkorn Tubtimkrob)
  3. ' / eMail : thongkorn@hotmail.com
  4. ' / URL: http://www.g2gnet.com (Khon Kaen - Thailand)
  5. ' / Facebook: https://www.facebook.com/g2gnet (For Thailand)
  6. ' / Facebook: https://www.facebook.com/commonindy (Worldwide)
  7. ' / Purpose: Print bill payment for rented room.
  8. ' / Microsoft Visual Basic .NET (2010) & MS Excel 2003+
  9. ' /
  10. ' / This is open source code under @CopyLeft by Thongkorn Tubtimkrob.
  11. ' / You can modify and/or distribute without to inform the developer.
  12. ' / ----------------------------------------------------------------
  13. Imports System.Data.OleDb

  14. Public Class frmMainBill
  15.     Dim ColCount As Integer
  16.     Dim DT As DataTable
  17.     Dim DR As OleDbDataReader

  18.     Private Sub btnBrowse_Click(sender As System.Object, e As System.EventArgs) Handles btnBrowse.Click
  19.         '/ ประกาศใช้งาน Open File Dialog ในแบบ Run Time
  20.         Dim dlgOpenFile As OpenFileDialog = New OpenFileDialog()

  21.         ' / ตั้งค่าการใช้งาน Open File Dialog
  22.         With dlgOpenFile
  23.             .InitialDirectory = MyPath(Application.StartupPath)
  24.             .Title = "เลือกไฟล์ MS Excel"
  25.             .Filter = "MS Excel Files (*.xlsx;*.xls)|*.xlsx;*xls"
  26.             .FilterIndex = 1
  27.             .RestoreDirectory = True
  28.         End With
  29.         '/ หากเลือกปุ่ม OK หลังจากการ Browse ...
  30.         If dlgOpenFile.ShowDialog() = DialogResult.OK Then
  31.             txtFileName.Text = dlgOpenFile.FileName
  32.             Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
  33.                 dlgOpenFile.FileName & "; Extended Properties=""Excel 12.0 Xml; HDR=YES"";"
  34.             Dim Conn As New OleDbConnection(strConn)
  35.             Conn.Open()
  36.             '/ มอง WorkSheet ให้เป็นตารางข้อมูล (Table)
  37.             Dim dtSheets As DataTable = Conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
  38.             Dim drSheet As DataRow

  39.             cmbSheetName.Items.Clear()
  40.             '/ นำรายชื่อ WorkSheet ทั้งหมด มาเก็บไว้ที่ ComboBox เพื่อรอให้ User เลือกนำไปใช้งานเอง
  41.             For Each drSheet In dtSheets.Rows
  42.                 cmbSheetName.Items.Add(drSheet("TABLE_NAME").ToString())
  43.             Next
  44.             Conn.Close()
  45.             '//
  46.             dgvData.Columns.Clear()
  47.         End If

  48.     End Sub

  49.     Private Sub cmbSheetName_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cmbSheetName.SelectedIndexChanged
  50.         Dim Conn As OleDbConnection
  51.         Dim Cmd As OleDbCommand
  52.         Dim DAP As OleDbDataAdapter
  53.         Dim DS As DataSet

  54.         '// Clear all columns.
  55.         dgvData.Columns.Clear()

  56.         Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
  57.             txtFileName.Text & "; Extended Properties=""Excel 12.0 Xml; HDR=YES"";"
  58.         Try
  59.             Conn = New OleDbConnection
  60.             Conn.ConnectionString = strConn
  61.             Cmd = New OleDbCommand
  62.             Dim Sql As String = "Select * FROM [" & cmbSheetName.Text & "]"
  63.             If Conn.State = ConnectionState.Closed Then Conn.Open()
  64.             Cmd.Connection = Conn
  65.             Cmd.CommandText = Sql
  66.             DR = Cmd.ExecuteReader()
  67.             DT = New DataTable
  68.             Dim iCol As Integer
  69.             '/ เริ่มอ่านค่าหลักจาก Excel เข้ามา ตั้งแต่ #ชื่อผู้เช่า (หลัก 0)
  70.             For iCol = 0 To DR.FieldCount - 1
  71.                 DT.Columns.Add(DR.GetName(iCol))
  72.                 '// ตั้งแต่หลักที่ 3 คอลัมน์ C (ค่าห้อง) ขึ้นไป จะมีแต่ตัวเลข จึงต้องกำหนด Data Type เป็น Double
  73.                 If iCol >= 3 Then
  74.                     DT.Columns(iCol).DataType = GetType(Double)
  75.                 End If
  76.             Next
  77.             '// อ่านค่าจำนวนแถวเข้ามา
  78.             If DR.HasRows Then
  79.                 While DR.Read
  80.                     Dim DRow As DataRow = DT.NewRow
  81.                     For i = 0 To DR.FieldCount - 1
  82.                         DRow(i) = DR.Item(i).ToString
  83.                     Next
  84.                     '// Next row
  85.                     DT.Rows.Add(DRow)
  86.                 End While
  87.             End If
  88.             '// ผูก DataTable เข้าสู่ตารางกริด
  89.             dgvData.DataSource = DT

  90.             '// เพิ่มปุ่มคำสั่งเข้ามาไว้ท้ายสุดในตารางกริดสำหรับการสั่ง Preview
  91.             Dim btn As New DataGridViewButtonColumn()
  92.             dgvData.Columns.Add(btn)
  93.             With btn
  94.                 .HeaderText = ""
  95.                 .Text = "Preview"
  96.                 .Name = "btnPreview"
  97.                 .UseColumnTextForButtonValue = True
  98.             End With
  99.             ColCount = DT.Columns.Count
  100.             '// จัดระเบียบตารางกริด
  101.             Call InitGrid()

  102.         Catch ex As Exception
  103.             MessageBox.Show(ex.Message)
  104.         Finally
  105.             Conn = Nothing
  106.             Cmd = Nothing
  107.             DAP = Nothing
  108.             DS = Nothing
  109.         End Try
  110.     End Sub

  111.     ' / --------------------------------------------------------------------------------
  112.     '// Initialize DataGridView @Run Time
  113.     Private Sub InitGrid()
  114.         '// Setup each column
  115.         With dgvData
  116.             '// Column 2 to 9
  117.             For i As Byte = 2 To ColCount - 1
  118.                 ' Header Alignment
  119.                 .Columns(i).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
  120.                 ' Cell Alignment
  121.                 .Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
  122.                 '// Value type
  123.                 .Columns(i).ValueType = GetType(Double)
  124.                 '// Format Number
  125.                 .Columns(i).DefaultCellStyle.Format = "N2"
  126.                 '// กรณีต้องการปิดการแสดงผลจำนวนหน่วย (ตั้งแต่หลัก F ค่าไฟฟ้าต่อหน่วย)
  127.                 'If i >= 5 Then
  128.                 '// ปิดการแสดงผลหลัก 5, 7 และหลัก 9 (การหารเอาเศษเลขจำนวนเต็มด้วย 2 หากได้คำตอบเป็น 1 คือเลขคี่)
  129.                 'If (i Mod 2) = 1 Then .Columns(i).Visible = False
  130.                 'End If
  131.             Next
  132.         End With
  133.         With dgvData
  134.             .RowHeadersVisible = False
  135.             .AllowUserToAddRows = False
  136.             .AllowUserToDeleteRows = False
  137.             .AllowUserToResizeRows = False
  138.             .MultiSelect = False
  139.             .SelectionMode = DataGridViewSelectionMode.FullRowSelect
  140.             .ReadOnly = True
  141.             .Font = New Font("Tahoma", 9)
  142.             ' Autosize Column
  143.             .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
  144.             .AutoResizeColumns()
  145.             '// Even-Odd Color
  146.             .AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue
  147.             ' Adjust Header Styles
  148.             With .ColumnHeadersDefaultCellStyle
  149.                 .BackColor = Color.Navy
  150.                 .ForeColor = Color.Black
  151.                 '.Font = New Font("Tahoma", 9, FontStyle.Bold)
  152.                 .WrapMode = DataGridViewTriState.False
  153.             End With
  154.         End With
  155.     End Sub

  156.     Private Sub txtFileName_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtFileName.KeyPress
  157.         '// Protect any key press in TextBox.
  158.         e.Handled = True
  159.     End Sub

  160.     Private Sub dgvData_CellClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvData.CellClick
  161.         Select Case e.ColumnIndex
  162.             Case ColCount
  163.                 'MsgBox(("Row : " + e.RowIndex.ToString & "  Col : ") + e.ColumnIndex.ToString)
  164.                 Dim colName As String = dgvData.Columns(e.ColumnIndex).Name
  165.                 If colName = "btnPreview" Then Call PreviewData()
  166.         End Select
  167.     End Sub

  168.     Private Sub dgvData_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles dgvData.KeyDown
  169.         If e.KeyCode = Keys.Enter Then
  170.             Call dgvData_DoubleClick(sender, e)
  171.             e.SuppressKeyPress = True
  172.         End If
  173.     End Sub

  174.     Private Sub dgvData_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvData.CellContentClick
  175.         '
  176.     End Sub

  177.     Private Sub dgvData_DoubleClick(sender As Object, e As System.EventArgs) Handles dgvData.DoubleClick
  178.         If dgvData.Rows.Count <= 0 Then Exit Sub
  179.         Call PreviewData()
  180.     End Sub

  181.     ' / ----------------------------------------------------------------
  182.     ' / Preview
  183.     Private Sub PreviewData()
  184.         Try
  185.             '/ Instance name ARDesigner มันจะชี้ไปที่ไฟล์ arRentRoomBill.vb
  186.             Dim rpt As New arRentRoomBill
  187.             '/ โหลดรายงาน document (arRentRoomBill) เข้าสู่ ActiveReports Viewer
  188.             '// Zoom 90%
  189.             Me.Viewer1.ReportViewer.Zoom = 0.9
  190.             Me.Viewer1.Document = rpt.Document
  191.             '/ Run Report
  192.             rpt.Run()
  193.         Catch ex As Exception
  194.             MessageBox.Show(ex.Message)
  195.         End Try
  196.     End Sub

  197.     Private Sub ToolStripStatusLabel2_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripStatusLabel2.Click
  198.         Process.Start("https://www.facebook.com/g2gnet")
  199.     End Sub

  200.     Private Sub itemBtnExit_Click(sender As System.Object, e As System.EventArgs) Handles itemBtnExit.Click
  201.         Me.Close()
  202.     End Sub

  203.     Private Sub itemBtnSetup_Click(sender As System.Object, e As System.EventArgs) Handles itemBtnSetup.Click
  204.         frmSetting.ShowDialog()
  205.     End Sub

  206.     Private Sub itemBtnAbout_Click(sender As System.Object, e As System.EventArgs) Handles itemBtnAbout.Click
  207.         frmAboutMe.ShowDialog()
  208.     End Sub

  209.     Private Sub ToolStripStatusLabel3_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripStatusLabel3.Click
  210.         Process.Start("http://www.g2gnet.com")
  211.     End Sub

  212.     Private Sub frmMainBill_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
  213.         Me.Dispose()
  214.         Application.Exit()
  215.     End Sub

  216.     Private Sub frmMainBill_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  217.         Me.ToolStrip1.Cursor = Cursors.Hand
  218.     End Sub

  219. End Class
คัดลอกไปที่คลิปบอร์ด

โค้ดในส่วนของการตั้งค่า (Setting) ด้วยการใช้ Initial File (INI) ...
  1. ' / --------------------------------------------------------------------------------
  2. ' / Developer : Mr.Surapon Yodsanga (Thongkorn Tubtimkrob)
  3. ' / eMail : thongkorn@hotmail.com
  4. ' / URL: http://www.g2gnet.com (Khon Kaen - Thailand)
  5. ' / Facebook: https://www.facebook.com/g2gnet (For Thailand)
  6. ' / Facebook: https://www.facebook.com/commonindy (Worldwide)
  7. ' / Purpose: Setting up information.
  8. ' / Microsoft Visual Basic .NET (2010) & MS Excel 2003+
  9. ' /
  10. ' / This is open source code under @CopyLeft by Thongkorn Tubtimkrob.
  11. ' / You can modify and/or distribute without to inform the developer.
  12. ' / --------------------------------------------------------------------------------
  13. Public Class frmSetting
  14.     Dim strFileINI As String

  15.     Private Sub frmSetting_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
  16.         Select Case e.KeyCode
  17.             Case Keys.F8
  18.                 Call btnSave_Click(sender, e)
  19.             Case Keys.Escape
  20.                 Me.Close()
  21.         End Select
  22.     End Sub

  23.     ' / --------------------------------------------------------------------------------
  24.     Private Sub frmSetting_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  25.         strFileINI = MyPath(Application.StartupPath) & "Config.ini"
  26.         '// เช็คว่ามีไฟล์ Config.ini อยู่หรือไม่???
  27.         If My.Computer.FileSystem.FileExists(strFileINI) Then
  28.             txtOwner.Text = ReadIni(strFileINI, "Config", "Owner", "")
  29.             txtAddress.Text = ReadIni(strFileINI, "Config", "Address", "")
  30.             txtHeaderBill.Text = ReadIni(strFileINI, "Config", "HeaderBill", "")
  31.             txtElectricRate.Text = ReadIni(strFileINI, "Config", "ElectricRate", "")
  32.             txtWaterRate.Text = ReadIni(strFileINI, "Config", "WaterRate", "")
  33.             txtRemark1.Text = ReadIni(strFileINI, "Config", "Remark1", "")
  34.             txtRemark2.Text = ReadIni(strFileINI, "Config", "Remark2", "")
  35.             '// กรณีไม่เจอ ให้เริ่มต้นค่าใหม่
  36.         Else
  37.             txtOwner.Text = "ทองก้อน อพาร์ทเมนท์ แอนด์ โฮมเพลย์สเตชั่น"
  38.             txtAddress.Text = "123/456 ถ.กลางเมือง ต.เมืองเก่า อ.เมือง จ.ขอนแก่น โทร.043-XXX-XXX"
  39.             txtHeaderBill.Text = "- ใบแจ้งค่าใช้จ่าย -"
  40.             txtElectricRate.Text = "10"
  41.             txtWaterRate.Text = "5"
  42.             txtRemark1.Text = "[1] กรุณาชำระเงินภายในวันที่ 5 ของทุกเดือน"
  43.             txtRemark2.Text = "[2] ชำระค่าปรับล่าช้าวันละ 50 บาท"
  44.         End If
  45.     End Sub

  46.     Private Sub txtElectricRate_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtElectricRate.KeyPress
  47.         e.Handled = CheckDigitOnly(Asc(e.KeyChar))
  48.     End Sub

  49.     ' / --------------------------------------------------------------------------------
  50.     '// บันทึกไฟล์ INI
  51.     Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
  52.         WriteIni(strFileINI, "Config", "Owner", txtOwner.Text)
  53.         WriteIni(strFileINI, "Config", "Address", txtAddress.Text)
  54.         WriteIni(strFileINI, "Config", "HeaderBill", txtHeaderBill.Text)
  55.         If txtElectricRate.Text.Length <> 0 Then
  56.             WriteIni(strFileINI, "Config", "ElectricRate", txtElectricRate.Text)
  57.         Else
  58.             WriteIni(strFileINI, "Config", "ElectricRate", "0")
  59.         End If
  60.         If txtWaterRate.Text.Length <> 0 Then
  61.             WriteIni(strFileINI, "Config", "WaterRate", txtWaterRate.Text)
  62.         Else
  63.             WriteIni(strFileINI, "Config", "WaterRate", "0")
  64.         End If
  65.         WriteIni(strFileINI, "Config", "Remark1", txtRemark1.Text)
  66.         WriteIni(strFileINI, "Config", "Remark2", txtRemark2.Text)
  67.         '//
  68.         MessageBox.Show("บันทึกการตั้งค่าระบบเรียบร้อย.", "รายงานสถานะ", MessageBoxButtons.OK, MessageBoxIcon.Information)
  69.         Me.Close()
  70.     End Sub

  71.     Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
  72.         Me.Close()
  73.     End Sub

  74.     Private Sub frmSetting_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
  75.         Me.Dispose()
  76.     End Sub

  77.     Private Sub txtOwner_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtOwner.KeyPress
  78.         If e.KeyChar = Chr(13) Then
  79.             e.Handled = True
  80.             SendKeys.Send("{TAB}")
  81.         End If
  82.     End Sub

  83.     Private Sub txtAddress_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtAddress.KeyPress
  84.         If e.KeyChar = Chr(13) Then
  85.             e.Handled = True
  86.             SendKeys.Send("{TAB}")
  87.         End If
  88.     End Sub

  89.     Private Sub txtRemark1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtRemark1.KeyPress
  90.         If e.KeyChar = Chr(13) Then
  91.             e.Handled = True
  92.             SendKeys.Send("{TAB}")
  93.         End If
  94.     End Sub

  95.     Private Sub txtRemark2_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtRemark2.KeyPress
  96.         If e.KeyChar = Chr(13) Then
  97.             e.Handled = True
  98.             SendKeys.Send("{TAB}")
  99.         End If
  100.     End Sub

  101.     Private Sub txtHeaderBill_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtHeaderBill.KeyPress
  102.         If e.KeyChar = Chr(13) Then
  103.             e.Handled = True
  104.             SendKeys.Send("{TAB}")
  105.         End If
  106.     End Sub
  107. End Class
คัดลอกไปที่คลิปบอร์ด

โค้ดในส่วนของ ActiveReports.NET ...
  1. ' / --------------------------------------------------------------------------------
  2. ' / Developer : Mr.Surapon Yodsanga (Thongkorn Tubtimkrob)
  3. ' / eMail : thongkorn@hotmail.com
  4. ' / URL: http://www.g2gnet.com (Khon Kaen - Thailand)
  5. ' / Facebook: https://www.facebook.com/g2gnet (For Thailand)
  6. ' / Facebook: https://www.facebook.com/commonindy (Worldwide)
  7. ' / Purpose: Print bill payment for rented room.
  8. ' / Microsoft Visual Basic .NET (2010) & MS Excel 2003+
  9. ' /
  10. ' / This is open source code under @CopyLeft by Thongkorn Tubtimkrob.
  11. ' / You can modify and/or distribute without to inform the developer.
  12. ' / --------------------------------------------------------------------------------
  13. Imports DataDynamics.ActiveReports
  14. Imports DataDynamics.ActiveReports.Document
  15. Imports DataDynamics.ActiveReports.Document.DDPaperSize
  16. Imports System.Drawing.Printing.PaperSize
  17. Imports System.Data.OleDb

  18. Public Class arRentRoomBill
  19.     '// ตัวแปรนี้ต้องประกาศเป็นแบบ Public (เฉพาะ arRoomReciept) เพื่อให้ส่วนของ Detail1_Format และ FetchData มองเห็นด้วย
  20.     Private ItemNo As Integer
  21.     Private GrandTotal As Double
  22.     '// เลือกจากแถวในตารางกริด
  23.     Private sRow As Integer
  24.     '// ตัวแปรนับหลัก โดยเริ่มต้นที่ 2 และเพิ่มขึ้นทีละ 2 (Detail1_Format)
  25.     Private sCol As Integer

  26.     Private Sub arRoomReciept_ReportStart(sender As Object, e As System.EventArgs) Handles Me.ReportStart
  27.         ' การตั้งค่าหน้ากระดาษ
  28.         With PageSettings
  29.             '/ หน่วยวัดเป็นนิ้ว
  30.             .Margins.Left = CmToInch(1) '/ แปลงค่า 1.0 ซม. เป็นนิ้ว
  31.             .Margins.Right = 0.1
  32.             .Margins.Top = 0.5
  33.             .Margins.Bottom = 0.2
  34.             '/ ตั้งค่ากระดาษแนวตั้ง
  35.             .Orientation = PageOrientation.Portrait
  36.             '.Orientation = PageOrientation.Landscape
  37.             ' กระดาษขนาด A4
  38.             '.PaperKind = Drawing.Printing.PaperKind.A4
  39.             '/ กรณีที่กำหนดขนาดกระดาษเอง
  40.             .PaperKind = Drawing.Printing.PaperKind.Custom
  41.             .PaperWidth = CmToInch(21) '/ 21 ซม.
  42.             .PaperHeight = CmToInch(14.8)
  43.         End With
  44.         ' ปกติต้องเคลียร์ค่าต่างๆของ TextBox ก่อนการพิมพ์
  45.         txtItem.Text = ""
  46.         txtDesc.Text = ""
  47.         txtUnitPrice.Text = ""
  48.         txtQTY.Text = ""
  49.         txtAmount.Text = ""
  50.         txtGrandTotal.Text = ""
  51.         '// แสดงกิจการและที่อยู่ โดยการอ่านค่าจาก INI (Initialized File)
  52.         Dim strFileINI As String = MyPath(Application.StartupPath) & "Config.ini"
  53.         If My.Computer.FileSystem.FileExists(strFileINI) Then
  54.             txtOwner.Text = ReadIni(strFileINI, "Config", "Owner", "")
  55.             txtAddress.Text = ReadIni(strFileINI, "Config", "Address", "")
  56.             txtHeaderBill.Text = ReadIni(strFileINI, "Config", "HeaderBill", "")
  57.             lblRemark1.Text = ReadIni(strFileINI, "Config", "Remark1", "")
  58.             lblRemark2.Text = ReadIni(strFileINI, "Config", "Remark2", "")
  59.             '// กรณีไม่เจอ ให้เริ่มต้นค่าใหม่
  60.         Else
  61.             txtOwner.Text = "ทองก้อน อพาร์ทเมนท์ แอนด์ โฮมเพลย์สเตชั่น"
  62.             txtAddress.Text = "123/456 ถ.กลางเมือง ต.เมืองเก่า อ.เมือง จ.ขอนแก่น โทร.043-XXX-XXX"
  63.             txtHeaderBill.Text = "- ใบแจ้งค่าใช้จ่าย -"
  64.             lblRemark1.Text = "[1] กรุณาชำระเงินภายในวันที่ 5 ของทุกเดือน"
  65.             lblRemark2.Text = "[2] ชำระค่าปรับล่าช้าวันละ 50 บาท"
  66.         End If
  67.         txtDate.Text = FormatDateTime(Now(), DateFormat.GeneralDate)
  68.         '// อ่านค่าชื่อ WorkSheet มาพิมพ์ประจำเดือน (ตัวอย่าง "กรกฎาคม 2561")
  69.         Dim strMonth As String = frmMainBill.cmbSheetName.Text
  70.         '// ตัดคำที่ไม่ต้องการ
  71.         strMonth = strMonth.Replace("'", "").Replace("[        DISCUZ_CODE_2        ]quot;, "")
  72.         txtDateReciept.Text = strMonth

  73.         '// รับค่า "แถว" ที่ถูกเลือกในตารางกริด
  74.         sRow = frmMainBill.dgvData.CurrentRow.Index
  75.         txtCname.Text = frmMainBill.dgvData.Rows(sRow).Cells(0).Value
  76.         txtRoomNo.Text = frmMainBill.dgvData.Rows(sRow).Cells(1).Value
  77.         '//
  78.         ItemNo = 0
  79.         '// ตั้งค่าหลักแรกที่จะพิมพ์คือหลักที่ 2 (หน่วยค่าห้อง)
  80.         sCol = 2
  81.     End Sub

  82.     Private Sub arRoomReciept_FetchData(sender As Object, eArgs As DataDynamics.ActiveReports.ActiveReport.FetchEventArgs) Handles Me.FetchData
  83.         ItemNo = ItemNo + 1
  84.         '/ ตรวจสอบจำนวนการพิมพ์ทั้งหมด ซึ่งจะมีทั้งหมด 10 หลัก แต่จะใช้การนับหลักเพิ่มทีละ 2
  85.         '/ จึงใช้ \ หรือการหารตัดเศษทิ้งด้วย 2 ก็จะได้หลักมา 5 หลักเท่านั้น
  86.         If ItemNo >= frmMainBill.dgvData.Columns.Count \ 2 Then
  87.             '/ หากหมดแล้วก็จบการพิมพ์
  88.             eArgs.EOF = True
  89.             Exit Sub
  90.             '/ ยังไม่หมดข้อมูลในหลักที่จะพิมพ์
  91.         Else
  92.             eArgs.EOF = False
  93.         End If
  94.     End Sub

  95.     Private Sub Detail1_Format(sender As Object, e As System.EventArgs) Handles Detail1.Format
  96.         '// ItemNo หรือลำดับที่ โดยจะเริ่มจาก 1 (กระโดดไปทำงานที่ FetchData ก่อนลงมาใน Detail1_Format)
  97.         txtItem.Text = ItemNo
  98.         With frmMainBill
  99.             '// ชื่อผู้เช่า (0), หมายเลขห้อง (1)
  100.             '// อ่านค่าเริ่มจากหลัก 2
  101.             '// 1 หน่วยค่าห้อง (2), ค่าเช่าห้อง (3), ค่าไฟฟ้า(4), ค่าไฟฟ้าต่อหน่วย (5) ... ไล่ไปทีละคู่
  102.             txtDesc.Text = .dgvData.Columns(sCol).HeaderText
  103.             txtQTY.Text = Format(Val(.dgvData.Rows(sRow).Cells(sCol).Value), "#,##0.00")
  104.             '// อ่านค่าข้อมูลจากแถวที่เลือกมา (sRow) และข้อมูลอยู่ในหลัก 2 (และเลื่อนหลักถัดๆไปโดยให้ sCol เพิ่มขึ้นทีละ 2)
  105.             txtUnitPrice.Text = Format(Val(.dgvData.Rows(sRow).Cells(sCol + 1).Value), "#,##0.00")
  106.             txtAmount.Text = Format(CDbl(txtUnitPrice.Text) * CDbl(txtQTY.Text), "#,##0.00")
  107.         End With
  108.         '/ รวมจำนวนเงินผ่านทางตัวแปร
  109.         GrandTotal = GrandTotal + CDbl(txtAmount.Text)
  110.         txtGrandTotal.Text = "รวมเงิน: " & Format(GrandTotal, "#,##0.00") & " บาท."
  111.         sCol += 2
  112.     End Sub

  113. End Class
คัดลอกไปที่คลิปบอร์ด

โค้ดในส่วนของโมดูลหากิน ... modFunction.vb
  1. Imports System.Data
  2. Imports System.Data.OleDb
  3. Module modFunction

  4.     ' / --------------------------------------------------------------------------------
  5.     ' / Initialized Management
  6.     Private Declare Unicode Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringW" ( _
  7.         ByVal lpApplicationName As String, _
  8.         ByVal lpKeyName As String, _
  9.         ByVal lpString As String, _
  10.         ByVal lpFileName As String _
  11.         ) As Int32

  12.     Private Declare Unicode Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringW" ( _
  13.         ByVal lpApplicationName As String, _
  14.         ByVal lpKeyName As String, _
  15.         ByVal lpDefault As String, _
  16.         ByVal lpReturnedString As String, _
  17.         ByVal nSize As Int32, _
  18.         ByVal lpFileName As String _
  19.         ) As Int32
  20.     ' / --------------------------------------------------------------------------------

  21.     ' / --------------------------------------------------------------------------------
  22.     Public Sub WriteIni(ByVal iniFileName As String, ByVal Section As String, ByVal ParamName As String, ByVal ParamVal As String)
  23.         Dim Result As Integer = WritePrivateProfileString(Section, ParamName, ParamVal, iniFileName)
  24.     End Sub

  25.     Public Function ReadIni(ByVal IniFileName As String, ByVal Section As String, ByVal ParamName As String, ByVal ParamDefault As String) As String
  26.         Dim ParamVal As String = Space$(1024)
  27.         Dim LenParamVal As Long = GetPrivateProfileString(Section, ParamName, ParamDefault, ParamVal, Len(ParamVal), IniFileName)
  28.         ReadIni = Left$(ParamVal, LenParamVal)
  29.     End Function

  30.     ' / --------------------------------------------------------------------------------
  31.     ' / Get my project path
  32.     ' / AppPath = C:\My Project\bin\debug
  33.     ' / Replace "\bin\debug" with ""
  34.     ' / Return : C:\My Project\
  35.     Function MyPath(ByVal AppPath As String) As String
  36.         '/ MessageBox.Show(AppPath);
  37.         AppPath = AppPath.ToLower()
  38.         '/ Return Value
  39.         MyPath = AppPath.Replace("\bin\debug", "").Replace("\bin\release", "").Replace("\bin\x86\debug", "")
  40.         '// If not found folder then put the \ (BackSlash) at the end.
  41.         If Right(MyPath, 1) <> "" Then MyPath = MyPath & ""
  42.     End Function

  43.     ' / --------------------------------------------------------------------------------
  44.     ' / ฟังค์ชั่นในการป้อนเฉพาะค่าตัวเลขได้เท่านั้น
  45.     Function CheckDigitOnly(ByVal index As Integer) As Boolean
  46.         Select Case index
  47.             Case 48 To 57 ' เลข 0 - 9
  48.                 CheckDigitOnly = False
  49.             Case 8, 13 ' Backspace = 8, Enter = 13
  50.                 CheckDigitOnly = False
  51.             Case Else
  52.                 CheckDigitOnly = True
  53.         End Select
  54.     End Function
  55. End Module
คัดลอกไปที่คลิปบอร์ด

ดาวน์โหลดโค้ดต้นฉบับเต็ม VB.NET (2010) ได้ที่นี่

ขออภัย! โพสต์นี้มีไฟล์แนบหรือรูปภาพที่ไม่ได้รับอนุญาตให้คุณเข้าถึง

คุณจำเป็นต้อง ลงชื่อเข้าใช้ เพื่อดาวน์โหลดหรือดูไฟล์แนบนี้ คุณยังไม่มีบัญชีใช่ไหม? ลงทะเบียน

x
สิ่งที่ดีกว่าการให้ คือการให้แบบไม่มีที่สิ้นสุด

0

กระทู้

1

โพสต์

212

เครดิต

Full Member

Rank: 3Rank: 3

เครดิต
212
โพสต์ 2018-12-27 16:19:31 | ดูโพสต์ทั้งหมด

0

กระทู้

1

โพสต์

8

เครดิต

Newbie

Rank: 1

เครดิต
8
โพสต์ 2019-4-29 10:54:13 | ดูโพสต์ทั้งหมด



ดีครับ

0

กระทู้

1

โพสต์

22

เครดิต

Newbie

Rank: 1

เครดิต
22
โพสต์ 2019-5-1 23:02:05 | ดูโพสต์ทั้งหมด

รบกวนถามครับ ทำยังไงให้เรียกพิมพ์ แบบselect all ได้ทั้งหมดครับ บางทีเลือกพิมพ์ pageได้บางทีก็เลือไม่ได้ครับ

308

กระทู้

498

โพสต์

5971

เครดิต

ผู้ดูแลระบบ

ทองก้อน ทับทิมกรอบ

Rank: 9Rank: 9Rank: 9

เครดิต
5971
 เจ้าของ| โพสต์ 2019-5-2 18:45:58 | ดูโพสต์ทั้งหมด

Peewoy122 ตอบกลับเมื่อ 2019-5-1 23:02
รบกวนถามครับ ทำยังไงให้เรียกพิมพ์ แบบselect all ได้ทั้งห ...

ก็ปกติน่ะครับ ลองดาวน์โหลดโปรแกรมใหม่ได้ที่นี่
สิ่งที่ดีกว่าการให้ คือการให้แบบไม่มีที่สิ้นสุด

0

กระทู้

51

โพสต์

233

เครดิต

Full Member

Rank: 3Rank: 3

เครดิต
233
โพสต์ 2020-3-18 06:40:18 | ดูโพสต์ทั้งหมด

ขอบคุณครับ

0

กระทู้

1

โพสต์

22

เครดิต

Newbie

Rank: 1

เครดิต
22
โพสต์ 2021-8-15 07:03:28 | ดูโพสต์ทั้งหมด

ขอบคุณครับ อาจารย์

0

กระทู้

1

โพสต์

6

เครดิต

Newbie

Rank: 1

เครดิต
6
โพสต์ 2022-10-24 03:12:44 | ดูโพสต์ทั้งหมด

แจ่มมากครับ อบตรงมีโ๕้ดให้ไปศึกษา
ขออภัย! คุณไม่ได้รับสิทธิ์ในการดำเนินการในส่วนนี้ กรุณาเลือกอย่างใดอย่างหนึ่ง ลงชื่อเข้าใช้ | ลงทะเบียน

รายละเอียดเครดิต

ข้อความล้วน|อุปกรณ์พกพา|ประวัติการแบน|G2GNet.com  

GMT+7, 2024-3-28 15:32 , Processed in 0.261955 second(s), 3 queries , File On.

Powered by Discuz! X3.4, Rev.62

Copyright © 2001-2020 Tencent Cloud.

ตอบกระทู้ ขึ้นไปด้านบน ไปที่หน้ารายการกระทู้