コード例 #1
0
        public static RequestResult Query(QueryParameters queryParameters, Account account)
        {
            RequestResult result = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var downStreamOrganizationIds = OrganizationDataAccessor.GetDownStreamOrganizationIds(new Guid(queryParameters.OrganizationId), true);

                    var query = context.Solutions.Where(x => downStreamOrganizationIds.Contains(x.OrganizationId) && account.QueryableOrganizationIds.Contains(x.OrganizationId)).AsQueryable();

                    if (!string.IsNullOrEmpty(queryParameters.SolutionType))
                    {
                        query = query.Where(x => x.OrganizationId == new Guid(queryParameters.OrganizationId) && x.Type == queryParameters.SolutionType);
                    }

                    if (!string.IsNullOrEmpty(queryParameters.Keyword))
                    {
                        query = query.Where(x => x.SId.Contains(queryParameters.Keyword) || x.Name.Contains(queryParameters.Keyword));
                    }

                    var organization = OrganizationDataAccessor.GetOrganization(new Guid(queryParameters.OrganizationId));

                    result.ReturnData(new GridViewModel()
                    {
                        OrganizationId       = queryParameters.OrganizationId,
                        Permission           = account.OrganizationPermission(new Guid(queryParameters.OrganizationId)),
                        SolutionType         = queryParameters.SolutionType,
                        OrganizationName     = organization.Name,
                        FullOrganizationName = organization.FullName,
                        Items = query.ToList().Select(x => new GridItem()
                        {
                            SolutionId       = x.SolutionId.ToString(),
                            Permission       = account.OrganizationPermission(x.OrganizationId),
                            OrganizationName = OrganizationDataAccessor.GetOrganizationName(x.OrganizationId),
                            SolutionType     = x.Type,
                            SId  = x.SId,
                            Name = x.Name
                        }).OrderBy(x => x.OrganizationName).ThenBy(x => x.SolutionType).ThenBy(x => x.SId).ToList()
                    });
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
コード例 #2
0
        public static RequestResult AddMaterialSpecification(List <MaterialSpecificationModel> materialSpecificationModels, List <string> selectedList, string refOrganizationId)
        {
            RequestResult result = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    foreach (string selected in selectedList)
                    {
                        string[] temp = selected.Split(Define.Seperators, StringSplitOptions.None);

                        var organizationId = temp[0];
                        var materialType   = temp[1];
                        var specUniqueID   = temp[2];

                        if (!string.IsNullOrEmpty(specUniqueID))
                        {
                            if (!materialSpecificationModels.Any(x => x.MaterialSpecificationId == specUniqueID))
                            {
                                var spec = context.MSpecifications.First(x => x.MSpecificationId == new Guid(specUniqueID));

                                materialSpecificationModels.Add(new MaterialSpecificationModel()
                                {
                                    MaterialSpecificationId = spec.MSpecificationId.ToString(),
                                    Name = spec.Name,
                                    Seq  = materialSpecificationModels.Count + 1,
                                    MaterialSpecificationOptionModels = context.MSOptions.Where(x => x.MSpecificationId == spec.MSpecificationId).Select(x => new MaterialSpecificationOptionModel
                                    {
                                        MaterialSpecificationOptionId = x.MSOptionId.ToString(),
                                        Name = x.Name,
                                        Seq  = x.Seq,
                                        MaterialSpecificationId = x.MSpecificationId.ToString()
                                    }).OrderBy(x => x.Name).ToList()
                                });
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(materialType))
                            {
                                var specList = context.MSpecifications.Where(x => x.OrganizationId == new Guid(organizationId) && x.MaterialType == materialType).ToList();

                                foreach (var spec in specList)
                                {
                                    if (!materialSpecificationModels.Any(x => x.MaterialSpecificationId == spec.MSpecificationId.ToString()))
                                    {
                                        materialSpecificationModels.Add(new MaterialSpecificationModel()
                                        {
                                            MaterialSpecificationId = spec.MSpecificationId.ToString(),
                                            Name = spec.Name,
                                            Seq  = materialSpecificationModels.Count + 1,
                                            MaterialSpecificationOptionModels = context.MSOptions.Where(x => x.MSpecificationId == spec.MSpecificationId).Select(x => new MaterialSpecificationOptionModel
                                            {
                                                MaterialSpecificationOptionId = x.MSpecificationId.ToString(),
                                                Name = x.Name,
                                                Seq  = x.Seq,
                                                MaterialSpecificationId = x.MSpecificationId.ToString()
                                            }).OrderBy(x => x.Name).ToList()
                                        });
                                    }
                                }
                            }
                            else
                            {
                                var availableOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(new Guid(refOrganizationId), true);

                                var downStreamOrganizationIds = OrganizationDataAccessor.GetDownStreamOrganizationIds(new Guid(organizationId), true);

                                foreach (var downStreamOrganization in downStreamOrganizationIds)
                                {
                                    if (availableOrganizationIds.Any(x => x == downStreamOrganization))
                                    {
                                        var specList = context.MSpecifications.Where(x => x.OrganizationId == downStreamOrganization).ToList();

                                        foreach (var spec in specList)
                                        {
                                            if (!materialSpecificationModels.Any(x => x.MaterialSpecificationId == spec.MSpecificationId.ToString()))
                                            {
                                                materialSpecificationModels.Add(new MaterialSpecificationModel()
                                                {
                                                    MaterialSpecificationId = spec.MSpecificationId.ToString(),
                                                    Name = spec.Name,
                                                    Seq  = materialSpecificationModels.Count + 1,
                                                    MaterialSpecificationOptionModels = context.MSOptions.Where(x => x.MSpecificationId == spec.MSpecificationId).Select(x => new MaterialSpecificationOptionModel
                                                    {
                                                        MaterialSpecificationOptionId = x.MSOptionId.ToString(),
                                                        Name = x.Name,
                                                        Seq  = x.Seq,
                                                        MaterialSpecificationId = x.MSpecificationId.ToString()
                                                    }).OrderBy(x => x.Name).ToList()
                                                });
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                materialSpecificationModels = materialSpecificationModels.OrderBy(x => x.Name).ToList();

                result.ReturnData(materialSpecificationModels);
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
コード例 #3
0
        public static RequestResult GetTreeItems(List <Models.Shared.Organization> organizationList, Guid refOrganizationId, Guid organizationId, string materialType)
        {
            RequestResult result = new RequestResult();

            try
            {
                var treeItemList = new List <TreeItem>();

                var attributes = new Dictionary <Define.EnumTreeAttribute, string>()
                {
                    { Define.EnumTreeAttribute.NodeType, string.Empty },
                    { Define.EnumTreeAttribute.ToolTip, string.Empty },
                    { Define.EnumTreeAttribute.OrganizationId, string.Empty },
                    { Define.EnumTreeAttribute.EquipmentType, string.Empty },
                    { Define.EnumTreeAttribute.MaterialId, string.Empty }
                };

                using (CFContext context = new CFContext())
                {
                    if (string.IsNullOrEmpty(materialType))
                    {
                        var materialTypes = context.Materials.Where(x => x.OrganizationId == organizationId).Select(x => x.MaterialType).Distinct().OrderBy(x => x).ToList();

                        foreach (var type in materialTypes)
                        {
                            var treeItem = new TreeItem()
                            {
                                Title = type
                            };

                            attributes[Define.EnumTreeAttribute.NodeType]       = Define.EnumTreeNodeType.EquipmentType.ToString();
                            attributes[Define.EnumTreeAttribute.ToolTip]        = type;
                            attributes[Define.EnumTreeAttribute.OrganizationId] = organizationId.ToString();
                            attributes[Define.EnumTreeAttribute.EquipmentType]  = type;
                            attributes[Define.EnumTreeAttribute.MaterialId]     = string.Empty;

                            foreach (var attribute in attributes)
                            {
                                treeItem.Attributes[attribute.Key.ToString()] = attribute.Value;
                            }

                            treeItem.State = "closed";

                            treeItemList.Add(treeItem);
                        }

                        var availableOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(refOrganizationId, true);

                        var organizations = organizationList.Where(x => x.ParentId == organizationId && availableOrganizationIds.Contains(x.OrganizationId)).OrderBy(x => x.OId).ToList();

                        foreach (var organization in organizations)
                        {
                            var downStreamOrganizationIds = OrganizationDataAccessor.GetDownStreamOrganizationIds(organization.OrganizationId, true);

                            if (context.Materials.Any(x => downStreamOrganizationIds.Contains(x.OrganizationId) && availableOrganizationIds.Contains(x.OrganizationId)))
                            {
                                var treeItem = new TreeItem()
                                {
                                    Title = organization.Name
                                };

                                attributes[Define.EnumTreeAttribute.NodeType]       = Define.EnumTreeNodeType.Organization.ToString();
                                attributes[Define.EnumTreeAttribute.ToolTip]        = string.Format("{0}/{1}", organization.OId, organization.Name);
                                attributes[Define.EnumTreeAttribute.OrganizationId] = organization.OrganizationId.ToString();
                                attributes[Define.EnumTreeAttribute.EquipmentType]  = string.Empty;
                                attributes[Define.EnumTreeAttribute.MaterialId]     = string.Empty;

                                foreach (var attribute in attributes)
                                {
                                    treeItem.Attributes[attribute.Key.ToString()] = attribute.Value;
                                }

                                treeItem.State = "closed";

                                treeItemList.Add(treeItem);
                            }
                        }
                    }
                    else
                    {
                        var materialList = context.Materials.Where(x => x.OrganizationId == organizationId && x.MaterialType == materialType).OrderBy(x => x.MId).ToList();

                        foreach (var material in materialList)
                        {
                            var treeItem = new TreeItem()
                            {
                                Title = material.Name
                            };

                            attributes[Define.EnumTreeAttribute.NodeType]       = Define.EnumTreeNodeType.Material.ToString();
                            attributes[Define.EnumTreeAttribute.ToolTip]        = string.Format("{0}/{1}", material.MId, material.Name);
                            attributes[Define.EnumTreeAttribute.OrganizationId] = material.OrganizationId.ToString();
                            attributes[Define.EnumTreeAttribute.MaterialType]   = material.MaterialType;
                            attributes[Define.EnumTreeAttribute.MaterialId]     = material.MaterialId.ToString();

                            foreach (var attribute in attributes)
                            {
                                treeItem.Attributes[attribute.Key.ToString()] = attribute.Value;
                            }

                            treeItemList.Add(treeItem);
                        }
                    }
                }

                result.ReturnData(treeItemList);
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
コード例 #4
0
        public static RequestResult AddSolution(List <SolutionModel> solutionModels, List <string> selectedList, Guid refOrganizationId)
        {
            RequestResult result = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    foreach (string selected in selectedList)
                    {
                        string[] temp = selected.Split(Define.Seperators, StringSplitOptions.None);

                        var organizationId = temp[0];
                        var solutionType   = temp[1];
                        var solutionId     = temp[2];

                        if (!string.IsNullOrEmpty(solutionId))
                        {
                            if (!solutionModels.Any(x => x.SolutionId == solutionId))
                            {
                                var solution = context.Solutions.First(x => x.SolutionId == new Guid(solutionId));

                                solutionModels.Add(new SolutionModel()
                                {
                                    SolutionId = solution.SolutionId.ToString(),
                                    Type       = solution.Type,
                                    SId        = solution.SId,
                                    Name       = solution.Name
                                });
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(solutionType))
                            {
                                var solutions = context.Solutions.Where(x => x.OrganizationId == new Guid(organizationId) && x.Type == solutionType).ToList();

                                foreach (var solution in solutions)
                                {
                                    if (!solutionModels.Any(x => x.SolutionId == solution.SolutionId.ToString()))
                                    {
                                        solutionModels.Add(new SolutionModel()
                                        {
                                            SolutionId = solution.SolutionId.ToString(),
                                            Type       = solution.Type,
                                            SId        = solution.SId,
                                            Name       = solution.Name
                                        });
                                    }
                                }
                            }
                            else
                            {
                                var availableOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(refOrganizationId, true);

                                var downStreamOrganizationIds = OrganizationDataAccessor.GetDownStreamOrganizationIds(new Guid(organizationId), true);

                                foreach (var downStreamOrganizationId in downStreamOrganizationIds)
                                {
                                    if (availableOrganizationIds.Any(x => x == downStreamOrganizationId))
                                    {
                                        var solutions = context.Solutions.Where(x => x.OrganizationId == downStreamOrganizationId).ToList();

                                        foreach (var solution in solutions)
                                        {
                                            if (!solutionModels.Any(x => x.SolutionId == solution.SolutionId.ToString()))
                                            {
                                                solutionModels.Add(new SolutionModel()
                                                {
                                                    SolutionId = solution.SolutionId.ToString(),
                                                    Type       = solution.Type,
                                                    SId        = solution.SId,
                                                    Name       = solution.Name
                                                });
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                result.ReturnData(solutionModels.OrderBy(x => x.Type).ThenBy(x => x.SId).ToList());
            }
            catch (Exception ex)
            {
                var err = new Error(MethodInfo.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
コード例 #5
0
ファイル: CheckpointDataAccessor.cs プロジェクト: dvcsgit/CF
        public static RequestResult GetTreeItem(List<Models.Shared.Organization> organizations, string refOrganizationId, string organizationId)
        {
            RequestResult result = new RequestResult();

            try
            {
                var treeItemList = new List<TreeItem>();

                var attributes = new Dictionary<Define.EnumTreeAttribute, string>()
                {
                    { Define.EnumTreeAttribute.NodeType, string.Empty },
                    { Define.EnumTreeAttribute.ToolTip, string.Empty },
                    { Define.EnumTreeAttribute.OrganizationId, string.Empty },
                    { Define.EnumTreeAttribute.CheckpointId, string.Empty }
                };

                using (CFContext context = new CFContext())
                {
                    var checkpoints = context.Checkpoints.Where(x => x.OrganizationId == new Guid(organizationId)).OrderBy(x => x.CId).ToList();

                    foreach (var checkpoint in checkpoints)
                    {
                        var treeItem = new TreeItem() { Title = string.Format("{0}/{1}", checkpoint.CId, checkpoint.Name) };

                        attributes[Define.EnumTreeAttribute.NodeType] = Define.EnumTreeNodeType.Checkpoint.ToString();
                        attributes[Define.EnumTreeAttribute.ToolTip] = string.Format("{0}/{1}", checkpoint.CId, checkpoint.Name);
                        attributes[Define.EnumTreeAttribute.OrganizationId ] = organizationId;
                        attributes[Define.EnumTreeAttribute.CheckpointId] = checkpoint.CheckpointId.ToString();

                        foreach (var attribute in attributes)
                        {
                            treeItem.Attributes[attribute.Key.ToString()] = attribute.Value;
                        }

                        treeItemList.Add(treeItem);
                    }

                    var availableOrganizationIds = OrganizationDataAccessor.GetOrganizationPermissions(new Guid(refOrganizationId)).Select(x => x.OrganizationId).ToList();

                    var newOrganizations = organizations.Where(x => x.ParentId == new Guid(organizationId)).OrderBy(x => x.OId).ToList();

                    foreach (var organization in newOrganizations)
                    {
                        var downStreamOrganizationIds = OrganizationDataAccessor.GetDownStreamOrganizationIds(organization.OrganizationId, true);

                        if (context.Checkpoints.Any(x => downStreamOrganizationIds.Contains(x.OrganizationId) && availableOrganizationIds.Contains(x.OrganizationId)))
                        {
                            var treeItem = new TreeItem() { Title = organization.Name };

                            attributes[Define.EnumTreeAttribute.NodeType] = Define.EnumTreeNodeType.Organization.ToString();
                            attributes[Define.EnumTreeAttribute.ToolTip] = string.Format("{0}/{1}", organization.OId, organization.Name);
                            attributes[Define.EnumTreeAttribute.OrganizationId] = organization.OrganizationId.ToString();
                            attributes[Define.EnumTreeAttribute.CheckpointId] = string.Empty;

                            foreach (var attribute in attributes)
                            {
                                treeItem.Attributes[attribute.Key.ToString()] = attribute.Value;
                            }

                            treeItem.State = "closed";

                            treeItemList.Add(treeItem);
                        }
                    }
                }

                result.ReturnData(treeItemList);
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return result;
        }
コード例 #6
0
ファイル: CheckpointDataAccessor.cs プロジェクト: dvcsgit/CF
        public static RequestResult AddCheckItem(List<CheckItemModel> checkItemModels, List<string> selectedList, string refOrganizationId)
        {
            RequestResult result = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    foreach (string selected in selectedList)
                    {
                        string[] temp = selected.Split(Define.Seperators, StringSplitOptions.None);

                        var organizationId = temp[0];
                        var checkType = temp[1];
                        var checkItemId = temp[2];

                        if (!string.IsNullOrEmpty(checkItemId))
                        {
                            if (!checkItemModels.Any(x => x.CheckItemId == checkItemId))
                            {
                                var checkItem = context.CheckItems.First(x => x.CheckItemId == new Guid(checkItemId));

                                checkItemModels.Add(new CheckItemModel()
                                {
                                    CheckItemId = checkItem.CheckItemId.ToString(),
                                    Type = checkItem.Type,
                                    CIId = checkItem.CIId,
                                    Name = checkItem.Name,
                                    IsFeelItem = checkItem.IsFeelItem,
                                    IsAccumulation = checkItem.IsAccumulation,
                                    IsInherit = true,
                                    OriLowerLimit = checkItem.LowerLimit,
                                    OriLowerAlertLimit = checkItem.LowerAlertLimit,
                                    OriUpperAlertLimit = checkItem.UpperAlertLimit,
                                    OriUpperLimit = checkItem.UpperLimit,
                                    OriAccumulationBase = checkItem.AccumulationBase,
                                    OriUnit = checkItem.Unit,
                                    OriRemark = checkItem.Remark
                                });
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(checkType))
                            {
                                var checkItems = context.CheckItems.Where(x => x.OrganizationId == new Guid(organizationId) && x.Type == checkType).ToList();

                                foreach (var checkItem in checkItems)
                                {
                                    if (!checkItemModels.Any(x => x.CheckItemId == checkItem.CheckItemId.ToString()))
                                    {
                                        checkItemModels.Add(new CheckItemModel()
                                        {
                                            CheckItemId = checkItem.CheckItemId.ToString(),
                                            Type = checkItem.Type,
                                            CIId = checkItem.CIId,
                                            Name = checkItem.Name,
                                            IsFeelItem = checkItem.IsFeelItem,
                                            IsAccumulation = checkItem.IsAccumulation,
                                            IsInherit = true,
                                            OriLowerLimit = checkItem.LowerLimit,
                                            OriLowerAlertLimit = checkItem.LowerAlertLimit,
                                            OriUpperAlertLimit = checkItem.UpperAlertLimit,
                                            OriUpperLimit = checkItem.UpperLimit,
                                            OriAccumulationBase = checkItem.AccumulationBase,
                                            OriUnit = checkItem.Unit,
                                            OriRemark = checkItem.Remark
                                        });
                                    }
                                }
                            }
                            else
                            {
                                var availableOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(new Guid(refOrganizationId), true);

                                var downStreamOrganizationIds = OrganizationDataAccessor.GetDownStreamOrganizationIds(new Guid(organizationId), true);

                                foreach (var downStreamOrganizationId in downStreamOrganizationIds)
                                {
                                    if (availableOrganizationIds.Any(x => x == downStreamOrganizationId))
                                    {
                                        var checkItems = context.CheckItems.Where(x => x.OrganizationId == downStreamOrganizationId).ToList();

                                        foreach (var checkItem in checkItems)
                                        {
                                            if (!checkItemModels.Any(x => x.CheckItemId == checkItem.CheckItemId.ToString()))
                                            {
                                                checkItemModels.Add(new CheckItemModel()
                                                {
                                                    CheckItemId = checkItem.CheckItemId.ToString(),
                                                    Type = checkItem.Type,
                                                    CIId = checkItem.CIId,
                                                    Name = checkItem.Name,
                                                    IsFeelItem = checkItem.IsFeelItem,
                                                    IsAccumulation = checkItem.IsAccumulation,
                                                    IsInherit = true,
                                                    OriLowerLimit = checkItem.LowerLimit,
                                                    OriLowerAlertLimit = checkItem.LowerAlertLimit,
                                                    OriUpperAlertLimit = checkItem.UpperAlertLimit,
                                                    OriUpperLimit = checkItem.UpperLimit,
                                                    OriAccumulationBase = checkItem.AccumulationBase,
                                                    OriUnit = checkItem.Unit,
                                                    OriRemark = checkItem.Remark
                                                });
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                checkItemModels = checkItemModels.OrderBy(x => x.Type).ThenBy(x => x.CIId).ToList();

                result.ReturnData(checkItemModels);
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return result;
        }