<%@ Register TagPrefix="Title" TagName="TitleShow" Src="/aspnetdata/Title.ascx" %>
<%@Page Debug=True %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web" %>
<html>
<head>
	<script language="VB" runat="server">
	Dim Source as SqlConnection
	Dim d as string="SELECT Orders.OrderID, Orders.CusID, Customers.CusName,Orders.OrderDate, Orders.BeforeTaxPrice, Orders.TotalPrice, Orders.TaxPrice, Orders.Tax FROM Orders INNER JOIN Customers ON Orders.CusID = Customers.CusID"
	Dim NowRecord as Integer'目前个数
	sub Page_load(sender as object,e as EventArgs)
		Source = Ctype(Session("NowSTKSQL"),SqlConnection)
		if IsPostBack=false then
			NowRecord = 0 '取得第一个记录
			Status.Text="查看记录"
			StatusSub.Text="查看记录"
			bindNew(true)
		end if
	end sub
	sub bindNew(tag as Boolean)
		if tag=true then
			Dim DS as DataSet = new DataSet()
			Dim NComm as SqlDataAdapter = new SqlDataAdapter(d, Source)
			NComm.Fill(DS, "Orders")
			NComm.Fill(DS, "OrdersN")
			DS.Tables("OrdersN").Rows.Clear()
			Session("NowDO")=DS'声明为Session
			ShowRecord() '执行显示记录
		else
			Dim DS as DataSet =Ctype(Session("NowDO"),DataSet)
			Orders.DataSource=DS.Tables("OrdersN").DefaultView
			Orders.DataBind()
		end if
	end sub
	sub ShowRecord()
		Dim NowDS as DataSet = CType(Session("NowDO"),DataSet)
		NowDS.Tables("OrdersN").Rows.Clear()
		if NowRecord >= 0 then '非添加时
			Dim NRow as DataRow = NowDS.Tables("Orders").Rows(NowRecord)
			NowDS.Tables("OrdersN").ImportRow(NRow)
			Orders.DataSource=NowDS.Tables("OrdersN").DefaultView
			Orders.DataBind()
			CurrentRecord.Text=(NowRecord+1).ToString()
			AllRecords.Text=NowDS.Tables("Orders").Rows.Count.ToString()
		else
			Dim DS as DataSet = CType(Session("NowDO"),DataSet)
			NowDS.Tables("OrdersN").Rows.Clear()'清除记录
			Dim NwRow as DataRow=DS.Tables("OrdersN").NewRow()'添加
			NwRow("Tax")=0'为各栏指定预设值
			NwRow("TaxPrice")=0
			NwRow("BeforeTaxPrice")=0
			NwRow("TotalPrice")=0
			DS.Tables("OrdersN").Rows.Add(NwRow)
			Orders.DataSource=NowDS.Tables("OrdersN").DefaultView
			Orders.EditItemIndex=0
			Orders.DataBind()
			Dim k as Control =CType(Orders,Control)
			DropDownListSource(k,"DataList","CusName","CusID",0,"Customers","CusID",0,"","CusID")
		end if
		DetailBind(true)
	end sub
	sub DetailBind(tag as Boolean)
		if tag=true then
			Dim NowDS as DataSet = CType(Session("NowDO"),DataSet)
			Dim k as string ="SELECT Product.ProductName, OrderDetail.ID, OrderDetail.OrderID, "
			k+="OrderDetail.ProductID, OrderDetail.Price, OrderDetail.Quantity, "
			k+="OrderDetail.TotalThis, OrderDetail.ToStock FROM OrderDetail INNER "
			k+=" JOIN Product ON OrderDetail.ProductID = Product.ProductID "
			k+="where OrderID ='" + NowDS.Tables("OrdersN").Rows(0)("OrderID") + "'"
			Dim NComm1 as SqlDataAdapter = new SqlDataAdapter(k, Source)
			try'若是第一次载入，会发生错误，以try避开
				NowDS.Tables("OrderDetail").Rows.Clear()'清除记录
			catch
			end try
			NComm1.Fill(NowDS, "OrderDetail")
			Detail.DataSource=NowDS.Tables("OrderDetail").DefaultView
			Detail.DataBind()

		else
			DIm NowDS as DataSet = CType(Session("NowDO"),DataSet)
			Detail.DataSource=NowDS.Tables("OrderDetail").DefaultView
			Detail.DataBind()
		end if
	end sub
	sub ChangeRecord(sender as object, e as CommandEventArgs)
		if e.CommandArgument = "Next" then'下个
			if CurrentRecord.Text=AllRecords.Text then
				NowRecord = Convert.ToInt32(AllRecords.Text)-1
			else
				CurrentRecord.Text=(Convert.ToInt32(CurrentRecord.Text)+1).ToString()
				NowRecord = Convert.ToInt32(CurrentRecord.Text)-1
			end if
		elseif e.CommandArgument = "First" then'首个
			CurrentRecord.Text="1"
			NowRecord = 0
		elseif e.CommandArgument = "Last" then'末个
			CurrentRecord.Text=(Convert.ToInt32(AllRecords.Text)).ToString()
			NowRecord = Convert.ToInt32(AllRecords.Text) - 1
		elseif e.CommandArgument = "Prev" then'上个
			if Convert.ToInt32(CurrentRecord.Text) > 1 then
				CurrentRecord.Text=(Convert.ToInt32(CurrentRecord.Text) - 1).ToString()
				NowRecord = Convert.ToInt32(CurrentRecord.Text)-1
			else
				NowRecord = 1
			end if
		end if
		ShowRecord()
		DetailBind(true)
	end sub
	sub GotoRecord(sender as object,e as EventArgs)
		try
			dim k as integer = Convert.ToInt32(ToRecord.Text)'取得输入之数字
			if k>Convert.ToInt32(AllRecords.Text) then'若输入大于总个数
				k = Convert.ToInt32(AllRecords.Text)
			end if
			if k<0 then'若输入小于0
				k = 1
			end if
			NowRecord=k-1
			ToRecord.Text=k.ToString()
			CurrentRecord.Text=k.ToString()
			ShowRecord()
		catch
			NowRecord=0
			ToRecord.Text="1"
			CurrentRecord.Text="1"
			ShowRecord()
		end try
	end sub
	sub Orders_Edit(sender as object,e as DataListCommandEventArgs)
		Orders.EditItemIndex = e.Item.ItemIndex
		bindNew(false)
		Dim f as TextBox =Ctype(Orders.Items(0).FindControl("OrderID"),TextBox)
		f.Visible=false
		Dim DS as DataSet = Ctype(Session("NowDO"),DataSet)
		Dim NRow as DataRow = DS.Tables("OrdersN").Rows(0)
		dim h as string =NRow("CusID").ToString()
		Dim k as Control =Ctype(Orders,Control)
		AddOrder.Visible=false
		AddDetail.Visible=false
		DropDownListSource(k,"DataList","CusName","CusID",0,"Customers","CusID",0,h,"CusID")
		Status.Text="编辑记录"
		Dim x as RangeValidator = Ctype(Orders.Items(0).FindControl("OrderDateValidate"),RangeValidator)
		Dim y as DateTime = DateTime.Today
		x.MaximumValue = y.AddDays(3).ToString("yyyy/MM/dd")
		x.MinimumValue = y.AddDays(-3).ToString("yyyy/MM/dd")
		x.ErrorMessage = "输入错误，允许起迄日期为" & x.MinimumValue & "至" & x.MaximumValue
		ChangeDetailEdit(false)
	end sub
	sub ChangeDetailEdit(tag as Boolean)
		dim i as integer
		for i=0 to Detail.Items.Count-1
			Detail.Items(i).Cells(0).Controls(0).Visible=tag
			Detail.Items(i).Cells(1).Controls(0).Visible=tag
		next
	end sub
	Function Teststring(h as string) as Double
		if h="" then
			return 0
		else
			return Convert.ToDouble(h)
		end if
	end function
	sub Orders_Update(sender as object,e as DataListCommandEventArgs)
		Dim DS as DataSet = Ctype(Session("NowDO"),DataSet)
		dim w as string =""
		dim OrderDate as TextBox = Ctype(e.Item.FindControl("OrderDate"),TextBox)
		dim BeforeTaxPrice as TextBox = Ctype(e.Item.FindControl("BeforeTaxPrice"),TextBox)
		dim TaxPrice as TextBox = Ctype(e.Item.FindControl("TaxPrice"),TextBox)
		dim TotalPrice as TextBox = Ctype(e.Item.FindControl("TotalPrice"),TextBox)
		Dim k as Double =Convert.ToDouble(TaxPrice.Text) + Convert.ToDouble(BeforeTaxPrice.Text)'取得含税价
		dim dt as DropDownList =Ctype(e.Item.FindControl("CusID"),DropDownList)
		dim y as integer = 0
		if TaxPrice.Text <> "0" then'若不等于0则y等于1
			y=1'y是含税否
		end if
		if Status.Text="编辑记录" then
			Dim NowID as Label = Ctype(e.Item.FindControl("OrderIDV"),Label)
			w = "Update Orders set"
			w += " OrderDate ='" & OrderDate.Text & "', BeforeTaxPrice =" & Teststring(BeforeTaxPrice.Text)
			w += ", TaxPrice =" & Teststring(TaxPrice.Text) & ", TotalPrice =" & k
			w += ", Tax = " & y & ",CusID ='" & dt.SelectedItem.Value & "' where OrderID ='" & NowID.Text & "'"
		else
			Dim Nowid as TextBox = Ctype(e.Item.FindControl("OrderID"),TextBox)
			w = "Insert Into Orders (OrderID,OrderDate,BeforeTaxPrice,Tax,TaxPrice,TotalPrice,CusID) Values ( '"
			w += Nowid.Text & "','" & OrderDate.Text & "'," & Teststring(BeforeTaxPrice.Text) & "," & y & "," & Teststring(TaxPrice.Text)
			w += "," & Teststring(TotalPrice.Text) & ",'" & dt.SelectedItem.Value & "')"
		end if
		try
			Dim UpOrder as SqlCommand = new SqlCommand(w,Source)
			UpOrder.Connection.Open()
			UpOrder.ExecuteNonQuery()'执行保存
			UpOrder.Connection.Close()
			Orders.EditItemIndex = -1
			NowRecord=Convert.ToInt32(CurrentRecord.Text)-1
			Orders.EditItemIndex = -1
			NowRecord=Convert.ToInt32(CurrentRecord.Text)-1
			bindNew(true)
			AddOrder.Visible=true
			AddDetail.Visible=true
			ChangeDetailEdit(true)
			Status.Text="查看记录"
		catch p as Exception
			errMsg.Text="以" & w & "添加失败" & p.ToString()
		end try
	end sub
	sub Orders_Cancel(sender as object,e as DataListCommandEventArgs)
		if Status.Text="添加记录" then
			Status.Text="查看记录"
			dim x as integer =Convert.ToInt32(AllRecords.Text)
			NowRecord=x-2
			AllRecords.Text=(x-1).ToString()
			CurrentRecord.Text=(x-1).ToString()
			ShowRecord()
		end if
		Orders.EditItemIndex = -1
		AddOrder.Visible=true
		AddDetail.Visible=true
		bindNew(false)
		ChangeDetailEdit(true)
	end sub
	sub AddOrder_Click(sender as object,e as EventArgs)
		NowRecord=-1
		ShowRecord()
		Status.Text="添加记录"
		dim f as Label =Ctype(Orders.Items(0).FindControl("OrderIDV"),Label)
		f.Visible=false'隐藏
		dim x as integer =Convert.ToInt32(AllRecords.Text)+1
		AllRecords.Text=x.ToString()'总个数加1
		CurrentRecord.Text=x.ToString()
		AddOrder.Visible=false
		DetailBind(true)
	end sub
	sub AddDetail_Click(sender as object,e as EventArgs)
		Dim NowDS as DataSet = Ctype(Session("NowDO"),DataSet)
		Dim NwRow as DataRow  =	NowDS.Tables("OrderDetail").NewRow()'声明新记录
		dim NowID as Label = Ctype(Orders.Items(0).FindControl("OrderIDL"),Label)
		NwRow("OrderID")= NowID.Text
		NwRow("Quantity")=0
		NwRow("Price")=0
		NwRow("TotalThis")=0
		NowDS.Tables("OrderDetail").Rows.Add(NwRow)
		Detail.DataSource=NowDS.Tables("OrderDetail").DefaultView'结合
		Detail.DataBind()
		Detail.EditItemIndex=Detail.Items.Count-1'编辑
		Detail.DataBind()
		Dim h as Control = Ctype(Detail,Control)
		DropDownListSource(h,"DataGrid","ProductName","ProductID",Detail.Items.Count-1,"Product","ProductID",2,"","ProductID")
		AddDetail.Visible=false
		StatusSub.Text="添加记录"
	end sub
	sub Detail_Cancel(sender as object,e as DataGridCommandEventArgs)
		Detail.EditItemIndex=-1
		DetailBind(true)
		AddDetail.Visible=true
		StatusSub.Text="查看记录"
	end sub
	sub DropDownListSource(Gd as Control,Type as string,TextField as String,ValueField as string,NowIndex as integer,Sname as string,ControlName as string,CellPosition as integer,CompareValue as string,CompareField as string)
		Dim dt as DropDownList '=null
		Dim NowDS as DataSet = Ctype(Session("NowDO"),DataSet)
		Dim NComm1 as SqlDataAdapter = new SqlDataAdapter("select * from " + Sname, Source)
		NComm1.Fill(NowDS, Sname)'取得来源
		if Type="DataGrid" then'判断传入之类型及寻找DropDownList
			dim nc as DataGrid = Ctype(Gd,DataGrid)
			dt=Ctype(nc.Items(NowIndex).Cells(CellPosition).FindControl(ControlName),DropDownList)
		elseif Type="DataList" then
			Dim nc as DataList = Ctype(Gd,DataList)
			dt=Ctype(nc.Items(NowIndex).FindControl(ControlName),DropDownList)
		end if
		dt.DataSource=NowDS.Tables(Sname).DefaultView
		dt.DataTextField=TextField
		dt.DataValueField=ValueField
		dt.DataBind()
		if CompareValue="" then'若未传入比对值
			dt.SelectedIndex=0 '选取第一个选项
			return
		end if
		dim f as integer = 0  '逐一比对
		Dim Row as DataRow
		for each Row in NowDS.Tables(Sname).Rows
			if Row(CompareField).ToString()=CompareValue then
				dt.SelectedIndex=f '找到及设定选取索引值
				exit sub
			end if
			f+=1
		next
	end sub
	sub Detail_Update(sender as object,e as DataGridCommandEventArgs)
		dim w as string =""
		dim dt as DropDownList = Ctype(e.Item.Cells(2).FindControl("ProductID"),DropDownList)
		Dim Quantity as TextBox=Ctype(e.Item.Cells(3).FindControl("Quantity"),TextBox)
		Dim Price as TextBox =Ctype(e.Item.Cells(4).FindControl("Price"),TextBox)
		Dim TotalThis as Label = Ctype(e.Item.Cells(5).FindControl("TotalThis"),Label)
		Dim NowID as Label = Ctype(Orders.Items(0).FindControl("OrderIDL"),Label)
		if StatusSub.Text="添加记录" then
			w="Insert Into OrderDetail (OrderID,ProductID,Quantity,Price,TotalThis) Values ("
			w += "'" & NowID.Text & "','" & dt.SelectedItem.Value & "'," & Quantity.Text & "," & Price.Text
			w += "," & TotalThis.Text & ")"
		else
			dim m as integer =Convert.ToInt32(Detail.DataKeys(Detail.EditItemIndex))
			w = "Update OrderDetail Set ProductID ='" & dt.SelectedItem.Value & "',Quantity =" & Quantity.Text
			w+=",Price =" & Price.Text & ",TotalThis =" & TotalThis.Text & " where ID =" & m
		end if
		try
			dim UpOrderDetail as SqlCommand = new SqlCommand(w,Source)
			UpOrderDetail.Connection.Open()
			UpOrderDetail.ExecuteNonQuery()'执行保存
			UpOrderDetail.Connection.Close()
			Detail.EditItemIndex=-1
			DetailBind(true)
			AddDetail.Visible=true
			StatusSub.Text="查看记录"
			AddOrder.Visible=true
			BeforeTaxCount()
