using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
namespace FineUIPro.Web.ZHGL.ServerCheck
{
public partial class SubUnitReport : PageBase
{
#region 定义变量
///
/// 主键
///
public string SubUnitReportId
{
get
{
return (string)ViewState["SubUnitReportId"];
}
set
{
ViewState["SubUnitReportId"] = value;
}
}
///
/// 明细主键
///
public string SubUnitReportItemId
{
get
{
return (string)ViewState["SubUnitReportItemId"];
}
set
{
ViewState["SubUnitReportItemId"] = value;
}
}
#endregion
#region 加载页面
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GetButtonPower();
this.InitTreeMenu();
}
}
#endregion
#region 加载树
///
/// 初始化树
///
private void InitTreeMenu()
{
trSubUnitReport.Nodes.Clear();
trSubUnitReport.ShowBorder = false;
trSubUnitReport.ShowHeader = false;
trSubUnitReport.EnableIcons = true;
trSubUnitReport.AutoScroll = true;
trSubUnitReport.EnableSingleClickExpand = true;
//TreeNode rootNode = new TreeNode
//{
// Text = "企业安全文件",
// NodeID = "0",
// Expanded = true
//};
//this.trSubUnitReport.Nodes.Add(rootNode);
BoundTree(this.trSubUnitReport.Nodes, "0");
}
///
///
///
///
///
private void BoundTree(TreeNodeCollection nodes, string menuId)
{
var dt = GetNewSubUnitReport(menuId);
if (dt.Count() > 0)
{
TreeNode tn = null;
foreach (var dr in dt)
{
tn = new TreeNode
{
Text = dr.SubUnitReportName,
NodeID = dr.SubUnitReportId,
ToolTip = "[" + dr.SubUnitReportCode + "]" + dr.SubUnitReportName,
EnableClickEvent = true
};
nodes.Add(tn);
if (tn != null)
{
if (BLL.SubUnitReportService.IsUpLoadSubUnitReport(dr.SubUnitReportId))
{
tn.Text = "" + tn.Text + "";
this.SetNodeColor(tn);
}
}
BoundTree(tn.Nodes, dr.SubUnitReportId);
}
}
}
///
/// 设置父级节点颜色
///
private void SetNodeColor(TreeNode tn)
{
if (tn.NodeID != "0")
{
tn.Text = "" + tn.Text + "";
if (tn.ParentNode != null)
{
this.SetNodeColor(tn.ParentNode);
}
}
}
#endregion
#region 得到菜单方法
///
/// 得到菜单方法
///
///
///
private List GetNewSubUnitReport(string parentId)
{
return (from x in Funs.DB.Supervise_SubUnitReport where x.SupSubUnitReportId == parentId orderby x.SubUnitReportCode descending select x).ToList(); ;
}
#endregion
#region 树点击事件
///
/// 选择Tree事件
///
///
///
protected void trSubUnitReport_NodeCommand(object sender, TreeCommandEventArgs e)
{
this.SubUnitReportId = string.Empty;
this.SubUnitReportItemId = string.Empty;
this.dpkReportDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
this.txtPlanReortDate.Text = string.Empty;
this.formTitle.Title = string.Empty;
var thisUnit = BLL.UnitService.GetUnitByUnitId(BLL.Const.UnitId_CD);
if (thisUnit != null)
{
this.txtUnitName.Text = thisUnit.UnitName;
}
this.panelCenterRegion.Hidden = true;
this.SubUnitReportId = this.trSubUnitReport.SelectedNodeID;
var subUnitReortItem = BLL.SubUnitReportItemService.GetSubUnitReportItemBySubUnitReportId(this.SubUnitReportId);
if (subUnitReortItem != null)
{
this.panelCenterRegion.Hidden = false;
this.txtReportTitle.Text = subUnitReortItem.ReportTitle;
this.dpkReportDate.Text = string.Format("{0:yyyy-MM-dd}", System.DateTime.Now);
this.SubUnitReportItemId = subUnitReortItem.SubUnitReportItemId;
if (!string.IsNullOrEmpty(subUnitReortItem.UnitId))
{
var unit = BLL.UnitService.GetUnitByUnitId(subUnitReortItem.UnitId);
if (unit != null)
{
this.txtUnitName.Text = unit.UnitName;
}
}
if (subUnitReortItem.PlanReortDate != null)
{
this.txtPlanReortDate.Text = string.Format("{0:yyyy-MM-dd}", subUnitReortItem.PlanReortDate);
}
this.txtReportTitle.Text = subUnitReortItem.ReportTitle;
this.txtReportContent.Text = subUnitReortItem.ReportContent;
if (subUnitReortItem.ReportDate.HasValue)
{
this.dpkReportDate.Text = string.Format("{0:yyyy-MM-dd}", subUnitReortItem.ReportDate);
}
if (subUnitReortItem.UpState == Const.UpState_3)
{
this.formTitle.Title = "上报状态:已上报";
if (this.CurrUser.UserId != BLL.Const.sysglyId)
{
this.btnSave.Hidden = true;
this.btnSaveUp.Hidden = true;
}
}
else
{
this.formTitle.Title = "上报状态:未上报";
this.btnSave.Hidden = false;
this.btnSaveUp.Hidden = false;
}
}
}
#endregion
#region 保存
///
/// 保存按钮
///
///
///
protected void btnSave_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.trSubUnitReport.SelectedNodeID))
{
SaveData(BLL.Const.UpState_1);
ShowNotify("保存成功!", MessageBoxIcon.Success);
this.InitTreeMenu();
this.EmptyText();
}
else
{
ShowNotify("请选择上报名称!", MessageBoxIcon.Warning);
return;
}
}
///
/// 保存并上报
///
///
///
protected void btnSaveUp_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.trSubUnitReport.SelectedNodeID))
{
SaveData(BLL.Const.UpState_2);
this.UpSubUnitReport(SubUnitReportId);//上报
this.InitTreeMenu();
this.EmptyText();
}
else
{
ShowNotify("请选择上报名称!", MessageBoxIcon.Warning);
return;
}
}
///
/// 保存数据
///
///
private void SaveData(string upState)
{
Model.Supervise_SubUnitReportItem item = new Model.Supervise_SubUnitReportItem
{
ReportTitle = this.txtReportTitle.Text.Trim(),
ReportContent = this.txtReportContent.Text.Trim()
};
if (!string.IsNullOrEmpty(this.dpkReportDate.Text.Trim()))
{
item.ReportDate = Convert.ToDateTime(this.dpkReportDate.Text.Trim());
}
item.UpState = upState;
if (!string.IsNullOrEmpty(this.SubUnitReportItemId))
{
item.SubUnitReportItemId = this.SubUnitReportItemId;
BLL.SubUnitReportItemService.UpdateSubUnitReportItem(item);
BLL.LogService.AddSys_Log(this.CurrUser, this.txtReportTitle.Text.Trim(), item.SubUnitReportItemId, BLL.Const.SubUnitReportMenuId, BLL.Const.BtnModify);
}
}
#endregion
#region 子单位上报到集团单位
///
/// 上报方法
///
///
///
private void UpSubUnitReport(string SubUnitReportId)
{
///创建客户端服务
if (!string.IsNullOrEmpty(this.trSubUnitReport.SelectedNodeID))
{
SaveData(BLL.Const.UpState_2);
string code = CNCECHSSEGetWebService.UpSupervise_SubUnitReportItem(this.SubUnitReportId, this.CurrUser);
if (code == "1")
{
ShowNotify("同步成功!", MessageBoxIcon.Success);
this.InitTreeMenu();
this.EmptyText();
}
else
{
Alert.ShowInParent("同步异常,请退出后重试!", MessageBoxIcon.Error);
}
this.InitTreeMenu();
this.EmptyText();
}
else
{
ShowNotify("请选择上报名称!", MessageBoxIcon.Warning);
return;
}
}
///
/// 企业安全文件上报到集团公司
///
///
///
//private void poxy_DataInsertSupervise_SubUnitReportTableCompleted(object sender, HSSEService.DataInsertSupervise_SubUnitReportItemItemTableCompletedEventArgs e)
//{
// if (e.Error == null)
// {
// var idList = e.Result;
// foreach (var item in idList)
// {
// var subUnitReportItem = BLL.SubUnitReportItemService.GetSubUnitReportItemById(item);
// if (subUnitReportItem != null)
// {
// subUnitReportItem.UpState = BLL.Const.UpState_3;
// subUnitReportItem.State = BLL.Const.UpState_3;
// BLL.SubUnitReportItemService.UpdateSubUnitReportItem(subUnitReportItem);
// }
// }
// this.InitTreeMenu();
// this.EmptyText();
// ShowNotify("【企业安全文件上报】上报到集团公司成功!", MessageBoxIcon.Success);
// BLL.LogService.AddSys_Log(this.CurrUser, "【企业安全文件上报】上报到集团公司" + idList.Count.ToString() + "条数据;", string.Empty, BLL.Const.SubUnitReportMenuId, BLL.Const.BtnUploadResources);
// }
// else
// {
// ShowNotify("【企业安全文件上报】上报到集团公司失败!", MessageBoxIcon.Warning);
// BLL.LogService.AddSys_Log(this.CurrUser, "【企业安全文件上报】上报到集团公司失败;", string.Empty, BLL.Const.SubUnitReportMenuId, BLL.Const.BtnUploadResources);
// }
//}
#endregion
#region 附件上传
///
/// 上传附件资源
///
///
///
protected void btnUploadResources_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.SubUnitReportItemId))
{
if (this.btnSave.Hidden)
{
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?toKeyId={0}&type=-1&path=FileUpload/SubUnitReport&menuId=" + BLL.Const.SubUnitReportMenuId, this.SubUnitReportItemId)));
}
else
{
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/SubUnitReport&menuId=" + BLL.Const.SubUnitReportMenuId, this.SubUnitReportItemId)));
}
}
else
{
ShowNotify("请选择上报名称!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region 清空文本
///
/// 清空文本
///
private void EmptyText()
{
this.SubUnitReportId = string.Empty;
this.SubUnitReportItemId = string.Empty;
this.txtReportTitle.Text = string.Empty;
this.txtReportContent.Text = string.Empty;
this.dpkReportDate.Text = string.Empty;
this.formTitle.Title = string.Empty;
this.txtUnitName.Text = string.Empty;
}
#endregion
#region 按钮权限
///
/// 按钮权限
///
private void GetButtonPower()
{
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.SubUnitReportMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnSave))
{
this.btnSave.Hidden = false;
this.btnSaveUp.Hidden = false;
}
}
}
#endregion
}
}