OracleUtil
using ICUValidationService.Log;
using System;
using System.Collections.Generic;
using Oracle.ManagedDataAccess.Client;
using System.IO;
using System.Text;
using EAPUtility;
public static class OracleUtil
{
public static string logPath = System.Environment.CurrentDirectory + "\\log\\";
public static String EDAConnectionString = "Data Source=10.2.1.2:11/ADB;Persist Security Info=True;User ID=AUSER;Password=AUSER";
public static void UpdateEDATable(EDA_Table table)
{
try
{
using (var conn = new OracleConnection(QAUtility.EDAConnectionString))
{
conn.Open();
String sql = @"
UPDATE EDAUSER.EDA_TABLE
SET LASTINDEX=:LASTINDEX, UPLOADDATE=sysdate
where TABLENAME=:TABLENAME
";
OracleCommand cmd = new OracleCommand(sql, conn);
cmd.Parameters.Add(new OracleParameter("LASTINDEX", table.LastIndex));
cmd.Parameters.Add(new OracleParameter("TABLENAME", table.TableName));
cmd.ExecuteNonQuery();
}
}
catch (Exception ex)
{
LogError("UpdateEDATable", ex.Message);
throw;
}
}
public static EDA_Table QueryTableUploadInfo(string tableName)
{
EDA_Table table = new EDA_Table();
table.TableName = tableName;
table.LastIndex = Int64.MaxValue;
try
{
using (var conn = new OracleConnection(QAUtility.EDAConnectionString))
{
conn.Open();
String sql = @"SELECT TABLENAME, LASTINDEX, UPLOADDATE FROM EDAUSER.EDA_TABLE
where TABLENAME=:TABLENAME";
OracleCommand cmd = new OracleCommand(sql, conn);
cmd.Parameters.Add(new OracleParameter("TABLENAME", tableName));
using (OracleDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
table.LastIndex = Decimal.Parse(reader["LASTINDEX"].ToString());
table.UploadDate = DateTime.Parse(reader["UPLOADDATE"].ToString());
}
}
}
}
catch (Exception ex)
{
LogError("QueryLastIndex", ex.Message);
throw;
}
return table;
}
public static bool InsertQARawTable(EDA_DC_TDATA bean)
{
bool result = false;
try
{
Console.WriteLine("InsertQARawTable = " + QAUtility.EDAConnectionString);
using (var conn = new OracleConnection(QAUtility.EDAConnectionString))
{
conn.Open();
String sql = @"INSERT INTO EDAUSER.EDA_DC_TDATA
(LOTID, EQPID, OPNO, TRAYID, CELLID, SLOTMAP, SLOTX, SLOTY, DATETYPE, CYCLENO, RECIPEID, STEP, STEPTIME, TEMP1, MAH, MWH,
STEP_MAH, VOL, CUR, POW, RES, CAP, STATUS, ACTIONSTS, ENDSTATUS, FILENAME, WEIGHT, UPDATETIME, MEASURETIME, CREATETIME, VAR1,
VAR2, VAR3, VAR4, VAR5, VAR6, VAR7, VAR8, VAR9, VAR10, VAR11, VAR12, VAR13, VAR14, VAR15, TEMP2, TEMP3, TEMP4, TEMP5,
TEMP6, TEMP7, TEMP8, TEMP9, TEMP10)
VALUES
(:LOTID, :EQPID, :OPNO, :TRAYID, :CELLID, :SLOTMAP, :SLOTX, :SLOTY, :DATETYPE, :CYCLENO, :RECIPEID, :STEP, :STEPTIME, :TEMP1, :MAH, :MWH, :
:STEP_MAH, :VOL, :CUR, :POW, :RES, :CAP, :STATUS, :ACTIONSTS, :ENDSTATUS, :FILENAME, :WEIGHT, :UPDATETIME, :MEASURETIME, :CREATETIME, :VAR1, :
:VAR2, :VAR3, :VAR4, :VAR5, :VAR6, :VAR7, :VAR8, :VAR9, :VAR10, :VAR11, :VAR12, :VAR13, :VAR14, :VAR15, :TEMP2, :TEMP3, :TEMP4, :TEMP5, :
:TEMP6, :TEMP7, :TEMP8, :TEMP9, :TEMP10)";
OracleCommand cmd = new OracleCommand(sql, conn);
cmd.Parameters.Add(new OracleParameter("LOTID", bean.LOTID));
cmd.Parameters.Add(new OracleParameter("EQPID", bean.EQPID));
cmd.Parameters.Add(new OracleParameter("OPNO", bean.OPNO));
cmd.Parameters.Add(new OracleParameter("TRAYID", bean.TRAYID));
cmd.Parameters.Add(new OracleParameter("CELLID", bean.CELLID));
cmd.Parameters.Add(new OracleParameter("SLOTMAP", bean.SLOTMAP));
cmd.Parameters.Add(new OracleParameter("SLOTX", bean.SLOTX));
cmd.Parameters.Add(new OracleParameter("SLOTY", bean.SLOTY));
cmd.Parameters.Add(new OracleParameter("DATETYPE", bean.DATETYPE));
cmd.Parameters.Add(new OracleParameter("CYCLENO", bean.CYCLENO));
cmd.Parameters.Add(new OracleParameter("RECIPEID", bean.RECIPEID));
cmd.Parameters.Add(new OracleParameter("STEP", bean.STEP));
cmd.Parameters.Add(new OracleParameter("STEPTIME", bean.STEPTIME));
cmd.Parameters.Add(new OracleParameter("TEMP1", bean.TEMP1));
cmd.Parameters.Add(new OracleParameter("MAH", bean.MAH));
cmd.Parameters.Add(new OracleParameter("MWH", bean.MWH));
cmd.Parameters.Add(new OracleParameter("STEP_MAH", bean.STEP_MAH));
cmd.Parameters.Add(new OracleParameter("VOL", bean.VOL));
cmd.Parameters.Add(new OracleParameter("CUR", bean.CUR));
cmd.Parameters.Add(new OracleParameter("POW", bean.POW));
cmd.Parameters.Add(new OracleParameter("RES", bean.RES));
cmd.Parameters.Add(new OracleParameter("CAP", bean.CAP));
cmd.Parameters.Add(new OracleParameter("STATUS", bean.STATUS));
cmd.Parameters.Add(new OracleParameter("ACTIONSTS", bean.ACTIONSTS));
cmd.Parameters.Add(new OracleParameter("ENDSTATUS", bean.ENDSTATUS));
cmd.Parameters.Add(new OracleParameter("FILENAME", bean.FILENAME));
cmd.Parameters.Add(new OracleParameter("WEIGHT", bean.WEIGHT));
cmd.Parameters.Add(new OracleParameter("UPDATETIME", (bean.UPDATETIME == null ? (object)DBNull.Value : (object)bean.UPDATETIME)));
cmd.Parameters.Add(new OracleParameter("MEASURETIME", (bean.MEASURETIME == null ? (object)DBNull.Value : (object)bean.MEASURETIME)));
cmd.Parameters.Add(new OracleParameter("CREATETIME", (bean.CREATETIME == null ? (object)DBNull.Value : (object)bean.CREATETIME)));
//cmd.Parameters.Add(new OracleParameter("MEASURETIME", bean.MEASURETIME));
//cmd.Parameters.Add(new OracleParameter("CREATETIME", bean.CREATETIME));
cmd.Parameters.Add(new OracleParameter("VAR1", bean.VAR1));
cmd.Parameters.Add(new OracleParameter("VAR2", bean.VAR2));
cmd.Parameters.Add(new OracleParameter("VAR3", bean.VAR3));
cmd.Parameters.Add(new OracleParameter("VAR4", bean.VAR4));
cmd.Parameters.Add(new OracleParameter("VAR5", bean.VAR5));
cmd.Parameters.Add(new OracleParameter("VAR6", bean.VAR6));
cmd.Parameters.Add(new OracleParameter("VAR7", bean.VAR7));
cmd.Parameters.Add(new OracleParameter("VAR8", bean.VAR8));
cmd.Parameters.Add(new OracleParameter("VAR9", bean.VAR9));
cmd.Parameters.Add(new OracleParameter("VAR10", bean.VAR10));
cmd.Parameters.Add(new OracleParameter("VAR11", bean.VAR11));
cmd.Parameters.Add(new OracleParameter("VAR12", bean.VAR12));
cmd.Parameters.Add(new OracleParameter("VAR13", bean.VAR13));
cmd.Parameters.Add(new OracleParameter("VAR14", bean.VAR14));
cmd.Parameters.Add(new OracleParameter("VAR15", bean.VAR15));
cmd.Parameters.Add(new OracleParameter("TEMP2", bean.TEMP2));
cmd.Parameters.Add(new OracleParameter("TEMP3", bean.TEMP3));
cmd.Parameters.Add(new OracleParameter("TEMP4", bean.TEMP4));
cmd.Parameters.Add(new OracleParameter("TEMP5", bean.TEMP5));
cmd.Parameters.Add(new OracleParameter("TEMP6", bean.TEMP6));
cmd.Parameters.Add(new OracleParameter("TEMP7", bean.TEMP7));
cmd.Parameters.Add(new OracleParameter("TEMP8", bean.TEMP8));
cmd.Parameters.Add(new OracleParameter("TEMP9", bean.TEMP9));
cmd.Parameters.Add(new OracleParameter("TEMP10", bean.TEMP10));
//if (bean.tem == decimal.MinValue)
// cmd.Parameters.Add(new OracleParameter("TEM", DBNull.Value));
//else
// cmd.Parameters.Add(new OracleParameter("TEM", bean.tem.ToString()));
//if (bean.humid == decimal.MinValue)
// cmd.Parameters.Add(new OracleParameter("HUMID", DBNull.Value));
//else
// cmd.Parameters.Add(new OracleParameter("HUMID", bean.humid.ToString()));
cmd.ExecuteNonQuery();
result = true;
}
}
catch (Exception ex)
{
LogError("InsertQARawTable", ex.Message);
}
return result;
}
public static bool InsertQASummaryTable(EDA_DC_FMSRESULT bean)
{
bool result = false;
try
{
Console.WriteLine("InsertQASummaryTable = " + QAUtility.EDAConnectionString);
using (var conn = new OracleConnection(QAUtility.EDAConnectionString))
{
conn.Open();
String sql = @"INSERT INTO EDAUSER.EDA_DC_FMSRESULT
(LOTID, TRAYID, CELLID, SLOTMAP, GRADE, VOL, CUR, RES, RNG_H, RNG_L, UPDATETIME, CREATETIME, VAR1, VAR2, VAR3, VAR4, VAR5, VAR6, VAR7, VAR8, VAR9, VAR10, VAR11, VAR12, VAR13, VAR14, VAR15, TEMP1, TEMP2, TEMP3, TEMP4, TEMP5, TEMP6, TEMP7, TEMP8, TEMP9, TEMP10, STEPTIME, MAH, MWH, CYCLENO)
VALUES
(:LOTID, :TRAYID, :CELLID, :SLOTMAP, :GRADE, :VOL, :CUR, :RES, :RNG_H, :RNG_L, :UPDATETIME, :CREATETIME, :VAR1, :VAR2, :VAR3, :VAR4, :VAR5, :VAR6, :VAR7, :VAR8, :VAR9, :VAR10, :VAR11, :VAR12, :VAR13, :VAR14, :VAR15, :TEMP1, :TEMP2, :TEMP3, :TEMP4, :TEMP5, :TEMP6, :TEMP7, :TEMP8, :TEMP9, :TEMP10, :STEPTIME, :MAH, :MWH, :CYCLENO)";
OracleCommand cmd = new OracleCommand(sql, conn);
cmd.Parameters.Add(new OracleParameter("LOTID", bean.LOTID));
cmd.Parameters.Add(new OracleParameter("TRAYID", bean.TRAYID));
cmd.Parameters.Add(new OracleParameter("CELLID", bean.CELLID));
cmd.Parameters.Add(new OracleParameter("SLOTMAP", bean.SLOTMAP));
cmd.Parameters.Add(new OracleParameter("GRADE", bean.GRADE));
cmd.Parameters.Add(new OracleParameter("VOL", bean.VOL));
cmd.Parameters.Add(new OracleParameter("CUR", bean.CUR));
cmd.Parameters.Add(new OracleParameter("RES", bean.RES));
cmd.Parameters.Add(new OracleParameter("RNG_H", bean.RNG_H));
cmd.Parameters.Add(new OracleParameter("RNG_L", bean.RNG_L));
cmd.Parameters.Add(new OracleParameter("UPDATETIME", bean.UPDATETIME));
cmd.Parameters.Add(new OracleParameter("CREATETIME", bean.CREATETIME));
cmd.Parameters.Add(new OracleParameter("VAR1", bean.VAR1));
cmd.Parameters.Add(new OracleParameter("VAR2", bean.VAR2));
cmd.Parameters.Add(new OracleParameter("VAR3", bean.VAR3));
cmd.Parameters.Add(new OracleParameter("VAR4", bean.VAR4));
cmd.Parameters.Add(new OracleParameter("VAR5", bean.VAR5));
cmd.Parameters.Add(new OracleParameter("VAR6", bean.VAR6));
cmd.Parameters.Add(new OracleParameter("VAR7", bean.VAR7));
cmd.Parameters.Add(new OracleParameter("VAR8", bean.VAR8));
cmd.Parameters.Add(new OracleParameter("VAR9", bean.VAR9));
cmd.Parameters.Add(new OracleParameter("VAR10", bean.VAR10));
cmd.Parameters.Add(new OracleParameter("VAR11", bean.VAR11));
cmd.Parameters.Add(new OracleParameter("VAR12", bean.VAR12));
cmd.Parameters.Add(new OracleParameter("VAR13", bean.VAR13));
cmd.Parameters.Add(new OracleParameter("VAR14", bean.VAR14));
cmd.Parameters.Add(new OracleParameter("VAR15", bean.VAR15));
cmd.Parameters.Add(new OracleParameter("TEMP1", bean.TEMP1));
cmd.Parameters.Add(new OracleParameter("TEMP2", bean.TEMP2));
cmd.Parameters.Add(new OracleParameter("TEMP3", bean.TEMP3));
cmd.Parameters.Add(new OracleParameter("TEMP4", bean.TEMP4));
cmd.Parameters.Add(new OracleParameter("TEMP5", bean.TEMP5));
cmd.Parameters.Add(new OracleParameter("TEMP6", bean.TEMP6));
cmd.Parameters.Add(new OracleParameter("TEMP7", bean.TEMP7));
cmd.Parameters.Add(new OracleParameter("TEMP8", bean.TEMP8));
cmd.Parameters.Add(new OracleParameter("TEMP9", bean.TEMP9));
cmd.Parameters.Add(new OracleParameter("TEMP10", bean.TEMP10));
cmd.Parameters.Add(new OracleParameter("STEPTIME", bean.STEPTIME));
cmd.Parameters.Add(new OracleParameter("MAH", bean.MAH));
cmd.Parameters.Add(new OracleParameter("MWH", bean.MWH));
cmd.Parameters.Add(new OracleParameter("CYCLENO", bean.CYCLENO));
//if (bean.tem == decimal.MinValue)
// cmd.Parameters.Add(new OracleParameter("TEM", DBNull.Value));
//else
// cmd.Parameters.Add(new OracleParameter("TEM", bean.tem.ToString()));
//if (bean.humid == decimal.MinValue)
// cmd.Parameters.Add(new OracleParameter("HUMID", DBNull.Value));
//else
// cmd.Parameters.Add(new OracleParameter("HUMID", bean.humid.ToString()));
cmd.ExecuteNonQuery();
result = true;
}
}
catch (Exception ex)
{
LogError("InsertQASummaryTable", ex.Message);
}
return result;
}
public static bool InsertEDAHumidTable(eonekh bean)
{
bool result = false;
try
{
Console.WriteLine("EDAConnectionString = " + QAUtility.EDAConnectionString);
using (var conn = new OracleConnection(QAUtility.EDAConnectionString))
{
conn.Open();
String sql = @"INSERT INTO EDAUSER.EDA_HUMID_EONEKH
(RECNO, STATION, RECTIME, TEM, HUMID, COMP)
VALUES(:RECNO,:STATION, :RECTIME, :TEM, :HUMID, '"+ bean.comp + "') ";
OracleCommand cmd = new OracleCommand(sql, conn);
//cmd.Parameters.Add(new OracleParameter("COMP", bean.comp));
cmd.Parameters.Add(new OracleParameter("RECNO", bean.recno.ToString()));
cmd.Parameters.Add(new OracleParameter("STATION", bean.station));
cmd.Parameters.Add(new OracleParameter("RECTIME", bean.rectime));
//cmd.Parameters.Add(new OracleParameter("RECTIME", OracleDbType.Date)).Value = bean.rectime;
//cmd.Parameters.Add(new OracleParameter("TEM", bean.tem));
//cmd.Parameters.Add(new OracleParameter("HUMID", bean.humid));
if (bean.tem == decimal.MinValue)
cmd.Parameters.Add(new OracleParameter("TEM", DBNull.Value));
else
cmd.Parameters.Add(new OracleParameter("TEM", bean.tem.ToString()));
if (bean.humid == decimal.MinValue)
cmd.Parameters.Add(new OracleParameter("HUMID", DBNull.Value));
else
cmd.Parameters.Add(new OracleParameter("HUMID", bean.humid.ToString()));
//cmd.Parameters.Add(new OracleParameter(":number_column", OracleType.Number)).Value = (s.Class.HasValue) ? s.Class.Value : (object)DBNull.Value;
cmd.ExecuteNonQuery();
result = true;
}
}
catch (Exception ex)
{
LogError("InsertEDAValueTable", ex.Message);
}
return result;
}
public static bool InsertEDAWindTable(EDA_WindSpeed_SpeedData bean)
{
bool result = false;
try
{
Console.WriteLine("EDAConnectionString = " + QAUtility.EDAConnectionString);
using (var conn = new OracleConnection(QAUtility.EDAConnectionString))
{
conn.Open();
String sql = "INSERT INTO EDAUSER.EDA_WINDSPEED_SPEEDDATA "+
"(AUTOINDEX, FACTORY, PANEL, ID, DATATIME, PV, SV, STATUS, \"Loop\") "+
"VALUES(:AUTOINDEX, :FACTORY, :PANEL, :ID, :DATATIME, :PV, :SV, :STATUS, :Loop)";
OracleCommand cmd = new OracleCommand(sql, conn);
cmd.Parameters.Add(new OracleParameter("AUTOINDEX", bean.autoindex));
cmd.Parameters.Add(new OracleParameter("FACTORY", bean.Factory));
cmd.Parameters.Add(new OracleParameter("PANEL", bean.Panel));
cmd.Parameters.Add(new OracleParameter("ID", bean.ID));
cmd.Parameters.Add(new OracleParameter("DATATIME", bean.DataTime));
cmd.Parameters.Add(new OracleParameter("PV", bean.PV));
cmd.Parameters.Add(new OracleParameter("SV", bean.SV));
cmd.Parameters.Add(new OracleParameter("STATUS", bean.Status));
cmd.Parameters.Add(new OracleParameter("Loop", bean.Loop));
//if (bean.humid == decimal.MinValue) cmd.Parameters.Add(new OracleParameter("HUMID", DBNull.Value));
//else cmd.Parameters.Add(new OracleParameter("HUMID", bean.humid.ToString()));
//cmd.Parameters.Add(new OracleParameter(":number_column", OracleType.Number)).Value = (s.Class.HasValue) ? s.Class.Value : (object)DBNull.Value;
cmd.ExecuteNonQuery();
result = true;
}
}
catch (Exception ex)
{
LogError("InsertEDAValueTable", ex.Message);
}
return result;
}
public static void LogError(string fuction, string log)
{
Logger.Instance.WriteLog(logPath, fuction + ":" + log, LogType.Error, "Error");
Console.WriteLine(DateTime.Now.ToString() + " E: " + log);
}
public static void Log(string log)
{
Logger.Instance.WriteLog(logPath, log, LogType.Information, "");
Console.WriteLine(DateTime.Now.ToString() + " M: " + log);
}
public class EDA_Table
{
public string TableName { get; set; }
public decimal LastIndex { get; set; }
public DateTime UploadDate { get; set; }
public EDA_Table()
{
}
}
public class EDA_WindSpeed_SpeedData
{
public decimal autoindex { get; set; }
public string Factory { get; set; }
public string Loop { get; set; }
public string Panel { get; set; }
public string ID { get; set; }
public DateTime DataTime { get; set; }
public string PV { get; set; }
public string SV { get; set; }
public string Status { get; set; }
public EDA_WindSpeed_SpeedData()
{
}
}
public class eonekh
{
public decimal recno { get; set; }
public decimal station { get; set; }
public DateTime rectime { get; set; }
public decimal tem { get; set; }
public decimal humid { get; set; }
public string comp { get; set; }
public eonekh()
{
}
}
public class EDA_DC_FMSRESULT
{
public string LOTID { get; set; }
public string TRAYID { get; set; }
public string CELLID { get; set; }
public string SLOTMAP { get; set; }
public int GRADE { get; set; }
public string VOL { get; set; }
public string CUR { get; set; }
public string RES { get; set; }
public string RNG_H { get; set; }
public string RNG_L { get; set; }
public DateTime UPDATETIME { get; set; }
public DateTime CREATETIME { get; set; }
public string VAR1 { get; set; }
public string VAR2 { get; set; }
public string VAR3 { get; set; }
public string VAR4 { get; set; }
public string VAR5 { get; set; }
public string VAR6 { get; set; }
public string VAR7 { get; set; }
public string VAR8 { get; set; }
public string VAR9 { get; set; }
public string VAR10 { get; set; }
public string VAR11 { get; set; }
public string VAR12 { get; set; }
public string VAR13 { get; set; }
public string VAR14 { get; set; }
public string VAR15 { get; set; }
public string TEMP1 { get; set; }
public string TEMP2 { get; set; }
public string TEMP3 { get; set; }
public string TEMP4 { get; set; }
public string TEMP5 { get; set; }
public string TEMP6 { get; set; }
public string TEMP7 { get; set; }
public string TEMP8 { get; set; }
public string TEMP9 { get; set; }
public string TEMP10 { get; set; }
public string STEPTIME { get; set; }
public string MAH { get; set; }
public string MWH { get; set; }
public string CYCLENO { get; set; }
public EDA_DC_FMSRESULT()
{
}
}
public class EDA_DC_TDATA
{
public string LOTID { get; set; }
public string EQPID { get; set; }
public string OPNO { get; set; }
public string TRAYID { get; set; }
public string CELLID { get; set; }
public string SLOTMAP { get; set; }
public string SLOTX { get; set; }
public string SLOTY { get; set; }
public string DATETYPE { get; set; }
public string CYCLENO { get; set; }
public string RECIPEID { get; set; }
public string STEP { get; set; }
public string STEPTIME { get; set; }
public string TEMP1 { get; set; }
public string MAH { get; set; }
public string MWH { get; set; }
public string STEP_MAH { get; set; }
public string VOL { get; set; }
public string CUR { get; set; }
public string POW { get; set; }
public string RES { get; set; }
public string CAP { get; set; }
public string STATUS { get; set; }
public string ACTIONSTS { get; set; }
public string ENDSTATUS { get; set; }
public string FILENAME { get; set; }
public string WEIGHT { get; set; }
public DateTime UPDATETIME { get; set; }
public DateTime MEASURETIME { get; set; }
public DateTime CREATETIME { get; set; }
public string VAR1 { get; set; }
public string VAR2 { get; set; }
public string VAR3 { get; set; }
public string VAR4 { get; set; }
public string VAR5 { get; set; }
public string VAR6 { get; set; }
public string VAR7 { get; set; }
public string VAR8 { get; set; }
public string VAR9 { get; set; }
public string VAR10 { get; set; }
public string VAR11 { get; set; }
public string VAR12 { get; set; }
public string VAR13 { get; set; }
public string VAR14 { get; set; }
public string VAR15 { get; set; }
public string TEMP2 { get; set; }
public string TEMP3 { get; set; }
public string TEMP4 { get; set; }
public string TEMP5 { get; set; }
public string TEMP6 { get; set; }
public string TEMP7 { get; set; }
public string TEMP8 { get; set; }
public string TEMP9 { get; set; }
public string TEMP10 { get; set; }
public EDA_DC_TDATA()
{
}
}
}
留言
張貼留言