using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.sqlClient; using System.Configuration; namespace TellCenter { public partial class customer : Form { public customer() { InitializeComponent(); } string sqlstr = ConfigurationManager.ConnectionStrings["con"].ConnectionString; private void btnlook_Click(object sender,EventArgs e) { if (this.checkname.Checked) { using (sqlConnection sqlcnn = new sqlConnection(sqlstr)) { using (sqlCommand sqlcmm=sqlcnn.CreateCommand()) { sqlcmm.CommandText = "select * from T_Clientele where ClientName=@name"; sqlcmm.Parameters.AddWithValue("@name",this.txtname.Text); GetInfo(sqlcnn,sqlcmm); } } } else if(this.checkphone.Checked) { using (sqlConnection sqlcnn=new sqlConnection(sqlstr)) { using (sqlCommand sqlcmm=sqlcnn.CreateCommand()) { sqlcmm.CommandText = "select * from T_Clientele where ClientPhone=@phone"; sqlcmm.Parameters.AddWithValue("@phone",this.txtphone.Text); GetInfo(sqlcnn,sqlcmm); } } } }//查看 private void GetInfo(sqlConnection sqlcnn,sqlCommand sqlcmm) { sqlcnn.open(); sqlDataReader reader = sqlcmm.ExecuteReader(); if (reader != null) { while (reader.Read()) { this.txtClientName.Text = reader["ClientName"].ToString(); this.txtClientPhone.Text = reader["ClientPhone"].ToString(); this.txtEmail.Text = reader["Email"].ToString(); this.txtClientAddress.Text = reader["ClientAddress"].ToString(); this.txtCode.Text = reader["Code"].ToString(); this.txtCarNum.Text = reader["CarNum"].ToString(); this.txtClientNums.Text = reader["ClientNums"].ToString(); this.txtCattype.Text = reader["Cattype"].ToString(); this.txtShopid.Text = reader["ShopId"].ToString(); this.txtShopDateTime.Text = reader["ShopDateTime"].ToString(); } } } private void DelCus_Click(object sender,EventArgs e) { using (sqlConnection sqlcnn=new sqlConnection(sqlstr)) { using (sqlCommand sqlcmm=sqlcnn.CreateCommand()) { sqlcmm.CommandText = "delete from T_Clientele where ClientName=@name"; sqlcmm.Parameters.AddWithValue("@name",this.txtClientName.Text); sqlcnn.open(); int i = sqlcmm.ExecuteNonQuery(); if (i>0) { MessageBox.Show("删除成功!"); this.txtClientName.Text = null; this.txtClientPhone.Text =null; this.txtEmail.Text = null; this.txtClientAddress.Text=null; this.txtCode.Text = null; this.txtCarNum.Text = null; this.txtClientNums.Text = null; this.txtCattype.Text = null; this.txtShopid.Text = null; this.txtShopDateTime.Text = null; } else { MessageBox.Show("删除失败!"); } } } }//删除 private void Addcus_Click(object sender,EventArgs e) { using (sqlConnection sqlcnn=new sqlConnection(sqlstr)) { using (sqlCommand sqlcmm=sqlcnn.CreateCommand()) { sqlcmm.CommandText = "insert into T_Clientele values(@name,@phone,@Email,@address,@code,@CarNum,@ClientNums,@Cattype,@ShopId,@ShopDateTime)"; sqlcnn.open(); GetPams(sqlcmm); int i=sqlcmm.ExecuteNonQuery(); if (i>0) { MessageBox.Show("添加成功!"); } else { MessageBox.Show("添加失败!"); } } } }//增加 private void GetPams(sqlCommand sqlcmm) { sqlcmm.Parameters.AddWithValue("@name",this.txtClientName.Text); sqlcmm.Parameters.AddWithValue("@phone",this.txtClientPhone.Text); sqlcmm.Parameters.AddWithValue("@Email",this.txtEmail.Text); sqlcmm.Parameters.AddWithValue("@address",this.txtClientAddress.Text); sqlcmm.Parameters.AddWithValue("@code",this.txtCode.Text); sqlcmm.Parameters.AddWithValue("@CarNum",this.txtCarNum.Text); sqlcmm.Parameters.AddWithValue("@ClientNums",this.txtClientNums.Text); sqlcmm.Parameters.AddWithValue("@Cattype",this.txtCattype.Text); sqlcmm.Parameters.AddWithValue("@ShopId",this.txtShopid.Text); sqlcmm.Parameters.AddWithValue("@ShopDateTime",this.txtShopDateTime.Text); } private void btnUpdate_Click(object sender,EventArgs e) { using (sqlConnection sqlcnn=new sqlConnection(sqlstr)) { using (sqlCommand sqlcmm=sqlcnn.CreateCommand()) { sqlcmm.CommandText = "update T_Clientele set ClientName=@name,ClientPhone=@phone,Email=@Email,ClientAddress=@address,Code=@code,CarNum=@CarNum,ClientNums=@ClientNums,Cattype=@Cattype,ShopId=@ShopId,ShopDateTime=@ShopDateTime"; sqlcnn.open(); GetPams(sqlcmm); int i = sqlcmm.ExecuteNonQuery(); if (i>0) { MessageBox.Show("更改成功!"); } else { MessageBox.Show("更改失败!"); } } } }//更改 } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。