protected void ButtonNewContractMaterial_Click(object sender, EventArgs e) { if (WebUserControlCustomerRelationContract1.SaveData(true)) { RelationContractMaterial NewObj = new RelationContractMaterial(); ModelTMSContainer Temp = new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session); EntityKey TempKey = new EntityKey("ModelTMSContainer.RelationContractSet", "Id", WebUserControlCustomerRelationContract1.KeyID); RelationContract TempObj = Temp.GetObjectByKey(TempKey) as RelationContract; NewObj.RelationContract = TempObj; NewObj.Material = Temp.MaterialSet.First(); NewObj.Description = "Nieuw materiaal"; Temp.AddToRelationContractMaterialSet(NewObj); Temp.SaveChanges(SaveOptions.DetectChangesBeforeSave); RefreshContractMaterials(); } }
protected void Page_PreRender(object Sender, EventArgs e) { if (DataItem != null) { RelationContractMaterial rcm = DataItem as RelationContractMaterial; RelationContract rc = rcm.RelationContract; if (rc != null) { LabelOnContract.Visible = rc.HasContractGuidance; LabelOnContract_AvgStockUnits.Visible = rc.HasContractGuidance; LabelOnContractPrice.Visible = rc.HasContractGuidance; LabelOnContractAvgPricePerUnit.Visible = rc.HasContractGuidance; LabelRequiredProfitContractGuidance.Visible = rc.HasContractGuidance; TextBox_AvgRequiredProfitPerUnit.Visible = rc.HasContractGuidance; if (rc.HasContractGuidance) { LabelOnContractAvgPricePerUnit.Text = rcm.AvgStockUnitPrice().ToString(); } } } }
private void DetermineCurrentSelectedMaterial(out Material MatItem, out RelationPriceAgreement PAItem, out RelationContractMaterial ContractItem) { MatItem = null; PAItem = null; ContractItem = null; if (DropDownListMaterials.SelectedValue != "") { // locate the material, price agreement or contract in the entitydatasource Guid SelID = Guid.Parse(DropDownListMaterials.SelectedValue); // try to load the data from material, relationcontract or relationpriceagreement EntityKey TempKey = new EntityKey("ModelTMSContainer.MaterialSet", "Id", SelID); try { MatItem = ControlObjectContext.GetObjectByKey(TempKey) as Material; } catch { }; if (MatItem == null) { TempKey = new EntityKey("ModelTMSContainer.RelationPriceAgreementSet", "Id", SelID); try { PAItem = ControlObjectContext.GetObjectByKey(TempKey) as RelationPriceAgreement; MatItem = PAItem.Material; } catch { }; } if ((MatItem == null) && (PAItem == null)) { TempKey = new EntityKey("ModelTMSContainer.RelationContractMaterialSet", "Id", SelID); try { ContractItem = ControlObjectContext.GetObjectByKey(TempKey) as RelationContractMaterial; MatItem = ContractItem.Material; } catch { }; } } }