<asp:Label ID="Label7" runat="server" Text="ID Agent :"></asp:Label>
<asp:Label ID="Label8" runat="server" Text="Label"></asp:Label>
<br />
<div id="center">
<asp:Label ID="Label2" runat="server" Text="Motif de l'absence:"></asp:Label>
<asp:TextBox ID="Motif_AbsenceTextBox" runat="server"
ontextchanged="Motif_AbsenceTextBox_TextChanged"></asp:TextBox>
</div>
<br />
<table>
<tr>
<td class="style1">
<br />
<asp:Label ID="Label3" runat="server" Text="Date du début de l'absence:"></asp:Label>
<asp:TextBox ID="Début_AbsenceTextBox" runat="server"
ontextchanged="Début_AbsenceTextBox_TextChanged"></asp:TextBox>
<br />
<asp:calendar id="Calendar1" runat="server"
Width="290px" Height="171px" BackColor="White" BorderColor="#3366CC"
BorderWidth="1px" CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana"
Font-Size="8pt" ForeColor="#003399"
onselectionchanged="Calendar1_SelectionChanged"
ondayrender="Calendar1_DayRender">
<TodayDayStyle Font-Names="Arial" ForeColor="White" BackColor="#99CCCC"></TodayDayStyle>
<SelectorStyle BackColor="#99CCCC" ForeColor="#336666"></SelectorStyle>
<DayStyle Font-Names="Arial"></DayStyle>
<NextPrevStyle Font-Names="Arial" ForeColor="#CCCCFF" BorderColor="#000600"
Font-Size="8pt"></NextPrevStyle>
<DayHeaderStyle Font-Names="Arial" ForeColor="#336666" BorderColor="#006600"
BackColor="#99CCCC" Height="1px"></DayHeaderStyle>
<SelectedDayStyle Font-Names="Arial" BackColor="#009999" Font-Bold="True"
ForeColor="#CCFF99"></SelectedDayStyle>
<TitleStyle Font-Names="Arial" ForeColor="#CCCCFF" BorderColor="#3366CC"
BackColor="#003399" BorderWidth="1px" Font-Bold="True" Font-Size="10pt"
Height="25px"></TitleStyle>
<WeekendDayStyle Font-Names="Arial" BackColor="#CCCCFF"></WeekendDayStyle>
<OtherMonthDayStyle Font-Names="Arial" ForeColor="#999999" BorderColor="White"></OtherMonthDayStyle>
</asp:calendar>
</td>
<td>
<asp:Label ID="MessageLabel" runat="server"></asp:Label>
</td>
<td class="style1">
<br />
<asp:Label ID="Label4" runat="server" Text="Date de Fin de l'absence:"></asp:Label>
<asp:TextBox ID="Fin_AbsenceTextBox" runat="server"
ontextchanged="Fin_AbsenceTextBox_TextChanged" Height="22px"></asp:TextBox>
<br />
<asp:Calendar ID="Calendar2" runat="server" BackColor="White"
BorderColor="#3366CC" BorderWidth="1px" CellPadding="1"
DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt"
ForeColor="#003399" Height="171px"
onselectionchanged="Calendar2_SelectionChanged" Width="300px"
ondayrender="Calendar2_DayRender">
<DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" />
<NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
<TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px"
Font-Bold="True" Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" />
<TodayDayStyle BackColor="#99CCCC" ForeColor="White" />
<WeekendDayStyle BackColor="#CCCCFF" />
</asp:Calendar>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Labelcalendar1" runat="server" Text="Label"></asp:Label>
<asp:SqlDataSource ID="SqlGriedView1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
DeleteCommand="DELETE FROM [Absence] WHERE [ID_Absence] = @ID_Absence"
InsertCommand="INSERT INTO [Absence] ([ID_Absence], [Matricule_Agent], [Motif_Absence], [Debut_Absence], [Fin_Absence]) VALUES (@ID_Absence, @Matricule_Agent, @Motif_Absence, @Debut_Absence, @Fin_Absence)"
SelectCommand="SELECT * FROM [Absence] WHERE ([Matricule_Agent] = @Matricule_Agent)"
UpdateCommand="UPDATE [Absence] SET [Matricule_Agent] = @Matricule_Agent, [Motif_Absence] = @Motif_Absence, [Debut_Absence] = @Debut_Absence, [Fin_Absence] = @Fin_Absence WHERE [ID_Absence] = @ID_Absence">
<DeleteParameters>
<asp:Parameter Name="ID_Absence" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="ID_Absence" Type="Int32" />
<asp:Parameter Name="Matricule_Agent" Type="String" />
<asp:Parameter Name="Motif_Absence" Type="String" />
<asp:Parameter DbType="Date" Name="Debut_Absence" />
<asp:Parameter DbType="Date" Name="Fin_Absence" />
</InsertParameters>
<SelectParameters>
<asp:SessionParameter Name="Matricule_Agent" SessionField="Matricule_Agent"
Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Matricule_Agent" Type="String" />
<asp:Parameter Name="Motif_Absence" Type="String" />
<asp:Parameter Name="Debut_Absence" DbType="Date" />
<asp:Parameter Name="Fin_Absence" DbType="Date" />
<asp:Parameter Name="ID_Absence" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="Sql" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [Absence]">
</asp:SqlDataSource>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID_Absence" DataSourceID="Sql" Height="16px" Width="16px">
<Columns>
<asp:BoundField DataField="ID_Absence" HeaderText="ID_Absence" ReadOnly="True"
SortExpression="ID_Absence" Visible="False" />
<asp:BoundField DataField="Matricule_Agent" HeaderText="Matricule_Agent"
SortExpression="Matricule_Agent" Visible="False" />
<asp:BoundField DataField="Motif_Absence" HeaderText="Motif_Absence"
SortExpression="Motif_Absence" Visible="False" />
<asp:BoundField DataField="Debut_Absence" HeaderText="Debut_Absence"
SortExpression="Debut_Absence" Visible="False" />
<asp:BoundField DataField="Fin_Absence" HeaderText="Fin_Absence"
SortExpression="Fin_Absence" Visible="False" />
</Columns>
</asp:GridView>
</td>
<td class="style1">
<asp:Button ID="Btn_Send" runat="server" Text="Envoyer" onclick="btn_Send_Click" />
<asp:Button ID="Btn_Raz" runat="server" Text="RAZ" onclick="Btn_Raz_Click" />
</td>
<td>
<asp:Label ID="Labelcalendar2" runat="server" Text="Label"></asp:Label>
</td>
</tr>
</table>
Code Behind c# pour le bouton send
protected void btn_Send_Click(object sender, EventArgs e)
{
if ((Motif_AbsenceTextBox.Text.Trim().Length == 0) || (Début_AbsenceTextBox.Text.Trim().Length == 0) || (Fin_AbsenceTextBox.Text.Trim().Length == 0))
{
MessageLabel.Text =
"Nous ne pouvons pas créé cette absence car tout les champs ne sont pas remplis";
return;
}
else
{
if ((Labelcalendar1.Text.Length > 40) || (Labelcalendar2.Text.Length > 40))
{
MessageLabel.Text =
"Nous ne pouvons pas créé cette absence car les dates selectionnées ne sont pas valide!";
return;
}
else
{
string sqlStmt;
string ConnectionString;
SqlConnection cn = null;
try
{
sqlStmt = "INSERT INTO [Absence] ([Matricule_Agent], [Motif_Absence], [Debut_Absence], [Fin_Absence]) VALUES (@Matricule_Agent, @Motif_Absence, @Debut_Absence, @Fin_Absence)";
ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Absence.mdf;Integrated Security=True;User Instance=True";
cn = new SqlConnection(ConnectionString);
SqlCommand command = new SqlCommand(sqlStmt, cn);
command.Parameters.Add("@Matricule_Agent", SqlDbType.NVarChar, 40);
command.Parameters.Add("@Motif_Absence", SqlDbType.Text, 40);
command.Parameters.Add("@Debut_Absence", SqlDbType.Date, 10);
command.Parameters.Add("@Fin_Absence", SqlDbType.Date, 10);
command.Parameters["@Matricule_Agent"].Value = Label8.Text;
command.Parameters["@Motif_Absence"].Value = Motif_AbsenceTextBox.Text;
command.Parameters["@Debut_Absence"].Value = DateTime.Parse(Début_AbsenceTextBox.Text);
command.Parameters["@Fin_Absence"].Value = DateTime.Parse(Fin_AbsenceTextBox.Text);
cn.Open();
command.ExecuteNonQuery();
MessageLabel.Text = "L'ajout de la ligne a été exécuté avec succès!";
}
catch (Exception ex)
{
MessageLabel.Text = "Problème dans l'ajout de la nouvelle absence! || erreur :" + ex.Message;
}
finally
{
cn.Close();
}
SqlGriedView1.DataBind();
Response.AppendHeader("Refresh", "1");
}
}
}
on est venu , on a vu et on l'a eu dans le cul.
