Ejemplo n.º 1
0
        private void 故障碼View_Show()
        {
            try
            {
                if (GlobalData.ListView_Show_OnCode != GlobalData.ListView_Show_OnCode_比對用)
                {
                    listView1.Items.Clear();
                    GlobalData.ListView_Show_OnCode_比對用 = string.Empty;
                    string   ListTime = string.Empty; string ListMsg = string.Empty; string Err = string.Empty;
                    string[] ErrorStrArray = GlobalData.ListView_Show_OnCode.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    int      ErrorNum      = ErrorStrArray.Length;
                    if (ErrorNum >= 1)
                    {
                        for (int i = 0; i < ErrorNum; i++)
                        {
                            string Error_only_Str_Temp = ErrorStrArray[i];
                            int    one, two;
                            string numStr1 = Error_only_Str_Temp.Substring(0, 3);
                            string numStr2 = APP.右邊開始取字串(Error_only_Str_Temp, 2);
                            one      = Convert.ToInt32(numStr1) - DmTable.Err_HR_點位起始;
                            two      = Convert.ToInt32(numStr2);
                            ListTime = GlobalData.ALL_Error[one, two, 0];
                            ListMsg  = GlobalData.ALL_Error[one, two, 1];
                            Err      = Error_only_Str_Temp;
                            if (!string.IsNullOrEmpty(ListTime) && !string.IsNullOrEmpty(ListMsg))
                            {
                                DataRow row = GlobalData.dvTable_All_Error.NewRow();
                                row[0] = ListTime;
                                row[1] = ListMsg;
                                row[2] = Err;

                                GlobalData.dvTable_All_Error.Rows.Add(row);
                                GlobalData.dvTable_All_Error.DefaultView.Sort = "Time DESC";
                                GlobalData.dvTable_All_Error = GlobalData.dvTable_All_Error.DefaultView.ToTable();
                            }
                        }
                        foreach (DataRow row in GlobalData.dvTable_All_Error.Rows)
                        {
                            ListViewItem item = new ListViewItem(row[0].ToString());
                            for (int x = 1; x < GlobalData.dvTable_All_Error.Columns.Count; x++)
                            {
                                item.SubItems.Add(row[x].ToString());
                            }
                            listView1.Items.Add(item);
                        }

                        GlobalData.dvTable_All_Error.Rows.Clear();
                        GlobalData.ListView_Show_OnCode_比對用 = GlobalData.ListView_Show_OnCode.Trim();
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception錯誤");
            }
        }
Ejemplo n.º 2
0
        private void 紀錄_寫入故障紀錄(string ON_OFF, string alert)
        {
            try
            {
                IErrorDescriptionService errorDescriptionService = new ErrorDescriptionService();
                ResponseModel            responseModel           = errorDescriptionService.GetAllData();
                List <string>            errorList = alert.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList();
                foreach (var errorId in errorList)
                {
                    ErrorDescription list = responseModel.ErrorDescriptionList.Where(x => x.ErrorID == errorId).FirstOrDefault();
                    if (!string.IsNullOrEmpty(list.ChDescription))
                    {
                        int one = Convert.ToInt32(list.ErrorID.Substring(0, 3)) - DmTable.Err_HR_點位起始;
                        int two = Convert.ToInt32(APP.右邊開始取字串(list.ErrorID, 2));
                        if (ON_OFF == "ON")
                        {
                            GlobalData.ALL_Error[one, two, 0] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                            GlobalData.ALL_Error[one, two, 1] = list.ChDescription;
                            GlobalData.ALL_Error[one, two, 4] = list.ErrorID;
                        }
                        else
                        {
                            string startTime = GlobalData.ALL_Error[one, two, 0];
                            string endTime   = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                            string message   = GlobalData.ALL_Error[one, two, 1];

                            // 寫入DB
                            IRecErrorService recErrorService = new RecErrorService();
                            recErrorService.AddData(new RecError
                            {
                                StartTime = Convert.ToDateTime(startTime),
                                EndTime   = Convert.ToDateTime(endTime),
                                ErrorID   = errorId,
                                Message   = message,
                                UserName  = GlobalParameter.UserName
                            });

                            // 寫出txt檔
                            string month     = string.Format("{0}月", DateTime.Now.Month.ToString());
                            string fileName  = string.Format("ErrorCode{0}.txt", DateTime.Now.ToString("yyyy/MM/dd"));
                            string pathWrite = Path.Combine("C:", month, fileName);
                            string content   = string.Format("{0},{1},{2},{3}", startTime, endTime, errorId, message);
                            File.AppendAllText(pathWrite, content, Encoding.Default);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception錯誤");
            }
        }