SGGL_SHJ/SGGL/FineUIPro.Web/OfficeCheck/Check/RectifyEdit.aspx.cs

573 lines
24 KiB
C#

using BLL;
using Model;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
namespace FineUIPro.Web.OfficeCheck.Check
{
public partial class RectifyEdit : PageBase
{
#region
/// <summary>
/// 检查Id
/// </summary>
public string CheckNoticeId
{
get
{
return (string)ViewState["CheckNoticeId"];
}
set
{
ViewState["CheckNoticeId"] = value;
}
}
/// <summary>
/// 定义集合
/// </summary>
public static List<Model.ProjectSupervision_RectifyItem> rectifyItemLists = new List<Model.ProjectSupervision_RectifyItem>();
#endregion
#region
/// <summary>
/// 加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string type = Request.Params["type"];
if (type == "1")
{
this.btnSave.Hidden = true;
this.btnAdd.Hidden = true;
this.btnSubmit.Hidden = true;
this.Grid1.Columns[11].Hidden = true;
}
this.CheckNoticeId = Request.Params["CheckNoticeId"];
var getRectify = ProjectSupervision_RectifyService.GetRectifyByCheckNoticeId(this.CheckNoticeId);
if (getRectify != null)
{
SetDrop(getRectify.ProjectId);
this.hdRectifyNoticesId.Text = getRectify.RectifyId;
if (!string.IsNullOrEmpty(getRectify.ProjectId))
{
this.drpProjectId.SelectedValue = getRectify.ProjectId;
}
if (!string.IsNullOrEmpty(getRectify.CheckManIds))
{
this.drpCheckMan.SelectedValueArray = getRectify.CheckManIds.Split(',');
}
this.txtCheckPerson.Text = getRectify.CheckManNames;
this.txtRectifyNoticesCode.Text = getRectify.RectifyCode;
this.txtCheckedDate.Text = getRectify.CheckedDate.ToString();
//if (!string.IsNullOrEmpty(getRectify.HiddenHazardType))
//{
// this.drpHiddenHazardType.SelectedValue = getRectify.HiddenHazardType;
//}
if (!string.IsNullOrEmpty(getRectify.SignPerson))
{
this.drpSignPerson.SelectedValue = getRectify.SignPerson;
}
if (getRectify.States == Const.State_1 || getRectify.States == Const.State_2)
{
this.btnSure.Hidden = false;
}
}
else
{
var getCheckNotice = CheckNoticeService.GetCheckNoticeById(this.CheckNoticeId);
if (getCheckNotice != null)
{
SetDrop(getCheckNotice.SubjectProjectId);
if (!string.IsNullOrEmpty(getCheckNotice.SubjectProjectId))
{
this.drpProjectId.SelectedValue = getCheckNotice.SubjectProjectId;
}
if (!string.IsNullOrEmpty(getCheckNotice.CheckTeamLeader))
{
this.drpCheckMan.SelectedValueArray = getCheckNotice.CheckTeamLeader.Split(',');
}
var getTeam = CheckTeamService.GetCheckTeamListByCheckNoticeId(this.CheckNoticeId);
foreach (var item in getTeam)
{
this.txtCheckPerson.Text += item.UserName + "、";
}
string perfix = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "-";
this.txtRectifyNoticesCode.Text = BLL.SQLHelper.RunProcNewId("SpGetNewCode3", "dbo.ProjectSupervision_Rectify", "RectifyCode", perfix);
}
this.txtCheckedDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
}
BindGrid();
rectifyItemLists.Clear();
}
}
private void SetDrop(string projectId)
{
//受检项目
BLL.ProjectService.InitAllProjectDropDownList(this.drpProjectId, true);
this.drpProjectId.SelectedValue = projectId;
///安全经理
BLL.Person_PersonsService.InitFlowOperateControlUserDropDownList(this.drpSignPerson, projectId, Const.UnitId_SEDIN, true);
///检察人员
BLL.Person_PersonsService.InitUserUnitIdDepartIdDropDownList(this.drpCheckMan, Const.UnitId_SEDIN, string.Empty, true);
}
/// <summary>
/// 绑定明细
/// </summary>
public void BindGrid()
{
string strSql = string.Empty;
List<SqlParameter> listStr = new List<SqlParameter>();
if (Funs.DB.ProjectSupervision_RectifyItem.FirstOrDefault(x => x.RectifyId == this.hdRectifyNoticesId.Text) != null)
{
strSql = @"select RectifyItemId,WrongContent,Requirement,LimitTime,RectifyResults,IsRectify,HiddenHazardType
,null as CheckReportItemId, RectifyItemId AS FileUrlId
from ProjectSupervision_RectifyItem
where RectifyId = @RectifyId";
listStr.Add(new SqlParameter("@RectifyId", this.hdRectifyNoticesId.Text));
}
else
{
strSql = @"select newid() as RectifyItemId,UnConformItem as WrongContent,null as Requirement,null as LimitTime, null as RectifyResults,0 as IsRectify
,'1' as HiddenHazardType,item.CheckReportItemId,item.CheckReportItemId AS FileUrlId
from ProjectSupervision_CheckReportItem as item
left join ProjectSupervision_CheckReport as Report on item.CheckReportId=Report.CheckReportId
where Report.CheckNoticeId = @CheckNoticeId";
listStr.Add(new SqlParameter("@CheckNoticeId", this.CheckNoticeId));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
#region
protected void btnAdd_Click(object sender, EventArgs e)
{
addViewTestPlanTrainingList();
Model.ProjectSupervision_RectifyItem notice = new Model.ProjectSupervision_RectifyItem();
notice.RectifyItemId = SQLHelper.GetNewID();
rectifyItemLists.Add(notice);
//将gd数据保存在list中
Grid1.DataSource = rectifyItemLists;
Grid1.DataBind();
}
private void addViewTestPlanTrainingList()
{
rectifyItemLists.Clear();
var data = Grid1.GetMergedData();
if (data != null)
{
foreach (JObject mergedRow in Grid1.GetMergedData())
{
int i = mergedRow.Value<int>("index");
JObject values = mergedRow.Value<JObject>("values");
string wrongContent = values.Value<string>("WrongContent");
string rectifyNoticesItemId = values.Value<string>("RectifyItemId");
string requirement = values.Value<string>("Requirement");
string rectifyResults = values.Value<string>("RectifyResults");
TextBox txtlimitTim = (TextBox)Grid1.Rows[i].FindControl("txtLimitTimes");
var item = new ProjectSupervision_RectifyItem();
item.RectifyItemId = rectifyNoticesItemId;
item.RectifyId = hdRectifyNoticesId.Text.Trim();
item.WrongContent = wrongContent;
item.Requirement = requirement;
item.LimitTime = Funs.GetNewDateTime(txtlimitTim.Text);
item.RectifyResults = rectifyResults;
DropDownList drpIsRect = (DropDownList)Grid1.Rows[i].FindControl("drpIsRectify");
item.IsRectify = Convert.ToBoolean(drpIsRect.SelectedValue);
DropDownList drpHiddenHazardType = (DropDownList)Grid1.Rows[i].FindControl("drpHiddenHazardTypeify");
item.HiddenHazardType = drpHiddenHazardType.SelectedValue;
rectifyItemLists.Add(item);
}
}
}
#endregion
#region
///// <summary>
///// 整改单明细数据验证
///// </summary>
///// <returns></returns>
//private bool validate()
//{
// bool res = false;
// string err = string.Empty;
// foreach (JObject mergedRow in Grid1.GetMergedData())
// {
// int i = mergedRow.Value<int>("index");
// JObject values = mergedRow.Value<JObject>("values");
// string WrongContent = values.Value<string>("WrongContent");
// string Requirement = values.Value<string>("Requirement");
// if (string.IsNullOrWhiteSpace(WrongContent) || string.IsNullOrWhiteSpace(Requirement))
// {
// err += "第" + (i + 1).ToString() + "行:";
// if (string.IsNullOrWhiteSpace(WrongContent))
// {
// err += "请输入具体位置及隐患内容,";
// }
// if (string.IsNullOrWhiteSpace(Requirement))
// {
// err += "请输入整改要求,";
// }
// err = err.Substring(0, err.LastIndexOf(","));
// err += "!";
// }
// }
// if (Grid1.Rows.Count > 0)
// {
// if (!string.IsNullOrWhiteSpace(err))
// {
// Alert.ShowInTop(err, MessageBoxIcon.Warning);
// }
// else
// {
// res = true;
// }
// }
// else
// {
// Alert.ShowInTop("请整改单内容!", MessageBoxIcon.Warning);
// }
// return res;
//}
#endregion
#region Grid行点击事件
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
string itemId = Grid1.DataKeys[e.RowIndex][0].ToString();
if (e.CommandName == "AttachUrl")
{
if (Funs.DB.ProjectSupervision_RectifyItem.FirstOrDefault(x => x.RectifyItemId == itemId) != null)
{
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Rectify&menuId={1}&type=0&strParam=1", itemId, BLL.Const.CheckInfoMenuId)));
}
else
{
string checkReportItemId = Grid1.Rows[e.RowIndex].Values[12].ToString();
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Rectify&menuId={1}&type=0&strParam=1", checkReportItemId, BLL.Const.CheckInfoMenuId)));
}
}
if (e.CommandName == "delete")
{
rectifyItemLists.Remove(rectifyItemLists.FirstOrDefault(p => p.RectifyItemId == itemId));
Grid1.DataSource = rectifyItemLists;
Grid1.DataBind();
}
if (e.CommandName == "ReAttachUrl")
{
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/Rectify&menuId={1}&type=0&strParam=2", itemId, BLL.Const.CheckInfoMenuId)));
}
}
#endregion
#region Grid行绑定事件
protected void Grid1_RowDataBound(object sender, GridRowEventArgs e)
{
//DataRowView row = e.DataItem as DataRowView;
for (int i = 0; i < this.Grid1.Rows.Count; i++)
{
System.Web.UI.WebControls.DropDownList drpIsRectify = (System.Web.UI.WebControls.DropDownList)(this.Grid1.Rows[i].FindControl("drpIsRectify"));
HiddenField hdIsRectify = (HiddenField)(this.Grid1.Rows[i].FindControl("hdIsRectify"));
if (!string.IsNullOrEmpty(hdIsRectify.Text))
{
if (hdIsRectify.Text == "True")
{
drpIsRectify.SelectedValue = "true";
}
else
{
drpIsRectify.SelectedValue = "false";
}
}
System.Web.UI.WebControls.DropDownList drpHiddenHazardType = (System.Web.UI.WebControls.DropDownList)(this.Grid1.Rows[i].FindControl("drpHiddenHazardType"));
HiddenField hdHiddenHazardType = (HiddenField)(this.Grid1.Rows[i].FindControl("hdHiddenHazardType"));
if (!string.IsNullOrEmpty(hdHiddenHazardType.Text))
{
drpHiddenHazardType.SelectedValue = hdHiddenHazardType.Text;
}
}
}
#endregion
#region
/// <summary>
/// 时间转换
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public string ConvertDate(object date)
{
if (!Convert.IsDBNull(date))
{
return string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(date));
}
else
{
return null;
}
}
#endregion
#region
protected void btnSave_Click(object sender, EventArgs e)
{
SaveRectifyNotices("save");
}
/// <summary>
/// 提交
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSubmit_Click(object sender, EventArgs e)
{
SaveRectifyNotices("submit");
}
/// <summary>
/// 保存方法
/// </summary>
/// <param name="saveType"></param>
private void SaveRectifyNotices(string saveType)
{
if (this.drpSignPerson.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("项目安全经理不能为空!", MessageBoxIcon.Warning);
return;
}
Model.ProjectSupervision_Rectify Notices = new Model.ProjectSupervision_Rectify();
Notices.RectifyCode = this.txtRectifyNoticesCode.Text.Trim();
if (this.drpProjectId.SelectedValue != BLL.Const._Null)
{
Notices.ProjectId = this.drpProjectId.SelectedValue;
}
if (this.drpCheckMan.SelectedValue != BLL.Const._Null)
{
string str = GetStringByArray(this.drpCheckMan.SelectedValueArray);
Notices.CheckManIds = str;
}
if (!string.IsNullOrEmpty(txtCheckPerson.Text))
{
Notices.CheckManNames = txtCheckPerson.Text;
}
if (!string.IsNullOrEmpty(this.txtCheckedDate.Text.Trim()))
{
Notices.CheckedDate = Convert.ToDateTime(this.txtCheckedDate.Text.Trim());
}
//if (this.drpHiddenHazardType.SelectedValue != BLL.Const._Null)
//{
// Notices.HiddenHazardType = this.drpHiddenHazardType.SelectedValue;
//}
if (this.drpSignPerson.SelectedValue != BLL.Const._Null)
{
Notices.SignPerson = this.drpSignPerson.SelectedValue;
}
if (saveType == "submit")
{
Notices.States = BLL.Const.State_1;
}
else
{
Notices.States = BLL.Const.State_0;
}
if (!string.IsNullOrEmpty(this.hdRectifyNoticesId.Text))
{
Notices.RectifyId = this.hdRectifyNoticesId.Text;
ProjectSupervision_RectifyService.UpdateRectify(Notices);
}
else
{
Notices.CheckNoticeId = this.CheckNoticeId;
Notices.RectifyId = SQLHelper.GetNewID(typeof(Model.ProjectSupervision_Rectify));
ProjectSupervision_RectifyService.AddRectify(Notices);
this.hdRectifyNoticesId.Text = Notices.RectifyId;
}
saveNoticesItemDetail();//增加明细
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
/// <summary>
/// 保存明细
/// </summary>
public void saveNoticesItemDetail()
{
int j = 0;
var data = Grid1.GetMergedData();
if (data != null)
{
foreach (JObject mergedRow in Grid1.GetMergedData())
{
int i = mergedRow.Value<int>("index");
JObject values = mergedRow.Value<JObject>("values");
string wrongContent = values.Value<string>("WrongContent");
string rectifyNoticesItemId = values.Value<string>("RectifyItemId");
string requirement = values.Value<string>("Requirement");
string rectifyResults = values.Value<string>("RectifyResults");
System.Web.UI.WebControls.TextBox txtlimitTim = (System.Web.UI.WebControls.TextBox)Grid1.Rows[i].FindControl("txtLimitTimes");
System.Web.UI.WebControls.DropDownList drpIsRect = (System.Web.UI.WebControls.DropDownList)Grid1.Rows[i].FindControl("drpIsRectify");
System.Web.UI.WebControls.DropDownList drpHiddenHazardType = (System.Web.UI.WebControls.DropDownList)Grid1.Rows[i].FindControl("drpHiddenHazardType");
string limitTime = txtlimitTim.Text.Trim();
Model.ProjectSupervision_RectifyItem rectifyNoticesItem = Funs.DB.ProjectSupervision_RectifyItem.FirstOrDefault(e => e.RectifyItemId == rectifyNoticesItemId);
if (rectifyNoticesItem != null)
{
rectifyNoticesItem.RectifyItemId = rectifyNoticesItemId;
rectifyNoticesItem.RectifyId = this.hdRectifyNoticesId.Text.Trim();
rectifyNoticesItem.WrongContent = wrongContent.Trim();
rectifyNoticesItem.Requirement = requirement.Trim();
rectifyNoticesItem.LimitTime = Funs.GetNewDateTime(limitTime);
rectifyNoticesItem.RectifyResults = rectifyResults.Trim();
rectifyNoticesItem.HiddenHazardType = drpHiddenHazardType.SelectedValue;
rectifyNoticesItem.IsRectify = Convert.ToBoolean(drpIsRect.SelectedValue);
Funs.DB.SubmitChanges();
if (rectifyNoticesItem.IsRectify == true)
{
j++;
}
}
else
{
var item = new ProjectSupervision_RectifyItem();
item.RectifyItemId = rectifyNoticesItemId;
item.RectifyId = this.hdRectifyNoticesId.Text.Trim();
item.WrongContent = wrongContent.Trim();
item.Requirement = requirement.Trim();
item.LimitTime = Funs.GetNewDateTime(limitTime);
item.RectifyResults = rectifyResults.Trim();
item.HiddenHazardType = drpHiddenHazardType.SelectedValue;
item.IsRectify = Convert.ToBoolean(drpIsRect.SelectedValue);
Funs.DB.ProjectSupervision_RectifyItem.InsertOnSubmit(item);
Funs.DB.SubmitChanges();
string hdCheckReportItemId = values.Value<string>("CheckReportItemId");
var getAtt = Funs.DB.AttachFile.FirstOrDefault(x => x.ToKeyId == hdCheckReportItemId + "#1");
if (getAtt != null)
{
UploadFileService.SaveAttachUrl(getAtt.AttachSource, getAtt.AttachUrl, BLL.Const.CheckInfoMenuId, item.RectifyItemId + "#1");
}
}
}
if (j == data.Count)
{
var re = BLL.ProjectSupervision_RectifyService.GetRectifyById(this.hdRectifyNoticesId.Text.Trim());
if (re != null)
{
re.States = BLL.Const.State_3;
BLL.ProjectSupervision_RectifyService.UpdateRectify(re);
}
}
}
}
#endregion
#region
private string GetStringByArray(string[] array)
{
string str = string.Empty;
foreach (var item in array)
{
if (item != BLL.Const._Null)
{
str += item + ",";
}
}
if (!string.IsNullOrEmpty(str))
{
str = str.Substring(0, str.LastIndexOf(","));
}
return str;
}
#endregion
#region DropDownList下拉选择
protected void drpCheckMan_SelectedIndexChanged(object sender, EventArgs e)
{
string[] array = this.drpCheckMan.SelectedValueArray;
List<string> str = new List<string>();
foreach (var item in array)
{
if (item != BLL.Const._Null)
{
str.Add(item);
}
}
this.drpCheckMan.SelectedValueArray = str.ToArray();
}
#endregion
protected void btnSure_Click(object sender, EventArgs e)
{
var getRectify = ProjectSupervision_RectifyService.GetRectifyByCheckNoticeId(this.CheckNoticeId);
if (getRectify != null)
{
saveNoticesItemDetail();//增加明细
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
}
/// <summary>
/// 获取整改前图片(放于Img中)
/// </summary>
/// <param name="registrationId"></param>
/// <returns></returns>
protected string ConvertImageUrlByImage(object FileUrlId)
{
string url = string.Empty;
if (FileUrlId != null)
{
var RectifyNoticesItem = BLL.AttachFileService.GetAttachFileByToKeyId(FileUrlId.ToString() + "#1");
if (RectifyNoticesItem != null)
{
url = HttpUtility.HtmlDecode(BLL.UploadAttachmentService.ShowImage("../../", RectifyNoticesItem.AttachUrl));
}
}
return url;
}
/// <summary>
/// 获取整改后图片
/// </summary>
/// <param name="registrationId"></param>
/// <returns></returns>
protected string ConvertImageUrlByImage2(object FileUrlId)
{
string url = string.Empty;
if (FileUrlId != null)
{
var RectifyNoticesItem = BLL.AttachFileService.GetAttachFileByToKeyId(FileUrlId.ToString() + "#2");
if (RectifyNoticesItem != null)
{
url = BLL.UploadAttachmentService.ShowImage("../../", RectifyNoticesItem.AttachUrl);
}
}
return url;
}
}
}