コード例 #1
0
        /// <summary>
        /// 绑定下拉列表控件为指定的数据字典列表
        /// </summary>
        /// <param name="combo">下拉列表控件</param>
        /// <param name="itemList">数据字典列表</param>
        /// <param name="defaultValue">控件默认值</param>
        public static void BindDictItems(this CustomGridLookUpEdit combo, List <CListItem> itemList, string defaultValue)
        {
            string       displayName = "显示内容";
            const string valueName   = "值内容";
            const string pinyin      = "拼音码";
            DataTable    dt          = DataTableHelper.CreateTable(string.Format("{0},{1},{2}", displayName, valueName, pinyin));

            foreach (CListItem item in itemList)
            {
                DataRow row = dt.NewRow();
                row[displayName] = item.Text;
                row[valueName]   = item.Value;
                row[pinyin]      = Pinyin.GetFirstPY(item.Text);
                dt.Rows.Add(row);
            }

            combo.Properties.ValueMember   = valueName;
            combo.Properties.DisplayMember = displayName;
            combo.Properties.DataSource    = dt;
            combo.Properties.PopulateViewColumns();
            combo.Properties.View.Columns[valueName].Visible = false;

            if (!string.IsNullOrEmpty(defaultValue))
            {
                combo.Text = defaultValue;
            }

            if (!string.IsNullOrEmpty(defaultValue))
            {
                combo.EditValue = defaultValue;
            }
        }
コード例 #2
0
        /// <summary>
        /// 绑定下拉列表控件为指定的数据字典列表
        /// </summary>
        /// <param name="combo">下拉列表控件</param>
        /// <param name="dictTypeName">数据字典类型名称</param>
        /// <param name="defaultValue">控件默认值</param>
        public static void BindDictItems(this CustomGridLookUpEdit combo, string dictTypeName, string defaultValue)
        {
            string       displayName = dictTypeName;
            const string valueName   = "值内容";
            const string pinyin      = "拼音码";
            DataTable    dt          = DataTableHelper.CreateTable(string.Format("{0},{1},{2}", displayName, valueName, pinyin));

            Dictionary <string, string> dict = BLLFactory <DictData> .Instance.GetDictByDictType(dictTypeName);

            foreach (string key in dict.Keys)
            {
                DataRow row = dt.NewRow();
                row[displayName] = key;
                row[valueName]   = dict[key];
                row[pinyin]      = Pinyin.GetFirstPY(key);
                dt.Rows.Add(row);
            }

            combo.Properties.ValueMember   = valueName;
            combo.Properties.DisplayMember = displayName;
            combo.Properties.DataSource    = dt;
            combo.Properties.PopulateViewColumns();
            combo.Properties.View.Columns[valueName].Visible = false;
            combo.Properties.View.Columns[displayName].Width = 400;
            combo.Properties.View.Columns[pinyin].Width      = 200;
            combo.Properties.PopupFormMinSize = new System.Drawing.Size(600, 0);

            if (!string.IsNullOrEmpty(defaultValue))
            {
                combo.EditValue = defaultValue;
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: yyan/winform
        private void btnPinyinUtil_Click(object sender, EventArgs e)
        {
            string[] maxims = new string[] {
                "事常与人违,事总在人为",
                "骏马是跑出来的,强兵是打出来的",
                "驾驭命运的舵是奋斗。不抱有一丝幻想,不放弃一点机会,不停止一日努力。 ",
                "如果惧怕前面跌宕的山岩,生命就永远只能是死水一潭",
                "懦弱的人只会裹足不前,莽撞的人只能引为烧身,只有真正勇敢的人才能所向披靡"
            };

            string[] medicines = new string[] {
                "聚维酮碘溶液",
                "开塞露",
                "炉甘石洗剂",
                "苯扎氯铵贴",
                "鱼石脂软膏",
                "莫匹罗星软膏",
                "红霉素软膏",
                "氢化可的松软膏",
                "曲安奈德软膏",
                "丁苯羟酸乳膏",
                "双氯芬酸二乙胺乳膏",
                "冻疮膏",
                "克霉唑软膏",
                "特比奈芬软膏",
                "酞丁安软膏",
                "咪康唑软膏、栓剂",
                "甲硝唑栓",
                "复方莪术油栓",
                "右桥小脑角岩斜区肿瘤"
            };

            StringBuilder sb = new StringBuilder("UTF8句子拼音:");

            foreach (string s in maxims)
            {
                sb.AppendFormat("汉字:{0}\n拼音:{1}\n简码:{2} \r\n", s, Pinyin.GetPinyin(s), Pinyin.GetFirstPY(s));
            }

            Encoding gb2312 = Encoding.GetEncoding("GB2312");

            sb.AppendFormat("GB2312拼音简码:");
            foreach (string m in medicines)
            {
                string s = Pinyin.ConvertEncoding(m, Encoding.UTF8, gb2312);
                sb.AppendFormat("药品:{0}\n简码:{1}\n", s, Pinyin.GetFirstPY(s, gb2312));
            }

            string testWord = "右桥小脑角岩斜区肿瘤,聚维酮碘溶液,酞丁安软膏";
            //中文拼音(首字母大写,空格分开)
            string letters = PinYinUtil.CHSToPinyin(testWord, " ", true);

            sb.AppendLine(testWord);
            sb.AppendLine("中文拼音:" + letters);
            sb.AppendLine("首字母:" + PinYinUtil.GetFirstPY(testWord));

            MessageDxUtil.ShowTips(sb.ToString());
        }