'			ChangeDetailEdit(true)
		catch g as Exception
			errMsg.Text="发生错误，无法保存" & g.ToString()
		end try
	end sub
	sub Detail_Edit(sender as object,e as DataGridCommandEventArgs)
		Dim v as Label = Ctype(e.Item.Cells(1).FindControl("ProductIDL"),Label)
		Dim v1 as string = v.Text
		Detail.EditItemIndex=e.Item.ItemIndex
		DetailBind(false)
		Dim h as Control = Ctype(Detail,Control)
		DropDownListSource(h,"DataGrid","ProductName","ProductID",e.Item.ItemIndex,"Product","ProductID",2,v1,"ProductID")
		AddDetail.Visible=false
		StatusSub.Text="编辑记录"
	end sub
	sub Qu_Changed(sender as object, e as EventArgs)
		Dim Qu as TextBox = Ctype(Detail.Items(Detail.EditItemIndex).Cells(3).FindControl("Quantity"),TextBox)
		Dim Pri as TextBox = Ctype(Detail.Items(Detail.EditItemIndex).Cells(4).FindControl("Price"),TextBox)
		Dim SubT as Label = Ctype(Detail.Items(Detail.EditItemIndex).Cells(5).FindControl("TotalThis"),Label)
		try
			SubT.Text=(Convert.ToInt32(Qu.Text) * Convert.ToInt32(Pri.Text)).ToString()
		catch
			SubT.Text="0"'发生错误
		end try
	end sub
	Function BeforeTaxTotal() as Double
		Dim Total as Double = 0
		Dim i as Integer = 0
		for i=0 to Detail.Items.Count-1
			Dim SubT as Label = Ctype(Detail.Items(i).Cells(5).FindControl("TotalThis"),Label)
			try
			Total += Convert.ToDouble(SubT.Text)
			catch
			end try
		next
		return Total
	end function
	sub Detail_Del(sender as object, e as DataGridCommandEventArgs)
		Dim Dstring as string
		Dim Nowid as string = Detail.DataKeys(e.Item.ItemIndex).ToString()
		Dstring = "Delete From OrderDetail where ID =" & Nowid
		try
			Dim UpStaff as SqlCommand =new SqlCommand(Dstring,Source)
			UpStaff.Connection.Open()
			UpStaff.ExecuteNonQuery()'执行保存
			UpStaff.Connection.Close()
			DetailBind(true)
			BeforeTaxCount()
		catch p as Exception
			errMsg.Text="Delete fail" & p.ToString()
		end try
	end sub
	sub BeforeTaxCount()
		Dim NowDS as DataSet = Ctype(Session("NowDO"),DataSet)
		Dim NowID as Label = Ctype(Orders.Items(0).FindControl("OrderIDL"),Label)
		NowDS.Tables("OrdersN").Rows(0)("BeforeTaxPrice")=BeforeTaxTotal()
		Dim a as Double = 0
		if NowDS.Tables("OrdersN").Rows(0)("Tax").ToString()="True" then
			a=BeforeTaxTotal()*0.05'计算税金
		end if
		Dim y as Double = BeforeTaxTotal() + a'含税价
		Dim w1 as string = "Update Orders Set BeforeTaxPrice =" & BeforeTaxTotal() & ",TotalPrice =" & y
		w1 += ",TaxPrice =" & a & " where OrderID='" & NowID.Text & "'"
		Dim UpOrder as SqlCommand=new SqlCommand(w1,Source)
		UpOrder.Connection.Open()
		UpOrder.ExecuteNonQuery()'执行保存
		UpOrder.Connection.Close()
		NowRecord=Convert.ToInt32(CurrentRecord.Text)-1
		bindNew(true)
	end sub
	</script>
