コード例 #1
0
        public async Task <EquipmentUI> AddOrUpdateEquipment(EquipmentUI ces)
        {
            using (var conn = new SqlConnection(AppSettings.ConnectionString))
            {
                if (ces.Id == 0)
                {
                    //insert new EquipmentModel, get Id
                    var em = new EquipmentModel
                    {
                        ModelId     = ces.ModelId,
                        EquipmentId = ces.Equipment.Id,
                        ParentId    = ces.ParentId,
                        IsMark      = ces.IsMark
                    };
                    var mr = new ModelRepository(_logger);
                    em = await mr.AddEquipmentToModel(em);

                    ces.Id = em.Id;
                }
                else
                {
                    var mr = new ModelRepository(_logger);
                    await mr.UpdateEquipment(new EquipmentModel
                    {
                        EquipmentId = ces.Equipment.Id,
                        Id          = ces.Id,
                        IsMark      = ces.IsMark
                    });
                }

                var shit = await GetEquipmentModelById(ces.Id);

                return(shit);
            }
        }
コード例 #2
0
        public async Task <NewEquipmentUIPaging> GetEquipment(int modelId, int parentId, int skip, int limit)
        {
            using (var conn = new SqlConnection(AppSettings.ConnectionString))
            {
                _logger.LogTrace(
                    $"start GetEquipmentWithCheckLists modelId = {modelId}, parentId = {parentId}, skip = {skip}, limit = {limit}");

                List <EquipmentModel> result;
                int count = 0;
                if (parentId == 0)
                {
                    var sql = Sql.SqlQueryCach["Equipment.GetEquipmentModelByModelAndParentNull"];
                    result = (await conn.QueryAsync <EquipmentModel>(
                                  sql,
                                  new { model_id = modelId, skip = skip, limit = limit, parent_id = parentId })).ToList();

                    var sqlc = Sql.SqlQueryCach["Equipment.CountEquipmentModelByModelAndParentNull"];
                    count = (await conn.QueryAsync <int>(sqlc, new { model_id = modelId })).FirstOrDefault();
                }
                else
                {
                    var sql = Sql.SqlQueryCach["Equipment.GetEquipmentModelByModelAndParent"];
                    result = (await conn.QueryAsync <EquipmentModel>(
                                  sql,

                                  new { model_id = modelId, skip = skip, limit = limit, parent_id = parentId })).ToList();
                    var sqlc = Sql.SqlQueryCach["Equipment.CountEquipmentModelByModelAndParent"];
                    count = (await conn.QueryAsync <int>(sqlc, new { model_id = modelId, parent_id = parentId }))
                            .FirstOrDefault();
                }

                var list = new List <EquipmentUI>();
                foreach (var eqm in result)
                {
                    var eqWithCheckLists = await GetEquipmentModelById(eqm.Id);

                    eqWithCheckLists.ParentId = eqm.ParentId;
                    eqWithCheckLists.Id       = eqm.Id;
                    eqWithCheckLists.ModelId  = eqm.ModelId;
                    eqWithCheckLists.IsMark   = eqm.IsMark;
                    list.Add(eqWithCheckLists);
                }

                var sqlrM = new ModelRepository(_logger);
                var model = await sqlrM.GetById(modelId);

                var ret = new NewEquipmentUIPaging
                {
                    Data  = list.ToArray(),
                    Model = model,
                    Total = count
                };
                return(ret);
            }
        }
コード例 #3
0
        public async Task <CarriageWithEquipment> GetByIdWithEquipment(int id)
        {
            using (var conn = new SqlConnection(AppSettings.ConnectionString))
            {
                var carriage = await GetById(id);

                var mr        = new ModelRepository(_logger);
                var equipment = await mr.GetEquipmentByModel(carriage.Model);

                var sqlr       = new EquipmentRepository(_logger);
                var sqlLabelsR = new LabelRepository();

                var listeq = new List <LocationEquipmentAlgo>();
                foreach (var loc in equipment)
                {
                    string nameFromParent = null;
                    if (loc.ParentId != 0)
                    {
                        nameFromParent = sqlr.GetByParentId(loc.ParentId).Name;
                    }

                    //названия типов чеклистов, прицепленных к данному оборудованию
                    var checkListEquipment = await sqlr.GetCheckListByEquipmentModelId(loc.Id);

                    var algosNameList = (from algo in checkListEquipment.Algorithms
                                         where algo.NameTask != null
                                         select TranslateChecklistType(algo.CheckListType)).ToList();

                    listeq.Add(new LocationEquipmentAlgo
                    {
                        Location  = nameFromParent,
                        Equipment = loc.Equipment.Name,
                        Algorithm = String.Join(", ", algosNameList.Distinct()),
                        Labels    = (await sqlLabelsR.GetByCarriageId(carriage.Id, loc.Id)).ToArray().Select(e => e.Rfid)
                                    .ToArray()
                    });
                }

                var ce = new CarriageWithEquipment
                {
                    Carriage  = carriage,
                    Equipment = listeq.ToArray()
                };

                return(ce);
            }
        }
