예제 #1
0
 /// <summary>
 /// 创建日期:2016/11/08
 /// 根据题干编码 ,初始化题支信息集合
 /// </summary>
 /// <param name="StemCode">题干编码</param>
 /// <param name="context"></param>
 private void InitOption(string StemCode, HttpContext context)
 {
     try
     {
         DataTable SourceTemp = new DataTable();
         SourceTemp = MgrServices.DistributeRecordService.GetProblem(StemCode);//题支数据集合
         if (SourceTemp != null && SourceTemp.Rows.Count > 0)
         {
             OptionEntity        option = new OptionEntity();
             List <OptionEntity> List_T = new List <OptionEntity>();
             foreach (DataRow DTR in SourceTemp.Rows)
             {
                 option             = new OptionEntity();
                 option.IndexNumber = DTR["OperationNum"].ToString();
                 option.OptionCode  = DTR["OperationCode"].ToString();
                 option.Content     = DTR["OperationContent"].ToString();
                 option.Faction     = Convert.ToInt32(DTR["OperationFraction"].ToString());
                 List_T.Add(option);
             }
             context.Response.Write(new JavaScriptSerializer().Serialize(List_T));
         }
     }
     catch
     { }
 }
        public async Task <OptionEntity> Create(CreateOptionModel model)
        {
            if (GetQuery().Any(
                    o => o.Code == model.Code.Trim() &&
                    o.Name == model.Name.Trim() &&
                    o.Value == model.Value
                    ))
            {
                throw new BadRequestException("This option combination already exists.");
            }
            var option = new OptionEntity
            {
                Code  = model.Code.Trim(),
                Name  = model.Name.Trim(),
                Value = model.Value.Trim(),
                ManufacturerEntityId = model.ManufacturerEntityId,
                Price        = model.Price,
                QtyStock     = model.QtyStock,
                CreateUserId = model.CreateUserId,
                CreateDate   = DateTime.UtcNow.ToLocalTime(),
                ModifyUserId = model.ModifyUserId,
                ModifyDate   = DateTime.UtcNow.ToLocalTime(),
                StatusId     = 1
            };

            _unitOfWork.Add(option);
            await _unitOfWork.CommitAsync();

            return(option);
        }
예제 #3
0
        /// <summary>
        /// Converts all enums into a List<SelectListItem> holder and cache it.
        /// after converting, returns the current OptionEntity as List<SelectListItem>
        /// </summary>
        /// <param name="entity">Current OptionEntity</param>
        /// <param name="entities">All OptionEntity</param>
        public static List <SelectListItem> CreateEnum(OptionEntity entity, List <OptionEntity> entities)
        {
            if (_selectItemsHolder != null)
            {
                return(RefreshHolder(entity));
            }

            _selectItemsHolder = new Dictionary <string, List <SelectListItem> >();

            var type = OptionHelper.Type;

            var optionEnums = type.GetProperties().Where(t => t.PropertyType.IsEnum);

            foreach (var entityEnum in entities.Where(e => e.Type == "Enum").ToList())
            {
                foreach (var optionEnum in optionEnums)
                {
                    if (optionEnum.Name == entityEnum.Key)
                    {
                        _selectItemsHolder.Add(entityEnum.Key, EnumToSelectedListItem(optionEnum.PropertyType, entity));
                        break;
                    }
                }
            }

            return(_selectItemsHolder[entity.Key]);
        }
예제 #4
0
        public async Task <OptionEntity> UpsertOption(OptionEntityCache cache, OptionEntity option)
        {
            // TODO: [TESTS] (OptionsService.UpsertOption) Add tests
            var category  = option.OptionCategory;
            var optionKey = option.OptionKey;
            var userId    = option.UserId;
            var dbOption  = cache.GetCachedEntry(option)
                            ?? await _optionRepo.GetRawOption(category, optionKey, userId);

            if (dbOption == null)
            {
                if (await _optionRepo.Add(option) == 0)
                {
                    return(null);
                }
            }
            else
            {
                option.OptionId = dbOption.OptionId;
                option.UserId   = dbOption.UserId;

                if (await _optionRepo.Update(option) == 0)
                {
                    return(null);
                }
            }

            dbOption = await _optionRepo.GetRawOption(category, optionKey, userId);

            cache.CacheEntry(dbOption);
            return(dbOption);
        }
