2017-12-29 64 views
0

私はデータベースからプルするアイテムのリストを持っていますが、同時にユーザーは発行された数量を入力します。テキストボックスを使用してデータベーステーブルに値を入力するAsp.net MVC

私の問題は、私が発行した量のために、データベース内のボタン印刷/問題に量をクリックした後、私は値を入力するようにユーザのためのテキストボックスを追加した0

であるということです。ここにあるものが正しく行われているかどうかはわかりません。

@Html.TextBoxFor(model => model.item.quantityI, new { htmlAttributes = new { @class = "form-control" } }) 
@Html.ValidationMessageFor(model => model.item.quantityI, "", new { @class = "text-danger" }) 

ビュー

if (@Model.items.Count > 0) 
{ 
    foreach (var issueditem in @Model.items) 
    { 
     <tr> 

      <td class="col-md-4">@issueditem.itemNumber</td> 
      <td class="col-md-4">@issueditem.description</td> 
      <td class="col-md-4">@issueditem.expense_account.getDescription</td> 
      <td class="col-md-2">@issueditem.quantity.ToString()</td> 
      <td class="col-md-5"> 
       @*@Html.LabelFor(model => model.item.quantityI, htmlAttributes: new { @class = "col-md-3" })*@ 
       @Html.TextBoxFor(model => model.item.quantityI, new { htmlAttributes = new { @class = "form-control" } }) 
       @Html.ValidationMessageFor(model => model.item.quantityI, "", new { @class = "text-danger" }) 
      </td> 
      <td class="col-md-1">@issueditem.selecteduomtext </td> 
      <td class="col-md-1">@issueditem.price.ToString()</td> 
     </tr> 
    } 
} 

コントローラ

public ActionResult ReceiptPrint(Issue issue) 
{ 
    IssueDAO dbdata = new IssueDAO(); 
    dbdata.connectionString = ConfigurationManager.ConnectionStrings["TWCL_OPERATIONSConnectionString"].ConnectionString; 
    getIssue.transactionDate = DateTime.Now; //Sets the transaction date to current date 
    getIssue.status = -1; 

    getIssue.docType = "Issue"; 
    ViewBag.StoresReps =dbdata.SelectEmployeesByDept("Stores"); 
    getIssue.employeeDetails.employeeNum = issue.employeeDetails.employeeNum; 
    getIssue.processedbyDetails.employeeNum = issue.processedbyDetails.employeeNum; 

    getIssue.inventory_acccount=5520; 

    Item item = new Item(); 

    try 
    { 
     dbdata.createIssue(getIssue, item);//Creates the issue in the database 
    } 
    catch (Exception ex) 
    { 
     LogWrite logWriter = new LogWrite(ex.ToString()); 
     ViewBag.errorMessage = "Unable to complete the Issue. Please see Log file for more Information"; 
     return View("IssueItem", getIssue); 

    } 
    DataSet ds = dbdata.GetReceipt(getIssue.requisitionNumber); 

    LocalReport localreport = new LocalReport(); 
    localreport.ReportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\Reciept.rdlc"; 
    localreport.DataSources.Add(new ReportDataSource("Receipt_Data", ds.Tables[0])); 
    localreport.SetParameters(new ReportParameter("Req_num", getIssue.requisitionNumber)); 

    string reporttype = "PDF"; 
    string mimeType; 
    string encoding; 
    string fileNameExtension = "pdf"; 
    string deviceInfo = @"<DeviceInfo>    
      <OutputFormat>PDF</OutputFormat>    
      <PageWidth>8.5in</PageWidth>    
      <PageHeight>11in</PageHeight>   
      <MarginTop>0.25in</MarginTop>   
      <MarginLeft>0.45in</MarginLeft>    
      <MarginRight>0.45in</MarginRight>  
      <MarginBottom>0.25in</MarginBottom></DeviceInfo>"; 
    Warning[] warnings; 
    string[] streams; 
    byte[] renderedBytes; 
    renderedBytes = localreport.Render(
    reporttype, deviceInfo, out mimeType, out encoding, out fileNameExtension, 
    out streams, out warnings); 


    var doc = new iTextSharp.text.Document(); 
    var reader = new PdfReader(renderedBytes); 
    using (FileStream fs = new FileStream(Server.MapPath("~/Receipt" + 
     Convert.ToString(Session["CurrentUserName"]) + ".pdf"), FileMode.Create)) 
    { 
     PdfStamper stamper = new PdfStamper(reader, fs); 
     string Printer = "Xerox Phaser 3635MFP PCL6"; 
     // This is the script for automatically printing the pdf in acrobat viewer 
     stamper.JavaScript = "var pp = getPrintParams();pp.interactive =pp.constants.interactionLevel.automatic; pp.printerName = " + 
         Printer + ";print(pp);\r"; 
     stamper.Close(); 
    } 
    reader.Close(); 
    FileStream fss = new FileStream(Server.MapPath("~/Receipt.pdf"), FileMode.Open); 
    byte[] bytes = new byte[fss.Length]; 
    fss.Read(bytes, 0, Convert.ToInt32(fss.Length)); 
    fss.Close(); 
    System.IO.File.Delete(Server.MapPath("~/Receipt.pdf")); 
    return File(bytes, "application/pdf", "receipt.pdf"); 
} 
+1

ここではすべてのプロセスが明確ではありません。ビューの断片にはフォームがありません、それはあなたの投稿ですか?そして、@ JohnMitchellはあなたが 'quantityI'をどこにも使っていないと言っています。もしそれが発行された量ならば、あなたはそれを設定していません。データをデータベースに保存していると思われるのは、 'dbdata.createIssue(getIssue、item)'を実行する部分だけです。とにかくそのメソッドに 'quantityI'を渡しているようではありません。 – Dzyann

答えて

0

私はあなたがモデルから数量を更新または選択したあなたのコントローラ内のどこにでも見ることができません。私はデータベースからデータを引き出すことを参照して、データベースへのプッシュを参照していますが、どこに量を設定しても表示されません。

通常は、(開始フォームで)

@using (Html.BeginForm("ActionMethodName","ControllerName")) 
{ 
    @Html.TextBoxFor(model => model.item.quantityI, new { htmlAttributes = new { @class = "form-control" } }) 
    @Html.ValidationMessageFor(model => model.item.quantityI, "", new { @class = "text-danger" }) 
    <input class="button" id="submit" type="submit" value="Submit" /> 
} 

をあなたのビューを持っています次に、あなたのコントローラにあなたが戻ってモデルデータをあなたの受け渡しを読むために何かを持っていると思います。モデルビューに

ActionResult ActionMethodNAme(MyClass myItem) 
{ 
    // MyClass would be defined as a class containing all your variables pulled from the form so you could do. You need to make MyClass in advance! 
    string quantity = myItem.quantityI; 
} 
を使用して直接名前付きの値

ActionResult ActionMethodNAme(string quantityI) 
{ 
    // The quantityI is already stored in the string parameter 
} 

3)を使用して、公共FormCollection

ActionResult ActionMethodName(FormCollection collection) 
{ 
    string quantity = collection.Get("quantityI); 
} 

2を使用して、これを行うには3つの主な方法、

1))があります。

関連する問題