public void test(string a) { try { tem = port.ReadExisting(); LogProgram.WriteLog("[Start4: COM]: ", tem); InputData += tem.Trim(); if (tem.StartsWith("")) { File.Create("Step1.txt"); LogProgram.WriteBeginTranfer(); frmMain.formMain.m_notifyicon.ShowBalloonTip(3, "MKV", "Đang nhận kết quả từ máy Stago Start 4", System.Windows.Forms.ToolTipIcon.Info); } if (tem.Trim().TrimEnd('\0').EndsWith("")) { File.Create("Step2.txt"); InputData = InputData.TrimStart('').TrimEnd('\0', ''); InputData = InputData.Replace("", "$"); string[] temp = InputData.Split('$'); foreach (string t in temp) { StagoStart4Result re = new StagoStart4Result(t); if (UpdateToSQL(re) == false) { File.Create("Step3.txt"); //LogProgram.WriteSaveFail(re); frmMain.formMain.m_notifyicon.ShowBalloonTip(3, "MKV", "Lưu kết quả '" + re.ID + "' từ máy Stago Start 4 không thành công", System.Windows.Forms.ToolTipIcon.Error); } else { //LogProgram.WriteSaveSucess(re); frmMain.formMain.m_notifyicon.ShowBalloonTip(3, "MKV", "Đã lưu kết quả '" + re.ID + "' từ máy Stago Start 4", System.Windows.Forms.ToolTipIcon.Info); } } LogProgram.WriteEndTranfer(); tem = ""; InputData = ""; } } catch (Exception ex) { LogProgram.WriteLog("[Start4:] ", ex.ToString()); } }
public StagoStart4Result(string ouputFromLaura) { ouputFromLaura = ouputFromLaura.Trim(); string[] opArray = ouputFromLaura.Split(' '); List <string> opList = new List <string>(); foreach (string str in opArray) { if (str.Trim() == "") { continue; } opList.Add(str.Trim()); } if (opList.Count >= 5) { if (opList[5].EndsWith("S")) { opList.Insert(5, "1"); } } int count; if (int.TryParse(opList[5], out count) == false) { count = 1; } this.ID = GetID(opList[6]); this.TypeID = opList[3].Substring(0, 1); this.C = opList[2]; if (TypeID == "1" && C == "1") { this.TypeName = "PT"; this.TQ = GetDecimal(opList[7]); this.PROTHROMBINE = GetDecimal(opList[8]); this.INR = GetDecimal(opList[9]); if (count >= 2) { this.SecondResult = new StagoStart4Result(); this.SecondResult.TypeID = this.TypeID; this.SecondResult.TypeName = this.TypeName; this.SecondResult.C = this.C; this.SecondResult.ID = GetID(opList[10]); this.SecondResult.TQ = GetDecimal(opList[11]); this.SecondResult.PROTHROMBINE = GetDecimal(opList[12]); this.SecondResult.INR = GetDecimal(opList[13]); if (count >= 3) { this.SecondResult.SecondResult = new StagoStart4Result(); this.SecondResult.SecondResult.TypeID = this.TypeID; this.SecondResult.SecondResult.TypeName = this.TypeName; this.SecondResult.SecondResult.C = this.C; this.SecondResult.SecondResult.ID = GetID(opList[14]); this.SecondResult.SecondResult.TQ = GetDecimal(opList[15]); this.SecondResult.SecondResult.PROTHROMBINE = GetDecimal(opList[16]); this.SecondResult.SecondResult.INR = GetDecimal(opList[17]); if (count >= 4) { this.SecondResult.SecondResult.SecondResult = new StagoStart4Result(); this.SecondResult.SecondResult.SecondResult.TypeID = this.TypeID; this.SecondResult.SecondResult.SecondResult.TypeName = this.TypeName; this.SecondResult.SecondResult.SecondResult.C = this.C; this.SecondResult.SecondResult.SecondResult.ID = GetID(opList[18]); this.SecondResult.SecondResult.SecondResult.TQ = GetDecimal(opList[19]); this.SecondResult.SecondResult.SecondResult.PROTHROMBINE = GetDecimal(opList[20]); this.SecondResult.SecondResult.SecondResult.INR = GetDecimal(opList[21]); } } } else if (TypeID == "2" && C == "1") { this.TypeName = "APTT"; this.TCK = GetDecimal(opList[7]); if (count >= 2) { this.SecondResult = new StagoStart4Result(); this.SecondResult.TypeID = this.TypeID; this.SecondResult.TypeName = this.TypeName; this.SecondResult.C = this.C; this.SecondResult.ID = GetID(opList[10]); this.SecondResult.TCK = GetDecimal(opList[11]); if (count >= 3) { this.SecondResult.SecondResult = new StagoStart4Result(); this.SecondResult.SecondResult.TypeID = this.TypeID; this.SecondResult.SecondResult.TypeName = this.TypeName; this.SecondResult.SecondResult.C = this.C; this.SecondResult.SecondResult.ID = GetID(opList[14]); this.SecondResult.SecondResult.TCK = GetDecimal(opList[15]); if (count >= 4) { this.SecondResult.SecondResult.SecondResult = new StagoStart4Result(); this.SecondResult.SecondResult.SecondResult.TypeID = this.TypeID; this.SecondResult.SecondResult.SecondResult.TypeName = this.TypeName; this.SecondResult.SecondResult.SecondResult.C = this.C; this.SecondResult.SecondResult.SecondResult.ID = GetID(opList[18]); this.SecondResult.SecondResult.SecondResult.TCK = GetDecimal(opList[19]); } } } } else if (TypeID == "3" && C == "1") { this.TypeName = "FIBRIOGEN"; this.FIBRINOGENE = GetDecimal(opList[7]); if (count >= 2) { this.SecondResult = new StagoStart4Result(); this.SecondResult.TypeID = this.TypeID; this.SecondResult.TypeName = this.TypeName; this.SecondResult.C = this.C; this.SecondResult.ID = GetID(opList[10]); this.SecondResult.FIBRINOGENE = GetDecimal(opList[11]); if (count >= 3) { this.SecondResult.SecondResult = new StagoStart4Result(); this.SecondResult.SecondResult.TypeID = this.TypeID; this.SecondResult.SecondResult.TypeName = this.TypeName; this.SecondResult.SecondResult.C = this.C; this.SecondResult.SecondResult.ID = GetID(opList[14]); this.SecondResult.SecondResult.FIBRINOGENE = GetDecimal(opList[15]); if (count >= 4) { this.SecondResult.SecondResult.SecondResult = new StagoStart4Result(); this.SecondResult.SecondResult.SecondResult.TypeID = this.TypeID; this.SecondResult.SecondResult.SecondResult.TypeName = this.TypeName; this.SecondResult.SecondResult.SecondResult.C = this.C; this.SecondResult.SecondResult.SecondResult.ID = GetID(opList[18]); this.SecondResult.SecondResult.SecondResult.FIBRINOGENE = GetDecimal(opList[19]); } } } } } }
//ST4 TR 1 1INR 13.281 2 14S 14.500 83.400 1.120 15S 15.700 71.600 1.240m private void DataReceive(object obj, SerialDataReceivedEventArgs e) { try { tem = port.ReadExisting(); LogProgram.WriteLog("[Start4: COM]: ", tem); if (tem.Length > 20) { InputData += tem.Trim(); } else { if (InputData.Trim().EndsWith("ST4")) { InputData += " " + tem.Trim(); } else { if (tem.EndsWith("S") && !tem.EndsWith("S")) { InputData += tem.ToString() + " "; } else if (tem.EndsWith("INR")) { InputData += tem.ToString() + " "; } else { InputData += tem.ToString(); } } } //if (tem.Trim().ToString()!="") //{ // InputData = InputData.Trim(); //} string time = DateTime.Now.ToString("ddMMyyyy") + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString(); if (tem.StartsWith("")) { //WriteFile("NhanDuLieuLuc" + time + ".txt",InputData); // File.Create("Step1.txt"); LogProgram.WriteBeginTranfer(); frmMain.formMain.m_notifyicon.ShowBalloonTip(3, "MKV", "Đang nhận kết quả từ máy Stago Start 4", System.Windows.Forms.ToolTipIcon.Info); } if (tem.Trim().TrimEnd('\0').EndsWith("")) { string a = InputData.Trim().ToString(); InputData = a; LogProgram.WriteLog("Stago Result:", InputData); string[] temp = InputData.Split(new char[] { '', '' }, StringSplitOptions.RemoveEmptyEntries); //WriteFile("DuLieuXuliLuc" + time + ".txt", InputData.ToString()); foreach (string t in temp) { StagoStart4Result re = new StagoStart4Result(t); if (UpdateToSQL(re) == false) { //WriteFile("XuliThatBaiLuc" + time + ".txt", InputData.ToString()); //LogProgram.WriteSaveFail(re); frmMain.formMain.m_notifyicon.ShowBalloonTip(3, "MKV", "Lưu kết quả '" + re.ID + "' từ máy Stago Start 4 không thành công", System.Windows.Forms.ToolTipIcon.Error); } else { //WriteFile("XuliThanhCongLuc" + time + ".txt", InputData.ToString()); //LogProgram.WriteSaveSucess(re); frmMain.formMain.m_notifyicon.ShowBalloonTip(3, "MKV", "Đã lưu kết quả '" + re.ID + "' từ máy Stago Start 4", System.Windows.Forms.ToolTipIcon.Info); } } LogProgram.WriteEndTranfer(); tem = ""; InputData = ""; } } catch (Exception ex) { LogProgram.WriteLog("[Start4:] ", ex.ToString()); tem = ""; InputData = ""; } }
public bool UpdateToSQL(StagoStart4Result result) { try { while (result != null) { ServerConnect.I.BeginTran(); string idkqua = DateTime.Today.ToString("yyMMdd") + "-" + result.ID; string idKetQuaTuMayCLS = GetIdKetQuaTuMayCLS(idkqua); List <string> paramName = new List <string>(); List <object> values = new List <object>(); List <SqlDbType> sqlTypes = new List <SqlDbType>(); if (result.FIBRINOGENE != null) { paramName.Add("@FIB"); values.Add(result.FIBRINOGENE.Value); sqlTypes.Add(SqlDbType.Float); } if (result.INR != null) { paramName.Add("@INR"); values.Add(result.INR.Value); sqlTypes.Add(SqlDbType.Float); } if (result.PROTHROMBINE != null) { paramName.Add("@PROT"); values.Add(result.PROTHROMBINE.Value); sqlTypes.Add(SqlDbType.Float); } if (result.TCK != null) { paramName.Add("@TCK"); values.Add(result.TCK.Value); sqlTypes.Add(SqlDbType.Float); } if (result.TQ != null) { paramName.Add("@TQ"); values.Add(result.TQ.Value); sqlTypes.Add(SqlDbType.Float); } if (idKetQuaTuMayCLS == "-1")//thêm mới { string sql = string.Format(@"INSERT INTO dbo.KetQuaTuMayCLS( mabenhnhan ,TenBenhNhan ,ngaythuchien , maketqua ,loaimay , STT , mota ) VALUES( '{0}' ,N'{1}' ,{2} ,'{3}' ,'{4}' , '{5}' , N'{6}' )", " ", "", "GetDate()", idkqua, AppParams.stagoStart4Config.MaMayCLS, "", result.TypeName); if (ServerConnect.I.ExecSQL(sql) == false) { ServerConnect.I.RollBack(); return(false); } idKetQuaTuMayCLS = GetIdKetQuaTuMayCLS(idkqua); string sqlCT = ""; if (result.FIBRINOGENE != null) { sqlCT += string.Format(@" INSERT INTO dbo.KetQuaTuMayCLS_CT ( idKetQuaTuMayCLS , tenthongso , giatri, giatrichuoi) VALUES ( {0} , N'{1}' , {2},{3})", idKetQuaTuMayCLS, AppParams.stagoStart4Config.FIBRINOGENE, "@FIB", "NULL"); } if (result.INR != null) { sqlCT += Environment.NewLine + string.Format(@"INSERT INTO dbo.KetQuaTuMayCLS_CT ( idKetQuaTuMayCLS , tenthongso , giatri, giatrichuoi) VALUES ( {0} , N'{1}' ,{2},{3})", idKetQuaTuMayCLS, AppParams.stagoStart4Config.INR, "@INR", "NULL"); } if (result.PROTHROMBINE != null) { sqlCT += Environment.NewLine + string.Format(@"INSERT INTO dbo.KetQuaTuMayCLS_CT ( idKetQuaTuMayCLS , tenthongso , giatri, giatrichuoi) VALUES ( {0} , N'{1}' ,{2},{3} )", idKetQuaTuMayCLS, AppParams.stagoStart4Config.PROTHROMBINE, "@PROT", "NULL"); } if (result.TCK != null) { sqlCT += Environment.NewLine + string.Format(@"INSERT INTO dbo.KetQuaTuMayCLS_CT ( idKetQuaTuMayCLS , tenthongso , giatri, giatrichuoi) VALUES ( {0} , N'{1}' ,{2},{3} )", idKetQuaTuMayCLS, AppParams.stagoStart4Config.TCK, "@TCK", "NULL"); } if (result.TQ != null) { sqlCT += Environment.NewLine + string.Format(@"INSERT INTO dbo.KetQuaTuMayCLS_CT ( idKetQuaTuMayCLS , tenthongso , giatri, giatrichuoi) VALUES ( {0} , N'{1}' ,{2},{3} )", idKetQuaTuMayCLS, AppParams.stagoStart4Config.TQ, "@TQ", "NULL"); } if (ServerConnect.I.Exec(sqlCT, paramName.ToArray(), values.ToArray(), sqlTypes.ToArray()) <= 0) { ServerConnect.I.RollBack(); return(false); } } else { string sql = string.Format(@"UPDATE dbo.KetQuaTuMayCLS_CT SET giatri={0} WHERE idKetQuaTuMayCLS={1} AND tenthongso='{2}'", result.FIBRINOGENE == null ? "NULL" : "@FIB", idKetQuaTuMayCLS, AppParams.stagoStart4Config.FIBRINOGENE); sql += Environment.NewLine + string.Format(@"UPDATE dbo.KetQuaTuMayCLS_CT SET giatri={0} WHERE idKetQuaTuMayCLS={1} AND tenthongso='{2}'", result.INR == null ? "NULL" : "@INR", idKetQuaTuMayCLS, AppParams.stagoStart4Config.INR); sql += Environment.NewLine + string.Format(@"UPDATE dbo.KetQuaTuMayCLS_CT SET giatri={0} WHERE idKetQuaTuMayCLS={1} AND tenthongso='{2}'", result.PROTHROMBINE == null ? "NULL" : "@PROT", idKetQuaTuMayCLS, AppParams.stagoStart4Config.PROTHROMBINE); sql += Environment.NewLine + string.Format(@"UPDATE dbo.KetQuaTuMayCLS_CT SET giatri={0} WHERE idKetQuaTuMayCLS={1} AND tenthongso='{2}'", result.TCK == null ? "NULL" : "@TCK", idKetQuaTuMayCLS, AppParams.stagoStart4Config.TCK); sql += Environment.NewLine + string.Format(@"UPDATE dbo.KetQuaTuMayCLS_CT SET giatri={0} WHERE idKetQuaTuMayCLS={1} AND tenthongso='{2}'", result.TQ == null ? "NULL" : "@TQ", idKetQuaTuMayCLS, AppParams.stagoStart4Config.TQ); if (ServerConnect.I.Exec(sql, paramName.ToArray(), values.ToArray(), sqlTypes.ToArray()) <= 0) { ServerConnect.I.RollBack(); return(false); } } ServerConnect.I.Commit(); result = result.SecondResult; } return(true); } catch { return(false); } }