Exemplo n.º 1
0
 public Field(string label, string nameProperty, TypeField typeField, string cssClass)
 {
     Label         = label;
     NameProperty  = nameProperty;
     TypeField     = typeField;
     this.cssClass = cssClass;
 }
Exemplo n.º 2
0
        public void ClickingTheTypeFieldOfTypeWithProvideSourceInfoShouldPingTheMonoScript()
        {
            var guiEvent   = new GuiEvent(EventType.MouseDown, Vector2.zero, 1, 0);
            var typeField  = new TypeField(Rect.zero, typeof(C), null, null, guiEvent);
            var monoScript = typeField.HandleTypeLabelClicked();

            Assert.IsNotNull(monoScript);
        }
Exemplo n.º 3
0
 public void Init(TypeField type)
 {
     Type = type;
     if (Type == TypeField.square)
     {
         InitSquare();
     }
 }
Exemplo n.º 4
0
        public void ClickingTheTypeFieldOfTypeWithoutProvideSourceInfoShouldLogWarning()
        {
            LogAssert.Expect(LogType.Warning, new Regex(nameof(ProvideSourceInfoAttribute)));
            var guiEvent   = new GuiEvent(EventType.MouseDown, Vector2.zero, 1, 0);
            var typeField  = new TypeField(Rect.zero, typeof(B), null, null, guiEvent);
            var monoScript = typeField.HandleTypeLabelClicked();

            Assert.IsNull(monoScript);
        }
Exemplo n.º 5
0
            public TypeClass(UnityReader reader, DerPopoClassDatabase database)
            {
                _database = database;

                ClassID      = reader.ReadInt32();
                BaseClassID  = reader.ReadInt32();
                _namePointer = reader.ReadInt32();
                int fieldCount = reader.ReadInt32();

                _fields = new TypeField[fieldCount];
                int depth = -1;

                Stack <TypeField> branchStack = new Stack <TypeField>();

                for (int i = 0; i < fieldCount; i++)
                {
                    var field = new TypeField(reader, database);
                    _fields[i] = field;

                    if (field.Depth > depth)
                    {
                        //New child
                        TypeField parent = branchStack.LastOrDefault();
                        branchStack.Push(field);
                    }
                    else if (field.Depth < depth)
                    {
                        //End of leaf, merge back to other branch
                        while (branchStack.Count > 0)
                        {
                            var branch = branchStack.Pop();
                            if (branch.Depth == field.Depth)
                            {
                                break;
                            }
                            if (branch.Depth < field.Depth)
                            {
                                throw new NotImplementedException();
                            }
                        }
                        branchStack.Push(field);
                    }
                    else
                    {
                        //sibling
                        branchStack.Pop();
                        var parent = branchStack.Count > 0 ? branchStack.Peek() : null;

                        branchStack.Push(field);
                    }

                    depth = field.Depth;
                }
            }
Exemplo n.º 6
0
    public void Init(int size, TypeField type, MethodCreating method, RedactionField redactionField)
    {
        Size   = size;
        Type   = type;
        Method = method;
        Fields = redactionField;

        if (Type == TypeField.square)
        {
            InitSquare();
        }
    }
Exemplo n.º 7
0
        private string GetFilterAnswer(Dictionary <string, string> questionAndAnswer)
        {
            TypeField type = new TypeField();

            ReviewPage.TypeAnsQuestionFilter(questionAndAnswer["q"], currentCard, ref type);
            var answer = Sound.ExpandSounds(questionAndAnswer["a"]);

            answer = LaTeX.MungeQA(answer, collection);
            if (String.IsNullOrWhiteSpace(type.CorrectAnswer))
            {
                answer = ReviewPage.TypeAnswerRegex.Replace(answer, "");
            }
            else
            {
                answer = ReviewPage.TypeAnswerRegex.Replace(answer, type.CorrectAnswer);
            }
            return(answer);
        }
Exemplo n.º 8
0
        public IEnumerator ClickingTypePickerShouldOpenTypePickerWindow()
        {
            var pickerArea = TypeField.GetPickerButtonArea(TypeFieldRect);
            var guiEvent   = new GuiEvent(
                EventType.MouseDown,
                pickerArea.center,
                1,
                0
                );
            var typeField  = new TypeField(TypeFieldRect, typeof(A), Types, null, guiEvent);
            var testWindow = EditorWindow.GetWindow <TestEditorWindow>();

            testWindow.onGui = new EditorEvent(typeField.DrawGui);
            yield return(new WaitUntil(testWindow.OnGUIInitialized).OrTimeout(2000));

            Assert.IsTrue(EditorWindow.HasOpenInstances <TypePickerWindow>());
            EditorWindow.GetWindow <TypePickerWindow>().Close();
        }
Exemplo n.º 9
0
        public IEnumerator ClickingTypeLabelTwiceForTypeDefinedInThisAssetShouldOpenThisAsset()
        {
            var guiEvent = new GuiEvent(
                EventType.MouseDown,
                TypeFieldRect.center,
                2,
                0
                );
            var typeField = new TypeField(
                TypeFieldRect,
                typeof(C),
                Types,
                null,
                guiEvent
                );

            thisScriptOpenedAtC = false;
            var testWindow = EditorWindow.GetWindow <TestEditorWindow>();

            testWindow.onGui = new EditorEvent(typeField.DrawGui);
            yield return(new WaitUntil(testWindow.OnGUIInitialized).OrTimeout(2000));

            Assert.IsTrue(thisScriptOpenedAtC);
        }
