예제 #1
0
        /// <summary>
        /// 检查服务器名是否本机
        /// </summary>
        /// <returns></returns>
        public static bool CheckServerNameIsLocal(string aServerName)
        {
            aServerName = I3StringUtil.SplitStringToList(aServerName.ToUpper(), "\\")[0];

            if (string.IsNullOrEmpty(aServerName))
            {
                return(true);
            }
            if (string.Equals(aServerName, "."))
            {
                return(true);
            }
            if (string.Equals(aServerName, "127.0.0.1"))
            {
                return(true);
            }
            if (string.Equals(aServerName, "(LOCAL)"))
            {
                return(true);
            }
            if (string.Equals(aServerName, GetMachineName().ToUpper()))
            {
                return(true);
            }
            foreach (string s in GetLocalIP())
            {
                if (string.Equals(aServerName, s.ToUpper()))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
        /// <summary>
        /// 根据控件的Tag设置,自动为控件设置数据绑定
        ///
        /// 注意:Tag的值必须是Text,MU_Name;Items,Mu_Name这样的形式
        /// 注意:自动绑定时,数据源不能有空值,否则会绑定失败
        ///
        /// 特殊配置属性:
        /// Control.Text
        /// ComboBox.Items(DataSource为DataTable类型)
        ///
        /// </summary>
        /// <param name="control"></param>
        /// <param name="dataSource"></param>
        public static void AddDataBingding(Control control, object dataSource)
        {
            if ((control == null) || (control.Tag == null))
            {
                return;
            }
            if (control.Tag.GetType() != typeof(string))
            {
                return;
            }
            if (string.IsNullOrEmpty(control.Tag.ToString()))
            {
                return;
            }

            string        tag     = (string)control.Tag.ToString();
            List <string> setList = I3StringUtil.SplitStringToList(tag, ";");

            foreach (string str in setList)
            {
                List <string> set = I3StringUtil.SplitStringToList(str, ",");
                if (set.Count == 2)
                {
                    string propertyName = (string)set[0];
                    string fieldName    = (string)set[1];
                    if (string.Equals(propertyName, "Items"))
                    {
                        #region ComboBox.Items
                        if (control.GetType() == typeof(ComboBox))
                        {
                            ComboBox comboBox = (ComboBox)control;
                            comboBox.Items.Clear();
                            DataTable dataTable = (DataTable)dataSource;
                            foreach (DataRow row in dataTable.Rows)
                            {
                                comboBox.Items.Add(row[fieldName].ToString());
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        control.DataBindings.Add(propertyName, dataSource, fieldName);
                    }
                }
            }
        }