tijian_jichuang/Code/SOH.JianYan.DEC_BC2900/BC2900.cs
2025-02-20 11:54:48 +08:00

233 lines
8.2 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SOH.JianYan.DEC_BC2900
{
public partial class BC2900 : SOH.JianYan.YiQi.Base.baseMain
{
string _yqbm = "";
public BC2900()
{
InitializeComponent();
}
private void BC2900_Load(object sender, EventArgs e)
{
System.Configuration.Configuration conf = System.Configuration.ConfigurationManager.OpenExeConfiguration(Application.StartupPath + "\\local.ext");
if (conf.AppSettings.Settings.AllKeys.Contains("yqbm"))
{
_yqbm = conf.AppSettings.Settings["yqbm"].Value;
}
if(conf.AppSettings.Settings.AllKeys.Contains("XYBC2900"))
{
conf.AppSettings.Settings["XYBC2900"].Value = "1";
}
else
{
conf.AppSettings.Settings.Add("XYBC2900", "1");
}
conf.Save();
if (System.IO.File.Exists(Application.StartupPath + "\\SOH.OnLine.exe"))
{
System.Diagnostics.Process p = System.Diagnostics.Process.Start(Application.StartupPath + "\\SOH.OnLine.exe");
Program.ps = p;
}
}
protected override void decoder()
{
base.decoder();
string decodefile = Application.StartupPath + "\\raw\\data.txt";
if (System.IO.File.Exists(decodefile))
{
int a = 0;
string data = "";
aa:
try
{
FileStream fs = new FileStream(decodefile, FileMode.Open, FileAccess.Read, FileShare.None);
StreamReader sr = new StreamReader(fs);
data = sr.ReadToEnd();
sr.Close();
sr.Dispose();
}
catch
{
a++;
if (a > 11)
goto aa;
}
if(data.EndsWith("\u0004\u000a\u000f"))
{
File.Delete(decodefile);
}
else
{
return;
}
while (data.Length > 0)
{
int pos = 0;
sjks:
pos = data.IndexOf("\u000a\u000f",pos+2);
if (pos == -1)
{
break;
}
string decdata = "";
if ((data.Length == pos + 2))
{
decdata = data;
data = "";
goto jm;
}
string ks = data.Substring(pos + 2, 2);
if (ks == "\u0010\u0005")
{
decdata = data.Substring(0, pos + 2);
data = data.Remove(0, pos + 2);
goto jm;
}
else
{
goto sjks;
}
jm:
string sampleno = "";
DateTime sampledate = new DateTime();
if (!decdata.StartsWith("\u0010\u0005"))
{
break;
}
decdata = decdata.Remove(0, 2);
pos = decdata.IndexOf("\u0003");
if (pos == -1)
return;
string MD = decdata.Substring(0, pos);
if (MD == "CTR")
{
decdata = decdata.Remove(0, pos+1);
}
else
{
continue;
}
while (decdata.Length > 0)
{
string item = "";
int posFD = decdata.IndexOf("\u000c");
if(posFD==-1)
{ break; }
else
{
item = decdata.Substring(0, posFD);
decdata = decdata.Remove(0, posFD + 1);
}
if(item== "SampleInfo")
{
pos = decdata.IndexOf("\u0004");
item = decdata.Substring(0, pos);
decdata = decdata.Remove(0, pos + 1);
string[] filds = item.Split('\u0008');
foreach(string fild in filds)
{
string[] fildv = fild.Split('\u0016');
if(fildv.Length!=2)
{
continue;
}
else
{
if(fildv[0]== "SampleID")
{
sampleno = fildv[1];
continue;
}
if (fildv[0] == "TestTime")
{
sampledate = DateTime.Parse(fildv[1]);
sampledate = sampledate.Date;
continue;
}
}
}
continue;
}
if(item== "AlarmFlag"||item== "SepLine")
{
decdata = decdata.Remove(0, decdata.IndexOf('\u0004') + 1);
continue;
}
if(item== "WBCHisto"|| item == "RBCHisto" || item == "PLTHisto")
{
pos = decdata.IndexOf("\u000a\u000f\u0010\u0005");
if (pos == -1)
break;
else
{
decdata = decdata.Remove(0, pos + 2);
continue;
}
}
string tdh = item;
pos = decdata.IndexOf("\u0004");
item = decdata.Substring(0, pos);
decdata = decdata.Remove(0, pos + 1);
string[] vfilds = item.Split('\u0008');
string jg = "";
foreach (string fild in vfilds)
{
string[] vfildv = fild.Split('\u0016');
if (vfildv.Length != 2)
{
continue;
}
else
{
if (vfildv[0] == "Val")
{
jg = vfildv[1];
continue;
}
}
}
if(YiQi.Base.Lis_result.canmodify(_yqbm,sampledate,sampleno))
{
YiQi.Base.Lis_result.addresult(sampledate, _yqbm, sampleno, tdh, jg);
}
continue;
}
YiQi.Base.Lis_result.calcsample(_yqbm, sampledate.Date, sampleno);
}
}
}
private void BC2900_FormClosed(object sender, FormClosedEventArgs e)
{
if(!Program.ps.HasExited)
{
Program.ps.Kill();
}
}
}
}