<%@Page Language="VB" Inherits="BaseClass" Src="transactions.vb" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Register TagPrefix="Hersh" TagName="nav" Src="nav.ascx" %>
<html>
<script language="VB" runat="server">
Sub Grid1_Update(sender As Object, e As DataGridCommandEventArgs)
	dim sql as string
	Dim vdate As String 
	Dim ref  As String 
	Dim code_value As String 
	Dim dr_amt As String 
	Dim cr_amt As String 
	Dim posted_display As String 
	Dim id As String 
	Dim narr As String 
	Dim myTextBox    As TextBox
	'主键：只读区
	Dim doc_no as string   = Grid1.DataKeys.Item(E.Item.ItemIndex).ToString
	myTextBox = E.Item.FindControl("edit_date")
	vdate =  mytextbox.text
	myTextBox = E.Item.FindControl("edit_ref")
	ref = trim(mytextbox.text)
	myTextBox = E.Item.FindControl("edit_dr_amt")
	dr_amt = trim(mytextbox.text)
	myTextBox = E.Item.FindControl("edit_cr_amt")
	cr_amt = trim(mytextbox.text)
	myTextBox = E.Item.FindControl("edit_posted_display")
	posted_display= trim(mytextbox.text)
	myTextBox = E.Item.FindControl("edit_narr")
	narr = trim(mytextbox.text)
	'执行存储过程
	'response.write(vdate+ ref + dr_amt + cr_amt + posted_display + narr)
	sql = "Execute p_trans @date = '" + vdate + "' ,@ref= '" + ref + "', @dr_amount =" 
	sql = sql + dr_amt + ",@cr_amount = " + cr_amt  +" , @posted_to = " + posted_display + " ," 
	sql = sql + "@id = 'RPT', @doc_no = " + doc_no + ", @narr= '" + narr+ "'"
	RunSql(sql)
	rebind() 
End Sub
Sub add_click(Source As Object, E As EventArgs) 
	dim sql as string  
	sql = "Execute p_trans @date = '" + adate.text + "' ,@ref= '" + aref.text + "', @dr_amount =" 
	sql = sql + adr_amount.text + ",@cr_amount = " + acr_amount.text  +" , @posted_to = '" + aposted_display.SelectedItem.value + "' ," 
	sql = sql + "@id = 'RPT', @doc_no = NULL" +  ", @narr= '" + anarr.text + "'"
	RunSql(sql) 
	rebind() 
	hidePanel()
End Sub
Sub add_show(Source As Object, E As EventArgs) 
	AddPanel.visible = true
end sub
Sub Grid1_delete(sender As Object, e As DataGridCommandEventArgs)
	Dim doc_no as string   = Grid1.DataKeys.Item(E.Item.ItemIndex).ToString
	Dim sql as string
	sql = " Delete from transactions where doc_no = " + cstr(doc_no)
	sql = sql + " Delete from tr_header where doc_no = " + cstr(doc_no)
	RunSql(sql)
	rebind() 
end sub
</script>
<head>
	<style>
	a	{	color:black;
			text-decoration:none;}
	a:hover	{	color:red;
			text-decoration:underline;}
	</style>
</head>
<body style="font: 10pt verdana; background-color:ivory">

<form runat="server">
<asp:ValidationSummary runat=server
headertext="There were errors on the page:" />
<!---- 导航条 开始-------------->
       <Hersh:nav id="menu" runat = server 
       vGridlines = Both
       vBorderColor = "Black"
       vCellPadding = 7 />
 <!---- 导航条 结束-------------->
<h3><font face="Verdana"> Transactions for Account #
<asp:Label id="title" runat="server"/>  </font></h3>
<table width="95%">
	<tr><td>
	<asp:Button id="Addshow" visible = "false" text="新事务" onclick="add_show" runat="server" />
	</td></tr> 
	<hr>
	<tr>
	<td valign="top">