<script language="javascript">
<!--
function CalCu(){
var b=0
var x=0
var c=0
b=Order.Orders__ctl1_BeforeTaxPrice.value-c
if(Order.TaxClient.checked=true){
	x=b*0.05
	Order.Orders__ctl1_TaxPrice.value=x
	Order.Orders__ctl1_TotalPrice.value=b + x
}else{
	Order.Orders__ctl1_TaxPrice.value=0
	Order.Orders__ctl1_TotalPrice.value=b
}
}
' -->
</script>
<script language="vbscript">
function ClientCheck() 
	if document.all("Orders__ctl1_OrderDateValiDate").IsValid <> -1 then
		MsgBox "日期输入错误"
	end if
end function
</script>
<link rel=stylesheet type="text/css" href="Style.css">
</head>
<body background="/aspnetdata/images/winback.gif">
<Title:TitleShow id="BookT" Runat="server" />
<form runat="server" id="Order">
<asp:LinkButton CausesValidation="false" ID="First" Tooltip="First" OnCommand="ChangeRecord" Runat="server" Text="首个" CommandArgument="First" cssclass="Tab_08" />
<asp:LinkButton CausesValidation="false" ID="Prev" Tooltip="Prev" OnCommand="ChangeRecord" Runat="server" Text="上个" CommandArgument="Prev"  cssclass="Tab_08"/>
<asp:LinkButton CausesValidation="false" ID="Next" Tooltip="Next" OnCommand="ChangeRecord" Runat="server" Text="下个" CommandArgument="Next"  cssclass="Tab_08"/>
<asp:LinkButton CausesValidation="false" ID="Last" Tooltip="Last" OnCommand="ChangeRecord" Runat="server" Text="末个" CommandArgument="Last"  cssclass="Tab_08"/>
至第<asp:TextBox Columns="3" AutoPostBack="true" ID="ToRecord" OnTextChanged="GotoRecord" Runat="server" />个
<p><ASP:LINKBUTTON ID="AddOrder" runat="server" onclick="AddOrder_Click" Text="Add" />　第<asp:Label ID="CurrentRecord" Tooltip="CurrentRecord" Runat="server" />个，共<asp:Label ID="AllRecords" Tooltip="AllRecords" Runat="server" />个　　
<font color="#FF0000"><b>目前状态：<asp:label id="Status" Tooltip="status" runat="server" /></b></font>
<font color="#FF0000"><b><asp:label id="errMsg" runat="server" /></b></font><br>
<asp:DataList id="Orders" runat="server"
	BorderColor="black"	BorderWidth="1"
	GridLines="Both"	CellPadding="3"
	CellSpacing="0" 	Font-Name="Verdana"
	Font-Size="11pt" 	RepeatColumns="1"
	Width="500px"		HeaderStyle-BackColor="#C0FFFF"
	AlternatingItemStyle-BackColor="Gainsboro"
	EditItemStyle-BackColor="#FFFFC0"
