public ApiResponse ImportTiKu() { string uploadPath = Path.Combine( PublicFunc.GetDeployDirectory(), PublicFunc.GetConfigByKey_AppSettings("Upload_Path")); HttpPostedFile file = HttpContext.Current.Request.Files[0]; //var file = new { FileName = "题库.xls" }; string strPath = Path.Combine(uploadPath, file.FileName); if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } file.SaveAs(strPath); var baseModel = GetModelBase(); var ds = Utility.ExcelToDataSet(strPath, "select * from [Sheet0$]"); var model = new TiKuMasterModel(); model.User = baseModel.User; if (ds != null && ds.Tables[0] != null) { model.TiKuName = file.FileName.Substring(0, file.FileName.LastIndexOf('.')); model.InDate = DateTime.Now; model.InUser = baseModel.User.UserID; model.LastEditDate = DateTime.Now; model.LastEditUser = baseModel.User.UserID; model.Status = (int)TiKuStatus.WaitForActive; model.Details = new List<TiKuDetailModel>(); foreach (DataRow row in ds.Tables[0].Rows) { model.Details.Add(new TiKuDetailModel { TeamName = row["TeamName"].ToString(), ProcessName = row["ProcessName"].ToString(), NodeName = row["NodeName"].ToString() }); } } tiKuService.CreateTiKu(model); if (File.Exists(strPath)) { File.Delete(strPath); } return ApiOk(); }
public void CreateTiKu(TiKuMasterModel master) { if (master != null) { var parameter = new SqlParameter() { DbType = DbType.String, ParameterName = "@TiKuName", Value = master.TiKuName }; adonetWrapper.ExecuteSqlCommand( @"declare @masterSysNo int select @masterSysNo = SysNo FROM dbo.TiKuMaster where TiKuName=@TiKuName delete from dbo.TiKuMaster where SysNo = @masterSysNo; delete from dbo.TiKuDetail where MasterSysNo = @masterSysNo" , parameter); var insertCount = tiKuRepo.Insert(PublicFunc.EntityMap<TiKuMasterModel, TiKuMaster>(master)); if (insertCount > 0) { var masterSysNo = tiKuRepo.Entities.FirstOrDefault(m => m.TiKuName == master.TiKuName).SysNo; var details = PublicFunc.EntityMap<List<TiKuDetailModel>, List<TiKuDetail>>(master.Details); if (details != null) { details.ForEach((detail) => { detail.MasterSysNo = masterSysNo; }); tiKuDetailRepo.Insert(details); var names = details.Select(m => m.ProcessName).Distinct().ToList(); foreach (var name in names) { var matchDetails = details.Where(m => m.ProcessName == name); if (matchDetails != null) { var initExam = new InitExamModel(); initExam.User = master.User; initExam.ProcessName = name; initExam.NodeTeams = new List<NodeTeamModel>(); foreach (var mDetail in matchDetails) { initExam.NodeTeams.Add(new NodeTeamModel() { NodeName = mDetail.NodeName, TeamName = mDetail.TeamName }); } taskService.InitExam(initExam); } } } } } }