ZHJA_HJGL/HJGL_ZH/FineUIPro.Web/HJGL/WeldingManage/WeldReport.aspx.cs

592 lines
23 KiB
C#
Raw Normal View History

2024-05-08 17:17:11 +08:00
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.WeldingManage
{
public partial class WeldReport : PageBase
{
#region
/// <summary>
/// 焊接日报主键
/// </summary>
public string DReportID
{
get
{
return (string)ViewState["DReportID"];
}
set
{
ViewState["DReportID"] = value;
}
}
/// <summary>
/// 项目ID
/// </summary>
public string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
this.DReportID = string.Empty;
this.txtReportDate.Text = string.Format("{0:yyyy-MM}", System.DateTime.Now);
this.drpProject.DataTextField = "ProjectCode";
this.drpProject.DataValueField = "ProjectId";
this.drpProject.DataSource = BLL.Base_ProjectService.GetProjectListByUserId(this.CurrUser.UserId, "1");
this.drpProject.DataBind();
this.drpProject.SelectedValue = this.CurrUser.LoginProjectId;
this.InitTreeMenu();//加载树
}
}
#endregion
#region --
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
this.tvControlItem.Nodes.Clear();
if (string.IsNullOrEmpty(this.txtReportDate.Text.Trim()))
{
ShowNotify("请选择日报月份!", MessageBoxIcon.Warning);
return;
}
TreeNode rootNode = new TreeNode();
rootNode.Text = "月份-日期-日报号";
rootNode.NodeID = "0";
rootNode.ToolTip = "月份";
rootNode.Expanded = true;
this.tvControlItem.Nodes.Add(rootNode);
DateTime startTime = Funs.GetNewDateTime(this.txtReportDate.Text.Trim()).Value;
DateTime endTime = startTime.AddMonths(1);
var days = (from x in Funs.DB.HJGL_BO_WeldReportMain
where x.JOT_WeldDate >= startTime && x.JOT_WeldDate < endTime
&& x.ProjectId == this.drpProject.SelectedValue
orderby x.JOT_WeldDate descending
select x.JOT_WeldDate).Distinct();
foreach (var item in days)
{
TreeNode newNode = new TreeNode();
newNode.Text = string.Format("{0:yyyy-MM-dd}", item);
newNode.NodeID = item.ToString() + "|" + rootNode.NodeID;
newNode.ToolTip = "日期";
newNode.EnableExpandEvent = true;
rootNode.Nodes.Add(newNode);
TreeNode tn = new TreeNode();
tn.NodeID = "temp";
tn.Text = "正在加载...";
newNode.Nodes.Add(tn);
}
//this.BindNodes(rootNode, startTime, endTime, this.drpProject.SelectedValue);
}
#endregion
#region
/// <summary>
/// 绑定树节点
/// </summary>
/// <param name="node"></param>
private void BindNodes(TreeNode node, string projectId)
{
if (node.ToolTip == "日期")
{
var dReports = from x in Funs.DB.HJGL_BO_WeldReportMain
where x.JOT_WeldDate == Funs.GetNewDateTime(node.Text)
&& x.ProjectId == projectId
orderby x.JOT_DailyReportNo descending
select x;
foreach (var item in dReports)
{
TreeNode newNode = new TreeNode();
if (!string.IsNullOrEmpty(item.JOT_DailyReportNo))
{
newNode.Text = item.JOT_DailyReportNo;
}
else
{
newNode.Text = "未知";
}
if (String.IsNullOrEmpty(this.IsDelete(item.DReportID)))
{
newNode.Text = "<font color='#FF7575'>" + newNode.Text + "</font>";
node.Text = "<font color='#FF7575'>" + node.Text + "</font>";
node.ToolTip = "该日报下焊口所在批已关闭或已做热处理,不能删除";
node.ParentNode.Text = "<font color='#FF7575'>" + node.ParentNode.Text + "</font>";
}
newNode.NodeID = item.DReportID;
newNode.EnableClickEvent = true;
node.Nodes.Add(newNode);
}
}
}
#endregion
#region
/// <summary>
/// 得到是否热处理
/// </summary>
/// <param name="bigType"></param>
/// <returns></returns>
protected string ConvertISProess(object JOT_ID)
{
string iSProess = string.Empty;
if (JOT_ID != null)
{
Model.HJGL_PW_JointInfo joint = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(JOT_ID.ToString());
if (joint != null)
{
if (joint.IS_Proess == "1")
{
iSProess = "是";
}
else if (joint.IS_Proess == "0")
{
iSProess = "否";
}
}
}
return iSProess;
}
#endregion
#region TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
this.DReportID = tvControlItem.SelectedNodeID;
if (DReportID != null)
{
var report = BLL.HJGL_WeldReportService.GetWeldReportByDReportID(DReportID);
this.ProjectId = report.ProjectId;
this.BindGrid();
this.CalculationAmount();
}
}
/// <summary>
///
/// </summary>
private void CalculationAmount()
{
this.lbAmountInfo.Text = string.Empty;
DateTime? date = Funs.GetNewDateTime(this.txtJOT_WeldDate.Text);
if (date.HasValue)
{
var jots = BLL.HJGL_PW_JointInfoService.GetJointInfoByDReportId(this.DReportID);
foreach (var item in jots)
{
decimal? dn = BLL.HJGL_PW_JointInfoService.GetWelderDN(this.CurrUser.LoginProjectId, item.JOT_CellWelder, date.Value);
if (dn != null)
{
this.lbAmountInfo.Text = string.Format("{0:0.##}", dn);
}
}
}
}
protected void tvControlItem_NodeExpand(object sender, TreeNodeEventArgs e)
{
if (e.Node.Nodes != null)
{
e.Node.Nodes.Clear();
}
this.BindNodes(e.Node, this.drpProject.SelectedValue);
}
#endregion
#region
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid()
{
this.PageInfoLoad(); ///页面输入提交信息
string strSql = @"SELECT JointInfo.JOT_ID,JointInfo.JOT_JointNo,IsoInfo.ISO_IsoNo,NDTRate.NDTR_Name,
CellWelder.WED_Code AS JOT_CellWelderCode,FloorWelder.WED_Code AS JOT_FloorWelderCode,
(CASE WHEN JointInfo.WLO_Code ='F' THEN '' ELSE '' END) AS WLO_CodeName,
JointInfo.JOT_JointAttribute,JointInfo.JOT_Location,JointInfo.JOT_Size,JointInfo.JOT_DoneDin,
JointInfo.JOT_Dia,JointInfo.JOT_Sch,WeldMethod.WME_Name,WeldMat.WMT_MatCode AS WeldMatCode,WeldSilk.WMT_MatCode AS WeldSilkCode
FROM HJGL_PW_JointInfo AS JointInfo
LEFT JOIN HJGL_PW_IsoInfo AS IsoInfo ON JointInfo.ISO_ID =IsoInfo.ISO_ID
LEFT JOIN HJGL_BS_NDTRate AS NDTRate ON JointInfo.NDTR_ID =NDTRate.NDTR_ID
LEFT JOIN HJGL_BS_Welder AS CellWelder ON JointInfo.JOT_CellWelder =CellWelder.WED_ID
LEFT JOIN HJGL_BS_Welder AS FloorWelder ON JointInfo.JOT_FloorWelder =FloorWelder.WED_ID
LEFT JOIN HJGL_BS_WeldMethod AS WeldMethod ON WeldMethod.WME_ID = JointInfo.WME_ID
LEFT JOIN HJGL_BS_WeldMaterial AS WeldMat ON WeldMat.WMT_ID=JointInfo.JOT_WeldMat
LEFT JOIN HJGL_BS_WeldMaterial AS WeldSilk ON WeldSilk.WMT_ID=JointInfo.JOT_WeldSilk
WHERE JointInfo.DReportID=@DReportID";
List<SqlParameter> listStr = new List<SqlParameter>();
//listStr.Add(new SqlParameter("@ProjectId", this.ProjectId));
listStr.Add(new SqlParameter("@DReportID", this.DReportID));
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()
{
this.btnEdit.Hidden = true;
this.btnDelete.Hidden = true;
this.SimpleForm1.Reset(); ///重置所有字段
var report = BLL.HJGL_WeldReportService.GetWeldReportByDReportID(this.DReportID);
if (report != null)
{
this.txtDReportID.Text = report.JOT_DailyReportNo;
if (!string.IsNullOrEmpty(report.BSU_ID))
{
var unit = BLL.Base_UnitService.GetUnit(report.BSU_ID);
if (unit != null)
{
this.drpUnit.Text = unit.UnitName;
}
}
if (!string.IsNullOrEmpty(report.InstallationId))
{
var install = BLL.Project_InstallationService.GetInstallationByInstallationId(report.InstallationId);
if (install != null)
{
this.drpInstall.Text = install.InstallationName;
}
}
if (!string.IsNullOrEmpty(report.CHT_Tabler))
{
var tabler = BLL.Sys_UserService.GetUsersByUserId(report.CHT_Tabler);
if (tabler != null)
{
this.drpCHT_Tabler.Text = tabler.UserName;
}
}
this.txtJOT_WeldDate.Text = string.Format("{0:yyyy-MM-dd}", report.JOT_WeldDate);
this.txtCHT_TableDate.Text = string.Format("{0:yyyy-MM-dd}", report.CHT_TableDate);
this.txtJOT_Remark.Text = report.JOT_Remark;
this.btnDelete.Hidden = false;
if (String.IsNullOrEmpty(this.IsDelete(report.DReportID)))
{
this.btnEdit.Hidden = false;
}
}
}
#endregion
#endregion
/// <summary>
/// 判断是否可删除
/// </summary>
/// <returns></returns>
private string IsDelete(string dReportID)
{
string isDeleteInfo = string.Empty;
// 判断页面信息是否能修改 是否已点口
var infos = from x in Funs.DB.HJGL_PW_JointInfo where x.DReportID == dReportID select x;
if (infos.Count() > 0)
{
string massage = string.Empty;
foreach (var item in infos)
{
var batchDetail = BLL.HJGL_BO_BatchDetailService.GetBatchDetailByJotId(item.JOT_ID);
if (batchDetail != null)
{
var batch = BLL.HJGL_BO_BatchService.GetBatchById(batchDetail.BatchId);
if (batch != null && batch.BatchIsClosed == true)
{
massage += "焊口号:" + item.JOT_JointNo + ";所在批号:" + batch.BatchCode;
}
}
}
if (!string.IsNullOrEmpty(massage))
{
isDeleteInfo += "该日报下焊口所在批已关闭!" + massage;
}
}
////是否已做热处理
var hotProessItem = from x in Funs.DB.View_HotProessItem where x.DReportID == dReportID && x.HotProessId != null select x;
if (hotProessItem.Count() > 0)
{
string hotMassage = string.Empty;
foreach (var itemHot in hotProessItem)
{
hotMassage += "焊口号:" + itemHot.JOT_JointNo;
var dr = Funs.DB.HJGL_HotProess.FirstOrDefault(x => x.HotProessId == itemHot.HotProessId);
if (dr != null)
{
hotMassage += ";热处理单号:" + dr.HotProessNo;
}
}
isDeleteInfo += "该日报下焊口已做热处理!" + hotMassage;
}
return isDeleteInfo;
}
#region
#region
/// <summary>
/// 页索引改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
#endregion
#region
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
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
/// <summary>
/// 增加焊接日报
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_WeldReportMenuId, Const.BtnAdd))
{
string window = String.Format("WeldReportEdit.aspx?DReportID={0}", string.Empty, "新增 - ");
PageContext.RegisterStartupScript(Window1.GetSaveStateReference(this.hdDReportID.ClientID)
+ Window1.GetShowReference(window));
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
#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_WeldReportMenuId, Const.BtnSave))
{
if (!String.IsNullOrEmpty(this.IsDelete(this.DReportID)))
{
ShowNotify("已使用单据不能修改!", MessageBoxIcon.Warning);
return;
}
var weldReport = BLL.HJGL_WeldReportService.GetWeldReportByDReportID(this.DReportID);
if (weldReport != null)
{
string window = String.Format("WeldReportEdit.aspx?DReportID={0}", this.DReportID, "编辑 - ");
PageContext.RegisterStartupScript(Window1.GetSaveStateReference(this.hdDReportID.ClientID)
+ Window1.GetShowReference(window));
}
else
{
ShowNotify("请先选择日报!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", 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_WeldReportMenuId, Const.BtnDelete))
{
string info = this.IsDelete(this.DReportID);
if (!String.IsNullOrEmpty(info))
{
Alert.ShowInTop(info, MessageBoxIcon.Warning);
return;
}
if (!string.IsNullOrEmpty(this.DReportID))
{
List<Model.HJGL_PW_JointInfo> jointInfos = BLL.HJGL_PW_JointInfoService.GetJointInfosByDReportID(this.DReportID);
if (jointInfos.Count() > 0)
{
foreach (var item in jointInfos)
{
item.DReportID = null;
item.JOT_CellWelder = null;
item.JOT_FloorWelder = null;
item.JOT_DoneDin = null;
BLL.HJGL_PW_JointInfoService.UpdateJointInfoByDReport(item);
// 更新焊口号 删除固定焊口号后 +G
BLL.HJGL_PW_JointInfoService.UpdateJointNoAddG(item.JOT_ID, item.JOT_JointAttribute, Const.Delete);
// 删除批明细
BLL.HJGL_BO_BatchDetailService.DeleteBatchDetail(item.JOT_ID);
}
}
BLL.HJGL_WeldReportService.DeleteWeldReportByDReportID(this.DReportID);
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除焊接日报");
Alert.ShowInTop("删除成功!", MessageBoxIcon.Success);
this.InitTreeMenu();
this.BindGrid();
}
else
{
ShowNotify("请先选择日报!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", 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.DReportID = this.hdDReportID.Text;
this.BindGrid();
this.InitTreeMenu();
this.hdDReportID.Text = string.Empty;
this.CalculationAmount();
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Tree_TextChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
this.BindGrid();
}
protected void drpProject_SelectedIndexChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 日报表打印
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnPrint_Click(object sender, EventArgs e)
{
//if (!string.IsNullOrEmpty(this.DReportID))
//{
// string varValue = string.Empty;
// varValue = this.drpInstall.Text + "|" + this.drpUnit.Text;
// var project = BLL.Base_ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
// if (project != null)
// {
// varValue += "|" + project.ProjectName;
// }
// if (string.IsNullOrEmpty(varValue))
// {
// varValue = Microsoft.JScript.GlobalObject.escape(varValue.Replace("/", ","));
// }
// varValue = "a|b|c";
// PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../Common/ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId={3}", BLL.Const.HJGL_JointReportDayReportId, this.DReportID, varValue, this.CurrUser.LoginProjectId, "打印 - ")));
//}
//else
//{
// ShowNotify("请选择日报告!", MessageBoxIcon.Warning);
// return;
//}
}
#endregion
}
}