ZHJA_HJGL/HJGL_ZH/FineUIPro.Web/HJGL/RepairManage/RepairManageEdit.aspx.cs

641 lines
25 KiB
C#

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.RepairManage
{
public partial class RepairManageEdit : PageBase
{
#region
/// <summary>
/// 返修委托主键
/// </summary>
public string CH_RepairID
{
get
{
return (string)ViewState["CH_RepairID"];
}
set
{
ViewState["CH_RepairID"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.drpIsProjectClosed.DataTextField = "Text";
this.drpIsProjectClosed.DataValueField = "Value";
this.drpIsProjectClosed.DataSource = BLL.DropListService.IsTrueOrFalseDrpList();
this.drpIsProjectClosed.DataBind();
Funs.FineUIPleaseSelect(this.drpIsProjectClosed);
this.drpIsProjectClosed.SelectedValue = BLL.Const._False;
var projects = BLL.Base_ProjectService.GetProjectListByUserIdAndState(this.CurrUser.UserId, this.drpIsProjectClosed.SelectedValue, "1");
RadioButtonList1.DataTextField = "ProjectCode";
RadioButtonList1.DataValueField = "ProjectId";
RadioButtonList1.DataSource = projects;
RadioButtonList1.DataBind();
this.drpNdtType.DataTextField = "NDT_Code";
this.drpNdtType.DataValueField = "NDT_ID";
this.drpNdtType.DataSource = BLL.HJGL_TestingService.GetNDTTypeNameList();
this.drpNdtType.DataBind();
Funs.FineUIPleaseSelect(this.drpNdtType);
this.drpIsPrint.DataTextField = "Text";
this.drpIsPrint.DataValueField = "Value";
this.drpIsPrint.DataSource = BLL.DropListService.IsTrueOrFalseDrpList();
this.drpIsPrint.DataBind();
Funs.FineUIPleaseSelect(this.drpIsPrint);
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
this.InitTreeMenu();//加载树
}
}
#endregion
#region
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
this.tvControlItem.Nodes.Clear();
TreeNode rootNode = new TreeNode();
rootNode.Text = "项目-月份-委托单号";
rootNode.ToolTip = "项目";
rootNode.NodeID = "0";
rootNode.Expanded = true;
this.tvControlItem.Nodes.Add(rootNode);
List<Model.HJGL_CH_Repair> trustLists = new List<Model.HJGL_CH_Repair>();
string selectProjectIds = String.Join("|", DropDownBox1.Values); //选择显示的项目
List<Model.Base_Project> projects = BLL.Base_ProjectService.GetProjectListByUserIdAndState(this.CurrUser.UserId, this.drpIsProjectClosed.SelectedValue, "1");
if (CurrUser.Account == Const.Gly)
{
//projects=
}
if (selectProjectIds.Length > 6) //勾选了显示项目
{
projects = projects.Where(x => selectProjectIds.Contains(x.ProjectId)).ToList();
}
foreach (var item in projects)
{
TreeNode rootProjectNode = new TreeNode();//定义根节点
rootProjectNode.Text = item.ProjectCode;
rootProjectNode.NodeID = item.ProjectId;
rootProjectNode.Expanded = true;
rootProjectNode.ToolTip = "项目名称";
rootNode.Nodes.Add(rootProjectNode);
trustLists = (from x in Funs.DB.HJGL_CH_Repair
where x.ProjectId == item.ProjectId //&& x.CH_TrustType == "1"
select x).ToList();
// 筛选关闭的批
if (this.drpIsPrint.SelectedValue != "null")
{
if (Convert.ToBoolean(drpIsPrint.SelectedValue))
{
trustLists = (from x in trustLists where x.CH_PrintDate != null select x).ToList();
}
else
{
trustLists = (from x in trustLists where x.CH_PrintDate == null select x).ToList();
}
}
// 筛选探伤类型
if (this.drpNdtType.SelectedValue != "null")
{
trustLists = (from x in trustLists where x.NDT_ID == drpNdtType.SelectedValue select x).ToList();
}
this.BindNodes(rootProjectNode, trustLists);
}
}
#endregion
#region
/// <summary>
/// 绑定树节点
/// </summary>
/// <param name="node"></param>
private void BindNodes(TreeNode node, List<Model.HJGL_CH_Repair> trustLists)
{
if (node.ToolTip == "项目名称")
{
var trustMonth = (from x in trustLists select string.Format("{0:yyyy-MM}", x.RepairTrustDate)).Distinct();
foreach (var item in trustMonth)
{
TreeNode newNode = new TreeNode();
newNode.Text = item;
newNode.NodeID = item + "|" + node.NodeID; ;
newNode.ToolTip = "月份";
node.Nodes.Add(newNode);
this.BindNodes(newNode, trustLists);
}
}
else if (node.ToolTip == "月份")
{
var dReports = from x in trustLists
where string.Format("{0:yyyy-MM}", x.RepairTrustDate) == node.Text
orderby x.CH_RepairNo descending
select x;
foreach (var item in dReports)
{
TreeNode newNode = new TreeNode();
if (!string.IsNullOrEmpty(item.CH_RepairNo))
{
newNode.Text = string.Format("{0:yyyy-MM-dd}", item.RepairTrustDate) + " " + item.CH_RepairNo;
}
else
{
newNode.Text = "未知";
}
newNode.NodeID = item.CH_RepairID;
newNode.EnableClickEvent = true;
node.Nodes.Add(newNode);
}
}
}
#endregion
#region TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
this.SetTextTemp();
this.CH_RepairID = tvControlItem.SelectedNodeID;
this.PageInfoLoad(); ///页面输入提交信息
e.Node.ParentNode.Expanded = true;
}
#endregion
#region
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid()
{
string strSql = @"SELECT repairItem.CH_RepairItemId
,repairItem.CH_RepairID
,repairItem.JOT_ID
,repair.NDT_ID
,repairItem.DefectNature
,repairItem.FilmNum
,IsoInfo.ISO_IsoNo
,(JointInfo.JOT_JointNo+repairRecord.RepairMark) AS JOT_JointNo
,repairRecord.RepairMark
,repairItem.Remark
,CAST(JointInfo.JOT_Dia AS Decimal(18,2)) AS JOT_Dia
,JointInfo.JOT_Sch
,JointInfo.WLO_Code
,WeldMethod.WME_Name
,batch.BatchCode
,JointInfo.Sort1,JointInfo.Sort2,JointInfo.Sort3,JointInfo.Sort4,JointInfo.Sort5
FROM HJGL_CH_RepairItem AS repairItem
LEFT JOIN dbo.HJGL_CH_Repair AS repair ON repair.CH_RepairID = repairItem.CH_RepairID
LEFT JOIN dbo.HJGL_CH_RepairItemRecord AS repairRecord ON repairRecord.RepairItemRecordId = repairItem.RepairItemRecordId
LEFT JOIN dbo.HJGL_PW_JointInfo AS JointInfo ON JointInfo.JOT_ID = repairItem.JOT_ID
LEFT JOIN dbo.HJGL_PW_IsoInfo AS IsoInfo ON JointInfo.ISO_ID = IsoInfo.ISO_ID
LEFT JOIN dbo.HJGL_BS_WeldMethod AS WeldMethod ON WeldMethod.WME_ID=JointInfo.WME_ID
LEFT JOIN dbo.HJGL_BO_Batch AS batch ON batch.BatchId = repair.BatchId
WHERE 1=1";
List<SqlParameter> listStr = new List<SqlParameter>();
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
{
strSql += " AND repairItem.CH_RepairID = @CH_RepairID";
listStr.Add(new SqlParameter("@CH_RepairID", this.tvControlItem.SelectedNodeID));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#region
/// <summary>
/// 加载页面输入提交信息
/// </summary>
private void PageInfoLoad()
{
var repair = BLL.HJGL_RepairService.GetCH_RepairByID(this.CH_RepairID);
if (repair != null)
{
this.txtCH_RepairNo.Text = repair.CH_RepairNo;
if (!string.IsNullOrEmpty(repair.CH_TrustUnit))
{
var unit = BLL.Base_UnitService.GetUnit(repair.CH_TrustUnit);
if (unit != null)
{
this.drpCH_TrustUnit.Text = unit.UnitName;
}
}
if (!string.IsNullOrEmpty(repair.InstallationId))
{
var install = BLL.Project_InstallationService.GetInstallationByInstallationId(repair.InstallationId);
if (install != null)
{
this.drpInstallationId.Text = install.InstallationName;
}
}
this.txtCH_TrustType.Text = repair.CH_TrustType == "1" ? "委托" : "扩透";
this.txtRepairTrustDate.Text = string.Format("{0:yyyy-MM-dd}", repair.RepairTrustDate);
if (repair.CH_PrintDate != null)
{
ckbIsPrint.Checked = true;
this.lbPrintDate.Text = repair.CH_PrintDate.Value.ToString();
this.lbPrinter.Text = repair.CH_Printer.Trim();
}
if (!string.IsNullOrEmpty(repair.CH_Tabler))
{
var hotHardMan = BLL.Sys_UserService.GetUsersByUserId(repair.CH_Tabler);
if (hotHardMan != null)
{
this.drpCH_Tabler.Text = hotHardMan.UserName;
}
}
if (!string.IsNullOrEmpty(repair.CH_CheckUnit))
{
var checkUnit = BLL.Base_UnitService.GetUnit(repair.CH_CheckUnit);
if (checkUnit != null)
{
this.drpCH_CheckUnit.Text = checkUnit.UnitName;
}
}
if (!string.IsNullOrEmpty(repair.BatchId))
{
var batch = BLL.HJGL_BO_BatchService.GetBatchById(repair.BatchId);
if (batch != null)
{
if (!string.IsNullOrEmpty(batch.NDTR_ID))
{
var ndt = BLL.HJGL_DetectionService.GetNDTRateByNDTRID(batch.NDTR_ID);
if (ndt != null)
{
this.drpCH_NDTRate.Text = ndt.NDTR_Name;
}
}
}
}
if (!string.IsNullOrEmpty(repair.NDT_ID))
{
var test = BLL.HJGL_TestingService.GetTestingByTestingId(repair.NDT_ID);
if (test != null)
{
this.drpCH_NDTMethod.Text = test.NDT_Name;
}
}
if (!string.IsNullOrEmpty(repair.CH_AcceptGrade))
{
var acceptGrade = BLL.HJGL_TrustManageEditService.GetAcceptGradeList().FirstOrDefault(x => x.Value == repair.CH_AcceptGrade);
if (acceptGrade != null)
{
this.drpCH_AcceptGrade.Text = acceptGrade.Text;
}
}
this.txtCH_NDTCriteria.Text = repair.CH_NDTCriteria;
this.txtCH_ItemName.Text = repair.CH_ItemName;
if (!string.IsNullOrEmpty(repair.CH_SlopeType))
{
var slopeType = BLL.HJGL_GrooveService.GetSlopeTypeByJSTID(repair.CH_SlopeType);
if (slopeType != null)
{
this.drpCH_SlopeType.Text = slopeType.JST_Name;
}
}
if (!string.IsNullOrEmpty(repair.CH_WeldMethod))
{
var weldMethod = BLL.HJGL_WeldingMethodService.GetWeldMethodByWMEID(repair.CH_WeldMethod);
if (weldMethod != null)
{
this.drpCH_WeldMethod.Text = weldMethod.WME_Name;
}
}
this.txtCH_Remark.Text = repair.CH_Remark;
BindGrid();
}
}
#endregion
#region
/// <summary>
/// 清空文本框
/// </summary>
private void SetTextTemp()
{
this.txtCH_RepairNo.Text = string.Empty;
this.drpCH_TrustUnit.Text = string.Empty;
this.drpInstallationId.Text = string.Empty;
this.txtCH_TrustType.Text = string.Empty;
this.txtRepairTrustDate.Text = string.Empty;
this.drpCH_Tabler.Text = string.Empty;
this.lbPrintDate.Text = string.Empty;
this.lbPrinter.Text = string.Empty;
this.drpCH_CheckUnit.Text = string.Empty;
this.drpCH_NDTRate.Text = string.Empty;
this.drpCH_NDTMethod.Text = string.Empty;
this.drpCH_AcceptGrade.Text = string.Empty;
this.txtCH_NDTCriteria.Text = string.Empty;
this.txtCH_ItemName.Text = string.Empty;
this.drpCH_SlopeType.Text = string.Empty;
this.drpCH_WeldMethod.Text = string.Empty;
this.txtCH_Remark.Text = string.Empty;
}
#endregion
#endregion
#region
#region
/// <summary>
/// 页索引改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 分页选择下拉改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
#endregion
#endregion
#region
#region
/// <summary>
/// 编辑返修委托
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnEdit_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_RepairManageEditMenuId, Const.BtnSave))
{
var repair = BLL.HJGL_RepairService.GetCH_RepairByID(this.CH_RepairID);
if (repair != null)
{
string window = String.Format("RepairManageItemEdit.aspx?RepairID={0}", this.CH_RepairID, "编辑 - ");
PageContext.RegisterStartupScript(Window1.GetSaveStateReference(this.hdCH_RepairID.ClientID)
+ Window1.GetShowReference(window));
}
else
{
Alert.ShowInTop("请选择要修改的返修委托记录!", MessageBoxIcon.Warning);
}
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
#endregion
#region
/// <summary>
/// 删除返修委托
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDelete_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_RepairManageEditMenuId, Const.BtnDelete))
{
var repair = BLL.HJGL_RepairService.GetCH_RepairByID(this.CH_RepairID);
if (repair != null)
{
BLL.HJGL_RepairItemService.DeleteCH_RepairItemByCH_RepairID(this.CH_RepairID);
BLL.HJGL_RepairService.DeleteRepairByCH_RepairID(this.CH_RepairID);
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除返修委托");
ShowNotify("删除成功!", MessageBoxIcon.Success);
this.InitTreeMenu();
this.PageInfoLoad();
}
else
{
Alert.ShowInTop("请选择要删除的返修委托记录!", MessageBoxIcon.Warning);
}
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#endregion
#region
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
this.CH_RepairID = this.hdCH_RepairID.Text;
this.InitTreeMenu();//加载树
this.PageInfoLoad();
this.tvControlItem.SelectedNodeID = this.CH_RepairID;
if (this.tvControlItem.SelectedNode.ParentNode != null)
{
this.tvControlItem.SelectedNode.ParentNode.Expanded = true;
}
this.hdCH_RepairID.Text = string.Empty;
}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//protected void Tree_TextChanged(object sender, EventArgs e)
//{
// this.InitTreeMenu();
// this.PageInfoLoad();
//}
protected void drpNdtType_SelectedIndexChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
}
protected void drpIsPrint_SelectedIndexChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
}
#endregion
/// <summary>
/// 打印信息修改
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ckbIsPrint_OnCheckedChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.CH_RepairID))
{
Model.HJGL_CH_Repair repair = BLL.HJGL_RepairService.GetCH_RepairByID(this.CH_RepairID);
if (ckbIsPrint.Checked)
{
repair.CH_PrintDate = DateTime.Now.Date;
repair.CH_Printer = this.CurrUser.UserName;
}
else
{
repair.CH_PrintDate = null;
repair.CH_Printer = null;
}
BLL.HJGL_RepairService.PrintCH_Repair(repair);
this.SetTextTemp();
this.PageInfoLoad();
}
else
{
Alert.ShowInTop("请选择委托单", MessageBoxIcon.Information);
return;
}
}
#region
/// <summary>
/// 报表打印
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnPrint_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
{
Model.HJGL_CH_Repair repair = BLL.HJGL_RepairService.GetCH_RepairByID(this.CH_RepairID);
repair.CH_PrintDate = DateTime.Now.Date;
repair.CH_Printer = this.CurrUser.UserName;
BLL.HJGL_RepairService.PrintCH_Repair(repair);
this.SetTextTemp();
this.PageInfoLoad();
string projectId = string.Empty;
string project = tvControlItem.SelectedNode.ParentNode.NodeID;
if (!string.IsNullOrEmpty(project))
{
string[] ps = project.Split('|');
if (ps.Count() > 1)
{
projectId = ps[1];
}
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.HJGL_RepairReportId, this.tvControlItem.SelectedNodeID, null, "打印 - ")));
}
else
{
Alert.ShowInTop("请选择委托单", MessageBoxIcon.Information);
return;
}
}
protected void btnPrint2_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.tvControlItem.SelectedNodeID))
{
Model.HJGL_CH_Repair repair = BLL.HJGL_RepairService.GetCH_RepairByID(this.CH_RepairID);
repair.CH_PrintDate = DateTime.Now.Date;
repair.CH_Printer = this.CurrUser.UserName;
BLL.HJGL_RepairService.PrintCH_Repair(repair);
this.SetTextTemp();
this.PageInfoLoad();
string projectId = string.Empty;
string project = tvControlItem.SelectedNode.ParentNode.NodeID;
if (!string.IsNullOrEmpty(project))
{
string[] ps = project.Split('|');
if (ps.Count() > 1)
{
projectId = ps[1];
}
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId=0", BLL.Const.HJGL_SubUnitRepairReportId, this.tvControlItem.SelectedNodeID, null, "打印 - ")));
}
else
{
Alert.ShowInTop("请选择委托单", MessageBoxIcon.Information);
return;
}
}
#endregion
protected void drpIsProjectClosed_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownBox1.Values = new string[0];
DropDownBox1.Text = string.Empty;
var projects = BLL.Base_ProjectService.GetProjectListByUserIdAndState(this.CurrUser.UserId, this.drpIsProjectClosed.SelectedValue, "1");
RadioButtonList1.DataTextField = "ProjectCode";
RadioButtonList1.DataValueField = "ProjectId";
RadioButtonList1.DataSource = projects;
RadioButtonList1.DataBind();
this.InitTreeMenu();
}
protected void DropDownBox1_TextChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
}
}
}