Ejemplo n.º 1
0
        public Row_R_LOT_STATUS GetByInput(string _InputData, string ColoumName, OleExec DB)
        {
            string           strsql = "";
            Row_R_LOT_STATUS R      = null;

            if (DBType == DB_TYPE_ENUM.Oracle)
            {
                //Modify by LLF 2018-02-24
                //strsql = $@" select ID from r_lot_status where {ColoumName}='{_InputData.Replace("'", "''")}' and closed_flag='0'";
                strsql = $@" select ID from r_lot_status where {ColoumName}='{_InputData.Replace("'", "''")}' ";
                string ID = DB.ExecSelectOneValue(strsql)?.ToString();
                if (ID != null)
                {
                    //string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000007", new string[] { ColoumName+":" + _InputData });
                    //throw new MESReturnMessage(errMsg);
                    R = (Row_R_LOT_STATUS)this.GetObjByID(ID, DB);
                }
                return(R);
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
        }
Ejemplo n.º 2
0
        public Row_R_LOT_DETAIL GetByLotID(string _LotID, string StrSN, OleExec DB) //add by StrSN by LLF 2018-02-22
        {
            string strsql = "";

            if (DBType == DB_TYPE_ENUM.Oracle)
            {
                //modify by LLF 2018-02-22
                //strsql = $@" select ID from r_lot_detail where lot_id='{_LotID.Replace("'", "''")}' and rownum=1";
                if (string.IsNullOrEmpty(StrSN))
                {
                    strsql = $@" select ID from r_lot_detail where lot_id='{_LotID.Replace("'", "''")}' and rownum=1 ";
                }
                else
                {
                    strsql = $@" select ID from r_lot_detail where lot_id='{_LotID.Replace("'", "''")}' and SN='{StrSN}' ";
                }

                string ID = DB.ExecSelectOneValue(strsql)?.ToString();
                if (ID == null)
                {
                    string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000007", new string[] { "LotID:" + _LotID });
                    throw new MESReturnMessage(errMsg);
                }
                Row_R_LOT_DETAIL Res = (Row_R_LOT_DETAIL)this.GetObjByID(ID, DB);
                return(Res);
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 补bip allpart data
        /// </summary>
        public void TEST()
        {
            OleExec APDB   = new OleExec("HWD_APDB", false);
            string  strsql = @"select A.SN,B.PANEL from r_sn_station_detail A, R_PANEL_SN B where A.workorderno = '002510037542' and A.current_station = 'BIP'
                            AND A.SN = B.SN";
            DataSet ds     = SFCDB.ExecSelect(strsql);

            try
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    try
                    {
                        strsql = $@"SELECT p_sn FROM (
                            SELECT DISTINCT(p_sn) FROM MES4.R_TR_PRODUCT_DETAIL WHERE WO = '002510037542' AND P_SN LIKE '{ds.Tables[0].Rows[i]["PANEL"]}%') WHERE ROWNUM =1";
                        string panel_sn = APDB.ExecSelectOneValue(strsql)?.ToString();
                        if (panel_sn == null)
                        {
                            continue;
                        }
                        strsql = $@"UPDATE MES4.R_TR_PRODUCT_DETAIL SET P_SN='{ds.Tables[0].Rows[i]["SN"]}' WHERE p_SN='{panel_sn}'";
                        APDB.ExecSQL(strsql);
                    }
                    catch (Exception E)
                    {
                        throw E;
                    }
                    finally { }
                }
            }
            catch { }
            finally {
                APDB.CloseMe();
            }
        }
