123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- 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;
- namespace Aitex.Sorter.RT.Module.DBRecorder
- {
- /*
- */
- public class CarrierDataRecorder
- {
- /// <summary>
- ///
- /// </summary>
- /// <param name="guid">唯一</param>
- /// <param name="station">位置</param>
- 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<HistoryProcessData> QueryDBProcessCarrier(string sql)
- {
- List<HistoryProcessData> result = new List<HistoryProcessData>();
- try
- {
- DataSet ds = DB.ExecuteDataset(sql);
- if (ds == null)
- return result;
- for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
- {
- HistoryProcessData ev = new HistoryProcessData();
- ev.Guid = ds.Tables[0].Rows[i]["guid"].ToString();
- ev.Rfid = ds.Tables[0].Rows[i]["rfid"].ToString();
- ev.RecipeName = 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.StartTime = ((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.EndTime = ((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;
- }
- public static List<HistoryProcessData> QueryDBProcessLot(string sql)
- {
- List<HistoryProcessData> result = new List<HistoryProcessData>();
- try
- {
- DataSet ds = DB.ExecuteDataset(sql);
- if (ds == null)
- return result;
- for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
- {
- HistoryProcessData ev = new HistoryProcessData();
- ev.Guid = ds.Tables[0].Rows[i]["guid"].ToString();
- ev.RecipeName = ds.Tables[0].Rows[i]["name"].ToString();
- if (!ds.Tables[0].Rows[i]["start_time"].Equals(DBNull.Value))
- ev.StartTime = ((DateTime)ds.Tables[0].Rows[i]["start_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
- if (!ds.Tables[0].Rows[i]["end_time"].Equals(DBNull.Value))
- ev.EndTime = ((DateTime)ds.Tables[0].Rows[i]["end_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
- result.Add(ev);
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- return result;
- }
- public static List<HistoryCarrierData> QueryDBCarrier(string sql)
- {
- List<HistoryCarrierData> result = new List<HistoryCarrierData>();
- 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;
- }
- public static List<WaferHistoryLot> QueryWaferHistoryLotsBySql(string sql)
- {
- List<WaferHistoryLot> result = new List<WaferHistoryLot>();
- try
- {
- DataSet dataSet = DB.ExecuteDataset(sql);
- if (dataSet == null)
- return result;
- if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
- return result;
- for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
- {
- WaferHistoryLot item = new WaferHistoryLot();
- if (!dataSet.Tables[0].Rows[i]["lot_id"].Equals(DBNull.Value))
- {
- item.CarrierID = dataSet.Tables[0].Rows[i]["lot_id"].ToString();
- item.Name = dataSet.Tables[0].Rows[i]["lot_id"].ToString();
- }
- else
- {
- continue;
- }
- item.ID = dataSet.Tables[0].Rows[i]["guid"].ToString();
- item.Type = WaferHistoryItemType.Lot;
- if (!dataSet.Tables[0].Rows[i]["rfid"].Equals(DBNull.Value))
- item.Rfid = dataSet.Tables[0].Rows[i]["rfid"].ToString();
- if (!dataSet.Tables[0].Rows[i]["load_time"].Equals(DBNull.Value))
- item.StartTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["load_time"].ToString());
- if (!dataSet.Tables[0].Rows[i]["unload_time"].Equals(DBNull.Value))
- item.EndTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["unload_time"].ToString());
- DataSet subDataSet = DB.ExecuteDataset(string.Format("SELECT * FROM \"wafer_data\" Where \"carrier_data_guid\"='{0}' ;", item.ID));
- if (subDataSet != null && subDataSet.Tables.Count != 0 && subDataSet.Tables[0].Rows.Count != 0)
- {
- item.WaferCount = subDataSet.Tables[0].Rows.Count;
- item.FaultWaferCount = subDataSet.Tables[0].Select("process_status='Failed'").Length;
- }
- result.Add(item);
- }
- }
- catch (Exception e)
- {
- LOG.Write(e);
- }
- return result;
- }
- public static List<WaferHistoryLot> GetWaferHistoryLots(DateTime startTime, DateTime endTime, string keyWord)
- {
- List<WaferHistoryLot> result = new List<WaferHistoryLot>();
- try
- {
- string sqlFilter = "";
- if (keyWord != null && !string.IsNullOrEmpty(keyWord.Trim()))
- {
- sqlFilter = "and (";
- var keyStrings = keyWord.Split(',');
- for (int i = 0; i < keyStrings.Length; i++)
- {
- sqlFilter += $"\"lot_id\" like '%{keyStrings[i].Trim()}%'";
- if (i < keyStrings.Length - 1)
- {
- sqlFilter += " or ";
- }
- }
- sqlFilter += ")";
- }
- string sql = string.Format("SELECT * FROM \"carrier_data\" where (\"unload_time\" is null and \"load_time\" >= '{2}') or (\"load_time\" >= '{0}' and \"load_time\" <= '{1}') or (\"unload_time\" >= '{0}' and \"unload_time\" <= '{1}') or (\"load_time\" <= '{0}' and \"unload_time\" >= '{1}') {3} order by \"station\" ASC, \"load_time\" ASC limit 1000;", startTime.ToString("yyyy/MM/dd HH:mm:ss.fff"), startTime.AddDays(-1).ToString("yyyy/MM/dd HH:mm:ss.fff"), endTime.ToString("yyyy/MM/dd HH:mm:ss.fff"), sqlFilter);
- DataSet dataSet = DB.ExecuteDataset(sql);
- if (dataSet == null)
- return result;
- if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
- return result;
- for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
- {
- WaferHistoryLot item = new WaferHistoryLot();
- if (!dataSet.Tables[0].Rows[i]["lot_id"].Equals(DBNull.Value))
- {
- item.CarrierID = dataSet.Tables[0].Rows[i]["lot_id"].ToString();
- item.Name = dataSet.Tables[0].Rows[i]["lot_id"].ToString();
- }
- else
- {
- continue;
- }
- item.ID = dataSet.Tables[0].Rows[i]["guid"].ToString();
- item.Type = WaferHistoryItemType.Lot;
- if (!dataSet.Tables[0].Rows[i]["rfid"].Equals(DBNull.Value))
- item.Rfid = dataSet.Tables[0].Rows[i]["rfid"].ToString();
- if (!dataSet.Tables[0].Rows[i]["load_time"].Equals(DBNull.Value))
- item.StartTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["load_time"].ToString());
- if (!dataSet.Tables[0].Rows[i]["unload_time"].Equals(DBNull.Value))
- item.EndTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["unload_time"].ToString());
- DataSet subDataSet = DB.ExecuteDataset(string.Format("SELECT * FROM \"wafer_data\" Where \"carrier_data_guid\"='{0}' ;", item.ID));
- if (subDataSet != null && subDataSet.Tables.Count != 0 && subDataSet.Tables[0].Rows.Count != 0)
- {
- item.WaferCount = subDataSet.Tables[0].Rows.Count;
- item.FaultWaferCount = subDataSet.Tables[0].Select("process_status='Failed'").Length;
- }
- result.Add(item);
- }
- }
- catch (Exception e)
- {
- LOG.Write(e);
- }
- return result;
- }
- }
- }
|