protected override void OnViewSet() { base.OnViewSet(); View.BeginInit(); View.UserDataPersistenceService = UserDataPersistenceService; View.EntityName = EntityName; var entity = GetEntity(); DynamicEntity = new SysBits.DynamicProxies.DynamicProxy(entity); RefreshEntityId(entity); Type entityType = entity.GetType(); Type listGenericType = typeof(List <>); Type listType = listGenericType.MakeGenericType(entityType); var list = (IList)Activator.CreateInstance(listType); list.Add(entity); var entityMetadata = MetadataProvider.Instance.EntiyMetadata.First(e => e.TableName == EntityName); BindData(list); View.InitEditors(entityMetadata); View.SetEditorStatus(WorkingMode == EntityDetailWorkingMode.View); View.EndInit(); }
protected override void OnViewSet() { View.InvoiceContractOkClicked += InvoiceContractOkClicked; var metadataService = new MetadataServiceClient(); var entityMetadata = metadataService.GetMetaEntities().First(e => e.TableName == "Contract"); int langId = System.Globalization.CultureInfo.CurrentCulture.LCID; var labels = metadataService.GetLocalizedLabels(langId); View.InitEditors(entityMetadata, labels); if (WorkItem.State["invoiceContractList"] != null) { var invoiceContractList = (IList)WorkItem.State["invoiceContractList"]; View.SelectedContracts.Clear(); foreach (object obj in invoiceContractList) { dynamic dynamicEntity = new SysBits.DynamicProxies.DynamicProxy(obj); Guid key = dynamicEntity.ContractId; if (!View.SelectedContracts.ContainsKey(key)) { View.SelectedContracts.Add(key, obj); } } } View.BindList(GetData()); View.ShowView(); }
public void CopyAndNew(object sender, EventArgs e) { View.PostEditors(); OnSaving(); if (!View.ValidateData()) { return; } if (NewEntityId == Guid.Empty) { _dynamicDataServiceContext = new DynamicDataServiceContext(); EntityId = NewEntityId; var newEntity = GetEntity(); var metaEntity = MetadataProvider.Instance.EntiyMetadata.Where(c => c.PhysicalName == EntityName).FirstOrDefault(); foreach (var att in metaEntity.Attributes) { if (att.IsCopyEnabled ?? false) { object targetValue = GetDynamicMember(DynamicEntity, att.TableColumnName); newEntity.GetType().GetProperty(att.TableColumnName).SetValue(newEntity, targetValue, null); } } DynamicEntity = new SysBits.DynamicProxies.DynamicProxy(newEntity); WorkingMode = EntityDetailWorkingMode.Add; RefreshEntityId(newEntity); NewEntityId = EntityId; Type entityType = newEntity.GetType(); Type listGenericType = typeof(List <>); Type listType = listGenericType.MakeGenericType(entityType); var list = (IList)Activator.CreateInstance(listType); list.Add(newEntity); BindData(list); } OnEntitySaved(new EventArgs <bool>(true)); }
private RoleViewModel GetRoleViewModel() { var roleViewModel = new RoleViewModel { RoleId = DynamicEntity.RoleId, RoleName = DynamicEntity.RoleName, Description = DynamicEntity.Description }; IList rolePrivilegeList = DynamicEntity.RolePrivileges; var privilegeEntities = DynamicDataServiceContext.GetObjects("PrivilegeEntity"); var privileges = DynamicDataServiceContext.GetObjects("Privilege"); var viewModelList = new Dictionary <string, EntityViewModel>(); foreach (var privilegeEntity in privilegeEntities) { dynamic dynamicEntity = new SysBits.DynamicProxies.DynamicProxy(privilegeEntity); var selectedEntityId = dynamicEntity.PrivilegeEntityId; Guid privilegeId = dynamicEntity.PrivilegeId; string entityName = dynamicEntity.EntityName; EntityViewModel entityViewModel; if (viewModelList.ContainsKey(entityName)) { entityViewModel = viewModelList[entityName]; } else { entityViewModel = new EntityViewModel() { EntityId = selectedEntityId, Name = entityName }; roleViewModel.SelectedEntities.Add(entityViewModel); viewModelList.Add(entityName, entityViewModel); } var privilege = privileges.AsQueryable().Where("PrivilegeId = @0", privilegeId)._First(); dynamic dynamicPrivilege = new SysBits.DynamicProxies.DynamicProxy(privilege); var privilegeViewModel = new PrivilegeViewModel { PrivilegeId = dynamicPrivilege.PrivilegeId, PrivilegeName = dynamicPrivilege.Name, Selected = SelectedPrivilege(rolePrivilegeList, privilegeId) }; entityViewModel.Privileges.Add(privilegeViewModel); } return(roleViewModel); }
void ViewQuoteLineItemSelectProductChanged(object sender, EventArgs e) { dynamic currentLineItem = new SysBits.DynamicProxies.DynamicProxy(View.CurrentQuoteLineItem); object productId = currentLineItem.ProductId; var product = productList.AsQueryable().Where("ProductId = @0", productId)._First(); if (product != null) { dynamic dynamicProduct = new SysBits.DynamicProxies.DynamicProxy(product); currentLineItem.UnitPrice = dynamicProduct.Price; } UpdateQuoteRelationAmount(); }
private void SetRole(RoleViewModel roleViewModel) { var rolePrivilegeType = DynamicTypeBuilder.Instance.GetDynamicType("RolePrivilege"); DynamicEntity.RoleName = roleViewModel.RoleName; DynamicEntity.Description = roleViewModel.Description; IList rolePrivilegeList = DynamicEntity.RolePrivileges; foreach (var privilege in roleViewModel.SelectedPrivileges) { var rolePrivilege = Activator.CreateInstance(rolePrivilegeType); dynamic dynamicPrivilege = new SysBits.DynamicProxies.DynamicProxy(rolePrivilege); dynamicPrivilege.RolePrivilegeId = Guid.NewGuid(); dynamicPrivilege.PrivilegeId = privilege.PrivilegeId; dynamicPrivilege.RoleId = EntityId; rolePrivilegeList.Add(rolePrivilege); } }
private void SetProjectMember() { if (View.SelectedProjectMember != null) { Type projectMemberType = DynamicTypeBuilder.Instance.GetDynamicType("ProjectMember"); IList projectMembers = DynamicEntity.ProjectMembers; while (projectMembers.Count > 0) { projectMembers.RemoveAt(0); } foreach (var selectedProjectMember in View.SelectedProjectMember) { var projectMember = Activator.CreateInstance(projectMemberType); dynamic dynamicProjectMember = new SysBits.DynamicProxies.DynamicProxy(projectMember); dynamicProjectMember.ProjectMemberId = Guid.NewGuid(); dynamicProjectMember.ProjectId = EntityId; dynamicProjectMember.MemberId = selectedProjectMember.AsDyanmic().UserId; projectMembers.Add(projectMember); } } }
private void SetInvoiceContract() { if (View.SelectedContracts != null) { Type contractType = DynamicTypeBuilder.Instance.GetDynamicType("InvoiceContract"); IList invoiceContracts = DynamicEntity.InvoiceContracts; while (invoiceContracts.Count > 0) { invoiceContracts.RemoveAt(0); } foreach (var selectedContract in View.SelectedContracts) { var contract = Activator.CreateInstance(contractType); dynamic dynamicContract = new SysBits.DynamicProxies.DynamicProxy(contract); dynamicContract.InvoiceContractId = Guid.NewGuid(); dynamicContract.InvoiceId = EntityId; dynamicContract.ContractId = selectedContract.AsDyanmic().ContractId; invoiceContracts.Add(contract); } } }
void UpdateQuoteRelationAmount() { View.PostEditors(); IEnumerable quoteLineItems = DynamicEntity.QuoteLineItems; decimal totalLineItemAmount = 0; foreach (object item in quoteLineItems) { dynamic currentLineItem = new SysBits.DynamicProxies.DynamicProxy(item); decimal unitPrice = currentLineItem.UnitPrice ?? 0; decimal quantity = currentLineItem.Quantity ?? 0; decimal totalPrice = unitPrice * quantity; currentLineItem.TotalPrice = totalPrice; currentLineItem.QuoteId = EntityId; totalLineItemAmount += totalPrice; } DynamicEntity.TotalLineItemAmount = totalLineItemAmount; decimal totalDiscountAmount = DynamicEntity.TotalDiscountAmount ?? 0; decimal totalTax = DynamicEntity.TotalTax ?? 0; DynamicEntity.TotalAmount = totalLineItemAmount - totalDiscountAmount + totalTax; }
private void SetUserRoleList() { var userRoleListResult = WorkItem.State["UserRoleList"] as List <UserRole>; if (userRoleListResult == null) { return; } IList userRoleListAble = DynamicEntity.UserRoles; userRoleListAble.Clear(); var userRoleType = DynamicTypeBuilder.Instance.GetDynamicType("UserRole"); foreach (var userRole in userRoleListResult) { var userRoleEntity = Activator.CreateInstance(userRoleType); dynamic dynamicEntity = new SysBits.DynamicProxies.DynamicProxy(userRoleEntity); dynamicEntity.Id = userRole.Id; dynamicEntity.RoleId = userRole.RoleID; dynamicEntity.UserId = EntityId; userRoleListAble.Add(userRoleEntity); } }