<%@Page Language="VB" Inherits="BaseClass" Src="StockTrans.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 qty_in As String 
	Dim qty_out As String 
	Dim id As String 
	Dim narr As String 
	Dim myTextBox    As TextBox
	'This is the key value : 
	'Retrieved from the DataKey, since it's a read only field
	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_qty_in")
	qty_in = trim(mytextbox.text)
	myTextBox = E.Item.FindControl("edit_qty_out")
	qty_out = trim(mytextbox.text)
	myTextBox = E.Item.FindControl("edit_narr")
	narr = trim(mytextbox.text)
	myTextBox = E.Item.FindControl("edit_code_value")
	code_value = trim(mytextbox.text)
	'Now execute stored procedure 
	sql = "Execute p_stock_trans @date = '" 
	sql = sql + vdate + "' ,@ref= '" + ref + "', @qty_in =" 
	sql = sql + qty_in + ",@qty_out = "+ qty_out +" , " 
	sql = sql + "@id = 'STK', @doc_no = "+doc_no+", @narr= '"+narr+ "',"
	sql = sql +  "@code_value=" + code_value
	'response.write(sql)
	RunSql(sql)
	rebind() 
End Sub
Sub add_click(Source As Object, E As EventArgs) 
	dim sql as string  
	sql = "Execute p_stock_trans @date = '" 
	sql = sql+ adate.text+"',@ref= '"+aref.text+"', @qty_in =" 
	sql = sql+ aqty_in.text+",@qty_out = "+aqty_out.text+" ,"
	sql = sql+ "@id = 'RPT', @doc_no = NULL"+", @narr= '" 
	sql = sql+ anarr.text+"', @code_value = "+acode_value.SelectedItem.value 
	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 stock_detail 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">
<asp:ValidationSummary runat=server
headertext="There were errors on the page:" />
<form runat="server">
<!---- Navigation Start-------------->
       <Hersh:nav id="menu" runat = server 
       vGridlines = Both
       vBorderColor = "Black"
       vCellPadding = 7 />
<!---- Navigation Ends-------------->
<h3><font face="Verdana"> Inventory Movements
<asp:Label id="title" runat="server"/>  </font></h3>
<table width="95%">
<tr><td>
<asp:Button id="Addshow" visible = "false" text="New Tranaction" 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="Edit"
CancelText="Cancel"
UpdateText="OK"
ItemStyle-Wrap="false"
HeaderText="Edit"
HeaderStyle-Wrap="false"/>
<asp:ButtonColumn Text="Delete" CommandName="Delete" 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="Date" >
	 <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="Inventory Account" >
	<ItemTemplate>
	<asp:Label Text='<%# Container.DataItem("code_display") %>' runat="server"/>
	</ItemTemplate>
	<EditItemTemplate>
	<asp:TextBox id="edit_code_value"  Text='<%# Container.DataItem("code_value") %>'
	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="Quantity In" >
	<ItemTemplate>
	<asp:Label Text='<%# Container.DataItem("qty_in") %>' runat="server"/>
	</ItemTemplate>
	<EditItemTemplate>
	<asp:TextBox id="edit_qty_in"   Text='<%# Container.DataItem("qty_in") %>'
	runat="server"/>
	</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Quantity Out" >
	<ItemTemplate>
	<asp:Label Text='<%# Container.DataItem("qty_out") %>' runat="server"/>
	</ItemTemplate>
	<EditItemTemplate>
	<asp:TextBox id="edit_qty_out"  Text='<%# Container.DataItem("qty_out") %>'
	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">
<!---- insert row logic-------------->
<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 (Required): </td>
		<td><asp:TextBox id="adate"  runat="server" value = ""  /></td>
		<td> <asp:RequiredFieldValidator runat=server 
		controltovalidate=adate
		errormessage="Date is required.">*
		</asp:RequiredFieldValidator></td>
	</tr>
	<tr>
		<td nowrap>Reference (Required/ must be unique): </td>
		<td><asp:TextBox id="aref" value = "" runat="server" /></td>
		<td> <asp:RequiredFieldValidator runat=server 
		controltovalidate=aref
		errormessage="A unique reference # is required.">*
		 </asp:RequiredFieldValidator></td>
	</tr>
	<tr>
		<td nowrap>Account Posted To: </td>
		<td><asp:DropDownList DataTextField = "code_display"
		DataValueField = "code_value" id="acode_value" runat="server" /></td>
	</tr>
	<tr>
		<td nowrap>Narration: </td>
		<td><asp:TextBox id="anarr"  value = "" runat="server" /></td>
	</tr>
	<tr>
		<td nowrap>Quantity In: </td>
		<td><asp:TextBox id="aqty_in" value = 0  runat="server" /></td>
	</tr>
	<tr>
		<td nowrap>Quantity Out: </td>
		<td><asp:TextBox id="aqty_out" value = 0  runat="server" /></td>
	</tr>
	<tr>
		<td style="padding-top:15">
		<asp:Button id="SubmitDetailsBtn" text="Submit" onclick="add_Click" runat="server" />
		</td>
	</tr>

	  </table>
</asp:Panel>
<!-------------Insert Logic ends -------->
</td>
</table>
<hr>
     <asp:Label id="Message" runat="server"/>  
  </form>
</body>
</html>
