<%@Page Debug=True %>
<%@ Register TagPrefix="stime" TagName="select" Src="Stime.ascx" %>
<%@ Register TagPrefix="Title" TagName="TitleShow" Src="/aspnetdata/Title.ascx" %>
<%@ Register TagPrefix="Drop" TagName="Dropdown" Src="Drop.ascx" %>
<%@ Register TagPrefix="Cal" TagName="Calendar" Src="cal.ascx" %>
<%@ 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 k as string ="SELECT Staff.cname, OverTime.sid, OverTime.id, OverTime.Odate, OverTime.StartTime, OverTime.EndTime FROM Staff INNER JOIN OverTime ON Staff.SID = OverTime.sid"
	sub Page_load(sender as object,e as EventArgs)
		Source = Ctype(Session("NowEMPSQL"),SqlConnection)
		if IsPostBack=false then
			bindNew(true)
		end if
	end sub
	sub bindNew(tag as Boolean)
'		ErrorSave.Text=""
		if tag = true then
			Dim DS as DataSet = new DataSet()
			Dim NComm as SqlDataAdapter = new SqlDataAdapter(k, Source)
			NComm.Fill(DS, "Overs")
			Session("NowOTime")=DS'声明为Session
			Otime.DataSource=DS.Tables("Overs").DefaultView
			Otime.DataBind()
		else
			Dim DS as DataSet = Ctype(Session("NowOTime"),DataSet)
			Otime.DataSource=DS.Tables("Overs").DefaultView
			Otime.DataBind()
		end if
	end sub
	sub Otime_Update(sender as object, e as DataGridCommandEventArgs)
		dim u as string=Otime.DataKeys(Otime.EditItemIndex).ToString()
		dim x as ASP.Drop_ascx
		x=Ctype(Otime.Items(Otime.EditItemIndex).Cells(1).FindControl("sid"),ASP.Drop_ascx)
		Dim y as ASP.Cal_ascx
		y=Ctype(Otime.Items(Otime.EditItemIndex).Cells(2).FindControl("ODate"),ASP.Cal_ascx)
		Dim z1 as ASP.Stime_ascx
		z1=Ctype(Otime.Items(Otime.EditItemIndex).Cells(3).FindControl("StartTime"),ASP.Stime_ascx)
		Dim z2 as ASP.Stime_ascx
		z2=Ctype(Otime.Items(Otime.EditItemIndex).Cells(4).FindControl("EndTime"),ASP.Stime_ascx)
		Dim STime as DateTime =Convert.ToDateTime(y.NowDate + " " + z1.NowTime + ":00")
		Dim ETime as DateTime =Convert.ToDateTime(y.NowDate + " " + z2.NowTime + ":00")
		Dim NowID as Label = Ctype(e.Item.FindControl("OrderIDV"),Label)
		Dim w as string = "Update OverTime set"
		w += " ODate ='" & y.NowDate & "', sid ='" & x.GetNowSelect & "'"
		w += ", StartTime='" & STime.ToString("yyyy/MM/dd HH:mm:ss") & "',EndTime ='" & ETime.ToString("yyyy/MM/dd HH:mm:ss") & "'"
		w += " where id =" & u 
		try
			Dim UpOtime as SqlCommand =new SqlCommand(w,Source)
			UpOtime.Connection.Open()
			UpOtime.ExecuteNonQuery()'执行保存
			UpOtime.Connection.Close()
			Otime.EditItemIndex = -1
			bindNew(true)
		catch
			ErrorMsg.Text="保存时发生错误"
		end try
	end sub
	sub Otime_Cancel(sender as object,e as DataGridCommandEventArgs)
		Otime.EditItemIndex = -1' '取消
		Otime.SelectedIndex = -1
		bindNew(false)
	end sub
	sub Otime_Edit(sender as object,e as DataGridCommandEventArgs)
		Dim p as Label =Ctype(Otime.Items(e.Item.ItemIndex).Cells(1).FindControl("sidv"),Label)
		dim h as string =p.Text
		Otime.EditItemIndex = e.Item.ItemIndex
		Otime.SelectedIndex=e.Item.ItemIndex
		bindNew(false)
		Dim x as ASP.Drop_ascx
		x=Ctype(Otime.Items(Otime.EditItemIndex).FindControl("sid"),ASP.Drop_ascx)
		x.Sname="Select * from staff"
		x.TextField="cname"
		x.ValueField="sid"
		x.CompareValue=h
		x.SessionName="NowEMPSQL"
		x.CompareField="sid"
		x.Show()
	end sub
	</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">
