public EmployeeImportResults Import(ImportRecord importRecord) { try { using (var db = GetDbContext()) { db.Configuration.AutoDetectChangesEnabled = false; db.Configuration.ValidateOnSaveEnabled = false; db.Imports.Add(importRecord); db.SaveChanges(); return(new EmployeeImportResults { ImportId = importRecord.Id, EmployeeImportCount = importRecord.Employees.Count, ImportedBy = importRecord.CreatedBy, ImportDate = importRecord.CreateDate, Source = importRecord.Source }); } } catch (Exception ex) { _logger.LogError($"Failed employee Import", ex); throw; } }
private static string DisplayImport(ImportRecord record) { return (record.TargetKind + ":" + (record.Alias != null ? $" alias='{record.Alias}'" : "") + (record.TargetAssembly != null ? $" assembly='{record.TargetAssembly}'" : "") + (record.TargetAssemblyAlias != null ? $" assembly-alias='{record.TargetAssemblyAlias}'" : "") + (record.TargetType != null ? $" type='{record.TargetType}'" : "") + (record.TargetString != null ? $" string='{record.TargetString}'" : "")); }
private static string DisplayImport(ImportRecord record) { return record.TargetKind + ":" + (record.Alias != null ? $" alias='{record.Alias}'" : "") + (record.TargetAssembly != null ? $" assembly='{record.TargetAssembly}'" : "") + (record.TargetAssemblyAlias != null ? $" assembly-alias='{record.TargetAssemblyAlias}'" : "") + (record.TargetType != null ? $" type='{record.TargetType}'" : "") + (record.TargetString != null ? $" string='{record.TargetString}'" : ""); }
private List <ImportRecord> ProcessList(List <List <DataRow> > inputList) { var list = new List <ImportRecord>(); foreach (var listDR in inputList) { //Skipping the header for (int i = 1; i < listDR.Count(); i++) { //Checking if it is an empty line if (string.IsNullOrEmpty(listDR[i][(int)RecordField.Date].ToString())) { break; } decimal expense = 0; var ValidValue = decimal.TryParse(listDR[i][(int)RecordField.Expense].ToString(), out expense); decimal revenue = 0; if (ValidValue) { ValidValue = decimal.TryParse(listDR[i][(int)RecordField.Revenue].ToString(), out revenue); } DateTime date = new DateTime(); if (ValidValue) { ValidValue = DateTime.TryParse(listDR[i][(int)RecordField.Date].ToString(), out date); } var record = new ImportRecord { Description = listDR[i][(int)RecordField.Description].ToString(), Category = listDR[i][(int)RecordField.Category].ToString(), Subcategory = listDR[i][(int)RecordField.Subcategory].ToString(), Expense = expense, Revenue = revenue, Comment = listDR[i][(int)RecordField.Comment].ToString(), Date = date, ImportError = !ValidValue }; list.Add(record); } } var errorNum = list.Where(p => p.ImportError == true).Select(p => p).ToList().Count(); return(list); }
public IHttpActionResult Post(ImportRecord import) { try { if (ModelState.IsValid) { return(Created($"{Request.RequestUri}", _employeeImportProvider.Import(import))); } return(BadRequest(ModelState)); } catch (Exception e) { _logger.LogError("Error when importing employees", e); return(InternalServerError(e)); } }
public static bool TryCreateFromVisualBasicImportString(string importString, out ImportRecord record, out ImportScope scope) { ImportTargetKind targetKind; string alias; string targetString; if (CustomDebugInfoReader.TryParseVisualBasicImportString(importString, out alias, out targetString, out targetKind, out scope)) { record = new NativeImportRecord( targetKind, externAlias: null, alias: alias, targetString: targetString); return true; } record = default(ImportRecord); return false; }
public static bool TryCreateFromCSharpImportString(string importString, out ImportRecord record) { ImportTargetKind targetKind; string externAlias; string alias; string targetString; if (CustomDebugInfoReader.TryParseCSharpImportString(importString, out alias, out externAlias, out targetString, out targetKind)) { record = new NativeImportRecord( targetKind, externAlias, alias, targetString); return true; } record = default(ImportRecord); return false; }
//添加 public static void AddImportRecord(ImportRecord tp) { //ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory(); ISession session = NHibernateHelper.sessionFactory.OpenSession(); ITransaction tx = session.BeginTransaction(); try { session.Save(tp); tx.Commit(); session.Close(); } catch (Exception e) { Debug.Assert(false, e.Message); tx.Rollback(); session.Close(); } }
public static bool TryCreateFromVisualBasicImportString(string importString, out ImportRecord record, out ImportScope scope) { ImportTargetKind targetKind; string alias; string targetString; if (CustomDebugInfoReader.TryParseVisualBasicImportString(importString, out alias, out targetString, out targetKind, out scope)) { record = new NativeImportRecord( targetKind, externAlias: null, alias: alias, targetString: targetString); return(true); } record = default(ImportRecord); return(false); }
//删除 public static void DelImportRecord(int iID) { //ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory(); ISession session = NHibernateHelper.OpenSession(); ITransaction tx = session.BeginTransaction(); ImportRecord toDelete = session.Get <ImportRecord>(iID); try { session.Delete(toDelete); tx.Commit(); session.Close(); } catch (Exception e) { Debug.Assert(false, e.Message); tx.Rollback(); session.Close(); } }
public static bool TryCreateFromCSharpImportString(string importString, out ImportRecord record) { ImportTargetKind targetKind; string externAlias; string alias; string targetString; if (CustomDebugInfoReader.TryParseCSharpImportString(importString, out alias, out externAlias, out targetString, out targetKind)) { record = new NativeImportRecord( targetKind, externAlias, alias, targetString); return(true); } record = default(ImportRecord); return(false); }
//修改 public static void UpdateImportRecord(ImportRecord tp) { ISession session = NHibernateHelper.OpenSession(); try { ITransaction tx = session.BeginTransaction(); ImportRecord t1 = session.Get <ImportRecord>(tp.ID); t1.PurchDateTime = tp.PurchDateTime; t1.MName = tp.MName; t1.MSpec = tp.MSpec; t1.Unit = tp.Unit; t1.Number = tp.Number; t1.Price = tp.Price; t1.SubAmount = tp.SubAmount; t1.DCost = tp.DCost; t1.Amount = tp.Amount; t1.UseSite = tp.UseSite; t1.Planner = tp.Planner; t1.PlanNo = tp.PlanNo; t1.PurchMan = tp.PurchMan; t1.Consignee = tp.Consignee; t1.ReceiptNo = tp.ReceiptNo; t1.Abstract = tp.Abstract; t1.SupplierName = tp.SupplierName; t1.ProjectName = tp.ProjectName; t1.ImportDateTime = tp.ImportDateTime; tx.Commit(); } catch (Exception e) { Debug.Assert(false, e.Message); } session.Close(); }
public static void FillDataTableImportRecord(DataTable tDt) { ISession session = NHibernateHelper.sessionFactory.OpenSession(); ITransaction tx = session.BeginTransaction(); try { DataRow[] drs; drs = tDt.Select("1=1"); for (int i = 0; i < drs.Length; i++) { ImportRecord tNew = new ImportRecord(); string ts = drs[i]["采购日期"].ToString(); if (ts.Length == 6) { ts = "20" + ts.Substring(0, 2) + "-" + ts.Substring(2, 2) + "-" + ts.Substring(4, 2); } else { ts = ts.Substring(0, 4) + "-" + ts.Substring(4, 2) + "-" + ts.Substring(6, 2); } tNew.PurchDateTime = Convert.ToDateTime(ts); tNew.MName = drs[i]["材料名称"].ToString(); tNew.MSpec = drs[i]["规格型号"].ToString(); tNew.Unit = drs[i]["单位"].ToString(); if (drs[i]["数量"].ToString() != "") { tNew.Number = Convert.ToDecimal(drs[i]["数量"]); } if (drs[i]["单价"].ToString() != "") { tNew.Price = Convert.ToDecimal(drs[i]["单价"]); } if (drs[i]["小计"].ToString() != "") { tNew.SubAmount = Convert.ToDecimal(drs[i]["小计"]); } if (drs[i]["采运费"].ToString() != "") { tNew.DCost = Convert.ToDecimal(drs[i]["采运费"]); } if (drs[i]["合计"].ToString() != "") { tNew.Amount = Convert.ToDecimal(drs[i]["合计"]); } tNew.UseSite = drs[i]["使用部位"].ToString(); tNew.Planner = drs[i]["材料计划人"].ToString(); if (drs[i]["材料计划编号"].ToString() != "") { tNew.PlanNo = Convert.ToInt32(drs[i]["材料计划编号"]); } tNew.PurchMan = drs[i]["采购人"].ToString(); tNew.Consignee = drs[i]["收货人"].ToString(); if (drs[i]["收货单号"].ToString() != "") { tNew.ReceiptNo = Convert.ToInt32(drs[i]["收货单号"]); } tNew.Abstract = drs[i]["备注"].ToString(); tNew.SupplierName = drs[i]["供方名称"].ToString(); tNew.ProjectName = drs[i]["项目名称"].ToString(); tNew.ImportDateTime = DateTime.Now; session.Save(tNew); LStatus.Text = "写入数据库:第" + i.ToString() + "条记录。标记行:" + drs[i]["标记"].ToString(); Application.DoEvents(); } tx.Commit(); session.Close(); } catch (Exception e) { Debug.Assert(false, e.Message); tx.Rollback(); session.Close(); } }
public static IRuleBuilderOptions <T, TProperty> WithImportState <T, TRecord, TProperty>(this IRuleBuilderOptions <T, TProperty> rule, ImportRecord <TRecord> importRecord) { return(rule.WithState(_ => new ImportValidationState <TRecord> { InvalidRecord = importRecord })); }
public ImportDynamicPropertiesValidator(ImportRecord <T> importRecord) { _importRecord = importRecord; AttachValidators(); }
private async Task LoadCountriesAsync(ImportRecord <T> importRecord, CustomContext context, CancellationToken cancellationToken) { context.ParentContext.RootContextData[ImportAddressValidator <T> .Countries] = await _countriesService.GetCountriesAsync(); }
public static Dictionary <string, int> RunMain(string startTime, string endTime, int sCityId, int[] cityIds, CancellationToken token) { Dictionary <string, int> caseCount = new Dictionary <string, int>(); String[] cityId = ConfigurationManager.AppSettings["CityList"].Split(','); int length = cityId.Length; int[] arrays = new int[length]; for (int i = 0; i < length; i++) { arrays[i] = Convert.ToInt32(cityId[i]); } bool isRemoveData = Convert.ToBoolean(ConfigurationManager.AppSettings["RemoveData"]); logger.Info("配置参数加载完成,获取远程数据信息"); //获取所有城市数据 IProxy psc = new WCFProxy(); int page = 1; List <City> list_city = new List <City>(); while (true) { List <City> list = ServiceRef.QueryCityInfoList(psc, page); if (list.Count > 0) { foreach (City item in list) { logger.DebugFormat("City name={0}, ID={1}", item.CityName, item.CityID); list_city.Add(item); if (sCityId != -1 && sCityId == item.CityID) { break; } } } else { break; } page++; } #region 用户选择城市列表 //var selectedCitys = App.Current.Dispatcher.Invoke(new Func<List<City>, object>((citys) => //{ // CityListWindow cityWin = new CityListWindow(); // cityWin.Owner = App.Current.MainWindow; // cityWin.DataContext = citys; // var r = cityWin.ShowDialog(); // if (r.HasValue && r.Value) // { // return null; // } // else // { // logger.Info("用户取消"); // return null; // } //}), list_city); //if (selectedCitys == null) //{ // return; //} #endregion Dictionary <string, int> PurposeMap = ServiceRef.QueryPurposeInfoMap(psc); Dictionary <string, int> FrontMap = ServiceRef.QueryFrontInfoMap(psc); Dictionary <string, int> BuildingTypeMap = ServiceRef.QueryBuildingTypeInfoMap(psc); Dictionary <string, int> HouseTypeMap = ServiceRef.QueryHouseTypeInfoMap(psc); Dictionary <string, int> StructureMap = ServiceRef.QueryStructureInfoMap(psc); Dictionary <string, int> MoneyUnitInfoMap = ServiceRef.QueryMoneyUnitInfoMap(psc); if (PurposeMap.Keys.Count == 0 || FrontMap.Keys.Count == 0 || BuildingTypeMap.Keys.Count == 0 || HouseTypeMap.Keys.Count == 0 || StructureMap.Keys.Count == 0) { logger.Info("基础数据获取不全,无法完成后续操作!"); return(caseCount); } CaseDao caseDao = new CaseDao(); Dictionary <string, string> paramMap = new Dictionary <string, string>(); paramMap.Add("[#StartTime#]", startTime); paramMap.Add("[#EndTime#]", endTime); ImportRecord record = new ImportRecord(); record.CaseBeginDate = DateTime.Parse(startTime); record.CaseEndDate = DateTime.Parse(endTime); record.ImportTime = DateTime.Now; record.ImportUser = CurrentData.Instance.UserName; record.ImportCaseNumber = 0; record.ExceptionCaseNumber = 0; int failCount = 0; foreach (City item in list_city) { if (sCityId == -1) { if (cityIds.Contains(item.CityID)) { continue; } } else { if (item.CityID != sCityId) { continue; } } if (token.IsCancellationRequested) { Console.WriteLine("Task cancel detected"); //token.ThrowIfCancellationRequested(); //throw new OperationCanceledException(token); return(caseCount); } failCount = 0; record.ID = item.CityID; record.CityName = item.CityName; List <DataCase> exceptionList = new List <DataCase>(); Console.WriteLine(item.CityName + " 转换数据开始时间= " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); logger.InfoFormat("{0} 转换数据开始时间= {1}", item.CityName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); if (paramMap.ContainsKey("[#CityID#]")) { paramMap.Remove("[#CityID#]"); } paramMap.Add("[#CityID#]", Convert.ToString(item.CityID)); //此处可以根据item,取出City的各个值 logger.Info("CityName = " + item.CityName + "\t" + item.ProjectTable + "\t" + item.CaseTable); //该集合中的对象到15个时,执行一次插入,并清空 List <DataCase> lst_sc = new List <DataCase>(); //循环获取房源信息【住宅案例_出售】 int pageIndex = 1; var a = psc.QueryAreaInfoMap(item.CityID).ValidateStatus <AreaResponseModel>().Areas; //获取城市对应的行政区 Dictionary <string, int> dict = new Dictionary <string, int>(); foreach (Area aitem in a) { //logger.Debug(aitem.AreaName + "\t" + aitem.AreaId); dict.Add(aitem.AreaName, aitem.AreaId); } item.AreaMap = dict; //获取城市对应的楼盘信息表(标准数据,对照源) //List<DataProject> lst_project = ServiceRef.QueryDataProjectList(psc, item.CityID, 0, item.ProjectTable); List <DataProject> lst_project = new List <DataProject>(); while (true) { List <DataProject> list = ServiceRef.PagingQueryDataProjectList(psc, item.CityID, 0, item.ProjectTable, pageIndex); if (list.Count == 0) { break; } lst_project.AddRange(list); pageIndex++; } //获取当前城市楼盘网络别名列表 List <SYS_ProjectMatch> projNetworkNames = new List <SYS_ProjectMatch>(); pageIndex = 1; while (true) { List <SYS_ProjectMatch> list = ServiceRef.PagingQueryNetworkNames(psc, item.CityID, pageIndex, 500); if (list.Count == 0) { break; } projNetworkNames.AddRange(list); pageIndex++; } Dictionary <string, int> cacheProjectIds = new Dictionary <string, int>(); pageIndex = 1; while (true) { if (token.IsCancellationRequested) { Console.WriteLine("Task cancel detected"); //token.ThrowIfCancellationRequested(); //throw new OperationCanceledException(token); return(caseCount); } bool flag = false; List <DataCase> list = caseDao.PagingQueryDataCase(pageIndex, 500, paramMap, out flag); if (flag)//重试一次 { flag = false; list = caseDao.PagingQueryDataCase(pageIndex, 500, paramMap, out flag); if (flag) { string str = "因查询数据库出错,本次导入任务终止,不影响异常数据和正式库,下次可以重新导入!"; logger.InfoFormat(str); Console.WriteLine(str); return(caseCount); } } if (list.Count == 0) { //取不到数据,就退出循环 break; } RemoveDuplicate(list);//原始数据先去重一次 foreach (DataCase data in list) { int projectId = ValidatorUtils.IsValidProject(lst_project, projNetworkNames, data, cacheProjectIds); bool isValid = ValidatorUtils.IsValidData(item, data, arrays, PurposeMap, FrontMap, BuildingTypeMap, HouseTypeMap, StructureMap, MoneyUnitInfoMap); if (isValid && projectId != -1) { #region 符合条件的数据 lst_sc.Add(new DataCase() { ProjectId = projectId, CaseDate = data.CaseDate, AreaId = data.AreaId == null ? -1 : data.AreaId, AreaName = data.AreaName == null ? null : data.AreaName, BuildingArea = data.BuildingArea = data.BuildingArea, PurposeCode = data.PurposeCode == null ? -1 : data.PurposeCode, BuildingDate = data.BuildingDate == null ? null : data.BuildingDate, BuildingTypeCode = data.BuildingTypeCode == null ? -1 : data.BuildingTypeCode, CaseTypeCode = data.CaseTypeCode == null ? -1 : data.CaseTypeCode, CityID = data.CityID == null ? -1 : data.CityID, CaseTypeName = data.CaseTypeName == null ? null : data.CaseTypeName, BuildingTypeName = data.BuildingTypeName == null ? null : data.BuildingTypeName, FloorNumber = data.FloorNumber, FrontCode = data.FrontCode == null ? -1 : data.FrontCode, FrontName = data.FrontName == null ? null : data.FrontName, HouseTypeCode = data.HouseTypeCode == null ? -1 : data.HouseTypeCode, HouseTypeName = data.HouseTypeName == null ? null : data.HouseTypeName, MoneyUnitCode = data.MoneyUnitCode == null ? -1 : data.MoneyUnitCode, MoneyUnitName = data.MoneyUnitName == null ? null : data.MoneyUnitName, PeiTao = data.PeiTao == null ? null : data.PeiTao, PurposeName = data.PurposeName == null ? null : data.PurposeName, ProjectName = data.ProjectName == null ? null : data.ProjectName, RecordWeek = data.RecordWeek, RemainYear = data.RemainYear, Remark = data.Remark == null ? null : data.Remark, SourceLink = data.SourceLink == null ? null : data.SourceLink, SourceName = data.SourceName == null ? null : data.SourceName, SightCode = data.SightCode == null ? -1 : data.SightCode, SourcePhone = data.SourcePhone == null ? null : data.SourcePhone, StructureCode = data.StructureCode == null ? -1 : data.StructureCode, StructureName = data.StructureName == null ? null : data.StructureName, CreateDate = DateTime.Now, Creator = data.Creator == null ? null : data.Creator, SurveyId = data.SurveyId == null ? 0 : data.SurveyId, TotalFloor = data.TotalFloor, TotalPrice = data.TotalPrice = data.TotalPrice, UnitPrice = data.UnitPrice = data.UnitPrice, Valid = data.Valid == null ? 1 : data.Valid, ZhuangXiu = data.ZhuangXiu == null ? null : data.ZhuangXiu, Depreciation = data.Depreciation }); #endregion } else { failCount++; exceptionList.Add(data); logger.InfoFormat("<<< INVALID DATA CityName={0}, ProjectName={1}, ProjectId={2}, isValid={3}", data.CityID, data.ProjectName, projectId, isValid); } } pageIndex++; } record.ExceptionCaseNumber = failCount; if (token.IsCancellationRequested) { Console.WriteLine("Task cancel detected"); return(caseCount); } if (exceptionList.Count > 0) { RemoveDuplicate(exceptionList);//去除异常数据中的重复数据 foreach (DataCase data in exceptionList) { #region 失败信息,需要入库 caseDao.AddExceptionData(data); #endregion } exceptionList = null; } if (lst_sc.Count > 0) { #region List中的对象数到15条,就执行一次入库 record.ImportCaseNumber = BatchCaseData(psc, lst_sc, item.CaseTable); lst_sc = new List <DataCase>(); #endregion caseCount.Add(item.CityName, record.ImportCaseNumber); } if (record.ImportCaseNumber > 0 || record.ExceptionCaseNumber > 0) { int r = record.Insert(); if (r != 1) { logger.Error("入库记录保存失败"); } } lst_project = null; projNetworkNames = null; cacheProjectIds = null; if (isRemoveData) { //从源库删除这些已经处理转换过的案例 Task.Factory.StartNew(() => { int cnt = caseDao.RemoveDataCase(paramMap); logger.Info("当前批量删除已经处理转换过的案例DataCase[" + cnt + "]行数据..."); }); } Console.WriteLine(item.CityName + " 转换数据结束时间= " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); logger.InfoFormat("{0} 转换数据结束时间= {1}", item.CityName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); } Console.WriteLine("================>> 数据转换完成,时间 = " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); logger.InfoFormat("================================================>> 数据转换完成,时间 = {0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); return(caseCount); }