Exemplo n.º 1
0
 /// <summary>
 ///   A simple constructor that initializes the object with the given values.
 /// </summary>
 /// <param name="p_actType">The type of the completion.</param>
 /// <param name="p_strName">The name of the selection.</param>
 /// <param name="p_strDescription">The description of the selection.</param>
 public XmlCompletionData(AutoCompleteType p_actType, string p_strName, string p_strDescription)
   : base(
     p_strName, p_strDescription,
     (p_actType == AutoCompleteType.AttributeValues) ? 2 : ((p_actType == AutoCompleteType.Attribute) ? 1 : 0))
 {
   m_actCompletionType = p_actType;
 }
Exemplo n.º 2
0
        internal static string GetVCardAttributeValue(AutoCompleteType type)
        {
            switch (type)
            {
            case AutoCompleteType.None:
            case AutoCompleteType.Disabled:
            case AutoCompleteType.Enabled:
                // should not happen
                throw new InvalidOperationException();

            case AutoCompleteType.Search:
                return("search");

            case AutoCompleteType.HomeCountryRegion:
                return("HomeCountry");

            case AutoCompleteType.BusinessCountryRegion:
                return("BusinessCountry");

            default:
                string result = Enum.Format(typeof(AutoCompleteType), type, "G");
                // Business and Home properties need to be prefixed with "."
                if (result.StartsWith("Business", StringComparison.Ordinal))
                {
                    result = result.Insert(8, ".");
                }
                else if (result.StartsWith("Home", StringComparison.Ordinal))
                {
                    result = result.Insert(4, ".");
                }
                return("vCard." + result);
            }
        }
Exemplo n.º 3
0
 public AutoComplete(AutoCompleteKeeper Keeper, AutoCompleteType type = AutoCompleteType.replace)
 {
     this.Keeper = Keeper;
     ParentForm  = ThisControl.FindForm();
     Type        = type;
     AddEvents();
 }
Exemplo n.º 4
0
 /// <summary>
 ///   A simple constructor that initializes the object with the given values.
 /// </summary>
 /// <param name="p_actType">The type of the completion.</param>
 /// <param name="p_strName">The name of the selection.</param>
 /// <param name="p_strDescription">The description of the selection.</param>
 public XmlCompletionData(AutoCompleteType p_actType, string p_strName, string p_strDescription)
     : base(
         p_strName, p_strDescription,
         (p_actType == AutoCompleteType.AttributeValues) ? 2 : ((p_actType == AutoCompleteType.Attribute) ? 1 : 0))
 {
     m_actCompletionType = p_actType;
 }
Exemplo n.º 5
0
        /// <summary>
        ///   Parse the current XML Schema to generate a list of autocomplete values.
        /// </summary>
        /// <param name="p_stkCode">A stack describing the path to the current XML element in the document.</param>
        /// <param name="p_lstSiblings">The siblings of the current XML element.</param>
        /// <param name="p_rtvReturnType">The type of autocomplete items we want.</param>
        /// <returns>The list of possible autocomplete values.</returns>
        private List <KeyValuePair <string, string> > ParseSchema(Stack <string> p_stkCode, List <string> p_lstSiblings,
                                                                  AutoCompleteType p_rtvReturnType)
        {
            var lstElements = new List <KeyValuePair <string, string> >();

            if (m_xstSchema == null)
            {
                return(lstElements);
            }

            XmlSchemaElement xseCurrentElement = null;

            foreach (XmlSchemaElement parentElement in m_xstSchema.GlobalElements.Values)
            {
                if (p_stkCode.Count == 0)
                {
                    lstElements.Add(new KeyValuePair <string, string>(parentElement.Name, GetDocumentation(parentElement)));
                }
                else if (p_stkCode.Peek().Equals(parentElement.Name))
                {
                    xseCurrentElement = findElement(parentElement, p_stkCode);
                    break;
                }
            }
            if (xseCurrentElement != null)
            {
                lstElements.AddRange(GetAutoCompleteList(xseCurrentElement, p_lstSiblings, p_rtvReturnType));
            }

            return(lstElements);
        }
Exemplo n.º 6
0
 /// <summary>
 /// A simple constructor that initializes the object with the given values.
 /// </summary>
 /// <param name="p_lstAutoCompleteList">The list of code completions.</param>
 /// <param name="p_strElementPath">The path to the current element in the XML.</param>
 /// <param name="p_strSiblings">The siblings of the current XML object being completed.</param>
 /// <param name="p_actType">The type of object being completed.</param>
 /// <param name="p_strLastWord">The word that has been entered thus far for the autocompletion string.</param>
 public AutoCompleteListEventArgs(List <XmlCompletionData> p_lstAutoCompleteList, string p_strElementPath, string[] p_strSiblings, AutoCompleteType p_actType, string p_strLastWord)
 {
     m_lstAutoCompleteList = p_lstAutoCompleteList;
     m_strElementPath      = p_strElementPath;
     m_strSiblings         = p_strSiblings;
     m_actType             = p_actType;
     m_strLastWord         = p_strLastWord;
 }
