Phần Không Tên 2
Imports System.IO.File
Imports System.Xml.Linq
Imports System.Xml
Dim XC, XM, XD, XI As New XDocument
Private Sub loadData()
XC = XDocument.Load("customer.xml")
XM = XDocument.Load("master.xml")
XD = XDocument.Load("detail.xml")
XI = XDocument.Load("item.xml")
Dim qr = From kh In XC.Descendants.Elements("customer") _
Select New With {.maso = kh.Attribute("ccode").Value, _
.hoten = kh.Attribute("cname").Value, _
.diachi = kh.Attribute("address").Value _
}
dgv_hanghoa.DataSource = qr.ToList
End Sub
Function isCustomer(ByVal code As String)
Dim result As String = ""
Dim qr = From kh In XC.Descendants.Elements("customer") _
Where kh.Attribute("ccode").Value = code _
Select kh.Attribute("cname").Value
If qr.Count > 0 Then
result = qr.First()
End If
isCustomer = result
End Function
Function isCustomer2(ByVal orderno As String)
Dim result As String = ""
Dim qr = From kh In XC.Descendants.Elements("customer") _
Join hd In XM.Descendants.Elements("order") _
On kh.Attribute("ccode").Value Equals (hd.Attribute("ccode").Value) _
Where hd.Attribute("orderno").Value = orderno _
Select kh.Attribute("cname").Value
If qr.Count > 0 Then
result = qr.First()
End If
isCustomer2 = result
End Function
Function isOrder(ByVal icode As String)
Dim result As XElement
Dim qr = From i In XI.Descendants.Elements("item") _
Where i.Attribute("icode").Value = icode _
Select i
If qr.Count > 0 Then
result = qr.First()
End If
isOrder = result
End Function
Private Sub btn_search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btn_search.Click
detailOrder(txt_search.Text)
End Sub
Private Sub HangHoa_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
loadData()
End Sub
Private Sub detailOrder(ByVal order As String)
Dim cname = isCustomer2(order)
Dim sum As Integer = 0
Dim qr = From d In XD.Descendants.Elements("item") _
Join i In XI.Descendants.Elements("item") _
On d.Attribute("icode").Value Equals i.Attribute("icode").Value _
Where d.Attribute("orderno").Value = order _
Select New With {.mahh = d.Attribute("icode").Value, _
.tenhh = i.Attribute("iname").Value, _
.gia = i.Attribute("price").Value, _
.sl = d.Attribute("qty").Value _
}
For Each x As Object In qr
sum = sum + (x.gia * x.sl)
Next
Dim out = _
<html>
<body>
<h3>Chi tiet don hang</h3>
So hoa don: <%= order %> Ho ten:<%= cname %>
<table>
<%= From d In XD.Descendants.Elements("item") _
Join i In XI.Descendants.Elements("item") _
On d.Attribute("icode").Value Equals i.Attribute("icode").Value _
Where d.Attribute("orderno").Value = order _
Select <tr>
<td><%= d.Attribute("icode").Value %></td>
<td><%= i.Attribute("iname").Value %></td>
<td><%= i.Attribute("price").Value %></td>
<td><%= d.Attribute("qty").Value * i.Attribute("price").Value %></td>
</tr> %>
</table>
Tong Tien = <%= sum %>
</body>
</html>
out.Save("chitiethoadon.html")
Process.Start("chitiethoadon.html")
End Sub
Private Sub detailMaster()
Dim sum_sl, sum_tt As Integer
Dim ele As XElement = isOrder(txt_search.Text)
For Each x As XElement In XD.Descendants.Elements("item")
sum_sl = sum_sl + x.Attribute("qty").Value
sum_tt = sum_tt + (x.Attribute("qty").Value * ele.Attribute("price").Value)
Next
Dim out = _
<html>
<head>
</head>
<body>
<h3>Danh sách chi tiết về một loại hàng hóa bán ra</h3>
Mã hàng: <%= ele.Attribute("icode").Value %> Tên hàng: <%= ele.Attribute("iname").Value %>
<table>
<tr>
<td>Số hóa đơn</td>
<td>Ngày</td>
<td>Khách</td>
<td>Số lượng</td>
<td>Thành tiền</td>
</tr>
<%= From m In XM.Descendants.Elements("order") _
Join d In XD.Descendants.Elements("item") _
On m.Attribute("orderno").Value Equals d.Attribute("orderno").Value _
Where d.Attribute("icode").Value = ele.Attribute("icode").Value _
Select <tr>
<td><%= m.Attribute("orderno").Value %></td>
<td><%= m.Attribute("orderdate").Value %></td>
<td><%= m.Attribute("ccode").Value %></td>
<td><%= d.Attribute("qty").Value %></td>
<td><%= d.Attribute("qty").Value * ele.Attribute("price").Value %></td>
</tr> %>
</table>
<p>Tổng:</p>
<p>Số lượng: <%= sum_sl %></p>
<p>Thành tiền: <%= sum_tt %></p>
</body>
</html>
out.Save("chitietmathang.html")
End Sub
Private Sub load_Detailitem()
Dim item As XElement = isOrder(txt_search.Text)
Dim sum_sl, sum_tt As Integer
For Each ele As XElement In XD.Descendants.Elements("item")
sum_sl = sum_sl + ele.Attribute("qty").Value
sum_tt = sum_sl * item.Attribute("price").Value
Next
Dim qr = From m In XM.Descendants.Elements("order") _
Join d In XD.Descendants.Elements("item") _
On m.Attribute("orderno").Value Equals d.Attribute("orderno").Value _
Where d.Attribute("icode").Value = item.Attribute("icode").Value _
Select New With {.sohoadon = m.Attribute("orderno").Value, _
.ngay = m.Attribute("orderdate").Value, _
.khach = m.Attribute("ccode").Value, _
.soluong = d.Attribute("qty").Value, _
.thanhtien = .soluong * item.Attribute("price").Value _
}
dgv_hanghoa.DataSource = qr.ToList()
End Sub
Đề 2:
Function customer(ByVal ccode$) As String
Dim kq$ = ""
Dim out = From cm As XElement In xkh.Descendants.Elements("customer") _
Where cm.Attribute("ccode").Value = ccode _
Select "Họ tên: " & cm.Attribute("cname").Value & " / Địa chỉ: " &
cm.Attribute("address").Value
kq = out.First
Return kq
End Function
Sub detailMaster(ByVal ccode$)
Dim out1 = From it As XElement In xit.Descendants.Elements("item") _
Join ct As XElement In xdt.Descendants.Elements("item") _
On ct.Attribute("icode").Value Equals it.Attribute("icode").Value _
Join mt As XElement In xmt.Descendants.Elements("order") _
On ct.Attribute("orderno").Value Equals mt.Attribute("orderno").Value _
Join cus As XElement In xkh.Descendants.Elements("customer") _
On mt.Attribute("ccode").Value Equals cus.Attribute("ccode").Value _
Where mt.Attribute("ccode").Value = ccode
Select it.Attribute("price").Value * ct.Attribute("qty").Value
Dim tt# = 0
For Each aa As Integer In out1
tt = tt + aa
Next
Dim out = _
<html>
<head>
</head>
<body>
<h3>Danh sách chi tiết về một loại hàng hóa bán ra</h3>
<%= customer(ccode) %>
<table>
<tr>
<td>Số hóa đơn</td>
<td>Ngày</td>
<td>Mã hàng</td>
<td>Tên hàng</td>
<td>Thành tiền</td>
</tr>
<%= From it As XElement In xit.Descendants.Elements("item") _
Join ct As XElement In xdt.Descendants.Elements("item") _
On ct.Attribute("icode").Value Equals it.Attribute("icode").Value _
Join mt As XElement In xmt.Descendants.Elements("order") _
On ct.Attribute("orderno").Value Equals mt.Attribute("orderno").Value _
Join cus As XElement In xkh.Descendants.Elements("customer") _
On mt.Attribute("ccode").Value Equals cus.Attribute("ccode").Value _
Where mt.Attribute("ccode").Value = ccode
Select <tr>
<td><%= mt.Attribute("orderno").Value %></td>
<td><%= mt.Attribute("orderdate").Value %></td>
<td><%= it.Attribute("icode").Value %></td>
<td><%= it.Attribute("iname").Value %></td>
<td><%= it.Attribute("price").Value * ct.Attribute("qty").Value %></td>
</tr> %>
</table>
<p>Tổng:</p>
<p>Thành tiền: <%= tt %></p>
</body>
</html>
out.Save("chitietmathang.html")
Process.Start("chitietmathang.html")
End Sub
Bạn đang đọc truyện trên: AzTruyen.Top