?? 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;
namespace 中文轉換
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (this.comboBox3.Text!= "" && this.comboBox4.Text!= "")
{
convert(this.comboBox3.SelectedItem.ToString(), this.comboBox4.SelectedItem.ToString());
}
else
{
MessageBox.Show("轉換的列和目標列不能為空,請選擇.");
this.comboBox3.Focus();
}
}
//轉換
public void convert(string col1,string col2)
{
string[] data=new string[500];
this.listViewafter.Items.Clear();
this.listViewafter.Columns.Clear();
for (int i = 0; i <this.listviewfront.Columns.Count; i++)
{
this.listViewafter.Columns.Add(this.listviewfront.Columns[i].Text);
}
for (int j = 0; j < this.listviewfront.Items.Count; j++)
{
for (int p = 0; p < this.listviewfront.Columns.Count; p++)
{
data[p] = this.listviewfront.Items[j].SubItems[p].Text;
}
this.listViewafter.Items.Add(new ListViewItem(data));
}
MessageBox.Show(col1,col2);
// int this.listViewafter.co
this.listViewafter.Columns.RemoveByKey(col1);
// MessageBox.Show("c1="+c1.ToString()+"c2="+c2.ToString());
//開始轉換
for (int q = 0; q < this.listViewafter.Items.Count; q++)
{
for (int k = 0; k < this.listViewafter.Columns.Count; k++)
{
//string c2 = this.listViewafter.FindItemWithText(col2);
// if(this.listViewafter.Items[q].SubItems[k].
//this.listViewafter.Items[q].SubItems[k].Text=
}
}
}
//先定列
private void selcol(string colname)
{
for (int i = 0; i < this.listViewafter.Items.Count; i++)
{
for (int j = 0; j < this.listViewafter.Columns.Count; j++)
{
if (listViewafter.Columns[j].Text ==colname)
{
this.listViewafter.Select();
}
}
}
}
//綁定表名
private void bindtable()
{
this.comboBox2.Items.Clear();
this.comboBox3.Items.Clear();
this.comboBox4.Items.Clear();
string database = this.textBox1.Text.Trim();
string contring = "server=.;database=" + database + ";uid=sa;pwd=makea";
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = contring;
SqlCommand opendata = new SqlCommand();
opendata.Connection = sqlcon;
string comtring = "select * from information_schema.tables where table_type='base table'";
opendata.CommandText = comtring;
try
{
sqlcon.Open();
}
catch { }
try
{
SqlDataReader datasdr = opendata.ExecuteReader();
while (datasdr.Read())
{
if (datasdr["table_name"].ToString() != "dtproperties")
{
this.comboBox2.Items.Add(datasdr["table_name"].ToString());
}
}
datasdr.Close();
}
catch (Exception X)
{
}
finally
{
sqlcon.Close();
}
}
private void bindcom()
{
this.comboBox3.Items.Clear();
this.comboBox4.Items.Clear();
string database = this.textBox1.Text.Trim();
string contring = "server=.;database=" + database + ";uid=sa;pwd=makea";
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = contring;
SqlCommand opendata = new SqlCommand();
opendata.Connection = sqlcon;
string comtring = "select * from syscolumns where id =(select id from sysobjects where name='"+this.comboBox2.Text+"')";
opendata.CommandText = comtring;
try
{
sqlcon.Open();
}
catch (Exception x) { MessageBox.Show(x.ToString()); }
try
{
SqlDataReader datasdr = opendata.ExecuteReader();
while (datasdr.Read())
{
this.comboBox3.Items.Add(datasdr["name"].ToString());
this.comboBox4.Items.Add(datasdr["name"].ToString());
}
datasdr.Close();
}
catch (Exception X)
{
MessageBox.Show(X.ToString());
}
finally
{
sqlcon.Close();
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
bindtable();
this.comboBox2.Text = null;
this.comboBox3.Text = null;
this.comboBox4.Text = null;
this.comboBox4.Items.Clear();
this.comboBox3.Items.Clear();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
bindcom();
ydatabind();
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void ydatabind()
{
this.listviewfront.Columns.Clear();
this.listviewfront.Items.Clear();
this.comboBox3.Text = null;
this.comboBox4.Text = null;
string database = this.textBox1.Text.Trim();
string contring = "server=.;database=" + database + ";uid=sa;pwd=makea";
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = contring;
SqlCommand opendata = new SqlCommand();
opendata.Connection = sqlcon;
string comtring = "select * from syscolumns where id =(select id from sysobjects where name='" + this.comboBox2.Text + "')";
opendata.CommandText = comtring;
try
{
sqlcon.Open();
}
catch (Exception x) { MessageBox.Show(x.ToString()); }
try
{
SqlDataReader datasdr = opendata.ExecuteReader();
//綁定列
while (datasdr.Read())
{
this.listviewfront.Columns.Add(datasdr["name"].ToString());
// this.comboBox4.Items.Add(datasdr["name"].ToString());
}
datasdr.Close();
//綁定數據
SqlCommand datlistcom = new SqlCommand();
datlistcom.CommandText = "select * from "+this.comboBox2.Text;
datlistcom.Connection = sqlcon;
SqlDataReader datalist=datlistcom.ExecuteReader();
int i=datalist.FieldCount;
string[] data=new string[i];
while(datalist.Read())
{
for (int j = 0; j < i; j++)
{
data[j]=datalist.GetValue(j).ToString();
} listviewfront.Items.Add(new ListViewItem(data));
//this.listviewfront.Items.Add(new ListviewItem(new string[{datalist[1].ToString()}]));
// this.comboBox4.Items.Add(datasdr["name"].ToString());
}
datalist.Close();
}
catch (Exception X)
{
MessageBox.Show(X.ToString());
}
finally
{
sqlcon.Close();
}
}
private void tdatabind()
{
this.listviewfront.Columns.Clear();
this.listviewfront.Items.Clear();
this.comboBox3.Text = null;
string database = this.textBox1.Text.Trim();
string contring = "server=.;database=" + database + ";uid=sa;pwd=makea";
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = contring;
SqlCommand opendata = new SqlCommand();
opendata.Connection = sqlcon;
string comtring = "select * from syscolumns where id =(select id from sysobjects where name='" + this.comboBox2.Text + "')";
opendata.CommandText = comtring;
try
{
sqlcon.Open();
}
catch (Exception x) { MessageBox.Show(x.ToString()); }
try
{
SqlDataReader datasdr = opendata.ExecuteReader();
//綁定列
while (datasdr.Read())
{
this.listviewfront.Columns.Add(datasdr["name"].ToString());
// this.comboBox4.Items.Add(datasdr["name"].ToString());
}
datasdr.Close();
//綁定數據
SqlCommand datlistcom = new SqlCommand();
datlistcom.CommandText = "select * from " + this.comboBox2.Text;
datlistcom.Connection = sqlcon;
SqlDataReader datalist = datlistcom.ExecuteReader();
int i = datalist.FieldCount;
string[] data = new string[i];
while (datalist.Read())
{
for (int j = 0; j < i; j++)
{
data[j] = datalist.GetValue(j).ToString();
} listViewafter.Items.Add(new ListViewItem(data));
//this.listviewfront.Items.Add(new ListviewItem(new string[{datalist[1].ToString()}]));
// this.comboBox4.Items.Add(datasdr["name"].ToString());
}
datalist.Close();
}
catch (Exception X)
{
MessageBox.Show(X.ToString());
}
finally
{
sqlcon.Close();
}
}
private void tool_Click(object sender, EventArgs e)
{
second tool = new second();
tool.Show();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -