private void btThem2_Click(object sender, EventArgs e) { try { sqlcnn.Open(); if (txtTenSP2.Text == "" || txtMaSP2.Text == "" || txtSL2.Text == "" || txtMaKe.Text == "") { MessageBox.Show("Vui lòng nhập đầy đủ các ô"); } else { this.txtNgayCat.Text = (DateTime.Now).ToString(); String sql2 = "INSERT INTO CatHang (MaThung, MaKe, MaSP, TenSP, SoLuong, NgayCat) " + "VALUES('" + this.txtMaThung2.Text + "','" + this.txtMaKe.Text + "','" + this.txtMaSP2.Text.Trim() + "','" + this.txtTenSP2.Text + "','" + this.txtSL2.Text + "','" + this.txtNgayCat.Text + "');"; SqlCommand cmd = new SqlCommand(sql2, sqlcnn); cmd.ExecuteNonQuery(); String sql3 = "INSERT INTO SanPham (MaSP, TenSP, MaKe, SoLuong) " + "VALUES('" + this.txtMaSP2.Text + "','" + this.txtTenSP2.Text + "','" + this.txtMaKe.Text + "','" + this.txtSL2.Text + "');"; SqlCommand cmd1 = new SqlCommand(sql3, sqlcnn); cmd1.ExecuteNonQuery(); MessageBox.Show("Thanh cong"); DataRow row = LocationProduct.NewRow(); row["MaThung"] = this.txtMaThung2.Text; row["MaKe"] = this.txtMaKe.Text; row["MaSP"] = this.txtMaSP2.Text; row["TenSP"] = this.txtTenSP2.Text; row["SoLuong"] = this.txtSL2.Text; row["NgayCat"] = this.txtNgayCat.Text; LocationProduct.Rows.Add(row); String delete = "DELETE FROM NhapHang WHERE MaThung = '" + txtMaThung2.Text + "';"; SqlCommand deleteCmd = new SqlCommand(delete, sqlcnn); deleteCmd.ExecuteNonQuery(); MessageBox.Show("Xóa thành công"); } sqlcnn.Close(); int rowIndex = -1; foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[0].Value.ToString().Trim().Equals(txtMaThung2.Text.Trim())) { rowIndex = row.Index; MessageBox.Show("success"); break; } } dataGridView1.Rows.RemoveAt(rowIndex); this.txtMaThung2.Text = this.txtMaSP2.Text = this.txtTenSP2.Text = this.txtSL2.Text = this.txtMaKe.Text = ""; } catch { MessageBox.Show("Lỗi Kết Nối"); } }
//Location & Location product methods LocationProduct IGRRepo.AddLocationProduct(int localID, int RecID, int RecQuan) { LocationProduct newlocalprod = new LocationProduct(); newlocalprod.LocID = localID; newlocalprod.RecID = RecID; newlocalprod.RecQuan = RecQuan; _context.LocationProducts.Add(newlocalprod); _context.SaveChanges(); return(newlocalprod); }
public LocationInvCRVM cast2LocationInvCRVM(LocationProduct localprod2cast, Record record2cast) { return(new LocationInvCRVM { ID = localprod2cast.ID, LocID = localprod2cast.LocID, RecID = localprod2cast.RecID, RecQuan = localprod2cast.RecQuan, //Actual Record Info RecordName = record2cast.RecordName, Artist = record2cast.Artist, GenreType = record2cast.GenreType, DaFormat = record2cast.DaFormat, DaCondition = record2cast.DaCondition, Price = record2cast.Price }); }
public async Task <IActionResult> DeleteProductFromLocation(int productId, int locationId) { LocationProduct locationProduct = await _context.LocationProducts .FirstOrDefaultAsync(x => x.ProductId == productId && x.LocationId == locationId); if (locationProduct == null) { return(BadRequest("Product is not currently found at that location.")); } _context.Remove(locationProduct); if (await _context.SaveChangesAsync() > 0) { return(Ok(locationProduct)); } return(BadRequest("something went wrong")); }