Exemplo n.º 10
0
 public FieldPivot(string fieldName, string caption, TypeField typeField,
     int visibleIndex, int width, FollowGroupField followGroupField)
 {
     this.fieldName = fieldName;
     this.caption = caption != "" ? caption : fieldName;
     this.typeField = typeField;
     this.visibleIndex = visibleIndex;
     this.width = width;
     this.followGroupField = followGroupField;
 }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            //使用CountWords方法
            string text = @"Do you like green eggs and ham?
                            I do not like them, Sam-I-am.
                            I do not like green eggs and ham.";
            Dictionary <string, int> frequencies = CountWords(text);

            foreach (KeyValuePair <string, int> entry in frequencies)
            {
                string word      = entry.Key;
                int    frequency = entry.Value;
                Console.WriteLine("{0}: {1}", word, frequency);
            }

            ConvertList();
            //使用自定义的泛型方法
            List <string> list = MakeList <string>("Line 1", "Line 2");

            foreach (var x in list)
            {
                Console.WriteLine(x);
            }

            //泛型比较
            string name   = "Jon";
            string intro1 = "My name is " + name;
            string intro2 = "My name is " + name;

            Console.WriteLine(intro1 == intro2);                   //使用string的重载运算符进行比较
            Console.WriteLine(AreReferencesEqual(intro1, intro2)); //编译器无法知道有什么重载类型,返回false

            //使用泛型方法,创建实现的泛型类
            Pair <int, string> pair = Pair.Of(10, "value");

            //封闭类型的静态字段
            TypeField <int> .filed      = "First";
            TypeField <string> .filed   = "Second";
            TypeField <DateTime> .filed = "Third";
            TypeField <int> .PrintField();

            TypeField <string> .PrintField();

            TypeField <DateTime> .PrintField();

            //嵌套泛型类型的静态构造函数
            //第一次调用dummy的时候,不论是什么类型,都会导致inner类型初始化
            //不同类型的实参被看作一个不同的封闭类型
            //相同的封闭类型,只会初始化一次
            Outer <int> .Inner <string, DateTime> .DummyMethod();

            Outer <string> .Inner <int, int> .DummyMethod();

            Outer <object> .Inner <string, object> .DummyMethod();

            Outer <string> .Inner <string, object> .DummyMethod();

            Outer <object> .Inner <object, string> .DummyMethod();

            Outer <string> .Inner <int, int> .DummyMethod(); //封闭成员已经在第二句执行过一次静态构造函数,所以这块不会打印

            //泛型枚举
            CountingEnumerable counter = new CountingEnumerable();

            foreach (int x in counter)
            {
                Console.WriteLine(x);
            }

            //对参数类型使用typeof操作符
            DemonstrateTypeof <int>();

            //获取泛型和已构造Type对象的各种方式
            string listTypeName = "System.Collections.Generic.List`1";
            Type   defByName    = Type.GetType(listTypeName);
            //这将会输出四个true,证明不论怎样获取一个特定对象类型的引用,都只涉及一个这样的对象。
            Type closedByName   = Type.GetType(listTypeName + "[System.String]");
            Type closedByMethod = defByName.MakeGenericType(typeof(string));
            Type closedByTypeof = typeof(List <string>);

            Console.WriteLine(closedByMethod == closedByName);
            Console.WriteLine(closedByName == closedByTypeof);
            Type defByTypeof = typeof(List <>);
            Type defByMethod = closedByName.GetGenericTypeDefinition();

            Console.WriteLine(defByMethod == defByName);
            Console.WriteLine(defByName == defByTypeof);

            //通过反射来获取调用泛型方法
            Type       type       = typeof(Outer <int> .Inner <int, int>);
            MethodInfo definition = type.GetMethod("Dummy");

            definition.Invoke(null, null);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Retrieve a list of fields of a given type identified by module
        /// name.  (see http://aka.ms/azureautomationsdk/typefieldoperations
        /// for more information)
        /// </summary>
        /// <param name='resourceGroupName'>
        /// Required. The name of the resource group
        /// </param>
        /// <param name='automationAccount'>
        /// Required. The automation account name.
        /// </param>
        /// <param name='moduleName'>
        /// Required. The name of module.
        /// </param>
        /// <param name='typeName'>
        /// Required. The name of type.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The response model for the list fields operation.
        /// </returns>
        public async Task <TypeFieldListResponse> ListAsync(string resourceGroupName, string automationAccount, string moduleName, string typeName, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException("resourceGroupName");
            }
            if (automationAccount == null)
            {
                throw new ArgumentNullException("automationAccount");
            }
            if (moduleName == null)
            {
                throw new ArgumentNullException("moduleName");
            }
            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("resourceGroupName", resourceGroupName);
                tracingParameters.Add("automationAccount", automationAccount);
                tracingParameters.Add("moduleName", moduleName);
                tracingParameters.Add("typeName", typeName);
                TracingAdapter.Enter(invocationId, this, "ListAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/subscriptions/";
            if (this.Client.Credentials.SubscriptionId != null)
            {
                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
            }
            url = url + "/resourceGroups/";
            url = url + Uri.EscapeDataString(resourceGroupName);
            url = url + "/providers/";
            if (this.Client.ResourceNamespace != null)
            {
                url = url + Uri.EscapeDataString(this.Client.ResourceNamespace);
            }
            url = url + "/automationAccounts/";
            url = url + Uri.EscapeDataString(automationAccount);
            url = url + "/modules/";
            url = url + Uri.EscapeDataString(moduleName);
            url = url + "/types/";
            url = url + Uri.EscapeDataString(typeName);
            url = url + "/fields";
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=2017-05-15-preview");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("Accept", "application/json");
                httpRequest.Headers.Add("ocp-referer", url);
                httpRequest.Headers.Add("x-ms-version", "2014-06-01");

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    TypeFieldListResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new TypeFieldListResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            JToken valueArray = responseDoc["value"];
                            if (valueArray != null && valueArray.Type != JTokenType.Null)
                            {
                                foreach (JToken valueValue in ((JArray)valueArray))
                                {
                                    TypeField typeFieldInstance = new TypeField();
                                    result.Fields.Add(typeFieldInstance);

                                    JToken nameValue = valueValue["name"];
                                    if (nameValue != null && nameValue.Type != JTokenType.Null)
                                    {
                                        string nameInstance = ((string)nameValue);
                                        typeFieldInstance.Name = nameInstance;
                                    }

                                    JToken typeValue = valueValue["type"];
                                    if (typeValue != null && typeValue.Type != JTokenType.Null)
                                    {
                                        string typeInstance = ((string)typeValue);
                                        typeFieldInstance.Type = typeInstance;
                                    }
                                }
                            }
                        }
                    }
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
Exemplo n.º 13
0
 public FieldPivot(string fieldName, string caption, TypeField typeField, string formatString,
     int visibleIndex, int width)
 {
     this.fieldName = fieldName;
     this.caption = caption != "" ? caption : fieldName;
     this.typeField = typeField;
     this.formatString = formatString;
     this.visibleIndex = visibleIndex;
     this.width = width;
 }
