<%@Page Language="VB" Inherits="BaseClass" Src="stockmasters.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 code_display As String 
      Dim rate As String 
      Dim uom As String 
      Dim opening As String 
      Dim closing As String 
      Dim myTextBox As TextBox
      '主键:
      '只读区
      Dim code_value As string = Grid1.DataKeys.Item(E.Item.ItemIndex).ToString
      myTextBox = E.Item.FindControl("edit_name")
      code_display = mytextbox.text
      myTextBox = E.Item.FindControl("edit_rate")
      rate = mytextbox.text
      myTextBox = E.Item.FindControl("edit_uom")
      uom = mytextbox.text
      myTextBox = E.Item.FindControl("edit_opening")
      opening = mytextbox.text
      myTextBox = E.Item.FindControl("edit_closing")
      closing = mytextbox.text
      '执行存储过程
      sql = "Execute p_Stock_master @code_value =" 
      sql = sql+code_value+", @code_display = '"+code_display+"',@rate=" 
      sql = sql+rate+", @uom='"+uom +"' ,@opening ="+opening+",@closing="+closing
      RunSql(sql)
    End Sub
    Sub add_click(Source As Object, E As EventArgs) 
      Dim sql As string  
      if acode_display.text = ""  then
        response.write("信息不完全")
        exit sub
      end if
      SQL = "Execute p_stock_master @code_value=NULL,@code_display='" 
      SQL = SQL+ acode_display.text + "',@rate=" 
      SQL = SQL+arate.Text+",@uom="+auom.text+",@opening="+aopening.text 
      RunSql(sql) 
      '重新设定值
      acode_display.text = ""
      aopening.text  = ""
      arate.text = ""
      auom.text = ""
      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 code_value As string = Grid1.DataKeys.Item(E.Item.ItemIndex).ToString
      Dim sql As string
      sql = "Delete from stock_master where code_value = " + cstr(code_value)
      RunSql(sql)
    End Sub
    Sub MyDataGrid_Page(sender As Object, e As DataGridPageChangedEventArgs)
      Grid1.CurrentPageIndex = e.NewPageIndex
      ReBind
    End Sub
    Sub MyDataGrid_Sort(sender As Object, e As DataGridSortCommandEventArgs)
      SortField = e.SortExpression
      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">Inventory Masters </font></h3>
      <asp:Label id="Message" runat="server"/>
      <asp:Button id="Addshow" text="添加记录" onclick="add_show" runat="server" />
      <table width="95%">
        <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="code_value"
              AllowPaging="True"
              PageSize="20"
              PagerStyle-Mode="NumericPages"
              PagerStyle-HorizontalAlign="Right"
              PagerStyle-NextPageText="Next"
              PagerStyle-PrevPageText="Prev"
              OnPageIndexChanged="MyDataGrid_Page"
              AllowSorting="true"
              OnSortCommand="MyDataGrid_Sort">
              <Columns>
                <asp:EditCommandColumn
                  EditText="编辑"
                  CancelText="取消"
                  UpdateText="确定"
                  ItemStyle-Wrap="false"
                  HeaderText="编辑"
                  HeaderStyle-Wrap="false"/>
                <asp:ButtonColumn Text="Delete" CommandName="删除" 
                  HeaderText="删除"/>
                <asp:BoundColumn HeaderText="Account #"  ReadOnly="true"
                  DataField="code_value" SortExpression="code_value" />
                <asp:TemplateColumn HeaderText="Name" 
                  SortExpression="code_display">
                <ItemTemplate>
                  <asp:Label Text='<%# Container.DataItem("code_display") %>'
                    runat="server"/>
                </ItemTemplate>
                <EditItemTemplate>
                  <asp:RequiredFieldValidator runat=server 
                    controltovalidate=edit_Name
                    errormessage="姓名不能为空.">*
                  </asp:RequiredFieldValidator>
                  <asp:TextBox id="edit_name" 
                    Text='<%# Container.DataItem("code_display") %>'
                    runat="server"/>
                </EditItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="Rate" SortExpression="rate"   >
                <ItemTemplate>
                  <asp:Label Text='<%# Container.DataItem("rate") %>' runat="server" />
                </ItemTemplate>
                <EditItemTemplate>
                  <asp:TextBox id="edit_rate"   Text='<%# Container.DataItem("rate") %>'
                  runat="server"/>
                </EditItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="uom" SortExpression="uom"   >
                <ItemTemplate>
                  <asp:Label Text='<%# Container.DataItem("uom") %>' runat="server"/>
                </ItemTemplate>
                <EditItemTemplate>
                  <asp:TextBox id="edit_uom" Text='<%# Container.DataItem("uom") %>'
                  runat="server"/>
                </EditItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="Opening" >
                <ItemTemplate>
                  <asp:Label Text='<%# Container.DataItem("opening") %>' runat="server"/>
                </ItemTemplate>
                <EditItemTemplate>
                  <asp:TextBox id="edit_opening" 
                  Text='<%# Container.DataItem("opening") %>'
                  runat="server"/> 
                </EditItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="Closing" >
                <ItemTemplate>
                  <asp:Label Text='<%# Container.DataItem("closing") %>' 
                    runat="server"/>
                </ItemTemplate>
                <EditItemTemplate>
                  <asp:TextBox id="edit_closing" BorderStyle="None" Readonly="True"
                    Text='<%# Container.DataItem("closing") %>'
                    runat="server"/>
                  </EditItemTemplate>
                </asp:TemplateColumn>
              </Columns>
              <HeaderStyle BackColor="Gray" 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">
                  添加一个新记录:</td>
                </tr>
                <tr>
                  <td nowrap>Name: </td>
                  <td><asp:TextBox id="acode_display" runat="server" /></td>
                  <td> <asp:RequiredFieldValidator runat=server 
                      controltovalidate=acode_display
                      errormessage="姓名不能为空.">*
                    </asp:RequiredFieldValidator></td>
                </tr>
                <tr>
                  <td nowrap>Rate: </td>
                  <td><asp:TextBox id="arate" value = "0" runat="server" /></td>
                </tr>
                <tr>
                  <td nowrap>Unit: </td>
                  <td><asp:TextBox id="auom" value = "pcs" runat="server" /></td>
                </tr>
                <tr>
                  <td nowrap>Opening Value: </td>
                  <td><asp:TextBox id="aopening" value = "0" runat="server" /></td>
                </tr>
                <tr>
                  <td style="padding-top:15">
                    <asp:Button id="SubmitDetailsBtn" text="提交" 
                      onclick="add_Click" runat="server" />
                  </td>
                </tr>
              </table>
            </asp:Panel>
            <!-------------插入逻辑 结束 -------->
          </td>
        </tr>
      </table>
    </form>
  </body>
</html>
