コード例 #1
0
        public LanguageEditorTemplate(Type T, LanguageEditorAttribute fixedDisplay, UserControl parentControl)
        {
            _parentControl = parentControl;
            _fixedDisplay  = fixedDisplay;
            _control       = "<%@ Register TagPrefix=\"dnn\" TagName=\"Label\" Src=\"~/controls/LabelControl.ascx\" %>\r\n";
            _control      += "<%@ Register TagPrefix=\"dnn\" TagName=\"TextEditor\" Src=\"~/controls/TextEditor.ascx\" %>\r\n";
            foreach (PropertyInfo pi in T.GetProperties())
            {
                LanguageEditorAttribute att = GetAttribute(pi);
                if (att != null)
                {
                    string labelName = att.Label == String.Empty ? pi.Name : att.Label;
                    switch (att.Control.ToLower())
                    {
                    case "textbox":
                        _control += "<div class=\"dnnFormItem\">\r\n" +
                                    "   <dnn:Label ID=\"lbl" + labelName + "\" runat=\"server\" ControlName=\"txt" + pi.Name + "\" Suffix=\":\" ></dnn:Label>\r\n" +
                                    "   <asp:TextBox ID=\"txt" + pi.Name + "\" runat=\"server\" CssClass=\"bbstore-template\" Width=\"" + att.Width + "\" MaxLength=\"" + att.MaxLength.ToString() + "\" " + (att.Rows > 1 ? "TextMode=\"MultiLine\"" : "") + " Rows = \"" + att.Rows.ToString() + "\" Text='<%# Bind(\"" + pi.Name + "\") %>' />\r\n" +
                                    "</div>";
                        break;

                    case "texteditor":
                        _control += "<div class=\"dnnFormItem\">\r\n" +
                                    "   <dnn:Label ID=\"lbl" + labelName + "\" runat=\"server\" ControlName=\"txt" + pi.Name + "\" Suffix=\":\" ></dnn:Label>\r\n" +
                                    "   <div style=\"float:right; width:70%\">\r\n" +
                                    "       <dnn:TextEditor ID=\"edt" + pi.Name + "\" runat=\"server\" Width=\"" + att.Width + "\" Height=\"" + att.Height + "\"  TextRenderMode=\"Raw\" HtmlEncode=\"False\" defaultmode=\"Rich\"  choosemode=\"False\" Text='<%# Bind(\"" + pi.Name + "\") %>' />\r\n" +
                                    "   </div>\r\n" +
                                    "</div>\r\n";
                        break;
                    }
                }
            }
        }
コード例 #2
0
        public void UpdateLangs()
        {
            if (Langs.Count > formViewLang.PageIndex)
            {
                foreach (PropertyInfo pi in _internalType.GetProperties())
                {
                    LanguageEditorAttribute att = GetAttribute(pi);
                    if (att != null)
                    {
                        string text = "";

                        switch (att.Control.ToLower())
                        {
                        case "textbox":
                            TextBox txt = formViewLang.FindControl("txt" + pi.Name) as TextBox;
                            if (txt != null)
                            {
                                text = txt.Text.Trim();
                            }
                            break;

                        case "texteditor":
                            TextEditor edt = formViewLang.FindControl("edt" + pi.Name) as TextEditor;
                            if (edt != null)
                            {
                                text = edt.Text;
                            }
                            break;
                        }
                        for (int i = 0; i < Langs.Count; i++)
                        {
                            ILanguageEditorInfo fg           = Langs[i];
                            PropertyInfo        propertyInfo = fg.GetType().GetProperty(pi.Name);

                            if ((string)propertyInfo.GetValue(fg, null) == String.Empty || i == formViewLang.PageIndex)
                            {
                                if (i == formViewLang.PageIndex)
                                {
                                    propertyInfo.SetValue(fg, text, null);
                                }
                                else
                                {
                                    if (!String.IsNullOrEmpty(text))
                                    {
                                        string newValue = "###" + fg.Language + " " + text;

                                        int maxLength = GetAttribute(propertyInfo).MaxLength;
                                        if (newValue.Length > maxLength)
                                        {
                                            newValue = newValue.Substring(0, maxLength);
                                        }
                                        propertyInfo.SetValue(fg, newValue, null);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
 protected LanguageEditorAttribute GetAttribute(PropertyInfo pi)
 {
     object[] attrs = pi.GetCustomAttributes(true);
     foreach (object attr in attrs)
     {
         LanguageEditorAttribute languageEditorAttribute = attr as LanguageEditorAttribute;
         if (languageEditorAttribute != null)
         {
             return(languageEditorAttribute);
         }
     }
     return(null);
 }
コード例 #4
0
        protected void Language_Selected(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            foreach (PropertyInfo pi in _internalType.GetProperties())
            {
                LanguageEditorAttribute att = GetAttribute(pi);
                if (att != null)
                {
                    string text = "";
                    switch (att.Control.ToLower())
                    {
                    case "textbox":
                        TextBox txt = formViewLang.FindControl("txt" + pi.Name) as TextBox;
                        if (txt != null)
                        {
                            text = txt.Text.Trim();
                        }
                        break;

                    case "texteditor":
                        TextEditor edt = formViewLang.FindControl("edt" + pi.Name) as TextEditor;
                        if (edt != null)
                        {
                            text = edt.Text;
                        }
                        break;
                    }
                    ILanguageEditorInfo fg           = Langs[formViewLang.PageIndex];
                    PropertyInfo        propertyInfo = fg.GetType().GetProperty(pi.Name);
                    propertyInfo.SetValue(fg, text, null);
                }
            }

            ImageButton btn      = sender as ImageButton;
            string      url      = btn.ImageUrl;
            string      language = url.Substring(url.LastIndexOf('\\') + 1);

            language = language.Replace(".gif", "");
            int i = 0;

            foreach (ILanguageEditorInfo lang in Langs)
            {
                if (lang.Language == language)
                {
                    formViewLang.PageIndex = i;
                    break;
                }
                i++;
            }
        }