Exemplo n.º 1
0
        public static RequestResult GetDetailViewModel(string solutionId, Account account)
        {
            RequestResult result = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var solution = context.Solutions.First(x => x.SolutionId == new Guid(solutionId));

                    result.ReturnData(new DetailViewModel()
                    {
                        SolutionId                 = solution.SolutionId.ToString(),
                        Permission                 = account.OrganizationPermission(solution.OrganizationId),
                        OrganizationId             = solution.OrganizationId.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(solution.OrganizationId),
                        SolutionType               = solution.Type,
                        SId  = solution.SId,
                        Name = solution.Name
                    });
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Exemplo n.º 2
0
        public static RequestResult GetDetailViewModel(string abnormalReasonId, Account account)
        {
            RequestResult result = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var abnormalReason = context.AbnormalReasons.Include("Solutions").First(x => x.AbnormalReasonId == new Guid(abnormalReasonId));

                    result.ReturnData(new DetailViewModel()
                    {
                        AbnormalReasonId           = abnormalReason.AbnormalReasonId.ToString(),
                        Permission                 = account.OrganizationPermission(abnormalReason.OrganizationId),
                        OrganizationId             = abnormalReason.OrganizationId.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(abnormalReason.OrganizationId),
                        Type          = abnormalReason.Type,
                        ARId          = abnormalReason.ARId,
                        Name          = abnormalReason.Name,
                        SolutionNames = abnormalReason.Solutions.Select(x => x.Name).ToList()
                    });
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Exemplo n.º 3
0
        public static RequestResult GetDetailViewModel(string equipmentSpecificationId, Account account)
        {
            RequestResult result = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var specification = context.ESpecifications.First(x => x.ESpecificationId == new Guid(equipmentSpecificationId));

                    result.ReturnData(new DetailViewModel()
                    {
                        EquipmentSpecificationId = specification.ESpecificationId.ToString(),
                        Permission                 = account.OrganizationPermission(specification.OrganizationId),
                        OrganizationId             = specification.OrganizationId.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(specification.OrganizationId),
                        EquipmentType              = specification.EquipmentType,
                        Name = specification.Name,
                        EquipmentSpecificationOptonNameList = context.ESOptions.Where(x => x.ESpecificationId == specification.ESpecificationId).OrderBy(x => x.Seq).Select(x => x.Name).ToList()
                    });
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Exemplo n.º 4
0
        public static RequestResult GetCopyFormModel(string abnormalReasonId)
        {
            RequestResult result = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var abnormalReason = context.AbnormalReasons.Include("Solutions").First(x => x.AbnormalReasonId == new Guid(abnormalReasonId));

                    var model = new CreateFormModel()
                    {
                        OrganizationId             = abnormalReason.OrganizationId.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(abnormalReason.OrganizationId),
                        Types = new List <SelectListItem>()
                        {
                            Define.DefaultSelectListItem(Resources.Resource.Select),
                            new SelectListItem()
                            {
                                Text  = Resources.Resource.Create + "...",
                                Value = Define.New
                            }
                        },
                        SolutionModels = abnormalReason.Solutions.Select(x => new SolutionModel
                        {
                            SolutionId = x.SolutionId.ToString(),
                            Type       = x.Type,
                            SId        = x.SId,
                            Name       = x.Name,
                        }).OrderBy(x => x.Type).ThenBy(x => x.SId).ToList(),
                        FormInput = new FormInput()
                        {
                            Type = abnormalReason.Type
                        }
                    };

                    var upStreamOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(abnormalReason.OrganizationId, true);

                    model.Types.AddRange(context.AbnormalReasons.Where(x => upStreamOrganizationIds.Contains(x.OrganizationId)).Select(x => x.Type).Distinct().OrderBy(x => x).Select(x => new SelectListItem
                    {
                        Value = x,
                        Text  = x
                    }).ToList());

                    model.Types.First(x => x.Value == abnormalReason.Type).Selected = true;

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

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Exemplo n.º 5
0
        public static RequestResult GetEditFormModel(string solutionId)
        {
            RequestResult result = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var solution = context.Solutions.First(x => x.SolutionId == new Guid(solutionId));

                    var model = new EditFormModel()
                    {
                        SolutionId                 = solution.SolutionId.ToString(),
                        OrganizationId             = solution.OrganizationId.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(solution.OrganizationId),
                        SolutionTypes              = new List <SelectListItem>()
                        {
                            Define.DefaultSelectListItem(Resources.Resource.Select),
                            new SelectListItem()
                            {
                                Text  = Resources.Resource.Create + "...",
                                Value = Define.New
                            }
                        },
                        FormInput = new FormInput()
                        {
                            Type = solution.Type,
                            SId  = solution.SId,
                            Name = solution.Name
                        }
                    };

                    var upStreamOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(new Guid(model.OrganizationId), true);

                    model.SolutionTypes.AddRange(context.Solutions.Where(x => upStreamOrganizationIds.Contains(x.OrganizationId)).Select(x => x.Type).Distinct().OrderBy(x => x).Select(x => new SelectListItem
                    {
                        Value = x,
                        Text  = x
                    }).ToList());

                    if (!string.IsNullOrEmpty(model.FormInput.Type) && model.SolutionTypes.Any(x => x.Value == model.FormInput.Type))
                    {
                        model.SolutionTypes.First(x => x.Value == model.FormInput.Type).Selected = true;
                    }

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

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Exemplo n.º 6
0
        public static RequestResult GetDetailViewModel(string checkpointId, Account account)
        {
            RequestResult result = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var checkpoint = context.Checkpoints.Include("CheckItems").First(x => x.CheckpointId == new Guid(checkpointId));

                    result.ReturnData(new DetailViewModel()
                    {
                        CheckpointId = checkpoint.CheckpointId.ToString(),
                        Permission = account.OrganizationPermission(checkpoint.OrganizationId),
                        OrganizationUniqueID = checkpoint.OrganizationId.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(checkpoint.OrganizationId),
                        CId = checkpoint.CId,
                        Name = checkpoint.Name,
                        IsFeelItemDefaultNormal = checkpoint.IsFeelItemDefaultNormal,
                        TagId = checkpoint.TagId,
                        Remark = checkpoint.Remark,
                        CheckItemModels = checkpoint.CheckItems.Select(x=>new CheckItemModel()
                        {
                            CheckItemId=x.CheckItemId.ToString(),
                            CIId=x.CIId,
                            Name=x.Name,
                            Type=x.Type,
                            IsFeelItem=x.IsFeelItem,
                            IsAccumulation=x.IsAccumulation,
                            IsInherit=x.IsInherit,
                            OriLowerLimit=x.LowerLimit,
                            OriLowerAlertLimit=x.LowerAlertLimit,
                            OriUpperAlertLimit=x.UpperAlertLimit,
                            OriUpperLimit=x.UpperLimit,
                            OriAccumulationBase=x.AccumulationBase,
                            OriUnit=x.Unit,
                            OriRemark=x.Remark,
                            LowerLimit=x.LowerLimit,
                            LowerAlertLimit=x.LowerAlertLimit,
                            UpperAlertLimit=x.UpperAlertLimit,
                            UpperLimit=x.UpperLimit,
                            AccumulationBase=x.AccumulationBase,
                            Unit=x.Unit,
                            Remark=x.Remark
                        }).OrderBy(x=>x.Type).ThenBy(x=>x.CIId).ToList()
                    });
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return result;
        }
Exemplo n.º 7
0
        public static RequestResult GetCopyFormModel(string equipmentSpecificationId)
        {
            RequestResult result = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var spec = context.ESpecifications.First(x => x.ESpecificationId == new Guid(equipmentSpecificationId));

                    var model = new CreateFormModel()
                    {
                        OrganizationId             = spec.OrganizationId.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(spec.OrganizationId),
                        EquipmentTypeSelectItems   = new List <SelectListItem>()
                        {
                            Define.DefaultSelectListItem(Resources.Resource.Select),
                            new SelectListItem()
                            {
                                Text  = string.Format("{0}...", Resources.Resource.Create),
                                Value = Define.New
                            }
                        },
                        FormInput = new FormInput()
                        {
                            EquipmentType = spec.EquipmentType
                        },
                        EquipmentSpecificationOptionModels = context.ESOptions.Where(x => x.ESpecificationId == spec.ESpecificationId).Select(x => new EquipmentSpecificationOptionModel
                        {
                            Name = x.Name,
                            Seq  = x.Seq
                        }).OrderBy(x => x.Seq).ToList()
                    };

                    var upStreamOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(spec.OrganizationId, true);

                    model.EquipmentTypeSelectItems.AddRange(context.ESpecifications.Where(x => upStreamOrganizationIds.Contains(x.OrganizationId)).Select(x => x.EquipmentType).Distinct().OrderBy(x => x).Select(x => new SelectListItem
                    {
                        Value = x,
                        Text  = x
                    }).ToList());

                    model.EquipmentTypeSelectItems.First(x => x.Value == spec.EquipmentType).Selected = true;

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

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Exemplo n.º 8
0
        public ActionResult Create(string orgnaizationId)
        {
            Session["ControlPointFormAction"]      = Define.EnumFormAction.Create;
            Session["ControlPointCreateFormModel"] = new CreateFormModel()
            {
                OrganizationId             = orgnaizationId,
                ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(new Guid(orgnaizationId))
            };

            return(PartialView("_Create", Session["ControlPointCreateFormModel"]));
        }
Exemplo n.º 9
0
        public static RequestResult GetCreateFormModel(string organizationId, string materialType)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var createFormModel = new CreateFormModel()
                    {
                        OrganizationId             = organizationId,
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(new Guid(organizationId)),
                        MaterialTypeSelectItems    = new List <SelectListItem>()
                        {
                            Define.DefaultSelectListItem(Resources.Resource.Select),
                            new SelectListItem()
                            {
                                Text  = string.Format("{0}...", Resources.Resource.Create),
                                Value = Define.New
                            }
                        },
                        FormInput = new FormInput()
                        {
                            MaterialType = materialType
                        }
                    };

                    var upStreamOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(new Guid(organizationId), true);

                    createFormModel.MaterialTypeSelectItems.AddRange(context.MSpecifications.Where(x => upStreamOrganizationIds.Contains(x.OrganizationId)).Select(x => x.MaterialType).Distinct().OrderBy(x => x).Select(x => new SelectListItem
                    {
                        Value = x,
                        Text  = x
                    }).ToList());

                    if (!string.IsNullOrEmpty(materialType) && createFormModel.MaterialTypeSelectItems.Any(x => x.Value == materialType))
                    {
                        createFormModel.MaterialTypeSelectItems.First(x => x.Value == materialType).Selected = true;
                    }

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

                Logger.Log(err);

                requestResult.ReturnError(err);
            }

            return(requestResult);
        }
Exemplo n.º 10
0
        public static RequestResult GetDetailViewModel(string materialId, Account account)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var material = context.Materials.Include("MaterialSpecificationOptions").Where(m => m.MaterialId == new Guid(materialId)).FirstOrDefault();
                    var materialSpecificationIds = material.MaterialSpecificationOptions.Select(ms => ms.MSpecificationId);

                    var detailViewModel = new DetailViewModel()
                    {
                        Permission             = account.OrganizationPermission(material.OrganizationId),
                        MaterialId             = material.MaterialId.ToString(),
                        OrganizationId         = material.OrganizationId.ToString(),
                        ParentOrganizationName = OrganizationDataAccessor.GetOrganizationFullName(material.OrganizationId),
                        MaterialType           = material.MaterialType,
                        MId          = material.MId,
                        MaterialName = material.Name,
                        Quantity     = material.Quantity,
                        MaterialSpecificationModels = context.MSpecifications.Where(ms => materialSpecificationIds.Contains(ms.MSpecificationId)).Select(ms => new MaterialSpecificationModel
                        {
                            MaterialSpecificationId = ms.MSpecificationId.ToString(),
                            Name = ms.Name,
                            MaterialSpecificationOptionId = context.MaterialSpecificationOptions.Where(x => x.MSpecificationId == ms.MSpecificationId).Select(x => x.MSOptionId).FirstOrDefault().ToString(),
                            Value = context.MaterialSpecificationOptions.Where(x => x.MSpecificationId == ms.MSpecificationId).Select(x => x.Value).FirstOrDefault().ToString(),
                            Seq   = context.MaterialSpecificationOptions.Where(x => x.MSpecificationId == ms.MSpecificationId).Select(x => x.Seq).FirstOrDefault(),
                            MaterialSpecificationOptionModels = context.MSOptions.Where(x => x.MSpecificationId == ms.MSpecificationId).Select(mso => new MaterialSpecificationOptionModel
                            {
                                MaterialSpecificationOptionId = mso.MSOptionId.ToString(),
                                MaterialSpecificationId       = mso.MSpecificationId.ToString(),
                                Name = mso.Name,
                                Seq  = mso.Seq
                            }).OrderBy(mso => mso.Seq).ToList()
                        }).OrderBy(ms => ms.Seq).ToList()
                    };

                    //
                    requestResult.ReturnData(detailViewModel);
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(requestResult);
        }
Exemplo n.º 11
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.ESpecifications.Where(x => downStreamOrganizationIds.Contains(x.OrganizationId) && account.QueryableOrganizationIds.Contains(x.OrganizationId)).AsQueryable();

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

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

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

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Exemplo n.º 12
0
        public static RequestResult GetCopyFormModel(Guid materialId)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var material = context.Materials.First(x => x.MaterialId == materialId);

                    var createFormModel = new CreateFormModel()
                    {
                        OrganizationId             = material.OrganizationId.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(material.OrganizationId),
                        MaterialTypeSelectItems    = new List <SelectListItem>()
                        {
                            Define.DefaultSelectListItem(Resources.Resource.Select),
                            new SelectListItem()
                            {
                                Text  = Resources.Resource.Create + "...",
                                Value = Define.New
                            }
                        },
                        FormInput = new FormInput()
                        {
                            MaterialType = material.MaterialType
                        },
                        MaterialSpecificationModels = (from x in context.MaterialSpecificationOptions
                                                       join s in context.MSpecifications
                                                       on x.MSpecificationId equals s.MSpecificationId
                                                       where x.MaterialId == material.MaterialId
                                                       select new MaterialSpecificationModel
                        {
                            MaterialSpecificationId = s.MSpecificationId.ToString(),
                            Name = s.Name,
                            MaterialSpecificationOptionId = x.MSOptionId.ToString(),
                            Value = x.Value,
                            Seq = x.Seq,
                            MaterialSpecificationOptionModels = context.MSOptions.Where(o => o.MSpecificationId == s.MSpecificationId).Select(o => new MaterialSpecificationOptionModel
                            {
                                MaterialSpecificationId = o.MSpecificationId.ToString(),
                                Seq = o.Seq,
                                Name = o.Name,
                                MaterialSpecificationOptionId = o.MSOptionId.ToString()
                            }).OrderBy(o => o.Seq).ToList()
                        }).OrderBy(x => x.Seq).ToList()
                    };

                    var upStreamOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(material.OrganizationId, true);

                    createFormModel.MaterialTypeSelectItems.AddRange(context.Materials.Where(x => upStreamOrganizationIds.Contains(x.OrganizationId)).Select(x => x.MaterialType).Distinct().OrderBy(x => x).Select(x => new SelectListItem
                    {
                        Value = x,
                        Text  = x
                    }).ToList());

                    createFormModel.MaterialTypeSelectItems.First(x => x.Value == material.MaterialType).Selected = true;

                    requestResult.ReturnData(createFormModel);
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);

                Logger.Log(error);

                requestResult.ReturnError(error);
            }

            return(requestResult);
        }
