明細行確認ボタン [VB 2010]
Visual Basic 2010/2008 やさしいADO.NET DBプログラム
フォームクラスに、選択明細行確認ボタンクリック処理と明細行追加ボタンクリック処理を実装します。
行確認ボタン・行追加ボタンクリック処理
【明細行確認ボタンクリック処理】
- 商品コードを引数に指定して、商品クラスのインスタンスを生成
- 商品名称プロパティと、単価プロパティから、商品名称と単価を取得
- 受注金額は、単価×数量を計算し、表示形式を指定
【明細行追加ボタンクリック処理】
- ClsInsertDetailRowクラスの共有メソッドCreateDataRowを呼び出して、受注ディテール表の1行分を生成
- この受注ディテール表行に商品コードと受注数量をセット
- この行データを引数に指定して、ClsInsertDetailRowクラスのインスタンスを生成
- バインディングソースに追加(受注明細リストにも追加される)
Private Sub BtnGyoKakunin_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles BtnGyoKakunin.Click
Try
Dim shohin As New ClsShohin(TxtShohinCode.Text)
LblShohinMeisho.Text = shohin.ShohinMeisho
LblJuchuTanka.Text = CStr(shohin.Tanka)
LblJuchuKingaku.Text = _
(NudSuryo.Value * shohin.Tanka).ToString("#,##0")
BtnGyoTsuika.Focus()
Catch ex As ShohinCodeException
MessageBox.Show(ex.Message, "商品コードエラー")
Catch ex As DBIOException
MessageBox.Show(ex.ToString, "DBIO例外発生")
Catch ex As Exception
MessageBox.Show(ex.ToString, "その他例外発生")
End Try
End Sub
Private Sub BtnGyoTsuika_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles BtnGyoTsuika.Click
Try
Dim dr As DataRow
dr = ClsInsertDetailRow.CreateDataRow
dr("商品コード") = TxtShohinCode.Text
dr("受注数量") = NudSuryo.Value
Dim meisaiGyo As New ClsInsertDetailRow(dr)
bindingSrc.Add(meisaiGyo)
Dim sum As Integer = 0
For i As Integer = 0 To meisaiList.Count - 1
sum += meisaiList(i).JuchuKingaku
Next
LblGokeiKingaku.Text = sum.ToString("#,##0")
TxtShohinCode.Text = Nothing
LblShohinMeisho.Text = Nothing
NudSuryo.Value = 1
LblJuchuTanka.Text = Nothing
LblJuchuKingaku.Text = Nothing
TxtShohinCode.Focus()
BtnGyoSakujo.Enabled = True
BtnGyoHenko.Enabled = True
Catch ex As ShohinCodeException
MessageBox.Show(ex.Message, "商品コードエラー")
Catch ex As DBIOException
MessageBox.Show(ex.ToString, "DBIO例外発生")
Catch ex As Exception
MessageBox.Show(ex.ToString, "その他例外発生")
End Try
End Sub