Form4.cs
上传用户:miknos
上传日期:2022-04-30
资源大小:802k
文件大小:8k
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace supershop
- {
- /// <summary>
- /// Form4 的摘要说明。
- /// </summary>
- public class Form4 : System.Windows.Forms.Form
- {
- private System.Windows.Forms.ListView listView1;
- private System.Windows.Forms.ColumnHeader columnHeader1;
- private System.Windows.Forms.ColumnHeader columnHeader2;
- private System.Windows.Forms.ColumnHeader columnHeader3;
- private System.Windows.Forms.ColumnHeader columnHeader4;
- private System.Windows.Forms.ColumnHeader columnHeader5;
- private System.Windows.Forms.ColumnHeader columnHeader6;
- private System.Data.OleDb.OleDbConnection oleDbConnection1;
- private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
- private System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
- private System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
- private System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
- private System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
- private System.Windows.Forms.Button button1;
- private System.Data.SqlClient.SqlConnection myConnection;
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- public Form4()
- {
- //
- // Windows 窗体设计器支持所必需的
- //
- InitializeComponent();
- //
- // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
- //
- }
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows 窗体设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form4));
- this.listView1 = new System.Windows.Forms.ListView();
- this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
- this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
- this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
- this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
- this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
- this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
- this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
- this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
- this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
- this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
- this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
- this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
- this.button1 = new System.Windows.Forms.Button();
- this.myConnection = new System.Data.SqlClient.SqlConnection();
- this.SuspendLayout();
- //
- // listView1
- //
- this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
- this.columnHeader1,
- this.columnHeader2,
- this.columnHeader3,
- this.columnHeader4,
- this.columnHeader5,
- this.columnHeader6});
- this.listView1.Location = new System.Drawing.Point(0, 0);
- this.listView1.Name = "listView1";
- this.listView1.Size = new System.Drawing.Size(640, 288);
- this.listView1.TabIndex = 0;
- this.listView1.View = System.Windows.Forms.View.Details;
- //
- // columnHeader1
- //
- this.columnHeader1.Text = "销售号";
- this.columnHeader1.Width = 89;
- //
- // columnHeader2
- //
- this.columnHeader2.Text = "商品名称";
- this.columnHeader2.Width = 103;
- //
- // columnHeader3
- //
- this.columnHeader3.Text = "商品数量";
- this.columnHeader3.Width = 73;
- //
- // columnHeader4
- //
- this.columnHeader4.Text = "商品总价格";
- this.columnHeader4.Width = 85;
- //
- // columnHeader5
- //
- this.columnHeader5.Text = "销售时间";
- this.columnHeader5.Width = 174;
- //
- // columnHeader6
- //
- this.columnHeader6.Text = "销售人员";
- this.columnHeader6.Width = 112;
- //
- // oleDbConnection1
- //
- this.oleDbConnection1.ConnectionString = @"Integrated Security=SSPI;Packet Size=4096;Data Source=MICROSOFTPANG;Tag with column collation when possible=False;Initial Catalog=supershop;Use Procedure for Prepare=1;Auto Translate=True;Persist Security Info=False;Provider=""SQLOLEDB.1"";Workstation ID=MICROSOFTPANG;Use Encryption for Data=False";
- //
- // oleDbDataAdapter1
- //
- this.oleDbDataAdapter1.DeleteCommand = this.oleDbDeleteCommand1;
- this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1;
- this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
- this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1;
- //
- // button1
- //
- this.button1.Location = new System.Drawing.Point(440, 304);
- this.button1.Name = "button1";
- this.button1.TabIndex = 1;
- this.button1.Text = "清除销售记录";
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // myConnection
- //
- this.myConnection.ConnectionString = "workstation id=MICROSOFTPANG;packet size=4096;integrated security=SSPI;data sourc" +
- "e=MICROSOFTPANG;persist security info=False;initial catalog=supershop";
- //
- // Form4
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(640, 333);
- this.Controls.Add(this.button1);
- this.Controls.Add(this.listView1);
- this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
- this.Name = "Form4";
- this.Text = "Form4";
- this.Load += new System.EventHandler(this.Form4_Load);
- this.ResumeLayout(false);
- }
- #endregion
- private void Form4_Load(object sender, System.EventArgs e)
- {
- string sss="select soled.sallflog,production.pname,soled.solett,soled.allp,slist.stime,slist.sname from soled,slist,production where soled.pid=production.pid and soled.sallflog=slist.sallid order by slist.sallid desc";
- this.oleDbDataAdapter1.SelectCommand.CommandText=sss;
- this.oleDbDataAdapter1.SelectCommand.Connection=this.oleDbConnection1;
- //打开数据库连接
- this.oleDbConnection1.Open();
- System.Data.OleDb.OleDbDataReader MyReader2=this.oleDbDataAdapter1.SelectCommand.ExecuteReader();
- try
- {
- this.listView1.Items.Clear();
- while(MyReader2.Read())
- {
- ListViewItem MyItem=new ListViewItem();
- MyItem.Text=MyReader2.GetValue(0).ToString();
- for(int j=0;j<MyReader2.FieldCount-1;j++)
- MyItem.SubItems.Add(MyReader2.GetValue(j+1).ToString());
- this.listView1.Items.Add(MyItem);
-
- }
- MyReader2.Close();
- this.oleDbConnection1.Close();
- }
- catch
- {
- MessageBox.Show(this,"帐户不存在!");
- }
- }
- private void button1_Click(object sender, System.EventArgs e)
- {
- string dl="delete from slist";
- SqlCommand myCommand = new SqlCommand(dl,myConnection);
- myCommand.Connection.Open();
- try
- {
- myCommand.ExecuteNonQuery();
- myCommand.Connection.Close();
- MessageBox.Show("删除数据成功! ");
- }
- catch(SqlException ex)
- {
- MessageBox.Show("删除数据错误! " + ex.Message.ToString());
- myCommand.Connection.Close();
- return;
- }
-
- string dll="delete from soled";
- SqlCommand myCommand2 = new SqlCommand(dll,myConnection);
- myCommand.Connection.Open();
- try
- {
- myCommand2.ExecuteNonQuery();
- myCommand2.Connection.Close();
- MessageBox.Show("删除数据成功! ");
- }
- catch(SqlException ex)
- {
- MessageBox.Show("删除数据错误! " + ex.Message.ToString());
- myCommand2.Connection.Close();
- return;
- }
- }
- }
- }