C#数据表字段内容简繁体批量互转工具

//设计思路:1.直接使用Microsoft.VisualBasic;2.直接使用函数替换掉对应的简体字和繁体字

//设计原由:多语言应用程序需要直接用程序执行批量替换掉系统初始化时候的类别或者系统设定的数据

//尚不完善的地方:没有搜集完成2000多个汉字的简繁体对应的数组

Form1.Designer.cs代码:

 

namespace CONVERTTOOL
{
    partial class Form1
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.label3 = new System.Windows.Forms.Label();
            this.button3 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.label2 = new System.Windows.Forms.Label();
            this.txtServerName = new System.Windows.Forms.TextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.richTextBox4 = new System.Windows.Forms.RichTextBox();
            this.txt_Password = new System.Windows.Forms.TextBox();
            this.Lab_Pwd = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.lab_SrvName = new System.Windows.Forms.Label();
            this.txt_UserName = new System.Windows.Forms.TextBox();
            this.txt_DatabaseName = new System.Windows.Forms.TextBox();
            this.Lab_UserName = new System.Windows.Forms.Label();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            //
            // groupBox1
            //
            this.groupBox1.Controls.Add(this.label3);
            this.groupBox1.Controls.Add(this.button3);
            this.groupBox1.Controls.Add(this.button2);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Controls.Add(this.txtServerName);
            this.groupBox1.Controls.Add(this.button1);
            this.groupBox1.Controls.Add(this.richTextBox4);
            this.groupBox1.Controls.Add(this.txt_Password);
            this.groupBox1.Controls.Add(this.Lab_Pwd);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Controls.Add(this.lab_SrvName);
            this.groupBox1.Controls.Add(this.txt_UserName);
            this.groupBox1.Controls.Add(this.txt_DatabaseName);
            this.groupBox1.Controls.Add(this.Lab_UserName);
            this.groupBox1.Location = new System.Drawing.Point(12, 12);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(336, 292);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "数据表文本字段简繁体互转";
            //
            // label3
            //
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(6, 91);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(53, 12);
            this.label3.TabIndex = 57;
            this.label3.Text = "转换结果";
            //
            // button3
            //
            this.button3.Location = new System.Drawing.Point(171, 254);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(75, 23);
            this.button3.TabIndex = 55;
            this.button3.Text = "繁体转简体";
            this.button3.UseVisualStyleBackColor = true;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            //
            // button2
            //
            this.button2.Location = new System.Drawing.Point(90, 254);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(75, 23);
            this.button2.TabIndex = 54;
            this.button2.Text = "简体转繁体";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            //
            // label2
            //
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(154, 17);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(41, 12);
            this.label2.TabIndex = 52;
            this.label2.Text = "數據庫";
            //
            // txtServerName
            //
            this.txtServerName.Location = new System.Drawing.Point(76, 14);
            this.txtServerName.Name = "txtServerName";
            this.txtServerName.Size = new System.Drawing.Size(71, 21);
            this.txtServerName.TabIndex = 53;
            this.txtServerName.Text = "127.0.0.1";
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(8, 254);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 51;
            this.button1.Text = "測試連接";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // richTextBox4
            //
            this.richTextBox4.Location = new System.Drawing.Point(8, 109);
            this.richTextBox4.Name = "richTextBox4";
            this.richTextBox4.Size = new System.Drawing.Size(314, 139);
            this.richTextBox4.TabIndex = 50;
            this.richTextBox4.Text = "";
            //
            // txt_Password
            //
            this.txt_Password.Location = new System.Drawing.Point(213, 50);
            this.txt_Password.Name = "txt_Password";
            this.txt_Password.PasswordChar = '*';
            this.txt_Password.Size = new System.Drawing.Size(109, 21);
            this.txt_Password.TabIndex = 45;
            this.txt_Password.Text = "123456";
            //
            // Lab_Pwd
            //
            this.Lab_Pwd.AutoSize = true;
            this.Lab_Pwd.Location = new System.Drawing.Point(154, 53);
            this.Lab_Pwd.Name = "Lab_Pwd";
            this.Lab_Pwd.Size = new System.Drawing.Size(53, 12);
            this.Lab_Pwd.TabIndex = 44;
            this.Lab_Pwd.Text = "登錄密碼";
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(193, 173);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(0, 12);
            this.label1.TabIndex = 46;
            //
            // lab_SrvName
            //
            this.lab_SrvName.AutoSize = true;
            this.lab_SrvName.Location = new System.Drawing.Point(6, 17);
            this.lab_SrvName.Name = "lab_SrvName";
            this.lab_SrvName.Size = new System.Drawing.Size(41, 12);
            this.lab_SrvName.TabIndex = 40;
            this.lab_SrvName.Text = "伺服器";
            //
            // txt_UserName
            //
            this.txt_UserName.Location = new System.Drawing.Point(76, 50);
            this.txt_UserName.Name = "txt_UserName";
            this.txt_UserName.Size = new System.Drawing.Size(72, 21);
            this.txt_UserName.TabIndex = 43;
            this.txt_UserName.Text = "sa";
            //
            // txt_DatabaseName
            //
            this.txt_DatabaseName.Location = new System.Drawing.Point(213, 14);
            this.txt_DatabaseName.Name = "txt_DatabaseName";
            this.txt_DatabaseName.Size = new System.Drawing.Size(109, 21);
            this.txt_DatabaseName.TabIndex = 41;
            this.txt_DatabaseName.Text = "iSystem";
            //
            // Lab_UserName
            //
            this.Lab_UserName.AutoSize = true;
            this.Lab_UserName.Location = new System.Drawing.Point(6, 53);
            this.Lab_UserName.Name = "Lab_UserName";
            this.Lab_UserName.Size = new System.Drawing.Size(53, 12);
            this.Lab_UserName.TabIndex = 42;
            this.Lab_UserName.Text = "登錄用戶";
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(360, 316);
            this.Controls.Add(this.groupBox1);
            this.Name = "Form1";
            this.Text = "C#数据表字段内容简繁体批量互转工具";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.Button button2;
        internal System.Windows.Forms.Label label2;
        internal System.Windows.Forms.TextBox txtServerName;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.RichTextBox richTextBox4;
        internal System.Windows.Forms.TextBox txt_Password;
        internal System.Windows.Forms.Label Lab_Pwd;
        private System.Windows.Forms.Label label1;
        internal System.Windows.Forms.Label lab_SrvName;
        internal System.Windows.Forms.TextBox txt_UserName;
        internal System.Windows.Forms.TextBox txt_DatabaseName;
        internal System.Windows.Forms.Label Lab_UserName;
        private System.Windows.Forms.Button button3;
        internal System.Windows.Forms.Label label3;
    }
}

 

 

