using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using BLL; using Newtonsoft.Json.Linq; 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(CommonService.GetThisUnitId()); 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); 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 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 附件上传 /// /// 上传附件资源 /// /// /// 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 /// /// 从集团获取 /// /// /// protected void btnGet_Click(object sender, EventArgs e) { var returnValue = getSupervise_SubUnitReportListToSUB(); if (returnValue.code == 1) { ShowNotify(returnValue.message, MessageBoxIcon.Success); } else { Alert.ShowInTop(returnValue.message, MessageBoxIcon.Success); } } #region 获取 /// /// 获取 /// /// /// public static Model.ResponeData getSupervise_SubUnitReportListToSUB() { var responeData = new Model.ResponeData(); try { string baseurl = SysConstSetService.CNCECPath + "/api/HSSEData/getSubUnitReport"; string contenttype = "application/json;charset=unicode"; Hashtable newToken = new Hashtable { { "token", ServerService.GetToken().Token } }; var strJosn = APIGetHttpService.Http(baseurl, "GET", contenttype, newToken, null); if (!string.IsNullOrEmpty(strJosn)) { JObject obj = JObject.Parse(strJosn); responeData.code = Funs.GetNewIntOrZero(obj["code"].ToString()); responeData.message = obj["message"].ToString(); if (responeData.code == 1) { string data = obj["data"].ToString(); JArray getData = JArray.Parse(data); if (getData.Count() > 0) { using (Model.SUBQHSEDB db = new Model.SUBQHSEDB(Funs.ConnString)) { if (getData.Count() > 0) { foreach (var item in getData) { string getSubUnitReportId = item["SubUnitReportId"].ToString(); var newSubUnitReport = db.Supervise_SubUnitReport.FirstOrDefault(e => e.SubUnitReportId == getSubUnitReportId); if (newSubUnitReport == null) { Model.Supervise_SubUnitReport newSubUnitReport1 = new Model.Supervise_SubUnitReport { SubUnitReportId = getSubUnitReportId, SubUnitReportCode = item["SubUnitReportCode"].ToString(), SubUnitReportName = item["SubUnitReportName"].ToString(), SupSubUnitReportId = item["SupSubUnitReportId"].ToString(), IsEndLever = Convert.ToBoolean(item["IsEndLever"].ToString()), }; db.Supervise_SubUnitReport.InsertOnSubmit(newSubUnitReport1); db.SubmitChanges(); } else { newSubUnitReport.SubUnitReportCode = item["SubUnitReportCode"].ToString(); newSubUnitReport.SubUnitReportName = item["SubUnitReportName"].ToString(); newSubUnitReport.SupSubUnitReportId = item["SupSubUnitReportId"].ToString(); newSubUnitReport.IsEndLever = Convert.ToBoolean(item["IsEndLever"].ToString()); db.SubmitChanges(); } } } string thisUnitId = CommonService.GetThisUnitId(); var strJosnItem = APIGetHttpService.Http(SysConstSetService.CNCECPath + "/api/HSSEData/getSubUnitReportItem?unitId=" + thisUnitId, "GET", contenttype, newToken, null); JObject objItem = JObject.Parse(strJosnItem); if (Funs.GetNewIntOrZero(objItem["code"].ToString()) == 1) { JArray getDataItem = JArray.Parse(objItem["data"].ToString()); if (getDataItem.Count() > 0) { foreach (var item in getDataItem) { string getSubUnitReportId = item["SubUnitReportId"].ToString(); string getSubUnitReportItemId = item["SubUnitReportItemId"].ToString(); var newItem = db.Supervise_SubUnitReportItem.FirstOrDefault(e => e.SubUnitReportItemId == getSubUnitReportItemId); if (newItem == null) { var newSubUnitReport = db.Supervise_SubUnitReport.FirstOrDefault(e => e.SubUnitReportId == getSubUnitReportId); if (newSubUnitReport != null) { Model.Supervise_SubUnitReportItem newItem1 = new Model.Supervise_SubUnitReportItem { SubUnitReportItemId = getSubUnitReportItemId, SubUnitReportId = getSubUnitReportId, UnitId = item["UnitId"].ToString(), PlanReortDate = Funs.GetNewDateTime(item["PlanReortDate"].ToString()), State = item["State"].ToString(), }; db.Supervise_SubUnitReportItem.InsertOnSubmit(newItem1); db.SubmitChanges(); } } else { newItem.SubUnitReportId = getSubUnitReportId; newItem.UnitId = item["UnitId"].ToString(); newItem.PlanReortDate = Funs.GetNewDateTime(item["PlanReortDate"].ToString()); newItem.State = item["State"].ToString(); db.SubmitChanges(); } } } responeData.message = "获取成功:类型记录" + getData.Count().ToString() + "条;明细记录" + getDataItem.Count().ToString() + "条"; } } } } } } catch (Exception ex) { responeData.code = 0; responeData.message = "获取失败:" + ex.Message; ErrLogInfo.WriteLog("企业安全文件获取!", ex); } return responeData; } #endregion } }