วิ่งให้เร็วกว่าเมื่อวาน

เขียน Transaction กับ TableAdapter

สร้าง Class เพื่อแทรกการทำงานของ TableAdapter
Namespace WholeSalesEZDataSetTableAdapters
Partial Public Class Pricing_Material_CustomerTableAdapter
Public Overridable Overloads Function UpdateTransacted(ByVal dataTable As WholeSalesEZDataSet.Pricing_Material_CustomerDataTable, ByVal Trx As SqlClient.SqlTransaction) As Integer
Me.Adapter.DeleteCommand.Transaction = Trx
Me.Adapter.InsertCommand.Transaction = Trx
Me.Adapter.UpdateCommand.Transaction = Trx
Dim rowsAffected As Integer = Me.Adapter.Update(dataTable)

Return rowsAffected
End Function
End Class
Partial Public Class GoodsIssuesTableAdapter
Public Overridable Overloads Function UpdateTransacted(ByVal dataTable As WholeSalesEZDataSet.GoodsIssuesDataTable, ByVal Trx As SqlClient.SqlTransaction) As Integer
Me.Adapter.DeleteCommand.Transaction = Trx
Me.Adapter.InsertCommand.Transaction = Trx
Me.Adapter.UpdateCommand.Transaction = Trx
Dim rowsAffected As Integer = Me.Adapter.Update(dataTable)

Return rowsAffected
End Function
End Class
End Namespace


เมื่อตอนเรียกใช้ใน Form
With Me.GoodsIssuesTableAdapter
.Connection()
Dim trx As SqlClient.SqlTransaction = .Connection.BeginTransaction

Me.GoodsIssueItemsTableAdapter.Connection = .Connection
PricingCustomerTableAdapter.Connection = .Connection
Try
Me.GoodsIssuesTableAdapter.UpdateTransacted(Me.WholeSalesEZDataSet.GoodsIssues, trx)
Me.GoodsIssueItemsTableAdapter.UpdateTransacted(Me.WholeSalesEZDataSet.GoodsIssueItems, trx)
PricingCustomerTableAdapter.UpdateTransacted(dtPricingCustomer, trx)
trx.Commit()
Catch ex As Exception
trx.Rollback()
Throw ex

End Try
.Connection.Close()
End With




 

Create Date : 14 มิถุนายน 2550   
Last Update : 14 มิถุนายน 2550 20:20:30 น.   
Counter : 607 Pageviews.  

การทำงานกับ DataSET และ TableAdapter

Dim WSDataSet As New WholeSalesDataSet

'Dim CSTableAdapter As WholeSalesDataSetTableAdapters.CustomerTableAdapter = New WholeSalesDataSetTableAdapters.CustomerTableAdapter

Dim CSTableAdapter As New WholeSalesDataSetTableAdapters.CustomerTableAdapter
CSTableAdapter.Fill(WSDataSet.Customer)

'Dim rwCustomer As WholeSalesDataSet.CustomerRow = CType(WSDataSet.Customer.Rows(0), WholeSalesDataSet.CustomerRow)


'###### FIND #######
Dim rwCustomer As WholeSalesDataSet.CustomerRow = WSDataSet.Customer.FindByCustomerNo(2003)
MessageBox.Show(rwCustomer.CustomerName)

'##### FIND AND UPDATE ##########3
Dim rwCustomer As WholeSalesDataSet.CustomerRow() = WSDataSet.Customer.Select("CustomerName Like 'Hello*'","CustomerNo DESC")

For Each r As WholeSalesDataSet.CustomerRow In rwCustomer
MessageBox.Show(r.CustomerNo & " : " & r.CustomerName)
r.CustomerName = "XXXX"
Next

CSTableAdapter.Update(WSDataSet.Customer)



'###### UPDATE ######
rwCustomer.CustomerName = "Hello World!"
CSTableAdapter.Update(WSDataSet.Customer)

MessageBox.Show(rwCustomer.CustomerName & " Count : " & WSDataSet.Customer.Count)

'###### ADD NEW ########
Dim newCustomer As WholeSalesDataSet.CustomerRow
newCustomer = WSDataSet.Customer.NewCustomerRow
newCustomer.CustomerNo = 2099
newCustomer.CustomerName = "Ming"
WSDataSet.Customer.AddCustomerRow(newCustomer)
MessageBox.Show(" Count : " & WSDataSet.Customer.Count)


'###### COMPUTE ########

Dim countObj As Object
countObj = WSDataSet.Customer.Compute("Count(CustomerNo)", "CustomerName Like '*H*'")

'####### DELETE #########
MessageBox.Show(" Count : " & WSDataSet.Customer.Count)
Try
Dim rwCustomer As WholeSalesDataSet.CustomerRow = WSDataSet.Customer.FindByCustomerNo(2099)
If rwCustomer IsNot Nothing Then
rwCustomer.Delete()
End If

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
CSTableAdapter.Update(WSDataSet.Customer)
MessageBox.Show(" Count : " & WSDataSet.Customer.Count)




 

Create Date : 28 พฤษภาคม 2550   
Last Update : 28 พฤษภาคม 2550 11:10:30 น.   
Counter : 678 Pageviews.  

Function ใช้ในการหา Form ID และ วิธีการ Set Print SETUP ของ Crystal Report

Dim BNSlip As New ReportDocument
Dim reportPath As String = Application.StartupPath & "\Reports\" & "BillingNote.rpt"
BNSlip.Load(reportPath)