itemStyle-width="450"
	OnEditCommand="Orders_Edit"
	OnUpdateCommand="Orders_Update"
	OnCancelCommand="Orders_Cancel"
            >
	<HeaderTemplate>
                订单基本资料
	</HeaderTemplate>
	<ItemTemplate>
		<asp:LinkButton id="button1" runat="server" Text="Edit" CommandName="edit" /><br>
<table><tr><td width="55%">
		订单编号：<asp:Label Text='<%# DataBinder.Eval(Container.DataItem,"OrderID") %>' ID="OrderIDL" runat="server" /><br>
</td><td>
		下单日期：<%# DataBinder.Eval(Container.DataItem,"OrderDate","{0:yyyy/MM/dd}")  %><br>
</td></tr><tr><td>
		客户：<%# DataBinder.Eval(Container.DataItem,"CusName")  %>
</td></tr><tr><td>
		未含税价：<asp:Label Text='<%# DataBinder.Eval(Container.DataItem,"BeforeTaxPrice","{0:#,###}") %>' id="BeforeTaxPriceV" runat="server" cssclass="Tab_07"/>
		含税否：<asp:checkbox Checked='<%# DataBinder.Eval(Container.DataItem,"Tax") %>' runat="server" Enabled="false"/>
</td><td>
		税金：<asp:Label Text='<%# DataBinder.Eval(Container.DataItem,"TaxPrice","{0:#,###}") %>' id="TaxPrice" Runat="server" cssclass="Tab_07"/>
		含税价：<asp:Label Text='<%# DataBinder.Eval(Container.DataItem,"TotalPrice","{0:#,###}") %>' id="TotalPrice" Runat="server" cssclass="Tab_07"/>
