public void Execute() { List <BanHang.Domain.BanHang> check = null; using (var cmd = new BanHangViewBusiness()) { cmd.ID = item.ID; check = cmd.Execute(); } if (check == null) { using (var cmd = new BanHangAddRepository()) { cmd.item = item; cmd.Execute(); } } }
private void bunifuTileButton2_Click(object sender, EventArgs e) { try { if (rand == 0) { rand = getRand(2); } var data = new BanHang.Domain.BanHang(); data.HanghoaId = this.cbbHangHoa.SelectedValue.ToString(); data.NhomHanghoaId = this.cbbNhomHangHoa.SelectedValue.ToString(); data.TenSanPham = this.cbbHangHoa.Text; data.NgayBan = DateTime.Now.ToString(); data.SoLuong = Convert.ToInt32(this.txtSoLuong.Text); data.Giaban = Convert.ToInt32(this.txtSoLuong.Text) * Convert.ToInt32(this.txtGiaBan.Text); data.ID = rand; using (var cmd = new BanHangAddRepository()) { cmd.item = data; cmd.Execute(); } using (var cmd = new BanHangSubBusiness()) { cmd.HanghoaId = data.HanghoaId; cmd.SoLuong = data.SoLuong; cmd.Execute(); } using (var cmd = new BanHangViewBusiness()) { cmd.ID = data.ID; this.banHangBindingSource.DataSource = cmd.Execute(); } this.txtSoLuong.Text = ""; } catch { MessageBox.Show("Vui lòng kiểm tra lại!", "CÓ LỖI XẢY RA!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }