public bool UpdateRow(ChiTietPhieuNhapSach obj) { try { if (_connection.State != ConnectionState.Open) { _connection.Open(); } string sql = "UPDATE [dbo].[ChiTietPhieuNhapSach]\n" + " SET [MaPhieuNhapSach] = @MaPhieuNhapSach\n" + " ,[MaSach] = @MaSach\n" + " ,[SoLuongNhap] = @SoLuongNhap\n" + " ,[DonGiaNhap] = @DonGiaNhap\n" + " WHERE [MaChiTietPhieuNhapSach] = @MaChiTietPhieuNhapSach"; var cmd = new SqlCommand(sql, _connection); cmd.Parameters.Add("@MaChiTietPhieuNhapSach", SqlDbType.Char).Value = obj.MaChiTietPhieuNhapSach; cmd.Parameters.Add("@MaPhieuNhapSach", SqlDbType.Char).Value = obj.MaPhieuNhapSach; cmd.Parameters.Add("@MaSach", SqlDbType.Char).Value = obj.MaSach; cmd.Parameters.Add("@SoLuongNhap", SqlDbType.Int).Value = obj.SoLuongNhap; cmd.Parameters.Add("@DonGiaNhap", SqlDbType.Money).Value = obj.DonGiaNhap; cmd.ExecuteNonQuery(); _connection.Close(); return(true); } catch (Exception ex) { _connection.Close(); Console.WriteLine(ex.Message); } return(false); }
public ChiTietPhieuNhapSach GetRow(string maCTPNS) { try { var obj = new ChiTietPhieuNhapSach(); if (_connection.State != ConnectionState.Open) { _connection.Open(); } SqlCommand command = new SqlCommand("SELECT * FROM ChiTietPhieuNhapSach WHERE MaChiTietPhieuNhapSach = @machitietpns", _connection); command.Parameters.Add("@machitietpns", SqlDbType.Char).Value = maCTPNS; SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { obj.MaChiTietPhieuNhapSach = reader["MaChiTietPhieuNhapSach"].ToString(); obj.MaPhieuNhapSach = reader["MaPhieuNhapSach"].ToString(); obj.MaSach = reader["MaSach"].ToString(); obj.SoLuongNhap = (int)reader["SoLuongNhap"]; obj.DonGiaNhap = (decimal)reader["DonGiaNhap"]; reader.Close(); } return(obj); } catch (Exception ex) { _connection.Close(); Console.WriteLine(ex.Message); } return(null); }
public bool UpdateChiTietPN(ChiTietPhieuNhapSach ctpn) { if (objCTPN.IsRowExists(ctpn.MaChiTietPhieuNhapSach)) { return(objCTPN.UpdateRow(ctpn)); } else { return(false); } }
public bool AddChiTietPN(ChiTietPhieuNhapSach ctpn) { if (!objCTPN.IsRowExists(ctpn.MaChiTietPhieuNhapSach) && objPN.IsRowExists(ctpn.MaPhieuNhapSach)) { return(objCTPN.AddRow(ctpn)); } else { return(false); } }
public ChiTietPhieuNhapDTO ConvertToDTO(ChiTietPhieuNhapSach item) { Sach book = sachBL.GetBookById((int)item.IdSach); ChiTietPhieuNhapDTO dto = new ChiTietPhieuNhapDTO(); dto.Id = item.Id; dto.TenSach = book.TenSach; if (book.Tap == null) { dto.Tap = ""; } else { dto.Tap = book.Tap.ToString(); } dto.SoLuong = (int)item.SoLuong; dto.DonGia = (decimal)item.DonGia; return(dto); }
public ActionResult ThemChiTiet(string so, string dg) { ChiTietPhieuNhapSach ct = new ChiTietPhieuNhapSach(); string ma = ""; var phieu = db.PhieuNhapSaches.OrderByDescending(x => x.IDPhieuNhapSach).ToList(); foreach (var item in phieu) { ma = item.IDPhieuNhapSach; break; } ct.IDPhieuNhapSach = ma; ct.IDSach = Session["IDSach"].ToString(); ct.SoLuong = Convert.ToInt32(so); ct.DonGia = Convert.ToInt32(dg); //ct.SoLuong = int.Parse(f["SoLuong"]); //ct.DonGia = int.Parse(f["DonGia"]); db.ChiTietPhieuNhapSaches.Add(ct); db.SaveChanges(); return(new EmptyResult()); }
public bool AddRow(ChiTietPhieuNhapSach obj) { try { if (_connection.State != ConnectionState.Open) { _connection.Open(); } string sql = "INSERT INTO [dbo].[ChiTietPhieuNhapSach]\n" + " ([MaChiTietPhieuNhapSach]\n" + " ,[MaPhieuNhapSach]\n" + " ,[MaSach]\n" + " ,[SoLuongNhap]\n" + " ,[DonGiaNhap])\n" + " VALUES\n" + " (@MaChiTietPhieuNhapSach\n" + " ,@MaPhieuNhapSach\n" + " ,@MaSach\n" + " ,@SoLuongNhap\n" + " ,@DonGiaNhap)"; SqlCommand cmd = new SqlCommand(sql, _connection); cmd.Parameters.Add("@MaChiTietPhieuNhapSach", SqlDbType.Char).Value = obj.MaChiTietPhieuNhapSach; cmd.Parameters.Add("@MaPhieuNhapSach", SqlDbType.Char).Value = obj.MaPhieuNhapSach; cmd.Parameters.Add("@MaSach", SqlDbType.Char).Value = obj.MaSach; cmd.Parameters.Add("@SoLuongNhap", SqlDbType.Int).Value = obj.SoLuongNhap; cmd.Parameters.Add("@DonGiaNhap", SqlDbType.Money).Value = obj.DonGiaNhap; cmd.ExecuteNonQuery(); _connection.Close(); return(true); } catch (Exception ex) { _connection.Close(); Console.WriteLine(ex.Message); } return(false); }