Пример #1
0
        //protected void GridViewHistory_RowCommand(Object sender, GridViewCommandEventArgs e)
        //{
        //    if (e.CommandName == "Delete")
        //    {
        //        GridViewRow gvr = (GridViewRow)((Control)e.CommandSource).NamingContainer;
        //        //int id = Convert.ToInt32(e.CommandSource);


        //        Label lblId = gvr.FindControl("lblId") as Label;

        //         if (lblId != null)
        //         {
        //             using (ProjectTrackerContainer context = new ProjectTrackerContainer())
        //             {
        //                 int id = Convert.ToInt32(lblId.Text);
        //                 PubHistory ph = context.PubHistories.First(t => t.Id == id);
        //                 context.PubHistories.Remove(ph);
        //                 context.SaveChanges();

        //                 GridViewHistory.DeleteRow(gvr.RowIndex);

        //             }
        //         }
        //    }
        //}

        protected void GridViewHistory_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            GridViewRow row = GridViewHistory.Rows[e.RowIndex];

            Label lblId = row.FindControl("lblId") as Label;

            if (lblId != null)
            {
                using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                {
                    int        id   = Convert.ToInt32(lblId.Text);
                    PubHistory hist = context.PubHistories.First(t => t.Id == id);
                    context.PubHistories.Remove(hist);
                    context.SaveChanges();

                    var pubHist = context.PubHistories
                                  .Join(context.Publications, h => h.PublicationId, p => p.Id, (h, p) => new { h })
                                  //.Join(context.PublishStatus, ph => ph.h.Status, ps => ps.Id, (ph, ps) => new { ph.h.Id, ps.Name, ph.h.StartDate, ph.h.EndDate, ph.h.Creator, ph.h.PublicationId })
                                  .Where(i => i.h.PublicationId == hist.PublicationId)
                                  .ToList();

                    GridViewHistory.DataSource = pubHist;
                    GridViewHistory.DataBind();
                }

                if (GridViewHistory.Rows.Count > 0)
                {
                    GridViewHistory.SelectRow(GridViewHistory.Rows.Count - 1);
                    GridViewHistory.SelectedRow.Focus();
                }
            }
        }
Пример #2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (ValidateControl())
            {
                using (ProjectTrackerContainer context = new ProjectTrackerContainer())
                {
                    int pubId = Convert.ToInt32(ddlPublication.SelectedValue);

                    PubHistory newHist = new PubHistory()
                    {
                        PublicationId = pubId,
                        StatusId      = PubStatus,
                        PaperDate     = Convert.ToDateTime(TextBoxStartDate.Text),
                        Creator       = Page.User.Identity.Name,
                        CreateDate    = Convert.ToDateTime(HiddenFieldCurrentDate.Value)
                    };

                    context.PubHistories.Add(newHist);

                    context.SaveChanges();

                    Response.Write("<script>alert('Publication History Saved.');</script>");

                    var pubHist = context.PubHistories
                                  .Join(context.Publications, h => h.PublicationId, p => p.Id, (h, p) => new { h })
                                  //.Join(context.PublishStatus, ph => ph.h.StatusId, ps => ps.Id, (ph, ps) => new { ph.h.Id, ps.Name, ph.h.PaperDate,  ph.h.Creator, ph.h.PublicationId })
                                  .Where(i => i.h.PublicationId == pubId)
                                  .ToList();

                    GridViewHistory.DataSource = pubHist;
                    GridViewHistory.DataBind();
                }
            }
            else
            {
                Response.Write("<script>alert('Please check the data entered.');</script>");
            }
        }