日期:2014-05-18 浏览次数:20925 次
类文件: public class goods { int save_flag = 0;//取得是否有记录 string goods_name = "";//品名 string goods_place ="";//产地 string goods_type ="";//型号 string goods_unit = "";//单位 string goods_price = "";//价格 //数据库里是否有此商品,0没有、1有 public int save_flags { get { return save_flag; } set { save_flag = value; } } //商品名 public string g_name { get { return goods_name; } set { goods_name = value; } } //商品产地信息 public string g_place { get { return goods_place; } set { goods_place = value; } } //商品规格信息 public string g_type { get { return goods_type; } set { goods_type = value; } } //商品单位信息 public string g_unit { get { return goods_unit; } set { goods_unit = value; } } //商品价格信息 public string g_price { get { return goods_price; } set { goods_price = value; } } //搜索商品的信息 public string goods_find(string goods) { string goods_finds = "select * from p_goods where goods_nums = '" + goods + "'"; m_sql_conn m_conn = new m_sql_conn(); SqlConnection conn = new SqlConnection(m_conn.sql_conn()); SqlCommand cmd = new SqlCommand(goods_finds, conn); try { conn.Open(); } catch (System.Exception) { MessageBox.Show("数据库打开失败", "提示"); return "GF0000001错误"; } SqlDataReader goods_rs = cmd.ExecuteReader(); if(goods_rs.Read()) { goods_name = goods_rs["goods_name"].ToString(); goods_place = goods_rs["goods_place"].ToString(); goods_type = goods_rs["goods_type"].ToString(); goods_unit = goods_rs["goods_unit"].ToString(); goods_price = goods_rs["goods_price"].ToString(); save_flag = 1; } conn.Close(); goods_rs.Close(); return goods; }
private void button1_Click(object sender, EventArgs e) { mygoods.goods_find(t_1.Text.Trim()); //按t_1.Text查找记录,按货号搜索 save_yn = mygoods.save_flags; //得到结果是否找到,有返回1,没有返回0 t_2.Text = mygoods.g_name.ToString(); t_3.Text = mygoods.g_place.ToString(); t_4.Text = mygoods.g_type.To