Exemplo n.º 7
0
 /// <summary>
 /// A simple constructor that initializes the object with the given values.
 /// </summary>
 /// <param name="p_lstAutoCompleteList">The list of code completions.</param>
 /// <param name="p_strElementPath">The path to the current element in the XML.</param>
 /// <param name="p_strSiblings">The siblings of the current XML object being completed.</param>
 /// <param name="p_actType">The type of object being completed.</param>
 /// <param name="p_strLastWord">The word that has been entered thus far for the autocompletion string.</param>
 public AutoCompleteListEventArgs(List<XmlCompletionData> p_lstAutoCompleteList, string p_strElementPath, string[] p_strSiblings, AutoCompleteType p_actType, string p_strLastWord)
 {
     m_lstAutoCompleteList = p_lstAutoCompleteList;
     m_strElementPath = p_strElementPath;
     m_strSiblings = p_strSiblings;
     m_actType = p_actType;
     m_strLastWord = p_strLastWord;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AutoCompletions"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 public AutoCompletions(AutoCompleteType type)
     : this(type, (IReadOnlyList <string>)null)
 {
     if (type.HasFlag(AutoCompleteType.Literal))
     {
         throw new ArgumentException("When AutoCompleteOptions.Literal is set, parameter literals must be supplied.", nameof(type));
     }
 }
Exemplo n.º 9
0
 public AutoComplete(Control ctrl, List <string> values, AutoCompleteKeeper Keeper, AutoCompleteType type = AutoCompleteType.replace)
 {
     ThisControl = ctrl;
     this.Keeper = Keeper;
     ParentForm  = ThisControl.FindForm();
     Values      = values;
     Type        = type;
     AddEvents();
 }
Exemplo n.º 10
0
 public WebApiResult GetList([FromQuery] AutoCompleteType type, [FromQuery] string filter)
 {
     try
     {
         return(Helper.OK(() => AutoCompleteService.GetList(type, filter)));
     }
     catch (Exception ex)
     {
         return(Helper.HandleException(ex));
     }
 }
Exemplo n.º 11
0
        private void SetAutoCompleteDataSource(TextBox control, AutoCompleteType type)
        {
            string[] autoCompleteDS = new string[] { "" };
            switch (type)
            {
            case AutoCompleteType.MRN:
                autoCompleteDS = (from p in Patients
                                  select p.MRN).Distinct().ToArray();
                break;

            case AutoCompleteType.FirstName:
                autoCompleteDS = (from p in Patients
                                  select p.FirstName).Distinct().ToArray();
                break;

            case AutoCompleteType.LastName:
                autoCompleteDS = (from p in Patients
                                  select p.LastName).Distinct().ToArray();
                break;

            case AutoCompleteType.PhysicianName:
                autoCompleteDS = (from p in Patients
                                  select p.Physician).Distinct().ToArray();
                break;

            case AutoCompleteType.WardName:
                autoCompleteDS = (from p in Patients
                                  select p.WardName).Distinct().ToArray();
                break;

            case AutoCompleteType.RoomNo:
                autoCompleteDS = (from p in Patients
                                  select p.RoomNo).Distinct().ToArray();
                break;

            case AutoCompleteType.BedNo:
                autoCompleteDS = (from p in Patients
                                  select p.BedNo).Distinct().ToArray();
                break;

            default:
                break;
            }
            control.AutoCompleteCustomSource.AddRange(autoCompleteDS);
            control.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
            control.AutoCompleteSource = AutoCompleteSource.CustomSource;
        }
Exemplo n.º 12
0
        private void SetAutoCompleteDataSource(TextBox control, AutoCompleteType type)
        {
            string[] autoCompleteDS = new string[] { "" };
            switch (type)
            {
            case AutoCompleteType.ItemCode:
                autoCompleteDS = (from p in Items
                                  select p.ItemCode).Distinct().ToArray();
                break;

            case AutoCompleteType.ItemName:
                autoCompleteDS = (from p in Items
                                  select p.ItemName).Distinct().ToArray();
                break;

            default:
                break;
            }
            control.AutoCompleteCustomSource.AddRange(autoCompleteDS);
            control.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
            control.AutoCompleteSource = AutoCompleteSource.CustomSource;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Get entity collection
        /// freeTextSearch - looks for in any text field
        /// </summary>
        public AutoCompleteListData GetList(AutoCompleteType type, string filter)
        {
            using (var scope = Scope("GetList"))
            {
                switch (type)
                {
                case AutoCompleteType.User:
                {
                    // authorize
                    AuthProvider.Authorize(Permission.AutoComplete_GetUsers);

                    // process
                    var maxRows = AppConfig.WebApplication.AutoCompleteMaxRows;
                    var list    = UserManager.GetList(null, filter, maxRows + 1).ToArray();
                    Helper.ValidateResult(list);

                    return(scope.Complete(
                               () => new AutoCompleteListData()
                        {
                            List = list.Take(maxRows).Select(t => new AutoCompleteItem(t.UserId, t.FullName)).OrderBy(t => t.Value).ToArray(),
                            TooMuchData = list.Count() > maxRows
                        },
                               t => $"AutoComplete User list loaded {t.List.Length} items."
                               ));
                }

                default:
                    return(scope.Complete(
                               () => new AutoCompleteListData()
                    {
                        List = new AutoCompleteItem[] { }
                    },
                               t => $"Invalid AutoComplete type, returning empty list: {type}."
                               ));
                }
            }
        }
Exemplo n.º 14
0
        // determine id/index of selected value from autocomplete extender (returns 0 if not found)
        public static int SelectedItemId(AutoCompleteType item_type, string selected_value)
        {
            // initialize
            int index = 0;
            string qryString="";

            // determine type of item
            switch (item_type)
            {
                case AutoCompleteType.Drawing:
                    qryString = "SELECT DWG_ID AS id FROM DWGLIST WHERE DWG_REF='" + selected_value + "'";
                    break;
                case AutoCompleteType.Cable:
                    qryString = "SELECT CABLE_ID AS id FROM CABLIST WHERE CABLE='" + selected_value + "'";
                    break;
                case AutoCompleteType.Component:
                case AutoCompleteType.Interlock:
                case AutoCompleteType.Power:
                    qryString = "SELECT COMP_ID AS id FROM COMPLIST WHERE COMP='" + selected_value + "'";
                    break;
                case AutoCompleteType.Route:
                    qryString = "SELECT NODE_ID AS id FROM ROUTELIST WHERE NODE='" + selected_value + "'";
                    break;
                case AutoCompleteType.FArea:
                    qryString = "SELECT FA_ID AS id FROM FALIST WHERE FA='" + selected_value + "'";
                    break;
                case AutoCompleteType.FZone:
                    qryString = "SELECT FZ_ID AS id FROM FZLIST WHERE FZ='" + selected_value + "'";
                    break;
                case AutoCompleteType.FRoom:
                    qryString = "SELECT RM_ID AS id FROM FRLIST WHERE RM='" + selected_value + "'";
                    break;
                case AutoCompleteType.Disposition:
                    qryString = "SELECT DISP_ID AS id FROM DISPLIST WHERE DISP='" + selected_value + "'";
                    break;
                case AutoCompleteType.BE:
                    qryString = "SELECT BE_ID AS id FROM BELIST WHERE BE='" + selected_value + "'";
                    break;
                case AutoCompleteType.KSF:
                    qryString = "SELECT KSF_ID AS id FROM KSFLIST WHERE KSF='" + selected_value + "'";
                    break;
                case AutoCompleteType.Mode:
                    qryString = "SELECT MODE_ID AS id FROM MODELIST WHERE MODE='" + selected_value + "'";
                    break;
                case AutoCompleteType.NSCA:
                    qryString = "SELECT COMP_ID AS id FROM COMPLIST WHERE COMP='" + selected_value + "' AND ((SSD_REQ=1 AND PRI_SUB='P') OR (NSCA_REQ=1))";
                    break;
                case AutoCompleteType.NPO:
                    qryString = "SELECT COMP_ID AS id FROM COMPLIST WHERE COMP='" + selected_value + "' AND NPO_REQ=1";
                    break;
                case AutoCompleteType.PRA:
                    qryString = "SELECT COMP_ID AS id FROM COMPLIST WHERE COMP='" + selected_value + "' AND PRA_REQ=1";
                    break;
                case AutoCompleteType.ALLDocument:
                    qryString = "SELECT DOC_ID AS id FROM DOCLIST WHERE DOC='" + selected_value + "'";
                    break;
                case AutoCompleteType.EEDocument:
                    qryString = "SELECT DOC_ID AS id FROM DOCLIST WHERE DOC='" + selected_value + "' AND DOC_TYPE='EE'";
                    break;
                case AutoCompleteType.LICDocument:
                    qryString = "SELECT DOC_ID AS id FROM DOCLIST WHERE DOC='" + selected_value + "' AND DOC_TYPE='LIC'";
                    break;
                case AutoCompleteType.GENDocument:
                    qryString = "SELECT DOC_ID AS id FROM DOCLIST WHERE DOC='" + selected_value + "' AND DOC_TYPE='GEN'";
                    break;
            }

            User user = (User)System.Web.HttpContext.Current.Session[Constant.session.User];
            IDBManager dbmgr = new DBManager(user.plantDBStr);                              // get provider
            dbmgr.ConnectionString = user.plantDBStr;                                       // set connection string

            try
            {
                dbmgr.Open();                                                               // open database
                dbmgr.ExecuteReader(CommandType.Text, qryString);                           // execute query
                while (dbmgr.DataReader.Read())                                             // get text and id for each item
                {
                    index = Convert.ToInt32(dbmgr.DataReader["id"]);
                    return index;
                }
            }
            catch
            {
                return index;
            }
            finally
            {
                dbmgr.Dispose();
            }

            return index;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Generate the list of possible code copmletion values.
        /// </summary>
        /// <param name="p_strFileName">The name of the file being edited.</param>
        /// <param name="p_txaTextArea">The area containing the document being edited.</param>
        /// <param name="p_chrCharTyped">The character that was typed that triggered the request for
        /// the code completion list.</param>
        /// <returns>The list of possible code copmletion values.</returns>
        public ICompletionData[] GenerateCompletionData(string p_strFileName, TextArea p_txaTextArea, char p_chrCharTyped)
        {
            string strText = p_txaTextArea.Document.TextContent.Substring(0, p_txaTextArea.Caret.Offset);
            Int32 intOpenTagPos = strText.LastIndexOf('<');
            bool booInsideTag = intOpenTagPos > strText.LastIndexOf('>');
            bool booInsideValue = false;

            if (!booInsideTag && (p_chrCharTyped != '<'))
                return null;

            if (booInsideTag)
            {
                Int32 intQuoteCount = 0;
                for (Int32 intStartPos = intOpenTagPos; (intStartPos = strText.IndexOf('"', intStartPos + 1)) > -1; intQuoteCount++) ;
                booInsideValue = (intQuoteCount % 2 == 1);
            }

            m_strPreSelection = null;

            //parse the buffer
            MatchCollection mclTags = rgxTagContents.Matches(strText);
            LinkedList<KeyValuePair<string, string>> lstTagAncestors = new LinkedList<KeyValuePair<string, string>>();
            Dictionary<Int32, List<string>> dicSiblings = new Dictionary<int, List<string>>();
            Int32 intDepth = -1;
            foreach (Match mtcTag in mclTags)
            {
                string strTag = mtcTag.Groups[1].Value.Trim();
                string strTagName = rgxTagName.Match(strTag).Groups[1].Value;
                if (strTag.StartsWith("/"))
                {
                    Int32 intAcestorCount = lstTagAncestors.Count;
                    Int32 intLastIndex = intAcestorCount - 1;
                    LinkedListNode<KeyValuePair<string, string>> lndItem = lstTagAncestors.Last;
                    while ((lndItem != null) && !lndItem.Value.Key.Equals(strTagName))
                    {
                        intLastIndex--;
                        lndItem = lndItem.Previous;
                    }
                    if (intLastIndex > -1)
                    {
                        while ((lstTagAncestors.Last != null) && !lstTagAncestors.Last.Value.Key.Equals(strTagName))
                            lstTagAncestors.RemoveLast();
                        lstTagAncestors.RemoveLast();
                        Int32 intOldDepth = intDepth;
                        intDepth -= intAcestorCount - intLastIndex;
                        for (Int32 i = intOldDepth + 1; i > intDepth + 1; i--)
                            if (dicSiblings.ContainsKey(i))
                                dicSiblings[i].Clear();
                    }
                }
                else
                {
                    intDepth++;
                    if (!dicSiblings.ContainsKey(intDepth))
                        dicSiblings[intDepth] = new List<string>();
                    dicSiblings[intDepth].Add(strTagName);
                    if (!strTag.EndsWith("/"))
                        lstTagAncestors.AddLast(new KeyValuePair<string, string>(strTagName, strTag));
                    else
                        intDepth--;
                }
            }
            intDepth++;
            if (!dicSiblings.ContainsKey(intDepth))
                dicSiblings[intDepth] = new List<string>();
            Stack<string> stkAncestors = new Stack<string>();
            for (LinkedListNode<KeyValuePair<string, string>> llnLast = lstTagAncestors.Last; llnLast != null; llnLast = llnLast.Previous)
                stkAncestors.Push(llnLast.Value.Key);

            List<KeyValuePair<string, string>> lstComplete = null;
            List<string> lstSiblings = dicSiblings[intDepth];
            m_actCompleteType = AutoCompleteType.Element;

            if (booInsideValue || (booInsideTag && p_chrCharTyped.Equals('=')))
            {
                string strOutsideText = strText;
                if (booInsideValue)
                {
                    Int32 intValueStart = strText.LastIndexOf('"');
                    strOutsideText = strText.Substring(0, intValueStart);
                }
                lstSiblings = new List<string>();
                if (rgxLastAttribute.IsMatch(strOutsideText))
                    lstSiblings.Add(rgxLastAttribute.Match(strOutsideText).Groups[1].Value);

                m_actCompleteType = AutoCompleteType.AttributeValues;
            }
            else if (booInsideTag && p_chrCharTyped.Equals(' '))
            {
                string strTagContents = lstTagAncestors.Last.Value.Value;
                lstSiblings = new List<string>();
                foreach (Match mtcAttribute in rgxAttribute.Matches(strTagContents))
                    lstSiblings.Add(mtcAttribute.Groups[1].Value);
                m_actCompleteType = AutoCompleteType.Attribute;
            }
            lstComplete = ParseSchema(stkAncestors, lstSiblings, m_actCompleteType);

            List<XmlCompletionData> k = new List<XmlCompletionData>();
            if (lstComplete.Count > 0)
                foreach (KeyValuePair<string, string> kvpCompletion in lstComplete)
                    k.Add(new XmlCompletionData(m_actCompleteType, kvpCompletion.Key, kvpCompletion.Value));

            m_dicExtraCompletionCharacters.Clear();
            if (GotAutoCompleteList != null)
            {
                StringBuilder stbPath = new StringBuilder();
                for (LinkedListNode<KeyValuePair<string, string>> llnFirst = lstTagAncestors.First; llnFirst != null; llnFirst = llnFirst.Next)
                {
                    stbPath.Append(llnFirst.Value.Key);
                    if (llnFirst.Next != null)
                        stbPath.Append(Path.DirectorySeparatorChar);
                }

                string strLastWord = "";
                if (ProcessKey(p_chrCharTyped) == CompletionDataProviderKeyResult.NormalKey)
                {
                    TextWord twdLastWord = p_txaTextArea.Document.GetLineSegment(p_txaTextArea.Caret.Line).GetWord(p_txaTextArea.Caret.Column - 1);
                    if (booInsideValue)
                    {
                        Int32 intValueStart = strText.LastIndexOf('"') + 1;
                        if (intValueStart < strText.Length)
                            strLastWord = strText.Substring(intValueStart) + p_chrCharTyped;
                        else
                            strLastWord = p_chrCharTyped.ToString();
                    }
                    else
                    {
                        if (!twdLastWord.Word.Equals("\""))
                        {
                            if (!twdLastWord.Word.Equals("="))
                                strLastWord = twdLastWord.Word + p_chrCharTyped;
                        }
                        else
                            strLastWord = p_chrCharTyped.ToString();
                    }
                    m_strPreSelection = String.IsNullOrEmpty(strLastWord) ? null : strLastWord.Substring(0, strLastWord.Length - 1);
                }
                AutoCompleteListEventArgs aclArgs = new AutoCompleteListEventArgs(k, stbPath.ToString(), lstSiblings.ToArray(), m_actCompleteType, strLastWord);
                GotAutoCompleteList(this, aclArgs);
                m_dicExtraCompletionCharacters[m_actCompleteType] = aclArgs.ExtraInsertionCharacters;
            }

            return k.ToArray();
        }
Exemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AutoCompletions"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="keyword">The keyword.</param>
 public AutoCompletions(AutoCompleteType type, string keyword)
     : this(type, new[] { keyword })
 {
 }
Exemplo n.º 17
0
        /// <internalonly/>
        /// <devdoc>
        /// </devdoc>
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            // Make sure we are in a form tag with runat=server.
            Page page = Page;

            if (page != null)
            {
                page.VerifyRenderingInServerForm(this);
            }

            string uniqueID = UniqueID;

            if (uniqueID != null)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Name, uniqueID);
            }

            TextBoxMode mode = TextMode;

            if (mode == TextBoxMode.MultiLine)
            {
                // MultiLine renders as textarea

                int  rows    = Rows;
                int  columns = Columns;
                bool adapterRenderZeroRowCol = false;

                if (!EnableLegacyRendering)
                {
                    // VSWhidbey 497755
                    if (rows == 0)
                    {
                        rows = DefaultMutliLineRows;
                    }
                    if (columns == 0)
                    {
                        columns = DefaultMutliLineColumns;
                    }
                }

                if (rows > 0 || adapterRenderZeroRowCol)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Rows, rows.ToString(NumberFormatInfo.InvariantInfo));
                }

                if (columns > 0 || adapterRenderZeroRowCol)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Cols, columns.ToString(NumberFormatInfo.InvariantInfo));
                }

                if (!Wrap)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Wrap, "off");
                }
            }
            else
            {
                // Everything else renders as input

                if (mode != TextBoxMode.SingleLine || String.IsNullOrEmpty(Attributes["type"]))
                {
                    // If the developer specified a custom type (like an HTML 5 type), use that type instead of "text".
                    // The call to base.AddAttributesToRender at the end of this method will add the custom type if specified.
                    writer.AddAttribute(HtmlTextWriterAttribute.Type, GetTypeAttributeValue(mode));
                }

                AutoCompleteType autoCompleteType = AutoCompleteType;
                if (mode == TextBoxMode.SingleLine &&
                    autoCompleteType != AutoCompleteType.None &&
                    autoCompleteType != AutoCompleteType.Enabled &&
                    autoCompleteType != AutoCompleteType.Disabled &&
                    SupportsVCard)
                {
                    // Renders the vcard_name attribute so that client browsers can support autocomplete
                    string name = GetVCardAttributeValue(autoCompleteType);
                    writer.AddAttribute(HtmlTextWriterAttribute.VCardName, name);
                }

                if (autoCompleteType == AutoCompleteType.Disabled &&
                    (RenderingCompatibility >= VersionUtil.Framework45 || mode >= TextBoxMode.Color || (SupportsVCard && mode == TextBoxMode.SingleLine)))
                {
                    // Only render autocomplete="off" when one of the following is true
                    // - 4.5 or higher rendering compat is being used
                    // - any of the new HTML5 modes are being used
                    // - browser supports vCard AND mode is SingleLine (this is the legacy pre-4.5 behavior)
                    writer.AddAttribute(HtmlTextWriterAttribute.AutoComplete, "off");
                }

                if (autoCompleteType == AutoCompleteType.Enabled)
                {
                    // Since Enabled is a new value in .NET 4.5 we don't need back-compat switches
                    writer.AddAttribute(HtmlTextWriterAttribute.AutoComplete, "on");
                }

                if (mode != TextBoxMode.Password)
                {
                    // only render value if we're not a password
                    string s = Text;
                    if (s.Length > 0)
                    {
                        writer.AddAttribute(HtmlTextWriterAttribute.Value, s);
                    }
                }

                int n = MaxLength;
                if (n > 0)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Maxlength, n.ToString(NumberFormatInfo.InvariantInfo));
                }
                n = Columns;
                if (n > 0)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Size, n.ToString(NumberFormatInfo.InvariantInfo));
                }
            }

            if (ReadOnly)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.ReadOnly, "readonly");
            }

            if (AutoPostBack && (page != null) && page.ClientSupportsJavaScript)
            {
                string onChange = null;
                if (HasAttributes)
                {
                    onChange = Attributes["onchange"];
                    if (onChange != null)
                    {
                        onChange = Util.EnsureEndWithSemiColon(onChange);
                        Attributes.Remove("onchange");
                    }
                }

                PostBackOptions options = new PostBackOptions(this, String.Empty);

                // ASURT 98368
                // Need to merge the autopostback script with the user script
                if (CausesValidation)
                {
                    options.PerformValidation = true;
                    options.ValidationGroup   = ValidationGroup;
                }

                if (page.Form != null)
                {
                    options.AutoPostBack = true;
                }

                onChange = Util.MergeScript(onChange, page.ClientScript.GetPostBackEventReference(options, true));
                writer.AddAttribute(HtmlTextWriterAttribute.Onchange, onChange);

                // VSWhidbey 482068: Enter key should be preserved in mult-line
                // textbox so the textBoxKeyHandlerCall should not be hooked up
                if (mode != TextBoxMode.MultiLine)
                {
                    string onKeyPress = _textBoxKeyHandlerCall;
                    if (HasAttributes)
                    {
                        string userOnKeyPress = Attributes["onkeypress"];
                        if (userOnKeyPress != null)
                        {
                            onKeyPress += userOnKeyPress;
                            Attributes.Remove("onkeypress");
                        }
                    }
                    writer.AddAttribute("onkeypress", onKeyPress);
                }

                if (EnableLegacyRendering)
                {
                    writer.AddAttribute("language", "javascript", false);
                }
            }
            else if (page != null)
            {
                page.ClientScript.RegisterForEventValidation(this.UniqueID, String.Empty);
            }

            if (Enabled && !IsEnabled && SupportsDisabledAttribute)
            {
                // We need to do the cascade effect on the server, because the browser
                // only renders as disabled, but doesn't disable the functionality.
                writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
            }

            base.AddAttributesToRender(writer);
        }
