using BLL; using FastReport.DevComponents.Editors; using FineUIPro.Web.HSSE.Check; using FineUIPro.Web.SysManage; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Linq; using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace FineUIPro.Web.InformationProject { public partial class ConstructionLogEdit : PageBase { #region 定义项 /// /// 主键 /// private string ConstructionLogId { get { return (string)ViewState["ConstructionLogId"]; } set { ViewState["ConstructionLogId"] = value; } } #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.btnClose.OnClientClick = ActiveWindow.GetHideRefreshReference(); this.ConstructionLogId = Request.Params["ConstructionLogId"] ?? SQLHelper.GetNewID(); var getLog = BLL.ConstructionLogNewService.GetConstructionLogById(this.ConstructionLogId); if (getLog == null) { getLog = BLL.ConstructionLogNewService.GetConstructionLogByPersonIdDate(this.CurrUser.LoginProjectId, this.CurrUser.UserId, DateTime.Now); } if (getLog != null) { this.ConstructionLogId = getLog.ConstructionLogId; this.txtUnitId.Text = UnitService.getUnitNamesUnitIds(getLog.UnitId); this.txtPersonName.Text = getLog.PersonName; this.hdPersonId.Text = getLog.PersonId; this.txtWorkDate.Text = string.Format("{0:yyyy-MM-dd}", getLog.WorkDate); } else { this.txtUnitId.Text = UnitService.getUnitNamesUnitIds(this.CurrUser.UnitId); this.txtPersonName.Text = this.CurrUser.UserName; this.hdPersonId.Text = this.CurrUser.UserId; this.txtWorkDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); } BindGrid(); } } #endregion #region 绑定Grid /// /// 绑定Grid /// private void BindGrid() { var getLogItemList = BLL.ConstructionLogNewService.GetConstructionLogItemListByConstructionLogId(this.ConstructionLogId); if (getLogItemList.Count() == 0) { getLogItemList = (from x in DropListService.getExamType() select new Model.InformationProject_ConstructionLogItem { ConstructionLogItemId = SQLHelper.GetNewID(), ConstructionLogId = this.ConstructionLogId, ExamTypeId = x.Value, Frequency = 0, }).ToList(); } this.Grid1.DataSource = getLogItemList; this.Grid1.PageIndex = 0; this.Grid1.DataBind(); } /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, EventArgs e) { BindGrid(); } #endregion #region 保存 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { this.SaveData(); PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } /// /// 保存数据 /// private void SaveData() { Model.InformationProject_ConstructionLog newConstructionLog = new Model.InformationProject_ConstructionLog { ConstructionLogId = this.ConstructionLogId, ProjectId = this.CurrUser.LoginProjectId, WorkDate = Funs.GetNewDateTimeOrNow(this.txtWorkDate.Text), UnitId = this.CurrUser.UnitId, PersonId = this.CurrUser.UserId, PersonName = this.CurrUser.UserName, }; var getLog = BLL.ConstructionLogNewService.GetConstructionLogById(this.ConstructionLogId); if (getLog != null) { BLL.ConstructionLogNewService.UpdateConstructionLog(newConstructionLog); } else { BLL.ConstructionLogNewService.AddConstructionLog(newConstructionLog); } ShowNotify(this.SaveDetail(), MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } /// /// 保存明细项 /// private string SaveDetail() { JArray teamGroupData = Grid1.GetMergedData(); foreach (JObject teamGroupRow in teamGroupData) { JObject values = teamGroupRow.Value("values"); string ConstructionLogItemId = teamGroupRow.Value("id"); Model.InformationProject_ConstructionLogItem newDetail = new Model.InformationProject_ConstructionLogItem { ConstructionLogItemId = ConstructionLogItemId, ConstructionLogId = this.ConstructionLogId, ExamTypeId = values.Value("ExamTypeId"), Frequency = Funs.GetNewIntOrZero(values.Value("Frequency")), Remark = values.Value("Remark"), }; var getItem = ConstructionLogNewService.GetConstructionLogItemById(ConstructionLogItemId); if (getItem != null) { ConstructionLogNewService.UpdateConstructionLogItem(newDetail); } else { ConstructionLogNewService.AddConstructionLogItem(newDetail); } } return "保存成功!"; } #endregion #region 获取 字面值,在 ASPX 中调用 /// /// 获取本部人员角色 /// /// /// protected string GetExamType(object value) { string name = string.Empty; if (value != null) { name = DropListService.getExamTypeNameByValue(value.ToString()); } return name; } #endregion protected void txtWorkDate_Blur(object sender, EventArgs e) { var datav = Funs.GetNewDateTime(this.txtWorkDate.Text); if (datav.HasValue) { var getLog = BLL.ConstructionLogNewService.GetConstructionLogByPersonIdDate(this.CurrUser.LoginProjectId, this.CurrUser.UserId, datav.Value); if (getLog != null) { this.ConstructionLogId = getLog.ConstructionLogId; } else { this.ConstructionLogId = SQLHelper.GetNewID(); } BindGrid(); } else { Alert.ShowInTop("请选择日期!", MessageBoxIcon.Warning); return; } } } }