Form1.cs代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Microsoft.VisualBasic;
namespace CONVERTTOOL
{
    public partial class Form1 : Form
    {

        private static string[] hz = new string[2];
        //蔚DataTable笢藩俴藩蹈蛌峈楛极
        //开始--设置--控制面板--区域和语言选项--高级--非UNICODE语言
        private void ConvertDataTableToBig5(string dtName, string connectionString)
        {
            //简体转繁体
            string sql = "";
            SqlCommand cmd = null;
            SqlDataAdapter da = null;
            DataTable dt = null;
            SqlCommandBuilder builder = null;
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                try
                {
                    sql = "select * from " + dtName;
                    cmd = new SqlCommand(sql, conn);
                    conn.Open();
                    da = new SqlDataAdapter(cmd);
                    //氝樓翋瑩茬扞
                    da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                    dt = new DataTable();
                    da.Fill(dt);                    //梢盪dt酕杸遙
                    if (dt.Rows.Count > 0)
                    {
                        //彆桶婦漪翋瑩
                        if (dt.PrimaryKey.Length > 0)
                        {
                            #region 梢盪
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                for (int j = 0; j < dt.Columns.Count; j++)
                                {
                                    if (dt.Columns[j].DataType.ToString() == "System.String")
                                    {
                                        if (dt.Rows[i][j] != null)
                                        {
                                            if (dt.Rows[i][j].ToString().Trim() != string.Empty)
                                            {
                                                string TempString = Convert.ToString(dt.Rows[i][j]).Trim();
                                                //TempString = Strings.StrConv(TempString, VbStrConv.Narrow, 0);//全角转半角
                                                //TempString =GetConvertString(TempString, CodingConsts.Traditional);
                                                TempString = Strings.StrConv(TempString, VbStrConv.TraditionalChinese, 1033);
                                                //richTextBox4.Text += "/r/n" + "转换前:" + dt.Rows[i][j].ToString().Trim() + " 转换后:" + TempString;
                                                //Console.WriteLine("转换前:" + dt.Rows[i][j].ToString().Trim() + " 转换后:" + TempString);
                                                dt.Rows[i][j] = TempString;
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion
                            builder = new SqlCommandBuilder(da);
                            da.Update(dt);
                        }
                    }
                    //庋溫訧埭
                    builder.Dispose();
                    cmd.Dispose();
                    da.Dispose();
                    dt.Clear();
                    dt.Dispose();

                }
                catch (Exception error)
                {
                    Console.WriteLine(error.ToString());
                }
                finally
                {
                    conn.Close();
                }

            }
        }
        //蔚DataTable笢藩俴藩蹈蚕楛极蛌峈潠极
        private void ConvertDataTableToGb2312(string dtName, string connectionString)
        {
            //繁体转简体
            string sql = "";
            SqlCommand cmd = null;
            SqlDataAdapter da = null;
            DataTable dt = null;
            SqlCommandBuilder builder = null;
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                try
                {
                    sql = "select * from " + dtName;
                    cmd = new SqlCommand(sql, conn);
                    conn.Open();
                    da = new SqlDataAdapter(cmd);
                    //氝樓翋瑩茬扞
                    da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                    dt = new DataTable();
                    da.Fill(dt);                    //梢盪dt酕杸遙
                    if (dt.Rows.Count > 0)
                    {
                        //彆桶婦漪翋瑩
                        if (dt.PrimaryKey.Length > 0)
                        {
                            #region 梢盪
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                for (int j = 0; j < dt.Columns.Count; j++)
                                {
                                    if (dt.Columns[j].DataType.ToString() == "System.String")
                                    {
                                        if (dt.Rows[i][j] != null)
                                        {
                                            if (dt.Rows[i][j].ToString().Trim() != string.Empty)
                                            {
                                                string TempString = Convert.ToString(dt.Rows[i][j]).Trim();
                                                //TempString = Strings.StrConv(TempString, VbStrConv.Narrow, 0);//全角转半角
                                                //TempString = GetConvertString(TempString, CodingConsts.Simplified);
                                                TempString = Strings.StrConv(TempString, VbStrConv.SimplifiedChinese, 1033);
                                                //this.richTextBox4.Text += "/r/n" + "转换前:" + dt.Rows[i][j].ToString().Trim() + " 转换后:" + TempString;
                                                //Console.WriteLine("改变前:"+dt.Rows[i][j].ToString().Trim()+"转换后"+TempString);
                                                dt.Rows[i][j] = TempString;
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion
                            builder = new SqlCommandBuilder(da);
                            da.Update(dt);
                        }
                    }
                    //庋溫訧埭
                    builder.Dispose();
                    cmd.Dispose();
                    da.Dispose();
                    dt.Clear();
                    dt.Dispose();

                }
                catch (Exception error)
                {
                    Console.WriteLine(error.ToString());
                }
                finally
                {
                    conn.Close();
                }
            }
        }
        //梢盪藩跺桶
        private static DataTable tableList(string connectionString)
        {
            //获取SQL所有数据表名的DataTable
            DataTable dt = new DataTable();
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                //SHOW TABLES峈MySQL蹈堤垀衄桶ㄛSQLServer妏蚚眈壽韜鍔
                //SqlCommand cmd = new SqlCommand("SHOW TABLES", conn);
                SqlCommand cmd = new SqlCommand("select Name from sysobjects where type='u'order by Name", conn);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet(); try
                {
                    conn.Open();
                    da.Fill(ds, "temp_tables");
                    dt = ds.Tables["temp_tables"];
                }
                catch (Exception error)
                {
                    Console.WriteLine(error.ToString());
                }
                finally
                {
                    conn.Close();
                }
            }
            return dt;
        }
        //潠极蛌楛极
        private static string getBig5(string gb2312)
        {
            //转换记录文本字段内容为繁体字符串
            string big5 = "";
            if ((gb2312 != null) && (gb2312 != String.Empty))
            {
                gb2312 = gb2312.Trim();
                big5 = Strings.StrConv(gb2312, VbStrConv.TraditionalChinese, 1028);
            }
            return big5;
        }
        //楛极蛌潠极
        private static string getGb2312(string bg5)
        {
            //转换记录文本字段内容为简体字符串
            string big5 = "";
            if ((big5 != null) && (big5 != String.Empty))
            {
                big5 = big5.Trim();
                big5 = Strings.StrConv(big5, VbStrConv.SimplifiedChinese, 2052);
            }
            return big5;
        }

 

        private void Form1_Load(object sender, EventArgs e)
        {
            hz[0] = @"皑蔼碍爱翱袄奥坝罢摆败颁办绊帮绑镑谤剥饱宝报鲍辈贝钡狈备惫绷笔毕毙币闭边编贬变辩辫标鳖别瘪濒滨宾摈饼并拨钵铂驳卜补财参蚕残惭惨灿苍舱仓沧厕侧册测层诧搀掺蝉馋谗缠铲产阐颤场尝长偿肠厂畅钞车彻尘沉陈衬撑称惩诚骋痴迟驰耻齿炽冲虫宠畴踌筹绸丑橱厨锄雏础储触处传疮闯创锤纯绰辞词赐聪葱囱从丛凑蹿窜错达带贷担单郸掸胆惮诞弹当挡党荡档捣岛祷导盗灯邓敌涤递缔颠点垫电淀钓调迭谍叠钉顶锭订丢东动栋冻斗犊独读赌镀锻断缎兑队对吨顿钝夺堕鹅额讹恶饿儿尔饵贰发罚阀珐矾钒烦范贩饭访纺飞诽废费纷坟奋愤粪丰枫锋风疯冯缝讽凤肤辐抚辅赋复负讣妇缚该钙盖干赶秆赣冈刚钢纲岗皋镐搁鸽阁铬个给龚宫巩贡钩沟构购够蛊顾剐关观馆惯贯广规硅归龟闺轨诡柜贵刽辊滚锅国过骇韩汉号阂鹤贺横轰鸿红后壶护沪户哗华画划话怀坏欢环还缓换唤痪焕涣黄谎挥辉毁贿秽会烩汇讳诲绘荤浑伙获货祸击机积饥讥鸡绩缉极辑级挤几蓟剂济计记际继纪夹荚颊贾钾价驾歼监坚笺间艰缄茧检碱硷拣捡简俭减荐槛鉴践贱见键舰剑饯渐溅涧将浆蒋桨奖讲酱胶浇骄娇搅铰矫侥脚饺缴绞轿较秸阶节茎鲸惊经颈静镜径痉竞净纠厩旧驹举据锯惧剧鹃绢杰洁结诫届紧锦仅谨进晋烬尽劲荆觉决诀绝钧军骏开凯颗壳课垦恳抠库裤夸块侩宽矿旷况亏岿窥馈溃扩阔蜡腊莱来赖蓝栏拦篮阑兰澜谰揽览懒缆烂滥捞劳涝乐镭垒类泪篱离里鲤礼丽厉励砾历沥隶俩联莲连镰怜涟帘敛脸链恋炼练粮凉两辆谅疗辽了镣猎临邻鳞凛赁龄铃凌灵岭领馏刘龙聋咙笼垄拢陇楼娄搂篓芦卢颅庐炉掳卤虏鲁赂禄录陆驴吕铝侣屡缕虑滤绿峦挛孪滦乱抡轮伦仑沦纶论萝罗逻锣箩骡骆络妈玛码蚂马骂吗买麦卖迈脉瞒馒蛮满谩猫锚铆贸么霉没镁门闷们锰梦谜弥觅幂绵缅庙灭悯闽鸣铭谬谋亩钠纳难挠脑恼闹馁内拟你腻撵捻酿鸟聂啮镊镍柠狞宁拧泞钮纽脓浓农疟诺欧鸥殴呕沤盘庞赔喷鹏骗飘频贫苹凭评泼颇扑铺朴谱栖凄脐齐骑岂启气弃讫牵扦钎铅迁签谦钱钳潜浅谴堑枪呛墙蔷强抢锹桥乔侨翘窍窃钦亲寝轻氢倾顷请庆琼穷趋区躯驱龋颧权劝却鹊确让饶扰绕热韧认纫荣绒软锐闰润洒萨鳃赛叁伞丧骚扫涩杀纱筛晒删闪陕赡缮伤赏烧绍赊摄慑设绅审婶肾渗声绳胜圣师狮湿诗尸时蚀实识驶势适释饰视试寿兽枢输书赎属术树竖数帅双谁税顺说硕烁丝饲耸怂颂讼诵擞苏诉肃虽随绥岁孙损笋缩琐锁獭挞抬态摊贪瘫滩坛谭谈叹汤烫涛绦讨腾誊锑题体屉条贴铁厅听烃铜统头秃图涂团颓蜕脱鸵驮驼椭洼袜弯湾顽万网韦违围为潍维苇伟伪纬谓卫温闻纹稳问瓮挝蜗涡窝卧呜钨乌污诬无芜吴坞雾务误锡牺袭习铣戏细虾辖峡侠狭厦吓锨鲜纤咸贤衔闲显险现献县馅羡宪线厢镶乡详响项向萧嚣销晓啸蝎协挟携胁谐写泻谢锌衅兴汹锈绣虚嘘须许叙绪续轩悬选癣绚学勋询寻驯训讯逊压鸦鸭哑亚讶阉烟盐严颜阎艳厌砚彦谚验鸯杨扬疡阳痒养样瑶摇尧遥窑谣药爷页业叶医铱颐遗仪彝蚁艺亿忆义诣议谊译异绎荫阴银饮隐樱婴鹰应缨莹萤营荧蝇赢颖哟拥佣痈踊咏涌优忧邮铀犹游诱舆鱼渔娱与屿语吁御狱誉预驭鸳渊辕园员圆缘远愿约跃钥岳粤悦阅云郧匀陨运蕴酝晕韵杂灾载攒暂赞赃脏凿枣灶责择则泽贼赠扎札轧铡闸栅诈斋债毡盏斩辗崭栈战绽张涨帐账胀赵蛰辙锗这贞针侦诊镇阵挣睁狰争帧郑证织职执纸挚掷帜质滞钟终种肿众诌轴皱昼骤猪诸诛烛瞩嘱贮铸筑驻专砖转赚桩庄装妆壮状锥赘坠缀谆着浊兹资渍踪综总纵邹诅组钻";
            hz[1] = @"皚藹礙愛翺襖奧壩罷擺敗頒辦絆幫綁鎊謗剝飽寶報鮑輩貝鋇狽備憊繃筆畢斃幣閉邊編貶變辯辮標鼈別癟瀕濱賓擯餅並撥缽鉑駁蔔補財參蠶殘慚慘燦蒼艙倉滄廁側冊測層詫攙摻蟬饞讒纏鏟産闡顫場嘗長償腸廠暢鈔車徹塵沈陳襯撐稱懲誠騁癡遲馳恥齒熾沖蟲寵疇躊籌綢醜櫥廚鋤雛礎儲觸處傳瘡闖創錘純綽辭詞賜聰蔥囪從叢湊躥竄錯達帶貸擔單鄲撣膽憚誕彈當擋黨蕩檔搗島禱導盜燈鄧敵滌遞締顛點墊電澱釣調叠諜疊釘頂錠訂丟東動棟凍鬥犢獨讀賭鍍鍛斷緞兌隊對噸頓鈍奪墮鵝額訛惡餓兒爾餌貳發罰閥琺礬釩煩範販飯訪忥飛誹廢費紛墳奮憤糞豐楓鋒風瘋馮縫諷鳳膚輻撫輔賦複負訃婦縛該鈣蓋幹趕稈贛岡剛鋼綱崗臯鎬擱鴿閣鉻個給龔宮鞏貢鈎溝構購夠蠱顧剮關觀館慣貫廣規矽歸龜閨軌詭櫃貴劊輥滾鍋國過駭韓漢號閡鶴賀橫轟鴻紅後壺護滬戶嘩華畫劃話懷壞歡環還緩換喚瘓煥渙黃謊揮輝毀賄穢會燴彙諱誨繪葷渾夥獲貨禍擊機積饑譏雞績緝極輯級擠幾薊劑濟計記際繼紀夾莢頰賈鉀價駕殲監堅箋間艱緘繭檢堿鹼揀撿簡儉減薦檻鑒踐賤見鍵艦劍餞漸濺澗將漿蔣槳獎講醬膠澆驕嬌攪鉸矯僥腳餃繳絞轎較稭階節莖鯨驚經頸靜鏡徑痙競淨糾廄舊駒舉據鋸懼劇鵑絹傑潔結誡屆緊錦僅謹進晉燼盡勁荊覺決訣絕鈞軍駿開凱顆殼課墾懇摳庫褲誇塊儈寬礦曠況虧巋窺饋潰擴闊蠟臘萊來賴藍欄攔籃闌蘭瀾讕攬覽懶纜爛濫撈勞澇樂鐳壘類淚籬離裏鯉禮麗厲勵礫曆瀝隸倆聯蓮連鐮憐漣簾斂臉鏈戀煉練糧涼兩輛諒療遼暸鐐獵臨鄰鱗凜賃齡鈴淩靈嶺領餾劉龍聾嚨籠壟攏隴樓婁摟簍蘆盧顱廬爐擄鹵虜魯賂祿錄陸驢呂鋁侶屢縷慮濾綠巒攣孿灤亂掄輪倫侖淪綸論蘿羅邏鑼籮騾駱絡媽瑪碼螞馬罵嗎買麥賣邁脈瞞饅蠻滿謾貓錨鉚貿麽黴沒鎂門悶們錳夢謎彌覓冪綿緬廟滅憫閩鳴銘謬謀畝鈉納難撓腦惱鬧餒內擬妳膩攆撚釀鳥聶齧鑷鎳檸獰甯擰濘鈕紐膿濃農瘧諾歐鷗毆嘔漚盤龐賠噴鵬騙飄頻貧蘋憑評潑頗撲鋪樸譜珳淒臍齊騎豈啓氣棄訖牽扡釺鉛遷簽謙錢鉗潛淺譴塹槍嗆牆薔強搶鍬橋喬僑翹竅竊欽親寢輕氫傾頃請慶瓊窮趨區軀驅齲顴權勸卻鵲確讓饒擾繞熱韌認紉榮絨軟銳閏潤灑薩鰓賽三傘喪騷掃澀殺紗篩曬刪閃陝贍繕傷賞燒紹賒攝懾設紳審嬸腎滲聲繩勝聖師獅濕詩屍時蝕實識駛勢適釋飾視試壽獸樞輸書贖屬術樹豎數帥雙誰稅順說碩爍絲飼聳慫頌訟誦擻蘇訴肅雖隨綏歲孫損筍縮瑣鎖獺撻擡態攤貪癱灘壇譚談歎湯燙濤縧討騰謄銻題體屜條貼鐵廳聽烴銅統頭禿圖塗團頹蛻脫鴕馱駝橢窪襪彎灣頑萬網韋違圍爲濰維葦偉僞緯謂衛溫聞紋穩問甕撾蝸渦窩臥嗚鎢烏汙誣無蕪吳塢霧務誤錫犧襲習銑戲細蝦轄峽俠狹廈嚇鍁鮮纖鹹賢銜閑顯險現獻縣餡羨憲線廂鑲鄉詳響項嚮蕭囂銷曉嘯蠍協挾攜脅諧寫瀉謝鋅釁興洶鏽繡虛噓須許敘緒續軒懸選癬絢學勳詢尋馴訓訊遜壓鴉鴨啞亞訝閹煙鹽嚴顔閻豔厭硯彥諺驗鴦楊揚瘍陽癢養樣瑤搖堯遙窯謠藥爺頁業葉醫銥頤遺儀彜蟻藝億憶義詣議誼譯異繹蔭陰銀飲隱櫻嬰鷹應纓瑩螢營熒蠅贏穎喲擁傭癰踴詠湧優憂郵鈾猶遊誘輿魚漁娛與嶼語籲禦獄譽預馭鴛淵轅園員圓緣遠願約躍鑰嶽粵悅閱雲鄖勻隕運蘊醞暈韻雜災載攢暫贊贓髒鑿棗竈責擇則澤賊贈紮劄軋鍘閘柵詐齋債氈盞斬輾嶄棧戰綻張漲帳賬脹趙蟄轍鍺這貞針偵診鎮陣掙睜猙爭幀鄭證織職執紙摯擲幟質滯鍾終種腫衆謅軸皺晝驟豬諸誅燭矚囑貯鑄築駐專磚轉賺樁莊裝妝壯狀錐贅墜綴諄著濁茲資漬蹤綜總縱鄒詛組鑽";
            Console.WriteLine("编码长度" + hz[0].Length.ToString());//1301个汉字,其它汉字等待搜集
        }
        /**/
        /// <summary>
        /// 汉字编码。
        /// </summary>
        public enum CodingConsts : int
        {
            /**/
            /// <summary>
            /// 简体。
            /// </summary>
            Simplified = 0,
            /**/
            /// <summary>
            /// 繁体。
            /// </summary>
            Traditional = 1
        }

 

        /**/
        /// <summary>
        /// 汉字简繁互换。
        /// </summary>
        /// <param name="HzString">输入的汉字。</param>
        /// <param name="Coding">转换后的编码。</param>
        /// <returns></returns>
        public static string GetConvertString(string HzString, CodingConsts Coding)
        {
            string ret = "";
            foreach (char c in HzString)
            {
                int b = ((int)Coding) == 0 ? 1 : 0;
                int i = hz[b].IndexOf(c);
                if (i > 0)
                    ret += hz[(int)Coding].Substring(i, 1);
                else
                    ret += c.ToString();
            }
            return ret;
        }
       
        public Form1()
        {
            InitializeComponent();
        }
       
        private void button1_Click(object sender, EventArgs e)
        {
            //测试数据库连接
            this.button1.Enabled = false;
            this.richTextBox4.Text = "";
            string strServerName = this.txtServerName.Text.Trim();
            string strDbName = this.txt_DatabaseName.Text.Trim();
            string strUserName = this.txt_UserName.Text.Trim();
            string strPassword = this.txt_Password.Text.Trim();
            DataTable myDataTable = new DataTable();
            try
            {
                SqlConnection thisConnection = new SqlConnection("Data Source=" + strServerName + ";Initial Catalog=Master;User ID=" + strUserName + ";password=" + strPassword);
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = new SqlCommand("select * from sysservers", thisConnection);
                DataSet ds = new DataSet();
                da.Fill(ds, "Temp");
                myDataTable = ds.Tables["Temp"];
                thisConnection.Close();
                if (myDataTable.Rows.Count > 0)
                {
                    this.richTextBox4.Text += "/r/n数据库连接测试成功";
                }
                else
                {
                    this.richTextBox4.Text += "/r/n数据库连接测试失败";
                }
            }
            catch (Exception ex)
            {
                this.richTextBox4.Text += "/r/n测试连接到数据库时出错" + ex.Message;
            }
            this.button1.Enabled = true;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            //简体转繁体
            this.button2.Enabled = false;
            string strServerName = this.txtServerName.Text.Trim();
            string strDbName = this.txt_DatabaseName.Text.Trim();
            string strUserName = this.txt_UserName.Text.Trim();
            string strPassword = this.txt_Password.Text.Trim();
            string strConnectionString = "Data Source=" + strServerName + ";User ID=" + strUserName + ";Password=" + strPassword + ";DataBase=" + strDbName + ";";
            //婦漪垀衄桶靡備腔DataTable(菴0蹈峈杅擂桶靡)
            DataTable dtAll = tableList(strConnectionString);
            if (dtAll != null)
            {
                if (dtAll.Rows.Count > 0)
                {
                    for (int i = 0; i < dtAll.Rows.Count; i++)
                    {
                        ConvertDataTableToBig5(dtAll.Rows[i][0].ToString(), strConnectionString);
                    }
                }
            }
            this.button2.Enabled = true;
        }
        private void button3_Click(object sender, EventArgs e)
        {
            //繁体转简体
            this.button3.Enabled = false;
            string strServerName = this.txtServerName.Text.Trim();
            string strDbName = this.txt_DatabaseName.Text.Trim();
            string strUserName = this.txt_UserName.Text.Trim();
            string strPassword = this.txt_Password.Text.Trim();
            string strConnectionString = "Data Source=" + strServerName + ";User ID=" + strUserName + ";Password=" + strPassword + ";DataBase=" + strDbName + ";";
            //婦漪垀衄桶靡備腔DataTable
            DataTable dtAll = tableList(strConnectionString);
            if (dtAll != null)
            {
                if (dtAll.Rows.Count > 0)
                {
                    for (int i = 0; i < dtAll.Rows.Count; i++)
                    {
                        ConvertDataTableToGb2312(dtAll.Rows[i][0].ToString(), strConnectionString);
                    }
                }
            }
            this.button3.Enabled = true;
        }

       
    }
}

你可能感兴趣的:(String,C#,null,工具,button,dataset)