Hi
i want to ask how to make a range data between selected month.
Example (2 -5) month to search data about my staff leave data.
C#
public partial class Op_UserApplyLeaveList : System.Web.UI.Page
{
protected void ibSearch_Click(object sender, ImageClickEventArgs e)
{
string message,
id = Session["ID"].ToString();
if (ddlSearch.SelectedIndex == 0)
{
if (Regex.IsMatch(tbSearch.Text, "[0-9]"))
{
sqlUsers.SelectCommand = "SELECT a.leaveId , p.Id, p.Name, a.start, a.end, a.total, a.dateapply, a.Type, a.Status " +
" FROM profile as p INNER JOIN " +
" leaveapp as a On a.Id = p.Id " +
" Where a.leaveId='" + tbSearch.Text.Trim() + "' " +
" ORDER BY a.leaveId DESC";
gvTranList.DataBind();
}
else
{
message = "Please enter ID number!";
string returnUrl = "UserApplyLeaveList.aspx";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "<script type = 'text/javascript'>" +
}
}
if (ddlSearch.SelectedIndex == 1)
{
if (Regex.IsMatch(tbSearch.Text, "[0-9]"))
{
sqlUsers.SelectCommand = "SELECT a.leaveId , p.Id, p.Name, a.start, a.end, a.total, a.dateapply, a.Type, a.Status " +
" FROM profile as p INNER JOIN " +
" leaveapp as a On a.Id = p.Id " +
" Where p.Id='" + tbSearch.Text.Trim() + "' " +
" ORDER BY a.leaveId DESC";
gvTranList.DataBind();
}
else
{
message = "Please enter Staf I/C!";
string returnUrl = "UserApplyLeaveList.aspx";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "<script type = 'text/javascript'>" +
}
}
if (ddlSearch.SelectedIndex == 2)
{
if (Regex.IsMatch(tbSearch.Text, "[0-9]"))
{
sqlUsers.SelectCommand = "SELECT a.leaveId , p.Id, p.Name, a.start, a.end, a.total, a.dateapply, a.Type, a.Status " +
" FROM profile as p INNER JOIN " +
" leaveapp as a On a.Id = p.Id " +
" Where Year(a.start) >= '" + tbSearch.Text.Trim() + "' " +
" and Year(a.end) <= '" + tbSearch.Text.Trim() + "' " +
" ORDER BY a.start DESC";
gvTranList.DataBind();
}
else
{
message = "Please enter year!";
string returnUrl = "UserApplyLeaveList.aspx";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "<script type = 'text/javascript'>" +
}
}
if (ddlSearch.SelectedIndex == 3)
{
if (tbSearch.Text != "")
{
sqlUsers.SelectCommand = "SELECT a.leaveId , p.Id, p.Name, a.start, a.end, a.total, a.dateapply, a.Type, a.Status " +
" FROM profile as p INNER JOIN " +
" leaveapp as a On a.Id = p.Id " +
" Where Month(a.start) >= '" + tbSearch.Text.Trim() + "' " +
" and Month(a.end) <= '" + tbSearch.Text.Trim() + "' " +
" ORDER BY a.start DESC";
gvTranList.DataBind();
}
else
{
message = "Please enter month!";
string returnUrl = "UserApplyLeaveList.aspx";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "<script type = 'text/javascript'>" +
}
}
if (ddlSearch.SelectedIndex == 4)
{
if (tbSearch.Text != "")
{
sqlUsers.SelectCommand = "SELECT a.leaveId , p.Id, p.Name, a.start, a.end, a.total, a.dateapply, a.Type, a.Status " +
" FROM profile as p INNER JOIN " +
" leaveapp as a On a.Id = p.Id " +
" Where a.Type='" + tbSearch.Text.Trim() + "' " +
" ORDER BY a.leaveId DESC";
gvTranList.DataBind();
}
else
{
message = "Please enter Type Leave!";
string returnUrl = "UserApplyLeaveList.aspx";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "<script type = 'text/javascript'>" +
}
}
}