📄 tongxun.cs
字号:
strdizhi = " ";
}
ListViewItem li = new ListViewItem () ;
li.SubItems.Clear() ;
string ID = m_nID.ToString();
li.SubItems[0].Text = ID;
li.SubItems.Add (strliebie) ;
li.SubItems.Add (strname) ;
li.SubItems.Add (strdianhua) ;
li.SubItems.Add (strdianhua2) ;
li.SubItems.Add (strdizhi) ;
string time = dateTimePicker1.Value.ToString();
li.SubItems.Add (time);
listView1.Items.Add ( li ) ;
//-----------------------------------------------------------
string strCommand = "INSERT INTO 通讯 (通讯类,名字,电话1,电话2,所在地址,当前时间) VALUES ('"+strliebie+"','"+strname+"','"+strdianhua+"','"+strdianhua2+"','"+strdizhi+"','"+time+"')";
Form1 dlg = new Form1();
oleDbConnection1.Open() ; // 打开数据连接
OleDbCommand cmd = new OleDbCommand ( strCommand ,oleDbConnection1 ) ;
cmd.CommandText=strCommand;
//reader = cmd.ExecuteReader() ;//获得数据集
int i=cmd.ExecuteNonQuery();
oleDbConnection1.Close();
cmd.Dispose();
}
private void delete_Click(object sender, System.EventArgs e)
{
int i;
for(i = listView1.SelectedItems.Count - 1;i>=0;i--)
{
string DBnum;
//获取当前选中的条目之一
ListViewItem li = listView1.SelectedItems[i];
//listView1.SelectedItems[0].SubItems[0].Text
//删除这个条目
listView1.Items.Remove(li);
DBnum =li.SubItems[6].Text;
//DBnum = listView1.SelectedItems[i].SubItems[5].Text;
string strCommand = "delete from 通讯 where 当前时间 = '"+DBnum+"'";
oleDbConnection1.Open() ; // 打开数据连接
OleDbCommand cmd = new OleDbCommand ( strCommand , oleDbConnection1 ) ;
cmd.CommandText=strCommand;
// reader = cmd.ExecuteReader() ;//获得数据集
int i1=cmd.ExecuteNonQuery();
oleDbConnection1.Close();
}
}
private void amend_Click(object sender, System.EventArgs e)
{
int i = 0;
for(i = listView1.SelectedItems.Count - 1;i>=0;i--)
{
ListViewItem li = listView1.SelectedItems[0];
stro = li.SubItems[6].Text;
string strliebie = leibie.Text;
if(strliebie == "" || strliebie == " ")
{
strliebie = " ";
}
string strname = name.Text;
if(strname == "" || strname == " ")
{
strname = " ";
}
string strdianhua = dianhua.Text;
if(strdianhua == "" || strdianhua == " ")
{
strdianhua = " ";
}
string strdianhua2 = dianhua2.Text;
if(strdianhua2 == "" || strdianhua2 == " ")
{
strdianhua2 = " ";
}
string strdizhi = dizhi.Text;
if(strdizhi == "" || strdizhi == " ")
{
strdizhi = " ";
}
string strCommand = "UPDATE 通讯 SET 通讯类 = '"+strliebie+"',名字 = '"+strname+"',电话1 = '"+strdianhua+"',电话2 = '"+strdianhua2+"',所在地址 = '"+strdizhi+"' where 当前时间 = '"+stro+"'";
oleDbConnection1.Open() ; // 打开数据连接
OleDbCommand cmd = new OleDbCommand ( strCommand , oleDbConnection1 ) ;
cmd.CommandText=strCommand;
// reader = cmd.ExecuteReader() ;//获得数据集
int i1=cmd.ExecuteNonQuery();
oleDbConnection1.Close();
li.SubItems[1].Text = strliebie;
li.SubItems[2].Text = strname;
li.SubItems[3].Text = strdianhua;
li.SubItems[4].Text = strdianhua2;
li.SubItems[5].Text = strdizhi;
break ;
}
}
private void chaxun_Click(object sender, System.EventArgs e)
{
bool m_bcontrol = false;
string strSql = "select * from 通讯 where ";
string strliebie = leibie.Text;
if(strliebie == "" || strliebie == " ")
{
}
else
{
strSql+= "通讯类 = '"+strliebie+"'";
m_bcontrol = true;
}
string strname = name.Text;
if(strname == "" || strname == " ")
{
strname = " ";
}
else
{
if(m_bcontrol == true)
{
strSql += " and 名字 = '"+strname+"'";
}
else
{
strSql += " 名字 = '"+strname+"'";
m_bcontrol = true;
}
}
string strdianhua = dianhua.Text;
if(strdianhua == "" || strdianhua == " ")
{
strdianhua = " ";
}
else
{
if(m_bcontrol == true)
{
strSql += " and 电话1 = '"+strdianhua+"'";
}
else
{
strSql += " 电话1 = '"+strdianhua+"'";
m_bcontrol = true;
}
}
string strdianhua2 = dianhua2.Text;
if(strdianhua2 == "" || strdianhua2 == " ")
{
strdianhua2 = " ";
}
else
{
if(m_bcontrol == true)
{
strSql += " and 电话2 = '"+strdianhua2+"'";
}
else
{
strSql += " 电话2 = '"+strdianhua2+"'";
m_bcontrol = true;
}
}
string strdizhi = dizhi.Text;
if(strdizhi == "" || strdizhi == " ")
{
strdizhi = " ";
}
else
{
if(m_bcontrol == true)
{
strSql += " and 所在地址 = '"+strdizhi+"'";
}
else
{
strSql += " 所在地址 = '"+strdizhi+"'";
}
}
oleDbConnection1.Open();
OleDbCommand cmd1 = new OleDbCommand ( strSql , oleDbConnection1 ) ;
cmd1.CommandText=strSql;
//获得数据集
reader = cmd1.ExecuteReader() ;
listView1.Items.Clear();
m_nID = 1;
while (reader.Read())
{
string strTemp;
string ID = m_nID.ToString();
ListViewItem li = new ListViewItem () ;
li.SubItems.Clear() ;
//strTemp = reader["编号"].ToString();
li.SubItems[0].Text = ID;
strTemp = reader["通讯类"].ToString();
li.SubItems.Add (strTemp) ;
strTemp = reader["名字"].ToString();
li.SubItems.Add (strTemp) ;
strTemp = reader["电话1"].ToString();
li.SubItems.Add (strTemp) ;
strTemp = reader["电话2"].ToString();
li.SubItems.Add (strTemp) ;
strTemp = reader["所在地址"].ToString();
li.SubItems.Add (strTemp) ;
strTemp = reader["当前时间"].ToString();
li.SubItems.Add (strTemp) ;
listView1.Items.Add ( li ) ;
m_nID++;
}
oleDbConnection1.Close();
m_nID = 0;
m_BIDconTrol = false;
}
private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
//listView1.r
int i = 0;
for(i = listView1.SelectedItems.Count - 1;i>=0;i--)
{
string str;
ListViewItem li = listView1.SelectedItems[0];
str = li.SubItems[1].Text;
if(str == " "|| str == null)
{
str = "";
}
leibie.Text = str;
str = li.SubItems[2].Text;
if(str == " "|| str == null)
{
str = "";
}
name.Text = str;
str = li.SubItems[3].Text;
if(str == " "|| str == null)
{
str = "";
}
dianhua.Text =str;
str = li.SubItems[4].Text;
if(str == " "|| str == null)
{
str = "";
}
dianhua2.Text =str;
str = li.SubItems[5].Text;
if(str == " "|| str == null)
{
str = "";
}
dizhi.Text = str;
break ;
}
}
private void deleteAll_Click(object sender, System.EventArgs e)
{
string strCommand = "delete from 通讯";
oleDbConnection1.Open() ; // 打开数据连接
OleDbCommand cmd = new OleDbCommand ( strCommand , oleDbConnection1 ) ;
cmd.CommandText=strCommand;
// reader = cmd.ExecuteReader() ;//获得数据集
int i1=cmd.ExecuteNonQuery();
oleDbConnection1.Close();
listView1.Items.Clear();
m_nID = 0;
}
private void showAll_Click(object sender, System.EventArgs e)
{
m_BIDconTrol = false;
string strSql = "select * from 通讯 ";
oleDbConnection1.Open();
OleDbCommand cmd1 = new OleDbCommand ( strSql , oleDbConnection1 ) ;
cmd1.CommandText=strSql;
//获得数据集
reader = cmd1.ExecuteReader() ;
listView1.Items.Clear();
m_nID = 1;
while (reader.Read())
{
string strTemp;
string ID = m_nID.ToString();
ListViewItem li = new ListViewItem () ;
li.SubItems.Clear() ;
li.SubItems[0].Text = ID;
strTemp = reader["通讯类"].ToString();
if(strTemp == " " || strTemp == " ")
{
strTemp = "";
}
li.SubItems.Add (strTemp) ;
strTemp = reader["名字"].ToString();
if(strTemp == " " || strTemp == " ")
{
strTemp = "";
}
li.SubItems.Add (strTemp) ;
strTemp = reader["电话1"].ToString();
if(strTemp == " " || strTemp == " ")
{
strTemp = "";
}
li.SubItems.Add (strTemp) ;
strTemp = reader["电话2"].ToString();
if(strTemp == " " || strTemp == " ")
{
strTemp = "";
}
li.SubItems.Add (strTemp) ;
strTemp = reader["所在地址"].ToString();
if(strTemp == " " || strTemp == " ")
{
strTemp = "";
}
li.SubItems.Add (strTemp) ;
strTemp = reader["当前时间"].ToString();
if(strTemp == " " || strTemp == " ")
{
strTemp = "";
}
li.SubItems.Add (strTemp) ;
listView1.Items.Add ( li ) ;
m_nID++;
}
oleDbConnection1.Close();
m_nID = 0;
m_BIDconTrol = false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -