using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using BLL; using Newtonsoft.Json.Linq; namespace FineUIPro.Web.HJGL.HotProessManage { public partial class RepairHotProessTrustEdit : PageBase { #region 定义项 /// /// 返修热处理委托主键 /// public string HotProessTrustId { get { return (string)ViewState["HotProessTrustId"]; } set { ViewState["HotProessTrustId"] = value; } } /// /// 项目主键 /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.HotProessTrustId = Request.Params["HotProessTrustId"]; this.ProjectId = Request.Params["ProjectId"]; var trust = BLL.HJGL_CH_HotProessTrustService.GetCH_HotProessTrustByID(this.HotProessTrustId); if (trust != null) { this.ProjectId = trust.ProjectId; } var pUnit = BLL.Base_UnitService.GetUnitsByProjectUnitType(this.ProjectId, BLL.Const.UnitType_4); if (pUnit != null) { this.drpUnit.DataTextField = "UnitName"; this.drpUnit.DataValueField = "UnitId"; this.drpUnit.DataSource = pUnit; this.drpUnit.DataBind(); } ///委托人 this.drpTrustMan.DataTextField = "UserName"; this.drpTrustMan.DataValueField = "UserId"; this.drpTrustMan.DataSource = BLL.Sys_UserService.GetUserListByProjectId(this.ProjectId); this.drpTrustMan.DataBind(); Funs.FineUIPleaseSelect(this.drpTrustMan); this.drpTrustMan.SelectedValue = this.CurrUser.UserId; this.PageInfoLoad(); ///加载页面 List lists = BLL.HJGL_CH_HotProessTrustService.GetHotProessTrustItem(this.ProjectId, this.HotProessTrustId); this.BindGrid(lists); ////初始化页面 } } #endregion #region 加载页面输入提交信息 /// /// 加载页面输入提交信息 /// private void PageInfoLoad() { var trust = BLL.HJGL_CH_HotProessTrustService.GetCH_HotProessTrustByID(this.HotProessTrustId); if (trust != null) { this.ProjectId = trust.ProjectId; this.txtProjectName.Text = trust.ProjectName; this.txtHotProessTrustCode.Text = trust.HotProessTrustCode; if (!string.IsNullOrEmpty(trust.TrustUnitId)) { this.drpUnit.SelectedValue = trust.TrustUnitId; } this.txtConstructionNo.Text = trust.ConstructionNo; if (!string.IsNullOrEmpty(trust.TrstManId)) { this.drpTrustMan.SelectedValue = trust.TrstManId; } } else { this.SimpleForm1.Reset(); ///重置所有字段 //委托单号自动生成,规则:施工号-日期(1127)-两位流水 this.txtHotProessTrustCode.Text = BLL.SQLHelper.RunProcNewIdByProjectId("SpGetNewCode2ByProjectId", "dbo.HJGL_CH_HotProessTrust", "HotProessTrustCode", this.CurrUser.LoginProjectId, BLL.Base_ProjectService.GetProjectCode(this.CurrUser.LoginProjectId) + "-" + string.Format("{0:MMdd}", DateTime.Now) + "-"); Model.Base_Project project = BLL.Base_ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId); if (project != null) { this.txtProjectName.Text = project.ProjectName; this.txtConstructionNo.Text = project.ProjectCode; } if (this.CurrUser.UserId != Const.GlyId) { this.drpTrustMan.SelectedValue = this.CurrUser.UserId; } } } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid(List lists) { DataTable tb = this.LINQToDataTable(lists); // 2.获取当前分页数据 //var table = this.GetPagedDataTable(GridNewDynamic, tb1); Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); var totalItems = from x in Funs.DB.HJGL_CH_HotProessTrustItem select x; for (int i = 0; i < this.Grid1.Rows.Count; i++) { //this.Grid1.Rows[i].RowCssClass = "green"; System.Web.UI.WebControls.CheckBoxList cblProessTypes = (System.Web.UI.WebControls.CheckBoxList)(this.Grid1.Rows[i].FindControl("cblProessTypes")); string jot_id = this.Grid1.Rows[i].DataKeys[0].ToString(); string hotProessTrustItemId = this.Grid1.Rows[i].DataKeys[1].ToString(); string trustItemID = this.Grid1.Rows[i].Values[10].ToString(); List items = new List(); if (string.IsNullOrEmpty(trustItemID)) //非返修口 { //获取对应焊口已存在的返修热处理委托明细 items = (from x in totalItems where x.JOT_ID == jot_id && x.HotProessTrustId != this.HotProessTrustId select x).ToList(); } else //返修口 { items = (from x in totalItems where x.JOT_ID == jot_id && x.HotProessTrustId != this.HotProessTrustId && x.TrustItemID == trustItemID select x).ToList(); } //已处理的热处理类型集合 List list = new List(); foreach (var item in items) { //获取结果反馈信息 if (!string.IsNullOrEmpty(item.ProessTypes)) { var hotProessResult = (from x in Funs.DB.HJGL_CH_HotProessResult where x.JOT_ID == item.JOT_ID && x.ProessTypes == item.ProessTypes && x.HotProessTrustId == item.HotProessTrustId select x).FirstOrDefault(); if (hotProessResult != null && (hotProessResult.IsOK == true || hotProessResult.IsOK == null)) //反馈记录合格或尚未进行反馈均视为已处理类型 { string[] strs = item.ProessTypes.Split('|'); foreach (var str in strs) { if (!string.IsNullOrEmpty(str)) { list.Add(str); } } } } } Model.HJGL_PW_JointInfo joint = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(jot_id); cblProessTypes.DataSource = BLL.HJGL_CH_HotProessTrustService.GetNeedProessTypes(joint.ProessTypes, list, this.HotProessTrustId, jot_id, hotProessTrustItemId); cblProessTypes.DataBind(); if (!string.IsNullOrEmpty(this.HotProessTrustId)) //修改记录 { List list2 = new List(); var items2 = (from x in totalItems where x.JOT_ID == jot_id && x.HotProessTrustItemId == hotProessTrustItemId select x).FirstOrDefault(); //获取已处理的热处理类型 if (!string.IsNullOrEmpty(items2.ProessTypes)) { //var hotProessResult = (from x in Funs.DB.HJGL_CH_HotProessResult where x.JOT_ID == item.JOT_ID && x.HotProessTrustId == item.HotProessTrustId select x).FirstOrDefault(); //if (hotProessResult == null || (hotProessResult != null && hotProessResult.IsOK == true)) //还没有结果反馈记录或结果反馈记录合格则视为已处理类型 //{ string[] strs = items2.ProessTypes.Split('|'); foreach (var str in strs) { if (!string.IsNullOrEmpty(str)) { list2.Add(str); } } //} } for (int j = 0; j < cblProessTypes.Items.Count; j++) { foreach (var item in list2) { if (BLL.HJGL_CH_HotProessTrustService.GetProessTypesId(cblProessTypes.Items[j].Value) == item) { cblProessTypes.Items[j].Selected = true; } } } } } } #endregion #region 返修热处理委托 提交事件 /// /// 编辑返修热处理委托 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_HotProessTrustMenuId, Const.BtnSave)) { if (BLL.HJGL_CH_HotProessTrustService.IsExistTrustCode(this.txtHotProessTrustCode.Text, this.HotProessTrustId, this.CurrUser.LoginProjectId)) { ShowNotify("委托单号已存在,请重新录入!", MessageBoxIcon.Warning); return; } int count = 0; for (int i = 0; i < this.Grid1.Rows.Count; i++) { System.Web.UI.WebControls.CheckBoxList cblProessTypes = (System.Web.UI.WebControls.CheckBoxList)(this.Grid1.Rows[i].FindControl("cblProessTypes")); for (int j = 0; j < cblProessTypes.Items.Count; j++) { if (cblProessTypes.Items[j].Selected) { count += 1; break; } } } if (count < this.Grid1.Rows.Count) { ShowNotify("热处理类型不能为空!", MessageBoxIcon.Warning); return; } Model.HJGL_CH_HotProessTrust newHotProessTrust = new Model.HJGL_CH_HotProessTrust(); newHotProessTrust.ProjectId = this.ProjectId; newHotProessTrust.HotProessTrustCode = this.txtHotProessTrustCode.Text.Trim(); if (this.drpUnit.SelectedValue != BLL.Const._Null) { newHotProessTrust.TrustUnitId = this.drpUnit.SelectedValue; } newHotProessTrust.ProjectName = this.txtProjectName.Text.Trim(); newHotProessTrust.ConstructionNo = this.txtConstructionNo.Text.Trim(); if (this.drpTrustMan.SelectedValue != BLL.Const._Null) { newHotProessTrust.TrstManId = this.drpTrustMan.SelectedValue; } if (!string.IsNullOrEmpty(this.HotProessTrustId)) { newHotProessTrust.HotProessTrustId = this.HotProessTrustId; BLL.HJGL_CH_HotProessTrustService.UpdateCH_HotProessTrust(newHotProessTrust); BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "修改返修热处理委托信息"); } else { this.HotProessTrustId = SQLHelper.GetNewID(typeof(Model.HJGL_CH_HotProessTrust)); newHotProessTrust.HotProessTrustId = this.HotProessTrustId; newHotProessTrust.TrustType = "2"; //返修口 BLL.HJGL_CH_HotProessTrustService.AddCH_HotProessTrust(newHotProessTrust); BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "添加返修热处理委托信息"); } BLL.HJGL_CH_HotProessTrustService.DeleteCH_HotProessTrustItemByCH_HotProessTrustID(this.HotProessTrustId); this.CollectGridJointInfo(); ShowNotify("提交成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(newHotProessTrust.HotProessTrustId) + ActiveWindow.GetHidePostBackReference()); } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } #endregion #region 收集Grid页面信息,提交明细 /// /// 收集Grid页面信息,提交明细 /// /// private void CollectGridJointInfo() { JArray mergedData = Grid1.GetMergedData(); foreach (JObject mergedRow in mergedData) { //Model.HJGL_CH_HotProessTrustItem item = new Model.HJGL_CH_HotProessTrustItem(); //string status = mergedRow.Value("status"); //JObject values = mergedRow.Value("values"); //int rowIndex = mergedRow.Value("index"); //item.HotProessTrustId = this.HotProessTrustId; //item.JOT_ID = values.Value("JOT_ID").ToString(); //System.Web.UI.WebControls.CheckBoxList cblProessTypes = (System.Web.UI.WebControls.CheckBoxList)(this.Grid1.Rows[rowIndex].FindControl("cblProessTypes")); //string str = string.Empty; ////bool needComplete = false; //for (int i = 0; i < cblProessTypes.Items.Count; i++) //{ // if (cblProessTypes.Items[i].Selected) // { // str += BLL.HJGL_CH_HotProessTrustService.GetProessTypesId(cblProessTypes.Items[i].Value) + "|"; // } //} //item.ProessTypes = str; string status = mergedRow.Value("status"); JObject values = mergedRow.Value("values"); int rowIndex = mergedRow.Value("index"); System.Web.UI.WebControls.CheckBoxList cblProessTypes = (System.Web.UI.WebControls.CheckBoxList)(this.Grid1.Rows[rowIndex].FindControl("cblProessTypes")); string str = string.Empty; //bool needComplete = false; for (int i = 0; i < cblProessTypes.Items.Count; i++) { if (cblProessTypes.Items[i].Selected) { Model.HJGL_CH_HotProessTrustItem item = new Model.HJGL_CH_HotProessTrustItem(); item.HotProessTrustId = this.HotProessTrustId; item.JOT_ID = values.Value("JOT_ID").ToString(); item.ProessTypes = BLL.HJGL_CH_HotProessTrustService.GetProessTypesId(cblProessTypes.Items[i].Value); item.TrustDate = Funs.GetNewDateTime(values.Value("TrustDate").ToString()); item.Remark = values.Value("Remark").ToString(); item.TrustItemID = values.Value("TrustItemID").ToString(); BLL.HJGL_CH_HotProessTrustService.AddCH_HotProessTrustItem(item); if (item.ProessTypes.Contains("4") || item.ProessTypes.Contains("5")) //需要进入热处理报告的记录 { Model.HJGL_HotProessItem oldHotProessItem = (from x in Funs.DB.HJGL_HotProessItem where x.JOT_ID == item.JOT_ID && x.ProessTypes == item.ProessTypes && x.HotProessTrustId == this.HotProessTrustId select x).FirstOrDefault(); if (oldHotProessItem == null) { Model.HJGL_HotProessItem hotProessItem = new Model.HJGL_HotProessItem(); hotProessItem.HotProessItemId = SQLHelper.GetNewID(typeof(Model.HJGL_HotProessItem)); hotProessItem.JOT_ID = item.JOT_ID; hotProessItem.HotProessTrustId = this.HotProessTrustId; hotProessItem.ProessTypes = item.ProessTypes; hotProessItem.SortIndex = BLL.HJGL_HotProessManageEditService.GetSortIndex(this.HotProessTrustId, item.JOT_ID, item.ProessTypes); BLL.HJGL_HotProessManageEditService.AddHotProessItem(hotProessItem, "", null); } } //进入热处理结果反馈 Model.HJGL_CH_HotProessResult oldHotProessResult = (from x in Funs.DB.HJGL_CH_HotProessResult where x.JOT_ID == item.JOT_ID && x.ProessTypes == item.ProessTypes && x.HotProessTrustId == this.HotProessTrustId select x).FirstOrDefault(); if (oldHotProessResult == null) { Model.HJGL_CH_HotProessResult hotProessResult = new Model.HJGL_CH_HotProessResult(); hotProessResult.JOT_ID = item.JOT_ID; hotProessResult.HotProessTrustId = this.HotProessTrustId; hotProessResult.ProessTypes = item.ProessTypes; BLL.HJGL_CH_HotProessResultService.AddHotProessResult(hotProessResult); } } } //if (str.Contains("1") || str.Contains("2") || str.Contains("3")) //{ // needComplete = true; //} //if (needComplete) //{ // System.Web.UI.WebControls.CheckBox cbIsComplete = (System.Web.UI.WebControls.CheckBox)(this.Grid1.Rows[rowIndex].FindControl("cbIsComplete")); // if (cbIsComplete.Checked) // { // item.IsComplete = true; // } // else // { // item.IsComplete = false; // } //} //else //{ // item.IsComplete = null; //} } } #endregion #region Grid 关闭弹出窗口事件 /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { List list = Funs.GetStrListByStr(hdItemsString.Text, '|'); List lists = BLL.HJGL_CH_HotProessTrustService.GetHotProessTrustAddItem(this.hdItemsString.Text); this.BindGrid(lists); //this.hdItemsString.Text = string.Empty; } #endregion #region 右键删除事件 /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { //this.CollectGridJointInfo(); List GetHotProessTrustItem = new List(); foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); if (!string.IsNullOrEmpty(this.hdItemsString.Text)) { GetHotProessTrustItem = BLL.HJGL_CH_HotProessTrustService.GetHotProessTrustAddItem(this.hdItemsString.Text); } else if (string.IsNullOrEmpty(this.hdItemsString.Text) && this.HotProessTrustId != null) { GetHotProessTrustItem = BLL.HJGL_CH_HotProessTrustService.GetHotProessTrustItem(this.ProjectId, this.HotProessTrustId); } var item = GetHotProessTrustItem.FirstOrDefault(x => x.JOT_ID == rowID); if (item != null) { if (string.IsNullOrEmpty(this.HotProessTrustId)) //新增记录可直接删除 { GetHotProessTrustItem.Remove(item); } else //修改记录时只能删除未处理的热处理记录 { var result = (from x in Funs.DB.HJGL_CH_HotProessResult where x.HotProessTrustId == item.HotProessTrustId && x.JOT_ID == item.JOT_ID && item.ProessTypes == x.ProessTypes select x).FirstOrDefault(); if (result != null) { if (result.IsOK == null) { GetHotProessTrustItem.Remove(item); } else { ShowNotify("热处理结果已反馈,无法删除!", MessageBoxIcon.Warning); return; } } } } } BindGrid(GetHotProessTrustItem); ShowNotify("操作完成!", MessageBoxIcon.Success); ShowNotify("操作完成!", MessageBoxIcon.Success); } } #endregion /// /// 查找未焊接焊口 /// /// /// protected void ckSelect_Click(object sender, EventArgs e) { //this.CollectGridJointInfo(); if (!string.IsNullOrEmpty(this.drpUnit.SelectedValue) && this.drpUnit.SelectedValue != BLL.Const._Null) { string strList = this.drpUnit.SelectedValue + "|" + this.HotProessTrustId + "|" + this.ProjectId; string window = String.Format("HotProessTrustItemEdit.aspx?strList={0}", strList, "编辑 - "); PageContext.RegisterStartupScript(Window1.GetSaveStateReference(hdItemsString.ClientID) + Window1.GetShowReference(window)); } else { Alert.ShowInTop("请选择单位!", MessageBoxIcon.Warning); } } /// /// 是否返修口 /// /// /// protected string ConvertIsRepair(object TrustItemID) { string state = string.Empty; if (TrustItemID != null) { string trustItemID = TrustItemID.ToString(); if (!string.IsNullOrEmpty(trustItemID)) { state = "是"; } } return state; } } }