private void GetGuardian() { using (SampleDataContext dbContext = new SampleDataContext()) { dbContext.guardians.ToList(); } }
protected int GetRowCount() { using (SampleDataContext db = new SampleDataContext()) { return(db.students.Count()); } }
//enables te add guardian button and disables the view guardian button if guardian already exists for the 'i' student and viceversa private void RowWork() { if (GridView1.DataSource != null) { using (SampleDataContext context = new SampleDataContext()) { for (int i = 0; i < GridView1.Rows.Count; i++) { LinkButton lb_add = (LinkButton)GridView1.Rows[i].FindControl("AddGuardian"); int id = Convert.ToInt32(lb_add.CommandArgument); LinkButton lb_view = (LinkButton)GridView1.Rows[i].FindControl("ViewSingleGuardian"); guardian g_check = context.guardians.Where(x => x.std_id == id).SingleOrDefault(); if (g_check != null) { lb_add.Enabled = false; lb_view.Enabled = true; } else { lb_add.Enabled = true; lb_view.Enabled = false; } } } } }
private void Update(int id) { using (SampleDataContext context = new SampleDataContext()) { guardian g = context.guardians.Where(x => x.id == id).SingleOrDefault(); int s_id = Convert.ToInt32(txtStd_id.Text); if (context.students.Where(x => x.std_id == s_id).Single() != null) { g.g_Fname = txtFname.Text; g.g_Lname = txtLname.Text; g.g_Address = txtAddress.Text; g.std_id = s_id; context.SubmitChanges(); GetData(); Clear(); } else { Response.Write("<script>alert('Student ID Not Found!!')</script>"); } } }
private void GetData() { using (SampleDataContext dbContext = new SampleDataContext()) { GridView1.DataSource = dbContext.students.ToList(); GridView1.DataBind(); } }
private void GetData() { using (SampleDataContext dbcontext = new SampleDataContext()) { GridView1.DataSource = dbcontext.guardians.ToList(); GridView1.DataBind(); } }
protected void GetList(int pageindex = 1, int incr = 10) { using (SampleDataContext db = new SampleDataContext()) { //db.students.Skip(pageindex * incr).Take(incr); var data = db.spindexWork(pageindex, incr); GridView1.DataSource = data; GridView1.DataBind(); } }
protected void Unnamed_Click(object sender, EventArgs e) { int id = Convert.ToInt32((sender as LinkButton).CommandArgument); using (SampleDataContext dbContext = new SampleDataContext()) { GridView2.DataSource = dbContext.students.FirstOrDefault(x => x.std_id == id); GridView2.DataBind(); } }
protected void MoreStudents_Click(object sender, EventArgs e) { int i = Convert.ToInt32((sender as LinkButton).CommandArgument); using (SampleDataContext con = new SampleDataContext()) { GridView2.DataSource = con.students.Where(x => x.std_id == i).ToList(); GridView2.DataBind(); } }
protected void ViewSingleGuardian_Click1(object sender, EventArgs e) { //getting std_id value from row by using command argument and storing it into the hidden field, checkout the command argument in Student.aspx Line num 38 hf1.Value = (sender as LinkButton).CommandArgument; i = Convert.ToInt32(hf1.Value); using (SampleDataContext context = new SampleDataContext()) { GridView2.DataSource = context.guardians.Where(x => x.std_id == i).ToList(); GridView2.DataBind(); GridView2.Visible = true; } }
protected void dltGuardian_Click(object sender, EventArgs e) { int i = Convert.ToInt32((sender as LinkButton).CommandArgument); using (SampleDataContext context = new SampleDataContext()) { guardian g = context.guardians.Where(x => x.id == i).SingleOrDefault(); g.std_id = null; context.SubmitChanges(); context.guardians.DeleteOnSubmit(g); context.SubmitChanges(); GridView2.DataSource = null; } GetData(); Clear(); }
protected void Edit_Click(object sender, EventArgs e) { btnInsert.Enabled = false; HideGrid(); hf1.Value = (sender as LinkButton).CommandArgument; i = Convert.ToInt32(hf1.Value); using (SampleDataContext context = new SampleDataContext()) { student std = context.students.SingleOrDefault(x => x.std_id == i); if (std != null) { txtFirstName.Text = std.std_Fname; txtLastName.Text = std.std_Lname; txtClass.Text = std.std_class.ToString(); } } }
protected void updGuardian_Click(object sender, EventArgs e) { hf1.Value = (sender as LinkButton).CommandArgument; int i = Convert.ToInt32(hf1.Value); btn_Update.Enabled = true; using (SampleDataContext context = new SampleDataContext()) { guardian g = context.guardians.Where(x => x.id == i).Single(); if (g != null) { txtFname.Text = g.g_Fname; txtLname.Text = g.g_Lname; txtAddress.Text = g.g_Address; txtStd_id.Text = g.std_id.ToString(); } } }
private bool isValidQuery(string req, double div) { using (SampleDataContext db = new SampleDataContext()) { int rows = db.students.Count(); double max_page = rows / div; int.TryParse(req, out int result); if (result >= 1 && result <= max_page) { return(true); } else { return(false); } } }
private void storeData() { student std = new student { std_Fname = "Muhammad", std_class = 16, std_Lname = "Zaman" }; List <student> lst = new List <student>(); for (int i = 0; i < 999; i++) { lst.Add(std); } using (SampleDataContext dbcontext = new SampleDataContext()) { dbcontext.students.InsertAllOnSubmit(lst); dbcontext.SubmitChanges(); } }
protected void Delete_Click(object sender, EventArgs e) { HideGrid(); hf1.Value = (sender as LinkButton).CommandArgument; i = Convert.ToInt32(hf1.Value); using (SampleDataContext context = new SampleDataContext()) { guardian g = context.guardians.Where(x => x.std_id == i).SingleOrDefault(); if (g != null) { g.std_id = null; context.SubmitChanges(); } student std = context.students.SingleOrDefault(x => x.std_id == i); context.students.DeleteOnSubmit(std); context.SubmitChanges(); Clear(); GetData(); } }
private void InsertOrUpdate(int ind) { using (SampleDataContext dbContext = new SampleDataContext()) { if (ind == 0) { student newstd = new student() { std_Fname = txtFirstName.Text, std_Lname = txtLastName.Text, std_class = Convert.ToInt32(txtClass.Text) }; dbContext.students.InsertOnSubmit(newstd); } else { student student_obj = dbContext.students.Single(x => x.std_id == ind); if (student_obj == null) { Response.Write("<script>alert('Not Found')</script>"); } else { student_obj.std_id = ind; student_obj.std_Fname = txtFirstName.Text; student_obj.std_Lname = txtLastName.Text; student_obj.std_class = Convert.ToInt32(txtClass.Text); } } dbContext.SubmitChanges(); Response.Write("<script>alert('Changes Saved!')</script>"); Clear(); GetData(); RowWork(); } }
protected void adGuardianBtn_Click(object sender, EventArgs e) { if (isValid()) { using (SampleDataContext dbcontext = new SampleDataContext()) { guardian newg = new guardian() { g_Fname = txtGuardianFName.Text, g_Lname = txtGuardianLname.Text, g_Address = txtGuardianAddress.Text, std_id = Convert.ToInt32(hf2.Value) }; dbcontext.guardians.InsertOnSubmit(newg); dbcontext.SubmitChanges(); Response.Redirect("~/Guardian.aspx"); } } else { Response.Write("<script>alert('Cannot Process Request due to validation error')</script>"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; string page_in = context.Request.QueryString["page"]; if (page_in == null) { page_in = "1"; } if (isValidQuery(page_in, 20)) { using (SampleDataContext db = new SampleDataContext()) { int p = Convert.ToInt32(page_in); var students = db.spindexWork(p, 20); context.Response.Write(JsonConvert.SerializeObject(students)); } } else { context.Response.Write(JsonConvert.SerializeObject("null")); } }