Exemplo n.º 1
0
        public void ReadControl(ControlCollection control)
        {
            string vLabel = string.Empty;
            IRepository <LanguageTranslation> repoLang = new LanguageTranslationRepository(this.session);

            foreach (Control C in control)
            {
                string vObjectName   = string.Empty;
                string vControlType  = string.Empty;
                string vDefaultLabel = string.Empty;
                if (C.HasControls())
                {
                    ReadControl(C.Controls);
                }
                if (C is TextBox)
                {
                    var textBox = (TextBox)C;
                    vObjectName  = C.ID;
                    vControlType = textBox.GetType().ToString();
                    if (textBox.Attributes["Trans"] != "false")
                    {
                        vDefaultLabel = textBox.Attributes["placeholder"];
                    }
                }
                else if (C is Label)
                {
                    var Label = (Label)C;
                    vObjectName  = C.ID;
                    vControlType = Label.GetType().ToString();
                    if (Label.Attributes["Trans"] != "false")
                    {
                        vDefaultLabel = Label.Text;
                    }
                }
                else if (C is LinkButton)
                {
                    var linkButton = (LinkButton)C;
                    vObjectName   = C.ID;
                    vControlType  = linkButton.GetType().ToString();
                    vDefaultLabel = linkButton.Text;
                }
                else if (C is Literal)
                {
                    var literal = (Literal)C;
                    vObjectName   = C.ID;
                    vControlType  = literal.GetType().ToString();
                    vDefaultLabel = literal.Text;
                }
                //else if (C is LiteralControl)
                //{
                //    var literal = (LiteralControl)C;
                //    vObjectName = C.ID;
                //    vControlType = literal.GetType().ToString();
                //    vDefaultLabel = literal.Text;
                //}
                else if (C is Button)
                {
                    var button = (Button)C;
                    vObjectName  = C.ID;
                    vControlType = button.GetType().ToString();
                    if (button.Attributes["Trans"] != "false")
                    {
                        vDefaultLabel = button.Text;
                    }
                }
                else if (C is Repeater)
                {
                    var repeater = (Repeater)C;
                    C.Load += new EventHandler(C_RepeterViewLoad);
                    repeater.ItemDataBound += new RepeaterItemEventHandler(repeater_ItemDataBoundReadControl);
                    //foreach(RepeaterItem item in repeater.Items)
                    //{
                    //    if (item.Controls[0] is Literal)
                    //    {
                    //        var literal = (Literal)C;
                    //        vObjectName = C.ID;
                    //        vControlType = literal.GetType().ToString();
                    //        vDefaultLabel = literal.Text;
                    //    }
                    //    if (item.ItemType is Literal)
                    //    {
                    //        var literal = (Literal)C;
                    //        vObjectName = C.ID;
                    //        vControlType = literal.GetType().ToString();
                    //        vDefaultLabel = literal.Text;
                    //    }
                    //}
                }
                else if (C is GridView)
                {
                    var gridView = (GridView)C;
                    C.Load += new EventHandler(C_GridViewLoad);
                    foreach (DataControlField col in gridView.Columns)
                    {
                        if (col is BoundField)
                        {
                            var boundField = (BoundField)col;
                            vObjectName   = C.ID + "_BF_" + boundField.DataField;
                            vControlType  = boundField.GetType().ToString();
                            vDefaultLabel = boundField.HeaderText;
                        }
                        if (col is TemplateField)
                        {
                            var templateField = (TemplateField)col;
                            if (!string.IsNullOrEmpty(templateField.SortExpression))
                            {
                                vObjectName = C.ID + "_TF_" + templateField.SortExpression;
                            }
                            vControlType  = templateField.GetType().ToString();
                            vDefaultLabel = templateField.HeaderText;
                        }
                        if (vDefaultLabel != "")
                        {
                            var id = new LanguageTranslationIdentifier {
                                Language = _Language, ModuleActivityId = _ActivityId, ModuleId = _ModuleId, ObjectName = vObjectName
                            };
                            LanguageTranslation langSet = null;
                            if (!string.IsNullOrEmpty(vObjectName) && !string.IsNullOrEmpty(vDefaultLabel))
                            {
                                langSet = new LanguageTranslation()
                                {
                                    Id = id, DefaultLabel = vDefaultLabel, Label = vDefaultLabel, ControlType = vControlType
                                };
                                langSet.SaveorUpdateLangTranslation(langSet);
                            }
                        }
                    }

                    vDefaultLabel = string.Empty;
                }
                else if (C is DetailsView)
                {
                    var detailsView = (DetailsView)C;
                    C.Load += new EventHandler(C_Load);
                }
                else if (C is RadioButton)
                {
                    var radioButton = (RadioButton)C;
                    vObjectName   = C.ID;
                    vControlType  = radioButton.GetType().ToString();
                    vDefaultLabel = radioButton.Text;
                }
                else if (C is CheckBox)
                {
                    var checkBox = (CheckBox)C;
                    vObjectName  = C.ID;
                    vControlType = checkBox.GetType().ToString();
                    if (checkBox.Attributes["Trans"] != "false")
                    {
                        vDefaultLabel = checkBox.Text;
                    }
                }
                else if (C is Panel)
                {
                    var panel = (Panel)C;
                    vObjectName   = C.ID;
                    vControlType  = panel.GetType().ToString();
                    vDefaultLabel = panel.GroupingText;
                }
                else if (C is HiddenField)
                {
                    var hiddenField = (HiddenField)C;
                    vObjectName   = C.ID;
                    vControlType  = hiddenField.GetType().ToString();
                    vDefaultLabel = hiddenField.Value;
                }
                if (vDefaultLabel != "")
                {
                    var id = new LanguageTranslationIdentifier {
                        Language = _Language, ModuleActivityId = _ActivityId, ModuleId = _ModuleId, ObjectName = vObjectName
                    };
                    LanguageTranslation langSet = null;
                    if (!string.IsNullOrEmpty(vObjectName) && !string.IsNullOrEmpty(vDefaultLabel))
                    {
                        langSet = new LanguageTranslation()
                        {
                            Id = id, DefaultLabel = vDefaultLabel, Label = vDefaultLabel, ControlType = vControlType
                        };
                        langSet.SaveorUpdateLangTranslation(langSet);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public LanguageTranslation()
 {
     Id = new LanguageTranslationIdentifier();
 }