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.MaterialManage { public partial class ElectrodeRecoveryEditBack : PageBase { #region 定义项 /// /// 主键 /// public string ElectrodeRecoveryId { get { return (string)ViewState["ElectrodeRecoveryId"]; } set { ViewState["ElectrodeRecoveryId"] = value; } } private bool AppendToEnd = false; #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.ElectrodeRecoveryId = Request.Params["ElectrodeRecoveryId"]; ///编制人 this.drpCompileMan.DataTextField = "UserName"; this.drpCompileMan.DataValueField = "UserId"; this.drpCompileMan.DataSource = BLL.UserService.GetProjectUserListByProjectId(this.CurrUser.LoginProjectId); this.drpCompileMan.DataBind(); Funs.FineUIPleaseSelect(this.drpCompileMan); if (!string.IsNullOrEmpty(this.ElectrodeRecoveryId)) { var electrode = BLL.HJGL_ElectrodeRecoveryService.GetElectrodeRecoveryByID(this.ElectrodeRecoveryId); if (electrode != null) { this.txtEletrodeCode.Text = electrode.ElectrodeRecoveryCode; this.txtElectrodeRecoveryDate.Text = string.Format("{0:yyyy-MM-dd hh:mm:ss}", electrode.ElectrodeRecoveryDate); this.txtCompileDate.Text = string.Format("{0:yyyy-MM-dd hh:mm:ss}", electrode.CompileDate); this.drpCompileMan.SelectedValue = electrode.CompileMan; } } else { this.txtElectrodeRecoveryDate.Text = string.Format("{0:yyyy-MM-dd hh:mm:ss}", System.DateTime.Now); this.txtCompileDate.Text = string.Format("{0:yyyy-MM-dd hh:mm:ss}", System.DateTime.Now); this.drpCompileMan.SelectedValue = this.CurrUser.UserId; //this.txtEletrodeCode.Text = BLL.SQLHelper.RunProcNewId("Sp_GetNewCode3ByProjectIdAndDate", "HJGL_ElectrodeRecovery", "ElectrodeRecoveryCode", "CompileDate", this.CurrUser.LoginProjectId, System.DateTime.Now.ToString("yyyy-MM-dd"), System.DateTime.Now.AddDays(1).ToString("yyyy-MM-dd")); } ///焊条 //this.drpWME_ID.DataTextField = "WMT_MatName"; //this.drpWME_ID.DataValueField = "WMT_MatName"; //this.drpWME_ID.DataSource = BLL.HJGL_ConsumablesService.GetMaterialList("2"); //this.drpWME_ID.DataBind(); //单元编号/专业名称 this.drpCnProfession.DataTextField = "Text"; this.drpCnProfession.DataValueField = "Text"; this.drpCnProfession.DataSource = BLL.DropListService.HJGL_CnProfession(); this.drpCnProfession.DataBind(); //Funs.FineUIPleaseSelect(this.drpCnProfession); //使用钢结构、设备代号、管道号 this.drpEquipment.DataTextField = "Text"; this.drpEquipment.DataValueField = "Text"; this.drpEquipment.DataSource = BLL.DropListService.HJGL_Equipment(); this.drpEquipment.DataBind(); //Funs.FineUIPleaseSelect(this.drpEquipment); // 删除选中单元格的客户端脚本 string deleteScript = GetDeleteScript(); // 新增数据初始值 JObject defaultObj = new JObject(); defaultObj.Add("WelderCode", ""); defaultObj.Add("InstallationName", ""); defaultObj.Add("CnProfession", ""); defaultObj.Add("Equipment", ""); defaultObj.Add("WMT_MatName", ""); //defaultObj.Add("WMT_MatName", ""); //defaultObj.Add("ElectrodeRecoveryModel", ""); //defaultObj.Add("ElectrodeGrade", ""); //defaultObj.Add("BatchNumber", ""); //defaultObj.Add("InLibCode", ""); //defaultObj.Add("Specifications", ""); //defaultObj.Add("WelderCode", ""); //defaultObj.Add("UseSite", ""); //defaultObj.Add("WeldingMaterial", ""); defaultObj.Add("RecipientsCount", "0"); //defaultObj.Add("RecoveryCount", "0.0"); //defaultObj.Add("GrantMan", this.CurrUser.UserName); defaultObj.Add("Delete", String.Format("", deleteScript, IconHelper.GetResolvedIconUrl(Icon.Delete))); // 在第一行新增一条数据 btnNew.OnClientClick = Grid1.GetAddNewRecordReference(defaultObj, AppendToEnd); // 删除选中行按钮 btnDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("请至少选择一项!") + deleteScript; // 绑定表格 this.BindGrid(); } } #endregion /// /// 焊工号的输入框事件 /// /// drpInstallation /// protected void Text_TextChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.txtWelderCode.Text)) { var w = Funs.DB.BS_Welder.FirstOrDefault(x => x.WED_Code == this.txtWelderCode.Text.Trim()); if (w != null) { //if (!string.IsNullOrEmpty(w.WED_Unit)) //{ // var unit = BLL.Base_UnitService.GetUnit(w.WED_Unit); // if (unit != null) // { // this.txtUnitName.Text = unit.UnitName; // } //} this.drpInstallation.DataTextField = "Text"; this.drpInstallation.DataValueField = "Text"; this.drpInstallation.DataSource = BLL.Project_InstallationService.GetInstallationList(w.ProjectId, w.WED_Unit); this.drpInstallation.DataBind(); ///焊条 this.drpWME_ID.DataTextField = "ConsumablesName"; this.drpWME_ID.DataValueField = "ConsumablesName"; var totalWeldMaterials = from x in Funs.DB.Base_Consumables select x; List welderQualifiedProjects = (from x in Funs.DB.BS_WelderQualifiedProject where x.WED_ID == w.WED_ID && x.LimitDate > DateTime.Now select x).ToList(); List weldMaterials = new List(); // if (welderQualifiedProjects.Count > 0) //{ // foreach (var welderQualifiedProject in welderQualifiedProjects) // { // if (welderQualifiedProject.QualifiedProjectCode.Contains("FeⅠ")) // { // weldMaterials.AddRange(totalWeldMaterials.Where(x => x.SteelType == "1")); //碳钢 // } // else if (welderQualifiedProject.QualifiedProjectCode.Contains("FeⅡ")) // { // weldMaterials.AddRange(totalWeldMaterials.Where(x => x.SteelType == "1" || x.SteelType == "4")); //碳钢、低合金钢 // } // else if (welderQualifiedProject.QualifiedProjectCode.Contains("FeⅢ")) // { // weldMaterials.AddRange(totalWeldMaterials.Where(x => x.SteelType == "1" || x.SteelType == "3" || x.SteelType == "4")); //碳钢、铬钼钢、低合金钢 // } // else if (welderQualifiedProject.QualifiedProjectCode.Contains("FeⅣ")) // { // weldMaterials.AddRange(totalWeldMaterials.Where(x => x.SteelType == "2")); //不锈钢 // } // else if (welderQualifiedProject.QualifiedProjectCode.Contains("Ni")) // { // weldMaterials.AddRange(totalWeldMaterials.Where(x => x.SteelType == "5")); //镍合金钢 // } // else if (welderQualifiedProject.QualifiedProjectCode.Contains("Ti")) // { // weldMaterials.AddRange(totalWeldMaterials.Where(x => x.SteelType == "6")); //钛合金钢 // } // } //} this.drpWME_ID.DataSource = totalWeldMaterials; this.drpWME_ID.DataBind(); } } } #region 数据绑定 /// /// 数据绑定 /// private void BindGrid() { string strSql = @"SELECT Item.ElectrodeRecoveryItemID" + @" ,Item.ElectrodeRecoveryId" + @" ,Item.ElectrodeGrade" + @" ,Item.BatchNumber" + @" ,Item.InLibCode" + @" ,Item.Specifications" + @" ,Item.WelderCode" + @" ,Item.UseSite" + @" ,Item.WeldingMaterial" + @" ,Item.RecipientsCount" + @" ,Item.RecoveryCount" + @" ,Item.GrantMan" + @" ,Item.ElectrodeRecoveryModel" + @" ,Item.WMT_ID" + @" ,Item.InstallationId" + @" ,(CASE Item.CnProfession WHEN '1' THEN '管道安装工程' WHEN '2' THEN '钢结构安装工程' WHEN '3' THEN '仪表安装工程' END) AS CnProfession" + @" ,(CASE Item.Equipment WHEN '1' THEN '管道' WHEN '2' THEN '钢结构' WHEN '3' THEN '仪表' END) AS Equipment" + @" ,Installation.InstallationName" + @",WeldMaterial.ConsumablesName as WMT_MatName" + @",Welder.WED_Name AS WelderName" + @" FROM HJGL_ElectrodeRecoveryItem AS Item" + @" LEFT JOIN Project_Installation AS Installation ON Installation.InstallationId = Item.InstallationId" + @" LEFT JOIN Base_Consumables AS WeldMaterial ON WeldMaterial.ConsumablesId = Item.WMT_ID " + @" LEFT JOIN BS_Welder AS Welder ON Welder.WED_Code = Item.WelderCode" + @" WHERE ElectrodeRecoveryId=@ElectrodeRecoveryId"; SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@ElectrodeRecoveryId",this.ElectrodeRecoveryId), }; DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.DataSource = tb; Grid1.DataBind(); } #endregion /// /// Grid1加载前事件 /// /// /// protected void Grid1_PreDataBound(object sender, EventArgs e) { // 设置LinkButtonField的点击客户端事件 LinkButtonField deleteField = Grid1.FindColumn("Delete") as LinkButtonField; deleteField.OnClientClick = GetDeleteScript(); } /// /// 删除提示 /// /// private string GetDeleteScript() { if (!CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_ElectrodeRecoveryMenuId, Const.BtnDelete)) { ShowNotify("您没有这个权限,请与管理员联系!"); return null; } else { return Confirm.GetShowReference("删除选中行?", String.Empty, MessageBoxIcon.Question, Grid1.GetDeleteSelectedRowsReference(), String.Empty); } } #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { BindGrid(); } #endregion #region 保存、审核 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (!CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_ElectrodeRecoveryMenuId, Const.BtnSave)) { ShowNotify("您没有这个权限,请与管理员联系!"); return; } this.SavaData(BLL.Const.BtnSave); ShowNotify("保存成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } /// /// 审核按钮 /// /// /// protected void btnAudit_Click(object sender, EventArgs e) { if (!CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_ElectrodeRecoveryMenuId, Const.BtnAuditing)) { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Information); return; } this.SavaData(BLL.Const.BtnAuditing); ShowNotify("审核成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } /// /// 保存数据 /// /// private void SavaData(string type) { Model.HJGL_ElectrodeRecovery newElectrodeRecovery = new Model.HJGL_ElectrodeRecovery(); newElectrodeRecovery.ElectrodeRecoveryCode = this.txtEletrodeCode.Text.Trim(); newElectrodeRecovery.ElectrodeRecoveryDate = Funs.GetNewDateTime(this.txtElectrodeRecoveryDate.Text).Value; newElectrodeRecovery.AuditDate = DateTime.Now; newElectrodeRecovery.AuditMan = this.CurrUser.UserId; //newElectrodeRecovery.UnitId = null; if (this.drpCompileMan.SelectedValue != BLL.Const._Null) { newElectrodeRecovery.CompileMan = this.drpCompileMan.SelectedValue; } newElectrodeRecovery.CompileDate = Funs.GetNewDateTime(this.txtCompileDate.Text); newElectrodeRecovery.ProjectId = this.CurrUser.LoginProjectId; if (type == BLL.Const.BtnAuditing) { newElectrodeRecovery.AuditMan = this.CurrUser.UserId; newElectrodeRecovery.AuditDate = System.DateTime.Now; } if (!string.IsNullOrEmpty(ElectrodeRecoveryId)) { newElectrodeRecovery.ElectrodeRecoveryId = ElectrodeRecoveryId; BLL.HJGL_ElectrodeRecoveryService.UpdateElectrodeRecovery(newElectrodeRecovery); //修改焊丝烘烤记录 BLL.HJGL_ElectrodeRecoveryService.DeleteElectrodeRecoveryItem(this.CurrUser.LoginProjectId, newElectrodeRecovery.UnitId,this.ElectrodeRecoveryId); // BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "修改焊条发放回收记录!"); } else { newElectrodeRecovery.ElectrodeRecoveryId = SQLHelper.GetNewID(typeof(Model.HJGL_ElectrodeRecovery)); BLL.HJGL_ElectrodeRecoveryService.AddElectrodeRecovery(newElectrodeRecovery); //添加焊丝烘烤记录主表信息 // BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "添加焊条发放回收记录!"); } JArray teamGroupData = Grid1.GetMergedData(); foreach (JObject teamGroupRow in teamGroupData) { JObject values = teamGroupRow.Value("values"); Model.HJGL_ElectrodeRecoveryItem newElectrodeRecoveryItem = new Model.HJGL_ElectrodeRecoveryItem(); newElectrodeRecoveryItem.ElectrodeRecoveryItemID = SQLHelper.GetNewID(typeof(Model.HJGL_ElectrodeRecoveryItem)); newElectrodeRecoveryItem.ElectrodeRecoveryId = newElectrodeRecovery.ElectrodeRecoveryId; newElectrodeRecoveryItem.WelderCode = values.Value("WelderCode"); var installation = Funs.DB.Project_Installation.FirstOrDefault(x => x.InstallationName == values.Value("InstallationName") && x.ProjectId == this.CurrUser.LoginProjectId); if (installation != null) { newElectrodeRecoveryItem.InstallationId = installation.InstallationId; } if (values.Value("CnProfession") == "管道安装工程") { newElectrodeRecoveryItem.CnProfession = "1"; } else if (values.Value("CnProfession") == "钢结构安装工程") { newElectrodeRecoveryItem.CnProfession = "2"; } else if (values.Value("CnProfession") == "仪表安装工程") { newElectrodeRecoveryItem.CnProfession = "3"; } if (values.Value("Equipment") == "管道") { newElectrodeRecoveryItem.Equipment = "1"; } else if (values.Value("Equipment") == "钢结构") { newElectrodeRecoveryItem.Equipment = "2"; } else if (values.Value("Equipment") == "仪表") { newElectrodeRecoveryItem.Equipment = "3"; } var mat = Funs.DB.Base_Consumables.FirstOrDefault(x => x.ConsumablesName == values.Value("WMT_MatName")); if (mat != null) { newElectrodeRecoveryItem.WMT_ID = mat.ConsumablesId; } //newElectrodeRecoveryItem.RecipientsCount = Funs.GetNewIntOrZero(values.Value("RecipientsCount")); //newElectrodeRecoveryItem.ElectrodeRecoveryModel = values.Value("ElectrodeRecoveryModel"); //newElectrodeRecoveryItem.ElectrodeGrade = values.Value("ElectrodeGrade"); //newElectrodeRecoveryItem.BatchNumber = values.Value("BatchNumber"); //newElectrodeRecoveryItem.InLibCode = values.Value("InLibCode"); //newElectrodeRecoveryItem.Specifications = values.Value("Specifications"); //newElectrodeRecoveryItem.WelderCode = values.Value("WelderCode"); //newElectrodeRecoveryItem.UseSite = values.Value("UseSite"); //newElectrodeRecoveryItem.WeldingMaterial = values.Value("WeldingMaterial"); //newElectrodeRecoveryItem.RecipientsCount = Funs.GetNewIntOrZero(values.Value("RecipientsCount")); newElectrodeRecoveryItem.RecoveryCount = Funs.GetNewDecimalOrZero(values.Value("RecoveryCount")); //newElectrodeRecoveryItem.GrantMan = values.Value("GrantMan"); //newElectrodeRecoveryItem.GrantMan = this.CurrUser.UserId; BLL.HJGL_ElectrodeRecoveryService.AddElectrodeRecoveryItem(newElectrodeRecoveryItem); if (!string.IsNullOrEmpty(newElectrodeRecoveryItem.WMT_ID) && type == BLL.Const.BtnAuditing) { decimal count = 0; if (newElectrodeRecoveryItem.RecipientsCount.HasValue) { count = count - newElectrodeRecoveryItem.RecipientsCount.Value; } if (newElectrodeRecoveryItem.RecoveryCount.HasValue) { count = count + newElectrodeRecoveryItem.RecoveryCount.Value; } BLL.HJGL_EMInventoryRecordsService.UpdateEMInventoryRecords(this.CurrUser.LoginProjectId, newElectrodeRecovery.UnitId,newElectrodeRecoveryItem.WMT_ID, newElectrodeRecoveryItem.ElectrodeRecoveryModel, newElectrodeRecoveryItem.Specifications, count); } } } #endregion } }