protected void GridViewRentedOutMaterials_RowDataBound(object sender, GridViewRowEventArgs e) { DateTime EndDateRent; if (e.Row.DataItem != null) { // register the row id in the hint (e.Row.Cells[0].Controls[1] as CheckBox).ToolTip = (e.Row.DataItem as DbDataRecord).GetValue(0).ToString(); (e.Row.Cells[0].Controls[1] as CheckBox).Checked = RentalNr > 0; // get the combobox ComboBox cbx = (e.Row.Cells[8].Controls[3] as ComboBox); // grab the possible new enddate from the grid EndDateRent = new DateTime(2100, 1, 1); try { EndDateRent = Convert.ToDateTime((e.Row.DataItem as DbDataRecord).GetValue(4)); EndDateRent = Convert.ToDateTime((e.Row.Cells[4].Controls[0]).ToString()); // original value } catch { } ObjectQuery Results = ControlObjectContext.CreateQuery <RentalItem>(MaterialAvailableQuery, new ObjectParameter("RentalType", (e.Row.DataItem as DbDataRecord).GetValue(2)), new ObjectParameter("LocationId", (e.Row.DataItem as DbDataRecord).GetValue(1)), new ObjectParameter("StartDate", (e.Row.DataItem as DbDataRecord).GetValue(3)), new ObjectParameter("EndDate", EndDateRent), new ObjectParameter("BorderEndDate", new DateTime(2100, 1, 1))); LoadComboBox(cbx, Results); URLPopUpControl upc = (e.Row.Cells[8].Controls[5] as URLPopUpControl); // get the corresponding RentalItemActivitySet Guid Temp = new Guid((e.Row.DataItem as DbDataRecord).GetValue(0).ToString()); // RentalItemActivity ria = ControlObjectContext.RentalItemActivitySet.Where(m => m.Id == Temp).First<RentalItemActivity>(); RentalItemActivity ria = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.RentalItemActivitySet", "Id", Temp)) as RentalItemActivity; upc.Visible = false; if ((ria != null) && (ria.InvoiceLine != null)) { upc.Visible = true; upc.URLToPopup = "WebFormPopup.aspx?UC=InvoiceBase&Id=" + ria.InvoiceLine.Invoice.Id.ToString(); } } }
protected void ButtonUpdate_Click(object sender, EventArgs e) { // update the availability in the combo box of this line Button btn = (sender as Button); GridViewRow gvr = btn.Parent.Parent as GridViewRow; Guid Temp = new Guid((gvr.Cells[0].Controls[1] as CheckBox).ToolTip); // get the corresponding RentalItemActivitySet // RentalItemActivity ria = ControlObjectContext.RentalItemActivitySet.Where(m => m.Id == Temp).First<RentalItemActivity>(); RentalItemActivity ria = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.RentalItemActivitySet", "Id", Temp)) as RentalItemActivity; // grab the possible new enddate from the grid DateTime EndDateRent = ria.RentEndStartDateTime; try { EndDateRent = Convert.ToDateTime((gvr.Cells[4].Controls[1] as CalendarWithTimeControl).Text); } catch { } (gvr.Cells[4].Controls[1] as CalendarWithTimeControl).Text = EndDateRent.ToString(); ObjectQuery Results = ControlObjectContext.CreateQuery <RentalItem>(MaterialAvailableQuery, new ObjectParameter("RentalType", ria.RentalItem.RentalType.Id), new ObjectParameter("LocationId", ria.RentLedger.Location.Id), new ObjectParameter("StartDate", ria.RentStartDateTime), new ObjectParameter("EndDate", EndDateRent), new ObjectParameter("BorderEndDate", new DateTime(2100, 1, 1))); // get the combobox to reload ComboBox cbx = (gvr.Cells[8].Controls[3] as ComboBox); LoadComboBox(cbx, Results); }