コード例 #1
0
ファイル: FormItemView.cs プロジェクト: pwx5507690/From
        private static void SetSourceValue(DyncField dyncField)
        {
            if (dyncField.Source == 0)
            {
                return;
            }

            if (dyncField.Source == 1 && dyncField.SourceValue.IsNullOrEmpty())
            {
                throw new Exception("url Param is null error");
            }

            var urlParam = dyncField.SourceValue.Split('=')[1];

            if (urlParam.IsNullOrEmpty())
            {
                throw new Exception("url urlParam is length number error");
            }

            var url = dyncField.SourceValue.Split('?')[0];

            if (url.IsNullOrEmpty())
            {
                throw new Exception("api url error");
            }

            var str = urlParam.Split('|');

            if (str.Length < 3)
            {
                throw new Exception("url Param is length number error");
            }

            var dyncExp = new DyncExp();

            if (str[0].IsNullOrEmpty())
            {
                throw new Exception("url table Param is error");
            }

            dyncExp.Table = str[0];
            if (str[1].IsNullOrEmpty())
            {
                throw new Exception("url FiledName Param is error");
            }

            dyncExp.FiledName = str[1];
            if (str[2].IsNotNullOrEmpty())
            {
                dyncExp.Param = str[2].Split(',').ToDictionary(t => t.Split(':')[0], x => x.Split(':')[1]);
            }

            var result = ApiProxy.Send(Common.Http.HttpMethod.POST, url, new StringContent(dyncExp.SerializeObject(), Encoding.UTF8));

            if (result.IsNullOrEmpty() || result == "null")
            {
                return;
            }

            dyncField.Itms = result.DeserializeObject <IEnumerable <SQLDynamicItem> >().Select(t =>
            {
                return(new DropdownModel()
                {
                    value = t.Value,
                    Checked = t.Value
                });
            });
        }