<%@ Register TagPrefix="Title" TagName="TitleShow" Src="/aspnetdata/Title.ascx" %>
<%@ Register TagPrefix="Toolbar" TagName="Bar" Src="Toolbar.ascx" %>
<%@ Register TagPrefix="NewDropDownlist" TagName="Drop" Src="Drop.ascx" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web" %>

<html>
<head>
	<script language="C#" runat="server">
	SqlConnection Source;
	int NowRecordP;//显示个数的全局变量
//	Dim GetNew as Boolean
	string d= "SELECT * from Product";
	void Page_load(Object sender, EventArgs e){
		Source = (SqlConnection)Session["NowSTKSQL"];
		if(IsPostBack==false){
			NowRecordP = 1;//取得第一个记录
			bindNew(true);
		}
	}
	void bindNew(Boolean tag){
		if(tag==true){
			DataSet DS = new DataSet();
			SqlDataAdapter NComm = new SqlDataAdapter(d, Source);
			SqlDataAdapter NComm1 = new SqlDataAdapter("SELECT * From Supplier order by SupID", Source);
			SqlDataAdapter NComm2 = new SqlDataAdapter("SELECT * From Category where CateType like '单位' order by CateID", Source);
			NComm.Fill(DS, "Product");
			NComm.Fill(DS, "ProductShow");
			DS.Tables["ProductShow"].Rows.Clear();
			NowBar.NowRecord=NowRecordP;
			NowBar.AllRecord=DS.Tables["Product"].Rows.Count;
			NowBar.NowSource=DS.Tables["Product"];
			NowBar.NowUseSource=DS.Tables["ProductShow"];
			NowBar.NowDataList="Product";
			NowBar.FirstUse=true;
			NowBar.NowStatus="查看记录";
			NowBar.ShowRecord(NowRecordP);
			Session["NowDSPro"]=DS;
		}
		else{//由Session取得记录
			DataSet NowDS = (DataSet)Session["NowDSE"];
			int k = NowBar.NowRecord;
			NowBar.ShowRecord(k);
		}
	}
	void Product_EditCommand(Object sender,DataListCommandEventArgs e){
		Product.EditItemIndex = e.Item.ItemIndex;
        	bindNew(false);
		NowBar.NowStatus="编辑记录";
	}
	void Product_DeleteCommand(Object sender, DataListCommandEventArgs e){
		Product.Items[0].FindControl("Sure").Visible=true;
		Product.Items[0].FindControl("Button5").Visible=true;
		Product.Items[0].FindControl("Button6").Visible=true;
	}
	void Product_CancelCommand(Object sender,DataListCommandEventArgs e){
		NowBar.NowStatus="查看记录";
		Product.EditItemIndex = -1;
		bindNew(false);
	}
	void Product_UpdateCommand(Object sender, DataListCommandEventArgs e){
		DataSet NowDS = (DataSet)Session["NowDSPRo"];
		string NowID = ((Label)Product.Items[0].FindControl("ProductID")).Text;
		SqlDataAdapter PDTCom = new SqlDataAdapter("Select * from Product where ProductID Like '" + NowID + "'", Source);
		PDTCom.Fill(NowDS,"NowProduct");
		NowDS.Tables["NowProduct"].Rows[0]["ProductName"]=((TextBox)Product.Items[0].FindControl("ProductName")).Text;
		SqlCommandBuilder custCB = new SqlCommandBuilder(PDTCom);
		PDTCom.Update(NowDS,"NowProduct");
		Product.EditItemIndex = -1;
		NowRecordP=NowBar.NowRecord;
		NowBar.NowStatus="查看记录";
		bindNew(true);
	}
	</script>
</head>
<body background="/aspnetdata/images/winback.gif">
<Title:TitleShow id="BookT" Runat="server" />
<form enctype="multipart/form-data" runat="server">
查看 <asp:hyperlink id="h1" NavigateUrl="/aspnetdata/shows.aspx?cate=c&file=ch12/12-2/cs/Toolbar.ascx" Text="Toolbar.ascx" runat="server" target="_blank"/><br>
<hr><Toolbar:Bar ID="NowBar" Runat="server" />
        <asp:DataList id="Product" runat="server"
            BorderColor="black"
            BorderWidth="0"
            GridLines="Both"
            CellPadding="3"
            CellSpacing="0"
            Font-Name="Verdana"
            Font-Size="10pt"
            RepeatColumns="1"
            RepeatDirection="Horizontal"
RepeatLayout="Table"
            Width="350px"
           HeaderStyle-BackColor="#C0FFFF"
            SelectedItemStyle-BackColor="#FFFFC0"
            DataKeyField="ProductID"
            OnEditCommand="Product_EditCommand"
            OnUpdateCommand="Product_UpdateCommand"
            OnCancelCommand="Product_CancelCommand"
            >
              <HeaderTemplate>
                产品基本资料
              </HeaderTemplate>
              <ItemTemplate>
                <asp:LinkButton id="button1" runat="server" Text="Edit" CommandName="edit" />
		<table border="1"><tr><td width="160">
		<asp:image width="130" Height="170" ImageURL='<%# DataBinder.Eval(Container.DataItem,"Photo") %>' id="img" Runat="server"/><br></td><td width="150">
                产品编号：<asp:Label id="ProductID1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ProductID")  %>' /><br>
                书籍名称：<%# DataBinder.Eval(Container.DataItem,"ProductName")  %><br>
                建议售价：<%# DataBinder.Eval(Container.DataItem,"PriceCus")  %><br>
                安全库存：<%# DataBinder.Eval(Container.DataItem,"StockSafe")  %><br>
                目前存量：<%# DataBinder.Eval(Container.DataItem,"StockCurrent")  %><br>
      </ItemTemplate>
             <EditItemTemplate>
<asp:LinkButton id="button3" runat="server" Text="Save" CommandName="Update" />
<asp:LinkButton id="button4" runat="server" Text="Cancel" CommandName="Cancel" /><br>
<table border="1"><tr><td width="160">
		照片：<br><asp:image width="130" Height="170" ImageURL='<%# DataBinder.Eval(Container.DataItem,"Photo") %>' id="img1" Runat="server"/><br></td><td width="150"></td><td width="175" align="left">
                产品编号：
                <asp:Label id="ProductID" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ProductID")  %>' /><br>
                产品名称：
                <asp:TextBox id="ProductName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ProductName")  %>' /><br>
		建议售价：
	 <asp:TextBox columns="6" id="PriceCus" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"PriceCus")  %>' /><br>
		安全库存：
	 <asp:TextBox columns="6" id="StockSafe" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"StockSafe")  %>' /><br>
		目前存量：
	 <asp:TextBox columns="6" id="StockCurrent" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"StockCurrent")  %>' /><br>
</td></tr>
</table>
              </EditItemTemplate>
        </asp:DataList>
</form>
</body>
