public ActionResult Index(StartPieceViewModel vm)
        {
            var ctx = new BarCodeContext();

            if (vm.FinishPiece == "yes")
            {
                var job = new Job
                {
                    Status = "started",
                    Start = DateTime.Now,
                    End = new DateTime(1900, 01, 01, 00, 00, 00),
                    PieceNo = vm.PieceNo
                };
                ctx.Job.Add(job);
                ctx.SaveChanges();

                vm = viewModel;
                return View("JobFinish", vm);
            }

            else
            {
                //var result = ctx.Job.First(a => a.TravellerId == scan.BarCode);
                var result = ctx.Import.First(a => a.PieceNo == vm.PieceNo);
                vm.Id = result.Id;
                vm.Project = result.Project;
                vm.CompanyName = result.CompanyName;
                vm.Description = result.Description;
                vm.JobNo = result.JobNo;

                viewModel = vm;
                return View("StartPiece", vm);

            }
        }
        public ActionResult Index(ImportSettings i)
        {
            BarCodeContext db = new BarCodeContext();

            Import newImport = new Import();

            if (Request.Files["FileUpload"].ContentLength > 0)
            {

                string extension = System.IO.Path.GetExtension(Request.Files["FileUpload"].FileName);
                string path = string.Format("{0}/{1}", Server.MapPath("~/Content/UploadedFolder"),Request.Files["FileUpload"].FileName);

                //ImportSettings newImportSettings = new ImportSettings(path, extension);
                if (System.IO.File.Exists(path))
                    System.IO.File.Delete(path);

                Request.Files["FileUpload"].SaveAs(path);
                //string sqlConnectionString = @"Data Source=PRONOY-XPS\XPSSERVER; Database=Import; Trusted_Connection=true;Persist Security Info=True";

                //Create connection string to Excel work book
                string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path +
                                               ";Extended Properties=Excel 12.0;Persist Security Info=False";
                //Create Connection to Excel work book
                OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
                //Create OleDbCommand to fetch data from Excel
                OleDbCommand cmd =
                    new OleDbCommand(
                        "Select [Ref],[Customer],[Job No],[Item No], [Labour Code], [Description], [Project], [Company Name] from [Sheet1$]",
                        excelConnection);
                excelConnection.Open();
                OleDbDataReader dReader;
                dReader = cmd.ExecuteReader();

                while (dReader.Read())
                {
                    newImport.Ref = (string) dReader["Ref"].ToString();
                    newImport.Customer = (string) dReader["Customer"].ToString();
                    newImport.JobNo = (string) dReader["Job No"].ToString();
                    newImport.ItemNo = (string) dReader["Item No"].ToString();
                    newImport.PieceNo = newImport.JobNo + '-' + newImport.ItemNo;
                    newImport.LabourCode = (string) dReader["Labour Code"].ToString();
                    newImport.Description = (string) dReader["Description"].ToString();
                    newImport.Project = (string) dReader["Project"].ToString();
                    newImport.CompanyName = (string) dReader["Company Name"].ToString();

                    if (ModelState.IsValid)
                    {

                        db.Import.Add(newImport);
                        db.SaveChanges();
                    }

                }

                //   SqlBulkCopy sqlBulk = new SqlBulkCopy(sqlConnectionString);
                //Give your Destination table name
                // sqlBulk.DestinationTableName = "tblStudents";
                //sqlBulk.WriteToServer(dReader);
                excelConnection.Close();
                // SQL Server Connection String

            }
            return RedirectToAction("Index");
        }