using BLL; using Model; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Data.Linq.SqlClient; using System.Data.SqlClient; using System.Linq; using System.Reflection; namespace FineUIPro.Web.Customization.CNCCG.HSSE.Problem { public partial class ProblemNoticeManagerEdit : PageBase { #region 定义项 /// /// 主键 /// public string ProNoticeId { get { return (string)ViewState["ProNoticeId"]; } set { ViewState["ProNoticeId"] = value; } } /// /// 签名附件路径 /// public string SignatureUrl { get { return (string)ViewState["SignatureUrl"]; } set { ViewState["SignatureUrl"] = value; } } /// /// 签名附件路径 /// public string SignatureUrl1 { get { return (string)ViewState["SignatureUrl1"]; } set { ViewState["SignatureUrl1"] = value; } } /// /// 类型 1查看 /// public string Types { get { return (string)ViewState["Types"]; } set { ViewState["Types"] = value; } } /// /// 定义集合 /// private static List details = new List(); #endregion /// /// 页面加载 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //初始化下拉框 InitDropDownList(); this.btnClose.OnClientClick = ActiveWindow.GetHideReference(); this.ProNoticeId = Request.Params["ProNoticeId"]; Types = Request.Params["Type"]; var thisUnit = BLL.CommonService.GetIsThisUnit(); BLL.ProjectService.InitAllProjectDropDownList(this.drpProject, true); if (!string.IsNullOrEmpty(ProNoticeId)) { var model = Funs.DB.Problem_Notice.FirstOrDefault(x => x.ProNoticeId == ProNoticeId); if (model != null) { drpProject.SelectedValue = model.ProjectId; if (model.ProType == "1") { rblType.SelectedValue = "1"; } else { rblType.SelectedValue = "2"; } UnitService.InitProjectUnitDropDownList(drpUnit, drpProject.SelectedValue, true); txtProCode.Text = model.ProCode; txtCheckStartTime.Text = string.Format("{0:yyyy-MM-dd}", model.CheckStartTime); txtCheckEndTime.Text = string.Format("{0:yyyy-MM-dd}", model.CheckEndTime); txtCheckMans.Text = model.CheckMans; txtSupervisionMan.Text = model.SupervisionMan; drpUnit.SelectedValue = model.Unitid; txtResume.Text = model.Resume; txtOtherJob.Text = model.OtherJob; //被检查单位负责人签名地址 if (!string.IsNullOrEmpty(model.CheckUnitSignature)) { this.SignatureUrl = model.CheckUnitSignature; this.Image2.ImageUrl = "~/" + this.SignatureUrl; } //检查组人员签名地址 if (!string.IsNullOrEmpty(model.CheckMansSignature)) { this.SignatureUrl1 = model.CheckMansSignature; this.Image1.ImageUrl = "~/" + this.SignatureUrl1; } if (details != null) { details.Clear(); } #region 加载检查项 var strSql = @"select F.ProNoticeCId,F.QueDescribe,F.Requirements,F.QueType as QueTypeName,F.RiskLevel as RiskLevelName ,F.CheckDatetime,F.ReDay,F.SortIndex from Problem_Notice_C F where ProNoticeId='" + model.ProNoticeId + "' order by SortIndex"; List listStr = new List(); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); details = GetList(table); Grid1.DataSource = table; Grid1.DataBind(); #endregion } } if (Types == "1") { btnSave.Hidden = true; btnSubmit.Hidden = true; //btnNew.Hidden = true; } } } /// /// 切换类型时 /// /// /// protected void rblType_SelectedIndexChanged(object sender, EventArgs e) { if (rblType.SelectedValue == "1") { //项目级 drpUnitT.Hidden = true; drpProject.Hidden = false; drpUnit.Hidden = false; } else { //公司级 drpProject.Hidden = true; drpUnit.Hidden = true; drpUnitT.Hidden = false; } } #region 初始化下拉框 private void InitDropDownList() { //问题类型 ListItem[] item = new ListItem[18]; item[0] = new ListItem("1.1安全管理制度类", "0"); item[1] = new ListItem("1.2组织机构及人员类", "1"); item[2] = new ListItem("1.3安全责任类", "2"); item[3] = new ListItem("1.4隐患排查类", "3"); item[4] = new ListItem("1.5安全教育培训类", ""); item[5] = new ListItem("1.6技术方案类", ""); item[6] = new ListItem("1.7质量管理类", ""); item[7] = new ListItem("1.8劳务实名类", ""); item[8] = new ListItem("1.9其他类", ""); item[9] = new ListItem("2.1临时用电类", ""); item[10] = new ListItem("2.2安全防护类", ""); item[11] = new ListItem("2.3机具设备类", ""); item[12] = new ListItem("2.4技术方案类", ""); item[13] = new ListItem("2.5消防安全类", ""); item[14] = new ListItem("2.6行为操作类", ""); item[15] = new ListItem("2.7文明施工类", ""); item[16] = new ListItem("2.8质量管理类", ""); item[17] = new ListItem("2.9其他类", ""); this.drpQueType.DataValueField = "Text"; this.drpQueType.DataTextField = "Text"; this.drpQueType.DataSource = item; this.drpQueType.DataBind(); //风险等级 ListItem[] item1 = new ListItem[3]; item1[0] = new ListItem("公司级", "公司级"); item1[1] = new ListItem("所属单位级", "所属单位级"); item1[2] = new ListItem("项目级", "项目级"); this.drpRiskLevel.DataValueField = "Text"; this.drpRiskLevel.DataTextField = "Text"; this.drpRiskLevel.DataSource = item1; this.drpRiskLevel.DataBind(); } #endregion #region 附件上传 /// /// 上传附件 /// /// /// protected void btnAttachUrl_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.ProNoticeId)) { SaveNew(); } //详情 if (Types == "1") { PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Problem&menuId={1}&type=-1", this.ProNoticeId, BLL.Const.ProblemNoticeManagerMenuId))); } else { PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Problem&menuId={1}&type=-1", this.ProNoticeId, BLL.Const.ProblemNoticeManagerMenuId))); } } #endregion #region 修改编号 /// /// 修改编号 根据检查时间识别到哪一个年份、哪一个季度 xxxx年x季度01 /// /// /// protected void changeCode(object sender, EventArgs e) { if (string.IsNullOrEmpty(ProNoticeId)) { var ObjCode = ""; var month = Convert.ToDateTime(Funs.GetNewDateTime(this.txtCheckStartTime.Text.Trim())); ObjCode = month.Year.ToString() + "年"; if (month.Month == 1 || month.Month == 2 || month.Month == 3) { ObjCode += "1季度"; } else if (month.Month == 4 || month.Month == 5 || month.Month == 6) { ObjCode += "2季度"; } else if (month.Month == 7 || month.Month == 8 || month.Month == 9) { ObjCode += "3季度"; } else if (month.Month == 10 || month.Month == 11 || month.Month == 12) { ObjCode += "4季度"; } //当前年份 //var count = Funs.DB.Problem_Notice.Where(x => SqlMethods.DateDiffDay(x.CreateDate, DateTime.Now) == 0).ToList().Count+1; var count = Funs.DB.Problem_Notice.Where(x => Convert.ToDateTime(x.CreateDate).Year == DateTime.Now.Year).ToList().Count + 1; if (count.ToString().Length == 1) { ObjCode += "0" + count.ToString(); } else { ObjCode += count.ToString(); } this.txtProCode.Text = ObjCode; } } #endregion #region 选择项目后加载项目中的单位 protected void changeProject(object sender, EventArgs e) { UnitService.InitProjectUnitDropDownList(drpUnit, drpProject.SelectedValue, true); } #endregion #region 保存 /// /// 保存 /// protected void btnSave_Click(object sender, EventArgs e) { if (rblType.SelectedValue == "1") { if (this.drpProject.SelectedValue == BLL.Const._Null) { ShowNotify("请选择项目!", MessageBoxIcon.Warning); return; } } else { if (this.drpUnitT.SelectedValue == BLL.Const._Null) { ShowNotify("请选择单位!", MessageBoxIcon.Warning); return; } } this.SaveData(Const.BtnSave); } /// /// 提交 /// /// /// protected void btnSubmit_Click(object sender, EventArgs e) { if (rblType.SelectedValue == "1") { if (this.drpProject.SelectedValue == BLL.Const._Null) { ShowNotify("请选择项目!", MessageBoxIcon.Warning); return; } if (this.drpUnit.SelectedValue == BLL.Const._Null) { ShowNotify("请选择回复单位!", MessageBoxIcon.Warning); return; } } else { if (this.drpUnitT.SelectedValue == BLL.Const._Null) { ShowNotify("请选择单位!", MessageBoxIcon.Warning); return; } } this.SaveData(Const.BtnSubmit); } /// /// 保存提交方法 /// /// private void SaveData(string type) { Model.Problem_Notice model = new Model.Problem_Notice { ProCode = txtProCode.Text.Trim(), CheckMans = txtCheckMans.Text.Trim(), CheckStartTime = Funs.GetNewDateTime(this.txtCheckStartTime.Text.Trim()), CheckEndTime = Funs.GetNewDateTime(this.txtCheckEndTime.Text.Trim()), Resume = txtResume.Text, OtherJob = txtOtherJob.Text, SupervisionMan = txtSupervisionMan.Text, CreateUser = CurrUser.UserId, CreateDate = DateTime.Now, State = "0", Unitid = this.drpUnit.SelectedValue }; if (rblType.SelectedValue == "1") { model.ProjectId = this.drpProject.SelectedValue; } else { model.ProjectId = this.drpUnit.SelectedValue; } model.ProType = rblType.SelectedValue; if (type == Const.BtnSubmit) { model.State = "1"; } //被检查单位负责人签名 if (!string.IsNullOrEmpty(this.SignatureUrl)) { model.CheckUnitSignature = SignatureUrl; model.CheckUnitDatetime = DateTime.Now; } //检查组人员签名 if (!string.IsNullOrEmpty(this.SignatureUrl1)) { model.CheckMansSignature = SignatureUrl1; model.CheckMansDatetime = DateTime.Now; } if (!string.IsNullOrEmpty(this.ProNoticeId)) { #region 状态 var newModel = Funs.DB.Problem_Notice.FirstOrDefault(x => x.ProNoticeId == ProNoticeId); if (newModel != null) { if (type == Const.BtnSubmit) { //提交 if (newModel.State == "1") { model.State = "2";//生成回复单 if (string.IsNullOrEmpty(this.SignatureUrl)) { ShowNotify("被检查单位负责人签名不能为空!", MessageBoxIcon.Warning); return; } } else { if (string.IsNullOrEmpty(this.SignatureUrl1)) { ShowNotify("检查组签名不能为空!", MessageBoxIcon.Warning); return; } } } else { //保存 model.State = newModel.State; } } #endregion model.ProNoticeId = this.ProNoticeId; BLL.ProblemNoticeService.Update(model); BLL.LogService.AddSys_Log(this.CurrUser, model.ProCode, model.ProNoticeId, BLL.Const.ProblemNoticeManagerMenuId, BLL.Const.BtnModify); // Check_ProblemDetailService.DeleteProblemDetails(this.ProblemId); } else { //第一次提交的时候 要判断签名是否为空 if (type == Const.BtnSubmit) { if (string.IsNullOrEmpty(this.SignatureUrl1)) { ShowNotify("检查组签名不能为空!", MessageBoxIcon.Warning); return; } } model.ProNoticeId = Guid.NewGuid().ToString(); this.ProNoticeId = model.ProNoticeId; BLL.ProblemNoticeService.Add(model); BLL.LogService.AddSys_Log(this.CurrUser, model.ProCode, model.ProNoticeId, BLL.Const.ProblemNoticeManagerMenuId, BLL.Const.BtnAdd); } this.SaveDetail(model.ProNoticeId); if (type == Const.BtnSubmit) { ShowNotify("提交成功,请等待单位回复", MessageBoxIcon.Success); } else { ShowNotify("保存成功。", MessageBoxIcon.Success); } PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } /// /// 保存明细项 /// private void SaveDetail(string objId) { //1.先删除明细项 var detailList = Funs.DB.Problem_Notice_C.Where(x => x.ProNoticeId == objId).ToList(); if (detailList.Count > 0) { Funs.DB.Problem_Notice_C.DeleteAllOnSubmit(detailList); Funs.DB.SubmitChanges(); } //2.根据列表中的明细项添加 List detailLists = new List(); JArray teamGroupData = Grid1.GetMergedData(); foreach (JObject teamGroupRow in teamGroupData) { JObject values = teamGroupRow.Value("values"); int rowIndex = teamGroupRow.Value("index"); Model.Problem_Notice_C newDetail = new Model.Problem_Notice_C { ProNoticeId = objId, //ProNoticeCId= values.Value("ProNoticeCId"), QueDescribe = values.Value("QueDescribe"), Requirements = values.Value("Requirements"), QueType = values.Value("QueTypeName"), RiskLevel = values.Value("RiskLevelName"), ReDay = values.Value("ReDay"), SortIndex = rowIndex }; if (Grid1.Rows[rowIndex].DataKeys.Length > 0) { newDetail.ProNoticeCId = Grid1.Rows[rowIndex].DataKeys[0].ToString(); } if (!string.IsNullOrEmpty(values.Value("CheckDatetime"))) { newDetail.CheckDatetime = values.Value("CheckDatetime"); } detailLists.Add(newDetail); } if (detailLists.Count > 0) { Funs.DB.Problem_Notice_C.InsertAllOnSubmit(detailLists); Funs.DB.SubmitChanges(); } } /// /// 添加 附件的时候添加 /// protected void SaveNew() { if (string.IsNullOrEmpty(this.ProNoticeId)) { Model.Problem_Notice model = new Model.Problem_Notice { ProNoticeId = Guid.NewGuid().ToString(), //ProjectId = this.drpProject.SelectedValue, ProCode = txtProCode.Text.Trim(), CheckMans = txtCheckMans.Text.Trim(), CheckStartTime = Funs.GetNewDateTime(this.txtCheckStartTime.Text.Trim()), CheckEndTime = Funs.GetNewDateTime(this.txtCheckEndTime.Text.Trim()), Resume = txtResume.Text, OtherJob = txtOtherJob.Text, SupervisionMan = txtSupervisionMan.Text, CreateUser = CurrUser.UserId, CreateDate = DateTime.Now, State = "0", Unitid = this.drpUnit.SelectedValue }; if (rblType.SelectedValue == "1") { model.ProjectId = this.drpProject.SelectedValue; } else { model.ProjectId = this.drpUnit.SelectedValue; } model.ProType = rblType.SelectedValue; //被检查单位负责人签名 if (!string.IsNullOrEmpty(this.SignatureUrl)) { model.CheckUnitSignature = SignatureUrl; model.CheckUnitDatetime = DateTime.Now; } //检查组人员签名 if (!string.IsNullOrEmpty(this.SignatureUrl1)) { model.CheckMansSignature = SignatureUrl1; model.CheckMansDatetime = DateTime.Now; } this.ProNoticeId = model.ProNoticeId; BLL.ProblemNoticeService.Add(model); BLL.LogService.AddSys_Log(this.CurrUser, model.ProCode, model.ProNoticeId, BLL.Const.ProblemNoticeManagerMenuId, BLL.Const.BtnAdd); } } #endregion #region 上传签名 /// /// 被检查单位负责人上传签名 /// /// /// protected void btnSignature_Click(object sender, EventArgs e) { if (fileSignature.HasFile) { string fileName = fileSignature.ShortFileName; if (!ValidateFileType(fileName)) { ShowNotify("无效的文件类型!", MessageBoxIcon.Warning); return; } this.SignatureUrl = UploadFileService.UploadAttachment(Funs.RootPath, this.fileSignature, this.SignatureUrl, UploadFileService.UserFilePath); this.Image2.ImageUrl = "~/" + this.SignatureUrl; } } /// /// 检查组人员上传签名 /// /// /// protected void btnSignature_Click1(object sender, EventArgs e) { if (fileSignature1.HasFile) { string fileName = fileSignature1.ShortFileName; if (!ValidateFileType(fileName)) { ShowNotify("无效的文件类型!", MessageBoxIcon.Warning); return; } this.SignatureUrl1 = UploadFileService.UploadAttachment(Funs.RootPath, this.fileSignature1, this.SignatureUrl1, UploadFileService.UserFilePath); this.Image1.ImageUrl = "~/" + this.SignatureUrl1; } } #endregion #region 检查项 /// /// /// /// /// protected void Grid1_PreDataBound(object sender, EventArgs e) { // 设置LinkButtonField的点击客户端事件 //LinkButtonField deleteField = Grid1.FindColumn("Delete") as LinkButtonField; //deleteField.OnClientClick = GetDeleteScript(); } /// /// 删除提示 /// /// private string GetDeleteScript() { return Confirm.GetShowReference("删除选中行?", String.Empty, MessageBoxIcon.Question, Grid1.GetDeleteSelectedRowsReference(), String.Empty); } protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { string itemId = Grid1.DataKeys[e.RowIndex][0].ToString(); if (e.CommandName == "attchUrl") { if (Types == "1") { PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Problem&menuId={1}&type=-1", itemId, BLL.Const.ProblemNoticeManagerMenuId))); } else { PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Problem&menuId={1}&type=-1", itemId, BLL.Const.ProblemNoticeManagerMenuId))); } } } /// /// 新增检查项 /// /// /// protected void btnAdd_Click(object sender, EventArgs e) { JArray teamGroupData = Grid1.GetMergedData(); List list = new List(); foreach (JObject teamGroupRow in teamGroupData) { JObject values = teamGroupRow.Value("values"); values.Add("ProNoticeCId", teamGroupRow.Value("id")); values.Add("SortIndex", teamGroupRow.Value("index")); list.Add(values); } JObject defaultObj = new JObject { { "ProNoticeCId",Guid.NewGuid() }, { "SortIndex", "" }, { "QueDescribe", "" }, { "Requirements", "" }, { "QueTypeName",""}, { "RiskLevelName", "" }, {"CheckDatetime","" }, { "ReDay", "" }, { "Delete", String.Format("", GetDeleteScript(), IconHelper.GetResolvedIconUrl(Icon.Delete)) } }; list.Add(defaultObj); Grid1.DataSource = list; Grid1.DataBind(); } #endregion #region datable转换list public class ProblemNoticeItems { public string ProNoticeCId { get; set; } public string QueDescribe { get; set; } public string Requirements { get; set; } public string QueTypeName { get; set; } public string RiskLevelName { get; set; } public DateTime? CheckDatetime { get; set; } public string ReDay { get; set; } public int SortIndex { get; set; } } public List GetList(DataTable table) { List list = new List(); T t = default(T); PropertyInfo[] propertypes = null; string tempName = string.Empty; foreach (DataRow row in table.Rows) { t = Activator.CreateInstance(); propertypes = t.GetType().GetProperties(); foreach (PropertyInfo pro in propertypes) { tempName = pro.Name; if (table.Columns.Contains(tempName)) { object value = row[tempName]; if (!value.ToString().Equals("")) { pro.SetValue(t, value, null); } } } list.Add(t); } return list.Count == 0 ? null : list; } #endregion } }