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.
149 lines
5.5 KiB
149 lines
5.5 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.ServiceProcess;
|
|
using System.Text;
|
|
using System.Timers;
|
|
using System.IO;
|
|
using QMAPP.FJC.Entity.CellCycle;
|
|
using QMAPP.FJC.BLL.CellCycle;
|
|
using QMAPP.FJC.Entity.Operation;
|
|
using QMAPP.FJC.BLL.Operation;
|
|
using QMAPP.FJC.Entity.Basic;
|
|
using QMAPP.FJC.BLL.Basic;
|
|
|
|
namespace TimerService
|
|
{
|
|
public partial class Service1 : ServiceBase
|
|
{
|
|
Timer timer;
|
|
public Service1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
protected override void OnStart(string[] args)
|
|
{
|
|
timer = new Timer(60000);
|
|
timer.Elapsed += new ElapsedEventHandler(Timer_Elapsed);
|
|
timer.Start();
|
|
WriteLog("服务启动");
|
|
}
|
|
|
|
protected override void OnStop()
|
|
{
|
|
timer.Stop();
|
|
timer.Dispose();
|
|
WriteLog("服务停止");
|
|
}
|
|
|
|
protected void Timer_Elapsed(object sender, ElapsedEventArgs e)
|
|
{
|
|
DateTime NowTime = DateTime.Now;
|
|
//当前时间减少1分钟,看时期是否为明天
|
|
DateTime NewTime = NowTime.AddMinutes(-1);
|
|
|
|
//不等于意味着日期发生变化,即为昨天
|
|
if (NowTime.ToString("yyyyMMdd") != (NewTime).ToString("yyyyMMdd"))
|
|
{
|
|
WriteLog("服务执行中");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
protected void WriteLog(string str)
|
|
{
|
|
string filePath = AppDomain.CurrentDomain.BaseDirectory + "Log.txt";
|
|
StreamWriter sw = null;
|
|
if (!File.Exists(filePath))
|
|
{
|
|
sw = File.CreateText(filePath);
|
|
}
|
|
else
|
|
{
|
|
sw = File.AppendText(filePath);
|
|
}
|
|
sw.Write(str + DateTime.Now.ToString() + Environment.NewLine);
|
|
|
|
sw.Close();
|
|
|
|
CellCycleTime cellcycletime = new CellCycleTime();
|
|
CellCycleTimeSetBLL cellCycleBll = new CellCycleTimeSetBLL();
|
|
List<CellCycleTimeSet> cellCycleList = cellCycleBll.GetAllList();
|
|
if (cellCycleList != null)
|
|
{
|
|
|
|
foreach (var item in cellCycleList)
|
|
{
|
|
List<MainOperation> mainlist = new List<MainOperation>();
|
|
MainOperation maininfo = new MainOperation();
|
|
|
|
List<MachineInfo> machineList = new List<MachineInfo>();
|
|
MachineInfo machine = new MachineInfo();
|
|
machine.MACHINECODDE = item.MACHINECODDE;
|
|
|
|
maininfo.MACHINECODDE = item.MACHINECODDE;
|
|
maininfo.OPERATEDDATE = DateTime.Now.AddDays(-1);
|
|
|
|
MainOperationBLL mainoperation = new MainOperationBLL();
|
|
MachineInfoBLL machineBll = new MachineInfoBLL();
|
|
//获取到数据信息(code+date)
|
|
mainlist = mainoperation.GetListUsedByCell(maininfo);
|
|
machineList = machineBll.GetAllList(machine);
|
|
foreach (var list in machineList)
|
|
{
|
|
cellcycletime.WORKCELL_CODE = list.WORKCELL_CODE;
|
|
cellcycletime.WORKCENTER_CODE = list.WORKCENTER_CODE;
|
|
}
|
|
var timeAdd = 0;
|
|
if (mainlist.Count > 1)
|
|
{
|
|
int[] cycleTime = new int[mainlist.Count - 1];
|
|
int count = 0;
|
|
for (int i = 1; i <= mainlist.Count - 1; i++)
|
|
{
|
|
DateTime dtone = Convert.ToDateTime(mainlist[i - 1].OPERATEDDATE);
|
|
DateTime dttwo = Convert.ToDateTime(mainlist[i].OPERATEDDATE);
|
|
TimeSpan ts = dttwo - dtone;
|
|
string[] min = ts.TotalSeconds.ToString().Split('.');
|
|
int time = Convert.ToInt32(min[0]);
|
|
//时间大于设定时间一半且小于三倍设定时间时满足条件,记次数
|
|
if (time > item.MAXVALUE / 2 && time <= item.MAXVALUE * 3)
|
|
{
|
|
cycleTime[i - 1] = time;
|
|
count = ++count;
|
|
}
|
|
//不满足时,设置时间为0
|
|
else {
|
|
cycleTime[i - 1] = 0;
|
|
}
|
|
timeAdd += cycleTime[i - 1];
|
|
}
|
|
cellcycletime.PID = Guid.NewGuid().ToString();
|
|
cellcycletime.MACHINECODDE = maininfo.MACHINECODDE;
|
|
cellcycletime.CYCLETIME = timeAdd + item.MAXVALUE;
|
|
cellcycletime.CYCLECOUNT = count;
|
|
cellcycletime.STATIS_DATE = DateTime.ParseExact(maininfo.OPERATEDDATE.ToString("yyyyMMdd"), "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
|
|
cellcycletime.CREATEDATE = DateTime.Now;
|
|
cellcycletime.UPDATEDATE = cellcycletime.CREATEDATE;
|
|
if (cellcycletime.CYCLECOUNT!=0)
|
|
{
|
|
cellCycleBll.Insert(cellcycletime);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|