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.txtName.Text = model.Name; this.txtContent.Text = model.Content; this.txtRemark.Text = model.Remark; this.txtPersonNum.Text = model.PersonNum.ToString(); this.txtLocation.Text = model.Location; this.txtDuration.Text = model.Duration.ToString(); this.txtLecturer.Text = model.Lecturer; if (!string.IsNullOrEmpty(model.UnitIds)) { this.drpUnits.SelectedValueArray = model.UnitIds.Split(','); } if (!string.IsNullOrEmpty(model.WorkPostIds)) { this.drpWorkPost.SelectedValueArray = model.WorkPostIds.Split(','); } if (model.TrainingTime != null) { this.txtTrainingTime.Text = string.Format("{0:yyyy-MM-dd}", model.TrainingTime); } 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", ""); this.txtLecturer.Text = this.CurrUser.UserName; this.txtTrainingTime.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); } this.Grid1DataBind(); } } /// /// 下拉框加载 /// private void InitDropDownList() { //培训单位 UnitService.InitUnitDropDownList(this.drpUnits, this.ProjectId, false); //所属岗位 WorkPostService.InitWorkPostDropDownList(this.drpWorkPost, true); ////获取适用岗位下拉框 //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.WorkPostName, x.PersonName select x).ToList(); Grid1.DataSource = recordDetails; Grid1.DataBind(); } #endregion #region 选择按钮 /// /// 选择按钮 /// /// /// protected void btnSelect_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.Id)) { this.SaveData(BLL.Const.BtnSave); } //培训岗位 string workPostIds = string.Empty; foreach (var item in this.drpWorkPost.SelectedValueArray) { workPostIds += item + ","; } if (!string.IsNullOrEmpty(workPostIds)) { workPostIds = workPostIds.Substring(0, workPostIds.LastIndexOf(",")); } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SelectPerson.aspx?RecordId={0}&WorkPostIds={1}", this.Id, workPostIds, "编辑 - "))); } #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 workPostIds = string.Empty; foreach (var item in this.drpWorkPost.SelectedValueArray) { workPostIds += item + ","; } if (!string.IsNullOrEmpty(workPostIds)) { workPostIds = workPostIds.Substring(0, workPostIds.LastIndexOf(",")); } newModel.UnitIds = unitIds; newModel.WorkPostIds = workPostIds; 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 btnImport_Click(object sender, EventArgs e) { if (this.drpCategory.SelectedValue == BLL.Const._Null) { ShowNotify("请选择培训类别!", MessageBoxIcon.Warning); return; } if (this.drpCourse.SelectedValue == BLL.Const._Null) { ShowNotify("请选择培训课程!", MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(this.Id)) { this.SaveData(BLL.Const.BtnSave); } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("RecordIn.aspx?RecordId={0}", this.Id, "导入 - "), "导入", 900, 560)); } #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 } }