using BLL; using FineUIPro.Web.HSSE.EduTrain; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; namespace FineUIPro.Web.HSSE.PostTraining { public partial class RecordEdit : PageBase { #region 定义项 /// /// 主键 /// public string Id { get { return (string)ViewState["Id"]; } set { ViewState["Id"] = value; } } /// /// 项目主键 /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } /// /// 定义集合 /// private static List recordDetails = new List(); #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ProjectId = this.CurrUser.LoginProjectId; this.btnClose.OnClientClick = ActiveWindow.GetHideReference(); this.InitDropDownList(); this.Id = Request.Params["Id"]; if (!string.IsNullOrEmpty(this.Id)) { Model.PostTraining_Record model = BLL.PostTrainingRecordService.GetRecordById(this.Id); if (model != null) { this.txtCode.Text = model.Code; this.txtRemark.Text = model.Remark; if (!string.IsNullOrWhiteSpace(model.CourseId)) { var course = BLL.PostTrainingCourseService.GetCourseById(model.CourseId); this.drpCategory.SelectedValue = course.CategoryId; //培训课程 PostTrainingCourseService.InitPostTrainingCourseDropDownList(this.drpCourse, course.CategoryId, false); this.drpCourse.SelectedValue = model.CourseId; } if (!string.IsNullOrWhiteSpace(model.Method)) { this.drpMethod.SelectedValue = model.Method; } } } else { ////自动生成编码 this.txtCode.Text = SQLHelper.RunProcNewId("SpGetNewCode5", "dbo.PostTraining_Record", "Code", ""); } } } /// /// 下拉框加载 /// private void InitDropDownList() { //培训单位 UnitService.InitUnitDropDownList(this.drpUnits, this.ProjectId, false); //获取适用岗位下拉框 PostTrainingRoleService.InitPostTrainingRoleDropDownList(this.drpRole, false); //获取培训类别下拉框 PostTrainingCategoryService.InitPostTrainingCategoryDropDownList(this.drpCategory, false); //获取培训方式下拉框 PostTrainingMethodService.InitPostTrainingMethodDropDownList(this.drpMethod, null, false); this.drpUnits.SelectedValue = this.CurrUser.UnitId; } /// /// 培训类别下拉加载 /// /// /// protected void drpCategory_SelectedIndexChanged(object sender, EventArgs e) { //培训课程 PostTrainingCourseService.InitPostTrainingCourseDropDownList(this.drpCourse, this.drpCategory.SelectedValue, false); } /// /// 绑定 Grid1 /// private void Grid1DataBind() { recordDetails = (from x in Funs.DB.View_PostTraining_RecordDetail where x.RecordId == this.Id orderby x.UnitName, x.RoleName, x.PersonName select x).ToList(); Grid1.DataSource = recordDetails; Grid1.DataBind(); //for (int i = 0; i < Grid1.Rows.Count; i++) //{ // bool isRed = true; // string trainDetailId = Grid1.Rows[i].DataKeys[0].ToString(); // var getAtt = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == trainDetailId); // if (getAtt != null) // { // isRed = false; // } // if (isRed) // { // var getRecordDetail = recordDetails.FirstOrDefault(x => x.DetailId == trainDetailId); // if (getRecordDetail != null && !string.IsNullOrEmpty(this.TestPlanId)) ////未参加过培训的人员 // { // var getTestRecord = Funs.DB.Training_TestRecord.FirstOrDefault(x => x.TestManId == getRecordDetail.PersonId && x.TestPlanId == this.TestPlanId); // if (getTestRecord != null) // { // isRed = false; // } // } // } // if (isRed) // { // Grid1.Rows[i].RowCssClass = "Red"; // } //} } #endregion #region 选择按钮 /// /// 选择按钮 /// /// /// protected void btnSelect_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.Id)) { this.SaveData(BLL.Const.BtnSave); } //培训岗位 string roleIds = string.Empty; foreach (var item in this.drpRole.SelectedValueArray) { roleIds += item + ","; } if (!string.IsNullOrEmpty(roleIds)) { roleIds = roleIds.Substring(0, roleIds.LastIndexOf(",")); } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SelectPerson.aspx?RecordId={0}&RoleIds={1}", this.Id, roleIds, "编辑 - "))); } #endregion #region 删除 /// /// 批量删除 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); BLL.PostTrainingRecordDetailService.DeleteTrainDetailByTrainDetail(rowID); } this.Grid1DataBind(); this.txtPersonNum.Text = recordDetails.Count.ToString(); this.ShowNotify("删除数据成功!(表格数据已重新绑定)"); } } #endregion #region 关闭弹出窗 /// /// 关闭弹出窗 /// /// /// protected void Window1_Close(object sender, EventArgs e) { this.Grid1DataBind(); this.txtPersonNum.Text = recordDetails.Count.ToString(); } #endregion #region 保存 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { this.SaveData(BLL.Const.BtnSave); PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } /// /// 保存数据 /// /// private void SaveData(string type) { Model.PostTraining_Record newModel = new Model.PostTraining_Record { ProjectId = this.ProjectId, Code = this.txtCode.Text.Trim(), CompileDate = DateTime.Now, CompileMan = this.CurrUser.UserId, PersonNum = this.Grid1.Rows.Count, TrainingTime = Funs.GetNewDateTimeOrNow(this.txtTrainingTime.Text.Trim()) }; newModel.Name = this.txtName.Text.Trim(); newModel.Content = this.txtContent.Text.Trim(); newModel.CategoryId = this.drpCategory.SelectedValue; newModel.CategoryName = this.drpCategory.SelectedText; newModel.CourseId = this.drpCourse.SelectedValue; newModel.CourseName = this.drpCourse.SelectedText; newModel.Location = this.txtLocation.Text.Trim(); newModel.Method = this.drpMethod.SelectedText; newModel.Lecturer = this.txtLecturer.Text.Trim(); newModel.Duration = decimal.Parse(this.txtDuration.Text.Trim()); newModel.Remark = this.txtRemark.Text.Trim(); //培训单位 string unitIds = string.Empty; foreach (var item in this.drpUnits.SelectedValueArray) { unitIds += item + ","; } if (!string.IsNullOrEmpty(unitIds)) { unitIds = unitIds.Substring(0, unitIds.LastIndexOf(",")); } //培训岗位 string roleIds = string.Empty; foreach (var item in this.drpRole.SelectedValueArray) { roleIds += item + ","; } if (!string.IsNullOrEmpty(roleIds)) { roleIds = roleIds.Substring(0, roleIds.LastIndexOf(",")); } newModel.UnitIds = unitIds; newModel.RoleIds = roleIds; if (!string.IsNullOrEmpty(this.Id)) { newModel.Id = this.Id; BLL.PostTrainingRecordService.UpdateRecord(newModel); BLL.LogService.AddSys_Log(this.CurrUser, newModel.Code, newModel.Id, BLL.Const.PostTrainingRecordMenuId, BLL.Const.BtnModify); } else { this.Id = SQLHelper.GetNewID(typeof(Model.PostTraining_Record)); newModel.Id = this.Id; BLL.PostTrainingRecordService.AddRecord(newModel); BLL.LogService.AddSys_Log(this.CurrUser, newModel.Code, newModel.Id, BLL.Const.PostTrainingRecordMenuId, BLL.Const.BtnAdd); } //JArray mergedData = Grid1.GetMergedData(); //foreach (JObject mergedRow in mergedData) //{ // string status = mergedRow.Value("status"); // JObject values = mergedRow.Value("values"); // Model.PostTraining_Record_Detail detail = BLL.PostTrainingRecordDetailService.GetRecordDetailById(values.Value("DetailId").ToString()); // if (detail != null) // { // if (values.Value("CheckResult").ToString() == "1") // { // detail.CheckResult = true; // } // else // { // detail.CheckResult = false; // } // detail.CheckScore = Funs.GetNewDecimalOrZero(values.Value("CheckScore").ToString()); ; // BLL.EduTrain_TrainRecordDetailService.UpdateTrainDetail(detail); // } //} } #endregion #region 附件上传 /// /// 上传附件 /// /// /// protected void btnAttachUrl_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.Id)) { SaveData(BLL.Const.BtnSave); } PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/PostTraining/Record&menuId={1}", Id, BLL.Const.PostTrainingRecordMenuId))); } #endregion } }