</td></tr></table>
	</ItemTemplate>
	<EditItemTemplate>
		<asp:LinkButton id="button2" runat="server" Text="Save" CommandName="Update" />
		<asp:LinkButton id="button3" runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="false" /><br>
<table><tr><td width="50%">
		订单编号：<asp:Label id="OrderIDV" Text='<%# DataBinder.Eval(Container.DataItem,"OrderID") %>' runat="server" />
			<asp:TextBox Text='<%# DataBinder.Eval(Container.DataItem,"OrderID") %>' ID="OrderID" runat="server" />
<br>
</td><td>
		下单日期：<asp:Textbox onchange="ClientCheck();" Text='<%# DataBinder.Eval(Container.DataItem,"OrderDate","{0:yyyy/MM/dd}") %>' Runat="server" ID="OrderDate" width="100" /><br>
<asp:RangeValidator
        id="OrderDateValiDate"
        Type="Date"
        ControlToValidate="OrderDate"
        runat="server">
</asp:RangeValidator>
</td></tr><tr><td>
		客户：<asp:DropDownlist id="CusID" Runat="server" />
</td></tr><tr><td>
		未含税价：<asp:TextBox Enabled="false" ID="BeforeTaxPrice" Text='<%# DataBinder.Eval(Container.DataItem,"BeforeTaxPrice") %>' Runat="server" width="50"/>
