CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/DCGL/ServerCheck/CheckRectifyEdit.aspx.cs

192 lines
7.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using BLL;
using Newtonsoft.Json.Linq;
namespace FineUIPro.Web.DCGL.ServerCheck
{
public partial class CheckRectifyEdit : PageBase
{
/// <summary>
/// 主键
/// </summary>
public string CheckRectifyId
{
get
{
return (string)ViewState["CheckRectifyId"];
}
set
{
ViewState["CheckRectifyId"] = value;
}
}
/// <summary>
/// 定义集合
/// </summary>
private static List<Model.View_DCGL_CheckRectifyListFromSUB> CheckRectifyItems = new List<Model.View_DCGL_CheckRectifyListFromSUB>();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.GetButtonPower();
this.CheckRectifyId = Request.Params["CheckRectifyId"];
if (!string.IsNullOrEmpty(this.CheckRectifyId))
{
var rectify = Funs.DB.DCGL_Check_CheckRectify.FirstOrDefault(x => x.CheckRectifyId == this.CheckRectifyId);
if (rectify != null)
{
var unit = BLL.UnitService.GetUnitByUnitId(rectify.UnitId);
if (unit != null)
{
this.lbUnitName.Text = unit.UnitName;
}
this.lbProjectName.Text = rectify.ProjectName;
this.lbCheckRectifyCode.Text = rectify.CheckRectifyCode;
if (!string.IsNullOrEmpty(rectify.IssueMan))
{
this.txtIssueMan.Text = rectify.IssueMan;
}
if (rectify.IssueDate.HasValue)
{
this.txtIssueDate.Text = string.Format("{0:yyyy-MM-dd}", rectify.IssueDate);
}
if (rectify.HandleState == BLL.Const.State_3)
{
this.btnSave.Hidden = true;
this.btnSaveUp.Hidden = true;
}
CheckRectifyItems = (from x in Funs.DB.View_DCGL_CheckRectifyListFromSUB where x.CheckRectifyId == this.CheckRectifyId orderby x.SortIndex select x).ToList();
Grid1.DataSource = CheckRectifyItems;
Grid1.DataBind();
//if (CheckRectifyItems.FirstOrDefault(x => x.DangerPoint.Length > 1) == null)
//{
this.Grid1.Columns[1].Hidden = true;
this.Grid1.Columns[2].Hidden = true;
//}
}
}
}
}
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
this.SavaData(BLL.Const.BtnSave);
}
/// <summary>
/// 保存并提交
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSaveUp_Click(object sender, EventArgs e)
{
this.SavaData(BLL.Const.BtnSaveUp);
}
/// <summary>
/// 保存数据方法
/// </summary>
/// <param name="type"></param>
private void SavaData(string type)
{
jerqueSaveList();
foreach (var item in CheckRectifyItems)
{
var newCheckRectifyItem = BLL.DCGLCheckRectifyItemService.GetCheckRectifyItemByCheckRectifyItemId(item.CheckRectifyItemId);
if (newCheckRectifyItem != null)
{
newCheckRectifyItem.RealEndDate = item.RealEndDate;
newCheckRectifyItem.OrderEndPerson = item.OrderEndPerson;
newCheckRectifyItem.Verification = item.Verification;
BLL.DCGLCheckRectifyItemService.UpdateCheckRectifyItem(newCheckRectifyItem);
}
}
var newCheckRectify = BLL.DCGLCheckRectifyService.GetCheckRectifyByCheckRectifyId(this.CheckRectifyId);
if (newCheckRectify != null && newCheckRectify.HandleState != BLL.Const.State_3)
{
newCheckRectify.HandleState = BLL.Const.State_2; //待上报
BLL.DCGLCheckRectifyService.UpdateCheckRectify(newCheckRectify);
}
if (type == BLL.Const.BtnSaveUp)
{
string code = CNCECHSSEGetWebService.UpDCGlCheck_CheckRectify(newCheckRectify.CheckRectifyId, this.CurrUser);
if (code == "1")
{
ShowNotify("同步成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
return;
}
else
{
Alert.ShowInParent("同步异常,请退出后重试!", MessageBoxIcon.Error);
}
}
BLL.LogService.AddSys_Log(this.CurrUser, string.Empty, string.Empty, BLL.Const.DCGLCheckRectifyMenuId, BLL.Const.BtnModify);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
/// <summary>
/// 保存集合
/// </summary>
private void jerqueSaveList()
{
JArray mergedData = Grid1.GetMergedData();
foreach (JObject mergedRow in mergedData)
{
string status = mergedRow.Value<string>("status");
JObject values = mergedRow.Value<JObject>("values");
string checkRectifyItemId = values.Value<string>("CheckRectifyItemId").ToString();
var item = CheckRectifyItems.FirstOrDefault(e => e.CheckRectifyItemId == checkRectifyItemId);
if (item != null)
{
item.OrderEndPerson = values.Value<string>("OrderEndPerson").ToString();
item.RealEndDate = Funs.GetNewDateTime(values.Value<string>("RealEndDate").ToString());
item.Verification = values.Value<string>("Verification").ToString();
}
}
}
#region
/// <summary>
/// 权限按钮设置
/// </summary>
private void GetButtonPower()
{
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.DCGLCheckRectifyMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnSave))
{
this.btnSave.Hidden = false;
this.btnSaveUp.Hidden = false;
}
}
}
#endregion
#region
/// <summary>
/// 关闭按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnClose_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
#endregion
}
}