Exemplo n.º 18
0
        private void ShowAutoComplete(string[] vals, AutoCompleteType actype)
        {
            Point csrLoc = this.GetPositionFromCharIndex(this.SelectionStart);
            if (this._autoCompMenu != null)
                this._autoCompMenu.Dispose();

            this._autoCompStart = this.SelectionStart;
            this._autoCompLine = this.CurrentLine;
            int mnuLocY = csrLoc.Y + this.Font.Height;
            this._autoCompMenu = new System.Windows.Forms.ListBox();
            this.Controls.Add(this._autoCompMenu);
            this._autoCompMenu.IntegralHeight = true;
            this._autoCompMenu.Height = (int)System.Math.Min(vals.Length, 20) * (this._autoCompMenu.ItemHeight + 2);

            // We now know how tall we *want* the dropdown list to be, we have to
            //   determine where we're going to actually draw the DropDownList and
            //   how tall the list will be.
            if (this.Bottom - mnuLocY >= mnuLocY)
            {
                // There's more space below the line.
                if (this._autoCompMenu.Height > this.Bottom - mnuLocY - 30)
                {
                    // The AutoCompleteMenu is taller than the available space, so we
                    //   have to shrink it to fit.
                    this._autoCompMenu.Height = this.Bottom - mnuLocY - 30;
                }
            }
            else
            {
                // There's more space above the line.
                if (this._autoCompMenu.Height > mnuLocY - this._autoCompMenu.Font.Height)
                {
                    // The AutoCompleteMenu is taller than the available space, so we
                    //   have to calculate how many entries will fit above the
                    //   current line since the dropdown will only list complete
                    //   items that can be completely drawn.
                    int rows = (mnuLocY - this._autoCompMenu.Font.Height) / (this._autoCompMenu.ItemHeight + 2);
                    this._autoCompMenu.Height = rows * (this._autoCompMenu.ItemHeight + 2);
                }
                // The top-most position of the menu will be it's height minus the
                //   height of a light, using the cursor as a base value.
                mnuLocY = csrLoc.Y - this._autoCompMenu.Font.Height - this._autoCompMenu.Height;
            }

            string longestWord = "";
            for (int i = 0; i < vals.Length; i++)
            {
                this._autoCompMenu.Items.Add(vals[i]);
                if (vals[i].Length > longestWord.Length)
                    longestWord = vals[i];
            }
            using (Graphics g = this._autoCompMenu.CreateGraphics())
                this._autoCompMenu.Width = (int)System.Math.Ceiling(g.MeasureString("W" + longestWord, this._autoCompMenu.Font).Width) + 18;

            // Can you believe that in all of this mess I forgot to handle the XPos
            //   for the last 2 years I've been using this auto-complete method?!
            // We'll just take whichever is lower: cursor position or the TextBox's
            //   right edge minus the menu width.
            int mnuLocX = (int)System.Math.Min(csrLoc.X, this.ClientRectangle.Right - this._autoCompMenu.Width);

            this._autoCompMenu.Location = new Point(mnuLocX, mnuLocY);
            this._autoCompMenu.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this._autoCompMenu.ScrollAlwaysVisible = true;
            this._autoCompMenu.Cursor = System.Windows.Forms.Cursors.Arrow;
            this._autoCompMenu.Click += new EventHandler(this.autoCompMenu_ItemClicked);
            this._autoCompMenu.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.autoCompMenu_KeyPress);
            this._autoCompMenu.Tag = actype;
            this._autoCompMenu.Show();
        }
