SGGL_HBAZ/SGGL/FineUIPro.Web/OfficeCheck/Inspect/ProjectSafetyInspectionEdit...

470 lines
18 KiB
C#

using BLL;
using Model;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using BLL.OfficeCheck.Inspect;
using System.Data.SqlClient;
namespace FineUIPro.Web.OfficeCheck.Inspect
{
public partial class ProjectSafetyInspectionEdit : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
public string InspectionId
{
get
{
return (string)ViewState["InspectionId"];
}
set
{
ViewState["InspectionId"] = value;
}
}
/// <summary>
/// 项目主键
/// </summary>
public string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
public string PhotoUrl
{
get
{
return (string)ViewState["PhotoUrl"];
}
set
{
ViewState["PhotoUrl"] = value;
}
}
public string VideoUrl
{
get
{
return (string)ViewState["VideoUrl"];
}
set
{
ViewState["VideoUrl"] = value;
}
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.btnMenuRectify.Hidden = false;
this.btnMenuShow.Hidden = false;
this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
this.ProjectId = Request.Params["ProjectId"];
UserService.InitUserDropDownList(this.drpPersonResponsible, this.ProjectId, true);
this.dpkInspectTime.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
BindGrid();
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
this.InspectionId = Request.Params["InspectionId"];
var Inspection = Inspect_InspectionService.GetInspectionByInspectionId(this.InspectionId);
if (Inspection != null)
{
this.ProjectId = Inspection.ProjectId;
if (this.ProjectId != this.CurrUser.LoginProjectId)
{
this.InitDropDownList();
}
txtInspectionCode.Text = Inspection.InspectionCode;
txtDescription.Text = Inspection.Description;
this.drpPersonResponsible.SelectedValue = Inspection.PersonResponsible;
if (Inspection.InspectTime != null)
{
this.dpkInspectTime.Text = string.Format("{0:yyyy-MM-dd}", Inspection.InspectTime);
}
string strSql =
@"select item.InspectionItemId,item.InspectionId,item.InspectionDescribe,item.PhotoUrl,item.VideoUrl,item.EvaluateResults,item.TimeLimited,item.RectificationDescription,"
+ @" (CASE WHEN item.RectificationResults ='1' THEN '同意'
WHEN item.RectificationResults ='2' THEN '不同意'
ELSE '' END) AS RectificationResults, "
+ @" (CASE WHEN item.States ='1' THEN '待评价'
WHEN item.States ='2' THEN '待整改'
WHEN item.States ='3' THEN '已整改待复查'
WHEN item.States ='5' THEN '已闭环'
ELSE '' END) AS States, "
+ @" item.CompileMan ,item.CompileTime,item.RectificationPhotoUrl from Inspect_InspectionItem item where 1=1 ";
List<SqlParameter> listStr = new List<SqlParameter>();
if (!string.IsNullOrEmpty(this.InspectionId))
{
strSql += " AND item.InspectionId = @InspectionId";
listStr.Add(new SqlParameter("@InspectionId", this.InspectionId));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
else
{
this.dpkInspectTime.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
}
}
/// <summary>
/// 初始化下拉框
/// </summary>
private void InitDropDownList()
{
//检查组成员
UserService.InitUserDropDownList(this.drpPersonResponsible, this.ProjectId, true);
}
protected void btnAdd_Click(object sender, EventArgs e)
{
JArray teamGroupData = Grid1.GetMergedData();
List<JObject> list = new List<JObject>();
foreach (JObject teamGroupRow in teamGroupData)
{
JObject values = teamGroupRow.Value<JObject>("values");
values.Add("InspectionItemId", teamGroupRow.Value<string>("id"));
list.Add(values);
}
JObject defaultObj = new JObject
{ { "InspectionItemId",Guid.NewGuid() },
{ "InspectionDescribe", "" },
{ "PhotoUrl", "" },
{ "VideoUrl",""},
{ "RectificationDescription",""},
{ "Delete", String.Format("<a href=\"javascript:;\" onclick=\"{0}\"><img src=\"{1}\"/></a>", GetDeleteScript(), IconHelper.GetResolvedIconUrl(Icon.Delete)) }
};
list.Add( defaultObj);
Grid1.DataSource = list;
Grid1.DataBind();
}
/// <summary>
/// 删除提示
/// </summary>
/// <returns></returns>
private string GetDeleteScript()
{
return Confirm.GetShowReference("删除选中行?", String.Empty, MessageBoxIcon.Question, Grid1.GetDeleteSelectedRowsReference(), String.Empty);
}
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
string itemId = string.Empty;
if (e.CommandName == "PhotoUrl")
{
itemId = Grid1.DataKeys[e.RowIndex][0].ToString() + "_1";
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format(
"../../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/InspectionItem&menuId={1}", itemId,
BLL.Const.ProjectSafetyInspectionMenuId)));
this.PhotoUrl = itemId;
}
else if (e.CommandName == "VideoUrl")
{
itemId = Grid1.DataKeys[e.RowIndex][0].ToString() + "_2";
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format(
"../../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/InspectionItem&menuId={1}",
itemId + "_2", BLL.Const.ProjectSafetyInspectionMenuId)));
this.VideoUrl = itemId;
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PreDataBound(object sender, EventArgs e)
{
// 设置LinkButtonField的点击客户端事件
LinkButtonField deleteField = Grid1.FindColumn("Delete") as LinkButtonField;
deleteField.OnClientClick = GetDeleteScript();
}
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
}
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
this.SaveData(Const.BtnSave);
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
}
#region
/// <summary>
/// 保存数据
/// </summary>
/// <param name="type"></param>
private void SaveData(string type)
{
var register = Inspect_InspectionService.GetInspectionByInspectionId(this.InspectionId);
// if (register.States != "1")
// {
List<string> ids = new List<string>();
List<Model.Inspect_InspectionItem> list = Inspect_InspectionService.GetInspectItemsByInspectionId(this.InspectionId);
list.ForEach(item => { ids.Add(item.InspectionItemId); });
Model.Inspect_InspectionItem InspectionItem;
JArray data = Grid1.GetMergedData();
if (data.Count > 0)
{
foreach (var item in data)
{
JObject values = item.Value<JObject>("values");
string id = item.Value<string>("id");
if (!ids.Contains(id))
{
InspectionItem = new Model.Inspect_InspectionItem
{
InspectionItemId = id,
InspectionId = this.InspectionId,
ProjectId = this.ProjectId,
States = "1",
};
}
else
{
//InspectionItem=Inspect_InspectionService.GetInspectItemsById(id);
}
if (!string.IsNullOrEmpty(values.Value<string>("InspectionDescribe")))
{
//InspectionItem.InspectionDescribe = values.Value<string>("InspectionDescribe");
}
var file = AttachFileService.GetAttachFile(id + "_1", BLL.Const.ProjectSafetyInspectionMenuId);
if (file != null)
{
//InspectionItem.PhotoUrl = file.AttachUrl.Trim();
}
var file1 = AttachFileService.GetAttachFile(id + "_2", BLL.Const.ProjectSafetyInspectionMenuId);
if (file1 != null)
{
//InspectionItem.VideoUrl = file1.AttachUrl.Trim();
}
//if (string.IsNullOrEmpty(InspectionItem.PhotoUrl) &&
// string.IsNullOrEmpty(InspectionItem.VideoUrl) &&
// string.IsNullOrEmpty(InspectionItem.InspectionDescribe))
//{
// ShowNotify("注意其中有检查项、图片、视频全是空!", MessageBoxIcon.Warning);
// return;
//}
if (!ids.Contains(id))
{
//Inspect_InspectionService.SaveInspection(InspectionItem);
}
else
{
//Inspect_InspectionService.UpdateInspectionItem(InspectionItem);
}
ids.Remove(id);
}
}
//删除多余数据
foreach (var id in ids)
{
Inspect_InspectionService.DeleteInspectItemsById(id);
}
List<Model.Inspect_InspectionItem> arr = Inspect_InspectionService.GetInspectItemsByInspectionId(this.InspectionId);
int EvaluateResultsCount = 0; // 初始化计数器
int StatesCount = 0; // 初始化计数器
if (int.Parse(register.States) > 2 && arr.Count > 0)
{
arr.ForEach(item =>
{
if (item.EvaluateResults == "不合格")
{
EvaluateResultsCount++;
}
if (item.States == "3")
{
StatesCount++;
}
});
if (EvaluateResultsCount == StatesCount)
{
Inspect_InspectionService.UpdateInspectionStates(this.InspectionId,"4");
}
}
else
{
Inspect_InspectionService.UpdateInspectionStates(this.InspectionId,"2");
}
// }
// else
// {
// //全删
// Inspect_InspectionService.DeleteInspectionItemsByInspectionId(this.InspectionId);
//
// //新增 从Grid中获取数据
// JArray data = Grid1.GetMergedData();
// if (data.Count > 0)
// {
// foreach (var item in data)
// {
// JObject values = item.Value<JObject>("values");
// string id = item.Value<string>("id");
// Model.Inspect_InspectionItem InspectionItem = new Model.Inspect_InspectionItem
// {
// InspectionItemId = id,
// InspectionId = this.InspectionId,
// ProjectId = this.ProjectId,
// States = "1",
// };
// if (!string.IsNullOrEmpty(values.Value<string>("InspectionDescribe")))
// {
// InspectionItem.InspectionDescribe = values.Value<string>("InspectionDescribe");
// }
//
// var file = AttachFileService.GetAttachFile(id + "_1", BLL.Const.ProjectSafetyInspectionMenuId);
// if (file != null)
// {
// InspectionItem.PhotoUrl = file.AttachUrl.Trim();
// }
//
// var file1 = AttachFileService.GetAttachFile(id + "_2", BLL.Const.ProjectSafetyInspectionMenuId);
// if (file1 != null)
// {
// InspectionItem.VideoUrl = file1.AttachUrl.Trim();
// }
//
// if (string.IsNullOrEmpty(InspectionItem.PhotoUrl) &&
// string.IsNullOrEmpty(InspectionItem.VideoUrl) &&
// string.IsNullOrEmpty(InspectionItem.InspectionDescribe))
// {
// ShowNotify("注意其中有检查项、图片、视频全是空!", MessageBoxIcon.Warning);
// return;
// }
//
// Inspect_InspectionService.AddInspectionItem(InspectionItem);
// }
//
// //改主表状态为待评价
// Inspect_InspectionService.UpdateInspectionStates(this.InspectionId, "2");
// }
// }
}
#endregion
/// <summary>
/// 提交按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSubmit_Click(object sender, EventArgs e)
{
}
/// <summary>
/// 获取图片(放于Img中)
/// </summary>
/// <param name="registrationId"></param>
/// <returns></returns>
protected string ConvertImageUrlByImage(object registrationId)
{
string url = string.Empty;
if (registrationId != null)
{
var registration = BLL.HSSE_Hazard_HazardRegisterService.GetHazardRegisterByHazardRegisterId(registrationId.ToString());
if (registration != null)
{
url = BLL.UploadAttachmentService.ShowImage(ConfigurationManager.AppSettings["CEMS_IMG_URL"], registration.ImageUrl);
}
}
return url;
}
protected void drpPersonResponsible_SelectedIndexChanged(object sender, EventArgs e)
{
this.drpPersonResponsible.SelectedValueArray = Funs.RemoveDropDownListNull(this.drpPersonResponsible.SelectedValueArray);
}
protected void btnRectify_Click(object sender, EventArgs e)
{
//获取当前数据的明细
var register = Inspect_InspectionService.GetInspectItemsById(this.Grid1.SelectedRowID);
//if (register.EvaluateResults == "合格")
//{
// Alert.ShowInTop("当前项已合格,无需整改!", MessageBoxIcon.Warning);
// return;
//}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ProjectSafetyInspectionRectify.aspx?InspectionItemId={0}&type={1}", this.Grid1.SelectedRowID,'0', "编辑 - ")));
}
protected void btnShow_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ProjectSafetyInspectionRectify.aspx?InspectionItemId={0}&type={1}", this.Grid1.SelectedRowID,'1', "查看 - ")));
}
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
ShowNotify("操作成功!", MessageBoxIcon.Success);
}
}
}