예제 #5
0
 public ActionResult SaveForm(string keyValue, OptionEntity entity)
 {
     if (!string.IsNullOrEmpty(Utils.GetCookie("property_id")))
     {
         entity.property_id = Utils.GetCookie("property_id");
     }
     optionbll.SaveForm(keyValue, entity);
     return(Success("操作成功。"));
 }
예제 #6
0
 private static Option Translate(OptionEntity source)
 {
     return(new Option
     {
         Id = source.Id,
         Name = source.Name,
         Content = source.Content
     });
 }
예제 #7
0
 /// <summary>
 /// 保存表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="entity">实体对象</param>
 /// <returns></returns>
 public void SaveForm(string keyValue, OptionEntity entity)
 {
     try
     {
         service.SaveForm(keyValue, entity);
     }
     catch (Exception)
     {
         throw;
     }
 }
예제 #8
0
        /// <summary>
        /// On known option selected
        /// </summary>
        /// <param name="dialogueId"></param>
        /// <param name="optionId"></param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public RuntimeBuilder OnOptionContinuing(string dialogueId, int optionNo, Action <DialogueRuntime, CurrentDialogue, OptionSelection> callback)
        {
            OptionEntity option = dialogueTree.GetDialogue(dialogueId).options[optionNo - 1];

            if (!listenerRegistry.KnownOptionSelectionListeners.ContainsKey(option.id))
            {
                listenerRegistry.KnownOptionSelectionListeners[option.id] = new List <Action <DialogueRuntime, CurrentDialogue, OptionSelection> >();
            }

            listenerRegistry.KnownOptionSelectionListeners[option.id].Add(callback);

            return(this);
        }
예제 #9
0
        // Public methods
        public void CacheEntry(OptionEntity option)
        {
            // TODO: [TESTS] (DbPolicyRuleCache.CacheEntry) Add tests
            if (option == null)
            {
                return;
            }

            _cache.AddOrUpdate(
                GenerateKey(option),
                option,
                (key, oldValue) => option
                );
        }
예제 #10
0
        // Privates

        /// <summary>
        /// When _selectItemsHolder has data, we use it instead of recreating SelectListItems.
        /// but maybe the selected item has been changed in every enum. so we should refresh the holder
        /// </summary>
        private static List <SelectListItem> RefreshHolder(OptionEntity entity)
        {
            _selectItemsHolder[entity.Key].ForEach(a =>
            {
                if (a.Value == entity.Value)
                {
                    a.Selected = true;
                }
                else
                {
                    a.Selected = false;
                }
            });
            return(_selectItemsHolder[entity.Key]);
        }
예제 #11
0
    /// <summary>
    /// 从json中解析问题
    /// </summary>
    /// <returns></returns>
    public static void ParseQuestions()
    {
        if (qes != null)
        {
            return;
        }
        qes = new List <QuestionEntity>();
        TextAsset file = Resources.Load("QuestionCollections") as TextAsset;

        if (file == null)
        {
            Debug.LogError("QuestionCollections" + "资源不存在");
            return;
        }

        JSONNode node = JSON.Parse(file.text);

        //Debug.Log("node.Count: " + node.Count);
        for (int i = 0; i < node.Count; i++)
        {
            QuestionEntity qe = new QuestionEntity();
            qe.questionId   = node[i]["questionId"].AsInt;
            qe.questionName = node[i]["questionName"].AsString;
            qe.point        = node[i]["point"].AsInt;
            qe.dubStr       = node[i]["dubStr"].AsString;
            //Debug.Log("--qe: " + qe.questionId + " " + qe.questionName);

            JSONArray options = node[i]["options"].AsArray;
            qe.options = new List <OptionEntity>();
            for (int j = 0; j < options.Count; j++)
            {
                OptionEntity oe = new OptionEntity();
                oe.optionId   = options[j]["optionId"].AsInt;
                oe.optionName = options[j]["optionName"].AsString;
                //Debug.Log("----oe: " + oe.optionId + " " + oe.optionName);
                qe.options.Add(oe);
            }

            JSONArray answers = node[i]["answers"].AsArray;
            qe.answers = new List <int>();
            for (int k = 0; k < answers.Count; k++)
            {
                //Debug.Log("----answer: " + answers[k]);
                qe.answers.Add(answers[k].AsInt);
            }
            qes.Add(qe);
        }
    }
예제 #12
0
        private static List <SelectListItem> EnumToSelectedListItem(Type enumType, OptionEntity entity)
        {
            List <SelectListItem> selectListItems = new List <SelectListItem>();

            foreach (var item in enumType.GetFields(BindingFlags.Public | BindingFlags.Static))
            {
                var value = item.GetValue();
                selectListItems.Add(new SelectListItem()
                {
                    Text     = item.GetDisplay(),
                    Value    = value,
                    Selected = entity.Value == value
                });
            }
            return(selectListItems);
        }
