protected void GridViewTimeEntry_RowDeleting(object sender, GridViewDeleteEventArgs e) { GridViewRow row = GridViewTimeEntry.Rows[e.RowIndex]; Label lblId = row.FindControl("lblId") as Label; if (lblId != null) { using (ProjectTrackerContainer context = new ProjectTrackerContainer()) { int id = Convert.ToInt32(lblId.Text); TimeEntry te = context.TimeEntries.First(t => t.Id == id); context.TimeEntries.Remove(te); context.SaveChanges(); } BindGridView(); if (GridViewTimeEntry.Rows.Count > 0) { GridViewTimeEntry.SelectRow(GridViewTimeEntry.Rows.Count - 1); GridViewTimeEntry.SelectedRow.Focus(); } } }
private void BindGridView() { int bioStatId, monthId, yearId; Int32.TryParse(ddlBioStat.SelectedValue, out bioStatId); Int32.TryParse(ddlMonth.SelectedValue, out monthId); Int32.TryParse(ddlYear.SelectedValue, out yearId); if (bioStatId > 0 && monthId > 0) { using (ProjectTrackerContainer context = new ProjectTrackerContainer()) { var query = context.TimeEntries .Join(context.Project2 , t => t.ProjectId , p => p.Id , (t, p) => new { t, p.Title, phase = t.ProjectPhase.Name } ) .Join(context.ServiceTypes , tt => tt.t.ServiceTypeId , s => s.Id , (tt, s) => new { tt, s.Name } ) .Join(context.Date1 , ttt => ttt.tt.t.DateKey , d => d.DateKey , (ttt, d) => new { ttt.tt.t.Id , ttt.tt.t.ProjectId , ttt.tt.phase , ttt.tt.Title , ttt.Name , d.Date , ttt.tt.t.Duration , ttt.tt.t.BioStatId , ttt.tt.t.Description } ) .Where(a => a.BioStatId == bioStatId && a.Date.Year == yearId && a.Date.Month == monthId) .OrderByDescending(t => t.Id); GridViewTimeEntry.DataSource = query.ToList(); GridViewTimeEntry.DataBind(); } } }
//protected void gvPhase_RowDeleting(object sender, GridViewDeleteEventArgs e) //{ // GridViewRow row = gvPhase.Rows[e.RowIndex]; // BindgvPhase(e.RowIndex); //} //protected void btnAddPhase_Click(object sender, EventArgs e) //{ // BindgvPhase(-1); //} //private void BindGridViewProjectEffort(int projectId) //{ // System.Data.DataTable dummy = new System.Data.DataTable(); // dummy.Columns.Add("InvoiceId"); // dummy.Columns.Add("ReqNum"); // dummy.Columns.Add("ReqDate"); // dummy.Columns.Add("FromDate"); // dummy.Columns.Add("ToDate"); // dummy.Columns.Add("PhdReq"); // dummy.Columns.Add("PhdSpt"); // dummy.Columns.Add("MsReq"); // dummy.Columns.Add("MsSpt"); // dummy.Rows.Add(); // GridViewProjectEffort.DataSource = dummy; // GridViewProjectEffort.DataBind(); // GridViewProjectEffort.Rows[0].Cells.Clear(); //} protected void GridViewTimeEntry_RowDeleting(object sender, GridViewDeleteEventArgs e) { GridViewRow row = GridViewTimeEntry.Rows[e.RowIndex]; Label lblId = row.FindControl("lblId") as Label; if (lblId != null) { bool validDate = ValidateDate(); if (validDate) { using (ProjectTrackerContainer context = new ProjectTrackerContainer()) { int id = Convert.ToInt32(lblId.Text); TimeEntry te = context.TimeEntries.First(t => t.Id == id); context.TimeEntries.Remove(te); context.SaveChanges(); } BindGridView(); if (GridViewTimeEntry.Rows.Count > 0) { GridViewTimeEntry.SelectRow(GridViewTimeEntry.Rows.Count - 1); GridViewTimeEntry.SelectedRow.Focus(); } } else { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(@"<script type='text/javascript'>"); sb.Append("alert('Can not change history input.');"); sb.Append(@"</script>"); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "CantDeleteScript", sb.ToString(), false); //Response.Write("<script>alert('Can not delete history input.');</script>"); } } }