</pre>1. 程序设计要求</h1></div><p>设计一个用户管理系统,对系统中的用户进行管理。假定,用户表中有下列字段:用户名,密码,电话和 email 等信息。要求,1)利用 SQL server 首先创建用户数据表;2)实现对用户的增加、删除、修改和查询等功能。</p><div style="background:#F0A22E"><h1>2.程序设计流程图</h1></div><p align="center"><img src="http://img.blog.csdn.net/20141123074524609?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDU3MDU1MQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /></p><div style="background:#F0A22E"><h1>3.程序设计亮点</h1></div><p>(0)根据学生在使用CMS系统和Discuz系统时,发现其数据库的后台操作界面很简单,因此根据sql语句的基本组成,设置where条件选择输入区和更新插入的更新区。</p><p>(1)只有在勾选该字段时,才允许输入该字段的值</p><p>(2)使用listview列出数据查询结果</p><p>(3)支持数据浏览,无须手动输入查询语句</p><div style="background:#F0A22E"><h1>4.程序运行截图</h1></div><p> 以下只是简单的几组测试,其他的sql组合同理能够运行</p><p>(1) 浏览数据</p><p style="text-align:center"></p><p align="right"><em><img src="http://img.blog.csdn.net/20141123074547218?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDU3MDU1MQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />注:选择浏览操作的示意图</em></p><p> (2)选择查看符合相应条件的数据</p><p align="right"></p><p align="right"><em><img src="http://img.blog.csdn.net/20141123074546626?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDU3MDU1MQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />注:设置选择的条件示意图</em></p><p align="right"></p><p align="right"><em><img src="http://img.blog.csdn.net/20141123074559590?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDU3MDU1MQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />注:执行选择后的结果</em></p><p> (3)插入数据</p><p align="right"></p><p align="right"><em><img src="http://img.blog.csdn.net/20141123074611555?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDU3MDU1MQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />注:插入数据示意</em></p><p align="right"></p><p align="right"><em><img src="http://img.blog.csdn.net/20141123074626500?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDU3MDU1MQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />注:数据插入后,浏览数据结果</em></p><p>(4)更新数据</p><p align="right"></p><p align="right"><em><img src="http://img.blog.csdn.net/20141123074637014?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDU3MDU1MQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />注:设置更新条件示意图</em></p><p align="right"></p><p align="right"><em><img src="http://img.blog.csdn.net/20141123074732160?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDU3MDU1MQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />注:执行更新操作后</em></p><p> </p><p>(5)删除数据</p><p align="right"></p><p align="right"><em><img src="http://img.blog.csdn.net/20141123074918734?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDU3MDU1MQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />注:设置删除条件示意图</em></p><p align="right"></p><p align="right"><em><img src="http://img.blog.csdn.net/20141123075043479?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDU3MDU1MQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />注:删除操作执行后</em></p><p align="right"><em></em></p><p align="right"><em></em></p><p align="right" style="text-align:left"><span style="font-size:18px; color:#009900"></span></p><pre name="code" class="html"><ol><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;">using System;</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;">using System.Collections.Generic;</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;">using System.ComponentModel;</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;">using System.Data;</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;">using System.Drawing;</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;">using System.Linq;</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;">using System.Text;</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;">using System.Windows.Forms;</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;">using System.Data;</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;">using System.Data.Sql;</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;">using System.Data.SqlClient;</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;">namespace 数据库操作_WNFORM</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;">{</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;"> public partial class Form1 : Form</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;"> {</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;"> private SqlConnection sqlcon;</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;"> private SqlCommand sqlcom;</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;"> private SqlDataReader sda;</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;"> private string conn_str = @"Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|info.mdf;Integrated Security=True;User Instance=True";</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;"> public Form1()</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;"> {</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;"> InitializeComponent();</span></li><li style="font-weight: bold;"><span style="font-family: Arial, Helvetica, sans-serif;"> }</span></li><li><strong>
</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> private void Form1_Load(object sender, EventArgs e)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> listView_res.Columns.Add("用户名");</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> listView_res.Columns.Add("密 码");</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> listView_res.Columns.Add("手机号");</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> listView_res.Columns.Add("邮箱号");</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> listView_res.Columns[0].Width = 250;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> listView_res.Columns[1].Width = 340;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> listView_res.Columns[2].Width = 245;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> listView_res.Columns[3].Width = 325;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong>
</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> private void checkBox1_CheckedChanged(object sender, EventArgs e)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_name.Enabled = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong>
</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> private void checkBox3_CheckedChanged(object sender, EventArgs e)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_pass.Enabled = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong>
</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> private void checkBox2_CheckedChanged(object sender, EventArgs e)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_name2.Enabled = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong>
</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> private void checkBox6_CheckedChanged(object sender, EventArgs e)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_pass2.Enabled = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong>
</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> private void checkBox4_CheckedChanged(object sender, EventArgs e)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_tel.Enabled = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong>
</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> private void checkBox5_CheckedChanged(object sender, EventArgs e)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_mail.Enabled = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong>
</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> private void checkBox7_CheckedChanged(object sender, EventArgs e)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_tel2.Enabled = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong>
</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> private void checkBox8_CheckedChanged(object sender, EventArgs e)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_mail2.Enabled = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> private void init_controler()</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> checkBox1.Checked = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> checkBox2.Checked = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> checkBox3.Checked = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> checkBox4.Checked = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> checkBox5.Checked = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> checkBox6.Checked = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> checkBox7.Checked = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> checkBox8.Checked = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> </strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_mail.Text = "";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_name.Text = "";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_pass.Text = "";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_tel.Text = "";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_mail2.Text = "";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_name2.Text = "";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_pass2.Text = "";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_tel2.Text = "";</strong></li><li><strong>
</strong></li><li><strong>
</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_mail.Enabled = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_name.Enabled = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_pass.Enabled = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_tel.Enabled = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_mail2.Enabled = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_name2.Enabled = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_pass2.Enabled = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> textBox_tel2.Enabled = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> private string [] get_where()</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> string [] res=new string[4];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (textBox_name.Text != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong>
</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res[0]= textBox_name.Text.ToString();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (textBox_pass.Text != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res[1]= textBox_pass.Text.ToString();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (textBox_tel.Text != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res[2]= textBox_tel.Text.ToString();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong>
</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (textBox_mail.Text != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res[3]= textBox_mail.Text.ToString();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> return res;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> private string[] get_value()</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> string[] res = new string[4];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (textBox_name2.Text != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res[0] = textBox_name2.Text.ToString();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (textBox_pass2.Text != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res[1] = textBox_pass2.Text.ToString();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (textBox_tel2.Text != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res[2] = textBox_tel2.Text.ToString();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong>
</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (textBox_mail2.Text != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res[3] = textBox_mail2.Text.ToString();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> return res;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> //执行数据库查询</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> private string execu_sql()</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong>
</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> string res = "";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcon = new SqlConnection(conn_str);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom = new SqlCommand();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcon.Open();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Connection = sqlcon;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> string sw = "";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sw = comboBox1.SelectedItem.ToString();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> MessageBox.Show(sw);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> /*</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> 浏览数据</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> 查询数据</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> 插入数据</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> 更新数据</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> 删除数据</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> */</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> switch (sw)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> { </strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> case "浏览数据":</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res = "select * from [用户表]";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.CommandText = res;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> int count = 0;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> try</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sda = sqlcom.ExecuteReader();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> listView_res.Items.Clear();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> while (sda.Read())</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> ListViewItem lvi = new ListViewItem();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.Text = sda.GetString(0);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.SubItems.Add(sda.GetString(1));</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.SubItems.Add(sda.GetString(2));</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.SubItems.Add(sda.GetString(3));</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.UseItemStyleForSubItems = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.SubItems[0].BackColor = Color.HotPink;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.SubItems[1].BackColor = Color.LightSkyBlue;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.SubItems[2].BackColor = Color.SpringGreen;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.SubItems[3].BackColor = Color.Orange;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> listView_res.Items.Add(lvi);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> count++;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if(count==0)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> MessageBox.Show("没有查询到匹配的数据");</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> catch (Exception ex)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> MessageBox.Show("出现数据查询错误,请重试" + ex.Message);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> finally {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcon.Close();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> break;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> case "查询数据":</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res = "select * from [用户表]";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> string [] wh=get_where();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> bool tags=false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if(wh!=null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" where ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (wh[0]!= "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res += " 用户名=@user ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> //res+=wh[0];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tags=true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (wh[1] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if(tags)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+="and ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" 密码=@pass ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> //res+=wh[1];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tags=true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (wh[2] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if(tags)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res += " and ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" 电话=@tel ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> //res+=wh[2];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tags=true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if(wh[3]!="")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if(tags)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res += " and ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" 邮箱=@mail ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> // res+=wh[1];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.CommandText = res;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (wh != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (wh[0] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@user", wh[0]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (wh[1] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@pass", wh[1]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (wh[2] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@tel", wh[2]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (wh[3] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@mail", wh[3]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> try</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sda = sqlcom.ExecuteReader();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> listView_res.Items.Clear();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (sda.Read())</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> ListViewItem lvi = new ListViewItem();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.Text = sda.GetString(0);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.SubItems.Add(sda.GetString(1));</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.SubItems.Add(sda.GetString(2));</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.SubItems.Add(sda.GetString(3));</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.UseItemStyleForSubItems = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.SubItems[0].BackColor = Color.HotPink;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.SubItems[1].BackColor = Color.LightSkyBlue;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.SubItems[2].BackColor = Color.SpringGreen;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> lvi.SubItems[3].BackColor = Color.Orange;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> listView_res.Items.Add(lvi);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> else</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> MessageBox.Show("没有查询到匹配的数据,请检查原因");</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> catch (Exception ex)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> MessageBox.Show("出现数据查询错误,请重试" + ex.Message);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> finally {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcon.Close();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> break;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> case "插入数据":</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res = "insert into [用户表](";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> string [] vl=get_value();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> bool tagi=false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vl != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vl[0] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res += "用户名";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tagi = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vl[1] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (tagi)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" , ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+="密码 ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tagi = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vl[2] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (tagi)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" , ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+="电话";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tagi = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vl[3] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (tagi)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" , ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+="邮箱";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res += " ) values(";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> /************* 构造values *****************/</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tagi=false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vl != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vl[0] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res += "@user";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> //res += vl[0];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tagi = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vl[1] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (tagi)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" , ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+="@pass";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> //res += vl[1];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tagi = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vl[2] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (tagi)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" , ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+="@tel";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> // res += vl[2];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tagi = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vl[3] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (tagi)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" , ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+="@mail";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> //res += vl[1];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res += " )";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.CommandText = res;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vl != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vl[0] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@user", vl[0]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vl[1] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@pass", vl[1]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vl[2] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@tel", vl[2]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vl[3] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@mail", vl[3]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> int i = sqlcom.ExecuteNonQuery();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (i > 0)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> MessageBox.Show("插入成功,请浏览数据");</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> else {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> MessageBox.Show("插入失败,请检查原因");</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcon.Close();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> break;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> case "更新数据":</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res = "update [用户表] set";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> string [] vlu=get_value();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> string[] whu = get_where();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> bool tagu=false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vlu != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vlu[0] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res += " 用户名=";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res += " @user2";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tagu = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vlu[1] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (tagu)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" , ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" 密码=";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res += " @pass2";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tagu = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vlu[2] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (tagu)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" , ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" 电话=";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res += " @tel2";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tagu = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vlu[3] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (tagu)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" , ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" 邮箱=";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" @mail2";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> } </strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tagu = false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whu != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" where ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whu[0] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res += " 用户名=@user ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> //res+=wh[0];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tagu = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whu[1] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (tagu)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+="and ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" 密码=@pass ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> //res+=wh[1];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tagu = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whu[2] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (tagu)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res += " and ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" 电话=@tel ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> //res+=wh[2];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tagu = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whu[3] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (tagu)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res += " and ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" 邮箱=@mail ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> // res+=wh[1];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong>
</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> /*</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> * </strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> * </strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> * </strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> */ </strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.CommandText = res;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vlu != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vlu[0] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@user2", vlu[0]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vlu[1] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@pass2", vlu[1]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vlu[2] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@tel2", vlu[2]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (vlu[3] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@mail2", vlu[3]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whu != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whu[0] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@user", whu[0]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whu[1] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@pass", whu[1]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whu[2] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@tel", whu[2]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whu[3] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@mail", whu[3]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> int pcount = sqlcom.ExecuteNonQuery();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (pcount > 0)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> MessageBox.Show("更新成功,请浏览数据");</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> else {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> MessageBox.Show("更新失败,请检查原因");</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcon.Close();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> break;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> case "删除数据":</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res = "delete from [用户表]";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> string [] whd=get_where();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> bool tagd=false;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whd != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" where ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whd[0] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res += " 用户名=@user ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> //res+=wh[0];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tagd = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whd[1] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (tagd)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+="and ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" 密码=@pass ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> //res+=wh[1];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tagd = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whd[2] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (tagd)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res += " and ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" 电话=@tel ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> //res+=wh[2];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> tagd = true;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whd[3] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (tagd)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res += " and ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> res+=" 邮箱=@mail ";</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> // res+=wh[1];</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.CommandText = res;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whd != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whd[0] != "")</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@user", whd[0]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whd[1] != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@pass", whd[1]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whd[2] != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@tel", whd[2]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (whd[3] != null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcom.Parameters.AddWithValue("@mail", whd[3]);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> try</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> int rc=sqlcom.ExecuteNonQuery();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (rc > 0)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> MessageBox.Show("数据删除成功,请浏览数据");</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> else</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> MessageBox.Show("数据删除失败,请检查原因");</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> catch (Exception ex)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> MessageBox.Show("出现数据查询错误,请重试" + ex.Message);</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> finally {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> sqlcon.Close();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> break;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> return res;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> private void button1_Click(object sender, EventArgs e)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> init_controler();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> </strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong>
</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> private void button2_Click(object sender, EventArgs e)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> if (comboBox1.SelectedItem == null)</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> {</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> MessageBox.Show("请选择右上方的操作后再执行确认");</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> return;</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> execu_sql();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> init_controler();</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;"> }</strong></li><li><strong style="font-family: Arial, Helvetica, sans-serif;">}</strong></li><li><span style="font-family:Arial, Helvetica, sans-serif;"><span style="white-space: normal;">
</span></span></li></ol>