Skip to content

Commit

Permalink
Merge pull request #68 from marvinkobit/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
marvinkobit authored Jul 18, 2023
2 parents 8962ea9 + 7de7817 commit a1e831f
Show file tree
Hide file tree
Showing 12 changed files with 390 additions and 68 deletions.
17 changes: 10 additions & 7 deletions Labtracker/AddUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,21 +402,24 @@ public bool AddUpdate(string dater,string repDate, string SaId, string week, str


//Overload for DnaExtraction
public bool AddUpdater(DateTime? dater, string PaId, string purity, string ndConc, string qubConc,string remark , string labInitial)
public bool AddDnaExtract(string dater, string PaId, string purity, string ndConc, string qubConc,string remark , string labInitial, string tubeLabel, string goodQQ,string sampleType, string assayReagent)
{
var tbgdnaextractupdates = new Dnaextract();

tbgdnaextractupdates.PatientId = PaId;
//tbgdstupdates.DstID = Convert.ToInt32(ResuId);
tbgdnaextractupdates.Initial = labInitial;
tbgdnaextractupdates.Purity = Convert.ToDecimal(purity);
tbgdnaextractupdates.NDConc = Convert.ToDecimal(ndConc);
tbgdnaextractupdates.QubitConc = Convert.ToDecimal(qubConc);


tbgdnaextractupdates.ExtractDate = Convert.ToDateTime(dater);
tbgdnaextractupdates.Purity = string.IsNullOrWhiteSpace(purity)? (decimal?)null : Convert.ToDecimal(purity);
tbgdnaextractupdates.NDConc = string.IsNullOrWhiteSpace(ndConc)? (decimal?)null : Convert.ToDecimal(ndConc);
tbgdnaextractupdates.QubitConc = qubConc;
tbgdnaextractupdates.ExtractDate = string.IsNullOrEmpty(dater)? (DateTime?)null : Convert.ToDateTime(dater);
tbgdnaextractupdates.Remark = remark;

tbgdnaextractupdates.GoodQQ = goodQQ;
tbgdnaextractupdates.TubeLabel = tubeLabel;
tbgdnaextractupdates.SampleType = sampleType;
tbgdnaextractupdates.AssayReagent = assayReagent;


using (SampleContext _db = new SampleContext())
{
Expand Down
176 changes: 176 additions & 0 deletions Labtracker/Controllers/DnaExtractExcelController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
using ExcelDataReader;
using Labtracker.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Labtracker.Controllers
{
public class DnaExtractExcelController : Controller
{
// GET: DnaExtractExcel
public ActionResult Index()
{
DataTable dt = new DataTable();
try
{
dt = (DataTable)Session["tmpdata"];
}
catch (Exception)
{
throw;
}

return View(dt);
}


[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index(HttpPostedFileBase upload)
{

if (ModelState.IsValid)
{

if (upload != null && upload.ContentLength > 0)
{
// ExcelDataReader works with the binary Excel file, so it needs a FileStream
// to get started. This is how we avoid dependencies on ACE or Interop:
Stream stream = upload.InputStream;

// We return the interface, so that
IExcelDataReader reader = null;


if (upload.FileName.EndsWith(".xls"))
{
reader = ExcelReaderFactory.CreateBinaryReader(stream);
}
else if (upload.FileName.EndsWith(".xlsx"))
{
reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
}
else
{
ModelState.AddModelError("File", "This file format is not supported");
return View();
}
int fieldcount = reader.FieldCount;
int rowcount = reader.RowCount;


DataTable dt = new DataTable();
//dt.Columns.Add("UserName");
//dt.Columns.Add("Adddress");
DataRow row;


DataTable dt_ = new DataTable();
string err1 = "", err2 = "";
try
{

dt_ = reader.AsDataSet().Tables[0];

string ret = "";

for (int i = 0; i < dt_.Columns.Count; i++)
{
dt.Columns.Add(dt_.Rows[0][i].ToString());
}

int rowcounter = 0;
for (int row_ = 1; row_ < dt_.Rows.Count; row_++)
{
row = dt.NewRow();

for (int col = 0; col < dt_.Columns.Count; col++)
{

row[col] = dt_.Rows[row_][col].ToString();
rowcounter++;
}
dt.Rows.Add(row);

err1 = row[9].ToString();
err2 = row[10].ToString();
//db insert
try
{
using (var context = new SampleContext())

{



var tbgdnaextractupdates = new Dnaextract();

tbgdnaextractupdates.PatientId = row[0].ToString();
tbgdnaextractupdates.TubeLabel = row[1].ToString();
tbgdnaextractupdates.GoodQQ = row[2].ToString();
tbgdnaextractupdates.NDConc = string.IsNullOrWhiteSpace(row[3].ToString()) ? (decimal?)null : Convert.ToDecimal(row[3].ToString());
tbgdnaextractupdates.Purity = string.IsNullOrWhiteSpace(row[5].ToString()) ? (decimal?)null : Convert.ToDecimal(row[5].ToString());
tbgdnaextractupdates.SampleType = row[6].ToString();
tbgdnaextractupdates.QubitConc = row[7].ToString();

tbgdnaextractupdates.AssayReagent = row[9].ToString();
tbgdnaextractupdates.ExtractDate = string.IsNullOrEmpty(row[10].ToString()) ? (DateTime?)null : Convert.ToDateTime(row[10].ToString());

//tbgdnaextractupdates.Initial = labInitial;
//tbgdnaextractupdates.Remark = remark;

context.Dnaextracts.Add(tbgdnaextractupdates);
context.SaveChanges();


}
}
catch (Exception ex1)
{
throw ex1;

}

}

}
catch (Exception ex)
{

ModelState.AddModelError("File", ex.ToString() + err1 + err2 + "Unable to Upload file! Info: Data Validation Error, Invalid data entry.");

return View();
}

DataSet result = new DataSet();//reader.AsDataSet();
result.Tables.Add(dt);
string minutes_ID = "";

reader.Close();
reader.Dispose();
// return View();
// return View(result.Tables[0]);

DataTable ddd = result.Tables[0];

Session["tmpdata"] = ddd;

return RedirectToAction("Index");

}
else
{
ModelState.AddModelError("File", "Please Choose Your file to Upload");
}
}
return View();
}

}
}
2 changes: 2 additions & 0 deletions Labtracker/Labtracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2278,6 +2278,7 @@
<Compile Include="Contact.aspx.designer.cs">
<DependentUpon>Contact.aspx</DependentUpon>
</Compile>
<Compile Include="Controllers\DnaExtractExcelController.cs" />
<Compile Include="Controllers\SampleExcelController.cs" />
<Compile Include="Controllers\ProgressExcelController.cs" />
<Compile Include="CrystalReport1.cs">
Expand Down Expand Up @@ -2493,6 +2494,7 @@
<Content Include="Views\Shared\_Layout.cshtml" />
<Content Include="Views\SampleExcel\Index.cshtml" />
<Content Include="Views\ProgressExcel\Index.cshtml" />
<Content Include="Views\DnaExtractExcel\Index.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
Expand Down
11 changes: 8 additions & 3 deletions Labtracker/Models/Dnaextract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public class Dnaextract
public string PatientId { get; set; }

[Display(Name = "ND Conc")]
public decimal NDConc { get; set; }
public Nullable<decimal> NDConc { get; set; }

[Display(Name = "Qubit Conc")]
public decimal QubitConc { get; set; }
public string QubitConc { get; set; }

[Display(Name = "Purity")]
public decimal Purity { get; set; }
public Nullable<decimal> Purity { get; set; }

[Display(Name = "Extract Date")]
public Nullable<DateTime> ExtractDate { get; set; }
Expand All @@ -32,6 +32,11 @@ public class Dnaextract

[Display(Name = "Initial")]
public string Initial { get; set; }
public string TubeLabel { get; set; }

public string GoodQQ { get; set; }
public string SampleType { get; set; }
public string AssayReagent { get; set; }

}
}
119 changes: 119 additions & 0 deletions Labtracker/Views/DnaExtractExcel/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@


@{
ViewBag.Title = "DNA Extract Excel Upload";
}

@model System.Data.DataTable
@using System.Data;




<script src="~/Scripts/jquery-3.3.1.js"></script>

<script>
function bs_input_file() {
$(".input-file").before(
function () {
if (!$(this).prev().hasClass('input-ghost')) {
var element = $("<input type='file' id='dataFile' name='upload' class='input-ghost' style='visibility:visible; height:20;'>");
element.attr("name", $(this).attr("name"));
element.change(function () {
element.next(element).find('input').val((element.val()).split('\\').pop());
});
$(this).find("button.btn-choose").click(function () {
element.click();
});
$(this).find("button.btn-reset").click(function () {
element.val(null);
$(this).parents(".input-file").find('input').val('');
});
$(this).find('input').css("cursor", "pointer");
$(this).find('input').mousedown(function () {
$(this).parents('.input-file').prev().click();
return false;
});
return element;
}
}
);
}
function clear() {
var input = $("#dataFile").val('');
};
$(function () {
clear();
bs_input_file();
});
</script>

@using (Html.BeginForm("Index", "DnaExtractExcel", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="info2">
<h2>DnaExtract Excel File Upload</h2>
@Html.AntiForgeryToken()

<div class="form-group" name="Fichier1">
<!-- COMPONENT START -->
<div class="form-group">
<div class="input-group input-file">
<span class="input-group-btn">
@*<button class="btn btn-default btn-choose" type="button">Choose</button>*@
</span>
@*<input type="text" class="form-control" placeholder='Choose a file...' />*@

</div>
</div>
@*<input type="file" id="dataFile" name="upload"/>*@

</div>

<div class="form-group">
<input type="submit" value="Import from Excel" class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm" />
@*<button class="btn btn-default" style="background-color:Highlight" >Save</button>*@
</div>


<div class="alert alert-danger">
@Html.ValidationSummary()
@*<strong></strong> asdasd*@
</div>



</div>
if (Model != null)
{
<table id="table1" class="table table-bordered table-hover">
<thead>
<tr>
@foreach (DataColumn col in Model.Columns)
{
<th>@col.ColumnName</th>
}
</tr>
</thead>
<tbody>
@foreach (DataRow row in Model.Rows)
{
<tr>
@foreach (DataColumn col in Model.Columns)
{
<td>@row[col.ColumnName]</td>
}
</tr>
}
</tbody>
</table>
}
}

<script>
$(document).ready(function () {
$("table1").DataTable();
});
</script>


Loading

0 comments on commit a1e831f

Please sign in to comment.