// Create.cs // Это представление о покупке. Я хотел бы напечатать название поставщика и название продукта в отчете. В настоящее время я могу получить только идентификатор поставщика и идентификатор продукта.
@model fyp2_test1.purchaceInvoice
@{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_sidePanelPage.cshtml";
}
<h2><b>Insert Purchase Invoice</b></h2>
<hr />
<script src="~/scripts/jquery-1.10.2.js"></script>
<script src="~/scripts/TableJS.js"></script>
<link rel="stylesheet" href="~/Content/Site.css" />
<script>
$(function () {
$("#datepicker").datetimepicker({
changeMonth: true,
changeYear: true,
yearRange: "-100:+0",
dateFormat: 'mm/dd/yy',
controlType: 'select',
timeFormat: 'hh:mm TT',
});
});
</script>
 
 
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<table class="table table-bordered">
<thead>
<tr>
<th>@Html.Label("Date")</th>
<th>@Html.Label("Suppliers") </th>
<th>@Html.Label("Product") </th>
<th>@Html.Label("Quantity") </th>
<th>@Html.Label("Unit Price (RM)") </th>
<th>@Html.Label("Buying Price (RM)") </th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="date" id="datePicker" name="datePicker" /></td>
<td>@Html.DropDownListFor(model => model.pi_suppID, ViewBag.suppList as SelectList, "--Please Select--", new { @class = "chzn-select", @style = "width:190px;" })</td>
<td>@Html.DropDownListFor(model => model.pi_proID, ViewBag.proList as SelectList, "--Please Select--", new { @class = "chzn-select", @style = "width:190px;" })</td>
<td>@Html.EditorFor(model => model.pi_quantity, new { htmlAttributes = new { @class = "form-control", @style = "width:220px;" } })</td>
<td>@Html.EditorFor(model => model.pi_unitPrice, new { htmlAttributes = new { @class = "form-control", @style = "width:220px;" } } )</td>
<td>@Html.EditorFor(model => model.pi_buyingPrice, new { htmlAttributes = new { @class = "form-control", @style = "width:220px;" } })</td>
</tr>
</tbody>
</table>
<input type="submit" value="CREATE" class="btn-default" style="background-color:forestgreen;" />
}
 
<div>
@Html.ActionLink("Back to List", "Index")
</div>
// purchaseaceInvoiceController.cs // Я использую функцию экспорта для создания отчета Crystal
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using fyp2_test1;
using fyp2_test1.Models;
using fyp2_test1.Reports;
using CrystalDecisions.CrystalReports.Engine;
using System.IO;
namespace fyp2_test1.Controllers
{
public class purchaceInvoicesController : Controller
{
private inventoryDBEntities1 db = new inventoryDBEntities1();
// GET: purchaceInvoices
public ActionResult Index()
{
return View(db.purchaceInvoices
.Include(pi => pi.supplier)
.Include(pi => pi.product)
.ToList());
}
public ActionResult Export()
{
ReportDocument rd = new ReportDocument();
rd.Load(Path.Combine(Server.MapPath("~/Reports/CrystalReport.rpt")));
rd.SetDataSource(db.purchaceInvoices.Select(p => new
{
Id = p.pi_id,
Date = p.pi_date,
Supplier = (p.pi_suppID),
Product = p.pi_proID,
Quantity = p.pi_quantity,
UnitPrice = p.pi_unitPrice,
BuyingPrice = p.pi_buyingPrice
}).ToList());
Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/pdf", "ListProducts.pdf");
}
// GET: purchaceInvoices/Details/5
public ActionResult Details(long? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
purchaceInvoice purchaceInvoice = db.purchaceInvoices.Find(id);
if (purchaceInvoice == null)
{
return HttpNotFound();
}
return View(purchaceInvoice);
}
// GET: purchaceInvoices/Create
public ActionResult Create()
{
ViewBag.pi_suppID = new SelectList(db.suppliers, "sup_id", "sup_name");
ViewBag.pi_proID = new SelectList(db.products, "pro_id", "pro_name");
//ViewBag.pi_unitPrice = new SelectList(db.products, "pro_id", "pro_unitPrice");
return View();
}
// POST: purchaceInvoices/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "pi_id,pi_date,pi_suppID,pi_proID,pi_quantity,pi_unitPrice,pi_buyingPrice")] purchaceInvoice purchaceInvoice)
{
if (ModelState.IsValid)
{
db.purchaceInvoices.Add(purchaceInvoice);
ViewBag.pi_suppID = new SelectList(db.suppliers, "sup_id", "sup_name", purchaceInvoice.pi_suppID);
ViewBag.pi_proID = new SelectList(db.products, "pro_id", "pro_name", purchaceInvoice.pi_proID);
//ViewBag.pi_unitPrice = new SelectList(db.products, "pro_id", "pro_unitPrice", purchaceInvoice.pi_unitPrice);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(purchaceInvoice);
}
// GET: purchaceInvoices/Edit/5
public ActionResult Edit(long? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
purchaceInvoice purchaceInvoice = db.purchaceInvoices.Find(id);
if (purchaceInvoice == null)
{
return HttpNotFound();
}
ViewBag.pi_suppID = new SelectList(db.suppliers, "sup_id", "sup_name", purchaceInvoice.pi_suppID);
ViewBag.pi_proID = new SelectList(db.products, "pro_id", "pro_name", purchaceInvoice.pi_proID);
//ViewBag.pi_unitPrice = new SelectList(db.products, "pro_id", "pro_unitPrice", purchaceInvoice.pi_unitPrice);
return View(purchaceInvoice);
}
// POST: purchaceInvoices/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "pi_id,pi_date,pi_suppID,pi_proID,pi_quantity,pi_unitPrice,pi_buyingPrice")] purchaceInvoice purchaceInvoice)
{
if (ModelState.IsValid)
{
db.Entry(purchaceInvoice).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.pi_suppID = new SelectList(db.suppliers, "sup_id", "sup_name", purchaceInvoice.pi_suppID);
ViewBag.pi_proID = new SelectList(db.products, "pro_id", "pro_name", purchaceInvoice.pi_proID);
//ViewBag.pi_unitPrice = new SelectList(db.products, "pro_id", "pro_unitPrice", purchaceInvoice.pi_unitPrice);
return View(purchaceInvoice);
}
// GET: purchaceInvoices/Delete/5
public ActionResult Delete(long? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
purchaceInvoice purchaceInvoice = db.purchaceInvoices.Find(id);
if (purchaceInvoice == null)
{
return HttpNotFound();
}
return View(purchaceInvoice);
}
// POST: purchaceInvoices/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(long id)
{
purchaceInvoice purchaceInvoice = db.purchaceInvoices.Find(id);
db.purchaceInvoices.Remove(purchaceInvoice);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}
myDB.edmx Я хочу получить имя поставщика и название продукта из таблицы поставщиков и продуктов, а не только их идентификатор.