private void button1_Click(object sender, System.EventArgs e) { string Givenwater = comboBox4.Text.Trim(); string givenwater=textBox6.Text.Trim(); waters waterselect=new waters(); switch(Givenwater) { case "查询全部": Fill_view(Givenwater); break; case "客户编号": Fill_view_kehu(Givenwater); break; default: break; } } 函数: //用于显示查询的内容-------客户编号----------未完成 private int Fill_view_kehu(string Givenwater) { DataSet waterall_View = new DataSet();
waters waterselectone = new waters(); int kehu=Int32.Parse(textBox6.Text.Trim() );
if(!waterselectone.Get_kehu_water(ref myConn, kehu)) return -1;
int waterCount = waterall_View.Tables["ScheduleList"].Rows.Count; // if( nScheduleCount > 0) dataGrid1.DataSource = waterall_View.Tables["ScheduleList"].DefaultView;
return 0; } //获取指定的客户资料 public bool Get_kehu_water(ref SqlConnection myConn, int Get_kehu) { SqlCommand cmd = new SqlCommand("GetwaterBykehu", myConn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(Get_kehu); SqlDataReader waterReader = cmd.ExecuteReader();
int kehu_c_id=0;// string kehu_address="";// string kehu_tel="";// DateTime kehu_p_time=DateTime.Now;// int kehu_out_water_num=0;// int kehu_back_barrel_num=0;//-------------- string kehu_money_metion=""; string kehu_man_out_water="";//------------- int kehu_remnant_water=0; int kehu_stock_water=0; string kehu_man_stock_water="";//------------- string kehu_back_up="";
try { if(waterReader.Read()) { kehu_c_id = Int32.Parse(waterReader["c_id"].ToString().Trim()); kehu_address = waterReader["address"].ToString().Trim(); kehu_tel = waterReader["tel"].ToString().Trim(); kehu_p_time = DateTime.Parse(waterReader["p_time"].ToString());
kehu_out_water_num = Int32.Parse(waterReader["out_water_num"].ToString().Trim()); kehu_back_barrel_num = Int32.Parse(waterReader["back_barrel_num"].ToString().Trim()); kehu_money_metion = waterReader["money_metion"].ToString().Trim(); kehu_man_out_water = waterReader["man_out_water"].ToString().Trim();
kehu_remnant_water = Int32.Parse(waterReader["remnant_water"].ToString().Trim()); kehu_stock_water = Int32.Parse(waterReader["stock_water"].ToString().Trim()); kehu_man_stock_water = waterReader["man_stock_water"].ToString().Trim(); kehu_back_up = waterReader["back_up"].ToString().Trim(); } } catch { waterReader.Close(); return false; }
c_id=kehu_c_id;// address=kehu_address;// tel=kehu_tel;// p_time=kehu_p_time;// out_water_num=kehu_out_water_num;// back_barrel_num=kehu_back_barrel_num;//-------------- money_metion=kehu_money_metion; man_out_water=kehu_man_out_water;//------------- remnant_water=kehu_remnant_water; stock_water=kehu_stock_water; man_stock_water=kehu_man_stock_water;//------------- back_up=kehu_back_up;
return true; } 存储过程 CREATE PROCEDURE GetwaterBykehu @c_id BIGINT AS SELECT * FROM water WHERE c_id = @c_id RETURN GO