/// <summary/>
        private static void InternalDoNumberField(string label, int controlId, ref string originalStr, float controlWidth, Func <string, string> parse)
        {
            var isLabel = !string.IsNullOrEmpty(label);

            if (isLabel)
            {
                GUILayout.BeginHorizontal(GUILayout.Width(controlWidth + LabelWidth), GUILayout.Height(ControlHeight));
            }

            if (!NumberFields.ContainsKey(controlId))
            {
                NumberFields.Add(controlId, originalStr);
            }

            GUI.SetNextControlName(controlId.ToString());
            if (isLabel)
            {
                NumberFields[controlId] = GUILayout.TextField(NumberFields[controlId], GUILayout.ExpandWidth(true), GUILayout.Height(ControlHeight));
            }
            else
            {
                NumberFields[controlId] = GUILayout.TextField(NumberFields[controlId], GUILayout.Width(controlWidth), GUILayout.Height(ControlHeight));
            }
            ImGui.CheckControlAndDrawPointer();

            if (isLabel)
            {
                ControlLabel(label, controlId);
                GUILayout.EndHorizontal();
            }

            var incomingControl = GUI.GetNameOfFocusedControl();

            if (_selectedNumberField != _nextNumberField || Event.current.isKey && Event.current.keyCode == KeyCode.Return)
            {
                if (_nextNumberField == controlId.ToString() || controlId.ToString() == "0")
                {
                    if (controlId.ToString() == "0")
                    {
                        try
                        {
                            controlId = Convert.ToInt32(_nextNumberField);
                        }
                        catch (Exception)
                        {
                            controlId = 0;
                        }
                    }

                    if (NumberFields.ContainsKey(controlId))
                    {
                        var str = NumberFields[controlId];
                        if (string.IsNullOrEmpty(str) || string.IsNullOrWhiteSpace(str))
                        {
                            originalStr = "0";
                        }
                        else
                        {
                            originalStr = parse.Invoke(str);
                        }

                        NumberFields.Remove(controlId);
                    }
                }
            }

            _nextNumberField     = _selectedNumberField;
            _selectedNumberField = incomingControl;
        }
Esempio n. 2
0
        protected virtual string BuildContent(PXCache sender, object row, PXResult res)
        {
            List <Type> allFields = new List <Type>();

            allFields.AddRange(titleFields);
            if (fields != null)
            {
                foreach (Type field in fields)
                {
                    if (!allFields.Contains(field))
                    {
                        allFields.Add(field);
                    }
                }
            }

            StringBuilder             sb     = new StringBuilder();
            Dictionary <Type, object> values = ExtractValues(sender, row, res, allFields);

            //Title:
            List <string> titleNumbers = new List <string>();
            List <object> titleArgs    = new List <object>();

            if (titleFields != null && titleFields.Length > 0)
            {
                foreach (Type field in titleFields)
                {
                    if (values.ContainsKey(field))
                    {
                        object fieldValue = values[field];
                        titleArgs.Add(fieldValue);

                        if (fieldValue != null && NumberFields != null && NumberFields.Contains(field))
                        {
                            string strValue            = fieldValue.ToString();
                            string numberWithoutPrefix = RemovePrefix(strValue);

                            if (numberWithoutPrefix.Length != strValue.Length)
                            {
                                titleNumbers.Add(numberWithoutPrefix);
                            }
                        }
                    }
                    else
                    {
                        titleArgs.Add(string.Empty);
                    }
                }
            }
            if (titlePrefix != null)
            {
                sb.Append(string.Format(titlePrefix, titleArgs.ToArray()));
            }
            sb.Append(" ");

            foreach (string num in titleNumbers)
            {
                sb.AppendFormat("{0} ", num);
            }

            if (fields != null)
            {
                foreach (Type field in fields)
                {
                    if (values.ContainsKey(field))
                    {
                        if (values[field] != null)
                        {
                            sb.Append(values[field].ToString());
                            sb.Append(" ");
                        }
                    }
                }
            }

            return(sb.ToString());
        }