Exemplo n.º 13
0
        public static RequestResult GetEditFormModel(string materialSpecificationId)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var specification = context.MSpecifications.First(x => x.MSpecificationId == new Guid(materialSpecificationId));

                    var editFormModel = new EditFormModel()
                    {
                        MaterialSpecificationId    = specification.MSpecificationId.ToString(),
                        OrganizationId             = specification.OrganizationId.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(specification.OrganizationId),
                        MaterialTypeSelectItems    = new List <SelectListItem>()
                        {
                            Define.DefaultSelectListItem(Resources.Resource.Select),
                            new SelectListItem()
                            {
                                Text  = string.Format("{0}...", Resources.Resource.Create),
                                Value = Define.New
                            }
                        },
                        FormInput = new FormInput()
                        {
                            MaterialType = specification.MaterialType,
                            Name         = specification.Name
                        },
                        MaterialSpecificationOptionModels = context.MSOptions.Where(x => x.MSpecificationId == specification.MSpecificationId).Select(x => new MaterialSpecificationOptionModel
                        {
                            MaterialSpecificationOptionId = x.MSOptionId.ToString(),
                            Name = x.Name,
                            Seq  = x.Seq
                        }).OrderBy(x => x.Seq).ToList()
                    };

                    var upStreamOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(specification.OrganizationId, true);

                    editFormModel.MaterialTypeSelectItems.AddRange(context.MSpecifications.Where(x => upStreamOrganizationIds.Contains(x.OrganizationId)).Select(x => x.MaterialType).Distinct().OrderBy(x => x).Select(x => new SelectListItem
                    {
                        Value = x,
                        Text  = x
                    }).ToList());

                    if (!string.IsNullOrEmpty(specification.MaterialType) && editFormModel.MaterialTypeSelectItems.Any(x => x.Value == specification.MaterialType))
                    {
                        editFormModel.MaterialTypeSelectItems.First(x => x.Value == specification.MaterialType).Selected = true;
                    }

                    requestResult.ReturnData(editFormModel);
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);

                Logger.Log(error);

                requestResult.ReturnError(error);
            }

            return(requestResult);
        }