//获取错误单元 string GetErrorCell(Hashtable hashtable) { try { if (hashtable == null) { return(""); } if (hashtable.Keys == null) { return(""); } foreach (string key in hashtable.Keys) { if (hashtable[key] == null) { string str = "相机" + g_NoCamera.ToString() + "处理异常:"; BaseParComprehensive baseParComprehensive = g_BaseParComprehensive.GetCellClass(key); string annotation = baseParComprehensive.Annotation; g_UCAlarm.AddInfo(str + key + ":" + annotation); g_UCStateWork.AddInfo(str + key + ":" + annotation); } } return(""); } catch (Exception ex) { Log.L_I.WriteError(NameClass, ex); return(""); } }
/// <summary> /// 通用state /// </summary> /// <param name="info"></param> public static void ShowState(string info) { try { if (info == "") { return; } if (!ParStateAndAlarm.P_I.BlAutoShow) { ParStateAndAlarm.P_I.BlShowMain = true; } if (ParStateAndAlarm.P_I.BlShowMain) { g_UCStateWork.AddInfo(info); } if (ParStateAndAlarm.P_I.BlAutoShow) { if (WinStateAndAlarm.GetWinInst() != null) { WinStateAndAlarm.GetWinInst().AddStateInfo(info); } } } catch (Exception ex) { Log.L_I.WriteError("WinInitMain", ex); } }
/// <summary> /// 删除旧型号 /// </summary> void DelteOldImage(BaseParDelFolder baseParDelFolder, UCStateWork uCStateWork) { try { DateTime dt = DateTime.Now; DateTime dtStd = dt.AddDays(-baseParDelFolder.Num); //用时间命名 string Year = dtStd.Year.ToString(); string Month = dtStd.Month.ToString().PadLeft(2, '0'); string Day = dtStd.Day.ToString().PadLeft(2, '0'); string date = Year + "-" + Month + "-" + Day + "\\"; DirectoryInfo strBaseLog = new DirectoryInfo(baseParDelFolder.PathFolder); //包含的文件夹 foreach (DirectoryInfo dirModel in strBaseLog.GetDirectories()) { //删除除当前型号之外的型号图片文件 if (dirModel.Name != ComConfigPar.C_I.NameModel) { foreach (DirectoryInfo dirDate in dirModel.GetDirectories()) { string dateOld = dirDate.Name; DateTime dtOld; if (DateTime.TryParse(dateOld, out dtOld)) { TimeSpan ts = dtOld.Subtract(dtStd); if ((int)ts.TotalDays < 0) //如果日期比删除指定日期提前,则删除 { Directory.Delete(dirDate.FullName, true); //删除文件夹,以及子文件夹子文件 uCStateWork.AddInfo(string.Format("根据设定,删除多余文件:{0}", dirDate.FullName)); } } } } } } catch (Exception ex) { Log.L_I.WriteError(NameClass, ex); } }
/// <summary> /// 监控文件是否可以删除 /// </summary> /// <param name="uCStateWork"></param> public void DelteFolder(UCStateWork uCStateWork) { try { bool blDel1 = true;//是否允许删除 foreach (BaseParDelFolder baseParDelFolder in ParDelFolder.P_I.BaseParDelFolder_L) { #region 是否定时删除 int hour = DateTime.Now.Hour; int minute = DateTime.Now.Minute; //时间1 if (ParDelFolder.P_I.BlDel1) { if (hour == ParDelFolder.P_I.Hour1 && minute > ParDelFolder.P_I.Minute1) { blDel1 = true; } else { blDel1 = false; } } //时间2 bool blDel2 = true;//是否允许删除 if (ParDelFolder.P_I.BlDel2) { if (hour == ParDelFolder.P_I.Hour2 && minute > ParDelFolder.P_I.Minute2) { blDel2 = true; } else { blDel2 = false; } } #endregion 是否定时删除 if (blDel1 || blDel2) { //删除本地记录 string path = baseParDelFolder.PathFolder; if (baseParDelFolder.Annotation.Contains("未使用型号图片记录") && baseParDelFolder.BlExcute) { //DelteOldImage(baseParDelFolder, uCStateWork); } else if (baseParDelFolder.Annotation.Contains("算法单元节拍") && baseParDelFolder.BlExcute) { for (int i = 0; i < 8; i++) { //string pathDel = path + "Camera" + (i + 1).ToString() + "\\"; //if (Log.L_I.GetDirectoryNum(pathDel) > baseParDelFolder.Num) //{ // Log.L_I.DeleteDir(pathDel, baseParDelFolder.Num); // uCStateWork.AddInfo(string.Format("根据设定,删除多余文件:{0}", pathDel)); //} } } else if (Log.L_I.GetDirectoryNum(path) > baseParDelFolder.Num) { if (baseParDelFolder.BlExcute)//是否执行删除文件 { Log.L_I.DeleteDir(path, baseParDelFolder.Num); uCStateWork.AddInfo(string.Format("根据设定,删除多余文件:{0}", baseParDelFolder.PathFolder)); } } //删除注册表记录 ClearNumRecordCell();//删除单元格运行计数 } } } catch (Exception ex) { Log.L_I.WriteError(NameClass, ex); } }