using BLL; using FineUIPro.Web.YLRQ.Dto; 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; using System.Web.UI; using System.Web.UI.WebControls; namespace FineUIPro.Web.YLRQ.ConstructionManagement { public partial class WeldReportEdit : PageBase { /// /// 焊接日报主键 /// public string DReportID { get { return (string)ViewState["DReportID"]; } set { ViewState["DReportID"] = value; } } /// /// 加载页面 /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.DReportID = Request.Params["DReportID"]; this.ddlProjectId.DataTextField = "ProjectTextField"; this.ddlProjectId.DataValueField = "ProjectId"; this.ddlProjectId.DataSource = BLL.Base_ProjectService.GetYlrqProjectListByUserId(this.CurrUser.UserId, "2");//BLL.Base_ProjectService.GetProjectListByUserId(this.CurrUser.UserId, "2"); this.ddlProjectId.DataBind(); Funs.FineUIPleaseSelect(ddlProjectId); this.ddlProjectId.SelectedValue = this.CurrUser.LoginProjectId; // 初始化页面 List GetWeldReportItem = WeldReportItem(this.DReportID); this.BindGrid(GetWeldReportItem); // 加载页面 this.PageInfoLoad(); } } /// /// 加载页面 /// public void PageInfoLoad() { //加载页面 this.ddlProjectId.Enabled = false; var report = Funs.DB.PV_BO_WeldReportMain.FirstOrDefault(x => x.DReportID == DReportID); if (report != null) { this.txtWeldDailyReportNo.Text = report.WeldDailyReportNo; this.txtReportDate.Text = report.ReportDate.ToString("yyyy-MM-dd"); this.txtTableDate.Text = report.TableDate != null ? report.TableDate.Value.ToString("yyyy-MM-dd") : string.Empty; this.txtRemark.Text = report.Remark; this.ddlProjectId.SelectedValue = report.ProjectId; } else { this.SimpleForm1.Reset(); ///重置所有字段 this.ddlProjectId.SelectedValue = this.CurrUser.LoginProjectId; this.txtReportDate.Text = DateTime.Now.ToString("yyyy-MM-dd"); this.txtTableDate.Text = DateTime.Now.ToString("yyyy-MM-dd"); } ///制单人 this.ddlTabler.DataTextField = "UserName"; this.ddlTabler.DataValueField = "UserId"; this.ddlTabler.DataSource = Funs.DB.Sys_User; //BLL.Sys_UserService.GetUserListByProjectId(this.ddlProjectId.SelectedValue); this.ddlTabler.DataBind(); Funs.FineUIPleaseSelect(this.ddlTabler); if (this.CurrUser.UserId != Const.GlyId) { this.ddlTabler.SelectedValue = this.CurrUser.UserId; } //获取焊工信息 string weldStr = "SELECT ProjectWelder.ProjectWelderId,ProjectWelder.WED_ID,Welder.WED_Code,Welder.WED_Name,ProjectWelder.IsSelected,ProjectWelder.SelectedMan,ProjectWelder.IsApprove,ProjectWelder.ApproveMan FROM dbo.Project_Welder AS ProjectWelder LEFT JOIN HJGL_BS_Welder AS Welder ON ProjectWelder.WED_ID = Welder.WED_ID WHERE ProjectWelder.ProjectId=@ProjectId "; SqlParameter[] weldParameter = new SqlParameter[] { new SqlParameter("@ProjectId", ddlProjectId.SelectedValue) }; var welderdt = SQLHelper.GetDataTableRunText(weldStr, weldParameter); //打底焊工 DropDownList ddlBackingWelder = Grid1.FindColumn("BackingWelderId").FindControl("ddlBackingWelder") as DropDownList; ddlBackingWelder.DataTextField = "WED_Name"; ddlBackingWelder.DataValueField = "WED_ID"; ddlBackingWelder.DataSource = welderdt; ddlBackingWelder.DataBind(); //盖面焊工 DropDownList ddlCoverWelder = Grid1.FindColumn("CoverWelderId").FindControl("ddlCoverWelder") as DropDownList; ddlCoverWelder.DataTextField = "WED_Name"; ddlCoverWelder.DataValueField = "WED_ID"; ddlCoverWelder.DataSource = welderdt; ddlCoverWelder.DataBind(); //单位下拉框绑定 this.drpUnit.Items.Clear(); var pUnit = BLL.Base_UnitService.GetUnitsByProjectUnitType(this.ddlProjectId.SelectedValue, BLL.Const.UnitType_4); if (pUnit != null) { this.drpUnit.DataTextField = "UnitName"; this.drpUnit.DataValueField = "UnitId"; this.drpUnit.DataSource = pUnit; this.drpUnit.DataBind(); } if (report != null) { if (!string.IsNullOrEmpty(report.UnitId)) { var tabler = this.ddlTabler.Items.FirstOrDefault(x => x.Value == report.Tabler); if (tabler != null) { this.ddlTabler.SelectedValue = report.Tabler; } } this.drpUnit.SelectedValue = report.UnitId; this.drpUnit.Enabled = false; } } #region 数据绑定 /// /// 数据绑定 /// private void BindGrid(List GetWeldReportItem) { DataTable tb = this.LINQToDataTable(GetWeldReportItem); // 2.获取当前分页数据 Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { List GetWeldReportItem = this.CollectGridJointInfo(); this.BindGrid(GetWeldReportItem); } #endregion #region 提交 /// /// 编辑焊接日报 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { try { if (ddlTabler.SelectedValue == Const._Null) { ShowNotify("请选择制单人!"); return; } if (string.IsNullOrWhiteSpace(this.DReportID)) { if (Funs.DB.PV_BO_WeldReportMain.Count(p => p.WeldDailyReportNo == txtWeldDailyReportNo.Text.Trim()) > 0) { ShowNotify("日报编号已存在,请重新录入!", MessageBoxIcon.Warning); return; } } else { if (Funs.DB.PV_BO_WeldReportMain.Count(p => p.WeldDailyReportNo == txtWeldDailyReportNo.Text.Trim() && p.DReportID != this.DReportID) > 0) { ShowNotify("日报编号已存在,请重新录入!", MessageBoxIcon.Warning); return; } } List weldReportItem = this.CollectGridJointInfo(); if (weldReportItem.Count == 0) { ShowNotify("请选择焊缝信息!", MessageBoxIcon.Warning); return; } //获取所有的焊缝信息 var weldingIds = weldReportItem.ConvertAll(p => p.WeldingId); List weldInfos = Funs.DB.PV_WeldInformation.Where(p => weldingIds.Contains(p.WeldingId)).ToList(); if (weldInfos.Count == 0) { ShowNotify("请选择焊缝信息!", MessageBoxIcon.Warning); return; } //添加焊缝报告 PV_BO_WeldReportMain weldMain = Funs.DB.PV_BO_WeldReportMain.FirstOrDefault(p => p.DReportID == this.DReportID); if (weldMain == null) { weldMain = new PV_BO_WeldReportMain(); weldMain.DReportID = Guid.NewGuid().ToString(); weldMain.ProjectId = ddlProjectId.SelectedValue; weldMain.ReportDate = DateTime.Parse(txtReportDate.Text); weldMain.TableDate = DateTime.Parse(txtTableDate.Text); weldMain.UnitId = drpUnit.SelectedValue; weldMain.Tabler = ddlTabler.SelectedValue; weldMain.Remark = txtRemark.Text.Trim(); weldMain.WeldDailyReportNo = txtWeldDailyReportNo.Text.Trim(); weldMain.ReportType = 1; Funs.DB.PV_BO_WeldReportMain.InsertOnSubmit(weldMain); } else { weldMain.ProjectId = ddlProjectId.SelectedValue; weldMain.ReportDate = DateTime.Parse(txtReportDate.Text); weldMain.TableDate = DateTime.Parse(txtTableDate.Text); weldMain.UnitId = drpUnit.SelectedValue; weldMain.Tabler = ddlTabler.SelectedValue; weldMain.Remark = txtRemark.Text.Trim(); weldMain.ReportType = 1; weldMain.WeldDailyReportNo = txtWeldDailyReportNo.Text.Trim(); } Funs.DB.SubmitChanges(); int i = 0; Dictionary> modifiedDict = Grid1.GetModifiedDict(); foreach (var item in weldReportItem) { CheckBoxField Confirmation = (CheckBoxField)Grid1.FindColumn("Confirmation"); var itemWeldinfo = weldInfos.FirstOrDefault(p => p.WeldingId == item.WeldingId); if (itemWeldinfo == null) continue; if (modifiedDict.ContainsKey(i)) { itemWeldinfo.BackingWelderId = modifiedDict[i].ContainsKey("BackingWelderId") ? modifiedDict[i]["BackingWelderId"].ToString() : item.BackingWelderId; itemWeldinfo.CoverWelderId = modifiedDict[i].ContainsKey("CoverWelderId") ? modifiedDict[i]["CoverWelderId"].ToString() : item.CoverWelderId; } else { itemWeldinfo.BackingWelderId = item.BackingWelderId; itemWeldinfo.CoverWelderId = item.CoverWelderId; } itemWeldinfo.DReportID = weldMain.DReportID; itemWeldinfo.Confirmation = Confirmation.GetCheckedState(i) ? 1 : 0; Funs.DB.SubmitChanges(); i++; } ShowNotify("提交成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(weldMain.DReportID) + ActiveWindow.GetHidePostBackReference()); } catch (Exception ex) { ShowNotify(ex.Message, MessageBoxIcon.Error); } } #endregion #region 收集Grid页面信息 /// /// 收集Grid页面信息 /// /// private List CollectGridJointInfo() { List getNewWeldReportItem = new List(); if (!string.IsNullOrEmpty(this.hdItemsString.Text)) { getNewWeldReportItem = GetWeldReportAddItem(this.hdItemsString.Text); } else if (string.IsNullOrEmpty(this.hdItemsString.Text) && this.DReportID != null) { getNewWeldReportItem = WeldReportItem(this.DReportID); } return getNewWeldReportItem; #region 注释 //JArray mergedData = Grid1.GetMergedData(); //foreach (JObject mergedRow in mergedData) //{ // string status = mergedRow.Value("status"); // JObject values = mergedRow.Value("values"); // string rowID = values.Value("JOT_ID").ToString(); // var item = GetWeldReportItem.FirstOrDefault(x => x.JOT_ID == rowID); // if (item != null) // { // var cellWelderCode = (from x in Funs.DB.HJGL_BS_Welder // join y in Funs.DB.Project_Welder // on x.WED_ID equals y.WED_ID // where y.ProjectId == ddlProjectId.SelectedValue && x.WED_Code == values.Value("JOT_CellWelderID") // select x).FirstOrDefault(); // if (cellWelderCode != null) // { // item.JOT_CellWelderCode = cellWelderCode.WED_Code; // item.JOT_CellWelderID = cellWelderCode.WED_ID; // } // var floorWelderCode = (from x in Funs.DB.HJGL_BS_Welder // join y in Funs.DB.Project_Welder // on x.WED_ID equals y.WED_ID // where y.ProjectId == ddlProjectId.SelectedValue && x.WED_Code == values.Value("JOT_FloorWelderID") // select x).FirstOrDefault(); // if (floorWelderCode != null) // { // item.JOT_FloorWelderCode = floorWelderCode.WED_Code; // item.JOT_FloorWelderID = floorWelderCode.WED_ID; // } // if (values.Value("WLO_CodeName").ToString() == "现场安装") // { // item.WLO_CodeName = "现场安装"; // item.WLO_CodeID = "F"; // } // else // { // item.WLO_CodeName = "预制"; // item.WLO_CodeID = "S"; // } // string s = values.Value("WME_ID"); // var weldingMethod = (from x in Funs.DB.HJGL_BS_WeldMethod where x.WME_Name == values.Value("WME_ID") select x).FirstOrDefault(); // if (weldingMethod != null) // { // item.WME_Name = weldingMethod.WME_Name; // item.WME_ID = weldingMethod.WME_ID; // } // var weldMat = (from x in Funs.DB.HJGL_BS_WeldMaterial where x.WMT_MatCode == values.Value("JOT_WeldMat") select x).FirstOrDefault(); // if (weldMat != null) // { // item.JOT_WeldMat = weldMat.WMT_ID; // item.WeldMatCode = weldMat.WMT_MatCode; // } // else // { // item.JOT_WeldMat = null; // item.WeldMatCode = null; // } // var weldSilk = (from x in Funs.DB.HJGL_BS_WeldMaterial where x.WMT_MatCode == values.Value("JOT_WeldSilk") select x).FirstOrDefault(); // if (weldSilk != null) // { // item.JOT_WeldSilk = weldSilk.WMT_ID; // item.WeldSilkCode = weldSilk.WMT_MatCode; // } // else // { // item.JOT_WeldSilk = null; // item.WeldSilkCode = null; // } // item.JOT_JointAttribute = values.Value("JOT_JointAttribute").ToString(); // item.JOT_Location = values.Value("JOT_Location").ToString(); // item.JOT_Size = Funs.GetNewDecimalOrZero(values.Value("JOT_Size").ToString()); // item.JOT_DoneDin = Funs.GetNewDecimalOrZero(values.Value("JOT_DoneDin").ToString()); // item.JOT_Dia = Funs.GetNewDecimal(values.Value("JOT_Dia")); // item.JOT_Sch = values.Value("JOT_Sch").ToString(); // getNewWeldReportItem.Add(item); // } //} //return getNewWeldReportItem; #endregion } #endregion #region Grid 关闭弹出窗口事件 /// /// 关闭弹出窗口 /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { List list = Funs.GetStrListByStr(hdItemsString.Text, '#'); if (list.Count() > 0) { List GetWeldReportItem = GetWeldReportAddItem(this.hdItemsString.Text); this.BindGrid(GetWeldReportItem); this.SetDailyReportNo(); } } #endregion #region 右键删除事件 /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { List GetWeldReportItem = this.CollectGridJointInfo(); foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); //var batchDetail = BLL.HJGL_BO_BatchDetailService.GetBatchDetailByJotId(rowID); //if (batchDetail != null) //{ // var batch = BLL.HJGL_BO_BatchService.GetBatchById(batchDetail.BatchId); // if (batch != null && (batch.BatchIsClosed == false || batch.BatchIsClosed == null)) // { // BLL.HJGL_BO_BatchDetailService.DeleteBatchDetail(rowID); // } //} var item = GetWeldReportItem.FirstOrDefault(x => x.WeldingId == rowID); if (item != null) GetWeldReportItem.Remove(item); } BindGrid(GetWeldReportItem); ShowNotify("操作完成!", MessageBoxIcon.Success); } } #endregion #region 查找 /// /// 查找未焊接焊口 /// /// /// protected void ckSelect_Click(object sender, EventArgs e) { string jotIds = string.Empty; string jointList = string.Empty; List GetWeldReportItem = this.CollectGridJointInfo(); if (GetWeldReportItem != null) { foreach (var item in GetWeldReportItem) { jotIds = jotIds + item.WeldingId + "|"; jointList = jointList + item.WeldingId + "|" + item.BackingWelderId + "|" + item.CoverWelderId + "^"; } } if (jotIds != string.Empty) { jotIds = jotIds.Substring(0, jotIds.Length - 1); jointList = jointList.Substring(0, jointList.Length - 1); } if (!string.IsNullOrEmpty(this.drpUnit.SelectedValue) && this.drpUnit.SelectedValue != BLL.Const._Null) { string strList = this.ddlProjectId.SelectedValue + "|" + this.drpUnit.SelectedValue + "|" + this.DReportID; string window = String.Format("WeldReportItemEdit.aspx?strList={0}&jotIds={1}&jointList={2}", strList, jotIds, jointList, "编辑 - "); PageContext.RegisterStartupScript(Window1.GetSaveStateReference(hdItemsString.ClientID) + Window1.GetShowReference(window)); } else { Alert.ShowInTop("请选择单位!", MessageBoxIcon.Warning); } } #endregion #region 私有方法 /// /// 根据报告获取焊缝明细 /// /// private static List WeldReportItem(string dreportID) { List weldReportItems = new List(); string strSql = "SELECT weld.WeldingId,weldReport.DReportID,weldReport.ProjectId,weldReport.Remark,weldReport.ReportDate,weldReport.TableDate,weldReport.Tabler,weldReport.UnitId,weldReport.WeldDailyReportNo,project.ProjectCode,weld.WeldingCode,weld.BackingWelderId,(select a.pkidStr from (SELECT STUFF(( SELECT ',' +convert(VARCHAR, WED_Name) FROM (select Welder.WED_Name from HJGL_BS_Welder as Welder where Welder.WED_ID in (select Id from StrToTable(weld.BackingWelderId)))t FOR XML PATH('')), 1, 1, '') AS pkidStr) a) as BackingWelderName,weld.CoverWelderId,(select a.pkidStr from (SELECT STUFF(( SELECT ',' +convert(VARCHAR, WED_Name) FROM (select Welder.WED_Name from HJGL_BS_Welder as Welder where Welder.WED_ID in (select Id from StrToTable(weld.CoverWelderId)))t FOR XML PATH('')), 1, 1, '') AS pkidStr) a) as CoverWelderName,weld.WmeId,WeldMethod.WME_Name,weld.Confirmation,(case Confirmation when 0 then '未确认' when 1 then '已确认' else '' end) as ConfirmationName FROM PV_WeldInformation AS weld INNER JOIN PV_BO_WeldReportMain as weldReport on weldReport.DReportID=weld.DReportID LEFT JOIN HJGL_BS_WeldMethod AS weldMethod ON weldMethod.WME_ID = weld.WmeId LEFT JOIN Base_Project as project on project.ProjectId=weld.ProjectId WHERE weld.DReportID=@DReportID order by weldReport.ReportDate desc"; List listStr = new List(); listStr.Add(new SqlParameter("@DReportID", dreportID)); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); if (tb.Rows.Count > 0) { for (int i = 0; i < tb.Rows.Count; i++) { PV_SpRpWeldReportItem weldReportModel = new PV_SpRpWeldReportItem(); weldReportModel.WeldingId = tb.Rows[i]["WeldingId"].ToString(); weldReportModel.WeldingCode = tb.Rows[i]["WeldingCode"].ToString(); weldReportModel.DReportID = tb.Rows[i]["DReportID"].ToString(); weldReportModel.ProjectId = tb.Rows[i]["ProjectId"].ToString(); weldReportModel.ProjectCode = tb.Rows[i]["ProjectCode"].ToString(); weldReportModel.Remark = tb.Rows[i]["Remark"].ToString(); weldReportModel.ReportDate = DateTime.Parse(tb.Rows[i]["ReportDate"].ToString()); weldReportModel.TableDate = DateTime.Parse(tb.Rows[i]["TableDate"].ToString()); weldReportModel.Tabler = tb.Rows[i]["Tabler"].ToString(); weldReportModel.UnitId = tb.Rows[i]["UnitId"].ToString(); weldReportModel.WeldDailyReportNo = tb.Rows[i]["WeldDailyReportNo"].ToString(); weldReportModel.BackingWelderId = tb.Rows[i]["BackingWelderId"].ToString(); weldReportModel.BackingWelderName = tb.Rows[i]["BackingWelderName"].ToString(); weldReportModel.CoverWelderId = tb.Rows[i]["CoverWelderId"].ToString(); weldReportModel.CoverWelderName = tb.Rows[i]["CoverWelderName"].ToString(); weldReportModel.WmeId = tb.Rows[i]["WmeId"].ToString(); weldReportModel.WME_Name = tb.Rows[i]["WME_Name"].ToString(); weldReportModel.Confirmation = !string.IsNullOrEmpty(tb.Rows[i]["Confirmation"].ToString()) ? int.Parse(tb.Rows[i]["Confirmation"].ToString()) : 0; weldReportModel.ConfirmationName = tb.Rows[i]["ConfirmationName"].ToString(); weldReportItems.Add(weldReportModel); } } return weldReportItems; } /// /// 查找后返回集合增加到列表集团中 /// /// public static List GetWeldReportAddItem(string hdItemsString) { List weldReportItems = new List(); if (!string.IsNullOrEmpty(hdItemsString)) { List list = Funs.GetStrListByStr(hdItemsString, '#'); if (list.Count() > 0) { var weldingIds = list.Select(p => p.Split('|')[0]); if (weldingIds.Count() == 0) return new List(); var idstr = string.Format("'{0}'", string.Join("','", string.Join(",", weldingIds).Split(','))); string strSql = @"select a.WeldingId,a.ProjectId,c.ProjectCode,a.WeldingCode,b.WME_ID,b.WME_Code,b.WME_Name,a.Confirmation,(case a.Confirmation when 0 then '未确认' when 1 then '已确认' else '' end) as ConfirmationName,d.ReportDate from PV_WeldInformation as a left join HJGL_BS_WeldMethod as b on a.WmeId=b.WME_ID left join Base_Project as c on c.ProjectId=a.ProjectId left join PV_BO_WeldReportMain as d on d.DReportID=a.DReportID WHERE 1=1 " + string.Format(" and a.WeldingId in ({0}) order by d.ReportDate desc", idstr); var tb = SQLHelper.GetDataTableRunText(strSql, new List().ToArray()); if (tb.Rows.Count > 0) { int i = 0; foreach (var jot in list) { string[] jotItem = jot.Split('|'); var itemRow = tb.Rows[i]; if (itemRow != null) { PV_SpRpWeldReportItem weldReportModel = new PV_SpRpWeldReportItem(); weldReportModel.WeldingId = itemRow["WeldingId"].ToString(); weldReportModel.ProjectCode = itemRow["ProjectCode"].ToString(); weldReportModel.WME_Name = itemRow["WME_Name"].ToString(); weldReportModel.WeldingCode = itemRow["WeldingCode"].ToString(); weldReportModel.ProjectId = itemRow["ProjectId"].ToString(); weldReportModel.BackingWelderId = jotItem[1]; weldReportModel.CoverWelderId = jotItem[2]; weldReportModel.WmeId = itemRow["WME_ID"].ToString(); weldReportModel.Confirmation = string.IsNullOrWhiteSpace(itemRow["Confirmation"].ToString()) ? 0 : int.Parse(itemRow["Confirmation"].ToString()); weldReportModel.Confirmation = 1; weldReportItems.Add(weldReportModel); } i++; } } } } return weldReportItems; } /// /// 设置日报号 /// private void SetDailyReportNo() { string projecName = BLL.Base_ProjectService.GetProjectCode(this.ddlProjectId.SelectedValue); string perfix = string.Empty; string date = DateTime.Now.ToString("yyyyMM"); if (string.IsNullOrEmpty(this.txtWeldDailyReportNo.Text)) { perfix = projecName + "-" + date + "-"; this.txtWeldDailyReportNo.Text = BLL.SQLHelper.RunProcNewIdByProjectId("SpGetNewCodeByProjectId", "dbo.PV_BO_WeldReportMain", "WeldDailyReportNo", this.ddlProjectId.SelectedValue, perfix); } } #endregion } }