Exemplo n.º 14
0
 public Task <List <Field> > GetTermsAsync(string lang, Dictionary <string, TypeField> words_search,
                                           TypeField typeField)
 {
     return(_iRequestTerms.GetTermsAsync(lang, words_search));
 }
Exemplo n.º 15
0
        public string CreateFields(int IdDeclare, TypeField TField, string SelectedField, string Account = "Admin")
        {
            string sql = "select D.*, P.ParamValue, W.ParamValue WValue from t_rpDeclare D(nolock) "
                         + " inner join t_sysParams P(nolock) on 'GridFind' + D.DecName = P.ParamName "
                         + " left join t_sysParams W(nolock) on D.DecName + '" + Account + "' = W.ParamName "
                         + " where IdDeclare = @IdDeclare";
            DataTable      decTab = new DataTable();
            SqlDataAdapter da     = new SqlDataAdapter(sql, DBClient.CnStr);

            da.SelectCommand.Parameters.AddWithValue("@IdDeclare", IdDeclare);
            da.Fill(decTab);
            string s = decTab.Rows[0]["ParamValue"].ToString();

            KeyField  = decTab.Rows[0]["KeyField"].ToString();
            DispField = decTab.Rows[0]["DispField"].ToString();
            TableName = decTab.Rows[0]["TableName"].ToString();

            string SaveFieldList = decTab.Rows[0]["SaveFieldList"].ToString();
            string WValue        = decTab.Rows[0]["WValue"].ToString();

            //31.07.2016 Список размеров
            string[] vars = WValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            Dictionary <string, string> FWidths = new Dictionary <string, string>();

            foreach (string v in vars)
            {
                string[] keyval = v.Split(new char[] { '=' });
                FWidths.Add(keyval[0], keyval[1]);
            }
            //===============================

            DecName = decTab.Rows[0]["DecName"].ToString();

            DataTable FieldMapTable = new DataTable();

            if (TField == TypeField.Edit)
            {
                string smap = "select * from t_sysFieldMap where DecName = @DecName";
                da = new SqlDataAdapter(smap, DBClient.CnStr);
                da.SelectCommand.Parameters.AddWithValue("@DecName", DecName);
                da.Fill(FieldMapTable);
            }

            StringBuilder sb        = new StringBuilder();
            string        ListField = "";
            XmlDocument   xm        = new XmlDocument();
            XmlElement    xRoot;

            xm.LoadXml(s);
            xRoot = xm.DocumentElement;
            bool FlagSelect = false;

            foreach (XmlNode xNod in xRoot.SelectNodes("COLUMN"))
            {
                XmlElement xCol          = (XmlElement)xNod;
                string     FName         = xCol.Attributes["FieldName"].Value;
                string     Title         = xCol.Attributes["FieldCaption"].Value;
                int        Wi            = int.Parse(xCol.Attributes["Width"].Value);
                string     Vis           = xCol.Attributes["Visible"].Value;
                string     DisplayFormat = xCol.Attributes["DisplayFormat"].Value;

                //31.07.2016 список размеров
                if (FWidths.ContainsKey(FName))
                {
                    try
                    {
                        Wi = int.Parse(FWidths[FName]);
                    }
                    catch
                    {; }
                }

                //==========================

                string alignStr = "";
                if (DisplayFormat.IndexOf("#") > -1)
                {
                    alignStr = ",align:'right'";
                }

                if (Vis == "1" & FName.ToLower().IndexOf("_bit") == -1)
                {
                    if (TField == TypeField.Grid)
                    {
                        sb.AppendLine(string.Format(@"<th data-options=""field:'{0}',width:{1}{3}"" sortable=""true"">{2}</th>", new object[] { FName, Wi, Title, alignStr }));
                    }
                    else
                    if (TField == TypeField.Select)
                    {
                        if (!FlagSelect & (SelectedField == FName | string.IsNullOrEmpty(SelectedField)))
                        {
                            sb.AppendLine(string.Format(@"<option selected value=""{0}"">{1}</option>", new object[] { FName, Title }));
                            FlagSelect = true;
                        }
                        else
                        {
                            sb.AppendLine(string.Format(@"<option value=""{0}"">{1}</option>", new object[] { FName, Title }));
                        }
                    }

                    else           //31.07.2016
                    if (TField == TypeField.List)
                    {
                        if (String.IsNullOrEmpty(ListField))
                        {
                            ListField = "'" + FName + "'";
                        }
                        else
                        {
                            ListField = ListField + ",'" + FName + "'";
                        }
                    }
                    else
                    {
                        //Выпадающие списки 21.12.2014
                        DataRow[] ar        = FieldMapTable.Select("dstField='" + FName + "' and IdDeclare > 0");
                        string    ClassName = "";
                        if (ar.Length > 0)
                        {
                            ClassName = ar[0]["ClassName"].ToString();
                        }

                        if (FName.ToLower() == "id" | SaveFieldList.ToLower().IndexOf(FName.ToLower()) == -1)
                        {
                            sb.AppendLine(string.Format(@"<th data-options=""field:'{0}',width:{1}, sortable:true"">{2}</th>", new object[] { FName, Wi, Title }));
                        }
                        else
                        {
                            if (String.IsNullOrEmpty(ClassName) | ClassName == "Bureau.Finder")
                            {
                                sb.AppendLine(string.Format(@"<th data-options=""field:'{0}',width:{1},editor:'text', sortable:true"" >{2}</th>", new object[] { FName, Wi, Title }));
                            }

                            if (ClassName == "Bureau.GridCombo" | ClassName == "Bureau.Check")
                            {
                                sb.AppendLine(string.Format(@"<th data-options=""field:'{0}',width:{1},formatter: format_{0}, sortable:true""  sortable=""true"">{2}</th>", new object[] { FName, Wi, Title }));
                            }
                        }

                        if (ClassName == "Bureau.Finder")
                        {
                            sb.AppendLine(string.Format(@"<th data-options=""field:'{0}_f', width:25, formatter: format_{0}""></th>", FName));
                        }
                    }
                }
            }

            //31/07/2016
            if (TField == TypeField.List)
            {
                //ListField = "[" + ListField + "]";
                return(ListField);
            }
            else
            {
                return(sb.ToString());
            }
        }
