public Result Import(List <Generation_gives> list) { db = new Db(); Generation_gives gives = null; List <Generation_gives> ignore = new List <Generation_gives>(); try { foreach (Generation_gives _this in list) { gives = db.Generation_gives.SingleOrDefault( t => t.salesman_card_id == _this.salesman_card_id && t.salesman_hiredate == _this.salesman_hiredate); if (gives == null) { _this.record_date = DateTime.Now; db.Generation_gives.Add(_this); } else { ignore.Add(_this); } } if (list.Count > ignore.Count) { Entity.SaveChanges(db); } if (ignore.Count > 0) { return(new Result(ResultType.success, "但部分人员信息因已存在已被忽略导入,详见表格", ignore)); } else { return(new Result(ResultType.success, "人员信息全部成功导入")); } } catch (Exception ex) { return(new Result(ResultType.error, new Message(ex).ErrorDetails)); } }
public void Execute(IJobExecutionContext context) { db_interface = db_interface ?? new DbInterface(); batch_id = batch_id ?? context.JobDetail.Key.Name; INTERFACE_MIO_BATCH_BZJ batch_interface = db_interface.INTERFACE_MIO_BATCH_BZJ.SingleOrDefault(t => t.FromBatchNo == batch_id); if (batch_interface != null && batch_interface.BatchStatus == 5) { try { db = new Db(); var batch = db.MioBatch.SingleOrDefault(t => t.batch_id == batch_id); batch.done_date = DateTime.Now; batch.push_result = batch_interface.Remark; db.Update(batch); var batch_interface_list = db_interface.INTERFACE_MIO_LIST_BZJ.Where(t => t.FromBatchNo == batch_id).ToList(); //获取清单表 Generation_gives gives = null; var batch_list = db.MioList.Where(t => t.batch_id == batch_id).ToList(); batch_list.ForEach(t => { var batch_detail = batch_interface_list.SingleOrDefault( s => s.FromBatchNo == batch_id && s.BankAcc == t.bank_account_no && s.BankAccName == t.bank_account_name); t.status = batch_detail.MioStatus; t.result = batch_detail.ErrMsg; //将清单表信息复制过来 db.Update(t); gives = db.Generation_gives.SingleOrDefault(b => b.id == t.generation_id); if (gives != null) { if (t.status == 0) //0表示处理成功 { gives.review_state = 6; } else { gives.review_state = -6; //失败退回到提交状态 } gives.process_result = batch_detail.ErrMsg; gives.finish_time = batch_detail.FinishTime; db.Update(gives); } }); db.SaveChanges(); } finally { QuartzManager <QueryGivesInfo> .RemoveJob(batch_id); } } }
public Result Save(string generation_gives, string deducted_items, int level) { db = new Db(); try { Generation_gives gives = JsonConvert.DeserializeObject <Generation_gives>(generation_gives); var list = db.Generation_gives.Where( t => t.salesman_card_id == gives.salesman_card_id && t.salesman_hiredate == gives.salesman_hiredate).ToList(); var old_gives = list.Any() ? list.First() : null; if (old_gives == null || gives.id > 0) { if (gives.id > 0) { Entity.Update(db, gives); var old_deducteds = db.Deducted.Where(t => t.generation_gives_id == gives.id).ToList(); if (old_deducteds.Any()) { db.Deducted.RemoveRange(old_deducteds); } } else { gives.record_date = DateTime.Now; switch (level) { case 2: gives.review_state = 2; break; case 3: gives.review_state = 1; break; case 4: gives.review_state = 0; break; } db.Generation_gives.Add(gives); } Entity.SaveChanges(db); if (!string.IsNullOrEmpty(deducted_items)) { List <Deducted> deducteds = JsonConvert.DeserializeObject <List <Deducted> >(deducted_items); deducteds.ForEach(t => { t.id = 0; t.generation_gives_id = gives.id; }); db.Deducted.AddRange(deducteds); Entity.SaveChanges(db); } return(new Result(ResultType.success, new { generation_gives_id = gives.id })); } else { return(new Result(ResultType.no_changed, "该人员的代付信息已被其它工作人员录入")); } } catch (Exception ex) { return(new Result(ResultType.error, new Message(ex).ErrorDetails)); } }
public string Import(HttpPostedFileBase file) { IWorkbook workbook = null; ISheet sheet = null; FileStream fs = null; string filePath = null; try { if (file != null) { filePath = Server.MapPath("~/Excel/") + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + file.FileName; file.SaveAs(filePath); fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); if (filePath.IndexOf(".xlsx") > 0) // 2007版本 { workbook = new XSSFWorkbook(fs); } else if (filePath.IndexOf(".xls") > 0) // 2003版本 { workbook = new HSSFWorkbook(fs); } sheet = workbook.GetSheetAt(0); //获取第一个sheet if (sheet != null) { var cell = sheet.GetRow(0).GetCell(0); if (cell != null && cell.StringCellValue == "管理机构") { var startRow = 2; var rowCount = sheet.LastRowNum; int cellCount = sheet.GetRow(0).LastCellNum; //一行最后一个cell的编号 即总的列数 var field = GetFieldDic(); var list = new List <Generation_gives>(); var gives = new Generation_gives(); var type = gives.GetType(); PropertyInfo property = null; for (var r = startRow; r <= rowCount; r++) { gives = new Generation_gives(); gives.agency_code = Request.Cookies["agency_code"].Value; gives.recorder_code = Request.Cookies["user_code"].Value; gives.record_date = DateTime.Now; gives.review_state = 0; for (var c = 0; c < cellCount; c++) { cell = sheet.GetRow(r).GetCell(c); property = type.GetProperty(field[c]); if (cell.CellType == CellType.Numeric) { if (field[c] == "salesman_hiredate") { property.SetValue(gives, cell.DateCellValue, null); } else { property.SetValue(gives, Convert.ToDecimal(cell.NumericCellValue), null); } } else { property.SetValue(gives, cell.StringCellValue, null); } } list.Add(gives); } if (list.Any()) { result = svr.Import(list); } else { result = new Result(ResultType.error, file.FileName + " 读取不到Excel中的数据!"); } } else { result = new Result(ResultType.error, file.FileName + "格式不正确!"); } } else { result = new Result(ResultType.error, file.FileName + " 第一个Sheet为空!"); } } else { result = new Result(ResultType.error, "找不到上传的文件,name = file"); } } catch (Exception ex) { result = new Result(ResultType.error, new Message(ex).ErrorDetails); } return(JsonConvert.SerializeObject(result)); }