I have the following code which allows me to display the gridview exactly as I want,
I need to move the 2 form checkboxes to the same cell but that can be done after.
I am trying to update my database based on the editing done in the DGV, I have set Name, DOB/DOD, Place Of Death, Crem/Burial, Date of Funeral and COR to read only, these values do not need to update back.
Is there a way to map the DTO back to the entity framework or a better way again?
Thanks
private void RefreshDataGrid()
{
var query = (from f in context.funerals
where f.IsPencil == 0
join d in context.deceaseddetails on f.DeceasedID equals d.ID
join i in context.funeralservices on f.ID equals i.FuneralID
where i.IsAlternative == 0
join h in context.htvalues on f.HtValuesID equals h.ID
join p in context.placeofdeaths on f.PlaceOfDeathID equals p.ID
join c in context.coroners on f.CoronerID equals c.ID
let val1 = d.DateOfDeath
let val2 = d.DateOfBirth
let val3 = i.Date
orderby i.Date
select new
{
d.LastName,
d.FirstName,
val2,
val1,
f.CremOrInt,
FormsSigned1 = h.FormsSigned1,
FormsSigned2 = h.FormsSigned2,
PlaceOfDeath = p.PlaceOfDeath1.Substring(0, 15),
val3,
HospOrDocInformed = h.HospOrDocInformed ?? "Unspecified",
CHQorCoroner = h.CHQorCoroner ?? "Unspecified",
CertReq = h.CertReq ?? "Unspecified",
RestingAt = h.RestingAt ?? "Unspecified",
CoffinModel = h.CoffinModel ?? "Unspecified",
SizeAct = h.CoffinSize ?? "Unspecified",
CoffinPlateComp = h.CoffinPlateComp,
HtBy = h.HtBy ?? "Unspecified",
COR = c.Abbrieviation ?? "Unspecified",
Information = h.HTInformation ?? "Unspecified",
RedStatus = h.RedStatus,
YellowStatus = h.YellowStatus,
GreenStatus = h.GreenStatus
}).ToList();
var dataobjects = query.Select(d => new DataBindingProjection
{
DeceasedName = (d.FirstName + Environment.NewLine + d.LastName),
DOBDOD = (d.val2.HasValue ? d.val2.Value.ToShortDateString() : string.Empty) + Environment.NewLine +
(d.val1.HasValue ? d.val1.Value.ToShortDateString() : string.Empty),
DeathPlace = d.PlaceOfDeath,
CremInt = d.CremOrInt,
FuneralDate = (d.val3.HasValue ? d.val3.Value.ToShortDateString() : string.Empty),
HospDoc = d.HospOrDocInformed,
CHQCor = d.CHQorCoroner,
forms1 = d.FormsSigned1,
forms2 = d.FormsSigned2,
CertReq = d.CertReq,
RestingAt = d.RestingAt,
CoffinModel = d.CoffinModel,
SizeAct = d.SizeAct,
CoffinPlate = d.CoffinPlateComp,
HtBy = d.HtBy,
COR = d.COR,
Information = d.Information,
red = d.RedStatus,
yellow = d.YellowStatus,
green = d.GreenStatus
}).ToList();
dataGridView1.DataSource = dataobjects;
dataGridView1.Columns[0].HeaderText = "Last Name" + Environment.NewLine + "First Name";
dataGridView1.Columns[0].ReadOnly = true;
dataGridView1.Columns[1].HeaderText = "DOB" + Environment.NewLine + "DOD";
dataGridView1.Columns[1].ReadOnly = true;
dataGridView1.Columns[2].HeaderText = "Place Of" + Environment.NewLine + "Death";
dataGridView1.Columns[2].ReadOnly = true;
dataGridView1.Columns[3].HeaderText = "Crem/Int";
dataGridView1.Columns[3].ReadOnly = true;
dataGridView1.Columns[4].HeaderText = "Funeral" + Environment.NewLine + "Date";
dataGridView1.Columns[4].ReadOnly = true;
dataGridView1.Columns[5].HeaderText = "Hosp or" + Environment.NewLine + "Doc Informed";
dataGridView1.Columns[6].HeaderText = "CHQ or" + Environment.NewLine + "Coroner";
dataGridView1.Columns[7].HeaderText = "Forms 1" + Environment.NewLine + "Signed?";
dataGridView1.Columns[8].HeaderText = "Forms 2" + Environment.NewLine + "Signed?";
dataGridView1.Columns[9].HeaderText = "Cert" + Environment.NewLine + "Req.";
dataGridView1.Columns[10].HeaderText = "Resting" + Environment.NewLine + "@";
dataGridView1.Columns[11].HeaderText = "Coffin" + Environment.NewLine + "Model";
dataGridView1.Columns[12].HeaderText = "Size" + Environment.NewLine + "Act.";
dataGridView1.Columns[13].HeaderText = "Coffin" + Environment.NewLine + "Plate Comp";
dataGridView1.Columns[14].HeaderText = "HT" + Environment.NewLine + "By";
dataGridView1.Columns[15].HeaderText = "COR";
dataGridView1.Columns[15].ReadOnly = true;
dataGridView1.Columns[16].HeaderText = "Information" + Environment.NewLine + "Of Interest";
dataGridView1.Columns[17].HeaderText = "Red" + Environment.NewLine + "Status";
dataGridView1.Columns[18].HeaderText = "Yellow" + Environment.NewLine + "Status";
dataGridView1.Columns[19].HeaderText = "Green" + Environment.NewLine + "Status";
}
private class DataBindingProjection
{
public string DeceasedName { get; set; }
public string DOBDOD {get; set;}
public string DeathPlace { get; set; }
public string CremInt { get; set; }
public string FuneralDate { get; set; }
public string HospDoc { get; set; }
public string CHQCor { get; set; }
public Boolean forms1 { get; set; }
public Boolean forms2 { get; set; }
public string CertReq { get; set; }
public string RestingAt { get; set; }
public string CoffinModel { get; set; }
public string SizeAct { get; set; }
public Boolean CoffinPlate { get; set; }
public string HtBy { get; set; }
public string COR { get; set; }
public string Information { get; set; }
public Boolean red { get; set; }
public Boolean yellow { get; set; }
public Boolean green { get; set; }
}