private void btn_save_Click(object sender, EventArgs e) { try { //List<int> selectedIndicatorIdList = selectedIndicatorModelList.Select(i => i.indicatorId).ToList(); //IndicatorTemplateMapCache.addCache(templateId, selectedIndicatorIdList); List <Tb_taskResult> resultList = new List <Tb_taskResult>(); int id = TaskResultCache.getCache().Count; if (selectedIndicatorModelList.Count == 0) { MessageBox.Show("保存失败,未选择任务指标", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } foreach (var item in selectedIndicatorModelList) { //Tb_taskIndicatorMap indicatorMap = new Tb_taskIndicatorMap(); //indicatorMap.taskId = taskInfoId; //indicatorMap.indicatorId = item; //indicatorMap.taskRound = currentRound; //TaskIndicatorMapCache.addCacheOnly(indicatorMap); Tb_taskResult taskResult = new Tb_taskResult(); taskResult.taskId = taskInfoId; taskResult.taskStep = 1;//新增轮次的步骤默认都是从1开始 taskResult.taskExecutor = User.currentUser.name; taskResult.taskDateTime = DateTime.Now; taskResult.modelId = item.modelId; taskResult.indicatorId = item.indicatorId; taskResult.taskRecord = ""; taskResult.taskResult = 0; taskResult.taskRemark = ""; taskResult.attachment = ""; taskResult.supplement = ""; taskResult.taskRound = currentRound + 1; resultList.Add(taskResult); } TaskResultCache.addCache(resultList); MessageBoxEx.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.Yes; } catch (Exception ex) { MessageBoxEx.Show("保存失败。" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.No; } }
private void btn_save_Click(object sender, EventArgs e) { List <Tb_taskResult> resultList = new List <Db.Entity.Tb_taskResult>(); //int oldRound = -1; if (currentRound != maxRound) { MessageBoxEx.Show("当前轮次不是最大轮次,无法保存", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //foreach (DataGridViewRow dr in trp.dgv.Rows) //{ // if (dr.Cells["taskRecord"].Value == null) // { // dr.Cells["taskRecord"].Value = ""; // } // if (dr.Cells["taskRemark"].Value == null) // { // dr.Cells["taskRemark"].Value = ""; // } // if (dr.Cells["attachment"].Value == null) // { // dr.Cells["attachment"].Value = ""; // } // //如果修改过测试结果,或是测试结果内有内容(无论是否本次输入),都保存 // if (dr.Cells["taskResult"].Style.BackColor == Color.LightSeaGreen // || dr.Cells["taskRecord"].Style.BackColor == Color.LightSeaGreen // || dr.Cells["taskRemark"].Style.BackColor == Color.LightSeaGreen // || dr.Cells["attachmentCount"].Style.BackColor == Color.LightSeaGreen // || dr.Cells["taskResult"].Value.ToString() != "0" // || dr.Cells["taskRecord"].Value.ToString() != string.Empty // || dr.Cells["taskRemark"].Value.ToString() != string.Empty // || dr.Cells["attachment"].Value.ToString() != string.Empty) // { // Tb_taskResult result = new Tb_taskResult(); // result.indicatorId = (int)dr.Cells["indicatorId"].Value; // result.modelId = (int)dr.Cells["modelId"].Value; // result.taskDateTime = DateTime.Now; // result.taskExecutor = User.currentUser.name; // result.taskId = taskInfoId; // result.taskRecord = dr.Cells["taskRecord"].Value == null ? "" : dr.Cells["taskRecord"].Value.ToString(); // result.taskRemark = dr.Cells["taskRemark"].Value.ToString(); // result.taskResult = (int)dr.Cells["taskResult"].Value; // result.attachment = dr.Cells["attachment"].Value.ToString(); // result.supplement = dr.Cells["supplement"].Value == null ? "" : dr.Cells["supplement"].Value.ToString(); // result.taskStep = maxTaskStep + 1; // result.taskRound = currentRound; // //result.taskRound = int.Parse(labelItem2.Text); // resultList.Add(result); // //保存任务之时,判断当前项是否填写完整,如果填写完整,则修改该控件下的isFillFinish值 // if (result.taskResult != 0 && result.taskRecord != "") // { // dr.Cells["isFill"].Value = 1; // } // } //} foreach (var item in trp.allResultModelList) { if (item.isHaveModi == 1) { Tb_taskResult result = new Tb_taskResult(); result.indicatorId = item.indicatorId; result.modelId = item.modelId; DateTime taskDateTime; result.taskDateTime = DateTime.TryParse(item.taskDateTime, out taskDateTime) ? taskDateTime : DateTime.Now; //result.taskDateTime = DateTime.TryParse(dr.Cells["taskDateTime"].Value.ToString(), out taskDateTime) ? taskDateTime : DateTime.Now;//DateTime.Now; result.taskExecutor = User.currentUser.name; result.taskId = taskInfoId; result.taskRecord = item.taskRecord; result.taskRemark = item.taskRemark; result.taskResult = item.taskResult; result.attachment = item.attachment; result.supplement = item.supplement; result.taskStep = maxTaskStep + 1; result.taskRound = currentRound; //result.taskRound = int.Parse(labelItem2.Text); resultList.Add(result); if (result.taskResult != 0 && result.taskRecord != "") { item.isFillFinish = 1; } } } if (resultList.Count > 0) { TaskResultCache.addCache(resultList); //添加测试记录 var taskInfo = TaskCache.getCacheById(taskInfoId); //更新任务进度字段 var taskResultMainCount = trp.getAllResultModelCount(); taskInfo.percent = resultList.Count * 100 / taskResultMainCount; TaskCache.addCache(taskInfo); //刷新单元格背景色为白色 foreach (DataGridViewRow dr in trp.dgv.Rows) { dr.Cells["taskResult"].Style.BackColor = Color.White; dr.Cells["taskRecord"].Style.BackColor = Color.White; dr.Cells["taskRemark"].Style.BackColor = Color.White; dr.Cells["attachmentCount"].Style.BackColor = Color.White; dr.Cells["taskStep"].Value = int.Parse(dr.Cells["taskStep"].Value.ToString()) + 1; } MainFormAdapter.reloadTaskMainPanel(); maxTaskStep++;//最大步骤编号,每次保存,都加1,如果切换轮次,需重新获取该轮次的最大步骤编号 trp.maxResultStep = maxTaskStep; trp.currentResultStep = maxTaskStep; } }