查看 <asp:hyperlink id="h1" NavigateUrl="/aspnetdata/shows.aspx?cate=c&file=ch12/12-2/vb/Drop.ascx" Text="Drop.ascx" runat="server" target="_blank"/>、
<asp:hyperlink id="h2" NavigateUrl="/aspnetdata/shows.aspx?cate=c&file=ch12/12-2/vb/Cal.ascx" Text="Cal.ascx" runat="server" target="_blank"/>、
<asp:hyperlink id="h3" NavigateUrl="/aspnetdata/shows.aspx?cate=c&file=ch12/12-2/vb/Stime.ascx" Text="Stime.ascx" runat="server" target="_blank"/><br>
      <ASP:DataGrid id="Otime" runat="server"
        BorderColor="black"
        BorderWidth="1"
        GridLines="Both"
        CellPadding="3"
        CellSpacing="0"
        Font-Name="Verdana"
        Font-Size="10pt"
        HeaderStyle-BackColor="GreenYellow"
AlternatingItemStyle-BackColor="LightYellow"
SelectedItemStyle-BackColor="LightCyan"
SelectedItemStyle-Font-Bold="true"
DataKeyField="id"
AutoGenerateColumns="false"
      OnEditCommand="Otime_Edit"
      OnCancelCommand="Otime_Cancel"
      OnUpdateCommand="Otime_Update"
>
      <Columns>
        <asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Save" ItemStyle-Wrap="false"/>
<asp:TemplateColumn HeaderText="人员姓名" >
          <ItemTemplate>
<asp:Label runat="server" Text=<%# DataBinder.Eval(Container.DataItem, "cname") %> id="cname"/>
<asp:Label runat="server" Text=<%# DataBinder.Eval(Container.DataItem, "sid") %> id="sidv"/>
          </ItemTemplate>
          <EditItemTemplate>
            <Drop:Dropdown runat="server" id="sid" />
          </EditItemTemplate>
        </asp:TemplateColumn>
<asp:TemplateColumn HeaderText="加班日" >
          <ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Odate","{0:yyyy/MM/dd}") %>' id="Odate1"/>
          </ItemTemplate>
          <EditItemTemplate>
<Cal:Calendar ID="ODate" NowDate=<%# DataBinder.Eval(Container.DataItem, "Odate","{0:yyyy/MM/dd}") %> runat="server" />
          </EditItemTemplate>
        </asp:TemplateColumn>
<asp:TemplateColumn HeaderText="开始时间" >
          <ItemTemplate>
<asp:Label runat="server" Text=<%# DataBinder.Eval(Container.DataItem, "StartTime","{0:HH:mm}") %> id="StartTime1"/>
          </ItemTemplate>
          <editItemTemplate>
<stime:select id="StartTime" runat="server" NowTime='<%# DataBinder.Eval(Container.DataItem,"StartTime","{0:HH:mm}")  %>' />
          </EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="结束时间" >
          <ItemTemplate>
<asp:Label runat="server" Enabled="False" Text=<%# DataBinder.Eval(Container.DataItem, "EndTime","{0:HH:mm}") %> id="Taxl"/>
          </ItemTemplate>
          <editItemTemplate>
<stime:select id="EndTime" runat="server" NowTime='<%# DataBinder.Eval(Container.DataItem,"EndTime","{0:HH:mm}")  %>' />
          </EditItemTemplate>
        </asp:TemplateColumn>
      </Columns>
</ASP:DataGrid>
<asp:Label ID="ErrorMsg" Tooltip="ErrorFile" Runat="server" />
</form>