Exemple #1
0
    protected void Unnamed2_Click(object sender, EventArgs e)
    {
        InternshipProgramEntities ipe = new InternshipProgramEntities();
        Intern1 inte = new Intern1();

        HttpPostedFile f     = Request.Files["photo"];
        string         fpath = System.IO.Path.GetFileName(f.FileName);

        f.SaveAs(Server.MapPath(System.IO.Path.Combine("~/images/", fpath)));
        HttpPostedFile a     = Request.Files["card"];
        string         apath = System.IO.Path.GetFileName(a.FileName);

        a.SaveAs(Server.MapPath(System.IO.Path.Combine("~/App_Data/", apath)));

        inte.adress       = res.Text;
        inte.dob          = DateTime.Parse(dob.Text);
        inte.Email        = email.Text;
        inte.FirstName    = fname.Text;
        inte.LastName     = lname.Text;
        inte.photo        = "/images/" + fpath;
        inte.Mobile       = int.Parse(pn.Text);
        inte.placeofbirth = bp.Text;
        inte.identitycard = "/App_data/" + apath;
        ipe.AddToIntern1(inte);
        ipe.SaveChanges();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        InternshipProgramEntities context = new InternshipProgramEntities();
        Button  button   = (Button)sender;
        string  username = button.Parent.Parent.Parent.Parent.ID;
        Intern1 c        = new Intern1()
        {
            ID = int.Parse(username)
        };

        context.Intern1.Attach(c);
        context.Intern1.DeleteObject(c);
        context.SaveChanges();

        Response.Redirect("./Interns.aspx");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        InternshipProgramEntities ipe = new InternshipProgramEntities();
        Intern1 c = ipe.Intern1.ToList().Where(x => x.ID == int.Parse(Request.QueryString["id"].ToString())).First();

        c.FirstName    = fn.Value;
        c.LastName     = ln.Value;
        c.dob          = DateTime.Parse(ag.Value);
        c.photo        = c.photo;
        c.identitycard = c.identitycard;
        c.placeofbirth = pob.Value;
        c.Email        = em.Value;
        c.Mobile       = int.Parse(mb.Value);
        c.adress       = ad.Value;
        ipe.SaveChanges();
    }
 protected void Page_Load(object sender, EventArgs e)
 {
     /*if (!Roles.IsUserInRole("admin"))
      * {
      *  Response.Write("<script>alert('You dont have permission')</script>");
      * }*/
     {
         InternshipProgramEntities ipe = new InternshipProgramEntities();
         Intern1 c = ipe.Intern1.ToList().Where(x => x.ID == int.Parse(Request.QueryString["id"].ToString())).First();
         fn.Value  = c.FirstName.ToString();
         ln.Value  = c.LastName.ToString();
         ag.Value  = DateTime.Parse(c.dob.ToString()).ToString("yyyy-MM-dd");
         pob.Value = c.placeofbirth.ToString();
         em.Value  = c.Email.ToString();
         mb.Value  = c.Mobile.ToString();
         ad.Value  = c.adress.ToString();
     }
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        InternshipProgramEntities context = new InternshipProgramEntities();
        bool val1 = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
        var  deps = context.Departments;

        foreach (Department dep in deps)
        {
            ddl.Items.Add(new System.Web.UI.WebControls.ListItem(dep.DepName.ToString(), dep.DepID.ToString()));
        }
        if (val1)
        {
            log.InnerHtml = "Welcome " + User.Identity.Name;
        }
        if (Roles.IsUserInRole("admin"))
        {
            log.InnerHtml += " Add Intern";
            log.HRef       = "./newIntern.aspx";
        }
        else if (Roles.IsUserInRole("employee"))
        {
            log.InnerHtml += "";
            log.HRef       = "";
        }
        else
        {
            log.InnerHtml = "Login/Register";
            log.HRef      = "./Login.aspx";
        }
        if (Request.QueryString.Count == 0)
        {
            var candids = context.Intern1;
            foreach (Intern1 i in candids)
            {
                HtmlGenericControl NewControl = new HtmlGenericControl("div");
                NewControl.ID = i.ID.ToString();
                HtmlTable tbl = new HtmlTable();
                //HtmlTableRow cell1 = new HtmlTableRow();
                //HtmlTableCell cll1 = new HtmlTableCell();
                //cll1.InnerHtml = string.Format("<a href='/intern.aspx?id=" + i.ID + "'><img src='" + i.photo + "' width='25%' height='25%' align='center'/></a>");
                //cell1.Cells.Add(cll1);
                HtmlTableRow  cell2 = new HtmlTableRow();
                HtmlTableCell cll2  = new HtmlTableCell();
                cll2.InnerHtml = string.Format("<a href='/intern.aspx?id=" + i.ID + "'>" + i.FirstName + " " + i.LastName + "</a>");
                cell2.Cells.Add(cll2);
                HtmlTableRow  cell3 = new HtmlTableRow();
                HtmlTableCell cll3  = new HtmlTableCell();
                cll3.InnerHtml = i.Mobile.ToString();
                cell3.Cells.Add(cll3);
                HtmlTableRow  cell4 = new HtmlTableRow();
                HtmlTableCell cll4  = new HtmlTableCell();
                cll4.InnerHtml = i.Email;
                cell4.Cells.Add(cll4);
                HtmlTableRow  cell5   = new HtmlTableRow();
                HtmlTableCell cll5    = new HtmlTableCell();
                Button        button2 = new Button();
                button2.Text     = "Delete";
                button2.CssClass = i.ID.ToString();
                button2.Click   += Button2_Click;
                button2.Attributes.Add("runat", "server");
                //cll5.Controls.Add(button2);
                cell5.Cells.Add(cll5);
                //tbl.Rows.Add(cell1);
                tbl.Rows.Add(cell2);
                tbl.Rows.Add(cell3);
                tbl.Rows.Add(cell4);
                tbl.Rows.Add(cell5);
                tbl.Style.Add("align", "center");
                NewControl.Controls.Add(tbl);
                NewControl.Style.Add("float", "left");
                NewControl.Style.Add("width", "33%");
                NewControl.Attributes.Add("align", "center");
                NewControl.Style.Add("text-align", "center");
                NewControl.Attributes["class"] = "interns col-4";
                NewControl.ID = i.ID.ToString();
                interns.Controls.Add(NewControl);
            }
        }
        else
        {
            if (Request.QueryString["Name"] != null)
            {
                var candids = context.Intern1.ToList().Where(n => n.FirstName.Contains(Request.QueryString["Name"].ToString()));
                foreach (Intern1 i in candids)
                {
                    HtmlGenericControl NewControl = new HtmlGenericControl("div");
                    NewControl.ID = i.ID.ToString();
                    HtmlTable tbl = new HtmlTable();
                    //HtmlTableRow cell1 = new HtmlTableRow();
                    //HtmlTableCell cll1 = new HtmlTableCell();
                    //cll1.InnerHtml = string.Format("<a href='/intern.aspx?id=" + i.ID + "'><img src='" + i.photo + "' width='25%' height='25%' align='center'/></a>");
                    //cell1.Cells.Add(cll1);
                    HtmlTableRow  cell2 = new HtmlTableRow();
                    HtmlTableCell cll2  = new HtmlTableCell();
                    cll2.InnerHtml = string.Format("<a href='/intern.aspx?id=" + i.ID + "'>" + i.FirstName + " " + i.LastName + "</a>");
                    cell2.Cells.Add(cll2);
                    HtmlTableRow  cell3 = new HtmlTableRow();
                    HtmlTableCell cll3  = new HtmlTableCell();
                    cll3.InnerHtml = i.Mobile.ToString();
                    cell3.Cells.Add(cll3);
                    HtmlTableRow  cell4 = new HtmlTableRow();
                    HtmlTableCell cll4  = new HtmlTableCell();
                    cll4.InnerHtml = i.Email;
                    cell4.Cells.Add(cll4);
                    HtmlTableRow  cell5   = new HtmlTableRow();
                    HtmlTableCell cll5    = new HtmlTableCell();
                    Button        button2 = new Button();
                    button2.Text     = "Delete";
                    button2.CssClass = i.ID.ToString();
                    button2.Click   += Button2_Click;
                    button2.Attributes.Add("runat", "server");
                    //cll5.Controls.Add(button2);
                    cell5.Cells.Add(cll5);
                    //tbl.Rows.Add(cell1);
                    tbl.Rows.Add(cell2);
                    tbl.Rows.Add(cell3);
                    tbl.Rows.Add(cell4);
                    tbl.Rows.Add(cell5);
                    tbl.Style.Add("align", "center");
                    NewControl.Controls.Add(tbl);
                    NewControl.Style.Add("float", "left");
                    NewControl.Style.Add("width", "33%");
                    NewControl.Attributes.Add("align", "center");
                    NewControl.Style.Add("text-align", "center");
                    NewControl.Attributes["class"] = "interns col-4";
                    NewControl.ID = i.ID.ToString();
                    interns.Controls.Add(NewControl);
                }
            }
            else if (Request.QueryString["Dep"] != null)
            {
                var eds = context.Educations.ToList().Where(x => x.Deptmnt == int.Parse(Request.QueryString["Dep"].ToString()));

                foreach (Education ed in eds)
                {
                    Intern1 i = new Intern1();
                    var     t = context.Intern1.ToList().Where(XPath => XPath.ID == ed.InternID).First();
                    i = t;
                    HtmlGenericControl NewControl = new HtmlGenericControl("div");
                    NewControl.ID = i.ID.ToString();
                    HtmlTable tbl = new HtmlTable();
                    //HtmlTableRow cell1 = new HtmlTableRow();
                    //HtmlTableCell cll1 = new HtmlTableCell();
                    //cll1.InnerHtml = string.Format("<a href='/intern.aspx?id=" + i.ID + "'><img src='" + i.photo + "' width='25%' height='25%' align='center'/></a>");
                    //cell1.Cells.Add(cll1);
                    HtmlTableRow  cell2 = new HtmlTableRow();
                    HtmlTableCell cll2  = new HtmlTableCell();
                    cll2.InnerHtml = string.Format("<a href='/intern.aspx?id=" + i.ID + "'>" + i.FirstName + " " + i.LastName + "</a>");
                    cell2.Cells.Add(cll2);
                    HtmlTableRow  cell3 = new HtmlTableRow();
                    HtmlTableCell cll3  = new HtmlTableCell();
                    cll3.InnerHtml = i.Mobile.ToString();
                    cell3.Cells.Add(cll3);
                    HtmlTableRow  cell4 = new HtmlTableRow();
                    HtmlTableCell cll4  = new HtmlTableCell();
                    cll4.InnerHtml = i.Email;
                    cell4.Cells.Add(cll4);
                    HtmlTableRow  cell5   = new HtmlTableRow();
                    HtmlTableCell cll5    = new HtmlTableCell();
                    Button        button2 = new Button();
                    button2.Text     = "Delete";
                    button2.CssClass = i.ID.ToString();
                    button2.Click   += Button2_Click;
                    button2.Attributes.Add("runat", "server");
                    //cll5.Controls.Add(button2);
                    cell5.Cells.Add(cll5);
                    //tbl.Rows.Add(cell1);
                    tbl.Rows.Add(cell2);
                    tbl.Rows.Add(cell3);
                    tbl.Rows.Add(cell4);
                    tbl.Rows.Add(cell5);
                    tbl.Style.Add("align", "center");
                    NewControl.Controls.Add(tbl);
                    NewControl.Style.Add("float", "left");
                    NewControl.Style.Add("width", "33%");
                    NewControl.Attributes.Add("align", "center");
                    NewControl.Style.Add("text-align", "center");
                    NewControl.Attributes["class"] = "interns col-4";
                    NewControl.ID = i.ID.ToString();
                    interns.Controls.Add(NewControl);
                }
            }
            else if (Request.QueryString["End"] != null)
            {
                var eds = context.Educations.ToList().Where(x => x.EndDate == null);

                foreach (Education ed in eds)
                {
                    Intern1 i = new Intern1();
                    var     t = context.Intern1.ToList().Where(XPath => XPath.ID == ed.InternID).First();
                    i = t;
                    HtmlGenericControl NewControl = new HtmlGenericControl("div");
                    NewControl.ID = i.ID.ToString();
                    HtmlTable tbl = new HtmlTable();
                    //HtmlTableRow cell1 = new HtmlTableRow();
                    //HtmlTableCell cll1 = new HtmlTableCell();
                    //cll1.InnerHtml = string.Format("<a href='/intern.aspx?id=" + i.ID + "'><img src='" + i.photo + "' width='25%' height='25%' align='center'/></a>");
                    //cell1.Cells.Add(cll1);
                    HtmlTableRow  cell2 = new HtmlTableRow();
                    HtmlTableCell cll2  = new HtmlTableCell();
                    cll2.InnerHtml = string.Format("<a href='/intern.aspx?id=" + i.ID + "'>" + i.FirstName + " " + i.LastName + "</a>");
                    cell2.Cells.Add(cll2);
                    HtmlTableRow  cell3 = new HtmlTableRow();
                    HtmlTableCell cll3  = new HtmlTableCell();
                    cll3.InnerHtml = i.Mobile.ToString();
                    cell3.Cells.Add(cll3);
                    HtmlTableRow  cell4 = new HtmlTableRow();
                    HtmlTableCell cll4  = new HtmlTableCell();
                    cll4.InnerHtml = i.Email;
                    cell4.Cells.Add(cll4);
                    HtmlTableRow  cell5   = new HtmlTableRow();
                    HtmlTableCell cll5    = new HtmlTableCell();
                    Button        button2 = new Button();
                    button2.Text     = "Delete";
                    button2.CssClass = i.ID.ToString();
                    button2.Click   += Button2_Click;
                    button2.Attributes.Add("runat", "server");
                    //cll5.Controls.Add(button2);
                    cell5.Cells.Add(cll5);
                    //tbl.Rows.Add(cell1);
                    tbl.Rows.Add(cell2);
                    tbl.Rows.Add(cell3);
                    tbl.Rows.Add(cell4);
                    tbl.Rows.Add(cell5);
                    tbl.Style.Add("align", "center");
                    NewControl.Controls.Add(tbl);
                    NewControl.Style.Add("float", "left");
                    NewControl.Style.Add("width", "33%");
                    NewControl.Attributes.Add("align", "center");
                    NewControl.Style.Add("text-align", "center");
                    NewControl.Attributes["class"] = "interns col-4";
                    NewControl.ID = i.ID.ToString();
                    interns.Controls.Add(NewControl);
                }
            }
        }
    }