private void buttonX_lapphieudat_Click(object sender, EventArgs e) { trangthai2(); dh = new DatHang(textBoxX_makh.Text, textBoxX_manv.Text, dateTime_date.Value); /*foreach (SP sp in dh.GetListSP()) * { * sp.GetMSP(); * sp.GetTensp(); * sp.GetGiaban(); * sp.GetSoluong(); * sp.GetThanhtien(); * }*/ }
public Boolean DatHang(DatHang dh) { connect(); con.Open(); SqlTransaction dathang = con.BeginTransaction(); try { SqlCommand insert_dh = new SqlCommand("INSERT_DATHANG", con, dathang); insert_dh.CommandType = CommandType.StoredProcedure; insert_dh.Parameters.Add("@MKH", SqlDbType.Char).Value = dh.GetMKH(); insert_dh.Parameters.Add("@MNV", SqlDbType.Char).Value = dh.GetMNV(); insert_dh.Parameters.Add("@DATE", SqlDbType.DateTime).Value = dh.GetDate(); //insert_dh.Parameters.Add("@TINHTRANG", SqlDbType.Int).Value = dh.GetStatus(); dh.SetMDH((int)insert_dh.ExecuteScalar()); foreach (SP sp in dh.GetListSP()) { SqlCommand insert_ctdh = new SqlCommand("INSERT_CTDH", con, dathang); insert_ctdh.CommandType = CommandType.StoredProcedure; insert_ctdh.Parameters.Add("@MDH", SqlDbType.Char).Value = dh.GetMDH(); insert_ctdh.Parameters.Add("@MSP", SqlDbType.Char).Value = sp.GetMSP(); insert_ctdh.Parameters.Add("@GIABAN", SqlDbType.Money).Value = sp.GetGiaban(); insert_ctdh.Parameters.Add("@SLDATHANG", SqlDbType.Int).Value = sp.GetSoluong(); insert_ctdh.Parameters.Add("@THANHTIEN", SqlDbType.Money).Value = sp.GetThanhtien(); insert_ctdh.ExecuteNonQuery(); } dathang.Commit(); return(true); } catch (Exception ex) { MessageBox.Show("loi " + ex.ToString()); dathang.Rollback(); return(false); } finally { con.Dispose(); } }
public HoaDon(DatHang dh)//giao hang : dat hang --> ghi hoa don { mkh = dh.GetMKH(); mnv = dh.GetMNV(); sp = dh.GetListSP(); }