BNSlip.SetDataSource(Me.WholeSalesDataSet)
BNSlip.PrintOptions.PaperSource = PaperSource.Tractor
BNSlip.PrintOptions.PrinterName = "LQ-300"
BNSlip.PrintOptions.PaperSize = CType(getPaperSize("9.5x5.5").RawKind, CrystalDecisions.Shared.PaperSize)

BNSlip.SetParameterValue("BillingNoteNo", Val(Me.BillingNoteNoTextBox.Text))
BNSlip.SetParameterValue("CompanyName", xCompany.CompanyName)

Dim fReportViewer As New frmReportViewer
fReportViewer.CRViewer.ReportSource = BNSlip
fReportViewer.Text = "Billing Note Slip"
fReportViewer.ShowDialog()


Public Function getPaperSize(ByVal sizeName As String) As System.Drawing.Printing.PaperSize

Dim i As Integer = 0

Dim PSize As New System.Drawing.Printing.PaperSize

Dim printDoc As New System.Drawing.Printing.PrintDocument

Dim pd As New System.Drawing.Printing.PrintDocument

For i = 0 To printDoc.PrinterSettings.PaperSizes.Count - 1

If (printDoc.PrinterSettings.PaperSizes(i).PaperName = sizeName) Then

PSize = printDoc.PrinterSettings.PaperSizes(i)

End If

i += 1

Next

Return PSize

End Function




 

Create Date : 23 พฤษภาคม 2550   
Last Update : 23 พฤษภาคม 2550 13:58:01 น.   
Counter : 703 Pageviews.  

VB.NET เชื่อมต่อฐานข้อมูล

Dim connStr As String
connStr = My.Settings.WinAppDBConnectionString

Dim conn As New SqlClient.SqlConnection(connStr)

Dim cmd1 As New SqlClient.SqlCommand("SELECT * FROM PRODUCT", conn)
Dim DR As SqlClient.SqlDataReader
conn()
DR = cmd1.ExecuteReader
While DR.Read
MessageBox.Show("Reader = " & DR("ProductNo"))
Exit While
End While
conn.Close()

Dim cmd2 As New SqlClient.SqlCommand("SELECT MAX(PRODUCTNO) AS MaxProductNo From Product", conn)
Dim strProductNo As String
conn()
strProductNo = cmd2.ExecuteScalar
MessageBox.Show("Scalar = " & strProductNo)
conn.Close()

Dim sqlInsert As String
Dim strProductName As String = Me.txtProductName.Text
Dim strUOM As String = Me.txtUOM.Text
Dim NewProductNo As Double
NewProductNo = Val(strProductNo.Substring(1, 5)) + 10

MessageBox.Show(NewProductNo.ToString("'P'00000"))
sqlInsert = " INSERT INTO Product (ProductNo, ProductName, UOM) VALUES('" & NewProductNo.ToString("'P'00000") & "' , '" & strProductName & "', '" & strUOM & "')"
Dim cmd3 As New SqlClient.SqlCommand(sqlInsert, conn)
conn()
Dim result As Integer
result = cmd3.ExecuteNonQuery
conn.Close()
MessageBox.Show("Update = " & result)




 

Create Date : 10 พฤษภาคม 2550   
Last Update : 10 พฤษภาคม 2550 11:00:52 น.   
Counter : 454 Pageviews.  

เขียน .NET ให้ส่ง Fax

ใช้ COM ที่มากับ Microsoft Windows XP โดยต้องทำการ Install Fax Service ใน Windows Component จากนั้นใน VS2005 ให้เพิ่ม COM Reference ชื่อ Microsoft Fax Service Extended COM Type Library (FAXCOMEXLib.dll) จากนั้นให้เขียนโปรแกรมตามนี้


Dim FS As FAXCOMEXLib.FaxServer
Dim FD As FAXCOMEXLib.FaxDocument
FS = New FAXCOMEXLib.FaxServer
FD = New FAXCOMEXLib.FaxDocument
FS.Connect("")


'** Build Fax Header
FD.Sender.TSID = "TSID" 'm_TSID '** Not Currently Supported in SDK
FD.DocumentName = "7000081725" 'm_FaxID
FD.AttachFaxToReceipt = True
FD.Priority = FAXCOMEXLib.FAX_PRIORITY_TYPE_ENUM.fptHIGH

'** Set Recipient
'FD.Recipients.Add(m_RecipientFaxNumber, m_RecipientName)
FD.Recipients.Add("9,029550000", "FiFth")

'** Set Sender
FD.Sender.Name = "FiFth"
FD.Sender.Company = "FiFth Corp."
FD.Sender.FaxNumber = "029985299"
FD.Sender.OfficePhone = "029985299"
FD.Sender.Title = "Title"

'** Set Subject/Body
FD.Subject = "7000081725"
FD.Note = "NiNth Inc."
FD.Body = "c:\temp\test.doc"

'** Fax Cover Page
FD.CoverPageType = FAXCOMEXLib.FAX_COVERPAGE_TYPE_ENUM.fcptNONE 'm_CoverPageType
FD.CoverPage = "TEST" ' m_CoverPageName

'** Submit Fax to WinXP Fax Service
Dim JobID As Object
JobID = FD.ConnectedSubmit(FS)




 

Create Date : 26 มกราคม 2550   
Last Update : 26 มกราคม 2550 16:25:24 น.   
Counter : 407 Pageviews.  

1  2  

The Fifth
Location :
กรุงเทพ Thailand

[Profile ทั้งหมด]

ฝากข้อความหลังไมค์
Rss Feed

ผู้ติดตามบล็อก : 1 คน [?]




คิด-ทำ-มี

ผู้เข้าชมทั้งหมด Free Hit Counter ครั้ง
[Add The Fifth's blog to your web]