Ejemplo n.º 4
0
        public DateTime GetDBDateTime()
        {
            OleExec sfcdb = _DBPools["SFCDB"].Borrow();

            try
            {
                string strSql = "select sysdate from dual";
                if (DBTYPE == DB_TYPE_ENUM.Oracle)
                {
                    strSql = "select sysdate from dual";
                }
                else if (DBTYPE == DB_TYPE_ENUM.SqlServer)
                {
                    strSql = "select get_date() ";
                }
                else
                {
                    throw new Exception(DBTYPE.ToString() + " not Work");
                }
                DateTime DBTime = (DateTime)sfcdb.ExecSelectOneValue(strSql);
                _DBPools["SFCDB"].Return(sfcdb);
                return(DBTime);
            }
            catch (Exception e)
            {
                _DBPools["SFCDB"].Return(sfcdb);
                throw e;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 檢查包裝內所有SN的當前工站是否一致:包裝為空或狀態不一致返回False
        /// </summary>
        /// <param name="DB"></param>
        /// <param name="Station"></param>
        /// <returns></returns>
        public bool CheckPackSnStatus(OleExec DB, string Station, string PackNo)
        {
            string strSql = $@" select count(1) lotnum from (                             
                                select count(1) as lotnum1 from r_sn a,r_packing b,r_sn_packing c,r_packing d where a.id=c.sn_id and c.pack_id=b.id and b.parent_pack_id=d.id 
                                and d.pack_no='{PackNo}' and a.next_station='{Station}') a,  
                                (select count(1) as lotnum2 from r_sn a,r_packing b,r_sn_packing c,r_packing d where a.id=c.sn_id and c.pack_id=b.id and b.parent_pack_id=d.id 
                                and d.pack_no='{PackNo}' ) b  where a.lotnum1=b.lotnum2 and a.lotnum1<>0";
            int    tolnum = Convert.ToInt32(DB.ExecSelectOneValue(strSql).ToString());

            if (tolnum == 1)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 6
0
        public string getNextStation(string routeId, string currentStation, OleExec DB)
        {
            string sql         = $@"    SELECT STATION_NAME
                              FROM(SELECT *
                                      FROM C_ROUTE_DETAIL
                                     WHERE ROUTE_ID = '{routeId}'
                                       AND SEQ_NO > (SELECT SEQ_NO
                                                       FROM C_ROUTE_DETAIL
                                                      WHERE ROUTE_ID = '{routeId}'
                                                        AND STATION_NAME = '{currentStation}')
                                     ORDER BY SEQ_NO)
                             WHERE ROWNUM = 1";
            string nextStation = (string)DB.ExecSelectOneValue(sql);

            return(nextStation);
        }
Ejemplo n.º 7
0
        public string getWOIdByWO(string _WO, OleExec DB)
        {
            string strsql = "";

            if (DBType == DB_TYPE_ENUM.Oracle)
            {
                strsql = $@"select ID from r_wo_base where workorderno='{_WO.Replace("'", "''")}'";
                string ID = DB.ExecSelectOneValue(strsql)?.ToString();
                return(ID);
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 獲取數據庫時間
        /// </summary>
        /// <param name="DB"></param>
        /// <returns></returns>
        public DateTime GetDBDateTime(OleExec DB)
        {
            string strSql = "select sysdate from dual";

            if (this.DBType == DB_TYPE_ENUM.Oracle)
            {
                strSql = "select sysdate from dual";
            }
            else if (this.DBType == DB_TYPE_ENUM.SqlServer)
            {
                strSql = "select get_date() ";
            }
            else
            {
                throw new Exception(this.DBType.ToString() + " not Work");
            }
            return((DateTime)DB.ExecSelectOneValue(strSql));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 獲取BIP Panel未分板數量
        /// </summary>
        /// <param name="PanelSn"></param>
        /// <param name="DB"></param>
        /// <param name="DBType"></param>
        /// <returns></returns>
        public int PanelNoBIPQty(string PanelSn, OleExec DB, DB_TYPE_ENUM DBType)
        {
            int    NoBIPQty = 0;
            string errMsg   = string.Empty;

            if (DBType.Equals(DB_TYPE_ENUM.Oracle))
            {
                string strsql = $@"select count(1) from r_sn where sn in (
                        select sn from r_panel_sn where panel = '{PanelSn}' ) 
                        and id = sn";
                NoBIPQty = int.Parse(DB.ExecSelectOneValue(strsql).ToString());
            }
            else
            {
                errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
            return(NoBIPQty);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 獲取SAMPLEQTY
        /// </summary>
        /// <param name="AQLType"></param>
        /// <param name="LotQty"></param>
        /// <param name="DB"></param>
        /// <returns></returns>
        public int GetSampleQty(string AQLType, int LotQty, OleExec DB)
        {
            string StrSql    = "";
            int    SampleQty = 0;

            if (DBType == DB_TYPE_ENUM.Oracle)
            {
                StrSql    = $@"select case when {LotQty} < sample_qty then {LotQty} else sample_qty end as SAMPLEQTY from 
                     (select * from C_AQLTYPE where LOT_QTY >= {LotQty} order by LOT_QTY) where rownum = 1";
                SampleQty = Convert.ToInt16(DB.ExecSelectOneValue(StrSql)?.ToString());

                return(SampleQty);
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
        }
Ejemplo n.º 11
0
        public bool isPacked(OleExec DB)
        {
            string SNID = this.baseSN.ID;

            string strSql = $@"SELECT COUNT(1) FROM R_SN_PACKING WHERE SN_ID ='{SNID}'";
            int    count;

            if (!Int32.TryParse(DB.ExecSelectOneValue(strSql).ToString(), out count))
            {
                throw new Exception("Err Select !");
            }
            if (count > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Get DB system datetime
        /// </summary>
        /// <param name="DB">OleExec</param>
        /// <param name="dbType">DB_TYPE_ENUM</param>
        /// <returns></returns>
        public static DateTime GetDBDateTime(OleExec DB, DB_TYPE_ENUM dbType)
        {
            string strSql = "select sysdate from dual";

            if (dbType == DB_TYPE_ENUM.Oracle)
            {
                strSql = "select sysdate from dual";
            }
            else if (dbType == DB_TYPE_ENUM.SqlServer)
            {
                strSql = "select get_date() ";
            }
            else
            {
                throw new Exception(dbType.ToString() + " not Work");
            }
            DateTime DBTime = (DateTime)DB.ExecSelectOneValue(strSql);

            return(DBTime);
        }
Ejemplo n.º 13
0
        public Boolean CheckPanelExist(string _panel, OleExec DB)
        {
            string strsql = "";

            if (DBType == DB_TYPE_ENUM.Oracle)
            {
                strsql = $@"select COUNT(ID) from r_panel_sn where panel='{_panel.Replace("'", "''")}'";
                string ID = DB.ExecSelectOneValue(strsql).ToString();
                if (Convert.ToInt32(ID) == 0)
                {
                    return(false);
                }
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
            return(true);
        }
Ejemplo n.º 14
0
        public Row_R_WO_BASE LoadWorkorder(string _WO, OleExec DB)
        {
            string strsql = "";

            if (DBType == DB_TYPE_ENUM.Oracle)
            {
                strsql = $@"select * from r_wo_base where workorderno='{_WO.Replace("'", "''")}'";
                string ID = DB.ExecSelectOneValue(strsql)?.ToString();
                if (ID == null)
                {
                    return(null);
                }
                Row_R_WO_BASE R = (Row_R_WO_BASE)this.GetObjByID(ID, DB);
                return(R);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 15
0
        public Row_R_LOT_STATUS GetSampleLotBySN(string _SN, OleExec DB)
        {
            string           strsql = "";
            Row_R_LOT_STATUS Res    = null;

            if (DBType == DB_TYPE_ENUM.Oracle)
            {
                strsql = $@"select ID from r_lot_status a where exists (select 1 from r_lot_detail b where b.sn = '{_SN.Replace("'", "''")}' and a.id = b.lot_id and a.closed_flag='1' and a.lot_status_flag='0') order by a.id desc";
                string ID = DB.ExecSelectOneValue(strsql)?.ToString();
                if (ID != null)
                {
                    Res = (Row_R_LOT_STATUS)this.GetObjByID(ID, DB);
                }
                return(Res);
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
        }
Ejemplo n.º 16
0
        public Row_R_LOT_STATUS GetLotBySkuAnd(string skuno, string stationName, OleExec DB)
        {
            string           strsql = "";
            Row_R_LOT_STATUS R      = null;

            if (DBType == DB_TYPE_ENUM.Oracle)
            {
                strsql = $@" select ID from r_lot_status where skuno='{skuno}' and SAMPLE_STATION='{stationName}' and closed_flag='0'";
                string ID = DB.ExecSelectOneValue(strsql)?.ToString();
                if (ID != null)
                {
                    R = (Row_R_LOT_STATUS)this.GetObjByID(ID, DB);
                }
                return(R);
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
        }
Ejemplo n.º 17
0
        public bool CheckKPListName(string KPListName, OleExec DB)
        {
            string strSql = $@"select count(1) from c_kp_list where LISTNAME='{KPListName}'";
            string strRet = DB.ExecSelectOneValue(strSql).ToString();

            try
            {
                if (Int32.Parse(strRet) > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ee)
            {
                throw new Exception(strSql + ":" + strRet);
            }
        }
Ejemplo n.º 18
0
        public Row_R_WO_HEADER_TJ GetWo(string _WO, OleExec DB)
        {
            string strsql = "";

            if (DBType == DB_TYPE_ENUM.Oracle)
            {
                strsql = $@"select ID from R_WO_HEADER_TJ where AUFNR='{_WO}'";
                string ID = DB.ExecSelectOneValue(strsql)?.ToString();
                if (ID == null)
                {
                    string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000007", new string[] { "WorkOrder:" + _WO });
                    throw new MESReturnMessage(errMsg);
                }
                Row_R_WO_HEADER_TJ R = (Row_R_WO_HEADER_TJ)this.GetObjByID(ID, DB);
                return(R);
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
        }
Ejemplo n.º 19
0
        public Row_C_REPAIR_ITEMS GetIDByItemName(string _ItemName, OleExec DB)
        {
            string strsql = "";

            if (DBType == DB_TYPE_ENUM.Oracle)
            {
                strsql = $@"select ID from c_repair_items where item_name='{_ItemName.Replace("'", "''")}'";
                string ID = DB.ExecSelectOneValue(strsql)?.ToString();
                if (ID == null)
                {
                    string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000007", new string[] { "ItemName:" + _ItemName });
                    throw new MESReturnMessage(errMsg);
                }
                Row_C_REPAIR_ITEMS R = (Row_C_REPAIR_ITEMS)this.GetObjByID(ID, DB);
                return(R);
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
        }
Ejemplo n.º 20
0
        public Row_R_WO_BASE GetWo(string _WO, OleExec DB)
        {
            string strsql = "";

            if (DBType == DB_TYPE_ENUM.Oracle)
            {
                strsql = $@"select ID from r_wo_base where workorderno='{_WO.Replace("'", "''")}'";
                string ID = DB.ExecSelectOneValue(strsql)?.ToString();
                if (ID == null)
                {
                    string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000007", new string[] { "WorkOrder:" + _WO });
                    throw new MESReturnMessage(errMsg);
                }
                Row_R_WO_BASE R = (Row_R_WO_BASE)this.GetObjByID(ID, DB);
                return(R);
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
        }
Ejemplo n.º 21
0
        public Row_C_SKU_SAMPLE GetBySkuNo(string _SkuNo, string _Station, OleExec DB)
        {
            string strsql = "";

            if (DBType == DB_TYPE_ENUM.Oracle)
            {
                strsql = $@" select ID from c_sku_sample where skuno='{_SkuNo.Replace("'", "''")}' and station_name='{_Station.Replace("'", "''")}'";
                string ID = DB.ExecSelectOneValue(strsql)?.ToString();
                if (ID == null)
                {
                    string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000189", new string[] { _SkuNo, _Station });
                    throw new MESReturnMessage(errMsg);
                }
                Row_C_SKU_SAMPLE R = (Row_C_SKU_SAMPLE)this.GetObjByID(ID, DB);
                return(R);
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
        }
Ejemplo n.º 22
0
        public Row_R_Station GetRowByDisplayName(string DisplayName, OleExec DB)
        {
            string strsql = "";

            if (DBType == DB_TYPE_ENUM.Oracle)
            {
                strsql = $@"select ID from {TableName} where Display_Station_Name = '{DisplayName.Replace("'", "''")}'";
                string ID = DB.ExecSelectOneValue(strsql)?.ToString();
                if (ID == null)
                {
                    string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000007", new string[] { "Station" + DisplayName });
                    throw new MESReturnMessage(errMsg);
                }
                Row_R_Station R = (Row_R_Station)this.GetObjByID(ID, DB);
                return(R);
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
        }
Ejemplo n.º 23
0
        public Row_C_AQLTYPE GetByAqltype(string _Aqltype, OleExec DB)
        {
            string strsql = "";

            if (DBType == DB_TYPE_ENUM.Oracle)
            {
                strsql = $@" select ID from C_AQLTYPE where AQL_TYPE='{_Aqltype.Replace("'", "''")}' ";
                string ID = DB.ExecSelectOneValue(strsql)?.ToString();
                if (ID == null)
                {
                    string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000007", new string[] { "AQLTYPE AT C_AQLTYPE:" + _Aqltype });
                    throw new MESReturnMessage(errMsg);
                }
                Row_C_AQLTYPE R = (Row_C_AQLTYPE)this.GetObjByID(ID, DB);
                return(R);
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 通過SN獲取沒有COLSED的LOT信息
        /// </summary>
        /// <param name="sn"></param>
        /// <param name="DB"></param>
        /// <returns></returns>
        public Row_R_LOT_STATUS GetLotBySNNotCloesd(string sn, OleExec DB)
        {
            string           strsql = "";
            string           id     = "";
            Row_R_LOT_STATUS Res    = null;

            if (DBType == DB_TYPE_ENUM.Oracle)
            {
                strsql = $@"select id from r_lot_status a where a.closed_flag='0' and exists (select 1 from r_lot_detail b 
                                where b.sn = '{sn.Replace("'", "''")}' and a.id = b.lot_id) order by a.id desc";
                id     = DB.ExecSelectOneValue(strsql)?.ToString();
                if (id != null)
                {
                    Res = (Row_R_LOT_STATUS)this.GetObjByID(id, DB);
                }
                return(Res);
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
        }
Ejemplo n.º 25
0
        public bool CheckLotDetailSNStatus(string LotID, string Station, OleExec DB)
        {
            bool      StrRet = false;
            string    strsql = "";
            DataTable dt;

            if (DBType == DB_TYPE_ENUM.Oracle)
            {
                strsql = $@"select count(1) from r_sn where sn in (select sn from r_lot_detail where lot_id='{LotID.Replace("'", "''")}') and next_station<>'{Station}'  AND VALID_FLAG='1'";
                //dt = DB.ExecSelect(strsql).Tables[0];
                int count = Int32.Parse(DB.ExecSelectOneValue(strsql).ToString());
                if (count != 0)
                {
                    StrRet = true;
                }
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
            return(StrRet);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 通過SN 獲取它所在的LOT_NO
        /// </summary>
        /// <param name="DB"></param>
        /// <returns></returns>
        public Row_R_LOT_STATUS GetLotBySNForInLot(string _SN, OleExec DB)
        {
            string           strsql = "";
            Row_R_LOT_STATUS Res    = null;

            if (DBType == DB_TYPE_ENUM.Oracle)
            {
                strsql = $@"select ID from r_lot_status a where a.closed_flag=1 and exists (select 1 from r_lot_detail b where b.sn = '{_SN.Replace("'", "''")}' and a.id = b.lot_id) order by a.id desc";
                string ID = DB.ExecSelectOneValue(strsql)?.ToString();
                if (ID != null)
                {
                    //Modify by LLF 2018-02-07
                    //string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000007", new string[] { "SN:" + _SN });
                    //throw new MESReturnMessage(errMsg);
                    Res = (Row_R_LOT_STATUS)this.GetObjByID(ID, DB);
                }
                return(Res);
            }
            else
            {
                string errMsg = MESReturnMessage.GetMESReturnMessage("MES00000019", new string[] { DBType.ToString() });
                throw new MESReturnMessage(errMsg);
            }
        }
Ejemplo n.º 27
0
        public static string GetNextSN(string RuleName, OleExec DB, string WO)
        {
            Row_C_SN_RULE root = null;
            List <Row_C_SN_RULE_DETAIL> detail = null;

            if (_Root.ContainsKey(RuleName))
            {
                root = _Root[RuleName];
            }
            else
            {
                T_C_SN_RULE TCSR = new T_C_SN_RULE(DB, MESDataObject.DB_TYPE_ENUM.Oracle);
                root = TCSR.GetDataByName(RuleName, DB);
                _Root.Add(RuleName, root);
            }

            if (_Detail.ContainsKey(RuleName))
            {
                detail = _Detail[RuleName];
            }
            else
            {
                T_C_SN_RULE_DETAIL TCSRD = new T_C_SN_RULE_DETAIL(DB, MESDataObject.DB_TYPE_ENUM.Oracle);
                detail = TCSRD.GetDataByRuleID(root.ID, DB);
                _Detail.Add(RuleName, detail);
            }
            string SN        = "";
            bool   ResetFlag = false;

            for (int i = 0; i < detail.Count; i++)
            {
                detail[i].LockMe(DB);
                if (detail[i].INPUTTYPE == "PREFIX")
                {
                    SN += detail[i].CURVALUE;
                }
                else if (detail[i].INPUTTYPE == "YYYY" || detail[i].INPUTTYPE == "MM" || detail[i].INPUTTYPE == "DD")
                {
                    string codeType = detail[i].CODETYPE;
                    List <Row_C_CODE_MAPPING> CodeMapping = null;
                    if (_CodeMapping.ContainsKey(codeType))
                    {
                        CodeMapping = _CodeMapping[codeType];
                    }
                    else
                    {
                        T_C_CODE_MAPPING TCCM = new T_C_CODE_MAPPING(DB, DB_TYPE_ENUM.Oracle);
                        CodeMapping = TCCM.GetDataByName(codeType, DB);
                        if (CodeMapping != null)
                        {
                            _CodeMapping.Add(codeType, CodeMapping);
                        }
                    }
                    string VALUE = null;
                    switch (detail[i].INPUTTYPE)
                    {
                    case "YYYY":
                        VALUE = DateTime.Now.Year.ToString();
                        break;

                    case "MM":
                        VALUE = DateTime.Now.Month.ToString();
                        break;

                    case "DD":
                        VALUE = DateTime.Now.Day.ToString();
                        break;
                    }


                    Row_C_CODE_MAPPING TAG = CodeMapping.Find(T => T.VALUE == VALUE);
                    if (detail[i].CURVALUE != TAG.CODEVALUE)
                    {
                        detail[i].CURVALUE = TAG.CODEVALUE;
                        if (detail[i].RESETSN_FLAG == 1)
                        {
                            ResetFlag = true;
                        }
                    }
                    SN += detail[i].CURVALUE;
                }
                else if (detail[i].INPUTTYPE == "WK")
                {
                    string wk        = detail[i].CODETYPE;
                    string sql       = $@"SELECT TO_CHAR(SYSDATE,'{wk}') FROM DUAL";
                    string currentWK = (string)DB.ExecSelectOneValue(sql);
                    SN += currentWK;
                }
                else if (detail[i].INPUTTYPE == "SQL")
                {
                    string sql = detail[i].CURVALUE;
                    sql = sql.Replace("{WO}", WO);
                    string value = (string)DB.ExecSelectOneValue(sql);
                    SN += value;
                }
                else if (detail[i].INPUTTYPE == "SN")
                {
                    if (ResetFlag)
                    {
                        detail[i].VALUE10 = detail[i].RESETVALUE;
                    }
                    string codeType = detail[i].CODETYPE;
                    List <Row_C_CODE_MAPPING> CodeMapping = null;
                    if (_CodeMapping.ContainsKey(codeType))
                    {
                        CodeMapping = _CodeMapping[codeType];
                    }
                    else
                    {
                        T_C_CODE_MAPPING TCCM = new T_C_CODE_MAPPING(DB, DB_TYPE_ENUM.Oracle);
                        CodeMapping = TCCM.GetDataByName(codeType, DB);
                        if (CodeMapping != null)
                        {
                            _CodeMapping.Add(codeType, CodeMapping);
                        }
                    }
                    int curValue = int.Parse(detail[i].VALUE10);
                    curValue++;
                    detail[i].VALUE10 = curValue.ToString();
                    int    T  = CodeMapping.Count;
                    string sn = "";

                    while (curValue / T != 0)
                    {
                        int R = curValue % T;
                        sn       = CodeMapping[R].CODEVALUE + sn;
                        curValue = curValue / T;
                    }
                    sn = CodeMapping[curValue].CODEVALUE + sn;
                    if (sn.Length < detail[i].CURVALUE.Length)
                    {
                        for (int k = 0; detail[i].CURVALUE.Length != sn.Length; k++)
                        {
                            sn = "0" + sn;
                        }
                    }
                    if (sn.Length > detail[i].CURVALUE.Length)
                    {
                        throw new Exception("生成的SN超過最大值!");
                    }

                    detail[i].CURVALUE = sn;
                    SN += detail[i].CURVALUE;
                }
                int T1 = 0;
                detail[i].EDIT_TIME = DateTime.Now;
                string ret = DB.ExecSQL(detail[i].GetUpdateString(DB_TYPE_ENUM.Oracle));
                if (!Int32.TryParse(ret, out T1))
                {
                    throw new Exception("更新序列值出錯!" + ret);
                }
            }
            int T2 = 0;

            root.CURVALUE = SN;
            string ret1 = DB.ExecSQL(root.GetUpdateString(DB_TYPE_ENUM.Oracle));

            if (!Int32.TryParse(ret1, out T2))
            {
                throw new Exception("更新序列值出錯!" + ret1);
            }
            return(SN);
        }
Ejemplo n.º 28
0
        public int GetCount(OleExec DB)
        {
            string strSQL = $@"select count(1) from R_SN_PACKING where PACK_ID = '{DATA.ID}'";

            return(int.Parse(DB.ExecSelectOneValue(strSQL).ToString()));
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Get Work Class
        /// </summary>
        /// <param name="oleDB">OleExec</param>
        /// <param name="DBtype">DB_TYPE_ENUM</param>
        /// <returns></returns>
        public string GetWorkClass(OleExec oleDB, DB_TYPE_ENUM DBtype)
        {
            string   strSql = "select sysdate from dual";
            DateTime sysdate;
            DateTime start_time;
            DateTime end_time;
            DateTime tempTime1  = Convert.ToDateTime("00:00:00");
            DateTime tempTime24 = Convert.ToDateTime("23:59:59");
            string   workClass  = "";
            string   sql        = $@"select * from c_work_class ";

            if (DBtype == DB_TYPE_ENUM.Oracle)
            {
                strSql = "select sysdate from dual";
            }
            else if (DBtype == DB_TYPE_ENUM.SqlServer)
            {
                strSql = "select get_date() ";
            }
            else
            {
                throw new Exception(DBtype.ToString() + " not Work");
            }
            try
            {
                sysdate = Convert.ToDateTime(oleDB.ExecSelectOneValue(strSql));
                DataSet dsWorkClass = oleDB.ExecSelect(sql);
                foreach (DataRow row in dsWorkClass.Tables[0].Rows)
                {
                    start_time = Convert.ToDateTime(row["START_TIME"].ToString());
                    end_time   = Convert.ToDateTime(row["End_TIME"].ToString());
                    if (DateTime.Compare(start_time, end_time) > 0)
                    {
                        if ((DateTime.Compare(sysdate, tempTime1) >= 0) && (DateTime.Compare(sysdate, end_time) <= 0))
                        {
                            workClass = row["NAME"].ToString();
                            break;
                        }
                        else if ((DateTime.Compare(sysdate, tempTime24) >= 0) && (DateTime.Compare(sysdate, start_time) <= 0))
                        {
                            workClass = row["NAME"].ToString();
                            break;
                        }
                    }
                    else
                    {
                        if ((DateTime.Compare(sysdate, start_time) >= 0) && (DateTime.Compare(sysdate, end_time) <= 0))
                        {
                            workClass = row["NAME"].ToString();
                            break;
                        }
                    }
                }
                if (string.IsNullOrEmpty(workClass))
                {
                    throw new Exception("Get Work Class Fail");
                }
                return(workClass);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 30
0
        public int GetSnCount(OleExec DB)
        {
            string strSQL = $@" select count(1) from R_SN_PACKING A,R_PACKING B WHERE A.PACK_ID=B.ID AND B.PARENT_PACK_ID='{DATA.ID}' ";

            return(int.Parse(DB.ExecSelectOneValue(strSQL).ToString()));
        }