Exemple #1
0
        public PartialViewResult EditSample(int?id)
        {
            if (id == null)
            {
                ViewBag.Error = "Sample Not found";
            }


            sample_detail editSample = db.sample_detail.Find(id);

            return(PartialView("_EditSample", editSample));
        }
Exemple #2
0
 public ActionResult DeleteSample(int id)
 {
     try
     {
         sample_detail sampleToDelete = db.sample_detail.Find(id);
         db.sample_detail.Remove(sampleToDelete);
         db.SaveChanges();
     }catch (Exception e)
     {
         ViewBag.Error = "Error occured. Sample Not found";
     }
     return(View("Samples"));
 }
Exemple #3
0
        public PartialViewResult DeleteSample(int?id)
        {
            sample_detail deleteSample = new sample_detail();

            if (id == null)
            {
                ViewBag.Error = "Sample Not found";
            }
            try
            {
                deleteSample = db.sample_detail.Find(id);
            }catch (Exception e)
            {
                ViewBag.Error = "Error occured. Sample Not found";
            }
            return(PartialView("_DeleteSample", deleteSample));
        }
Exemple #4
0
        public ActionResult EditSample(sample_detail sample)
        {
            try
            {
                if (ModelState.IsValid)

                {
                    db.Entry(sample).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ViewBag.Error = "Check Sample Details.\nGCL ID must be unique values.";
            }
            return(View("Samples"));
        }
        public ActionResult UploadFile(HttpPostedFileBase fileIn)
        {
            try
            {
                if (Request != null)
                {
                    HttpPostedFileBase file = Request.Files["UploadedFile"];
                    DataSet            ds   = new DataSet();

                    if ((file != null) && (file.ContentLength > 0))
                    {
                        string fileExtension = System.IO.Path.GetExtension(file.FileName);

                        if (fileExtension == ".xls" || fileExtension == ".xlsx")
                        {
                            string fileName        = file.FileName;
                            string fileContentType = file.ContentType;
                            byte[] fileBytes       = new byte[file.ContentLength];
                            var    data            = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength));
                            var    sampleList      = new List <sample_detail>();
                            using (var package = new ExcelPackage(file.InputStream))
                            {
                                var currentSheet = package.Workbook.Worksheets;
                                var workSheet    = currentSheet.First();
                                var noOfCol      = workSheet.Dimension.End.Column;
                                var noOfRow      = workSheet.Dimension.End.Row;

                                for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
                                {
                                    var sample = new sample_detail();
                                    sample.project_id = int.Parse(workSheet.Cells[rowIterator, 1].Value.ToString());
                                    sample.gcl_id     = workSheet.Cells[rowIterator, 2].Value.ToString();
                                    sample.sample_id  = workSheet.Cells[rowIterator, 3].Value.ToString();

                                    sampleList.Add(sample);
                                }

                                foreach (var i in sampleList)
                                {
                                    if (ModelState.IsValid)
                                    {
                                        using (pimsEntitiesNew db = new pimsEntitiesNew())
                                        {
                                            sample_detail newsample = new sample_detail();

                                            newsample.project_id = i.project_id;
                                            newsample.gcl_id     = i.gcl_id;
                                            newsample.sample_id  = i.sample_id;

                                            db.sample_detail.Add(newsample);
                                            db.SaveChanges();
                                        }
                                    }
                                }
                                ModelState.Clear();

                                ViewBag.Message = "File data successfully updated!";
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ViewBag.Error = "Make sure that GCL ID for samples are unique.\nAll Fields must have values and correct Datatypes.";
            }

            return(View("UploadFile"));
        }