含税否：<input id="TaxClient" type="checkbox" Checked='<%# DataBinder.Eval(Container.DataItem,"Tax") %>' onclick="javascript:CalCu()">
</td><td>
		税金：<asp:TextBox text='<%# DataBinder.Eval(Container.DataItem,"TaxPrice","{0:#,###}") %>' ID="TaxPrice" Runat="server" width="35"/>
		含税价：<asp:TextBox Enabled="false" Text='<%# DataBinder.Eval(Container.DataItem,"TotalPrice") %>' ID="TotalPrice" Runat="server" width="55"/>
</td></tr></table>
	</EditItemTemplate>
</asp:DataList>
<p>明细资料<br>
<asp:linkbutton id="AddDetail" runat="server" onclick="AddDetail_Click" Text="AddDetail" />　<font color="#FF0000"><b>目前状态：<asp:label id="StatusSub" Tooltip="status" runat="server" /></b></font>
<br>      <ASP:DataGrid id="Detail" runat="server"
        BorderColor="black"
        BorderWidth="1"
        GridLines="Both"
        CellPadding="3"
        CellSpacing="0"
        Font-Name="Verdana"
        Font-Size="9pt"
        HeaderStyle-BackColor="LightYellow"
	HeaderStyle-HorizontalAlign="Center"
	AutoGenerateColumns="FALSE"
	SelectedItemStyle-BackColor="#FFFFC0"
	ItemStyle-HorizontalAlign="right"
	EditItemStyle-HorizontalAlign="right"
	DataKeyField="ID"
	OnEditCommand="Detail_Edit"
	OnCancelCommand="Detail_Cancel"
	OnUpdateCommand="Detail_Update"
	OnDeleteCommand="Detail_Del"
	ShowFooter="True"