コード例 #4
0
        public async Task DeleteEquipmentWithCheckLists(CheckListEquipmentUI eq)
        {
            //Начинаем блядь КВН
            using (var transaction = new TransactionScope(asyncFlowOption: TransactionScopeAsyncFlowOption.Enabled))
            {
                using (var conn = new SqlConnection(AppSettings.ConnectionString))
                {
                    var mr = new ModelRepository(_logger);

                    //сначала удалим чеклисты
                    await _DeleteCheckListsFromEquipment(eq.Id);

                    //затем связку с моделями
                    await mr.DeleteEquipmentFromModel(eq.Id);
                }

                transaction.Complete();
            }
        }
コード例 #5
0
        public async Task <EquipmentUIPaging> GetEquipmentWithCheckLists(int modelId, int parentId, int skip, int limit,
                                                                         string filter)
        {
            using (var conn = new SqlConnection(AppSettings.ConnectionString))
            {
                var all = await GetEquipmentWithCheckLists(modelId, parentId, 0, Int32.MaxValue);

                var filters = JsonConvert.DeserializeObject <Other.Other.FilterBody[]>(filter);
                var list    = new List <CheckListEquipmentUI>();
                foreach (var itemAll in all.Data)
                {
                    if (itemAll.Equipment.Name.ToLower().Contains(filters.FirstOrDefault().Value.ToLower()))
                    {
                        list.Add(itemAll);
                    }
                }

                var listSkiplimit = new List <CheckListEquipmentUI>();
                if (skip < list.Count)
                {
                    if (limit + skip > list.Count)
                    {
                        limit = list.Count - skip;
                    }
                    for (int i = skip; i < limit + skip; i++)
                    {
                        listSkiplimit.Add(list[i]);
                    }
                }

                var sqlrM = new ModelRepository(_logger);
                var model = await sqlrM.GetById(modelId);

                var result = new EquipmentUIPaging
                {
                    Data  = listSkiplimit.ToArray(),
                    Model = model,
                    Total = list.Count
                };
                return(result);
            }
        }
コード例 #6
0
        public async Task <CheckListEquipmentUI> AddOrUpdateEquipmentWithCheckLists(CheckListEquipmentUI ces)
        {
            if (ces == null)
            {
                throw new Exception("Не указано наименование");
            }

            //Начинаем блядь КВН
            using (var transaction = new TransactionScope(asyncFlowOption: TransactionScopeAsyncFlowOption.Enabled))
            {
                using (var conn = new SqlConnection(AppSettings.ConnectionString))
                {
                    if (ces.Id == 0)
                    {
                        //insert new EquipmentModel, get Id
                        var em = new EquipmentModel
                        {
                            ModelId     = ces.ModelId,
                            EquipmentId = ces.Equipment.Id,
                            ParentId    = ces.ParentId,
                            IsMark      = ces.IsMark
                        };
                        var mr = new ModelRepository(_logger);
                        em = await mr.AddEquipmentToModel(em);

                        ces.Id         = em.Id;
                        ces.Algorithms = new List <Algorithm>().ToArray();
                    }
                    else
                    {
                        var mr = new ModelRepository(_logger);
                        await mr.UpdateEquipment(new EquipmentModel
                        {
                            EquipmentId = ces.Equipment.Id,
                            Id          = ces.Id,
                            IsMark      = ces.IsMark
                        });
                    }

                    //
                    var listAdded = new List <CheckListType>();
                    foreach (var algo in ces.Algorithms)
                    {
                        //if (string.IsNullOrEmpty(algo.NameTask) || algo.FaultType == null)
                        //    throw new Exception("Не заполнены Алгоритмы");
                        if (string.IsNullOrEmpty(algo.NameTask) || algo.Value == null || algo.ValueType == null)
                        {
                            continue;
                        }

                        await AddOrUpdateCheckListToEquipment(ces.Id, algo);

                        listAdded.Add(algo.CheckListType);
                    }

                    foreach (CheckListType cType in Enum.GetValues(typeof(CheckListType)))
                    {
                        if (cType == CheckListType.Surrender)
                        {
                            continue;
                        }

                        var already = listAdded.Where(item => item == cType).ToList();
                        if (already.Count == 0)
                        {
                            await DeleteCheckListFromEquipment(new CheckListEquipment
                            {
                                CheckListType    = cType,
                                EquipmentModelId = ces.Id
                            });

                            /*var algo = new Algorithm
                             * {
                             *  CheckListType = cType
                             * };
                             * await AddOrUpdateCheckListToEquipment(ces.Id, algo);*/
                        }
                    }

                    var shit = await GetCheckListByEquipmentModelId(ces.Id);

                    transaction.Complete();
                    return(shit);
                }
            }
        }
