Beispiel #1
0
        //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;
                        }
                    }
                }
            }
        }
Beispiel #2
0
        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>");
                }
            }
        }
Beispiel #3
0
        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();
        }
Beispiel #4
0
        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();
                }
            }
        }
Beispiel #5
0
        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();
            }
        }
 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>");
     }
 }
 private void detach_guardians(guardian entity)
 {
     this.SendPropertyChanging();
     entity.student = null;
 }
 private void attach_guardians(guardian entity)
 {
     this.SendPropertyChanging();
     entity.student = this;
 }
 partial void Deleteguardian(guardian instance);
 partial void Updateguardian(guardian instance);
 partial void Insertguardian(guardian instance);