예제 #13
0
        /// <summary>
        /// 生成
        /// </summary>
        /// <param name="jsonParam"></param>
        /// <returns></returns>
        public bool SaveContractIncomeForm(string jsonParam)
        {
            try
            {
                var jsonObj = jsonParam.ToJObject();

                DbParameter[] parameter2 =
                {
                    DbParameters.CreateDbParameter("@propertyid", jsonObj["propertyID"].ToString()),
                    DbParameters.CreateDbParameter("@dtyear",     jsonObj["sel_year"].ToString()),
                    DbParameters.CreateDbParameter("@dtmonth",    jsonObj["sel_month"].ToString())
                };

                this.BaseRepository().ExecuteByProc("CreateContractIncomeCheck", parameter2);

                string         safeSql       = string.Empty;
                OptionIService optionService = new OptionService();
                OptionEntity   option        = optionService.GetEntity(jsonObj["propertyID"].ToString());
                if (option != null)
                {
                    safeSql = "update wy_option set option_exchange=@optionValue,option_point=@optionPoint where property_id=@propertyID";
                }
                else
                {
                    safeSql = "insert into wy_option(property_id,option_exchange,option_point) values (@propertyID,@optionValue,@optionPoint)";
                }

                DbParameter[] parameter =
                {
                    DbParameters.CreateDbParameter("@propertyID",  jsonObj["propertyID"].ToString()),
                    DbParameters.CreateDbParameter("@optionValue", jsonObj["option_exchange"].ToString()),
                    DbParameters.CreateDbParameter("@optionPoint", jsonObj["option_point"].ToString())
                };

                return(this.BaseRepository().ExecuteBySql(safeSql, parameter) > 0 ? true : false);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
예제 #14
0
    // Public methods
    public void AddOption(OptionEntity option)
    {
      // TODO: [TESTS] (RawOptions.AddOption) Add tests
      var dictionaryKey = GenerateDictionaryKey(option);

      // First time seeing this option
      if (!Options.ContainsKey(dictionaryKey))
      {
        Options[dictionaryKey] = option;
        return;
      }

      // User options always win
      if (Options[dictionaryKey].UserId > 0)
      {
        return;
      }

      // New user option - replace GLOBAL one
      Options[dictionaryKey] = option;
    }
예제 #15
0
 private string GetInsertionOptionLine(OptionEntity option)
 {
     return($"({option.OptionId}, {option.QuestionId}, N'{option.Text}', {option.Position}, {option.AnswersCount})");
 }
예제 #16
0
 public async Task <int> Add(OptionEntity option)
 {
     // TODO: [TESTS] (OptionRepo.Add) Add tests
     return(await ExecuteAsync(nameof(Add), _queries.Add(), option));
 }
예제 #17
0
 public async Task <int> Update(OptionEntity option)
 {
     // TODO: [TESTS] (OptionRepo.Update) Add tests
     return(await ExecuteAsync(nameof(Update), _queries.Update(), option));
 }
 public bool CanExecute(OptionEntity _)
 {
     return(true);
 }
 public Option <ValidationMessage> Execute(OptionEntity option)
 {
     return((option.Problems(Repo.GetElement).Count() > 1)
            .Then(() => ValidationMessage.Warning("Multiple Problems addressed by an Option")));
 }
예제 #20
0
 // Internal methods
 private static string GenerateDictionaryKey(OptionEntity option)
 {
   // TODO: [TESTS] (RawOptions.GenerateDictionaryKey) Add tests
   return GenerateDictionaryKey(option.OptionCategory, option.OptionKey);
 }
예제 #21
0
 public OptionEntity GetCachedEntry(OptionEntity option)
 => GetCachedEntry(option.OptionCategory, option.OptionKey, option.UserId);
예제 #22
0
 protected void ClearOptionConnection(OptionEntity option)
 {
     CurrentTree.ClearOptionConnection(option.id);
 }
예제 #23
0
 private static string GenerateKey(OptionEntity option)
 => GenerateKey(option.OptionCategory, option.OptionKey, option.UserId);
예제 #24
0
 public OptionSelection(DialogueTreeEntity tree, OptionEntity option, string text)
 {
     this.tree   = tree;
     this.option = option;
     this.Text   = text;
 }