xinjiang/SGGL/FineUIPro.Web/HSSE/PostTraining/RecordEdit.aspx.cs

369 lines
14 KiB
C#
Raw Normal View History

2025-02-21 18:11:40 +08:00
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
/// <summary>
/// 主键
/// </summary>
public string Id
{
get
{
return (string)ViewState["Id"];
}
set
{
ViewState["Id"] = value;
}
}
/// <summary>
/// 项目主键
/// </summary>
public string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
/// <summary>
/// 定义集合
/// </summary>
private static List<Model.View_PostTraining_RecordDetail> recordDetails = new List<Model.View_PostTraining_RecordDetail>();
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
2025-02-25 16:41:06 +08:00
this.txtName.Text = model.Name;
this.txtContent.Text = model.Content;
2025-02-21 18:11:40 +08:00
this.txtRemark.Text = model.Remark;
2025-02-25 16:41:06 +08:00
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);
}
2025-02-21 18:11:40 +08:00
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", "");
2025-02-25 16:41:06 +08:00
this.txtLecturer.Text = this.CurrUser.UserName;
this.txtTrainingTime.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
2025-02-21 18:11:40 +08:00
}
2025-02-25 16:41:06 +08:00
this.Grid1DataBind();
2025-02-21 18:11:40 +08:00
}
}
/// <summary>
/// 下拉框加载
/// </summary>
private void InitDropDownList()
{
//培训单位
UnitService.InitUnitDropDownList(this.drpUnits, this.ProjectId, false);
2025-02-25 16:41:06 +08:00
//所属岗位
WorkPostService.InitWorkPostDropDownList(this.drpWorkPost, true);
////获取适用岗位下拉框
//PostTrainingRoleService.InitPostTrainingRoleDropDownList(this.drpRole, false);
2025-02-21 18:11:40 +08:00
//获取培训类别下拉框
PostTrainingCategoryService.InitPostTrainingCategoryDropDownList(this.drpCategory, false);
//获取培训方式下拉框
PostTrainingMethodService.InitPostTrainingMethodDropDownList(this.drpMethod, null, false);
this.drpUnits.SelectedValue = this.CurrUser.UnitId;
}
/// <summary>
/// 培训类别下拉加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpCategory_SelectedIndexChanged(object sender, EventArgs e)
{
//培训课程
PostTrainingCourseService.InitPostTrainingCourseDropDownList(this.drpCourse, this.drpCategory.SelectedValue, false);
}
/// <summary>
/// 绑定 Grid1
/// </summary>
private void Grid1DataBind()
{
recordDetails = (from x in Funs.DB.View_PostTraining_RecordDetail
where x.RecordId == this.Id
2025-02-25 16:41:06 +08:00
orderby x.UnitName, x.WorkPostName, x.PersonName
2025-02-21 18:11:40 +08:00
select x).ToList();
Grid1.DataSource = recordDetails;
Grid1.DataBind();
}
#endregion
#region
/// <summary>
/// 选择按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSelect_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.Id))
{
this.SaveData(BLL.Const.BtnSave);
}
//培训岗位
2025-02-25 16:41:06 +08:00
string workPostIds = string.Empty;
foreach (var item in this.drpWorkPost.SelectedValueArray)
2025-02-21 18:11:40 +08:00
{
2025-02-25 16:41:06 +08:00
workPostIds += item + ",";
2025-02-21 18:11:40 +08:00
}
2025-02-25 16:41:06 +08:00
if (!string.IsNullOrEmpty(workPostIds))
2025-02-21 18:11:40 +08:00
{
2025-02-25 16:41:06 +08:00
workPostIds = workPostIds.Substring(0, workPostIds.LastIndexOf(","));
2025-02-21 18:11:40 +08:00
}
2025-02-25 16:41:06 +08:00
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SelectPerson.aspx?RecordId={0}&WorkPostIds={1}", this.Id, workPostIds, "编辑 - ")));
2025-02-21 18:11:40 +08:00
}
#endregion
#region
/// <summary>
/// 批量删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
/// <summary>
/// 关闭弹出窗
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, EventArgs e)
{
this.Grid1DataBind();
this.txtPersonNum.Text = recordDetails.Count.ToString();
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
this.SaveData(BLL.Const.BtnSave);
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
}
/// <summary>
/// 保存数据
/// </summary>
/// <param name="type"></param>
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(","));
}
//培训岗位
2025-02-25 16:41:06 +08:00
string workPostIds = string.Empty;
foreach (var item in this.drpWorkPost.SelectedValueArray)
2025-02-21 18:11:40 +08:00
{
2025-02-25 16:41:06 +08:00
workPostIds += item + ",";
2025-02-21 18:11:40 +08:00
}
2025-02-25 16:41:06 +08:00
if (!string.IsNullOrEmpty(workPostIds))
2025-02-21 18:11:40 +08:00
{
2025-02-25 16:41:06 +08:00
workPostIds = workPostIds.Substring(0, workPostIds.LastIndexOf(","));
2025-02-21 18:11:40 +08:00
}
newModel.UnitIds = unitIds;
2025-02-25 16:41:06 +08:00
newModel.WorkPostIds = workPostIds;
2025-02-21 18:11:40 +08:00
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<string>("status");
// JObject values = mergedRow.Value<JObject>("values");
// Model.PostTraining_Record_Detail detail = BLL.PostTrainingRecordDetailService.GetRecordDetailById(values.Value<string>("DetailId").ToString());
// if (detail != null)
// {
// if (values.Value<string>("CheckResult").ToString() == "1")
// {
// detail.CheckResult = true;
// }
// else
// {
// detail.CheckResult = false;
// }
// detail.CheckScore = Funs.GetNewDecimalOrZero(values.Value<string>("CheckScore").ToString()); ;
// BLL.EduTrain_TrainRecordDetailService.UpdateTrainDetail(detail);
// }
//}
}
#endregion
2025-02-25 16:41:06 +08:00
#region
/// <summary>
/// 导入按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
2025-02-21 18:11:40 +08:00
#region
/// <summary>
/// 上传附件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
}
}