コード例 #7
0
        public async Task <ReportPagingUI> GetReportEquipmentTaskHistory(int skip, int limit, string filter, string orderby)
        {
            using (var conn = new SqlConnection(AppSettings.ConnectionString))
            {
                CreateFilter(filter, out string sqlfilter);
                CreateOrderBy(orderby, out string sqlorderby);
                var result = (await conn.QueryAsync <TrainTaskReport1>(
                                  $"{ReportCommon.Sql2Select} {ReportCommon.Sql2Common} {sqlfilter} {sqlorderby} {ReportCommon.Sql2End}",
                                  new[]
                {
                    typeof(TrainTaskReport1), typeof(Carriage), typeof(Train), typeof(EquipmentModel),
                    typeof(Equipment)
                },
                                  objects =>
                {
                    var task = (TrainTaskReport1)objects[0];
                    task.Carriage = (Carriage)objects[1];
                    task.Carriage.Train = (Train)objects[2];
                    task.EquipmentModel = (EquipmentModel)objects[3];
                    task.EquipmentModel.Equipment = (Equipment)objects[4];
                    return(task);
                }, new { skip = skip, limit = limit }
                                  )).ToArray();

                var sqlc  = $"{TaskCommon.SqlCount} {TaskCommon.SqlCommon}";
                var count = conn.ExecuteScalar <int>(sqlc);

                var columns = new List <ReportColumnsUI>
                {
                    new ReportColumnsUI
                    {
                        Name  = "Номер",
                        Type  = "int",
                        Alias = "TaskId"
                    },
                    new ReportColumnsUI
                    {
                        Name  = "Состав",
                        Type  = "string",
                        Alias = "TrainName"
                    },
                    new ReportColumnsUI
                    {
                        Name  = "Вагон",
                        Type  = "string",
                        Alias = "CarriageName"
                    },
                    new ReportColumnsUI
                    {
                        Name  = "Наименование оборудования",
                        Type  = "string",
                        Alias = "EquipmentName"
                    },
                    new ReportColumnsUI
                    {
                        Name  = "Тип инцидента",
                        Type  = "string",
                        Alias = "TaskTypeId"
                    },
                    new ReportColumnsUI
                    {
                        Name  = "Время создания инцидента",
                        Type  = "date",
                        Alias = "CreateDate"
                    },
                    new ReportColumnsUI
                    {
                        Name  = "Время закрытия инцидента",
                        Type  = "date",
                        Alias = "CloseDate"
                    },
                };


                var sqlRmodel = new ModelRepository(_logger);
                foreach (var item in result)
                {
                    var carriageTypeId = (int)(await sqlRmodel.GetById(item.Carriage.ModelId)).ModelType;
                    if (carriageTypeId == 0)
                    {
                        item.CarriageTypeString = Other.Other.CarriageTypeString.HeadVagon;
                    }

                    if (carriageTypeId == 1)
                    {
                        item.CarriageTypeString = Other.Other.CarriageTypeString.TractionVagon;
                    }

                    if (carriageTypeId == 2)
                    {
                        item.CarriageTypeString = Other.Other.CarriageTypeString.TrailerVagon;
                    }
                }


                var ret = new ReportPagingUI
                {
                    Columns = columns.ToArray(),
                    Rows    = result.Select(row => new List <string>
                    {
                        row.Id.ToString(),
                        row.Carriage.Train.Name,
                        row.Carriage.Serial + " (" + row.Carriage.Number + ", " + row.CarriageTypeString + ")",
                        row.EquipmentModel.Equipment.Name,
                        _TaskTypeEnumToString(row.TaskType),
                        row.CreateDate.ToString(),
                        row.UpdateDate.ToString()
                    })
                              .Select(vals => new ReportValuesUI
                    {
                        Values = vals.ToArray()
                    }).ToArray(),
                    Total = count
                };

                return(ret);
            }
        }