Exemplo n.º 16
0
        public void TestTypeField(TypeField field)
        {
            var clone = Helpers.ParseTypeField(field.ToString(), invertNonNull: true);

            Assert.Equal(field.ToString(), clone.ToString());
        }
Exemplo n.º 17
0
 public bool IsUpdated(TypeField f)
 {
     return(updateAttr[(int)f]);
 }
Exemplo n.º 18
0
    private TableRow CreateRowForCustomField(TypeField typeField, string group, List <CrmCustomField> valueFields, CustomFieldDto Field)
    {
        var tr = new TableRow()
        {
            ID = "TableRow" + group + Field.Id
        };
        var tcName = new TableCell()
        {
            ID = "TableCellName" + group + Field.Id
        };
        var labelName = new Label()
        {
            ID   = "LabelFieldName" + group + Field.Id,
            Text = Field.Name
                   //    + "_" + Field.TypeId
        };

        tcName.Controls.Add(labelName);
        tr.Cells.Add(tcName);
        var tcValue = new TableCell()
        {
            ID = "TableCellValue" + group + Field.Id
        };
        var hfIdField = new HiddenField()
        {
            ID = "HiddenFieldIdField" + group + Field.Id, Value = Field.Id.ToString()
        };

        tcValue.Controls.Add(hfIdField);
        var hfGroup = new HiddenField()
        {
            ID = "HiddenFieldGroupField" + group + Field.Id, Value = group
        };

        tcValue.Controls.Add(hfGroup);
        var hfTypeField = new HiddenField()
        {
            ID = "HiddenFieldTypeField" + group + Field.Id, Value = Field.TypeId.ToString()
        };

        tcValue.Controls.Add(hfTypeField);

        switch (Field.TypeId)
        {
        case 5:
        {
            var selectValue = new CheckBoxList()
            {
                ID = "CheckBoxListFieldValue" + group + Field.Id
            };
            var enums = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(Field.Enums.ToString());
            foreach (var option in enums)
            {
                selectValue.Items.Add(new ListItem()
                    {
                        Value = option.Key.ToString(), Text = option.Value
                    });
            }
            ;
            var selectedValue = valueFields.FirstOrDefault(r => r.Id == Field.Id);
            if (selectedValue != null)
            {
                foreach (var _val in selectedValue.Values)
                {
                    var option = selectValue.Items.FindByValue(_val.Enum);
                    if (option != null)
                    {
                        option.Selected = true;
                    }
                }
            }
            ;
            tcValue.Controls.Add(selectValue);
        }
        break;

        case 4:
        {
            var selectValue = new DropDownList()
            {
                ID = "DropDownListFieldValue" + group + Field.Id, CssClass = "form-control"
            };
            var enums = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(Field.Enums.ToString());
            selectValue.Items.Add(new ListItem()
                {
                    Value = "", Text = "-----"
                });
            foreach (var option in enums)
            {
                selectValue.Items.Add(new ListItem()
                    {
                        Value = option.Key.ToString(), Text = option.Value
                    });
            }
            ;
            var selectedValue = valueFields.FirstOrDefault(r => r.Id == Field.Id);
            if (selectedValue != null && selectValue.Items.FindByValue(selectedValue.Values.FirstOrDefault().Enum) != null)
            {
                selectValue.SelectedValue = selectedValue.Values.FirstOrDefault().Enum;
            }
            ;
            tcValue.Controls.Add(selectValue);
        }
        break;

        case 2:
        {
            var selectedValue = valueFields.FirstOrDefault(r => r.Id == Field.Id);
            var val           = selectedValue != null && selectedValue.Values != null && selectedValue.Values.FirstOrDefault() != null?selectedValue.Values.FirstOrDefault().Value : "";

            var numValue = new TextBox()
            {
                ID = "TextBoxFieldValue" + group + Field.Id, Text = val, TextMode = TextBoxMode.Number, CssClass = "form-control"
            };
            tcValue.Controls.Add(numValue);
        }
        break;

        case 1:
        {
            var selectedValue = valueFields.FirstOrDefault(r => r.Id == Field.Id);
            var val           = selectedValue != null && selectedValue.Values != null && selectedValue.Values.FirstOrDefault() != null?selectedValue.Values.FirstOrDefault().Value : "";

            var numValue = new TextBox()
            {
                ID = "TextBoxFieldValue" + group + Field.Id, Text = val, TextMode = TextBoxMode.SingleLine, CssClass = "form-control"
            };
            tcValue.Controls.Add(numValue);
        }
        break;

        case 3:
        {
            var selectedValue = valueFields.FirstOrDefault(r => r.Id == Field.Id);
            var val           = selectedValue != null && selectedValue.Values != null && selectedValue.Values.FirstOrDefault() != null?selectedValue.Values.FirstOrDefault().Value : "";

            var numValue = new CheckBox()
            {
                ID = "CheckBoxFieldValue" + group + Field.Id, Checked = val == "True"
            };
            tcValue.Controls.Add(numValue);
        }
        break;

        case 8:
        {
            if (Session.Contents["MultiFields" + group + Field.Id.ToString()] == null)
            {
                Session.Contents["MultiFields" + group + Field.Id.ToString()] = new Dictionary <String, Panel>();
            }
            var sessionFields = (Session.Contents["MultiFields" + group + Field.Id.ToString()] as Dictionary <String, Panel>);

            var it            = 0;
            var selectedValue = valueFields.FirstOrDefault(r => r.Id == Field.Id);
            var vals          = selectedValue != null && selectedValue.Values != null ? selectedValue.Values : new List <CrmCustomFieldValue>();
            foreach (var val in vals)
            {
                var lc = new Panel()
                {
                    ID = "Panel" + group + Field.Id + it, CssClass = "input-group"
                };

                var ddl = new DropDownList()
                {
                    ID = "DropDownListValue" + group + Field.Id + it, Width = 100, CssClass = "input-group-prepend"
                };
                var enums = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(Field.Enums.ToString());
                foreach (var option in enums)
                {
                    ddl.Items.Add(new ListItem()
                        {
                            Value = option.Key.ToString(), Text = option.Value
                        });
                }
                ;
                ddl.SelectedValue = val.Enum;
                lc.Controls.Add(ddl);
                var numValue = new TextBox()
                {
                    ID = "TextBoxFieldValue" + group + Field.Id + it, Text = val.Value, CssClass = "form-control"
                };
                lc.Controls.Add(numValue);
                var addValue = new Button()
                {
                    ID = "ButtonFieldValue" + group + Field.Id + it, Text = "+", CssClass = "input-group-append input-group-text"
                };

                addValue.Click          += addValue_Click;
                addValue.CommandArgument = JsonConvert.SerializeObject(Field);

                lc.Controls.Add(addValue);
                if (sessionFields.ContainsKey(lc.ID) != null)
                {
                    sessionFields.Remove(lc.ID);
                }
                tcValue.Controls.Add(lc);
                it++;
            }
            foreach (var panel in sessionFields)
            {
                tcValue.Controls.Add(panel.Value);
                it++;
            }
            if (it == 0)
            {
                var lc = new Panel()
                {
                    ID = "Panel" + group + Field.Id + it, CssClass = "input-group"
                };

                var ddl = new DropDownList()
                {
                    ID = "DropDownListValue" + group + Field.Id + it, Width = 100, CssClass = "input-group-prepend"
                };
                var enums = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(Field.Enums.ToString());
                foreach (var option in enums)
                {
                    ddl.Items.Add(new ListItem()
                        {
                            Value = option.Key.ToString(), Text = option.Value
                        });
                }
                ;
                ddl.SelectedIndex = 0;
                lc.Controls.Add(ddl);
                var numValue = new TextBox()
                {
                    ID = "TextBoxFieldValue" + group + Field.Id + it, Text = "", CssClass = "form-control"
                };
                lc.Controls.Add(numValue);
                var addValue = new Button()
                {
                    ID = "ButtonFieldValue" + group + Field.Id + it, Text = "+", CssClass = "input-group-append input-group-text"
                };
                addValue.Click += addValue_Click;
                lc.Controls.Add(addValue);
                tcValue.Controls.Add(lc);
            }
            Session.Contents["MultiFields" + group + Field.Id.ToString()] = sessionFields;
        }
        break;

        case 9:
        {
            var selectedValue = valueFields.FirstOrDefault(r => r.Id == Field.Id);
            var val           = selectedValue != null && selectedValue.Values != null && selectedValue.Values.FirstOrDefault() != null?selectedValue.Values.FirstOrDefault().Value : "";

            var numValue = new TextBox()
            {
                ID = "TextBoxFieldValue" + group + Field.Id, Text = val, TextMode = TextBoxMode.MultiLine, CssClass = "form-control"
            };
            tcValue.Controls.Add(numValue);
        }
        break;
        }
        tr.Cells.Add(tcValue);
        return(tr);
    }