Exemplo n.º 19
0
        /// <summary>
        /// Gets the list of possible next values.
        /// </summary>
        /// <param name="p_xseElement">The current elment in the XML document.</param>
        /// <param name="p_lstSiblings">The siblings of the current XML element.</param>
        /// <param name="p_rtvReturnType">The type of autocomplete items we want.</param>
        /// <returns>The list of possible next values.</returns>
        private List <KeyValuePair <string, string> > GetAutoCompleteList(XmlSchemaElement p_xseElement, List <string> p_lstSiblings, AutoCompleteType p_rtvReturnType)
        {
            List <KeyValuePair <string, string> > lstCompleteList = null;

            switch (p_rtvReturnType)
            {
            case AutoCompleteType.Element:
                if (p_xseElement.ElementSchemaType is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType xctElement = (XmlSchemaComplexType)p_xseElement.ElementSchemaType;
                    if (xctElement.ContentTypeParticle != null)
                    {
                        if (!ContainsSiblings(xctElement.ContentTypeParticle, ref lstCompleteList, p_lstSiblings))
                        {
                            lstCompleteList = GetChildrenElements(xctElement.ContentTypeParticle);
                        }
                    }
                }
                else
                {
                    XmlSchemaSimpleType xstElement = (XmlSchemaSimpleType)p_xseElement.ElementSchemaType;
                    switch (xstElement.TypeCode)
                    {
                    case XmlTypeCode.String:
                        lstCompleteList = new List <KeyValuePair <string, string> >();
                        lstCompleteList.Add(new KeyValuePair <string, string>("![CDATA[", "Character data."));
                        break;
                    }
                }
                if (lstCompleteList == null)
                {
                    lstCompleteList = new List <KeyValuePair <string, string> >();
                }
                lstCompleteList.Add(new KeyValuePair <string, string>("/" + p_xseElement.Name + ">", "Closing tag."));
                break;

            case AutoCompleteType.Attribute:
                lstCompleteList = new List <KeyValuePair <string, string> >();
                if (p_xseElement.ElementSchemaType is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType xctElement = (XmlSchemaComplexType)p_xseElement.ElementSchemaType;
                    if (xctElement.Attributes != null)
                    {
                        foreach (XmlSchemaObject xsoAttribute in xctElement.Attributes)
                        {
                            if (xsoAttribute is XmlSchemaAttribute)
                            {
                                if (!p_lstSiblings.Contains(((XmlSchemaAttribute)xsoAttribute).Name))
                                {
                                    lstCompleteList.Add(new KeyValuePair <string, string>(((XmlSchemaAttribute)xsoAttribute).Name, GetDocumentation((XmlSchemaAnnotated)xsoAttribute)));
                                }
                            }
                            else if (xsoAttribute.ToString() == "System.Xml.Schema.XmlSchemaAttributeGroupRef")
                            {
                            }
                        }
                    }
                }
                break;

            case AutoCompleteType.AttributeValues:
                lstCompleteList = new List <KeyValuePair <string, string> >();
                if (p_xseElement.ElementSchemaType is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType xctElement = (XmlSchemaComplexType)p_xseElement.ElementSchemaType;
                    if (xctElement.Attributes != null)
                    {
                        XmlSchemaAttribute xsaAttribute = null;
                        foreach (XmlSchemaObject attribute in xctElement.Attributes)
                        {
                            if (attribute is XmlSchemaAttribute)
                            {
                                xsaAttribute = (XmlSchemaAttribute)attribute;
                                if (xsaAttribute.Name == p_lstSiblings[p_lstSiblings.Count - 1])
                                {
                                    break;
                                }
                            }
                            xsaAttribute = null;
                        }
                        if (xsaAttribute != null)
                        {
                            XmlSchemaSimpleType xssSimpleType = null;
                            if (xsaAttribute.SchemaType != null)
                            {
                                xssSimpleType = xsaAttribute.SchemaType;
                            }
                            else
                            {
                                xssSimpleType = (XmlSchemaSimpleType)m_xstSchema.GlobalTypes[xsaAttribute.SchemaTypeName];
                            }
                            if (xssSimpleType == null)
                            {
                                switch (xsaAttribute.AttributeSchemaType.TypeCode)
                                {
                                case XmlTypeCode.Boolean:
                                    lstCompleteList.Add(new KeyValuePair <string, string>("0", null));
                                    lstCompleteList.Add(new KeyValuePair <string, string>("1", null));
                                    lstCompleteList.Add(new KeyValuePair <string, string>("true", null));
                                    lstCompleteList.Add(new KeyValuePair <string, string>("false", null));
                                    break;
                                }
                            }
                            else if (xssSimpleType.Content.ToString() == "System.Xml.Schema.XmlSchemaSimpleTypeRestriction")
                            {
                                foreach (XmlSchemaEnumerationFacet sefEnumValue in ((XmlSchemaSimpleTypeRestriction)xssSimpleType.Content).Facets)
                                {
                                    lstCompleteList.Add(new KeyValuePair <string, string>(sefEnumValue.Value, GetDocumentation(sefEnumValue)));
                                }
                            }
                        }
                    }
                }
                break;
            }

            return(lstCompleteList);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Generate the list of possible code copmletion values.
        /// </summary>
        /// <param name="p_strFileName">The name of the file being edited.</param>
        /// <param name="p_txaTextArea">The area containing the document being edited.</param>
        /// <param name="p_chrCharTyped">The character that was typed that triggered the request for
        /// the code completion list.</param>
        /// <returns>The list of possible code copmletion values.</returns>
        public ICompletionData[] GenerateCompletionData(string p_strFileName, TextArea p_txaTextArea, char p_chrCharTyped)
        {
            string strText        = p_txaTextArea.Document.TextContent.Substring(0, p_txaTextArea.Caret.Offset);
            Int32  intOpenTagPos  = strText.LastIndexOf('<');
            bool   booInsideTag   = intOpenTagPos > strText.LastIndexOf('>');
            bool   booInsideValue = false;

            if (!booInsideTag && (p_chrCharTyped != '<'))
            {
                return(null);
            }

            if (booInsideTag)
            {
                Int32 intQuoteCount = 0;
                for (Int32 intStartPos = intOpenTagPos; (intStartPos = strText.IndexOf('"', intStartPos + 1)) > -1; intQuoteCount++)
                {
                    ;
                }
                booInsideValue = (intQuoteCount % 2 == 1);
            }

            m_strPreSelection = null;

            //parse the buffer
            MatchCollection mclTags = rgxTagContents.Matches(strText);
            LinkedList <KeyValuePair <string, string> > lstTagAncestors = new LinkedList <KeyValuePair <string, string> >();
            Dictionary <Int32, List <string> >          dicSiblings     = new Dictionary <int, List <string> >();
            Int32 intDepth = -1;

            foreach (Match mtcTag in mclTags)
            {
                string strTag     = mtcTag.Groups[1].Value.Trim();
                string strTagName = rgxTagName.Match(strTag).Groups[1].Value;
                if (strTag.StartsWith("/"))
                {
                    Int32 intAcestorCount = lstTagAncestors.Count;
                    Int32 intLastIndex    = intAcestorCount - 1;
                    LinkedListNode <KeyValuePair <string, string> > lndItem = lstTagAncestors.Last;
                    while ((lndItem != null) && !lndItem.Value.Key.Equals(strTagName))
                    {
                        intLastIndex--;
                        lndItem = lndItem.Previous;
                    }
                    if (intLastIndex > -1)
                    {
                        while ((lstTagAncestors.Last != null) && !lstTagAncestors.Last.Value.Key.Equals(strTagName))
                        {
                            lstTagAncestors.RemoveLast();
                        }
                        lstTagAncestors.RemoveLast();
                        Int32 intOldDepth = intDepth;
                        intDepth -= intAcestorCount - intLastIndex;
                        for (Int32 i = intOldDepth + 1; i > intDepth + 1; i--)
                        {
                            if (dicSiblings.ContainsKey(i))
                            {
                                dicSiblings[i].Clear();
                            }
                        }
                    }
                }
                else
                {
                    intDepth++;
                    if (!dicSiblings.ContainsKey(intDepth))
                    {
                        dicSiblings[intDepth] = new List <string>();
                    }
                    dicSiblings[intDepth].Add(strTagName);
                    if (!strTag.EndsWith("/"))
                    {
                        lstTagAncestors.AddLast(new KeyValuePair <string, string>(strTagName, strTag));
                    }
                    else
                    {
                        intDepth--;
                    }
                }
            }
            intDepth++;
            if (!dicSiblings.ContainsKey(intDepth))
            {
                dicSiblings[intDepth] = new List <string>();
            }
            Stack <string> stkAncestors = new Stack <string>();

            for (LinkedListNode <KeyValuePair <string, string> > llnLast = lstTagAncestors.Last; llnLast != null; llnLast = llnLast.Previous)
            {
                stkAncestors.Push(llnLast.Value.Key);
            }

            List <KeyValuePair <string, string> > lstComplete = null;
            List <string> lstSiblings = dicSiblings[intDepth];

            m_actCompleteType = AutoCompleteType.Element;

            if (booInsideValue || (booInsideTag && p_chrCharTyped.Equals('=')))
            {
                string strOutsideText = strText;
                if (booInsideValue)
                {
                    Int32 intValueStart = strText.LastIndexOf('"');
                    strOutsideText = strText.Substring(0, intValueStart);
                }
                lstSiblings = new List <string>();
                if (rgxLastAttribute.IsMatch(strOutsideText))
                {
                    lstSiblings.Add(rgxLastAttribute.Match(strOutsideText).Groups[1].Value);
                }

                m_actCompleteType = AutoCompleteType.AttributeValues;
            }
            else if (booInsideTag && p_chrCharTyped.Equals(' '))
            {
                string strTagContents = lstTagAncestors.Last.Value.Value;
                lstSiblings = new List <string>();
                foreach (Match mtcAttribute in rgxAttribute.Matches(strTagContents))
                {
                    lstSiblings.Add(mtcAttribute.Groups[1].Value);
                }
                m_actCompleteType = AutoCompleteType.Attribute;
            }
            lstComplete = ParseSchema(stkAncestors, lstSiblings, m_actCompleteType);

            List <XmlCompletionData> k = new List <XmlCompletionData>();

            if (lstComplete.Count > 0)
            {
                foreach (KeyValuePair <string, string> kvpCompletion in lstComplete)
                {
                    k.Add(new XmlCompletionData(m_actCompleteType, kvpCompletion.Key, kvpCompletion.Value));
                }
            }

            m_dicExtraCompletionCharacters.Clear();
            if (GotAutoCompleteList != null)
            {
                StringBuilder stbPath = new StringBuilder();
                for (LinkedListNode <KeyValuePair <string, string> > llnFirst = lstTagAncestors.First; llnFirst != null; llnFirst = llnFirst.Next)
                {
                    stbPath.Append(llnFirst.Value.Key);
                    if (llnFirst.Next != null)
                    {
                        stbPath.Append(Path.DirectorySeparatorChar);
                    }
                }

                string strLastWord = "";
                if (ProcessKey(p_chrCharTyped) == CompletionDataProviderKeyResult.NormalKey)
                {
                    TextWord twdLastWord = p_txaTextArea.Document.GetLineSegment(p_txaTextArea.Caret.Line).GetWord(p_txaTextArea.Caret.Column - 1);
                    if (booInsideValue)
                    {
                        Int32 intValueStart = strText.LastIndexOf('"') + 1;
                        if (intValueStart < strText.Length)
                        {
                            strLastWord = strText.Substring(intValueStart) + p_chrCharTyped;
                        }
                        else
                        {
                            strLastWord = p_chrCharTyped.ToString();
                        }
                    }
                    else
                    {
                        if (!twdLastWord.Word.Equals("\""))
                        {
                            if (!twdLastWord.Word.Equals("="))
                            {
                                strLastWord = twdLastWord.Word + p_chrCharTyped;
                            }
                        }
                        else
                        {
                            strLastWord = p_chrCharTyped.ToString();
                        }
                    }
                    m_strPreSelection = String.IsNullOrEmpty(strLastWord) ? null : strLastWord.Substring(0, strLastWord.Length - 1);
                }
                AutoCompleteListEventArgs aclArgs = new AutoCompleteListEventArgs(k, stbPath.ToString(), lstSiblings.ToArray(), m_actCompleteType, strLastWord);
                GotAutoCompleteList(this, aclArgs);
                m_dicExtraCompletionCharacters[m_actCompleteType] = aclArgs.ExtraInsertionCharacters;
            }

            return(k.ToArray());
        }
        /// <summary>
        /// Represents the HTML attribute "autocomplete".
        /// </summary>
        /// <param name="autoComplete">The value.</param>
        /// <returns>The same instance of <see cref="Hex.AttributeBuilders.HtmlAttributeBuilder"/>.</returns>
        public HtmlAttributeBuilder AutoComplete( AutoCompleteType autoComplete )
        {
            this.Attributes[ HtmlAttributes.AutoComplete ] = autoComplete.ToLowerString();

            return this;
        }
Exemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AutoCompletions"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="literals">The literals.</param>
 public AutoCompletions(AutoCompleteType type, [NotNull] params IEnumerable <string>[] literals)
     : this(type, literals.Where(l => l != null).SelectMany(l => l).Distinct().ToArray())
 {
 }
        private static MvcHtmlString GetAutocompleteForString <TModel, TValue>(HtmlHelper <TModel> helper, Expression <Func <TModel, TValue> > expression, string DisplayText, AutoCompleteType autoCompleteType, string actionUrl = "", bool?isRequired = false, IDictionary <string, object> viewhtmlAttributes = null, string onselectfunction = "")
        {
            if (viewhtmlAttributes == null)
            {
                viewhtmlAttributes = new Dictionary <string, object>();
            }

            viewhtmlAttributes.Add("data-autocomplete", true);

            viewhtmlAttributes.Add("data-autocompletetype", autoCompleteType.ToString().ToLower());

            viewhtmlAttributes.Add("data-sourceurl", actionUrl);


            if (!string.IsNullOrEmpty(onselectfunction))
            {
                viewhtmlAttributes.Add("data-electfunction", onselectfunction);
            }
            Func <TModel, TValue> method = expression.Compile();
            object value = null;

            if (helper.ViewData.Model != null)
            {
                value = method((TModel)helper.ViewData.Model);
            }

            string modelpropname = ((MemberExpression)expression.Body).ToString();

            modelpropname = modelpropname.Substring(modelpropname.IndexOf('.') + 1);

            viewhtmlAttributes.Add("data-valuetarget", modelpropname);


            if (isRequired.HasValue && isRequired.Value)
            {
                viewhtmlAttributes.Add("data-val", "true");
                viewhtmlAttributes.Add("data-val-required", modelpropname + " is required");
            }


            MvcHtmlString hidden = helper.HiddenFor(expression);

            MvcHtmlString textBox = helper.TextBox(modelpropname + "_AutoComplete", DisplayText, viewhtmlAttributes);

            var builder = new StringBuilder();

            builder.AppendLine(hidden.ToHtmlString());

            builder.AppendLine(textBox.ToHtmlString());

            return(new MvcHtmlString(builder.ToString()));
        }
Exemplo n.º 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AutoCompletions"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="literals">The literals.</param>
 public AutoCompletions(AutoCompleteType type, IReadOnlyList <string> literals)
 {
     this.Type     = type;
     this.Literals = literals;
 }
        public static MvcHtmlString Autocomplete(this HtmlHelper helper, string name, string value, string text, AutoCompleteType autoCompleteType, bool?isRequired = false, IDictionary <string, object> viewhtmlAttributes = null, string onselectfunction = "")
        {
            string    actionUrl = string.Empty;
            UrlHelper url       = new UrlHelper(helper.ViewContext.RequestContext);
            string    acpath    = url.Content("~/Home/");

            if (autoCompleteType == AutoCompleteType.Lab)
            {
                actionUrl = acpath + "GetLabs";
            }
            else if (autoCompleteType == AutoCompleteType.Patient)
            {
                actionUrl = acpath + "GetPatients";
            }


            return(GetAutocompleteString(helper, name, value, text, autoCompleteType, actionUrl, isRequired: isRequired, viewhtmlAttributes: viewhtmlAttributes, onselectfunction: onselectfunction));
        }
Exemplo n.º 26
0
 internal static string GetVCardAttributeValue(AutoCompleteType type) {
     switch (type) {
         case AutoCompleteType.None:
         case AutoCompleteType.Disabled:
         case AutoCompleteType.Enabled:
             // should not happen
             throw new InvalidOperationException();
         case AutoCompleteType.Search:
             return "search";
         case AutoCompleteType.HomeCountryRegion:
             return "HomeCountry";
         case AutoCompleteType.BusinessCountryRegion:
             return "BusinessCountry";
         default:
             string result = Enum.Format(typeof(AutoCompleteType), type, "G");
             // Business and Home properties need to be prefixed with "."
             if (result.StartsWith("Business", StringComparison.Ordinal)) {
                 result = result.Insert(8, ".");
             }
             else if (result.StartsWith("Home", StringComparison.Ordinal)) {
                 result = result.Insert(4, ".");
             }
             return "vCard." + result;
     }
 }
        private static MvcHtmlString GetAutocompleteString(HtmlHelper helper, string name, string value, string text, AutoCompleteType autoCompleteType, string actionUrl = "", bool?isRequired = false, IDictionary <string, object> viewhtmlAttributes = null, string onselectfunction = "")
        {
            if (viewhtmlAttributes == null)
            {
                viewhtmlAttributes = new Dictionary <string, object>();
            }

            viewhtmlAttributes.Add("data-autocomplete", true);

            viewhtmlAttributes.Add("data-autocompletetype", autoCompleteType.ToString().ToLower());

            viewhtmlAttributes.Add("data-sourceurl", actionUrl);


            viewhtmlAttributes.Add("data-valuetarget", name);

            if (!string.IsNullOrEmpty(onselectfunction))
            {
                viewhtmlAttributes.Add("data-electfunction", onselectfunction);
            }
            if (isRequired.HasValue && isRequired.Value)
            {
                viewhtmlAttributes.Add("data-val", "true");
                viewhtmlAttributes.Add("data-val-required", name + " is required");
            }

            var hidden = helper.Hidden(name, value);

            var textBox = helper.TextBox(name + "_AutoComplete", text, viewhtmlAttributes);

            var builder = new StringBuilder();

            builder.AppendLine(hidden.ToHtmlString());

            builder.AppendLine(textBox.ToHtmlString());

            return(new MvcHtmlString(builder.ToString()));
        }
Exemplo n.º 28
0
        /// <summary>
        /// Gets the list of possible next values.
        /// </summary>
        /// <param name="p_xseElement">The current elment in the XML document.</param>
        /// <param name="p_lstSiblings">The siblings of the current XML element.</param>
        /// <param name="p_rtvReturnType">The type of autocomplete items we want.</param>
        /// <returns>The list of possible next values.</returns>
        private List<KeyValuePair<string, string>> GetAutoCompleteList(XmlSchemaElement p_xseElement, List<string> p_lstSiblings, AutoCompleteType p_rtvReturnType)
        {
            List<KeyValuePair<string, string>> lstCompleteList = null;
            switch (p_rtvReturnType)
            {
                case AutoCompleteType.Element:
                    if (p_xseElement.ElementSchemaType is XmlSchemaComplexType)
                    {
                        XmlSchemaComplexType xctElement = (XmlSchemaComplexType)p_xseElement.ElementSchemaType;
                        if (xctElement.ContentTypeParticle != null)
                        {
                            if (!ContainsSiblings(xctElement.ContentTypeParticle, ref lstCompleteList, p_lstSiblings))
                                lstCompleteList = GetChildrenElements(xctElement.ContentTypeParticle);
                        }
                    }
                    else
                    {
                        XmlSchemaSimpleType xstElement = (XmlSchemaSimpleType)p_xseElement.ElementSchemaType;
                        switch (xstElement.TypeCode)
                        {
                            case XmlTypeCode.String:
                                lstCompleteList = new List<KeyValuePair<string, string>>();
                                lstCompleteList.Add(new KeyValuePair<string, string>("![CDATA[", "Character data."));
                                break;
                        }
                    }
                    if (lstCompleteList == null)
                        lstCompleteList = new List<KeyValuePair<string, string>>();
                    lstCompleteList.Add(new KeyValuePair<string, string>("/" + p_xseElement.Name + ">", "Closing tag."));
                    break;
                case AutoCompleteType.Attribute:
                    lstCompleteList = new List<KeyValuePair<string, string>>();
                    if (p_xseElement.ElementSchemaType is XmlSchemaComplexType)
                    {
                        XmlSchemaComplexType xctElement = (XmlSchemaComplexType)p_xseElement.ElementSchemaType;
                        if (xctElement.Attributes != null)
                        {
                            foreach (XmlSchemaObject xsoAttribute in xctElement.Attributes)
                            {
                                if (xsoAttribute is XmlSchemaAttribute)
                                {
                                    if (!p_lstSiblings.Contains(((XmlSchemaAttribute)xsoAttribute).Name))
                                        lstCompleteList.Add(new KeyValuePair<string, string>(((XmlSchemaAttribute)xsoAttribute).Name, GetDocumentation((XmlSchemaAnnotated)xsoAttribute)));
                                }
                                else if (xsoAttribute.ToString() == "System.Xml.Schema.XmlSchemaAttributeGroupRef")
                                {

                                }
                            }
                        }
                    }
                    break;
                case AutoCompleteType.AttributeValues:
                    lstCompleteList = new List<KeyValuePair<string, string>>();
                    if (p_xseElement.ElementSchemaType is XmlSchemaComplexType)
                    {
                        XmlSchemaComplexType xctElement = (XmlSchemaComplexType)p_xseElement.ElementSchemaType;
                        if (xctElement.Attributes != null)
                        {
                            XmlSchemaAttribute xsaAttribute = null;
                            foreach (XmlSchemaObject attribute in xctElement.Attributes)
                            {
                                if (attribute is XmlSchemaAttribute)
                                {
                                    xsaAttribute = (XmlSchemaAttribute)attribute;
                                    if (xsaAttribute.Name == p_lstSiblings[p_lstSiblings.Count - 1])
                                        break;
                                }
                                xsaAttribute = null;
                            }
                            if (xsaAttribute != null)
                            {
                                XmlSchemaSimpleType xssSimpleType = null;
                                if (xsaAttribute.SchemaType != null)
                                    xssSimpleType = xsaAttribute.SchemaType;
                                else
                                    xssSimpleType = (XmlSchemaSimpleType)m_xstSchema.GlobalTypes[xsaAttribute.SchemaTypeName];
                                if (xssSimpleType == null)
                                {
                                    switch (xsaAttribute.AttributeSchemaType.TypeCode)
                                    {
                                        case XmlTypeCode.Boolean:
                                            lstCompleteList.Add(new KeyValuePair<string, string>("0", null));
                                            lstCompleteList.Add(new KeyValuePair<string, string>("1", null));
                                            lstCompleteList.Add(new KeyValuePair<string, string>("true", null));
                                            lstCompleteList.Add(new KeyValuePair<string, string>("false", null));
                                            break;
                                    }
                                }
                                else if (xssSimpleType.Content.ToString() == "System.Xml.Schema.XmlSchemaSimpleTypeRestriction")
                                    foreach (XmlSchemaEnumerationFacet sefEnumValue in ((XmlSchemaSimpleTypeRestriction)xssSimpleType.Content).Facets)
                                        lstCompleteList.Add(new KeyValuePair<string, string>(sefEnumValue.Value, GetDocumentation(sefEnumValue)));
                            }
                        }
                    }
                    break;
            }

            return lstCompleteList;
        }
        public static MvcHtmlString AutocompleteFor <TModel, TValue>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TValue> > expression, string DisplayProperty, AutoCompleteType autoCompleteType, bool?isRequired = false, IDictionary <string, object> viewhtmlAttributes = null, string onselectfunction = "")
        {
            string    actionUrl = string.Empty;
            UrlHelper url       = new UrlHelper(helper.ViewContext.RequestContext);
            string    acpath    = url.Content("~/Home/");

            if (autoCompleteType == AutoCompleteType.Lab)
            {
                actionUrl = acpath + "GetLabs";
            }
            else if (autoCompleteType == AutoCompleteType.Patient)
            {
                actionUrl = acpath + "GetPatients";
            }


            return(GetAutocompleteForString(helper, expression, DisplayProperty, autoCompleteType, actionUrl, isRequired: isRequired, viewhtmlAttributes: viewhtmlAttributes, onselectfunction: onselectfunction));
        }
