| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 | using System;using System.Collections.Generic;using System.Data;using System.Linq;using Aitex.Core.RT.DBCore;using Aitex.Core.RT.Log;using Aitex.Core.UI.ControlDataContext;using Aitex.Sorter.Common;using MECF.Framework.Common.Equipment;namespace MECF.Framework.Common.DBCore{    public class RecipeDataRecorder    {        public static void RecipeStart(string guid, string waferDataGuid, string recipeName, string settingTime, string chamber)        {            string sql = string.Format(                "INSERT INTO \"recipe_data\"(\"guid\", \"wafer_data_guid\", \"recipe_begin_time\", \"recipe_name\", \"recipe_setting_time\" , \"chamber\"  )VALUES ('{0}', '{1}', '{2}' , '{3}', '{4}', '{5}' );",                guid,                waferDataGuid,                DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),                recipeName,                settingTime,                chamber);            DB.Insert(sql);        }        public static void RecipeEnd(string guid)        {            string sql = string.Format(                "UPDATE \"recipe_data\" SET \"recipe_end_time\"='{0}' WHERE \"guid\"='{1}';",                DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),                guid);            DB.Insert(sql);        }        public static void RecipeStepStart(string guid, int recipeStepNo, string recipeStepName, string settingTime)        {            string sql = string.Format(                "INSERT INTO \"recipe_step_data\"(\"guid\", \"recipe_step_no\", \"recipe_step_name\", \"recipe_step_setting_time\" , \"recipe_step_begin_time\")VALUES ('{0}', '{1}', '{2}' , '{3}', '{4}' );",                guid,                recipeStepNo,                recipeStepName,                settingTime,                DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"));            DB.Insert(sql);        }        public static void RecipeStepEnd(string guid, int recipeStepNo)        {            string sql = string.Format(                "UPDATE \"recipe_step_data\" SET \"recipe_step_end_time\"='{0}' WHERE \"guid\"='{1}' AND \"recipe_step_no\"='{2}';",                DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),                guid,                recipeStepNo);            DB.Insert(sql);        }        public static WaferHistoryRecipe GetWaferHistoryRecipe(string id)        {            WaferHistoryRecipe result = new WaferHistoryRecipe();            try            {                string sql = string.Format("SELECT * FROM \"recipe_data\" where \"guid\" = '{0}'  limit 1000;", id);                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++)                {                    result.ID = dataSet.Tables[0].Rows[i]["guid"].ToString();                    result.Type = WaferHistoryItemType.Recipe;                    result.Chamber = dataSet.Tables[0].Rows[i]["chamber"].ToString();                    result.SettingTime = dataSet.Tables[0].Rows[i]["recipe_setting_time"].ToString();                    if (!dataSet.Tables[0].Rows[i]["recipe_begin_time"].Equals(DBNull.Value))                        result.StartTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["recipe_begin_time"].ToString());                    if (!dataSet.Tables[0].Rows[i]["recipe_end_time"].Equals(DBNull.Value))                        result.EndTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["recipe_end_time"].ToString());                    result.ActualTime = result.EndTime.CompareTo(result.StartTime) <= 0 ? "" : result.EndTime.Subtract(result.StartTime).ToString();                    result.Recipe = dataSet.Tables[0].Rows[i]["recipe_name"].ToString();                    result.Name = dataSet.Tables[0].Rows[i]["recipe_name"].ToString();                    result.Steps = GetRecipeStepInfoList(id);                }            }            catch (Exception e)            {                LOG.Write(e);            }            return result;        }        public static List<WaferHistoryWafer> GetWaferHistoryWafers(string id)        {            List<WaferHistoryWafer> result = new List<WaferHistoryWafer>();            try            {                string sql = string.Format("SELECT * FROM \"wafer_data\" where \"carrier_data_guid\" = '{0}' and \"lot_id\" <> '' order by  \"wafer_id\"  ASC  limit 1000;", id);                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++)                {                    WaferHistoryWafer item = new WaferHistoryWafer();                    item.ID = dataSet.Tables[0].Rows[i]["guid"].ToString();                    item.Type = WaferHistoryItemType.Wafer;                    item.Name = dataSet.Tables[0].Rows[i]["wafer_id"].ToString();                    if (!dataSet.Tables[0].Rows[i]["sequence_name"].Equals(DBNull.Value))                    {                        item.ProcessJob = dataSet.Tables[0].Rows[i]["sequence_name"].ToString();                    }                    if (!dataSet.Tables[0].Rows[i]["create_time"].Equals(DBNull.Value))                        item.StartTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["create_time"].ToString());                    if (!dataSet.Tables[0].Rows[i]["delete_time"].Equals(DBNull.Value))                        item.EndTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["delete_time"].ToString());                    result.Add(item);                }            }            catch (Exception e)            {                LOG.Write(e);            }            return result;        }        private static List<RecipeStep> GetRecipeStepInfoList(string guid)        {            List<RecipeStep> result = new List<RecipeStep>();            DataSet recipeStepDataSet = DB.ExecuteDataset(string.Format("SELECT * FROM \"recipe_step_data\" where \"guid\" = '{0}'  limit 1000;", guid));            if (recipeStepDataSet != null && recipeStepDataSet.Tables.Count != 0 && recipeStepDataSet.Tables[0].Rows.Count != 0)            {                for (int i = 0; i < recipeStepDataSet.Tables[0].Rows.Count; i++)                {                    RecipeStep rs = new RecipeStep();                    rs.No = int.Parse(recipeStepDataSet.Tables[0].Rows[i]["recipe_step_no"].ToString());                    rs.Name = recipeStepDataSet.Tables[0].Rows[i]["recipe_step_name"].ToString();                    rs.SettingTime = recipeStepDataSet.Tables[0].Rows[i]["recipe_step_setting_time"].ToString();                    if (!recipeStepDataSet.Tables[0].Rows[i]["recipe_step_begin_time"].Equals(DBNull.Value))                        rs.StartTime = DateTime.Parse(recipeStepDataSet.Tables[0].Rows[i]["recipe_step_begin_time"].ToString());                    if (!recipeStepDataSet.Tables[0].Rows[i]["recipe_step_end_time"].Equals(DBNull.Value))                        rs.EndTime = DateTime.Parse(recipeStepDataSet.Tables[0].Rows[i]["recipe_step_end_time"].ToString());                    rs.ActualTime = rs.EndTime.CompareTo(rs.StartTime) <= 0 ? "" : rs.EndTime.Subtract(rs.StartTime).ToString();                    result.Add(rs);                }            }            return result;        }        public static List<WaferHistoryRecipe> GetWaferHistoryRecipes(string id)        {            List<WaferHistoryRecipe> result = new List<WaferHistoryRecipe>();            try            {                string sql = string.Format("SELECT * FROM \"process_data\" where \"wafer_data_guid\" = '{0}'  limit 1000;", id);                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++)                {                    result.Add(GetWaferHistoryRecipe(dataSet.Tables[0].Rows[i]["guid"].ToString()));                }            }            catch (Exception e)            {                LOG.Write(e);            }            return result;        }        public static List<WaferHistorySecquence> GetWaferHistorySecquences(string id)        {            List<WaferHistorySecquence> result = new List<WaferHistorySecquence>();            try            {                string sql = string.Format("SELECT * FROM \"wafer_data\" where \"guid\" = '{0}'  and \"lot_id\" <> '' order by  \"wafer_id\"  ASC  limit 1000;", id);                DataSet dataSet = DB.ExecuteDataset(sql);                if (dataSet == null)                    return result;                if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)                    return result;                int index = 0;                try                {                    sql = string.Format("SELECT * FROM \"wafer_move_history\" where \"wafer_data_guid\" = '{0}' order by \"arrive_time\" ASC limit 1000;", id);                    DataSet dataSeta = DB.ExecuteDataset(sql);                    if (dataSeta.Tables.Count == 0 || dataSeta.Tables[0].Rows.Count == 0)                        return result;                                        for (int i = 0; i < dataSeta.Tables[0].Rows.Count; i++)                    {                        if (dataSeta.Tables[0].Rows[i]["station"].ToString() == "Cassette")                        {                            index = i + 1;                            break;                        }                        if (i == dataSeta.Tables[0].Rows.Count - 1)                            index = i + 1;                    }                    if (dataSeta.Tables[0].Rows.Count % index > 0)                        index = dataSeta.Tables[0].Rows.Count / index + 1;                    else                        index = dataSeta.Tables[0].Rows.Count / index;                }                catch (Exception e)                {                    LOG.Write(e);                }                for (int i = 0; i < index; i++)                {                    result.Add(GetWaferHistorySecquence(id, dataSet.Tables[0].Rows[0]["sequence_name"].ToString(),i));                }            }            catch (Exception e)            {                LOG.Write(e);            }            return result;        }        public static WaferHistorySecquence GetWaferHistorySecquence(string id,string SecquenceName,int count)        {            WaferHistorySecquence result = new WaferHistorySecquence();            try            {                string sql = string.Format("SELECT * FROM \"wafer_move_history\" where \"wafer_data_guid\" = '{0}' order by \"arrive_time\" ASC limit 1000;", id);                DataSet dataSet = DB.ExecuteDataset(sql);                if (dataSet == null)                    return result;                if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)                    return result;                int index = 0;                for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)                {                    if (dataSet.Tables[0].Rows[i]["station"].ToString() == "Cassette")                    {                        index = i;                        break;                    }                    if (i == dataSet.Tables[0].Rows.Count - 1)                        index = i;                }                for (int i = 0; i < dataSet.Tables[0].Rows.Count;)                {                    i = count > 0 ? index * count + count - 1: index * count + count;                    result.SecquenceName = SecquenceName;                    result.Recipe = SecquenceName;                    result.SecQuenceStartTime = dataSet.Tables[0].Rows[i]["arrive_time"].ToString();                    result.StartTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["arrive_time"].ToString());                    i = index * count + count;                    i += index;                    if (i >= dataSet.Tables[0].Rows.Count)                    {                        result.SecQuenceEndTime = dataSet.Tables[0].Rows[dataSet.Tables[0].Rows.Count - 1]["arrive_time"].ToString();                        result.EndTime = DateTime.Parse(dataSet.Tables[0].Rows[dataSet.Tables[0].Rows.Count - 1]["arrive_time"].ToString());                    }                    else                    {                        result.SecQuenceEndTime = dataSet.Tables[0].Rows[i]["arrive_time"].ToString();                        result.EndTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["arrive_time"].ToString());                    }                    result.ActualTime = result.EndTime.CompareTo(result.StartTime) <= 0 ? "" : result.EndTime.Subtract(result.StartTime).ToString();                    break;                }            }            catch (Exception e)            {                LOG.Write(e);            }            return result;        }    }}
 |