Exemplo n.º 19
0
    private List <T> GetCustomFieldsValues <T>(TypeField typeField, string group) where T : class, IAddCustomField, new()
    {
        var CustomFields = new List <T>();
        var table        = (Table)FindControl("Table" + group);

        foreach (TableRow tr in table.Rows)
        {
            Int64 IdField   = 0;
            Int64 TypeField = 0;
            foreach (Control c in tr.Cells[1].Controls)
            {
                if (c is HiddenField)
                {
                    if (c.ID.Contains("HiddenFieldIdField"))
                    {
                        IdField = Convert.ToInt64(((HiddenField)c).Value);
                    }
                    if (c.ID.Contains("HiddenFieldTypeField"))
                    {
                        TypeField = Convert.ToInt64(((HiddenField)c).Value);
                    }
                }
            }
            if (IdField > 0)
            {
                switch (TypeField)
                {
                case 4:
                {
                    var _value = "";
                    foreach (Control c in tr.Cells[1].Controls)
                    {
                        if (c is DropDownList && ((DropDownList)c).SelectedIndex > -1)
                        {
                            _value = ((DropDownList)c).SelectedValue;
                        }
                    }
                    CustomFields.Add(new T()
                        {
                            Id = IdField, Values = new List <Object> {
                                new AddCustomFieldValues()
                                {
                                    Value = _value
                                }
                            }
                        });
                }
                break;

                case 5:
                {
                    var _values = new List <Object>();

                    foreach (Control c in tr.Cells[1].Controls)
                    {
                        if (c is CheckBoxList)
                        {
                            foreach (ListItem Item in (c as CheckBoxList).Items)
                            {
                                if (Item.Selected)
                                {
                                    _values.Add(Item.Value);
                                }
                            }
                        }
                    }
                    CustomFields.Add(new T()
                        {
                            Id = IdField, Values = _values
                        });
                }
                break;

                case 8:
                {
                    foreach (Control c in tr.Cells[1].Controls)
                    {
                        if (c is Panel)
                        {
                            var _value = "";
                            var _code  = "";
                            var _panel = ((Panel)c);
                            foreach (Control cp in _panel.Controls)
                            {
                                if (cp is TextBox)
                                {
                                    _value = ((TextBox)cp).Text;
                                }
                                if (cp is DropDownList)
                                {
                                    _code = ((DropDownList)cp).SelectedItem.Text;
                                }
                            }
                            if (_value != "")
                            {
                                CustomFields.Add(new T()
                                    {
                                        Id = IdField, Values = new List <Object> {
                                            new AddCustomFieldValuesEnum()
                                            {
                                                Value = _value, Enum = _code
                                            }
                                        }
                                    });
                            }
                        }
                    }
                }
                break;

                case 9:
                case 2:
                case 1:
                {
                    var _value = "";
                    foreach (Control c in tr.Cells[1].Controls)
                    {
                        if (c is TextBox)
                        {
                            _value = ((TextBox)c).Text;
                        }
                    }
                    CustomFields.Add(new T()
                        {
                            Id = IdField, Values = new List <Object> {
                                new AddCustomFieldValues()
                                {
                                    Value = _value
                                }
                            }
                        });
                }
                break;
                }
            }
        }
        return(CustomFields);
    }
