Beispiel #1
0
 /// <summary>
 /// 处理回发数据
 /// </summary>
 /// <param name="postDataKey">回发数据键</param>
 /// <param name="postCollection">回发数据集</param>
 /// <returns>回发数据是否改变</returns>
 public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
 {
     if (String.IsNullOrEmpty(GroupName))
     {
         // This radio button is not in a group
         string postValue   = postCollection[postDataKey];
         bool   postChecked = !String.IsNullOrEmpty(postValue);
         if (Checked != postChecked)
         {
             Checked = postChecked;
             XState.BackupPostDataProperty("Checked");
             return(true);
         }
     }
     else
     {
         // This radio is in a group
         string postValue = postCollection[GroupName];
         if (!String.IsNullOrEmpty(postValue))
         {
             bool postChecked = (ClientID == postValue) ? true : false;
             if (Checked != postChecked)
             {
                 Checked = postChecked;
                 XState.BackupPostDataProperty("Checked");
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #2
0
        //private void AfterDataBind()
        //{
        //    //// 必须重新计算模拟数的数据
        //    //mustReCalculateSimulateTreeData = true;
        //}

        #endregion

        #region IPostBackDataHandler Members

        /// <summary>
        /// 处理回发数据
        /// </summary>
        /// <param name="postDataKey">回发数据键</param>
        /// <param name="postCollection">回发数据集</param>
        /// <returns>回发数据是否改变</returns>
        public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            string postValue = postCollection[postDataKey];

            if (SelectedValue != postValue)
            {
                ListItem item = Items.FindByValue(postValue);
                if (item != null)
                {
                    SelectedValue = postValue;
                    XState.BackupPostDataProperty("SelectedValue");
                    return(true);
                }
                else
                {
                    if (!ForceSelection)
                    {
                        SelectedValue = null;
                        XState.BackupPostDataProperty("SelectedValue");

                        Text = postValue;
                        XState.BackupPostDataProperty("Text");
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// 构造函数
        /// </summary>
        public ControlBase()
        {

            _state = new XState(this);

            AddServerAjaxProperties("Hidden", "Enabled");
            AddClientAjaxProperties();

        }
Beispiel #4
0
        /// <summary>
        /// 处理回发数据
        /// </summary>
        /// <param name="postDataKey">回发数据键</param>
        /// <param name="postCollection">回发数据集</param>
        /// <returns>回发数据是否改变</returns>
        public virtual bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            bool postCollapsed = Convert.ToBoolean(postCollection[CollapsedHiddenFieldID]);

            if (Collapsed != postCollapsed)
            {
                Collapsed = postCollapsed;
                XState.BackupPostDataProperty("Collapsed");
                return(true);
            }

            return(false);
        }
Beispiel #5
0
        /// <summary>
        /// 处理回发数据
        /// </summary>
        /// <param name="postDataKey">回发数据键</param>
        /// <param name="postCollection">回发数据集</param>
        /// <returns>回发数据是否改变</returns>
        public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            string postValue = postCollection[ActiveTabIndexHiddenFieldID];

            int postActiveTabIndex = Convert.ToInt32(postValue);

            if (ActiveTabIndex != postActiveTabIndex)
            {
                ActiveTabIndex = postActiveTabIndex;
                XState.BackupPostDataProperty("ActiveTabIndex");
                return(true);
            }
            return(false);
        }
Beispiel #6
0
        /// <summary>
        /// 处理回发数据
        /// </summary>
        /// <param name="postDataKey">回发数据键</param>
        /// <param name="postCollection">回发数据集</param>
        /// <returns>回发数据是否改变</returns>
        public override bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            base.LoadPostData(postDataKey, postCollection);

            bool postHidden = Convert.ToBoolean(postCollection[HiddenHiddenFieldID]);

            if (Hidden != postHidden)
            {
                Hidden = postHidden;
                XState.BackupPostDataProperty("Hidden");
                return(true);
            }

            return(false);
        }
Beispiel #7
0
        /// <summary>
        /// 处理回发数据
        /// </summary>
        /// <param name="postDataKey">回发数据键</param>
        /// <param name="postCollection">回发数据集</param>
        /// <returns>回发数据是否改变</returns>
        public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            string postValue = postCollection[postDataKey];

            bool postChecked = !String.IsNullOrEmpty(postValue);

            if (Checked != postChecked)
            {
                Checked = postChecked;
                XState.BackupPostDataProperty("Checked");
                return(true);
            }

            return(false);
        }
Beispiel #8
0
        /// <summary>
        /// 处理回发数据
        /// </summary>
        /// <param name="postDataKey">回发数据键</param>
        /// <param name="postCollection">回发数据集</param>
        /// <returns>回发数据是否改变</returns>
        public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            if (EnablePress)
            {
                bool pressed = Convert.ToBoolean(postCollection[PressedHiddenFieldID]);
                if (pressed != Pressed)
                {
                    Pressed = pressed;
                    XState.BackupPostDataProperty("Pressed");
                    return(true);
                }
            }

            return(false);
        }
Beispiel #9
0
        /// <summary>
        /// 处理回发数据
        /// </summary>
        /// <param name="postDataKey">回发数据键</param>
        /// <param name="postCollection">回发数据集</param>
        /// <returns>回发数据是否改变</returns>
        public virtual bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            string postValue = postCollection[postDataKey];

            if (postValue != null && SelectedValue != postValue)
            {
                RadioItem item = Items.FindByValue(postValue);
                if (item != null)
                {
                    SelectedValue = postValue;
                    XState.BackupPostDataProperty("SelectedValue");
                    return(true);
                }
            }
            return(false);
        }
Beispiel #10
0
        /// <summary>
        /// 处理回发数据
        /// </summary>
        /// <param name="postDataKey">回发数据键</param>
        /// <param name="postCollection">回发数据集</param>
        /// <returns>回发数据是否改变</returns>
        public virtual bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            string postSelectedDateStr = postCollection[SelectedDateHiddenFieldID];

            if (!String.IsNullOrEmpty(postSelectedDateStr))
            {
                DateTime currentSelectedDate = DateTime.ParseExact(postSelectedDateStr, DateFormatString, CultureInfo.InvariantCulture);
                if (currentSelectedDate != SelectedDate)
                {
                    SelectedDate = currentSelectedDate;
                    XState.BackupPostDataProperty("SelectedDate");
                    return(true);
                }
            }

            return(false);
        }
