private void button1_Click(object sender, EventArgs e)//生成快递单添加到数据库中去
{
if (txtfajianaddress.Text != "" && txtfajianname.Text != "" && txtfajianphone.Text != "" && txtshoujianaddress.Text != "" && txtshoujianname.Text != "" && txtshoujianphone.Text != "")
{
string fajianname = txtfajianname.Text;
string fajianphone = txtfajianphone.Text;
string fajiandizhi = txtfajianaddress.Text;
string kuaidi = comboBox1.SelectedItem.ToString();
string shoujianname = txtshoujianname.Text;
string shoujianphone = txtshoujianphone.Text;
string shoujianaddress = txtshoujianaddress.Text;
SqlConnection conn = new SqlConnection("server=.;database=Taobao;user=sa;pwd=123");
SqlCommand cmd = conn.CreateCommand();
conn.Open();
cmd.CommandText = "insert into kuaididan values(@fname,@fphone,@faddress,@kuaidi,@sname,@sphone,@saddress)";
cmd.Parameters.Clear();
cmd.Parameters.Add("@fname", fajianname);
cmd.Parameters.Add("@fphone", fajianphone);
cmd.Parameters.Add("@faddress", fajiandizhi);
cmd.Parameters.Add("@kuaidi", kuaidi);
cmd.Parameters.Add("@sname", shoujianname);
cmd.Parameters.Add("@sphone", shoujianphone);
cmd.Parameters.Add("@saddress", shoujianaddress);
cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
MessageBox.Show("生成成功,请打印订单");
}
else
{
MessageBox.Show("请完善所有信息");
}
}
private void button2_Click(object sender, EventArgs e)//打印订单
{
if (txtfajianaddress.Text != "")
{
//连接数据库打印快递单
SqlConnection conn = new SqlConnection("server=.;database=Taobao;user=sa;pwd=123");
SqlCommand cmd = conn.CreateCommand();
conn.Open();
cmd.CommandText = "select top 1* from kuaididan order by code desc"; //只显示刚加进去的那一条订单信息
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
DataRow row = DataSet1.kuaididan.NewRow();//利用Datatable 临时表来存放数据。 造一个新行,是关于DataSet1数据集下的kuaididan然后点出来NewRow();
//将数据一条条加进去
row["code"] = dr["code"];
row["fname"] = dr["fname"];
row["fphone"] = dr["fphone"];
row["faddress"] = dr["faddress"];
row["kuaidi"] = dr["kuaidi"];
row["sname"] = dr["sname"];
row["sphone"] = dr["sphone"];
row["saddress"] = dr["saddress"];
DataSet1.kuaididan.Rows.Add(row);//最后将所有的行加在一块
}
}
cmd.Dispose();
conn.Close();
this.reportViewer1.RefreshReport();//在报表浏览器中显示报表
}
else
{
MessageBox.Show("请先添加快递单信息");
}
}