protected void Button2_Click(object sender, EventArgs e)
        {
            VisitorDetail vd = new VisitorDetail();

            if (!(string.IsNullOrEmpty(TextBox1.Text)))
            {
                string name = TextBox1.Text;
                var    data = (from t in db.VisitorDetails
                               where (t.Fname == name && t.Status == "Signed In")
                               select new { t.VisitorId, t.Fname, t.Lname, t.Idtype, t.Idnum }).ToList();
                if (data.Count == 0)
                {
                    Label3.Visible = true;
                    Label3.Text    = "No Records Found With Name :" + name;
                }
                else
                {
                    GridView1.DataSource = data;
                    GridView1.DataBind();
                }
            }
            else
            {
                Label3.Visible = true;
                Label3.Text    = "Please Enter ID or Name to search";
            }
        }
示例#2
0
        protected void btnsave_Click(object sender, EventArgs e)
        {
            string fname    = tbfname.Text;
            string lname    = tblname.Text;
            string company  = tbcompany.Text;
            string visiting = tbvisit.Text;
            string idtype   = ddlidtype.SelectedItem.ToString();
            string idnum    = tbidnum.Text;
            string vnum     = "";

            if (!(tbvnum.Text == null))
            {
                vnum = tbvnum.Text;
            }
            string        contact = tbcno.Text;
            string        purpose = tbpurpose.Text;
            VisitorDetail vd      = new VisitorDetail();

            vd.Fname     = fname;
            vd.Lname     = lname;
            vd.Company   = company;
            vd.Visiting  = visiting;
            vd.Idtype    = idtype;
            vd.Idnum     = idnum;
            vd.Vnumber   = vnum;
            vd.Contactno = contact;
            vd.Purpose   = purpose;
            vd.Status    = "Signed In";
            vd.ctime     = DateTime.Now;
            db.VisitorDetails.Add(vd);
            lbResult.Visible = true;
            var res = db.SaveChanges();
            int id  = vd.VisitorId;

            if (res > 0)
            {
                lbResult.Text = "The Visitor's Details Has Been Saved Successfully with the Visitors ID :" + id;
            }
            else
            {
                lbResult.Text = "Fail";
            }
            tbfname.Text   = "";
            tblname.Text   = "";
            tbcompany.Text = "";
            tbvisit.Text   = "";
            ddlidtype.SelectedItem.Value = "Select";
            tbidnum.Text   = "";
            tbvnum.Text    = "";
            tbcno.Text     = "";
            tbpurpose.Text = "";
        }