Beispiel #11
0
        /// <summary>
        /// 处理回发数据
        /// 回发到服务器,判断控件的属性是否变化,
        /// 如果变化返回true,则RaisePostDataChangedEvent
        /// </summary>
        /// <param name="postDataKey">回发数据键</param>
        /// <param name="postCollection">回发数据集</param>
        /// <returns>回发数据是否改变</returns>
        public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            string postValue = postCollection[UniqueID];

            //// Extjs4.0.1 没能正确的设置 htmleditor 的提交隐藏字段,这个在更高版本中可能要删除
            //string postValue = postCollection[ClientID + "_Text"];

            if (postValue != null && Text != postValue)
            {
                Text = postValue;
                XState.BackupPostDataProperty("Text");
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #12
0
        //private JArray GetItemsJArray()
        //{
        //    JArray ja = new JArray();
        //    int itemIndex = 0;
        //    foreach (RadioItem item in Items)
        //    {
        //        JObject jo = new JObject();
        //        jo.Add("inputValue", item.Value);
        //        jo.Add("boxLabel", item.Text);
        //        jo.Add("name", UniqueID);
        //        if (item.Selected)
        //        {
        //            jo.Add("checked", true);
        //        }

        //        ja.Add(jo);

        //        itemIndex++;
        //    }

        //    return ja;
        //}

        #endregion

        #endregion

        #region DataBind

        /// <summary>
        /// 绑定到数据源
        /// </summary>
        public override void DataBind()
        {
            base.DataBind();

            if (_dataSource != null)
            {
                // 1. 首先清空 Items 属性
                Items.Clear();

                // 2. 绑定到数据源
                if (_dataSource is DataView || _dataSource is DataSet || _dataSource is DataTable)
                {
                    DataTable dataTable = null;
                    if (_dataSource is DataView)
                    {
                        dataTable = ((DataView)_dataSource).ToTable();
                    }
                    else if (_dataSource is DataSet)
                    {
                        dataTable = ((DataSet)_dataSource).Tables[0];
                    }
                    else
                    {
                        dataTable = ((DataTable)_dataSource);
                    }
                    DataBindToDataTable(dataTable);
                }
                else if (_dataSource is IEnumerable)
                {
                    DataBindToEnumerable((IEnumerable)_dataSource);
                }
                else
                {
                    throw new Exception("DataSource doesn't support data type: " + _dataSource.GetType().ToString());
                }

                // X_Items属性不是ServerAjaxProperty,所以只在页面第一次加载时判断是否改变
                if (!Page.IsPostBack)
                {
                    XState.AddModifiedProperty("X_Items");
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// 处理回发数据
        /// </summary>
        /// <param name="postDataKey">回发数据键</param>
        /// <param name="postCollection">回发数据集</param>
        /// <returns>回发数据是否改变</returns>
        public virtual bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            string postValue = postCollection[UniqueID];

            // 只有启用表单控件时,才判断Text是否改变
            // 对于TextBox,如果禁用了(disabled="disabled")则postValue == null,也就是说此表单字段不会提交到服务器(这是浏览器行为)。
            if (Enabled)
            {
                // If post value is empty, null or equals to the EmptyText property, we can consider it to be String.Empty.
                if (String.IsNullOrEmpty(postValue) || postValue == EmptyText)
                {
                    postValue = String.Empty;
                }

                if (Text != postValue)
                {
                    Text = postValue;
                    XState.BackupPostDataProperty("Text");
                    return(true);
                }
            }
            return(false);
        }
Beispiel #14
0
        /// <summary>
        /// 处理回发数据
        /// </summary>
        /// <param name="postDataKey">回发数据键</param>
        /// <param name="postCollection">回发数据集</param>
        /// <returns>回发数据是否改变</returns>
        public virtual bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            //string postValue = postCollection[postDataKey];

            List <string> selectedValues = new List <string>();

            for (int i = 0, count = Items.Count; i < count; i++)
            {
                if (!String.IsNullOrEmpty(postCollection[postDataKey + "_" + i.ToString()]))
                {
                    CheckItem item = Items[i];
                    selectedValues.Add(item.Value);
                }
            }
            string[] selectedValueArray = selectedValues.ToArray();
            if (!StringUtil.CompareStringArray(selectedValueArray, SelectedValueArray))
            {
                SelectedValueArray = selectedValueArray;
                XState.BackupPostDataProperty("SelectedValueArray");
                return(true);
            }

            /*
             * if (postValue != null && SelectedValue != postValue)
             * {
             *  CheckItem item = Items.FindByValue(postValue);
             *  if (item != null)
             *  {
             *      SelectedValue = postValue;
             *      XState.BackupPostDataProperty("SelectedValue");
             *      return true;
             *  }
             * }
             */
            return(false);
        }
Beispiel #15
0
        protected override void OnFirstPreRender()
        {
            // 确保 X_Items 和 SelectedValue 在页面第一次加载时都存在于x_state中
            XState.AddModifiedProperty("X_Items");
            XState.AddModifiedProperty("SelectedValue");

            base.OnFirstPreRender();

            #region examples

            //var nextStepList = [
            //    ['审核', '1'],
            //    ['不审核', '2']
            //];
            //var nextStepStore = new Ext.data.SimpleStore({
            //    fields: ['text', 'value'],
            //    data: nextStepList
            //});
            //{
            //    xtype:'combo',
            //    store: nextStepStore,
            //    displayField:'text',
            //    valueField:'value',
            //    typeAhead: true,
            //    mode: 'local',
            //    triggerAction: 'all',
            //    value:'1',
            //    emptyText:'请选择下一步',
            //    selectOnFocus:true,
            //    allowBlank:false,
            //    fieldLabel: '下一步',
            //    labelSeparator:'&nbsp;<span style="color:red;vertical-align:text-bottom;">*</span>',
            //    name: 'nextStep',
            //    anchor:'95%'
            //}

            #endregion

            #region Properties

            if (!EnableEdit)
            {
                OB.AddProperty("editable", false);
            }

            if (!ForceSelection)
            {
                OB.AddProperty("forceSelection", false);
            }

            if (Resizable)
            {
                OB.AddProperty("resizable", true);
            }

            OB.AddProperty("hiddenName", UniqueID);
            //OB.RemoveProperty("name");
            OB.AddProperty("store", "new Ext.data.ArrayStore({fields:['value','text','enabled','prefix']})", true);


            #region old code
            //OB.AddProperty("mode", "local");
            //// 点击下拉按钮时显示全部内容
            //OB.AddProperty("triggerAction", "all");
            //// 必须选中一个值,不能自己输入内容
            //OB.AddProperty("forceSelection", true);
            //// 此下拉列表控件不可以编辑
            //OB.AddProperty("editable", false);

            //OB.AddProperty(OptionName.Title, "Title");
            //if (TypeAhead) OB.AddProperty(OptionName.TypeAhead, true);
            //OB.AddProperty(OptionName.SelectOnFocus, true);

            //// SelectedValue可以为空
            //if (!String.IsNullOrEmpty(SelectedValue))
            //{
            //    OB.AddProperty("value", SelectedValue);
            //}
            #endregion

            #endregion

            #region old code

            //string hiddenFieldsScript = String.Empty;
            //if (AutoPostBack)
            //{
            //    hiddenFieldsScript += GetSetHiddenFieldValueScript(LastSelectedValueHiddenID, SelectedValue);
            //}

            //string disableSelectRowIndexsString = GetDisableSelectRowIndexsString();
            //string disableSelectRowIndexsScript = GetSetHiddenFieldValueScript(DisableRowIndexsHiddenID, disableSelectRowIndexsString);

            //// TODO:
            //// 这个要放在加载数据的前面,因为加载数据时需要渲染UI,渲染UI时需要用到这个隐藏字段的值
            //if (AjaxPropertyChanged("DisableSelectRowIndexsString", disableSelectRowIndexsString))
            //{
            //    AddAjaxPropertyChangedScript(disableSelectRowIndexsScript);
            //}


            // 不管是不是disableSelectFields.Count > 0,都要执行下面的语句,因为可能页面加载时为0,在Ajax后不为零
            //if (disableSelectFields.Count > 0)
            //OB.AddProperty(OptionName.Tpl, String.Format("'<tpl for=\".\"><div class=\"x-combo-list-item {{[X.util.isHiddenFieldContains(\"{0}\",xindex-1) ? \"box-combo-list-item-disable-select\" : \"\"]}}\">{{text}}</div></tpl>'", DisableSelectRowIndexsHiddenID), true);
            //var tplStr = "'<tpl for=\".\"><div class=\"x-combo-list-item\">{text}</div></tpl>'";
            //var tplStr = "new Ext.XTemplate('<tpl for=\".\"><div class=\"x-combo-list-item\">{text}</div></tpl>')";

            //var tplStr = "<tpl for=\".\"><div class=\"x-combo-list-item <tpl if=\"!enabled\">x-combo-list-item-disable</tpl>\">{prefix}{text}</div></tpl>";
            //OB.AddProperty("tpl", tplStr);
            //OB.AddProperty("tpl", tplStr.Replace("#DisableRowIndexsHiddenID#", DisableRowIndexsHiddenID), true);


            //string setSimulateTreeTextFunctionScript = String.Empty;
            //string setSimulateTreeTextScript = String.Empty;
            //if (EnableSimulateTree)
            //{
            //    string setSimulateTextScript = String.Format("var text=Ext.get('{0}').dom.value;if(text.lastIndexOf('<img')>=0){{Ext.get('{0}').dom.value=X.util.stripHtmlTags(text);}}", ClientID);
            //    setSimulateTreeTextFunctionScript = String.Format("{0}_setSimulateText=function(){{{1}}};", ClientJavascriptID, setSimulateTextScript);

            //    // 加载完毕后,显示选中的值
            //    //AddAbsoluteStartupScript(String.Format("{0}_setSimulateText();", ClientJavascriptID));
            //    // 下拉列表加载完毕后,立即去掉前面图片的HTML标签
            //    string renderScript = JsHelper.GetDeferScript(String.Format("{0}_setSimulateText();", ClientJavascriptID), 20); // "(function(){" + String.Format("{0}_setSimulateText();", ClientJavascriptID) + "}).defer(20);";
            //    OB.Listeners.AddProperty(OptionName.EVENT_RENDER, "function(component){" + renderScript + "}", true);
            //}


            //string simulateTreeAllScript = String.Empty;
            //if (EnableSimulateTree)
            //{
            //    // 在选中一项后,立即去掉前面图片的HTML标签
            //    simulateTreeAllScript += "\r\n";
            //    //string simulateTreeScript = String.Format("function(ddl,record,index){{var text=record.data.text;var startDivIndex=text.lastIndexOf('</div>');text=text.substr(startDivIndex+6);Ext.get('{0}').dom.value=text;}}", ClientID);
            //    string simulateTreeScript = String.Format("function(ddl,record,index){{X.{0}_setSimulateText();}}", ClientJavascriptID);
            //    simulateTreeScript = String.Format("{0}.on('{1}',{2},box,{{delay:0}});", ClientJavascriptID, OptionName.Select, simulateTreeScript);
            //    //AddAbsoluteStartupScript( simulateTreeScript);
            //    simulateTreeAllScript += simulateTreeScript;

            //    simulateTreeAllScript += "\r\n";
            //    string simulateTreeBlurScript = String.Format("function(ddl){{X.{0}_setSimulateText();}}", ClientJavascriptID);
            //    simulateTreeBlurScript = String.Format("{0}.on('{1}',{2},box,{{delay:10}});", ClientJavascriptID, OptionName.Blur, simulateTreeBlurScript);
            //    //AddAbsoluteStartupScript( simulateTreeBlurScript);
            //    simulateTreeAllScript += simulateTreeBlurScript;
            //}



            // These are default values, which are assignment in extender.js.
            //OB.AddProperty("displayField", "text");
            //OB.AddProperty("valueField", "value");
            //OB.AddProperty("store", "new Ext.data.ArrayStore({fields:['value','text','enabled','prefix']})", true);

            //string dataScript = String.Empty;
            //string fields = "['value','text','enabled','prefix']";
            //string storeScript = "new Ext.data.ArrayStore({fields:['value','text','enabled','prefix']})";//", fields, GetDataArrayString()); // GetDataArrayString()

            //OB.AddProperty(OptionName.Store, String.Format("new Ext.data.ArrayStore({{fields:['value','text'],data:{0}}})", dataArrayString), true);
            //OB.AddProperty("store", String.Format("{0}_data", XID), true);
            //string dataScript = String.Format("{0}_data=new Ext.data.ArrayStore({{fields:['value','text'],data:{1}}});", ClientJavascriptID, dataArrayString);
            //sb.AppendFormat("this.{0}_store=new Ext.data.SimpleStore({{fields:['text', 'value'],data:this.{0}_data}});", ClientJavascriptID);
            #endregion

            #region AutoPostBack

            StringBuilder beforeselectSB = new StringBuilder();
            // 是否能选中一项(如果此项不能选中,则点击没用)
            //beforeselectSB.AppendFormat("if(X.util.isHiddenFieldContains('{0}',index)){{return false;}}", DisableRowIndexsHiddenID);
            beforeselectSB.Append("if(!record.data.enabled){return false;}");

            if (AutoPostBack)
            {
                beforeselectSB.Append("cmp.x_tmp_lastvalue=cmp.getValue();");

                string selectScript = "if(cmp.x_tmp_lastvalue!==cmp.getValue()){" + GetPostBackEventReference() + "}";
                OB.Listeners.AddProperty("select", JsHelper.GetFunction(selectScript, "cmp"), true);
            }

            OB.Listeners.AddProperty("beforeselect", JsHelper.GetFunction(beforeselectSB.ToString(), "cmp", "record", "index"), true);

            #region old code
            //if (AutoPostBack)
            //{
            //    // Note: we can't use change event, because it get triggered when the combox lost focus, which is not in time.
            //    // Beforeselect - If current select item is not changed, don't PostBack.
            //    string beforeselectScript = String.Format("function(ddl,record,index){{Ext.get('{0}').dom.value=Ext.get('{1}').dom.value;}}", LastSelectedValueHiddenID, SelectedValueHiddenID);
            //    beforeselectScript = String.Format("{0}.on('{1}',{2},X,{{delay:0}});", XID, "beforeselect", beforeselectScript);
            //    //AddAbsoluteStartupScript( beforeselectScript);
            //    autoPostBackScript += beforeselectScript;

            //    // Select
            //    string selectScript = String.Format("function(ddl,record,index){{if(record.data.value!=Ext.get('{0}').dom.value){{{1}}}}}", LastSelectedValueHiddenID, GetPostBackEventReference());
            //    selectScript = String.Format("{0}.on('{1}',{2},X,{{delay:0}});", XID, "select", selectScript);
            //    //AddAbsoluteStartupScript( selectScript);
            //    autoPostBackScript += selectScript;


            //    //OB.Listeners.RemoveProperty(OptionName.Change);
            //    //OB.Listeners.AddProperty(OptionName.Change, String.Format("function(ddl,newValue,oldValue){{box_pageStateChange();alert(newValue+':'+oldValue);}}"), true);
            //}
            #endregion

            #endregion

            #region Listeners - render

            string renderScript = "cmp.x_loadData();cmp.x_setValue();";

            OB.Listeners.AddProperty("render", JsHelper.GetFunction(renderScript, "cmp"), true);

            #endregion

            #region AddStartupScript

            string contentScript = String.Format("var {0}=new Ext.form.ComboBox({1});", XID, OB.ToString());

            AddStartupScript(contentScript);

            #region old code
            //List<string> totalModifiedProperties = XState.GetTotalModifiedProperties();
            //StringBuilder loadDataSB = new StringBuilder();
            //if (totalModifiedProperties.Contains("X_Items"))
            //{
            //    loadDataSB.AppendFormat("{0}.x_loadData();", XID);
            //}
            //else
            //{
            //    loadDataSB.AppendFormat("{0}.store.loadData({1});", XID, X_Items.ToString());
            //}

            //if (totalModifiedProperties.Contains("SelectedValue"))
            //{
            //    loadDataSB.AppendFormat("{0}.x_setValue();", XID);
            //}
            //else
            //{
            //    loadDataSB.AppendFormat("{0}.x_setValue({1});", XID, JsHelper.Enquote(SelectedValue));
            //}
            #endregion

            #endregion
        }