Form4.cs
上传用户:miknos
上传日期:2022-04-30
资源大小:802k
文件大小:8k
源码类别:

百货/超市行业

开发平台:

Visual C++

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data.SqlClient;
  7. namespace supershop
  8. {
  9. /// <summary>
  10. /// Form4 的摘要说明。
  11. /// </summary>
  12. public class Form4 : System.Windows.Forms.Form
  13. {
  14. private System.Windows.Forms.ListView listView1;
  15. private System.Windows.Forms.ColumnHeader columnHeader1;
  16. private System.Windows.Forms.ColumnHeader columnHeader2;
  17. private System.Windows.Forms.ColumnHeader columnHeader3;
  18. private System.Windows.Forms.ColumnHeader columnHeader4;
  19. private System.Windows.Forms.ColumnHeader columnHeader5;
  20. private System.Windows.Forms.ColumnHeader columnHeader6;
  21. private System.Data.OleDb.OleDbConnection oleDbConnection1;
  22. private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
  23. private System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
  24. private System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
  25. private System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
  26. private System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
  27. private System.Windows.Forms.Button button1;
  28. private System.Data.SqlClient.SqlConnection myConnection;
  29. /// <summary>
  30. /// 必需的设计器变量。
  31. /// </summary>
  32. private System.ComponentModel.Container components = null;
  33. public Form4()
  34. {
  35. //
  36. // Windows 窗体设计器支持所必需的
  37. //
  38. InitializeComponent();
  39. //
  40. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  41. //
  42. }
  43. /// <summary>
  44. /// 清理所有正在使用的资源。
  45. /// </summary>
  46. protected override void Dispose( bool disposing )
  47. {
  48. if( disposing )
  49. {
  50. if(components != null)
  51. {
  52. components.Dispose();
  53. }
  54. }
  55. base.Dispose( disposing );
  56. }
  57. #region Windows 窗体设计器生成的代码
  58. /// <summary>
  59. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  60. /// 此方法的内容。
  61. /// </summary>
  62. private void InitializeComponent()
  63. {
  64. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form4));
  65. this.listView1 = new System.Windows.Forms.ListView();
  66. this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
  67. this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
  68. this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
  69. this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
  70. this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
  71. this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
  72. this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
  73. this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
  74. this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
  75. this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
  76. this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
  77. this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
  78. this.button1 = new System.Windows.Forms.Button();
  79. this.myConnection = new System.Data.SqlClient.SqlConnection();
  80. this.SuspendLayout();
  81. // 
  82. // listView1
  83. // 
  84. this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
  85. this.columnHeader1,
  86. this.columnHeader2,
  87. this.columnHeader3,
  88. this.columnHeader4,
  89. this.columnHeader5,
  90. this.columnHeader6});
  91. this.listView1.Location = new System.Drawing.Point(0, 0);
  92. this.listView1.Name = "listView1";
  93. this.listView1.Size = new System.Drawing.Size(640, 288);
  94. this.listView1.TabIndex = 0;
  95. this.listView1.View = System.Windows.Forms.View.Details;
  96. // 
  97. // columnHeader1
  98. // 
  99. this.columnHeader1.Text = "销售号";
  100. this.columnHeader1.Width = 89;
  101. // 
  102. // columnHeader2
  103. // 
  104. this.columnHeader2.Text = "商品名称";
  105. this.columnHeader2.Width = 103;
  106. // 
  107. // columnHeader3
  108. // 
  109. this.columnHeader3.Text = "商品数量";
  110. this.columnHeader3.Width = 73;
  111. // 
  112. // columnHeader4
  113. // 
  114. this.columnHeader4.Text = "商品总价格";
  115. this.columnHeader4.Width = 85;
  116. // 
  117. // columnHeader5
  118. // 
  119. this.columnHeader5.Text = "销售时间";
  120. this.columnHeader5.Width = 174;
  121. // 
  122. // columnHeader6
  123. // 
  124. this.columnHeader6.Text = "销售人员";
  125. this.columnHeader6.Width = 112;
  126. // 
  127. // oleDbConnection1
  128. // 
  129. 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";
  130. // 
  131. // oleDbDataAdapter1
  132. // 
  133. this.oleDbDataAdapter1.DeleteCommand = this.oleDbDeleteCommand1;
  134. this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1;
  135. this.oleDbDataAdapter1.SelectCommand = this.oleDbSelectCommand1;
  136. this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1;
  137. // 
  138. // button1
  139. // 
  140. this.button1.Location = new System.Drawing.Point(440, 304);
  141. this.button1.Name = "button1";
  142. this.button1.TabIndex = 1;
  143. this.button1.Text = "清除销售记录";
  144. this.button1.Click += new System.EventHandler(this.button1_Click);
  145. // 
  146. // myConnection
  147. // 
  148. this.myConnection.ConnectionString = "workstation id=MICROSOFTPANG;packet size=4096;integrated security=SSPI;data sourc" +
  149. "e=MICROSOFTPANG;persist security info=False;initial catalog=supershop";
  150. // 
  151. // Form4
  152. // 
  153. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  154. this.ClientSize = new System.Drawing.Size(640, 333);
  155. this.Controls.Add(this.button1);
  156. this.Controls.Add(this.listView1);
  157. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  158. this.Name = "Form4";
  159. this.Text = "Form4";
  160. this.Load += new System.EventHandler(this.Form4_Load);
  161. this.ResumeLayout(false);
  162. }
  163. #endregion
  164. private void Form4_Load(object sender, System.EventArgs e)
  165. {
  166. 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";
  167. this.oleDbDataAdapter1.SelectCommand.CommandText=sss;
  168. this.oleDbDataAdapter1.SelectCommand.Connection=this.oleDbConnection1;
  169. //打开数据库连接
  170. this.oleDbConnection1.Open();
  171. System.Data.OleDb.OleDbDataReader MyReader2=this.oleDbDataAdapter1.SelectCommand.ExecuteReader();
  172. try
  173. {
  174. this.listView1.Items.Clear();
  175. while(MyReader2.Read())
  176. {
  177. ListViewItem MyItem=new ListViewItem();
  178. MyItem.Text=MyReader2.GetValue(0).ToString();
  179. for(int j=0;j<MyReader2.FieldCount-1;j++)
  180.     MyItem.SubItems.Add(MyReader2.GetValue(j+1).ToString());
  181. this.listView1.Items.Add(MyItem);
  182. }
  183. MyReader2.Close();
  184. this.oleDbConnection1.Close();
  185. }
  186. catch
  187. {
  188. MessageBox.Show(this,"帐户不存在!");
  189. }
  190. private void button1_Click(object sender, System.EventArgs e)
  191. {
  192. string dl="delete from slist";
  193. SqlCommand myCommand = new SqlCommand(dl,myConnection);
  194. myCommand.Connection.Open();
  195. try
  196. {
  197. myCommand.ExecuteNonQuery();
  198. myCommand.Connection.Close();
  199. MessageBox.Show("删除数据成功! ");
  200. }
  201. catch(SqlException ex)
  202. {
  203. MessageBox.Show("删除数据错误! " + ex.Message.ToString());
  204. myCommand.Connection.Close();
  205. return;
  206. }
  207. string dll="delete from soled";
  208. SqlCommand myCommand2 = new SqlCommand(dll,myConnection);
  209. myCommand.Connection.Open();
  210. try
  211. {
  212. myCommand2.ExecuteNonQuery();
  213. myCommand2.Connection.Close();
  214. MessageBox.Show("删除数据成功! ");
  215. }
  216. catch(SqlException ex)
  217. {
  218. MessageBox.Show("删除数据错误! " + ex.Message.ToString());
  219. myCommand2.Connection.Close();
  220. return;
  221. }
  222. }
  223. }
  224. }