>
      <Columns>
        <asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Save" ItemStyle-Wrap="false"/>
	<asp:ButtonColumn Text="Delete" CommandName="Delete"/>
	<asp:TemplateColumn HeaderText="BookName" >
		<ItemTemplate>
			<asp:Label runat="server" Text=<%# DataBinder.Eval(Container.DataItem, "ProductName") %> id="BNameV"/>
			<asp:Label runat="server" Text=<%# DataBinder.Eval(Container.DataItem, "ProductID") %> id="ProductIDL" visible="false"/>
		</ItemTemplate>
		<EditItemTemplate>
			<asp:DropDownlist runat="server" id="ProductID"/>
		</EditItemTemplate>
	</asp:TemplateColumn>
	<asp:TemplateColumn HeaderText="Quantity" >
		<ItemTemplate>
			<asp:Label runat="server" Text=<%# DataBinder.Eval(Container.DataItem, "Quantity") %> id="QuantityV"/>
		</ItemTemplate>
		<EditItemTemplate>
			<asp:textBox runat="server" AutoPostBack="true" OnTextChanged="Qu_Changed" Text=<%# DataBinder.Eval(Container.DataItem, "Quantity") %> id="Quantity" width="35"/>
		</EditItemTemplate>
	</asp:TemplateColumn>
	<asp:TemplateColumn HeaderText="Price" >
		<ItemTemplate>
			<asp:Label runat="server" Text=<%# DataBinder.Eval(Container.DataItem, "Price") %> id="PriceV"/>
		</ItemTemplate>
		<EditItemTemplate>
			<asp:TextBox runat="server" AutoPostBack="true" OnTextChanged="Qu_Changed" Text=<%# DataBinder.Eval(Container.DataItem, "Price") %> id="Price" width="35"/>
		</EditItemTemplate>
	</asp:TemplateColumn>
	<asp:TemplateColumn HeaderText="SubTotal" >
		<ItemTemplate>
			<asp:Label runat="server" Text=<%# DataBinder.Eval(Container.DataItem, "TotalThis","{0:#,###}") %> id="TotalThis"/>
		</ItemTemplate>
         <FooterTemplate>
             SubTotal:<asp:Label ID="NowSubTotal" Text="<%# BeforeTaxTotal() %>" Runat="server" />
         </FooterTemplate>
	</asp:TemplateColumn>
	</Columns>
</ASP:DataGrid>
</form>