Exemplo n.º 1
0
        /// <summary>
        /// Get alarm message
        /// </summary>
        /// <param name="node_id"> 設備系統代碼 </param>
        /// <param name="error_message"> 錯誤訊息 </param>
        /// <returns></returns>
        public AlarmMessage Get(string node_id, string error_message)
        {
            AlarmMessage alarm;
            DataTable    dtTemp;

            string strAlarmAxis        = string.Empty;
            string strAlarmAxisEnglish = string.Empty;
            string strCode28           = string.Empty;
            //int itFirst = 0;
            //int itCode28 = 0;
            string strErrorCode = string.Empty;
            string strSql       = string.Empty;
            DBUtil dBUtil       = new DBUtil();

            string supplier = string.Empty;
            string eqp_type = string.Empty;
            string address  = string.Empty;

            try
            {
                strSql = "select * from config_node where node_id = '" + node_id + "' and equipment_model_id = '" + SANWA.Utility.Config.SystemConfig.Get().SystemMode + "'";
                dtTemp = dBUtil.GetDataTable(strSql, null);

                if (dtTemp.Rows.Count > 0)
                {
                    supplier = dtTemp.Rows[0]["vendor"].ToString();
                    eqp_type = dtTemp.Rows[0]["node_type"].ToString();
                    address  = dtTemp.Rows[0]["sn_no"].ToString();
                }
                else
                {
                    supplier = "SANWA";
                    eqp_type = "SYSTEM";
                    address  = "0";
                }

                alarm = new AlarmMessage();
                alarm.Return_Code_ID = error_message;

                // * Special rule
                switch (supplier.ToUpper())
                {
                //case "SANWA":

                //    int s = 0;
                //    if (int.TryParse(error_message.Substring(0, 1), out s))
                //    {
                //        itFirst = s;
                //        strCode28 = Convert.ToString(itFirst, 2);
                //        itCode28 = int.Parse(strCode28.Substring(strCode28.Length - 1, 1));

                //        if (itCode28 == 1)
                //        {
                //            strSql = "SELECT * " +
                //                        "FROM config_list_item " +
                //                        "WHERE list_type = 'SANWA_CODE' " +
                //                        "  AND list_value = '" + error_message.Substring(5, 1) + "'" +
                //                        "ORDER BY sort_sequence ASC";

                //            dtTemp = dBUtil.GetDataTable(strSql, null);

                //            if (dtTemp.Rows.Count > 0)
                //            {
                //                strAlarmAxis = dtTemp.Rows[0]["list_name"].ToString();
                //                strAlarmAxisEnglish = dtTemp.Rows[0]["list_name_en"].ToString();
                //            }
                //            else
                //            {
                //                throw new Exception("SANWA.Utility.AlarmMapping\r\nException: Alarm Axis Code not exists.");
                //            }

                //            strErrorCode = error_message.Substring(0, 5) + "0" + error_message.Substring(6, 2);

                //        }
                //        else
                //        {
                //            strErrorCode = error_message;
                //        }
                //    }
                //    else
                //    {
                //        strErrorCode = error_message;
                //    }

                //    break;

                //case "TDK":
                //case "KAWASAKI":
                //case "ATEL":

                //    strErrorCode = error_message;

                //    break;

                //case "ASYST":

                //    for (int i = 0; i < error_message.Split(' ').Length; i++)
                //    {
                //        if (i >= 2)
                //        {
                //            if (strErrorCode.Length == 0)
                //            {
                //                strErrorCode = error_message.Split(' ')[i].ToString();
                //            }
                //            else
                //            {
                //                strErrorCode = strErrorCode + " " + error_message.Split(' ')[i].ToString();
                //            }
                //        }
                //    }

                //    break;

                default:

                    strErrorCode = error_message;

                    break;
                }

                var query = (from a in dtCode.AsEnumerable()
                             where a.Field <string>("node_type") == eqp_type.ToUpper() &&
                             a.Field <string>("vendor") == supplier.ToUpper() &&
                             a.Field <string>("return_code").ToUpper() == strErrorCode.ToUpper() &&
                             a.Field <string>("device_address_id") == address
                             select a).ToList();

                if (query.Count > 0)
                {
                    dtTemp                   = query.CopyToDataTable();
                    alarm.CodeID             = strAlarmAxis == string.Empty ? dtTemp.Rows[0]["sys_code_id"].ToString() : dtTemp.Rows[0]["device_code_id"].ToString() + alarm.Return_Code_ID;
                    alarm.IsStop             = dtTemp.Rows[0]["Is_stop"].ToString() == "Y" ? true : false;
                    alarm.Code_Type          = dtTemp.Rows[0]["return_code_type"].ToString();
                    alarm.Code_Name          = dtTemp.Rows[0]["Code_Name"].ToString();
                    alarm.Code_Cause         = strAlarmAxis == string.Empty ? dtTemp.Rows[0]["Code_Desc"].ToString() : strAlarmAxis + " " + dtTemp.Rows[0]["Code_Desc"].ToString();
                    alarm.Code_Cause_English = strAlarmAxisEnglish == string.Empty ? dtTemp.Rows[0]["Code_Desc_EN"].ToString() : strAlarmAxisEnglish + " " + dtTemp.Rows[0]["Code_Desc_EN"].ToString();
                    alarm.Position           = dtTemp.Rows[0]["location"].ToString();
                    alarm.Code_Group         = dtTemp.Rows[0]["category"].ToString();
                }
                else
                {
                    alarm.CodeID             = error_message;
                    alarm.IsStop             = false;
                    alarm.Code_Type          = error_message;
                    alarm.Code_Name          = error_message;
                    alarm.Code_Cause         = "未知";
                    alarm.Code_Cause_English = "unknown";
                    alarm.Position           = string.Empty;
                    alarm.Code_Group         = "UNDEFINITION";
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }

            return(alarm);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get alarm message
        /// </summary>
        /// <param name="supplier"> 設備供應商 </param>
        /// <param name="eqp_type"> 設備種類 </param>
        /// <param name="error_message"> 錯誤訊息 </param>
        /// <returns></returns>
        public AlarmMessage Get(string supplier, string eqp_type, string error_message)
        {
            AlarmMessage alarm;
            DataTable    dtTemp;

            string strAlarmType        = string.Empty;
            string strAlarmCode        = string.Empty;
            string strAlarmAxis        = string.Empty;
            string strAlarmAxisEnglish = string.Empty;
            string strCode28           = string.Empty;
            int    itFirst             = 0;
            int    itCode28            = 0;
            string strErrorCode        = string.Empty;

            try
            {
                alarm = new AlarmMessage();

                var query = (from a in dtCode.AsEnumerable()
                             where a.Field <string>("Category_ID") == "EquipmentAlarmCode" &&
                             a.Field <string>("Code_Type") == string.Format("{0}.{1}", supplier.ToUpper(), eqp_type.ToUpper())
                             select a).ToList();

                dtTemp = query.CopyToDataTable();

                if (dtTemp.Rows.Count > 0)
                {
                    strAlarmType = dtTemp.Rows[0]["Code_ID"].ToString();
                    alarm.CodeID = string.Format("{0}{1}", strAlarmType, error_message);
                }
                else
                {
                    throw new Exception(string.Format("SANWA.Utility.AlarmMapping\r\nException: {0} {1} Alarm type not exists.", supplier.ToUpper(), eqp_type.ToUpper()));
                }

                // * Special rule
                switch (supplier.ToUpper())
                {
                case "SANWA":

                    itFirst   = int.Parse(error_message.Substring(0, 1));
                    strCode28 = Convert.ToString(itFirst, 2);
                    itCode28  = int.Parse(strCode28.Substring(strCode28.Length - 1, 1));

                    if (itCode28 == 1)
                    {
                        query = null;
                        query = (from a in dtCode.AsEnumerable()
                                 where a.Field <string>("Category_ID") == "AxisCode" &&
                                 a.Field <string>("Code_ID") == error_message.Substring(5, 1)
                                 select a).ToList();

                        dtTemp = query.CopyToDataTable();

                        if (dtTemp.Rows.Count > 0)
                        {
                            strAlarmAxis        = dtTemp.Rows[0]["Code_Cause"].ToString();
                            strAlarmAxisEnglish = dtTemp.Rows[0]["Code_Cause_English"].ToString();
                        }
                        else
                        {
                            throw new Exception("SANWA.Utility.AlarmMapping\r\nException: Alarm Axis Code not exists.");
                        }

                        strErrorCode = error_message.Substring(0, 5) + "0" + error_message.Substring(6, 2);
                    }
                    else
                    {
                        strErrorCode = error_message;
                    }

                    break;

                case "TDK":

                    strErrorCode = error_message;

                    break;

                default:

                    strErrorCode = error_message;

                    break;
                }


                query = null;
                query = (from a in dtCode.AsEnumerable()
                         where a.Field <string>("Category_ID") == strAlarmType &&
                         a.Field <string>("Code_ID") == strErrorCode
                         select a).ToList();

                dtTemp = query.CopyToDataTable();

                if (dtTemp.Rows.Count > 0)
                {
                    alarm.Code_Type          = dtTemp.Rows[0]["Code_Type"].ToString();
                    alarm.Code_Name          = dtTemp.Rows[0]["Code_Name"].ToString();
                    alarm.Code_Cause         = strAlarmAxis == string.Empty ? dtTemp.Rows[0]["Code_Cause"].ToString() : strAlarmAxis + " " + dtTemp.Rows[0]["Code_Cause"].ToString();
                    alarm.Code_Cause_English = strAlarmAxisEnglish == string.Empty ? dtTemp.Rows[0]["Code_Cause_English"].ToString() : strAlarmAxisEnglish + " " + dtTemp.Rows[0]["Code_Cause_English"].ToString();
                }
                else
                {
                    throw new Exception("SANWA.Utility.AlarmMapping\r\nException: Alarm Code not exists.");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }

            return(alarm);
        }