天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

794 lines
49 KiB

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.IO;
using System.Net;
using System.Text;
using QMAPP.FJC.BLL.Basic;
using QMAPP.FJC.BLL.FileCopy;
using QMAPP.FJC.BLL.Process;
using QMAPP.FJC.Entity.Basic;
using QMAPP.FJC.Entity.FileCopy;
using QMAPP.FJC.Entity.Operation;
using QMAPP.FJC.Entity.ProcessParameter;
namespace AutoFileCopyNet.Q5DFileAnalytic
{
/// <summary>
/// 海天复制解析文件
/// </summary>
public class Q5D
{
//获取所有未完成的金属支架
List<Product> listPro = new List<Product>();
public void Run()
{
try
{
//取海天设备编号
StringBuilder sb1 = new StringBuilder();
List<MachineInfo> listMachine = new MachineInfoBLL().GetAllList(new MachineInfo { EQUIPMENT_TYPE_CODE = ConfigurationManager.AppSettings.Get("DCS_ET_START_TYPE") });
foreach (MachineInfo dr in listMachine)
{
//复制文件
//CopyFile(dr);
//解析文件
ExpFile(dr);
//定时删除文件
if ("1".Equals(ConfigurationManager.AppSettings["NEEDDEL"].ToString()))
{
AutoFileCopy.AutoFileDelete(dr, ConfigurationManager.AppSettings["SHARESERVER_IP"].ToString()
, ConfigurationManager.AppSettings["DCSLocalDriverPath"].ToString()
, DirHandler.GetNewPrefix()
, ConstParam.ERROR_MESSAGE_HEAD
, ConfigurationManager.AppSettings["CONWAY"].ToString()
, ConfigurationManager.AppSettings["DELDAY"].ToString()
, ConfigurationManager.AppSettings["STARTTIME"].ToString()
, ConfigurationManager.AppSettings["ENDTIME"].ToString()
, ConfigurationManager.AppSettings["DELTIME"].ToString()
, ConfigurationManager.AppSettings["DCS_FILEPATH_BAK"].ToString() + dr.MACHINECODDE + "\\");
}
}
}
catch (Exception e)
{
LogFileAccess.WriteLogFile("海天数据文件解析失败" + e.Message + e.Source + "文件:" + "" + " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
}
/// <summary>
/// 复制文件
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
private bool CopyFile(MachineInfo info)
{
bool result = false;
try
{
String equipmentType = ConfigurationManager.AppSettings["DCS_ET_START_TYPE"].ToString();
String toDir = ConfigurationManager.AppSettings["DCS_FILEPATH"].ToString();//目标目录
String localDriverPath = ConfigurationManager.AppSettings["DCSLocalDriverPath"].ToString();//磁盘映射名
String fileRenamePrefix = DirHandler.GetNewPrefix();//随机数
String errorMessageHead = ConstParam.ERROR_MESSAGE_HEAD;//错误信息
string server_ip = ConfigurationManager.AppSettings["SHARESERVER_IP"].ToString();//服务IP
string conn_way = ConfigurationManager.AppSettings["CONWAY"].ToString();//打开连接方式
AutoFileCopy.AutoFileCopyFromEquipmentByType(info,equipmentType, server_ip, toDir, localDriverPath,conn_way);
LogFileAccess.WriteLogFile("海天数据文件复制" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
catch (Exception ex)
{
LogFileAccess.WriteLogFile("海天网络共享文件抓取失败" + ex.Message + ex.Source + "---" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
return result;
}
/// <summary>
/// 解析文件
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
private bool ExpFile(MachineInfo dr)
{
string fileNameForLog = string.Empty;
bool result = true;
string ekey = dr.PID.ToString();
//设备主键
string Equipmentinfokey = dr.PID.ToString();
var dn = Dns.GetHostName();
//当文件没有解析过或者解析时间在写入时间之前时开始解析此文件
List<FileCopyRecord> listFile = new FileCopyRecordBLL().GetAllList(new FileCopyRecord { EQUIPMENT_INFO_KEY = ekey, FILE_HOSTNAME = Dns.GetHostName(), IsOperation = true });
foreach (FileCopyRecord row in listFile)
{
try
{
string filepath = row.RECORD_EQUIPMENT_DIRECTORY.ToString();
string filename = row.RECORD_FILENAME.ToString();
fileNameForLog = filename;
//文件完整路径
filepath = filepath + filename;
//filepath = "e:\\abc\\11.CSV";
if (File.Exists(filepath))
{
//用流读文件UTF-8编码类型
System.IO.StreamReader b = new System.IO.StreamReader(filepath, System.Text.Encoding.GetEncoding("UTF-8"), true);
//s就是 取到的每行的值
string s = string.Empty;
//测量时间
string pdate = string.Empty;
StringBuilder sqlTitle = new StringBuilder();
//列头
string strtitle = "";
//数据
string insertdata = "";
//当数据没有读完的时候
while ((s = b.ReadLine()) != null)
{
//当每行的值不为空时
if (s.Trim() == string.Empty)
{
continue;
}
else
{
#region "读取时间"
if (s.Contains("测量开始") || s.Contains("Measure start"))
{
if (s.Contains("Measure start"))
{
pdate = s.Substring(14);
}
else
{
string[] titledate = s.Split('\\');
pdate = titledate[1].Substring(2, titledate[1].Length - 2);
}
DateTime dt;
DateTime.TryParse(pdate, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out dt);
pdate = dt.ToString("yyyy-MM-dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo);
}
#endregion
#region read column title
if (s.Contains("_.sv_Scrap") && !s.Contains("?"))
{
//列头
strtitle = GetExcelTitle(s);
}
#endregion
#region "read column data"
if ((s.Contains("8KY") && s.Length >= 50) || (!s.Contains("_.sv_Scrap") && s.Contains(";") && s.Length >= 50))
{
try
{
//如果没有列头,取模板的列头
if (string.IsNullOrEmpty(strtitle))
{
strtitle = GetTemplateTitle(dr.MACHINECODDE.ToString());
pdate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo); ;
}
insertdata = GetExcelValues(s);
if (insertdata.Equals("-1"))//不是b9产品
{
continue;
}
//数据为空则列头和数据列对应不上,跳出循环,读取下一个文件
if (string.IsNullOrEmpty(insertdata))
{
LogFileAccess.WriteLogFile("海天数据文件解析失败" + "文件:" + fileNameForLog + " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
break;
}
SaveImpor(strtitle, insertdata, pdate, Equipmentinfokey, dr);
}
catch (Exception er)
{
result = false;
b.Close();
LogFileAccess.WriteLogFile(er.Message + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
throw;
}
}
#endregion
}
}
b.Close();
if (result)
{
//读完整个文件后进行更新
updateFile(ekey, filename, Dns.GetHostName());
LogFileAccess.WriteLogFile("海天数据文件解析成功文件:" + fileNameForLog + " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
}
}
catch (Exception ex)
{
LogFileAccess.WriteLogFile("海天数据文件解析失败跳过----" + ex.Message + "----" + ex.Source + "----文件:" + fileNameForLog + "----" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
}
return result;
}
//列头和索引的集合
Dictionary<string, int> dir;
//列头长度
int titlecount = 0;
#region 获取要解析EXCEL的列头
/// <summary>
/// 获取要解析EXCEL的列头
/// </summary>
/// <param name="readlines"></param>
/// <returns></returns>
private string GetExcelTitle(string readlines)
{
dir = new Dictionary<string, int>();
//列头
StringBuilder sqlTitle = new StringBuilder();
string[] titleline = readlines.Split(';');
//列头长度
titlecount = titleline.Length;
for (int i = 1; i < titleline.Length; i++)
{
if (titleline[i] != "")
{
string[] col = titleline[i].Split('[');
switch (col[0].Trim())
{
#region 列对比
case "开模到底位置":
case "Mld.Op.End Pos.": sqlTitle.Append("MODESIZE,"); dir.Add("MODESIZE", i); break;
case "储料时间":
case "Chrg. Time": sqlTitle.Append("STORAGETIME,"); dir.Add("STORAGETIME", i); break;
case "储料结束位置":
case "Chrg.End Pos.": sqlTitle.Append("STORAGEENDPOINT,"); dir.Add("STORAGEENDPOINT", i); break;
case "转保压位置":
case "Hold Sw.": sqlTitle.Append("PRESSUREPOINT,"); dir.Add("PRESSUREPOINT", i); break;
case "注射终点":
case "Hold Sw.End": sqlTitle.Append("PRESSUREPOINTEND,"); dir.Add("PRESSUREPOINTEND", i); break;
case "转保压压力":
case "Pres.": sqlTitle.Append("PRESS,"); dir.Add("PRESS", i); break;
case "注射保压时间":
case "Hold T.": sqlTitle.Append("PRESSTIME,"); dir.Add("PRESSTIME", i); break;
case "最大注射压力":
case "Max.Inj.Pres.": sqlTitle.Append("MAXBAR,"); dir.Add("MAXBAR", i); break;
case "注射时间":
case "Inj. Time": sqlTitle.Append("INJECTIONTIME,"); dir.Add("INJECTIONTIME", i); break;
case "段1实际温度":
case "Act.Temp.Zone1": sqlTitle.Append("ACTUALTEMPERATURE1,"); dir.Add("ACTUALTEMPERATURE1", i); break;
case "段2实际温度":
case "Act.Temp.Zone2": sqlTitle.Append("ACTUALTEMPERATURE2,"); dir.Add("ACTUALTEMPERATURE2", i); break;
case "段3实际温度":
case "Act.Temp.Zone3": sqlTitle.Append("ACTUALTEMPERATURE3,"); dir.Add("ACTUALTEMPERATURE3", i); break;
case "段4实际温度":
case "Act.Temp.Zone4": sqlTitle.Append("ACTUALTEMPERATURE4,"); dir.Add("ACTUALTEMPERATURE4", i); break;
case "段5实际温度":
case "Act.Temp.Zone5": sqlTitle.Append("ACTUALTEMPERATURE5,"); dir.Add("ACTUALTEMPERATURE5", i); break;
case "段6实际温度":
case "Act.Temp.Zone6": sqlTitle.Append("ACTUALTEMPERATURE6,"); dir.Add("ACTUALTEMPERATURE6", i); break;
case "模数":
case "Shots": sqlTitle.Append("ANALOGDIGITAL,"); dir.Add("ANALOGDIGITAL", i); break;
case "合模时间":
case "Mold Cl.Time": sqlTitle.Append("ANALOGDIGITALDATE,"); dir.Add("ANALOGDIGITALDATE", i); break;
case "开模时间":
case "Mold Op.Time": sqlTitle.Append("MODEDATE,"); dir.Add("MODEDATE", i); break;
case "保压位置":
case "Hold End P.": sqlTitle.Append("HOLDINGPOSITION,"); dir.Add("HOLDINGPOSITION", i); break;
case "段7实际温度":
case "Act.Temp.Zone7": sqlTitle.Append("ACTUALTEMPERATURE7,"); dir.Add("ACTUALTEMPERATURE7", i); break;
case "段8实际温度":
case "Act.Temp.Zone8": sqlTitle.Append("ACTUALTEMPERATURE8,"); dir.Add("ACTUALTEMPERATURE8", i); break;
case "设置1区加热值":
case "Set Value Zone1": sqlTitle.Append("SETHOT1,"); dir.Add("SETHOT1", i); break;
case "设置2区加热值":
case "Set Value Zone2": sqlTitle.Append("SETHOT2,"); dir.Add("SETHOT2", i); break;
case "设置3区加热值":
case "Set Value Zone3": sqlTitle.Append("SETHOT3,"); dir.Add("SETHOT3", i); break;
case "设置4区加热值":
case "Set Value Zone4": sqlTitle.Append("SETHOT4,"); dir.Add("SETHOT4", i); break;
case "设置5区加热值":
case "Set Value Zone5": sqlTitle.Append("SETHOT5,"); dir.Add("SETHOT5", i); break;
case "实际锁模力":
case "Act. Clamp Force": sqlTitle.Append("ACTUALLOCK,"); dir.Add("ACTUALLOCK", i); break;
case "设置6区加热值":
case "Set Value Zone6": sqlTitle.Append("SETHOT6,"); dir.Add("SETHOT6", i); break;
case "循环时间":
case "Cyc.Time": sqlTitle.Append("CYCLETIME,"); dir.Add("CYCLETIME", i); break;
case "最大储压":
case "Max.Chrg.Pr": sqlTitle.Append("MAXPO,"); dir.Add("MAXPO", i); break;
case "最大注射速度":
case "Max.Inj.Speed": sqlTitle.Append("MAXSPEED,"); dir.Add("MAXSPEED", i); break;
case "最大转速.":
case "Max.Rpm.": sqlTitle.Append("MAXZSD,"); dir.Add("MAXZSD", i); break;
case "注射起点":
case "Inj.StartPos": sqlTitle.Append("INJECTIONSTARTE,"); dir.Add("INJECTIONSTARTE", i); break;
case "顶出位置":
case "Eject.Fwd.End": sqlTitle.Append("TOPSIZE,"); dir.Add("TOPSIZE", i); break;
case "顶退位置":
case "Eject.Bwd.End": sqlTitle.Append("TOPTUISIZE,"); dir.Add("TOPTUISIZE", i); break;
case "顶出时间":
case "Eje. Fwd Time": sqlTitle.Append("TOPOUTTIME,"); dir.Add("TOPOUTTIME", i); break;
case "顶退时间":
case "Eje. Bwd Time": sqlTitle.Append("TOPEXITTIME,"); dir.Add("TOPEXITTIME", i); break;
case "顶针位置":
case "Eject. Pos": sqlTitle.Append("TOPZHENSIZE,"); dir.Add("TOPZHENSIZE", i); break;
//后加参数
case "rWActHRSZone33": sqlTitle.Append("rWActHRSZone33,"); dir.Add("rWActHRSZone33", i); break;
case "rWActHRSZone34": sqlTitle.Append("rWActHRSZone34,"); dir.Add("rWActHRSZone34", i); break;
case "rWActHRSZone35": sqlTitle.Append("rWActHRSZone35,"); dir.Add("rWActHRSZone35", i); break;
case "rWActHRSZone36": sqlTitle.Append("rWActHRSZone36,"); dir.Add("rWActHRSZone36", i); break;
case "rWActHRSZone37": sqlTitle.Append("rWActHRSZone37,"); dir.Add("rWActHRSZone37", i); break;
case "rWActHRSZone38": sqlTitle.Append("rWActHRSZone38,"); dir.Add("rWActHRSZone38", i); break;
case "rWActHRSZone39": sqlTitle.Append("rWActHRSZone39,"); dir.Add("rWActHRSZone39", i); break;
case "rWActHRSZone40": sqlTitle.Append("rWActHRSZone40,"); dir.Add("rWActHRSZone40", i); break;
case "rWActHRSZone41": sqlTitle.Append("rWActHRSZone41,"); dir.Add("rWActHRSZone41", i); break;
case "rWActHRSZone42": sqlTitle.Append("rWActHRSZone42,"); dir.Add("rWActHRSZone42", i); break;
case "rWActHRSZone43": sqlTitle.Append("rWActHRSZone43,"); dir.Add("rWActHRSZone43", i); break;
case "rWActHRSZone44": sqlTitle.Append("rWActHRSZone44,"); dir.Add("rWActHRSZone44", i); break;
case "rWActHRSZone45": sqlTitle.Append("rWActHRSZone45,"); dir.Add("rWActHRSZone45", i); break;
case "rWActHRSZone46": sqlTitle.Append("rWActHRSZone46,"); dir.Add("rWActHRSZone46", i); break;
case "rWActHRSZone47": sqlTitle.Append("rWActHRSZone47,"); dir.Add("rWActHRSZone47", i); break;
case "rWActHRSZone48": sqlTitle.Append("rWActHRSZone48,"); dir.Add("rWActHRSZone48", i); break;
case "rWActUnit2Zone1": sqlTitle.Append("rWActUnit2Zone1,"); dir.Add("rWActUnit2Zone1", i); break;
case "rWActUnit2Zone2": sqlTitle.Append("rWActUnit2Zone2,"); dir.Add("rWActUnit2Zone2", i); break;
case "rWActUnit2Zone3": sqlTitle.Append("rWActUnit2Zone3,"); dir.Add("rWActUnit2Zone3", i); break;
case "rWActUnit2Zone4": sqlTitle.Append("rWActUnit2Zone4,"); dir.Add("rWActUnit2Zone4", i); break;
case "rWActUnit2Zone5": sqlTitle.Append("rWActUnit2Zone5,"); dir.Add("rWActUnit2Zone5", i); break;
case "rWActUnit2Zone6": sqlTitle.Append("rWActUnit2Zone6,"); dir.Add("rWActUnit2Zone6", i); break;
case "rWActUnit2Zone7": sqlTitle.Append("rWActUnit2Zone7,"); dir.Add("rWActUnit2Zone7", i); break;
case "rWActUnit2Zone8": sqlTitle.Append("rWActUnit2Zone8,"); dir.Add("rWActUnit2Zone8", i); break;
case "rWActUnit2Zone9": sqlTitle.Append("rWActUnit2Zone9,"); dir.Add("rWActUnit2Zone9", i); break;
case "rWActUnit2Zone10": sqlTitle.Append("rWActUnit2Zone10,"); dir.Add("rWActUnit2Zone10", i); break;
case "rWActUnit2Zone11": sqlTitle.Append("rWActUnit2Zone11,"); dir.Add("rWActUnit2Zone11", i); break;
case "rWActUnit2Zone12": sqlTitle.Append("rWActUnit2Zone12,"); dir.Add("rWActUnit2Zone12", i); break;
case "rWActUnit2Zone13": sqlTitle.Append("rWActUnit2Zone13,"); dir.Add("rWActUnit2Zone13", i); break;
case "rWActUnit2Zone14": sqlTitle.Append("rWActUnit2Zone14,"); dir.Add("rWActUnit2Zone14", i); break;
case "rWActUnit2Zone15": sqlTitle.Append("rWActUnit2Zone15,"); dir.Add("rWActUnit2Zone15", i); break;
case "rWActUnit2Zone16": sqlTitle.Append("rWActUnit2Zone16,"); dir.Add("rWActUnit2Zone16", i); break;
case "储料2时间": sqlTitle.Append("STORAGETIME2,"); dir.Add("STORAGETIME2", i); break;
case "储料2结束位置": sqlTitle.Append("STORAGEENDPOINT2,"); dir.Add("STORAGEENDPOINT2", i); break;
case "Charge2PeakPre": sqlTitle.Append("Charge2PeakPre,"); dir.Add("Charge2PeakPre", i); break;
case "Inject2StartPos": sqlTitle.Append("Inject2StartPos,"); dir.Add("Inject2StartPos", i); break;
case "ActDelayDecAfterPlast2": sqlTitle.Append("ActDelayDecAfterPlast2,"); dir.Add("ActDelayDecAfterPlast2", i); break;
case "ActDelayDecBefPlast2": sqlTitle.Append("ActDelayDecBefPlast2,"); dir.Add("ActDelayDecBefPlast2", i); break;
case "ActDelayTimeInject2": sqlTitle.Append("ActDelayTimeInject2,"); dir.Add("ActDelayTimeInject2", i); break;
case "Last InjectHold Time2": sqlTitle.Append("Last InjectHold Time2,"); dir.Add("Last InjectHold Time2", i); break;
case "保压位置2": sqlTitle.Append("HOLDINGPOSITION2,"); dir.Add("HOLDINGPOSITION2", i); break;
case "储料前射退时间2": sqlTitle.Append("STOREBTIME2,"); dir.Add("STOREBTIME2", i); break;
case "储料后射退时间2": sqlTitle.Append("STOREHTIME2,"); dir.Add("STOREHTIME2", i); break;
case "实际储料2延时": sqlTitle.Append("ACSTORETIME2,"); dir.Add("ACSTORETIME2", i); break;
case "实际座进2延时": sqlTitle.Append("ACZUOTIME2,"); dir.Add("ACZUOTIME2", i); break;
case "实际座进时间2": sqlTitle.Append("ACZUOSTIME2,"); dir.Add("ACZUOSTIME2", i); break;
case "最大注射压力2": sqlTitle.Append("MAXBAR2,"); dir.Add("MAXBAR2", i); break;
case "实际座退2延时": sqlTitle.Append("ACZUOTYTIME2,"); dir.Add("ACZUOTYTIME2", i); break;
case "实际座退时间2": sqlTitle.Append("ACZUOTTIME2,"); dir.Add("ACZUOTTIME2", i); break;
case "最大注射速度2": sqlTitle.Append("MaxSpeed2,"); dir.Add("MaxSpeed2", i); break;
case "最后储料2时间": sqlTitle.Append("ZCHULIAOTIME2,"); dir.Add("ZCHULIAOTIME2", i); break;
case "注射 2": sqlTitle.Append("INJECTION2,"); dir.Add("INJECTION2", i); break;
case "注射2时间": sqlTitle.Append("INJECTION2TIME,"); dir.Add("INJECTION2TIME", i); break;
case "最大转速2.": sqlTitle.Append("MAXZSD2,"); dir.Add("MAXZSD2", i); break;
case "注射保压时间2": sqlTitle.Append("PRESSURETIME2,"); dir.Add("PRESSURETIME2", i); break;
case "转保压位置2": sqlTitle.Append("PRESSUREPOINT2,"); dir.Add("PRESSUREPOINT2", i); break;
case "转保压压力2": sqlTitle.Append("TRANSFERBAR2,"); dir.Add("TRANSFERBAR2", i); break;
case "顶出2位置": sqlTitle.Append("TOPSIZE2,"); dir.Add("TOPSIZE2", i); break;
case "顶退2位置": sqlTitle.Append("TOPTUISIZE2,"); dir.Add("TOPTUISIZE2", i); break;
case "顶针2位置": sqlTitle.Append("TOPZHENSIZE2,"); dir.Add("TOPZHENSIZE2", i); break;
case "抱闸开时间": sqlTitle.Append("BRAKESTARTDATE,"); dir.Add("BRAKESTARTDATE", i); break;
case "抱闸关时间": sqlTitle.Append("BRAKEENDDATE,"); dir.Add("BRAKEENDDATE", i); break;
default: break;
#endregion
}
}
}
//列头去掉最后一个逗号
string strtitle = sqlTitle.ToString().Substring(0, sqlTitle.Length - 1);
return strtitle;
}
#endregion
#region 获取模板的列头
/// <summary>
/// 获取模板的列头
/// </summary>
/// <param name="ecode">设备code</param>
/// <returns></returns>
private string GetTemplateTitle(string ecode)
{
dir = new Dictionary<string, int>();
//列头
StringBuilder sqlTitle = new StringBuilder();
string temppath = ConfigurationManager.AppSettings.Get(ecode);
System.IO.StreamReader b = new System.IO.StreamReader(temppath, System.Text.Encoding.GetEncoding("UTF-8"), true);
string readlines = b.ReadToEnd();
string[] titleline = readlines.Split(';');
//列头长度
titlecount = titleline.Length;
for (int i = 1; i < titleline.Length; i++)
{
if (titleline[i] != "")
{
string[] col = titleline[i].Split('[');
switch (col[0].Trim())
{
#region 列对比
case "模数":
case "Shots": sqlTitle.Append("ANALOGDIGITAL,"); dir.Add("ANALOGDIGITAL", i); break;
case "合模时间":
case "Mold Cl.Time": sqlTitle.Append("ANALOGDIGITALDATE,"); dir.Add("ANALOGDIGITALDATE", i); break;
case "开模到底位置":
case "Mld.Op.End Pos.": sqlTitle.Append("MODESIZE,"); dir.Add("MODESIZE", i); break;
case "开模时间":
case "Mold Op.Time": sqlTitle.Append("MODEDATE,"); dir.Add("MODEDATE", i); break;
case "保压位置":
case "Hold End P.": sqlTitle.Append("HOLDINGPOSITION,"); dir.Add("HOLDINGPOSITION", i); break;
case "储料时间":
case "Chrg. Time": sqlTitle.Append("STORAGETIME,"); dir.Add("STORAGETIME", i); break;
case "最大注射压力":
case "Max.Inj.Pres.": sqlTitle.Append("MAXBAR,"); dir.Add("MAXBAR", i); break;
case "注射时间":
case "Inj. Time": sqlTitle.Append("INJECTIONTIME,"); dir.Add("INJECTIONTIME", i); break;
case "段1实际温度":
case "Act.Temp.Zone1": sqlTitle.Append("ACTUALTEMPERATURE1,"); dir.Add("ACTUALTEMPERATURE1", i); break;
case "段2实际温度":
case "Act.Temp.Zone2": sqlTitle.Append("ACTUALTEMPERATURE2,"); dir.Add("ACTUALTEMPERATURE2", i); break;
case "段3实际温度":
case "Act.Temp.Zone3": sqlTitle.Append("ACTUALTEMPERATURE3,"); dir.Add("ACTUALTEMPERATURE3", i); break;
case "段4实际温度":
case "Act.Temp.Zone4": sqlTitle.Append("ACTUALTEMPERATURE4,"); dir.Add("ACTUALTEMPERATURE4", i); break;
case "段5实际温度":
case "Act.Temp.Zone5": sqlTitle.Append("ACTUALTEMPERATURE5,"); dir.Add("ACTUALTEMPERATURE5", i); break;
case "段6实际温度":
case "Act.Temp.Zone6": sqlTitle.Append("ACTUALTEMPERATURE6,"); dir.Add("ACTUALTEMPERATURE6", i); break;
case "段7实际温度":
case "Act.Temp.Zone7": sqlTitle.Append("ACTUALTEMPERATURE7,"); dir.Add("ACTUALTEMPERATURE7", i); break;
case "段8实际温度":
case "Act.Temp.Zone8": sqlTitle.Append("ACTUALTEMPERATURE8,"); dir.Add("ACTUALTEMPERATURE8", i); break;
case "设置1区加热值":
case "Set Value Zone1": sqlTitle.Append("SETHOT1,"); dir.Add("SETHOT1", i); break;
case "设置2区加热值":
case "Set Value Zone2": sqlTitle.Append("SETHOT2,"); dir.Add("SETHOT2", i); break;
case "设置3区加热值":
case "Set Value Zone3": sqlTitle.Append("SETHOT3,"); dir.Add("SETHOT3", i); break;
case "设置4区加热值":
case "Set Value Zone4": sqlTitle.Append("SETHOT4,"); dir.Add("SETHOT4", i); break;
case "储料结束位置":
case "Chrg.End Pos.": sqlTitle.Append("STORAGEENDPOINT,"); dir.Add("STORAGEENDPOINT", i); break;
case "设置5区加热值":
case "Set Value Zone5": sqlTitle.Append("SETHOT5,"); dir.Add("SETHOT5", i); break;
case "实际锁模力":
case "Act. Clamp Force": sqlTitle.Append("ACTUALLOCK,"); dir.Add("ACTUALLOCK", i); break;
case "设置6区加热值":
case "Set Value Zone6": sqlTitle.Append("SETHOT6,"); dir.Add("SETHOT6", i); break;
case "循环时间":
case "Cyc.Time": sqlTitle.Append("CYCLETIME,"); dir.Add("CYCLETIME", i); break;
case "转保压位置":
case "Hold Sw.": sqlTitle.Append("PRESSUREPOINT,"); dir.Add("PRESSUREPOINT", i); break;
case "最大储压":
case "Max.Chrg.Pr": sqlTitle.Append("MAXPO,"); dir.Add("MAXPO", i); break;
case "最大注射速度":
case "Max.Inj.Speed": sqlTitle.Append("MAXSPEED,"); dir.Add("MAXSPEED", i); break;
case "最大转速.":
case "Max.Rpm.": sqlTitle.Append("MAXZSD,"); dir.Add("MAXZSD", i); break;
case "注射起点":
case "Inj.StartPos": sqlTitle.Append("INJECTIONSTARTE,"); dir.Add("INJECTIONSTARTE", i); break;
case "注射保压时间":
case "Inj&Hold T.": sqlTitle.Append("PRESSURETIME,"); dir.Add("PRESSURETIME", i); break;
case "注射终点":
case "Inj.Min.Pos.": sqlTitle.Append("INJECTIONPOINT,"); dir.Add("INJECTIONPOINT", i); break;
case "转保压压力":
case "Switch Pres.": sqlTitle.Append("TRANSFERBAR,"); dir.Add("TRANSFERBAR", i); break;
case "顶出位置":
case "Eject.Fwd.End": sqlTitle.Append("TOPSIZE,"); dir.Add("TOPSIZE", i); break;
case "顶退位置":
case "Eject.Bwd.End": sqlTitle.Append("TOPTUISIZE,"); dir.Add("TOPTUISIZE", i); break;
case "顶出时间":
case "Eje. Fwd Time": sqlTitle.Append("TOPOUTTIME,"); dir.Add("TOPOUTTIME", i); break;
case "顶退时间":
case "Eje. Bwd Time": sqlTitle.Append("TOPEXITTIME,"); dir.Add("TOPEXITTIME", i); break;
case "顶针位置":
case "Eject. Pos": sqlTitle.Append("TOPZHENSIZE,"); dir.Add("TOPZHENSIZE", i); break;
//后加参数
case "rWActHRSZone33": sqlTitle.Append("rWActHRSZone33,"); dir.Add("rWActHRSZone33", i); break;
case "rWActHRSZone34": sqlTitle.Append("rWActHRSZone34,"); dir.Add("rWActHRSZone34", i); break;
case "rWActHRSZone35": sqlTitle.Append("rWActHRSZone35,"); dir.Add("rWActHRSZone35", i); break;
case "rWActHRSZone36": sqlTitle.Append("rWActHRSZone36,"); dir.Add("rWActHRSZone36", i); break;
case "rWActHRSZone37": sqlTitle.Append("rWActHRSZone37,"); dir.Add("rWActHRSZone37", i); break;
case "rWActHRSZone38": sqlTitle.Append("rWActHRSZone38,"); dir.Add("rWActHRSZone38", i); break;
case "rWActHRSZone39": sqlTitle.Append("rWActHRSZone39,"); dir.Add("rWActHRSZone39", i); break;
case "rWActHRSZone40": sqlTitle.Append("rWActHRSZone40,"); dir.Add("rWActHRSZone40", i); break;
case "rWActHRSZone41": sqlTitle.Append("rWActHRSZone41,"); dir.Add("rWActHRSZone41", i); break;
case "rWActHRSZone42": sqlTitle.Append("rWActHRSZone42,"); dir.Add("rWActHRSZone42", i); break;
case "rWActHRSZone43": sqlTitle.Append("rWActHRSZone43,"); dir.Add("rWActHRSZone43", i); break;
case "rWActHRSZone44": sqlTitle.Append("rWActHRSZone44,"); dir.Add("rWActHRSZone44", i); break;
case "rWActHRSZone45": sqlTitle.Append("rWActHRSZone45,"); dir.Add("rWActHRSZone45", i); break;
case "rWActHRSZone46": sqlTitle.Append("rWActHRSZone46,"); dir.Add("rWActHRSZone46", i); break;
case "rWActHRSZone47": sqlTitle.Append("rWActHRSZone47,"); dir.Add("rWActHRSZone47", i); break;
case "rWActHRSZone48": sqlTitle.Append("rWActHRSZone48,"); dir.Add("rWActHRSZone48", i); break;
case "rWActUnit2Zone1": sqlTitle.Append("rWActUnit2Zone1,"); dir.Add("rWActUnit2Zone1", i); break;
case "rWActUnit2Zone2": sqlTitle.Append("rWActUnit2Zone2,"); dir.Add("rWActUnit2Zone2", i); break;
case "rWActUnit2Zone3": sqlTitle.Append("rWActUnit2Zone3,"); dir.Add("rWActUnit2Zone3", i); break;
case "rWActUnit2Zone4": sqlTitle.Append("rWActUnit2Zone4,"); dir.Add("rWActUnit2Zone4", i); break;
case "rWActUnit2Zone5": sqlTitle.Append("rWActUnit2Zone5,"); dir.Add("rWActUnit2Zone5", i); break;
case "rWActUnit2Zone6": sqlTitle.Append("rWActUnit2Zone6,"); dir.Add("rWActUnit2Zone6", i); break;
case "rWActUnit2Zone7": sqlTitle.Append("rWActUnit2Zone7,"); dir.Add("rWActUnit2Zone7", i); break;
case "rWActUnit2Zone8": sqlTitle.Append("rWActUnit2Zone8,"); dir.Add("rWActUnit2Zone8", i); break;
case "rWActUnit2Zone9": sqlTitle.Append("rWActUnit2Zone9,"); dir.Add("rWActUnit2Zone9", i); break;
case "rWActUnit2Zone10": sqlTitle.Append("rWActUnit2Zone10,"); dir.Add("rWActUnit2Zone10", i); break;
case "rWActUnit2Zone11": sqlTitle.Append("rWActUnit2Zone11,"); dir.Add("rWActUnit2Zone11", i); break;
case "rWActUnit2Zone12": sqlTitle.Append("rWActUnit2Zone12,"); dir.Add("rWActUnit2Zone12", i); break;
case "rWActUnit2Zone13": sqlTitle.Append("rWActUnit2Zone13,"); dir.Add("rWActUnit2Zone13", i); break;
case "rWActUnit2Zone14": sqlTitle.Append("rWActUnit2Zone14,"); dir.Add("rWActUnit2Zone14", i); break;
case "rWActUnit2Zone15": sqlTitle.Append("rWActUnit2Zone15,"); dir.Add("rWActUnit2Zone15", i); break;
case "rWActUnit2Zone16": sqlTitle.Append("rWActUnit2Zone16,"); dir.Add("rWActUnit2Zone16", i); break;
case "储料2时间": sqlTitle.Append("STORAGETIME2,"); dir.Add("STORAGETIME2", i); break;
case "储料2结束位置": sqlTitle.Append("STORAGEENDPOINT2,"); dir.Add("STORAGEENDPOINT2", i); break;
case "Charge2PeakPre": sqlTitle.Append("Charge2PeakPre,"); dir.Add("Charge2PeakPre", i); break;
case "Inject2StartPos": sqlTitle.Append("Inject2StartPos,"); dir.Add("Inject2StartPos", i); break;
case "ActDelayDecAfterPlast2": sqlTitle.Append("ActDelayDecAfterPlast2,"); dir.Add("ActDelayDecAfterPlast2", i); break;
case "ActDelayDecBefPlast2": sqlTitle.Append("ActDelayDecBefPlast2,"); dir.Add("ActDelayDecBefPlast2", i); break;
case "ActDelayTimeInject2": sqlTitle.Append("ActDelayTimeInject2,"); dir.Add("ActDelayTimeInject2", i); break;
case "Last InjectHold Time2": sqlTitle.Append("Last InjectHold Time2,"); dir.Add("Last InjectHold Time2", i); break;
case "保压位置2": sqlTitle.Append("HOLDINGPOSITION2,"); dir.Add("HOLDINGPOSITION2", i); break;
case "储料前射退时间2": sqlTitle.Append("STOREBTIME2,"); dir.Add("STOREBTIME2", i); break;
case "储料后射退时间2": sqlTitle.Append("STOREHTIME2,"); dir.Add("STOREHTIME2", i); break;
case "实际储料2延时": sqlTitle.Append("ACSTORETIME2,"); dir.Add("ACSTORETIME2", i); break;
case "实际座进2延时": sqlTitle.Append("ACZUOTIME2,"); dir.Add("ACZUOTIME2", i); break;
case "实际座进时间2": sqlTitle.Append("ACZUOSTIME2,"); dir.Add("ACZUOSTIME2", i); break;
case "最大注射压力2": sqlTitle.Append("MAXBAR2,"); dir.Add("MAXBAR2", i); break;
case "实际座退2延时": sqlTitle.Append("ACZUOTYTIME2,"); dir.Add("ACZUOTYTIME2", i); break;
case "实际座退时间2": sqlTitle.Append("ACZUOTTIME2,"); dir.Add("ACZUOTTIME2", i); break;
case "最大注射速度2": sqlTitle.Append("MaxSpeed2,"); dir.Add("MaxSpeed2", i); break;
case "最后储料2时间": sqlTitle.Append("ZCHULIAOTIME2,"); dir.Add("ZCHULIAOTIME2", i); break;
case "注射 2": sqlTitle.Append("INJECTION2,"); dir.Add("INJECTION2", i); break;
case "注射2时间": sqlTitle.Append("INJECTION2TIME,"); dir.Add("INJECTION2TIME", i); break;
case "最大转速2.": sqlTitle.Append("MAXZSD2,"); dir.Add("MAXZSD2", i); break;
case "注射保压时间2": sqlTitle.Append("PRESSURETIME2,"); dir.Add("PRESSURETIME2", i); break;
case "转保压位置2": sqlTitle.Append("PRESSUREPOINT2,"); dir.Add("PRESSUREPOINT2", i); break;
case "转保压压力2": sqlTitle.Append("TRANSFERBAR2,"); dir.Add("TRANSFERBAR2", i); break;
case "顶出2位置": sqlTitle.Append("TOPSIZE2,"); dir.Add("TOPSIZE2", i); break;
case "顶退2位置": sqlTitle.Append("TOPTUISIZE2,"); dir.Add("TOPTUISIZE2", i); break;
case "顶针2位置": sqlTitle.Append("TOPZHENSIZE2,"); dir.Add("TOPZHENSIZE2", i); break;
default: break;
#endregion
}
}
}
//列头去掉最后一个逗号
string strtitle = sqlTitle.ToString().Substring(0, sqlTitle.Length - 1);
return strtitle;
}
#endregion
string barcode = "";
#region 获取要解析EXCEL的每列的值
/// <summary>
/// 获取EXCEL要解析值
/// </summary>
/// <param name="readlines"></param>
/// <returns></returns>
private string GetExcelValues(string readlines)
{
string[] strdata = readlines.Replace(",", ".").Split(';');//同时将逗号转换为小数点
//当解析的列头+1和列的值-2数量不一致时。直接返回null.
if (dir.Count != strdata.Length - 3)
{
return "";
}
StringBuilder sqlData = new StringBuilder();
foreach (KeyValuePair<string, int> a in dir)
{
sqlData.Append("" + strdata[a.Value] + ",");
}
barcode = strdata[strdata.Length - 2];
sqlData.Append("" + barcode + "");
//判断该条码是否符合B9
string proType = "";
if (barcode.Length > 3)
{
proType = new InjectionProcess().GetProductType(barcode);
}
if (string.IsNullOrEmpty(proType))
{
return "-1";
}
return sqlData.ToString();
}
#endregion
/// <summary>
/// 保存解析后的数据。
/// </summary>
/// <param name="strtitle"></param>
/// <param name="insertdata"></param>
private void SaveImpor(string strtitle, string insertdata, string pdate, string Equipmentinfokey,MachineInfo machine)
{
bool insertflg = true;
//判断参数表是否存在
insertflg = new InjectionProcess().CheckParameter(barcode, pdate);
if (insertflg == false)
{
//插入数据库
InJectionParameter injectPara = new InJectionParameter();
injectPara.PRODUCTCODE = barcode;
string[] strtitles = strtitle.Split(',');
string[] insertdatas = insertdata.Split(',');
int index = -1;
//index = Array.IndexOf(strtitles, "MODESIZE");
//if (index >=0)
// injectPara.MODESIZE = insertdatas[index];
//index = Array.IndexOf(strtitles, "STORAGETIME");
//if (index >= 0)
// injectPara.STORAGETIME = insertdatas[index];
//index = Array.IndexOf(strtitles, "STORAGEENDPOINT");
//if (index >= 0)
// injectPara.STORAGEENDPOINT = insertdatas[index];
//index = Array.IndexOf(strtitles, "PRESSUREPOINT");
//if (index >= 0)
// injectPara.PRESSUREPOINT = insertdatas[index];
//index = Array.IndexOf(strtitles, "PRESSUREPOINTEND");
//if (index >= 0)
// injectPara.PRESSUREPOINTEND = insertdatas[index];
//index = Array.IndexOf(strtitles, "PRESS");
//if (index >= 0)
// injectPara.PRESS = insertdatas[index];
//index = Array.IndexOf(strtitles, "PRESSTIME");
//if (index >= 0)
// injectPara.PRESSTIME = insertdatas[index];
//index = Array.IndexOf(strtitles, "MAXBAR");
//if (index >= 0)
// injectPara.MAXBAR = insertdatas[index];
//index = Array.IndexOf(strtitles, "INJECTIONTIME");
//if (index >= 0)
// injectPara.INJECTIONTIME = insertdatas[index];
//index = Array.IndexOf(strtitles, "ACTUALTEMPERATURE1");
//if (index >= 0)
// injectPara.ACTUALTEMPERATURE1 = insertdatas[index];
//index = Array.IndexOf(strtitles, "ACTUALTEMPERATURE2");
//if (index >= 0)
// injectPara.ACTUALTEMPERATURE2 = insertdatas[index];
//index = Array.IndexOf(strtitles, "ACTUALTEMPERATURE3");
//if (index >= 0)
// injectPara.ACTUALTEMPERATURE3 = insertdatas[index];
//index = Array.IndexOf(strtitles, "ACTUALTEMPERATURE4");
//if (index >= 0)
// injectPara.ACTUALTEMPERATURE4 = insertdatas[index];
//index = Array.IndexOf(strtitles, "ACTUALTEMPERATURE5");
//if (index >= 0)
// injectPara.ACTUALTEMPERATURE5 = insertdatas[index];
//index = Array.IndexOf(strtitles, "ACTUALTEMPERATURE6");
//if (index >= 0)
// injectPara.ACTUALTEMPERATURE6 = insertdatas[index];
injectPara.OPERATEDATE = Convert.ToDateTime(pdate, DateTimeFormatInfo.InvariantInfo);
injectPara.MACHINECODDE = machine.MACHINECODDE;
injectPara.MACHINENAME = machine.MACHINENAME;
try
{
new InjectionProcess().ProcessAuto(machine, injectPara);
}
catch (Exception ee)
{
LogFileAccess.WriteLogFile("海天数据文件解析保存失败" + ee.Message + ee.Source + " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
throw;
}
}
}
private void updatecopyfile(string fromDir, string EQUIPMENT_INFO_KEY, string EQUIPMENT_Code, string EQUIPMENT_Type_Code, string toDir)
{
FileCopyRecordBLL bll = new FileCopyRecordBLL();
FileCopyRecord record = new FileCopyRecord();
if (!System.IO.Directory.Exists(fromDir))
{
return;
}
if (toDir[toDir.Length - 1] != System.IO.Path.DirectorySeparatorChar)
{
toDir += System.IO.Path.DirectorySeparatorChar;
}
if (!System.IO.Directory.Exists(toDir))
{
System.IO.Directory.CreateDirectory(toDir);
}
DirectoryInfo Dir = new DirectoryInfo(fromDir);
try
{
foreach (FileInfo f in Dir.GetFiles()) //查找文件
{
string hostname = Dns.GetHostName();
string lastwritetime = f.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo);
//查询该文件是否复制过,如果没有复制过,则开始复制该文件
List<FileCopyRecord> list = bll.GetAllList(new FileCopyRecord { RECORD_FILENAME = f.Name, EQUIPMENT_INFO_KEY = EQUIPMENT_INFO_KEY, FILE_HOSTNAME = hostname });
//判断数据库中是否有记录,如果没有则插入数据
string templastwrit = "";
if (list.Count > 0)
{
templastwrit = list[0].FILE_LASTWRITETIME.ToString();
}
if (list.Count <= 0)
{
File.Copy(f.FullName, toDir + f.Name, true);
#region "把文件复制记录写入数据库"
record.RECORD_KEY = Guid.NewGuid().ToString();
record.RECORD_EQUIPMENT_CODE = EQUIPMENT_Code;
record.RECORD_EQUIPMENT_TYPE_CODE = EQUIPMENT_Type_Code;
record.RECORD_EQUIPMENT_DIRECTORY = toDir;
record.RECORD_KEYWORDS = EQUIPMENT_Code;
record.RECORD_COPY_DATETIME = DateTime.Now;
record.RECORD_READFLAG = "0";
record.RECORD_FILENAME = f.Name;
record.EQUIPMENT_INFO_KEY = EQUIPMENT_INFO_KEY;
//record.FILE_LASTWRITETIME = lastwritetime;
record.FILE_HOSTNAME = hostname;
bll.Insert(record);
#endregion
}
else if (lastwritetime != templastwrit)
{
File.Copy(f.FullName, toDir + f.Name, true);//复制后覆盖原文件
#region "把修改数据库中文件复制时间"
record = list[0];
record.RECORD_COPY_DATETIME = DateTime.Now;
//record.FILE_LASTWRITETIME = lastwritetime;
record.RECORD_FILENAME = f.Name;
record.FILE_HOSTNAME = Dns.GetHostName();
bll.Update(record);
#endregion
}
else if (!File.Exists(@toDir + f.Name))
{
File.Copy(f.FullName, toDir + f.Name, true);
}
}
}
catch (Exception e)
{
LogFileAccess.WriteLogFile("海天数据复制文件失败" + e.Message + e.Source + " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
}
//更新
private void updateFile(string ekey, string filename, string file_hostname)
{
string strdatatime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo);
try
{
new FileCopyRecordBLL().UpdateForTime(ekey, filename, file_hostname, strdatatime);
}
catch (Exception ee)
{
LogFileAccess.WriteLogFile("海天数据文件解析更新失败" + ee.Message + ee.Source + " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
throw;
}
}
}
}