public Datas Get(string Id, SettingsModel settingsModel, ref string msg) { if (State == -1) { return(null); } var db = new DbContext(); Datas datas = db.DatasDb.GetById(Id); if (datas != null) { return(datas); } datas = new Datas { Id = Id, StationId = settingsModel.StationId, Color = settingsModel.Color, Region = settingsModel.Region, Project = settingsModel.Project, Location = settingsModel.Location, Pahse = settingsModel.Pahse, CreateDate = DateTime.Now }; var ps = typeof(Datas).GetProperties(); foreach (var one in Datas) { var d = one.Value; if (d.Data == null) { continue; } var map = Config.DataMapping.FirstOrDefault(p => p.CAMNO.Contains(one.Key)); if (map != null) { foreach (var mapping in map.Mapping) { if (mapping.Name.ToLower().IndexOf("ins") > -1) { continue; } var pinfo = ps.Where(p => p.Name.ToLower() == mapping.Name.ToLower()).FirstOrDefault(); if (pinfo == null) { continue; } var v = d.Data[mapping.Index]; pinfo.SetValue(datas, v, null); } } for (int i = 0; i < Config.Station.Count; i++) { var pinfo = ps.Where(p => p.Name.ToLower() == $"ins{i + 1}code").FirstOrDefault(); var npinfo = ps.Where(p => p.Name.ToLower() == $"ins{i + 1}name").FirstOrDefault(); if (pinfo == null) { continue; } var users = GetTypeData(i + 1, d.Data); if (users != null) { pinfo.SetValue(datas, users.UserCode, null); npinfo.SetValue(datas, users.UserNumber, null); } } } if (string.IsNullOrEmpty(msg)) { db.DatasDb.Insert(datas); } else { return(null); } return(datas); }