Exemplo n.º 20
0
        private static async Task <List <Field> > Field(string lang, List <string> wordsSearch, TypeField typeField,
                                                        List <Field> fields)
        {
            foreach (var word in wordsSearch)
            {
                fields.Add(new Field
                {
                    Name       = word,
                    Multiplier = 500,
                    TypeFields = typeField
                });

                string baseUrl = string.Format(Url_Path, lang, word);
                using var client = new HttpClient();
                string data = await client.GetStringAsync(baseUrl);

                HtmlDocument doc = new HtmlDocument();

                doc.LoadHtml(data);
                var relevantSynonyms = doc.DocumentNode.SelectNodes("//a[@class='synonym  relevant']");
                if (relevantSynonyms != null)
                {
                    foreach (var item in relevantSynonyms)
                    {
                        var pivotField = new Field
                        {
                            Name       = item.InnerText,
                            Multiplier = 500,
                            TypeFields = typeField
                        };
                        fields.Add(pivotField);
                    }
                }

                var synonyms = doc.DocumentNode.SelectNodes("//a[@class='synonym ']");
                if (synonyms != null)
                {
                    foreach (var item in synonyms)
                    {
                        var pivotField = new Field
                        {
                            Name       = item.InnerText,
                            Multiplier = 300,
                            TypeFields = typeField
                        };
                        fields.Add(pivotField);
                    }
                }
            }
            return(fields);
        }