Update.cs
上传用户:nbcygd
上传日期:2008-07-25
资源大小:2566k
文件大小:3k
源码类别:

SQL Server

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Data.Sql;
  9. using System.Data.SqlClient;
  10. using System.Data.SqlTypes;
  11. namespace Super_market
  12. {
  13.     public partial class Update : Form
  14.     {
  15.         private SqlDataAdapter da;
  16.         public delegate void dele();
  17.         public event dele evt;       
  18.         private SqlConnection con;
  19.         private SqlConnectionStringBuilder b = new SqlConnectionStringBuilder();
  20.         private DataSet ds;
  21.         private DBTools db;
  22.         DLbh c = DLbh.getIns();
  23.         public Update()
  24.         {
  25.             InitializeComponent();
  26.             b.DataSource = ".";
  27.             b.InitialCatalog = "wkdl";
  28.             b.IntegratedSecurity = true;
  29.             con = new SqlConnection(b.ConnectionString);
  30.             da = new SqlDataAdapter("select id as 商品编号,warename as 商品名称,price as 单价,entries as 已售出数量,keep as 保质期 from ", con);
  31.             ds = new DataSet();
  32.             this.skinEngine1.SkinFile = "vista1.ssk";
  33.         }
  34.         private void Update_Load(object sender, EventArgs e)
  35.         {
  36.             db = new DBTools(".", "wkdl", true, "sa", "wdxg");
  37.             SqlDataReader b = db.getResult("Select * from ware where id=" + c.Num);
  38.             while (b.Read())
  39.             {
  40.            
  41.                 textBox1.Text = b["id"].ToString();
  42.                 textBox2.Text = b["warename"].ToString();
  43.                 textBox3.Text = b["price"].ToString();
  44.                 textBox4.Text = b["entries"].ToString();
  45.                 textBox5.Text = b["keep"].ToString();
  46.                 
  47.             }
  48.             db.Disconnect();
  49.         }
  50.         private void button2_Click(object sender, EventArgs e)
  51.         {
  52.             this.Dispose(true);            
  53.         }
  54.         private void button1_Click(object sender, EventArgs e)
  55.         {
  56.             try
  57.             {
  58.                 
  59.                     if (textBox1.Text.Trim().Length == 0 || textBox2.Text.Trim().Length == 0 || textBox3.Text.Trim().Length == 0 || textBox4.Text.Trim().Length == 0 || textBox5.Text.Trim().Length == 0)
  60.                     {
  61.                         MessageBox.Show("不能有任何一项为空!", "系统提示");
  62.                     }
  63.                     else
  64.                     {
  65.                         string strc = "update ware set warename='" + textBox2.Text.Trim().ToString() + "',price=" + decimal.Parse(textBox3.Text.Trim()) + ",entries=" + int.Parse(textBox4.Text.Trim()) + ",keep=" + int.Parse(textBox5.Text.Trim()) + " where [id]=" + c.Num;
  66.                         da.InsertCommand = con.CreateCommand();
  67.                         da.InsertCommand.CommandText = strc;
  68.                         con.Open();
  69.                         da.InsertCommand.ExecuteNonQuery();
  70.                         con.Close();
  71.                         this.Dispose(true);
  72.                         evt();
  73.                     }      
  74.                
  75.             }
  76.             catch (Exception)
  77.             {
  78.                 MessageBox.Show("数据类型不符,请核对后再插入!","系统提示");
  79.             }
  80.             finally
  81.             {
  82.                 con.Close();
  83.             }
  84.         }
  85.         
  86.     }
  87. }