private void btluu_Click(object sender, EventArgs e) { DonHangPublic dhpublic = new DonHangPublic(); dhpublic.MADH = tbmadh.Text.Trim(); dhpublic.NGAYBAN = DateTime.Parse(datengayban.Text.Trim()); dhpublic.KHACHHANG = combokh.SelectedValue.ToString(); dhpublic.NHANVIEN = textBoxMaNV.Text.Trim(); try { if (dhbus.themDonHang(dhpublic)) MessageBox.Show("Thêm đơn hàng thành công", "Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Error); else MessageBox.Show("Them don hang that bai", "Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { DS_đơn_hàng = dhbus.getDonHang(); DGDonHang.DataSource = DS_đơn_hàng; } }
public bool themDonHang(DonHangPublic dh) { try { return(dhdal.themDonHang(dh)); } catch (Exception ex) { throw ex; } }
public bool themDonHang(DonHangPublic dh) { cmd.CommandText = "insert into DON_HANG(MaDH, MaNV, MaKH, NgayBan) values ('" + dh.MADH + "', '" + dh.NHANVIEN + "', '" + dh.KHACHHANG + "', '" + dh.NGAYBAN.ToString("MM/dd/yyyy") + "')"; cmd.CommandType = CommandType.Text; cmd.Connection = con.Connection; int row = 0; try { con.OpenConn(); row = cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { cmd.Dispose(); con.CloseConn(); } return(Convert.ToBoolean(row)); }