Exemplo n.º 1
0
 /// <summary>
 /// 클라이언트 컨트롤에 값을 지정하는 JScript 코드를 생성함. 쓰기 전용.
 /// </summary>
 /// <param name="PropType">클라이언트 컨트롤의 type(text, span 등...)</param>
 /// <param name="Name">클라이언트 컨트롤의 id</param>
 public string this[ClientControlPropertyTypes PropType, string Id]
 {
     set
     {
         this.maControlId.Add(Id);
         this.maPropType.Add(PropType);
         this.maValue.Add(value);
         this.maIndex.Add(-1);
         this.maFindValue.Add("");
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 이전에 Indexer로 지정한 값들을 해석해서 실제 JScript 코드 문자열을 리턴함.
        /// </summary>
        /// <param name="AddScriptTag">JScript 코드 양쪽에 script 태그로 둘러쌓을 지 여부.</param>
        /// <returns>JScript 코드</returns>
        /// <example>
        /// 다음은 txtName 컨트롤에 '홍길동'을 지정하는 JScript를 출력함.
        /// <code>
        /// CClientControl cc = new CClientControl();
        /// cc["span", "spnName"] = "홍길동";
        /// string Stmt = cc.GetScript(false);
        /// string StmtWithTag = cc.GetScript(true);
        ///
        /// //document.getElementById("spnName").innerText = "홍길동";
        /// Console.WriteLine(Stmt);
        ///
        /// //&lt;script language="javascript"&gt;
        /// //document.getElementById("spnName").innerText = "홍길동";
        /// //&lt;/script&gt;
        /// Console.WriteLine(StmtWithTag);
        /// </code>
        /// </example>
        public string GetScript(bool AddScriptTag)
        {
            string s = "";

            if (AddScriptTag)
            {
                s += "<script language=\"javascript\" type=\"text/javascript\">\r\n";
            }

            for (int i = 0, i2 = this.maValue.Count; i < i2; i++)
            {
                ClientControlPropertyTypes PropType = this.maPropType[i];
                string Property = GetPropertyByType(PropType);

                string Value     = GetValueByType(PropType, i);
                string ControlId = this.maControlId[i];

                if ((this.maIndex[i] == -1) && (this.maFindValue[i] == ""))
                {
                    s += "document.getElementById(\"" + ControlId + "\")." + Property + " = " + Value + ";\r\n";
                }
                else
                {
                    if (this.maIndex[i] != -1)
                    {
                        int Index = Convert.ToInt32(this.maIndex[i]);
                        s += "document.getElementById(\"" + ControlId + "\")[" + Index.ToString() + "]" + "." + Property + " = " + Value + ";\r\n";
                    }
                    else
                    {
                        s += "for (var _i = 0; _i < document.getElementById(\"" + ControlId + "\").length; _i++)\r\n";
                        s += "{\r\n";
                        s += "	if (document.getElementById(\""+ ControlId + "\")[_i].value == '" + this.maFindValue[i] + "')\r\n";
                        s += "	{\r\n";
                        s += "		document.getElementById(\""+ ControlId + "\")[_i]." + Property + " = " + Value + ";\r\n";
                        s += "		break;\r\n";
                        s += "	}\r\n";
                        s += "}\r\n";
                    }
                }
            }

            if (this.mFocusedCtl != "")
            {
                s += "document.getElementById(\"" + this.mFocusedCtl + "\").focus();\r\n";
            }

            if (AddScriptTag)
            {
                s += "</script>";
            }

            return(s);
        }
Exemplo n.º 3
0
        private string GetPropertyByType(ClientControlPropertyTypes PropType)
        {
            string Property = "";

            switch (PropType)
            {
            case ClientControlPropertyTypes.InputText:
            case ClientControlPropertyTypes.TextArea:
            case ClientControlPropertyTypes.InputPassword:
            case ClientControlPropertyTypes.Select:
            case ClientControlPropertyTypes.InputHidden:
                Property = "value";
                break;

            case ClientControlPropertyTypes.StyleBackgroundImage:
                Property = "style.backgroundImage";
                break;

            case ClientControlPropertyTypes.StyleDisplay:
                Property = "style.display";
                break;

            case ClientControlPropertyTypes.StyleColor:
                Property = "style.color";
                break;

            case ClientControlPropertyTypes.ImgSrc:
                Property = "src";
                break;

            case ClientControlPropertyTypes.InputRadio:
            case ClientControlPropertyTypes.InputCheckBox:
                Property = "checked";
                break;

            case ClientControlPropertyTypes.Span:
                Property = "innerHTML";
                break;

            default:
                throw new Exception("PropType:" + PropType.ToString() + "은 허용되지 않습니다.");
            }

            return(Property);
        }
Exemplo n.º 4
0
        private string GetValueByType(ClientControlPropertyTypes PropType, int Index)
        {
            string Value = "";

            if ((PropType == ClientControlPropertyTypes.InputRadio) || (PropType == ClientControlPropertyTypes.InputCheckBox))
            {
                Value = this.maValue[Index];
                if ((Value != "true") && (Value != "false"))
                {
                    throw new Exception("radio, checkbox인 경우, 'true', 'false' 값만 허용됩니다.");
                }
            }
            else
            {
                Value = "\"" + CScript.ReplaceForScriptVariable(this.maValue[Index]) + "\"";
            }

            return(Value);
        }