Exemplo n.º 30
0
        /// <summary>
        /// Parse the current XML Schema to generate a list of autocomplete values.
        /// </summary>
        /// <param name="p_stkCode">A stack describing the path to the current XML element in the document.</param>
        /// <param name="p_lstSiblings">The siblings of the current XML element.</param>
        /// <param name="p_rtvReturnType">The type of autocomplete items we want.</param>
        /// <returns>The list of possible autocomplete values.</returns>
        private List<KeyValuePair<string, string>> ParseSchema(Stack<string> p_stkCode, List<string> p_lstSiblings, AutoCompleteType p_rtvReturnType)
        {
            List<KeyValuePair<string, string>> lstElements = new List<KeyValuePair<string, string>>();
            if (m_xstSchema == null)
                return lstElements;

            XmlSchemaElement xseCurrentElement = null;
            foreach (XmlSchemaElement parentElement in m_xstSchema.GlobalElements.Values)
            {
                if (p_stkCode.Count == 0)
                    lstElements.Add(new KeyValuePair<string, string>(parentElement.Name, GetDocumentation(parentElement)));
                else if (p_stkCode.Peek().Equals(parentElement.Name))
                {
                    xseCurrentElement = findElement(parentElement, p_stkCode);
                    break;
                }
            }
            if (xseCurrentElement != null)
                lstElements.AddRange(GetAutoCompleteList(xseCurrentElement, p_lstSiblings, p_rtvReturnType));

            return lstElements;
        }