<asp:DataGrid id="Grid1" runat="server"
AutoGenerateColumns="false"
BackColor="White"
BorderWidth="1px" BorderStyle="Solid" BorderColor="Tan"
CellPadding="2" CellSpacing="0"
Font-Name="Verdana" Font-Size="8pt"
OnEditCommand="Grid1_Edit"
OnCancelCommand="Grid1_Cancel"
OnUpdateCommand="Grid1_Update"
OnDeleteCommand = "Grid1_delete"
DataKeyField="doc_no">
  <Columns>
	<asp:EditCommandColumn
	EditText="编辑"
	CancelText="取消"
	UpdateText="确定"
	ItemStyle-Wrap="false"
	HeaderText="编辑"
	HeaderStyle-Wrap="false"/>
	<asp:ButtonColumn Text="删除" CommandName="删除" HeaderText="Delete"/>
	<asp:BoundColumn HeaderText="Doc #" ReadOnly="true" DataField="doc_no"/>
	 <asp:TemplateColumn HeaderText="Ref" >
		   <ItemTemplate>
		   <asp:Label Text='<%# Container.DataItem("ref") %>' runat="server"/>
		   </ItemTemplate>
		   <EditItemTemplate>
		   <asp:TextBox id="edit_ref" Text='<%# Container.DataItem("ref") %>'
		    runat="server"/>
		  </EditItemTemplate>
         </asp:TemplateColumn>
         <asp:TemplateColumn HeaderText="日期" >
		 <ItemTemplate>
		 <asp:Label Text='<%# Container.DataItem("date") %>' runat="server" />
		 </ItemTemplate>
		 <EditItemTemplate >
		 <asp:TextBox id="edit_date" BorderStyle="None" Readonly="True" Text='<%# Container.DataItem("date") %>'
		    runat="server"  />
	       	</EditItemTemplate>
          </asp:TemplateColumn>
          <asp:TemplateColumn HeaderText="Payee" >
		    <ItemTemplate>
		    <asp:Label Text='<%# Container.DataItem("posted_display") %>' runat="server"/>
		    </ItemTemplate>
		    <EditItemTemplate>
		    <asp:TextBox id="edit_posted_display"  Text='<%# Container.DataItem("posted_to") %>'
		    runat="server" ReadOnly="true" BorderStyle="None" />    
		    </EditItemTemplate>
	   </asp:TemplateColumn>
	   <asp:TemplateColumn HeaderText="Narration" >
	   		    <ItemTemplate>
	   		    <asp:Label Text='<%# Container.DataItem("narr") %>' runat="server"/>
	   		    </ItemTemplate>
	   		    <EditItemTemplate>
	   		    <asp:TextBox id="edit_narr"  Text='<%# Container.DataItem("narr") %>'
	   		    runat="server"/>    
	   		    </EditItemTemplate>
	   </asp:TemplateColumn>
	   <asp:TemplateColumn HeaderText="Deposit" >
	   		    <ItemTemplate>
	   		    <asp:Label Text='<%# Container.DataItem("dr_amount") %>' runat="server"/>
	   		    </ItemTemplate>
	   		    <EditItemTemplate>
	   		    <asp:TextBox id="edit_dr_amt"   Text='<%# Container.DataItem("dr_amount") %>'
	   		    runat="server"/>
	   		    </EditItemTemplate>
	   </asp:TemplateColumn>
	  <asp:TemplateColumn HeaderText="Payment" >
		    <ItemTemplate>
		    <asp:Label Text='<%# Container.DataItem("cr_amount") %>' runat="server"/>
		    </ItemTemplate>
		    <EditItemTemplate>
		    <asp:TextBox id="edit_cr_amt"  Text='<%# Container.DataItem("cr_amount") %>'
		    runat="server"/>
		    </EditItemTemplate>
	   </asp:TemplateColumn>	             
   </Columns>
	<HeaderStyle BackColor="DarkRed" ForeColor="White" Font-Bold="true"/>
	<ItemStyle ForeColor="DarkSlateBlue"/>
	<AlternatingItemStyle BackColor="Beige"/>
</asp:DataGrid>
</td>
<td valign="top">
        <!---- 插入行 逻辑-------------->
        <asp:Panel id="AddPanel" runat="server" Visible="false">
        <table style="font: 8pt verdana">
	            <tr>
	              <td colspan="2" bgcolor="#aaaadd" style="font:10pt verdana">Add a New Transaction:</td>
	            </tr>
	            <tr>
			   <td nowrap>Date (必填): </td>
			   <td><asp:TextBox id="adate"  runat="server" value = ""  /></td>
			   <td> <asp:RequiredFieldValidator runat=server 
		               controltovalidate=adate
		               errormessage="日期不能为空.">*
       			 </asp:RequiredFieldValidator></td>
	            </tr>
	            </tr>
			  <tr>
			   <td nowrap>Reference (必填/唯一): </td>
			   <td><asp:TextBox id="aref" value = "" runat="server" /></td>
			   <td> <asp:RequiredFieldValidator runat=server 
			       controltovalidate=aref
			       errormessage="引用必须唯一.">*
				 </asp:RequiredFieldValidator></td>
			  <td> 
	            </tr>
	            <tr>
			  <td nowrap>Account Posted To: </td>
			  <td><asp:DropDownList DataTextField = "code_display"
			   DataValueField = "code_value" id="aposted_display" runat="server" /></td>
	            </tr>
			  <tr>
			   <td nowrap>Narration: </td>
			   <td><asp:TextBox id="anarr"  value = "" runat="server" /></td>
	            </tr>
	            </tr>
			  <tr>
			   <td nowrap>Deposit Amount: </td>
			   <td><asp:TextBox id="adr_amount" value = 0  runat="server" /></td>
	            </tr>
	            </tr>
			  <tr>
			   <td nowrap>Payment Amount: </td>
			   <td><asp:TextBox id="acr_amount" value = 0  runat="server" /></td>
	            </tr>
	              </td>
	              <td style="padding-top:15">
	              <asp:Button id="SubmitDetailsBtn" text="Submit" onclick="add_Click" runat="server" />
	              </td>
	            </tr>
	            </tr>
          </table>
        </asp:Panel>
         <!-------------插入逻辑 结束 -------->
        </td>
</table><hr>
<asp:Label id="Message" runat="server"/>  
</form>
</body>
</html>
