public void FillData(DataSet dataSet) { var curColumn = 0; var curRow = 0; var showRoCo = true; try { var owList = new List <OverWork>(); var dataTable = dataSet.Tables[0]; for (; curRow < dataTable.Rows.Count; curRow++) { curColumn = 0; showRoCo = true; var number = dataTable.Rows[curRow][curColumn++]?.ToString(); var epNo = dataTable.Rows[curRow][curColumn++]?.ToString(); var epName = dataTable.Rows[curRow][curColumn++]?.ToString(); var startTime = DateTime.Parse(dataTable.Rows[curRow][curColumn++]?.ToString()); var endTime = DateTime.Parse(dataTable.Rows[curRow][curColumn++]?.ToString()); var applyTime = int.Parse(dataTable.Rows[curRow][curColumn++].ToString()); //var reduceTime = DateTime.Parse(dataTable.Rows[ro][curColumn++]?.ToString()); var typeOverWork = dataTable.Rows[curRow][curColumn++]?.ToString(); var IsOnduty = int.Parse(dataTable.Rows[curRow][curColumn++].ToString()); var IsOffduty = int.Parse(dataTable.Rows[curRow][curColumn++].ToString()); var description = dataTable.Rows[curRow][curColumn++]?.ToString(); var creator = dataTable.Rows[curRow][curColumn]?.ToString(); showRoCo = false; var foundEp = ModelSource.Employees.ToList() .Find(ep => ep.EmployeeNO == epNo && ep.EmployeeBaseInfo.EmployName == epName); if (foundEp == null) { throw new Exception($"未找到员工:{epNo}/{epName}"); } var o = new OverWork { Number = number, Employee = foundEp, BeginDateTime = startTime.ToString(CultureInfo.InvariantCulture), EndDateTime = endTime.ToString(CultureInfo.InvariantCulture), ApplyTime = applyTime.ToString(), //ReduceTime = reduceTime.ToString(CultureInfo.InvariantCulture), OverWorkType = typeOverWork, IsOnDuty = IsOnduty.ParseToBoolean(), IsOffDuty = IsOffduty.ParseToBoolean(), Description = description, Creator = creator }; owList.Add(o); ModelSource.OverWorks.AddWithoutEntity(o); //Console.WriteLine(cellValue is DBNull ? "Empty" : cellValue); } (ModelSource.OverWorks.EntityCtrl as OverWorkControl)?.ImportData(owList); } catch (Exception exception) { //第一行为列名, 第二行开始; 代码从0开始, 显示从1开始; 计算列时catch之前已经被++,所以不用+1 var failTip = showRoCo? $"(行:{curRow + 2} 列:{curColumn})" : string.Empty; MessageBox.Show($"{exception.Message}\r\n{failTip}", "加班单导入失败!"); StatusConsole.WriteLine("加班单导入失败! " + failTip); } }
private void OnMainWindowLoaded() { ShowExpireTip(); CurUserName = ModelSource.CurrentUser.UserName; CurUserType = ModelSource.CurrentUser.SystemRole.Name; StatusConsole.WriteLine(CurUserName + "已登录, 欢迎使用!"); }
private static bool ValidateSingleFcnt(uint?fCntStart, uint?fCntStartRep, uint?fCntResetCounter, uint?fCntResetCounterRep, string fCntStartType) { if (fCntStart == null) { // fCntStart not set. Nothing to do. return(true); } // fCntStartRep not null if (fCntStartRep == null || fCntStart > fCntStartRep) { StatusConsole.WriteLine(MessageType.Info, $"{fCntStartType} {fCntStart} will be set on gateway."); return(true); } // fCntStartRep not null, fCntStartRep not null, fCntStart <= fCntStartRep if (fCntResetCounter == null) { StatusConsole.WriteLine(MessageType.Warning, $"{fCntStartType} {fCntStart} will not be set on gateway. Reported {fCntStartType} {fCntStartRep} is larger or equal and FCntResetCounter is not set."); return(true); } // fCntStartRep not null, fCntStartRep not null, fCntStart <= fCntStartRep, // fCntResetCounter not null if (fCntResetCounterRep == null || fCntResetCounter > fCntResetCounterRep) { StatusConsole.WriteLine(MessageType.Info, $"{fCntStartType} {fCntStart} will be set on gateway."); return(true); } // fCntStartRep not null, fCntStartRep not null, fCntStart <= fCntStartRep, // fCntResetCounter not null, fCntResetCounterRep not null, fCntResetCounter <= fCntResetCounterRep StatusConsole.WriteLine(MessageType.Warning, $"{fCntStartType} {fCntStart} will not be set on gateway. Reported {fCntStartType} {fCntStartRep} is larger or equal and FCntResetCounter {fCntResetCounter} is not larger than reported FCntResetCounter {fCntResetCounterRep}."); return(true); }
public static bool ValidateSensorDecoder(string sensorDecoder) { var isValid = true; var isWarning = false; if (sensorDecoder == null) { StatusConsole.WriteLine(MessageType.Error, "SensorDecoder is missing."); return(false); } if (sensorDecoder == string.Empty) { StatusConsole.WriteLine(MessageType.Info, "SensorDecoder is empty. No decoder will be used."); return(true); } if (sensorDecoder.StartsWith("http", StringComparison.OrdinalIgnoreCase) || sensorDecoder.Contains('/')) { if (!Uri.TryCreate(sensorDecoder, UriKind.Absolute, out Uri validatedUri)) { StatusConsole.WriteLine(MessageType.Error, "SensorDecoder has an invalid URL."); isValid = false; } // if (validatedUri.Host.Any(char.IsUpper)) if (!sensorDecoder.StartsWith(validatedUri.Scheme, StringComparison.OrdinalIgnoreCase) || sensorDecoder.IndexOf(validatedUri.Host) != validatedUri.Scheme.Length + 3) { StatusConsole.WriteLine(MessageType.Error, "SensorDecoder Hostname must be all lowercase."); isValid = false; } if (validatedUri.AbsolutePath.IndexOf("/api/") < 0) { StatusConsole.WriteLine(MessageType.Warning, "SensorDecoder is missing \"api\" keyword."); isWarning = true; } } if (!isValid || isWarning) { StatusConsole.WriteLine(MessageType.Info, "Make sure the URI based SensorDecoder Twin desired property looks like \"http://containername/api/decodername\"."); } else { StatusConsole.WriteLine(MessageType.Info, $"SensorDecoder {sensorDecoder} is valid."); } return(isValid); }
public bool UpDataEntity() { try { var effect = Factory.Update(); ParaList.Add(effect.ToString()); WriteLog("更新成功,更新记录"); StatusConsole.WriteLine("已更新记录"); return(true); } catch (Exception e) { WriteLogFalse("更新失败", e); StatusConsole.WriteLine("更新失败"); return(false); } }
public virtual bool AddEntity(T t) { InitLogNeed(t); try { Factory.Add(t); WriteLog("添加成功"); StatusConsole.WriteLine("添加成功"); return(true); } catch (Exception e) { WriteLogFalse("添加失败", e); StatusConsole.WriteLine("添加失败"); return(false); } }
public bool DeleteEntity(T t) { InitLogNeed(t); if (!DeleteProtected(t)) { WriteDeleteProtectedLog("删除失败"); StatusConsole.WriteLine("删除失败! (对象受删除保护)"); return(false); } try { Factory.Delete(t); WriteLog("删除成功"); StatusConsole.WriteLine("删除成功"); return(true); } catch (Exception e) { WriteLogFalse("删除失败", e); StatusConsole.WriteLine("删除失败"); return(false); } }
public bool ReadConfig() { string connectionString, netId; Console.WriteLine("Reading configuration file \"settings.json\"..."); // Read configuration file settings.json try { var configurationBuilder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("settings.json", optional: false, reloadOnChange: true) .Build(); connectionString = configurationBuilder["IoTHubConnectionString"]; netId = configurationBuilder["NetId"]; } catch (Exception ex) { StatusConsole.WriteLine(MessageType.Error, $"{ex.Message}"); StatusConsole.WriteLine(MessageType.Info, "The file should have the following structure: { \"IoTHubConnectionString\" : \"HostName=xxx.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=xxx\" }"); return(false); } // Validate connection setting if (string.IsNullOrEmpty(connectionString)) { StatusConsole.WriteLine(MessageType.Error, "Connection string not found in settings file. The format should be: { \"IoTHubConnectionString\" : \"HostName=xxx.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=xxx\" }."); return(false); } else { // Just show IoT Hub Hostname if (this.GetHostFromConnectionString(connectionString, out string hostName)) { StatusConsole.WriteLine(MessageType.Info, $"Using IoT Hub: {hostName}"); } else { StatusConsole.WriteLine(MessageType.Error, "Invalid connection string in settings.json. Can not find \"HostName=\". The file should have the following structure: { \"IoTHubConnectionString\" : \"HostName=xxx.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=xxx\" }."); return(false); } } // Validate NetId setting if (string.IsNullOrEmpty(netId)) { netId = ValidationHelper.CleanNetId(Constants.DefaultNetId.ToString()); StatusConsole.WriteLine(MessageType.Info, $"NetId is not set in settings file. Using default {netId}."); } else { netId = ValidationHelper.CleanNetId(netId); if (ValidationHelper.ValidateHexStringTwinProperty(netId, 3, out string customError)) { StatusConsole.WriteLine(MessageType.Info, $"Using NetId {netId} from settings file."); } else { var netIdBad = netId; netId = ValidationHelper.CleanNetId(Constants.DefaultNetId.ToString()); StatusConsole.WriteLine(MessageType.Warning, $"NetId {netIdBad} in settings file is invalid. {customError}."); StatusConsole.WriteLine(MessageType.Warning, $"Using default NetId {netId} instead."); } } StatusConsole.WriteLine(MessageType.Info, $"To override, use --netid parameter."); this.NetId = netId; // Create Registry Manager using connection string try { this.RegistryManager = RegistryManager.CreateFromConnectionString(connectionString); } catch (Exception ex) { StatusConsole.WriteLine(MessageType.Error, $"Can not connect to IoT Hub (possible error in connection string): {ex.Message}."); return(false); } Console.WriteLine("done."); return(true); }