Exemplo n.º 31
0
        // fetches autocomplete list
        public static string[] FetchAutoCompleteList(string prefix, string ContextKey, AutoCompleteType type)
        {
            // NOTE: autocomplete lists are utilized as web service instead of dropdownlist to minimize view state

            string qryString = "";
            List<string> items = new List<string>();

            switch (type)
            {
                case AutoCompleteType.Component:
                    qryString = "SELECT COMP_ID, COMP FROM COMPLIST WHERE COMP LIKE '" + prefix + "%'  AND PRI_SUB <> 'D' ORDER BY COMP";
                    break;
                case AutoCompleteType.Drawing:
                    qryString = "SELECT DWG_ID, DWG_REF FROM DWGLIST WHERE DWG_REF LIKE '" + prefix + "%' ORDER BY DWG_REF, DWG_REV DESC";
                    break;
                case AutoCompleteType.Power:
                    qryString = "SELECT POWER_ID, POWER FROM viewPOWERLIST WHERE POWER LIKE '" + prefix + "%' ORDER BY POWER";
                    break;
                case AutoCompleteType.Subcomp:
                    // qryString = "SELECT COMP_ID, COMP FROM COMPLIST WHERE COMP LIKE '" + prefix + "%' AND PRI_SUB='S' ORDER BY COMP";
                    qryString = "SELECT COMP_ID, COMP FROM COMPLIST WHERE COMP LIKE '" + prefix + "%'  AND PRI_SUB <> 'D' ORDER BY COMP";
                    break;
                case AutoCompleteType.Interlock:
                    qryString = "SELECT COMP_ID AS INTLK_ID, COMP AS INTLK FROM COMPLIST WHERE COMP LIKE '" + prefix + "%' ORDER BY COMP";
                    break;
                case AutoCompleteType.Cable:
                    qryString = "SELECT CABLE_ID, CABLE FROM CABLIST WHERE CABLE LIKE '" + prefix + "%' ORDER BY CABLE";
                    break;
                case AutoCompleteType.Route:
                    qryString = "SELECT NODE_ID, NODE FROM ROUTELIST WHERE NODE LIKE '" + prefix + "%' ORDER BY NODE";
                    break;
                case AutoCompleteType.FArea:
                    qryString = "SELECT FA_ID, FA FROM FALIST WHERE FA LIKE '" + prefix + "%' ORDER BY FA";
                    break;
                case AutoCompleteType.FZone:
                    qryString = "SELECT FZ_ID, FZ FROM FZLIST WHERE FZ LIKE '" + prefix + "%' ORDER BY FZ";
                    break;
                case AutoCompleteType.FRoom:
                    qryString = "SELECT RM_ID, RM FROM FRLIST WHERE RM LIKE '" + prefix + "%' ORDER BY RM";
                    break;
                case AutoCompleteType.Disposition:
                    qryString = "SELECT DISP_ID, DISP FROM DISPLIST WHERE DISP LIKE '" + prefix + "%' ORDER BY DISP";
                    break;
                case AutoCompleteType.NSCA:
                    qryString = "SELECT COMP_ID, COMP FROM COMPLIST WHERE COMP LIKE '" + prefix + "%' AND PRI_SUB <> 'D' AND ((SSD_REQ=1 AND PRI_SUB='P') OR (NSCA_REQ=1)) ORDER BY COMP";
                    break;
                case AutoCompleteType.PRA:
                    qryString = "SELECT COMP_ID, COMP FROM COMPLIST WHERE COMP LIKE '" + prefix + "%' AND PRI_SUB <> 'D' AND PRA_REQ=1 ORDER BY COMP";
                    break;
                case AutoCompleteType.NPO:
                    qryString = "SELECT COMP_ID, COMP FROM COMPLIST WHERE COMP LIKE '" + prefix + "%' AND PRI_SUB <> 'D' AND NPO_REQ=1 ORDER BY COMP";
                    break;
                case AutoCompleteType.BDEndpt:
                    qryString = "SELECT DISTINCT 0 AS BD_ENDPT_ID, BD_ENDPT FROM viewBDENDPOINTS WHERE BD_ENDPT LIKE '" + prefix + "%' ORDER BY BD_ENDPT";
                    break;
                case AutoCompleteType.BE:
                    qryString = "SELECT DISTINCT BE_ID, BE FROM BELIST WHERE BE LIKE '" + prefix + "%' ORDER BY BE";
                    break;
                case AutoCompleteType.KSF:
                    qryString = "SELECT DISTINCT KSF_ID, KSF FROM KSFLIST WHERE KSF LIKE '" + prefix + "%' ORDER BY KSF";
                    break;
                case AutoCompleteType.Mode:
                    qryString = "SELECT DISTINCT MODE_ID, MODE FROM MODELIST WHERE MODE LIKE '" + prefix + "%' ORDER BY MODE";
                    break;
                case AutoCompleteType.ALLDocument:
                    qryString = "SELECT DISTINCT DOC_ID, DOC FROM DOCLIST WHERE DOC LIKE '" + prefix + "%' ORDER BY DOC";
                    break;
                case AutoCompleteType.EEDocument:
                    qryString = "SELECT DISTINCT DOC_ID, DOC FROM DOCLIST WHERE DOC LIKE '" + prefix + "%' AND DOC_TYPE='EE' ORDER BY DOC";
                    break;
                case AutoCompleteType.LICDocument:
                    qryString = "SELECT DISTINCT DOC_ID, DOC FROM DOCLIST WHERE DOC LIKE '" + prefix + "%' AND DOC_TYPE='LIC' ORDER BY DOC";
                    break;
                case AutoCompleteType.GENDocument:
                    qryString = "SELECT DISTINCT DOC_ID, DOC FROM DOCLIST WHERE DOC LIKE '" + prefix + "%' AND DOC_TYPE='GEN' ORDER BY DOC";
                    break;
            }

            String dbString = Util.Crypto.Decrypt(Util.Crypto.CryptoType.TripleDES, Util.Config.getValue("dbKey", "FRIAS"), ContextKey);
            IDBManager dbmgr = new DBManager(dbString);
            dbmgr.ConnectionString = dbString;

            try
            {
                dbmgr.Open();                                                               // open database
                dbmgr.ExecuteReader(CommandType.Text, qryString);                           // execute query
                while (dbmgr.DataReader.Read())                                             // get text and id for each item
                {
                    items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dbmgr.DataReader.GetString(1), dbmgr.DataReader.GetInt32(0).ToString()));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbmgr.Dispose();
            }

            return items.ToArray();                                                         //return the string array
        }