using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Data; using BLL; using System.Linq; using Newtonsoft.Json.Linq; using Model; namespace FineUIPro.Web.HJGL.HotProcessHard { public partial class HotProessReportItem : PageBase { #region 定义项 public string hotProessTrustItemId { get { return (string)ViewState["hotProessTrustItemId"]; } set { ViewState["hotProessTrustItemId"] = value; } } public string WeldJointId { get { return (string)ViewState["WeldJointId"]; } set { ViewState["WeldJointId"] = value; } } /// /// 报告集合 /// private List HotProessReportList = new List(); #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); Funs.FineUIPleaseSelect(this.drpIsCompleted); this.hotProessTrustItemId = Request.Params["HotProessTrustItemId"]; var hotProessFeedback = BLL.HotProessTrustItemService.GetHotProessTrustItemById(hotProessTrustItemId); if (hotProessFeedback != null) { if (!string.IsNullOrEmpty(hotProessFeedback.IsCompleted.ToString())) { drpIsCompleted.SelectedValue = hotProessFeedback.IsCompleted.Value.ToString(); } if (!string.IsNullOrEmpty(hotProessFeedback.WeldJointId)) { var getWeldJoint = PW_JointInfoService.GetJointInfoByJotID(hotProessFeedback.WeldJointId); if (getWeldJoint != null) { this.WeldJointId = getWeldJoint.JOT_ID; this.lbWeldJointCode.Text = getWeldJoint.JOT_JointNo; var getPipeline = PW_IsoInfoService.GetIsoInfoByIsoInfoId(getWeldJoint.ISO_ID); if (getPipeline != null) { this.lbPipeLineCode.Text = getPipeline.ISO_IsoNo; } } } } //若生成硬度委托,则焊口是否完成状态不可更改 Model.HJGL_Hard_TrustItem hardTrustItem = BLL.Hard_TrustItemService.GetHardTrustItemByHotProessTrustItemId(this.hotProessTrustItemId); if (hardTrustItem != null) { this.drpIsCompleted.Enabled = false; } //// 绑定表格 var getReports = HotProessReportService.GetHotProessReportListById(hotProessTrustItemId); foreach (var item in getReports) { Model.HJGL_HotProess_Report NewReport = new Model.HJGL_HotProess_Report(); NewReport.HotProessReportId = item.HotProessReportId; NewReport.HotProessTrustItemId = item.HotProessTrustItemId; NewReport.WeldJointId = item.WeldJointId; NewReport.PointCount = item.PointCount; NewReport.RequiredT = item.RequiredT; NewReport.ActualT = item.ActualT; NewReport.RequestTime = item.RequestTime; NewReport.ActualTime = item.ActualTime; NewReport.ProessDate = item.ProessDate; NewReport.RecordChartNo = item.RecordChartNo; HotProessReportList.Add(NewReport); } if (HotProessReportList.Count == 0)//没有绑定过,初始化 { var trustItem = Funs.DB.HJGL_HotProess_TrustItem.FirstOrDefault(x => x.HotProessTrustItemId == hotProessTrustItemId); if (trustItem != null) { var jointInfo = Funs.DB.PW_JointInfo.FirstOrDefault(x => x.JOT_ID == trustItem.WeldJointId); if (jointInfo != null && !string.IsNullOrEmpty(jointInfo.MaterialId)) { var material = Funs.DB.Base_Material.FirstOrDefault(x => x.MaterialId == jointInfo.MaterialId); if (material != null) { var hotProcessTech = Funs.DB.Base_HotProcessTech.Where(x => x.JOT_DiaMin <= jointInfo.JOT_Dia && jointInfo.JOT_Dia < x.JOT_DiaMax && x.Material.Contains(material.MaterialCode)).OrderBy(x => x.PointCount).ToList(); foreach (var item in hotProcessTech) { Model.HJGL_HotProess_Report NewReport = new Model.HJGL_HotProess_Report(); NewReport.HotProessReportId = SQLHelper.GetNewID(typeof(Model.HJGL_HotProess_Report)); NewReport.HotProessTrustItemId = hotProessTrustItemId; NewReport.WeldJointId = WeldJointId; NewReport.PointCount = int.Parse(item.PointCount); NewReport.RequiredT = item.RequiredT; NewReport.ActualT = item.ActualT; NewReport.RequestTime = item.RequiredTime; NewReport.ActualTime = item.ActualTime; HotProessReportList.Add(NewReport); } } } } } Grid1.DataSource = HotProessReportList; Grid1.DataBind(); } } #region 绑定数据 /// /// 绑定数据 /// private void BindGrid() { var getReports = HotProessReportService.GetHotProessReportListById(hotProessTrustItemId); foreach (var item in getReports) { Model.HJGL_HotProess_Report NewReport = new Model.HJGL_HotProess_Report(); NewReport.HotProessReportId = item.HotProessReportId; NewReport.HotProessTrustItemId = item.HotProessTrustItemId; NewReport.WeldJointId = item.WeldJointId; NewReport.PointCount = item.PointCount; NewReport.RequiredT = item.RequiredT; NewReport.ActualT = item.ActualT; NewReport.RequestTime = item.RequestTime; NewReport.ActualTime = item.ActualTime; NewReport.ProessDate = item.ProessDate; NewReport.RecordChartNo = item.RecordChartNo; HotProessReportList.Add(NewReport); } Grid1.DataSource = HotProessReportList; Grid1.DataBind(); } /// /// 改变索引事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } /// /// 分页下拉选择事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { BindGrid(); } /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, EventArgs e) { BindGrid(); } #endregion #endregion #region 增加按钮事件 /// /// 增加按钮事件 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_HotProessReportMenuId, Const.BtnAdd)) { HotProessReportList = GetDetails(); Model.HJGL_HotProess_Report NewReport = new Model.HJGL_HotProess_Report(); NewReport.HotProessReportId = SQLHelper.GetNewID(typeof(Model.HJGL_HotProess_Report)); NewReport.HotProessTrustItemId = hotProessTrustItemId; NewReport.WeldJointId = WeldJointId; //Model.HJGL_WeldJoint weldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(WeldJointId); //if (weldJoint != null) //{ // Model.WPQ_WPQList wpq = BLL.WPQListServiceService.GetWPQById(weldJoint.WPQId); // if (wpq != null) // { // NewReport.RequiredT = wpq.RequiredT; // NewReport.RequestTime = wpq.RequestTime; // } //} HotProessReportList.Add(NewReport); Grid1.DataSource = HotProessReportList; Grid1.DataBind(); } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } private List GetDetails() { HotProessReportList.Clear(); foreach (JObject mergedRow in Grid1.GetMergedData()) { JObject values = mergedRow.Value("values"); int i = mergedRow.Value("index"); string PointCount = values.Value("PointCount"); string RequiredT = values.Value("RequiredT"); string ActualT = values.Value("ActualT"); string RequestTime = values.Value("RequestTime"); string ActualTime = values.Value("ActualTime"); string ProessDate = values.Value("ProessDate"); string RecordChartNo = values.Value("RecordChartNo"); Model.HJGL_HotProess_Report NewReport = new Model.HJGL_HotProess_Report(); NewReport.HotProessReportId = Grid1.Rows[i].DataKeys[0].ToString(); NewReport.HotProessTrustItemId = hotProessTrustItemId; NewReport.WeldJointId = Grid1.Rows[i].DataKeys[1].ToString(); if (!string.IsNullOrEmpty(PointCount)) { NewReport.PointCount = Convert.ToInt32(PointCount); } NewReport.RequiredT = RequiredT; NewReport.ActualT = ActualT; NewReport.RequestTime = RequestTime; NewReport.ActualTime = ActualTime; NewReport.ProessDate = Funs.GetNewDateTime(ProessDate); NewReport.RecordChartNo = RecordChartNo; HotProessReportList.Add(NewReport); } return HotProessReportList; } #endregion #region 保存 protected void btnSave_Click(object sender, EventArgs e) { if (this.drpIsCompleted.SelectedValue == BLL.Const._Null) { ShowNotify("请选择是否完成!", MessageBoxIcon.Warning); return; } HotProessReportList = GetDetails(); if (this.drpIsCompleted.SelectedValue == "True") { if (HotProessReportList.Count == 0) { ShowNotify("请添加热处理报告数据后,再点击保存完成!", MessageBoxIcon.Warning); return; } } string hotProessTrustItemId = Request.Params["HotProessTrustItemId"]; var hotProessFeedback = BLL.HotProessTrustItemService.GetHotProessTrustItemById(hotProessTrustItemId); if (this.drpIsCompleted.SelectedValue != BLL.Const._Null) { hotProessFeedback.IsCompleted = Convert.ToBoolean(drpIsCompleted.SelectedValue); hotProessFeedback.IsHardness = Convert.ToBoolean(drpIsCompleted.SelectedValue); } else { hotProessFeedback.IsCompleted = null; hotProessFeedback.IsHardness = null; } BLL.HotProessTrustItemService.UpdateHotProessFeedback(hotProessFeedback); ///保存热处理报告 HotProessReportService.DeleteAllHotProessReportById(hotProessTrustItemId); foreach (var item in HotProessReportList) { Model.HJGL_HotProess_Report NewReport = new Model.HJGL_HotProess_Report(); NewReport.HotProessReportId = item.HotProessReportId; NewReport.HotProessTrustItemId = item.HotProessTrustItemId; NewReport.WeldJointId = item.WeldJointId; NewReport.PointCount = item.PointCount; NewReport.RequiredT = item.RequiredT; NewReport.ActualT = item.ActualT; NewReport.RequestTime = item.RequestTime; NewReport.ActualTime = item.ActualTime; NewReport.ProessDate = item.ProessDate; NewReport.RecordChartNo = item.RecordChartNo; BLL.HotProessReportService.AddHotProessReport(NewReport); } Alert.ShowInTop("保存成功", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } #endregion #region 删除 /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_HotProessReportMenuId, Const.BtnDelete)) { if (Grid1.SelectedRowIndexArray.Length > 0) { string strShowNotify = string.Empty; foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); var hotProessReport = BLL.HotProessReportService.GetHotProessReportById(rowID); if (hotProessReport != null) { string cont = judgementDelete(rowID); if (string.IsNullOrEmpty(cont)) { BLL.AttachFileService.DeleteAttachFile(Funs.RootPath, rowID, Const.HJGL_HotProessReportMenuId);//删除附件 BLL.HotProessReportService.DeleteHotProessReportById(rowID); } } } BindGrid(); if (!string.IsNullOrEmpty(strShowNotify)) { Alert.ShowInTop(strShowNotify, MessageBoxIcon.Warning); } else { ShowNotify("删除成功!", MessageBoxIcon.Success); } } } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } #region 判断是否可删除 /// /// 判断是否可以删除 /// /// private string judgementDelete(string id) { string content = string.Empty; //if (Funs.DB.Project_ProjectUser.FirstOrDefault(x => x.UserId == id) != null) //{ // content += "已在【项目用户】中使用,不能删除!"; //} return content; } #endregion #endregion #region 行点击事件 /// /// Grid行点击事件 /// /// /// protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { string hotProessReportId = Grid1.DataKeys[e.RowIndex][0].ToString(); HotProessReportList = GetDetails(); if (e.CommandName == "attchUrl") { PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/HJGL/HotProcessHard&menuId={1}&edit=0", hotProessReportId, BLL.Const.HJGL_HotProessReportMenuId))); } if (e.CommandName == "del")//删除 { var Report = HotProessReportList.FirstOrDefault(x => x.HotProessReportId == hotProessReportId); if (Report != null) { HotProessReportList.Remove(Report); } this.Grid1.DataSource = HotProessReportList; this.Grid1.DataBind(); } } #endregion } }