<%@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="C#" runat="server">
	SqlConnection Source;
	string k="SELECT Staff.cname, OverTime.sid, OverTime.id, OverTime.Odate, OverTime.StartTime, OverTime.EndTime FROM Staff INNER JOIN OverTime ON Staff.SID = OverTime.sid";
	void Page_load(object sender, EventArgs e){
		Source = (SqlConnection)Session["NowEMPSQL"];
		if(IsPostBack==false){
			bindNew(true);
		}
	}
	void bindNew(Boolean tag){
//		ErrorSave.Text="";
		if(tag == true){
			DataSet DS = new DataSet();
			SqlDataAdapter NComm = new SqlDataAdapter(k, Source);
			NComm.Fill(DS, "Overs");
			Session["NowOTime"]=DS;//声明为Session
			Otime.DataSource=DS.Tables["Overs"].DefaultView;
			Otime.DataBind();
		}
		else{
			DataSet DS = (DataSet)Session["NowOTime"];
			Otime.DataSource=DS.Tables["Overs"].DefaultView;
			Otime.DataBind();
		}
	}
	void Otime_Update(object sender, DataGridCommandEventArgs e){
		string u=Otime.DataKeys[Otime.EditItemIndex].ToString();
		ASP.Drop_ascx x;
		x=(ASP.Drop_ascx)Otime.Items[Otime.EditItemIndex].Cells[1].FindControl("sid");
		ASP.Cal_ascx y;
		y=(ASP.Cal_ascx)Otime.Items[Otime.EditItemIndex].Cells[2].FindControl("ODate");
		ASP.Stime_ascx z1;
		z1=(ASP.Stime_ascx)Otime.Items[Otime.EditItemIndex].Cells[3].FindControl("StartTime");
		ASP.Stime_ascx z2;
		z2=(ASP.Stime_ascx)Otime.Items[Otime.EditItemIndex].Cells[4].FindControl("EndTime");
		DateTime STime=Convert.ToDateTime(y.NowDate + " " + z1.NowTime + ":00");
		DateTime ETime=Convert.ToDateTime(y.NowDate + " " + z2.NowTime + ":00");
		Label NowID = (Label)e.Item.FindControl("OrderIDV");
		string w = "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{
			SqlCommand UpOtime=new SqlCommand(w,Source);
			UpOtime.Connection.Open();
			UpOtime.ExecuteNonQuery();//执行保存
			UpOtime.Connection.Close();
			Otime.EditItemIndex = -1;
			bindNew(true);
		}
		catch{
			ErrorMsg.Text="保存时发生错误";
		}
	}
	void Otime_Cancel(object sender, DataGridCommandEventArgs e){
		Otime.EditItemIndex = -1;// '取消
		Otime.SelectedIndex = -1;
		bindNew(false);
	}
	void Otime_Edit(object sender, DataGridCommandEventArgs e){
		Label p=(Label)Otime.Items[e.Item.ItemIndex].Cells[1].FindControl("sidv");
		string h=p.Text;
		Otime.EditItemIndex = e.Item.ItemIndex;
		Otime.SelectedIndex=e.Item.ItemIndex;
		bindNew(false);
		ASP.Drop_ascx x;
		x=(ASP.Drop_ascx)Otime.Items[Otime.EditItemIndex].FindControl("sid");
		x.Sname="Select * from staff";
		x.TextField="cname";
		x.ValueField="sid";
		x.CompareValue=h;
		x.SessionName="NowEMPSQL";
		x.CompareField="sid";
		x.Show();
	}
	</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/cs/Drop.ascx" Text="Drop.ascx" runat="server" target="_blank"/>、
<asp:hyperlink id="h2" NavigateUrl="/aspnetdata/shows.aspx?cate=c&file=ch12/12-2/cs/Cal.ascx" Text="Cal.ascx" runat="server" target="_blank"/>、
<asp:hyperlink id="h3" NavigateUrl="/aspnetdata/shows.aspx?cate=c&file=ch12/12-2/cs/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>