using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Aitex.Core.RT.DBCore;
using Aitex.Core.RT.Event;
using Aitex.Core.RT.Log;
using Aitex.Sorter.Common;
using MECF.Framework.Common.CommonData;
namespace Aitex.Sorter.RT.Module.DBRecorder
{
/*
*/
public class CarrierDataRecorder
{
///
///
///
/// 唯一
/// 位置
public static void Loaded(string guid, string station)
{
string sql = string.Format("INSERT INTO \"carrier_data\"(\"guid\", \"load_time\", \"station\" )VALUES ('{0}', '{1}', '{2}');",
guid,
DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
station );
DB.Insert(sql);
}
public static void UpdateCarrierId(string guid, string rfid)
{
string sql = string.Format(
"UPDATE \"carrier_data\" SET \"rfid\"='{0}' WHERE \"guid\"='{1}';",
rfid, guid);
DB.Insert(sql);
}
public static void UpdateLotId(string guid, string lotId)
{
string sql = string.Format(
"UPDATE \"carrier_data\" SET \"lot_id\"='{0}' WHERE \"guid\"='{1}';",
lotId, guid);
DB.Insert(sql);
}
public static void UpdateProductCategory(string guid, string productCategory)
{
string sql = string.Format(
"UPDATE \"carrier_data\" SET \"product_category\"='{0}' WHERE \"guid\"='{1}';",
productCategory, guid);
DB.Insert(sql);
}
public static void Unloaded(string guid)
{
string sql = string.Format(
"UPDATE \"carrier_data\" SET \"unload_time\"='{0}' WHERE \"guid\"='{1}';",
DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
guid);
DB.Insert(sql);
}
public static List QueryDBCarrier(string sql)
{
List result = new List();
try
{
DataSet ds = DB.ExecuteDataset(sql);
if (ds == null)
return result;
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
HistoryCarrierData ev = new HistoryCarrierData();
ev.Guid = ds.Tables[0].Rows[i]["guid"].ToString();
ev.Rfid = ds.Tables[0].Rows[i]["rfid"].ToString();
ev.LotId = ds.Tables[0].Rows[i]["lot_id"].ToString();
ev.ProductCategory = ds.Tables[0].Rows[i]["product_category"].ToString();
ev.Station = ds.Tables[0].Rows[i]["station"].ToString();
if (!ds.Tables[0].Rows[i]["load_time"].Equals(DBNull.Value))
ev.LoadTime = ((DateTime)ds.Tables[0].Rows[i]["load_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
if (!ds.Tables[0].Rows[i]["unload_time"].Equals(DBNull.Value))
ev.UnloadTime = ((DateTime)ds.Tables[0].Rows[i]["unload_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
result.Add(ev);
}
}
catch (Exception ex)
{
LOG.Write(ex);
}
return result;
}
}
}