286 lines
12 KiB
C#
286 lines
12 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Model;
|
|
using BLL;
|
|
using System.Collections.Generic;
|
|
using Microsoft.Office.Interop.Excel;
|
|
|
|
namespace FineUIPro.Web.HSSE.EduTrain
|
|
{
|
|
public partial class CompanyTrainingItemSave : PageBase
|
|
{
|
|
#region 定义变量
|
|
/// <summary>
|
|
/// 主键
|
|
/// </summary>
|
|
public string CompanyTrainingItemId
|
|
{
|
|
get
|
|
{
|
|
return (string)ViewState["CompanyTrainingItemId"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["CompanyTrainingItemId"] = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 主表主键
|
|
/// </summary>
|
|
public string CompanyTrainingId
|
|
{
|
|
get
|
|
{
|
|
return (string)ViewState["CompanyTrainingId"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["CompanyTrainingId"] = value;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 加载页面
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
this.GetButtonPower();
|
|
btnClose.OnClientClick = ActiveWindow.GetHideReference();
|
|
BoundTree(treeTestTraining.Nodes, "0");
|
|
BindEnumrableToDropDownList();
|
|
this.CompanyTrainingItemId = Request.QueryString["CompanyTrainingItemId"];
|
|
this.CompanyTrainingId = Request.QueryString["CompanyTrainingId"];
|
|
if (!string.IsNullOrEmpty(this.CompanyTrainingItemId))
|
|
{
|
|
var model = CompanyTrainingItemService.GetCompanyTrainingItemById(this.CompanyTrainingItemId);
|
|
if (model != null)
|
|
{
|
|
this.CompanyTrainingId = model.CompanyTrainingId;
|
|
txtCompanyTrainingItemCode.Text = model.CompanyTrainingItemCode;
|
|
txtCompanyTrainingItemName.Text = model.CompanyTrainingItemName;
|
|
txtCompileMan.Text = model.CompileMan;
|
|
hdCompileMan.Text = model.CompileMan;
|
|
if (model.Outcome!=null)
|
|
drpOutcome.SelectedValue = model.Outcome.ToString();
|
|
if (!string.IsNullOrEmpty(model.TestTrainingIds))
|
|
{
|
|
ddTestTraining.Values = model.TestTrainingIds.Split(',');
|
|
string text = "";
|
|
var trains = Funs.DB.Training_TestTraining.ToList();
|
|
foreach (var ids in ddTestTraining.Values)
|
|
{
|
|
var t = trains.FirstOrDefault(x => x.TrainingId == ids);
|
|
if (t != null)
|
|
{
|
|
text += "[" + t.TrainingCode + "]" + t.TrainingName + ",";
|
|
}
|
|
}
|
|
ddTestTraining.Text = text.TrimEnd(new char[] { ',' });
|
|
}
|
|
if (!string.IsNullOrEmpty(model.WorkPostIds))
|
|
{
|
|
string[] ids1 = model.WorkPostIds.Split(',');
|
|
DropDownBox1.Values = ids1;
|
|
}
|
|
if (model.LearningTime.HasValue)
|
|
{
|
|
txtLearningTime.Text = (model.LearningTime.Value/60).ToString();
|
|
}
|
|
if (model.CompileDate != null)
|
|
{
|
|
txtCompileDate.Text = string.Format("{0:yyyy-MM-dd}", model.CompileDate);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var cTraining = BLL.CompanyTrainingService.GetCompanyTrainingById(this.CompanyTrainingId);
|
|
if (cTraining != null)
|
|
{
|
|
txtCompileMan.Text = this.CurrUser.UserName;
|
|
hdCompileMan.Text = this.CurrUser.UserName;
|
|
this.txtCompanyTrainingItemName.Text = cTraining.CompanyTrainingName;
|
|
this.txtCompanyTrainingItemCode.Text = SQLHelper.RunProcNewId("SpGetNewCode3", "Training_CompanyTrainingItem", "CompanyTrainingItemCode", cTraining.CompanyTrainingCode + "-");
|
|
txtCompileDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void BindEnumrableToDropDownList()
|
|
{
|
|
List<Model.Base_WorkPost> workPostList = BLL.WorkPostService.GetWorkPostList();
|
|
RadioButtonList1.DataTextField = "WorkPostName";
|
|
RadioButtonList1.DataValueField = "WorkPostId";
|
|
RadioButtonList1.DataSource = workPostList;
|
|
RadioButtonList1.DataBind();
|
|
|
|
Enums.InitOutcomeDropDownList(drpOutcome, false);
|
|
}
|
|
|
|
#endregion
|
|
private List<Model.Training_TestTraining> GetNewTraining(string parentId)
|
|
{
|
|
return (from x in Funs.DB.Training_TestTraining
|
|
where x.SupTrainingId == parentId
|
|
orderby x.TrainingCode
|
|
select x).ToList();
|
|
}
|
|
private void BoundTree(TreeNodeCollection nodes, string parentId)
|
|
{
|
|
var dt = GetNewTraining(parentId);
|
|
if (dt.Count() > 0)
|
|
{
|
|
TreeNode tn = null;
|
|
foreach (var dr in dt)
|
|
{
|
|
string name = dr.TrainingName;
|
|
if (!string.IsNullOrEmpty(dr.TrainingCode))
|
|
{
|
|
name = "[" + dr.TrainingCode + "]" + dr.TrainingName;
|
|
}
|
|
tn = new TreeNode
|
|
{
|
|
|
|
Text = name,
|
|
NodeID = dr.TrainingId,
|
|
EnableClickEvent = true,
|
|
ToolTip = dr.TrainingName
|
|
};
|
|
nodes.Add(tn);
|
|
///是否存在下级节点
|
|
var sup = Funs.DB.Training_TestTraining.FirstOrDefault(x => x.SupTrainingId == tn.NodeID);
|
|
if (sup != null)
|
|
{
|
|
BoundTree(tn.Nodes, tn.NodeID);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#region 保存
|
|
/// <summary>
|
|
/// 保存数据
|
|
/// </summary>
|
|
private void SaveData(bool isClose)
|
|
{
|
|
Model.Training_CompanyTrainingItem newModel = new Training_CompanyTrainingItem
|
|
{
|
|
CompanyTrainingItemCode = this.txtCompanyTrainingItemCode.Text.Trim(),
|
|
CompanyTrainingItemName = this.txtCompanyTrainingItemName.Text.Trim(),
|
|
CompileMan = hdCompileMan.Text.Trim()
|
|
};
|
|
|
|
newModel.Outcome = int.Parse(drpOutcome.SelectedValue);
|
|
if (!string.IsNullOrEmpty(DropDownBox1.Text))
|
|
{
|
|
newModel.WorkPostIds = String.Join(",", DropDownBox1.Values);
|
|
newModel.WorkPostNames = String.Join(",", DropDownBox1.Texts);
|
|
}
|
|
if (ddTestTraining.Values != null && ddTestTraining.Values.Length > 0)
|
|
{
|
|
newModel.TestTrainingIds = string.Join(",", ddTestTraining.Values);
|
|
}
|
|
if (!string.IsNullOrEmpty(txtLearningTime.Text))
|
|
{
|
|
newModel.LearningTime = int.Parse(txtLearningTime.Text)*60;
|
|
}
|
|
if (!string.IsNullOrEmpty(txtCompileDate.Text.Trim()))
|
|
{
|
|
newModel.CompileDate = Convert.ToDateTime(txtCompileDate.Text.Trim());
|
|
}
|
|
if (!string.IsNullOrEmpty(this.CompanyTrainingItemId))
|
|
{
|
|
newModel.CompanyTrainingItemId = this.CompanyTrainingItemId;
|
|
BLL.CompanyTrainingItemService.UpdateCompanyTrainingItem(newModel);
|
|
BLL.LogService.AddSys_Log(this.CurrUser, newModel.CompanyTrainingItemCode, newModel.CompanyTrainingItemId,BLL.Const.CompanyTrainingMenuId,BLL.Const.BtnModify);
|
|
}
|
|
else
|
|
{
|
|
newModel.CompanyTrainingId = this.CompanyTrainingId;
|
|
this.CompanyTrainingItemId = SQLHelper.GetNewID(typeof(Model.Training_CompanyTrainingItem));
|
|
newModel.CompanyTrainingItemId = this.CompanyTrainingItemId;
|
|
BLL.CompanyTrainingItemService.AddCompanyTrainingItem(newModel);
|
|
BLL.LogService.AddSys_Log(this.CurrUser, newModel.CompanyTrainingItemCode, newModel.CompanyTrainingItemId, BLL.Const.CompanyTrainingMenuId, BLL.Const.BtnAdd);
|
|
}
|
|
if (isClose)
|
|
{
|
|
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存按钮
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
SaveData(true);
|
|
}
|
|
#endregion
|
|
|
|
#region 验证教材名称是否存在
|
|
/// <summary>
|
|
/// 验证教材名称是否存在
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void TextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
var q = Funs.DB.Training_CompanyTrainingItem.FirstOrDefault(x => x.CompanyTrainingId == this.CompanyTrainingId && x.CompanyTrainingItemName == this.txtCompanyTrainingItemName.Text.Trim() && (x.CompanyTrainingItemId != this.CompanyTrainingItemId || (this.CompanyTrainingItemId == null && x.CompanyTrainingItemId != null)));
|
|
if (q != null)
|
|
{
|
|
ShowNotify("输入的教材名称已存在!", MessageBoxIcon.Warning);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 上传附件资源
|
|
/// <summary>
|
|
/// 上传附件资源
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnUploadResources_Click(object sender, EventArgs e)
|
|
{
|
|
if (this.btnSave.Hidden)
|
|
{
|
|
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/CompanyTraining&menuId={1}&type=-1", CompanyTrainingItemId, BLL.Const.CompanyTrainingMenuId)));
|
|
}
|
|
else
|
|
{
|
|
if (string.IsNullOrEmpty(this.CompanyTrainingItemId))
|
|
{
|
|
SaveData(false);
|
|
}
|
|
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/CompanyTraining&menuId={1}", CompanyTrainingItemId, BLL.Const.CompanyTrainingMenuId)));
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 按钮权限
|
|
/// <summary>
|
|
/// 获取按钮权限
|
|
/// </summary>
|
|
/// <param name="button"></param>
|
|
/// <returns></returns>
|
|
private void GetButtonPower()
|
|
{
|
|
if (Request.Params["value"] == "0")
|
|
{
|
|
return;
|
|
}
|
|
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.CompanyTrainingMenuId);
|
|
if (buttonList.Count() > 0)
|
|
{
|
|
if (buttonList.Contains(BLL.Const.BtnSave))
|
|
{
|
|
this.btnSave.Hidden = false;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |