using System;
using System.Linq;
using Model;
using BLL;
using System.Collections.Generic;
using Microsoft.Office.Interop.Excel;
namespace FineUIPro.Web.BaseInfo
{
public partial class SafetyProblemClassifyItemSave : PageBase
{
#region 定义变量
///
/// 主键
///
public string ClassifyItemId
{
get
{
return (string)ViewState["ClassifyItemId"];
}
set
{
ViewState["ClassifyItemId"] = value;
}
}
///
/// 主表主键
///
public string ClassifyId
{
get
{
return (string)ViewState["ClassifyId"];
}
set
{
ViewState["ClassifyId"] = 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.ClassifyItemId = Request.QueryString["ClassifyItemId"];
this.ClassifyId = Request.QueryString["ClassifyId"];
if (!string.IsNullOrEmpty(this.ClassifyItemId))
{
var model = SafetyProblemClassifyItemService.GetClassifyItemById(this.ClassifyItemId);
if (model != null)
{
this.ClassifyId = model.ClassifyId;
this.txtClassifyItemCode.Text = model.ClassifyItemCode;
this.txtClassifyItemName.Text = model.ClassifyItemName;
this.txtCompileMan.Text = model.CompileManName;
if (model.CompileDate != null)
{
txtCompileDate.Text = string.Format("{0:yyyy-MM-dd}", model.CompileDate);
}
}
}
else
{
var model = BLL.CompanyTrainingService.GetCompanyTrainingById(this.ClassifyId);
if (model != null)
{
this.txtCompileMan.Text = this.CurrUser.UserName;
this.txtClassifyItemName.Text = model.CompanyTrainingName;
//this.txtClassifyItemCode.Text = SQLHelper.RunProcNewId("SpGetNewCode3", "Base_SafetyProblemClassifyItem", "ClassifyItemCode", model.ClassifyItemCode + "-");
this.txtCompileDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
}
}
}
}
#endregion
private List 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 保存
///
/// 保存数据
///
private void SaveData(bool isClose)
{
Model.Base_SafetyProblemClassifyItem newModel = new Base_SafetyProblemClassifyItem
{
ClassifyItemCode = this.txtClassifyItemCode.Text.Trim(),
ClassifyItemName = this.txtClassifyItemName.Text.Trim(),
CompileMan = this.CurrUser.UserId,
CompileManName = this.CurrUser.UserName,
};
if (!string.IsNullOrEmpty(txtCompileDate.Text.Trim()))
{
newModel.CompileDate = Convert.ToDateTime(txtCompileDate.Text.Trim());
}
if (!string.IsNullOrEmpty(this.ClassifyItemId))
{
newModel.ClassifyItemId = this.ClassifyItemId;
BLL.SafetyProblemClassifyItemService.UpdateClassifyItem(newModel);
BLL.LogService.AddSys_Log(this.CurrUser, newModel.ClassifyItemCode, newModel.ClassifyItemId, BLL.Const.SafetyProblemClassifyMenuId, BLL.Const.BtnModify);
}
else
{
newModel.ClassifyId = this.ClassifyId;
this.ClassifyItemId = SQLHelper.GetNewID(typeof(Model.Base_SafetyProblemClassifyItem));
newModel.ClassifyItemId = this.ClassifyItemId;
BLL.SafetyProblemClassifyItemService.AddClassifyItem(newModel);
BLL.LogService.AddSys_Log(this.CurrUser, newModel.ClassifyItemCode, newModel.ClassifyItemId, BLL.Const.SafetyProblemClassifyMenuId, BLL.Const.BtnAdd);
}
if (isClose)
{
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
}
///
/// 保存按钮
///
///
///
protected void btnSave_Click(object sender, EventArgs e)
{
SaveData(true);
}
#endregion
#region 验证安全问题分类是否存在
///
/// 验证安全问题分类是否存在
///
///
///
protected void TextBox_TextChanged(object sender, EventArgs e)
{
var q = Funs.DB.Base_SafetyProblemClassifyItem.FirstOrDefault(x => x.ClassifyId == this.ClassifyId && x.ClassifyItemName == this.txtClassifyItemName.Text.Trim() && (x.ClassifyItemId != this.ClassifyItemId || (this.ClassifyItemId == null && x.ClassifyItemId != null)));
if (q != null)
{
ShowNotify("输入的安全问题分类已存在!", MessageBoxIcon.Warning);
}
}
#endregion
//#region 上传附件资源
/////
///// 上传附件资源
/////
/////
/////
//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", ClassifyItemId, BLL.Const.SafetyProblemClassifyMenuId)));
// }
// else
// {
// if (string.IsNullOrEmpty(this.ClassifyItemId))
// {
// SaveData(false);
// }
// PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/CompanyTraining&menuId={1}", ClassifyItemId, BLL.Const.SafetyProblemClassifyMenuId)));
// }
//}
//#endregion
#region 按钮权限
///
/// 获取按钮权限
///
///
///
private void GetButtonPower()
{
if (Request.Params["value"] == "0")
{
return;
}
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.SafetyProblemClassifyMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnSave))
{
this.btnSave.Hidden = false;
}
}
}
#endregion
}
}