62,046
社区成员
发帖
与我相关
我的任务
分享
DAL
public static void SellInsert(string sellCode, string customer, SqlTransaction tran)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString);
try
{
conn.Open();
//tran = conn.BeginTransaction();
SqlCommand insertcmd = new SqlCommand("insert into tb_Sell(SellCode,Customer_name) values ('" + sellCode + "'," + "'" + customerName +"')", conn);
insertcmd.ExecuteNonQuery();
}
catch (System.Exception ee)
{
HttpContext.Current.Response.Write("<script language=javascript>alert('" + ee.Message.ToString() + "')</script>");
}
finally
{
conn.Close();
}
}
public static void SellDetailInsert(string sellCode, string product, SqlTransaction tran)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString);
try
{
conn.Open();
//tran = conn.BeginTransaction();
SqlCommand insertcmd = new SqlCommand("insert into tb_SellDetail(SellCode,Product) values ('" + sellCode + "'," + "'" + product +"')", conn);
insertcmd.ExecuteNonQuery();
}
catch (System.Exception ee)
{
HttpContext.Current.Response.Write("<script language=javascript>alert('" + ee.Message.ToString() + "')</script>");
}
finally
{
conn.Close();
}
}
BLL
protected void btnSave_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ChengYiConnectionString"].ConnectionString);
conn.Open();
SqlTransaction tran = conn.BeginTransaction();
try
{
DAL.Product.SellInsert(this.lblSellCode.Text,this.tbCustomerName.Text,tran);
DAL.Product.SellDetailInsert(this.lblSellCode.Text,this.tbProduct.Text,tran);
tran.Commit();
catch (Exception ex)
{
tran.Rollback();
Response.Write(ex.Message);
}
finally
{
tran.Dispose();
conn.Close();
}
}