Attendance Project : When i pressed mark attendance saved many times i want only everyday attendance please solve this send code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Reflection.Emit;
public partial class Attendance : System.Web.UI.Page
{
string strcon = ConfigurationManager.ConnectionStrings["rkcomputers"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
DateTime utcNow = DateTime.UtcNow;
TimeZoneInfo indiaTimeZone = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
DateTime indiaTime = TimeZoneInfo.ConvertTimeFromUtc(utcNow, indiaTimeZone);
Label1.Text = indiaTime.ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (checkstudentexist())
{
Response.Write("<script>alert('Already Student Attendance SAVED for TODAY...');</script>");
}
//else if (checkstudentexist() == (checkstudentexist11to12()))
// {
// Response.Write("<script>alert('Attendance Already Completed');</script>");
// }
else
{
studentattendance();
Response.Write("<script>alert('Student Attendance SAVED for TODAY...');</script>");
}
//ScriptManager.RegisterStartupScript(this, this.GetType(), "Redit", "window.location='" + Request.ApplicationPath + "regform.aspx';", true);
}
private void saveattendance(int admissionno, string studentname, string dateofclass1, string status, string sclass)
{
string query = " insert into StudentAttendance(admissionno,studentname,dateofclass,attendancestatus,class) values(" + admissionno + ",'" + studentname + "','" + dateofclass1 + "', '" + status + "','" + sclass + "')";
SqlConnection con = new SqlConnection(strcon);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = query;
cmd.Connection = con;
cmd.ExecuteNonQuery();
}
bool checkstudentexist()
{
try
{
SqlConnection con = new SqlConnection(strcon);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("SELECT* from StudentAttendance where dateofclass = '" + Label1.Text + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count >= 1)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "');</script>");
return false;
}
}
void studentattendance()
{
try
{
foreach (GridViewRow row in GridView1.Rows)
{
int admissionno1 = Convert.ToInt32(row.Cells[0].Text);
string studentname1 = row.Cells[1].Text;
RadioButton rbtn1 = (row.Cells[2].FindControl("RadioButton1") as RadioButton);
RadioButton rbtn2 = (row.Cells[2].FindControl("RadioButton2") as RadioButton);
string status1;
if (rbtn1.Checked)
{
status1 = "Present";
}
else
{
status1 = "Absent";
}
DateTime utcNow = DateTime.UtcNow;
TimeZoneInfo indiaTimeZone = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
DateTime indiaTime = TimeZoneInfo.ConvertTimeFromUtc(utcNow, indiaTimeZone);
string dateofclass1 = indiaTime.ToString();
string sclass1 = DropDownList1.SelectedItem.Text;
saveattendance(admissionno1, studentname1, dateofclass1, status1, sclass1);
//Label2.Text = "Attendance HAVE Been Completed...";
}
}
catch (Exception Ex)
{
// Response.Write("<script>alert('" + ex.Message + "');</script>");
}
}
}