public M_ClassApex(List<string> lines) { DataTable tmpTable = new DataTable(); setupTempTable(tmpTable); setupOutputTable(); populateTempTable(lines, tmpTable); tmp = tmpTable; //Step Though Table and fit Columns Structure pos = Structure.Info; M_ClassApexInfo info = new M_ClassApexInfo(); List<M_ClassApexInvestigation> investigstion = new List<M_ClassApexInvestigation>(); ; DataKey key = DataKey.Key; string currentKey = ""; //return tmpTable; foreach (DataRow contentrow in tmpTable.Rows) { if (pos == Structure.Info) { info = new M_ClassApexInfo(); info = populateInfo(ref pos, contentrow, ref investigstion); } else if (pos == Structure.Data){ populateData(info, ref key, ref currentKey, contentrow, investigstion); pos = Structure.Info; } } }
private static M_ClassApexInfo populateInfo(ref Structure pos, DataRow contentrow, ref List<M_ClassApexInvestigation> investigstion) { M_ClassApexInfo info = new M_ClassApexInfo(); //Location info.Location = contentrow[0].ToString(); info.Date = Convert.ToDateTime(contentrow[1].ToString()); info.Read = Convert.ToDateTime(contentrow[2].ToString()); info.LabID = contentrow[3].ToString(); if(contentrow[4].ToString().Trim() != ""){ //Found Investigation pos = Structure.Investigation; populateInvestigation(investigstion, contentrow); } pos = Structure.Data; return info; }
private void populateData(M_ClassApexInfo info, ref DataKey key, ref string currentKey, DataRow contentrow, List<M_ClassApexInvestigation> investigstion) { int col = 0; //Find Operator while (contentrow[col].ToString().Trim() != "") { if (key == DataKey.Key) { currentKey = contentrow[col].ToString().Trim(); key = DataKey.Value; } else { if (currentKey == "Operator") { info.Operator = contentrow[col].ToString(); } key = DataKey.Key; } col += 1; } //Reset Counter col = 0; while (contentrow[col].ToString().Trim() != "") { if (key == DataKey.Key) { currentKey = contentrow[col].ToString().Trim(); key = DataKey.Value; } else { if (currentKey == "Operator") { info.Operator = contentrow[col].ToString(); } else { //Can Write row to table DataRow NewDR = Data.NewRow(); NewDR[0] = info.Location; NewDR[1] = info.Date.ToShortDateString(); if (currentKey == "Finger Dab") { NewDR[2] = "Finger Touch Plate"; } else { NewDR[2] = currentKey; } NewDR[3] = info.Operator; NewDR[4] = contentrow[col].ToString(); string searchString = currentKey + " Investigation"; //Look Up Growth if (investigstion.Count > 0) { var match = (from m in investigstion where m.Investigation.Equals(searchString) select m).Single<M_ClassApexInvestigation>(); //if (match) //{ NewDR[4] = match.Growth + " : " + match.Number; //} } Data.Rows.Add(NewDR); } key = DataKey.Key; } col += 1; } }
public M_ClassImportToMRS(DataTable dt) { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); int defaultGrowthID = Convert.ToInt16(config.AppSettings.Settings["DefaultType"].Value); Class_Micro_Growth_Type defaultGrowth = new Class_Micro_Growth_Type(defaultGrowthID); ResultSets = new List<Class_Micro_Result_Set>(); ResultError = new List<M_ClassApexInfo>(); LoginClassLib.GlobalVaribles.AppDetails = new ClassAppDetails(); LoginClassLib.GlobalVaribles.AppDetails.LoadDatabaseSettings(); LoginClassLib.GlobalVaribles.AppDetails.FillDetails(); //Load Maps M_ClassMapHandler.LoadMaps(); //Loop Through Each Row in the DS. foreach (DataRow dr in dt.Rows) { //Find Location in Map var plates = from p in M_ClassMapHandler.MAP where p.MapID.ToString().Trim() == dr[0].ToString().Trim() && p.Type.ToString().Trim() == dr[2].ToString().Trim() select p; if (plates.Count() > 0) { foreach (var plate in plates) { //Find Plate Default RS Class_Micro_Plates Plate = new Class_Micro_Plates(plate.PlateID); Class_Micro_Room_Instance Instance = Class_Micro_Room_Instance.GetDefaultInstance(Plate.RoomID); //Check if RS Exists DateTime DT = Convert.ToDateTime(dr[1]); var results = from r in ResultSets where r.RoomInstanceID == Instance.ID && r.ResultsDate == DT select r; if (results.Count() == 0) { //Need to Create RS Class_Micro_Result_Set RS = Class_Micro_Result_Set.CreateResultSet(Instance.ID, DT, Instance.RoomID); RS.Import = true; RS.ImportResults = new System.Collections.ArrayList(); Class_Micro_Notes Note = new Class_Micro_Notes(); Note.Note = "Results Imported Automatically"; Note.DateTime = DateTime.Now; Note.NoteType = Class_Micro_Notes.e_NoteType.ResultEntryComment; Note.UserID = LoginClassLib.GlobalVaribles.LoggedOnUser.ID; RS.Notes = new System.Collections.ArrayList(); RS.Notes.Add(Note); ResultSets.Add(RS); results = from r in ResultSets where r.RoomInstanceID == Instance.ID && r.ResultsDate == Convert.ToDateTime(dr[1]) select r; } foreach (var resultSet in results) { Class_Micro_Result result = new Class_Micro_Result(); result.PlateID = plate.PlateID; string OpInitials = dr[3].ToString().Trim(); int RoomID = new Class_Micro_Room_Instance(resultSet.RoomInstanceID).RoomID; int OpInitialsNumber; if (int.TryParse(OpInitials, out OpInitialsNumber) && OpInitialsNumber <= 9) { OpInitials = "0" + OpInitials; } result.OperatorID = Class_Micro_Operator_Room.OperatorFromRoomInitials(OpInitials, RoomID); result.NoRecord = false; //Is there a growth? if (dr[4].ToString().Trim() != "NO GROWTH") { //Do something //MessageBox.Show(dr[4].ToString()); int Num; bool isNum = int.TryParse(dr[4].ToString(), out Num); if (isNum) { Class_Micro_Growth Growth = new Class_Micro_Growth(); Growth.Number = Num; Growth.Type = defaultGrowth; result.AddGrowth(Growth); result.Growths = Growth.Number; } } resultSet.ImportResults.Add(result); } } } else { M_ClassApexInfo Info = new M_ClassApexInfo(); Info.Location = dr[0].ToString() + " " + dr[2].ToString() ; Info.Date = Convert.ToDateTime(dr[1].ToString()); ResultError.Add(Info); } } }