protected void save_Click(object sender, EventArgs e) { var stDal = new sdk_task_dal(); var ids = Request.QueryString["taskIds"]; var thisTaskList = stDal.GetTaskByIds(ids, $" and type_id in ({(int)DicEnum.TASK_TYPE.PROJECT_TASK},{(int)DicEnum.TASK_TYPE.PROJECT_ISSUE})"); if (thisTaskList != null && thisTaskList.Count > 0) { var pageTitle = Request.Form["title"]; var pageStatu = Request.Form["status_id"]; var pagePriority = Request.Form["priority"]; var displayIsChange = noChange.Checked; var pageEstimated_hours = Request.Form["estimated_hours"]; var pageDepa = Request.Form["department_id"]; var pageRes = Request.Form["owner_resource_id"]; var user = UserInfoBLL.GetUserInfo(GetLoginUserId()); var ctaDal = new v_task_all_dal(); foreach (var thisTask in thisTaskList) { if (pageTitle != "多个值-保持不变") { if (!string.IsNullOrEmpty(pageTitle)) { thisTask.title = pageTitle; } } if (pageStatu != "0") { thisTask.status_id = int.Parse(pageStatu); } if (!string.IsNullOrEmpty(pagePriority)) { thisTask.priority = int.Parse(pagePriority); } if (!displayIsChange) // 代表页面上选择进行更改 { if (DisplayInCapNone.Checked) { thisTask.is_visible_in_client_portal = 0; } else { thisTask.is_visible_in_client_portal = 1; if (DisplayInCapYes.Checked) { thisTask.can_client_portal_user_complete_task = 1; } else if (DisplayInCapYesNoComplete.Checked) { thisTask.can_client_portal_user_complete_task = 0; } } } if (!typeNoChange.Checked) { if (TaskTypeFixedWork.Checked) { thisTask.estimated_type_id = (int)DicEnum.TIME_ENTRY_METHOD_TYPE.FIXWORK; } else if (TaskTypeFixedDuration.Checked) { thisTask.estimated_type_id = (int)DicEnum.TIME_ENTRY_METHOD_TYPE.FIXDURATION; } } if (!string.IsNullOrEmpty(pageEstimated_hours)) { thisTask.estimated_hours = decimal.Parse(pageEstimated_hours); var vTask = ctaDal.FindById(thisTask.id); if (vTask != null) { thisTask.projected_variance = (vTask.worked_hours == null ? 0 : (decimal)vTask.worked_hours) - (thisTask.estimated_hours + (vTask.change_Order_Hours == null ? 0 : (decimal)vTask.change_Order_Hours)) + (vTask.remain_hours == null ? 0 : (decimal)vTask.remain_hours); } } if (pageDepa != "0") { if (!string.IsNullOrEmpty(pageDepa)) { thisTask.department_id = int.Parse(pageDepa); } else { thisTask.department_id = null; } } if (pageRes != "0") { if (!string.IsNullOrEmpty(pageRes)) { thisTask.owner_resource_id = long.Parse(pageRes); } else { thisTask.owner_resource_id = null; } } OperLogBLL.OperLogUpdate <sdk_task>(thisTask, stDal.FindNoDeleteById(thisTask.id), thisTask.id, GetLoginUserId(), OPER_LOG_OBJ_CATE.PROJECT_TASK, "修改task"); stDal.Update(thisTask); var thisUdfValue = udfBLL.GetUdfValue(UDF_CATE.TASK, thisTask.id, udfTaskPara); if (udfTaskPara != null && udfTaskPara.Count > 0) // 首先判断是否有自定义信息 { var list = new List <UserDefinedFieldValue>(); foreach (var udf in udfTaskPara) // 循环添加 { var new_udf = new UserDefinedFieldValue(); // if(udf.data_type != (int)EMT.DoneNOW.DTO.DicEnum.UDF_DATA_TYPE.LIST) // todo,根据类型去取值 new_udf.id = udf.id; var thisvv = Request.Form[udf.id.ToString()]; if (thisvv == "多个值-保持不变") { new_udf.value = thisUdfValue.FirstOrDefault(_ => _.id == udf.id).value; } else { new_udf.value = thisvv == "" ? null : thisvv; } list.Add(new_udf); } udfBLL.UpdateUdfValue(UDF_CATE.TASK, udfTaskPara, thisTask.id, list, user, OPER_LOG_OBJ_CATE.PROJECT_TASK); } } } ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script>alert('保存成功!');window.close();self.opener.location.reload();</script>"); }
/// <summary> /// 获取相应参数 /// </summary> private TaskSaveDto GetParam() { TaskSaveDto param = AssembleModel <TaskSaveDto>(); param.resDepIds = Request.Form["resDepList"]; // 员工角色 Id param.contactIds = Request.Form["conIds"]; // 联系人 ID var preTaskIds = Request.Form["preIds"]; // 前驱任务IDs if (!string.IsNullOrEmpty(preTaskIds)) { var preTasArr = preTaskIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); Dictionary <long, int> predic = new Dictionary <long, int>(); foreach (var preTasId in preTasArr) { var layDays = Request.Form[preTasId + "_lagDays"]; if ((!string.IsNullOrEmpty(layDays)) && (!string.IsNullOrWhiteSpace(layDays))) { predic.Add(long.Parse(preTasId), int.Parse(layDays)); } } param.predic = predic; } var pageTask = AssembleModel <sdk_task>(); pageTask.cost_code_id = pageTask.cost_code_id == 0 ? null : pageTask.cost_code_id; if (pageTask.parent_id == null) { var subList = new sdk_task_dal().GetAllProTask(thisProject.id); if (subList != null && subList.Count >= 99) { if (isAdd) { Response.Write("<script>alert('项目下任务过多,不能添加!');window.close();</script>"); return(null); } else { if (!subList.Any(_ => _.id == thisTask.id)) { Response.Write("<script>alert('项目下任务过多,不能保存!');window.close();</script>"); return(null); } } } } //if (parTask != null) //{ // pageTask.parent_id = parTask.id; //} if (type_id != (int)DicEnum.TASK_TYPE.PROJECT_PHASE) { pageTask.is_visible_in_client_portal = (sbyte)(DisplayInCapNone.Checked ? 1 : 0); pageTask.can_client_portal_user_complete_task = (sbyte)(DisplayInCapYes.Checked ? 1 : 0); if (TaskTypeFixedWork.Checked) { pageTask.estimated_type_id = (int)DicEnum.TIME_ENTRY_METHOD_TYPE.FIXWORK; } else if (TaskTypeFixedDuration.Checked) { pageTask.estimated_type_id = (int)DicEnum.TIME_ENTRY_METHOD_TYPE.FIXDURATION; } } else { if (rateList != null && rateList.Count > 0) { Dictionary <long, decimal> rateDic = new Dictionary <long, decimal>(); foreach (var rate in rateList) { var hours = Request.Form[rate.id + "_esHours"]; if (!string.IsNullOrEmpty(hours) && !string.IsNullOrWhiteSpace(hours)) { rateDic.Add(rate.id, decimal.Parse(hours)); } } param.rateDic = rateDic; } pageTask.status_id = (int)DicEnum.TICKET_STATUS.NEW; } var startString = Request.Form["estimated_beginTime"]; var estimated_start = Request.Form["estimated_start"]; var estimated_end_time = Request.Form["estimated_end_time_"]; if (!string.IsNullOrEmpty(startString) && !string.IsNullOrEmpty(estimated_end_time) && !string.IsNullOrEmpty(estimated_start)) { pageTask.estimated_end_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Parse(estimated_end_time)); pageTask.estimated_begin_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Parse(startString + " " + estimated_start)); // if (type_id == (int)DicEnum.TASK_TYPE.PROJECT_PHASE) // d //{ TimeSpan ts1 = new TimeSpan((DateTime.Parse(startString)).Ticks); TimeSpan ts2 = new TimeSpan(Tools.Date.DateHelper.ConvertStringToDateTime((long)pageTask.estimated_end_time).Ticks); TimeSpan ts = ts1.Subtract(ts2).Duration(); //pageTask.estimated_duration = ts.Days + 1; // } // RetrunMaxTime 计算结束时间 if (type_id != (int)DicEnum.TASK_TYPE.PROJECT_PHASE) { if (thisProject.use_resource_daily_hours == 1) // 用工作量为固定工作任务计算时间 { decimal teaNum = 0; var dayWorkHours = (decimal)thisProject.resource_daily_hours; if (!string.IsNullOrEmpty(param.resDepIds)) { teaNum += param.resDepIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Count(); } if (pageTask.owner_resource_id != null) { teaNum += 1; } teaNum = teaNum == 0 ? 1 : teaNum; var workHours = pageTask.estimated_hours; pageTask.estimated_duration = (int)Math.Ceiling(((workHours / teaNum) / dayWorkHours)); pageTask.estimated_end_time = Tools.Date.DateHelper.ToUniversalTimeStamp(new TaskBLL().RetrunMaxTime(thisProject.id, DateTime.Parse(startString), (int)pageTask.estimated_duration)); } else { } } else { pageTask.estimated_duration = new TaskBLL().GetDayByTime((long)pageTask.estimated_begin_time, (long)pageTask.estimated_end_time, (long)thisProject.id); } } if (isAdd) { param.task = pageTask; param.task.type_id = type_id; param.task.project_id = thisProject.id; param.task.account_id = thisProject.account_id; } else { // thisTask thisTask.title = pageTask.title; thisTask.parent_id = pageTask.parent_id; thisTask.description = pageTask.description; if (thisTask.estimated_begin_time != pageTask.estimated_begin_time) { thisTask.estimated_begin_time = pageTask.estimated_begin_time; thisTask.start_no_earlier_than_date = Tools.Date.DateHelper.ConvertStringToDateTime((long)thisTask.estimated_begin_time); } if (thisTask.estimated_end_time != pageTask.estimated_end_time) { thisTask.estimated_end_time = pageTask.estimated_end_time; thisTask.estimated_duration = new TaskBLL().GetDayByTime((long)thisTask.estimated_begin_time, (long)pageTask.estimated_end_time, (long)thisTask.project_id); } else { if (thisTask.estimated_duration != pageTask.estimated_duration) { thisTask.estimated_end_time = Tools.Date.DateHelper.ToUniversalTimeStamp(new TaskBLL().RetrunMaxTime(thisProject.id, DateTime.Parse(startString), (int)pageTask.estimated_duration)); thisTask.estimated_duration = pageTask.estimated_duration; } else { thisTask.estimated_end_time = pageTask.estimated_end_time; thisTask.estimated_duration = pageTask.estimated_duration; } } if (!isPhase) { thisTask.status_id = pageTask.status_id; thisTask.priority = pageTask.priority; thisTask.purchase_order_no = pageTask.purchase_order_no; thisTask.can_client_portal_user_complete_task = pageTask.can_client_portal_user_complete_task; thisTask.is_visible_in_client_portal = pageTask.is_visible_in_client_portal; thisTask.is_project_issue = pageTask.is_project_issue; thisTask.issue_report_contact_id = pageTask.issue_report_contact_id; thisTask.estimated_type_id = pageTask.estimated_type_id; thisTask.estimated_hours = pageTask.estimated_hours; // thisTask.estimated_duration = pageTask.estimated_duration; thisTask.hours_per_resource = pageTask.hours_per_resource; if (thisTask.start_no_earlier_than_date == null) { thisTask.start_no_earlier_than_date = pageTask.start_no_earlier_than_date; } thisTask.department_id = pageTask.department_id; thisTask.cost_code_id = pageTask.cost_code_id; thisTask.owner_resource_id = pageTask.owner_resource_id; thisTask.template_id = pageTask.template_id; var IsEditEsTime = this.IsEditEsTime.Value; //Request.Form["IsEditEsTime"]; var thisVt = new v_task_all_dal().FindById(thisTask.id); if (!string.IsNullOrEmpty(IsEditEsTime)) { if (IsEditEsTime == "1") { thisTask.projected_variance = (thisVt.worked_hours == null ? 0 : (decimal)thisVt.worked_hours) - (thisTask.estimated_hours + (thisVt.change_Order_Hours == null ? 0 : (decimal)thisVt.change_Order_Hours)) + (thisVt.remain_hours == null ? 0 : (decimal)thisVt.remain_hours); } else if (IsEditEsTime == "0") { thisTask.projected_variance = (thisVt.worked_hours == null ? 0 : (decimal)thisVt.worked_hours) - (thisTask.estimated_hours + (thisVt.change_Order_Hours == null ? 0 : (decimal)thisVt.change_Order_Hours)); } } else { } } param.task = thisTask; } if (task_udfList != null && task_udfList.Count > 0) { var list = new List <UserDefinedFieldValue>(); foreach (var udf in task_udfList) // 循环添加 { var new_udf = new UserDefinedFieldValue() { id = udf.id, value = string.IsNullOrEmpty(Request.Form[udf.id.ToString()]) ? null : Request.Form[udf.id.ToString()], }; list.Add(new_udf); } param.udf = list; } return(param); }