Mvc4uses FormCollection to add data in batches. mvc4formcollection

Source: Internet
Author: User

Mvc4uses FormCollection to add data in batches. mvc4formcollection

 


// POST:/Assay_BillMain/Create
/// <Summary>
/// Add data in batches
/// </Summary>
/// <Param name = "assay_billmain"> </param>
/// <Param name = "fc"> </param>
/// <Param name = "assau_billdetail"> </param>
/// <Returns> </returns>
[HttpPost]
[ValidateAntiForgeryToken]
Public ActionResult Create (Assay_BillMain assay_billmain, FormCollection fc, Assay_BillDetail assau_billdetail)
{
Int BillMain_PTR = 0;
String [] ItemNoArr = new string [] {};
String [] TankNoArr = new string [] {};
String [] ItemArr = new string [] {};
String [] MeiRangeArr = new string [] {};
String [] AnalyseRangeArr = new string [] {};
String [] ResultArr = new string [] {};
String [] MethodsArr = new string [] {};
String [] ChemicalsArr = new string [] {};
String [] QuantityArr = new string [] {};
String [] FinalResultArr = new string [] {};
String [] FinalTimeArr = new string [] {};

If (ModelState. IsValid)
{
Db. Assay_BillMain.Add (assay_billmain );
Db. SaveChanges ();
String strMaxSql = "select * from dbo. Assay_BillMain where RKEY = (select max (RKEY) from dbo. Assay_BillMain );";
DataSet ds = SqlHelper. Query (strMaxSql );

If (ds. Tables [0]. Rows. Count> 0)
{
BillMain_PTR = Convert. ToInt32 (ds. Tables [0]. Rows [0] ["RKEY"]);
}

ItemNoArr = fc ["ItemNo"]. Split (',');
TankNoArr = fc ["TankNo"]. Split (',');
ItemArr = fc ["Item"]. Split (',');
MeiRangeArr = fc ["MeiRange"]. Split (',');
AnalyseRangeArr = fc ["AnalyseRange"]. Split (',');
ResultArr = fc ["Result"]. Split (',');
MethodsArr = fc ["Methods"]. Split (',');
ChemicalsArr = fc ["Chemicals"]. Split (',');
QuantityArr = fc ["Quantity"]. Split (',');
FinalResultArr = fc ["FinalResult"]. Split (',');
FinalTimeArr = fc ["FinalTime"]. Split (',');

For (int n = 0; n <ItemNoArr. Length; n ++)
{
Assau_billdetail = new Assay_BillDetail ();
Assau_billdetail.BillMain_PTR = BillMain_PTR;
Assau_billdetail.ItemNo = Convert. ToInt16 (ItemNoArr [n]);
Assau_billdetail.TankNo = TankNoArr [n];
Assau_billdetail.Item = ItemArr [n];
Assau_billdetail.MeiRange = MeiRangeArr [n];
Assau_billdetail.AnalyseRange = AnalyseRangeArr [n];
Assau_billdetail.Result = ResultArr [n];
Assau_billdetail.Methods = MethodsArr [n];
Assau_billdetail.Chemicals = ChemicalsArr [n];
Assau_billdetail.Quantity = QuantityArr [n];
Assau_billdetail.FinalResult = FinalResultArr [n];
Assau_billdetail.FinalTime = FinalTimeArr [n];
Db. Assay_BillDetail.Add (assau_billdetail );
Db. SaveChanges ();
}
Return Content ("<script type = 'text/javascript '> alert ('document input successful! '); Window. location. href ='/Assay_BillMain/create' </script> ");
}

ViewBag. Process_PTR = new SelectList (db. Assay_Process, "RKEY", "ProcessName", assay_billmain.Process_PTR );
ViewBag. Type_PTR = new SelectList (db. EnmItemValues, "RKEY", "ItemValue", assay_billmain.Type_PTR );
Return View (assay_billmain );
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.