Ejemplo n.º 1
0
        private void cmbCity_SelectedIndexChanged(object sender, EventArgs e)
        {
            var name = string.Format(
                "{0}_{1}",
                ((ComboboxItem)this.cmbProvice.SelectedItem).Text.TrimEnd('省'),
                ((ComboboxItem)((ComboBox)sender).SelectedItem).Text.TrimEnd('市'));

            this.txbPinyin.Text = TextToPinyin.Convert(name).Pinyin.ToLower();
        }
Ejemplo n.º 2
0
        private void DoSomthing(object nobject)
        {
            try
            {
                NameObject nameObject = nobject as NameObject;
                string     quanpin    = nameObject.quanpin;
                string     shouZim    = nameObject.shouZim;
                string     hanzi      = nameObject.hanzi;
                string     tableName  = nameObject.tableName;
                string     msg2       = "开始获取所有数据信息";
                if (this.OnProcessNotify != null)
                {
                    this.OnProcessNotify(msg2, 0);
                }
                string sqlString = "SELECT gid," + hanzi + "," + quanpin + "," + shouZim + " FROM " + tableName
                                   + " where " + hanzi + " is not null and (szm is  null or szm = '')";

                if (tableName.Contains("roadnet") || tableName.Contains("road"))
                {
                    sqlString = string.Format(
                        "select  distinct name from {0}   where name is not null and name != ''",
                        tableName);
                }
                msg2 = "完成获取所有数据信息";
                if (this.OnProcessNotify != null)
                {
                    this.OnProcessNotify(msg2, 0);
                }
                int count =
                    int.Parse(
                        this.dbcon.ExecuteScalar(string.Format("Select Count(1) From ({0}) as t", sqlString)).ToString());
                var          read = this.dbcon.ExecuteReader(sqlString);
                int          j    = 0;
                PinyinHelper helper;
                while (read.Read())
                {
                    j++;
                    string sql = "";
                    try
                    {
                        if (tableName.Contains("roadnet") || tableName.Contains("road"))
                        {
                            var    name       = read.GetString(0);
                            string hanziValue = name.Trim().Replace('\'', ' ').Replace('(', '(').Replace(')', ')');
                            helper = TextToPinyin.Convert(hanziValue);
                            //sql = "update " + tableName + " set " + quanpin + "='" + helper.Pinyin + "',"
                            //      + shouZim + "='" + helper.Szm + "' where name ='" + read.GetInt32(0) + "'";

                            sql = string.Format(
                                "update {0} set quanpin='{1}',szm='{2}' where name ='{3}'",
                                tableName,
                                helper.Pinyin,
                                helper.Szm, name);

                            this.dbcon.ExecuteNonQuery(sql);
                        }
                        else
                        {
                            string hanziValue = read.GetString(1).Trim().Replace('\'', ' ').Replace('(', '(').Replace(')', ')');
                            helper = TextToPinyin.Convert(hanziValue);
                            sql    = "update " + tableName + " set " + quanpin + "='" + helper.Pinyin + "',"
                                     + shouZim + "='" + helper.Szm + "' where gid=" + read.GetInt32(0);

                            this.dbcon.ExecuteNonQuery(sql);
                        }
                    }
                    catch (Exception e)
                    {
                        log.Error(e);
                    }
                    string msg = "已处理路网数据" + j.ToString() + "条,共" + count.ToString() + "条";
                    if (this.OnProcessNotify != null)
                    {
                        this.OnProcessNotify(msg, (j * 100) / count);
                    }
                }
                read.Close();
                string msg1 = "处理完成";
                if (this.OnProcessNotify != null)
                {
                    this.OnProcessNotify(msg1, 100);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }