xinjiang/SGGL/FineUIPro.Web/HJGL/WeldingManage/WeldReportEdit.aspx.cs

575 lines
26 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.WeldingManage
{
public partial class WeldReportEdit : PageBase
{
#region
/// <summary>
/// 焊接日报主键
/// </summary>
public string DReportID
{
get
{
return (string)ViewState["DReportID"];
}
set
{
ViewState["DReportID"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.DReportID = Request.Params["DReportID"];
///焊接区域
this.drpCodeName.DataTextField = "Text";
this.drpCodeName.DataValueField = "Text";
this.drpCodeName.DataSource = BLL.DropListService.HJGL_JointArea();
this.drpCodeName.DataBind();
///焊口属性
this.drpJointAttribute.DataTextField = "Text";
this.drpJointAttribute.DataValueField = "Value";
this.drpJointAttribute.DataSource = BLL.DropListService.HJGL_JointAttribute();
this.drpJointAttribute.DataBind();
///焊接位置
this.drpLocation.DataTextField = "Text";
this.drpLocation.DataValueField = "Value";
this.drpLocation.DataSource = BLL.DropListService.HJGL_JOT_LocationItem();
this.drpLocation.DataBind();
//this.SetDailyReportNo(null, null);
List<Model.View_JointInfo> GetWeldReportItem = BLL.WeldReportService.GetDistinctWeldReportItem(this.DReportID);
this.BindGrid(GetWeldReportItem); // 初始化页面
this.PageInfoLoad(); // 加载页面
}
}
#endregion
#region
/// <summary>
/// 加载页面输入提交信息
/// </summary>
private void PageInfoLoad()
{
if (!string.IsNullOrEmpty(this.CurrUser.UnitId))
{
this.hdUnitId.Text = this.CurrUser.UnitId;
//this.txtUnitName.Text = BLL.UnitService.GetUnitNameByUnitId(this.CurrUser.UnitId);
}
if (!string.IsNullOrEmpty(this.CurrUser.UserId))
{
this.hdUserId.Text = this.CurrUser.UserId;
this.txtUserName.Text = BLL.UserService.GetUserNameByUserId(this.CurrUser.UserId);
}
//BLL.Project_InstallationService.InitInstallationListDownList(this.drpInstallation, this.CurrUser.LoginProjectId, this.CurrUser.UnitId, true);
//this.drpInstallation.SelectedValue = BLL.Const._Null;
this.drpUnit.Items.Clear();
var pUnit = BLL.UnitService.GetUnitByProjectIdUnitTypeList(this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_2);
if (pUnit != null)
{
this.drpUnit.DataTextField = "UnitName";
this.drpUnit.DataValueField = "UnitId";
this.drpUnit.DataSource = pUnit;
this.drpUnit.DataBind();
this.drpUnit.SelectedValue = this.hdUnitId.Text;
if (this.CurrUser.UnitId != Const.UnitId_TCC && this.CurrUser.UserId != Const.hfnbdId)
{
this.drpUnit.Enabled = false;
}
}
BLL.Project_InstallationService.InitInstallationListDownList(this.drpInstallation, this.CurrUser.LoginProjectId, this.drpUnit.SelectedValue, true);
this.drpInstallation.SelectedValue = BLL.Const._Null;
///盖面焊工
this.drpCellWelderCode.Items.Clear();
///打底焊工
this.drpFloorWelderCode.Items.Clear();
if (this.drpUnit.SelectedValue != BLL.Const._Null)
{
drpCellWelderCode.DataTextField = "Text";
drpCellWelderCode.DataValueField = "Value";
drpCellWelderCode.DataSource = BLL.WelderService.GetWelderCodeListByProjectIdAndUnitId(this.CurrUser.LoginProjectId, this.drpUnit.SelectedValue);
drpCellWelderCode.DataBind();
drpFloorWelderCode.DataTextField = "Text";
drpFloorWelderCode.DataValueField = "Value";
drpFloorWelderCode.DataSource = BLL.WelderService.GetWelderCodeListByProjectIdAndUnitId(this.CurrUser.LoginProjectId, this.drpUnit.SelectedValue);
drpFloorWelderCode.DataBind();
}
var report = BLL.WeldReportService.GetWeldReportByDReportID(this.DReportID);
if (report != null)
{
//this.txtDailyReportNo.Text = report.JOT_DailyReportNo;
if (!string.IsNullOrEmpty(report.UnitId))
{
this.hdUnitId.Text = report.UnitId;
//this.txtUnitName.Text = BLL.UnitService.GetUnitNameByUnitId(report.UnitId);
}
if (!string.IsNullOrEmpty(report.CHT_Tabler))
{
this.hdUserId.Text = report.CHT_Tabler;
this.txtUserName.Text = BLL.UserService.GetUserNameByUserId(report.CHT_Tabler);
}
if (!string.IsNullOrEmpty(report.InstallationId))
{
this.drpInstallation.SelectedValue = report.InstallationId;
}
this.hdDailyReportNo.Text = report.JOT_DailyReportNo;
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;
}
else
{
this.SimpleForm1.Reset(); ///重置所有字段
this.txtJOT_WeldDate.Text = string.Format("{0:yyyy-MM-dd}", System.DateTime.Now);
this.txtCHT_TableDate.Text = string.Format("{0:yyyy-MM-dd}", System.DateTime.Now);
}
/////制单人
//this.drpCHT_Tabler.DataTextField = "UserName";
//this.drpCHT_Tabler.DataValueField = "UserId";
//this.drpCHT_Tabler.DataSource = BLL.UserService.GetProjectUserListByProjectId(this.CurrUser.LoginProjectId);
//this.drpCHT_Tabler.DataBind();
//Funs.FineUIPleaseSelect(this.drpCHT_Tabler);
//if (this.CurrUser.UserId != Const.sysglyId && this.CurrUser.UserId != BLL.Const.hfnbdId)
//{
// this.drpCHT_Tabler.SelectedValue = this.CurrUser.UserId;
//}
//BLL.Project_InstallationService.InitInstallationsDropDownList(this.drpInstallation, this.CurrUser.LoginProjectId, true);
//if (report != null)
//{
//if (!string.IsNullOrEmpty(report.CHT_Tabler))
//{
// var tabler = this.drpCHT_Tabler.Items.FirstOrDefault(x => x.Value == report.CHT_Tabler);
// if (tabler != null)
// {
// this.drpCHT_Tabler.SelectedValue = report.CHT_Tabler;
// }
//}
//this.drpUnit.SelectedValue = report.UnitId;
//if (!string.IsNullOrEmpty(report.UnitId))
//{
// drpCellWelderCode.DataTextField = "Text";
// drpCellWelderCode.DataValueField = "Value";
// drpCellWelderCode.DataSource = BLL.WelderService.GetWelderCodeListByProjectIdAndUnitId(this.CurrUser.LoginProjectId, this.drpUnit.SelectedValue);
// drpCellWelderCode.DataBind();
// drpFloorWelderCode.DataTextField = "Text";
// drpFloorWelderCode.DataValueField = "Value";
// drpFloorWelderCode.DataSource = BLL.WelderService.GetWelderCodeListByProjectIdAndUnitId(this.CurrUser.LoginProjectId, this.drpUnit.SelectedValue);
// drpFloorWelderCode.DataBind();
//}
//this.drpInstallation.SelectedValue = report.InstallationId;
//this.drpUnit.Enabled = false;
//}
}
#endregion
#region
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid(List<Model.View_JointInfo> GetWeldReportItem)
{
DataTable tb = this.LINQToDataTable(GetWeldReportItem);
// 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();
}
#endregion
#region
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
List<Model.View_JointInfo> GetWeldReportItem = this.CollectGridJointInfo();
this.BindGrid(GetWeldReportItem);
}
#endregion
#region
/// <summary>
/// 编辑焊接日报
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_WeldReportMenuId, Const.BtnSave))
{
//if (BLL.WeldReportService.IsExistDailyReportNO(this.txtDailyReportNo.Text, this.DReportID, this.CurrUser.LoginProjectId))
//{
// ShowNotify("日报编号已存在,请重新录入!", MessageBoxIcon.Warning);
// return;
//}
if (string.IsNullOrEmpty(this.txtJOT_WeldDate.Text) || this.drpInstallation.SelectedValue == BLL.Const._Null)
{
ShowNotify("装置、焊接日期不能为空!", MessageBoxIcon.Warning);
return;
}
List<Model.View_JointInfo> GetWeldReportItem = this.CollectGridJointInfo();
Model.BO_WeldReportMain newWeldReportMain = new Model.BO_WeldReportMain();
newWeldReportMain.ProjectId = this.CurrUser.LoginProjectId;
//newWeldReportMain.JOT_DailyReportNo = this.txtDailyReportNo.Text.Trim();
if (this.drpUnit.SelectedValue != BLL.Const._Null)
{
newWeldReportMain.UnitId = this.drpUnit.SelectedValue;
}
//if (!string.IsNullOrEmpty(this.CurrUser.UnitId))
//{
// newWeldReportMain.UnitId = this.CurrUser.UnitId;
//}
if (this.drpInstallation.SelectedValue != BLL.Const._Null&&!string.IsNullOrEmpty(this.drpInstallation.SelectedValue))
{
newWeldReportMain.InstallationId = this.drpInstallation.SelectedValue;
}
DateTime? weldDate = Funs.GetNewDateTime(this.txtJOT_WeldDate.Text);
if (weldDate.HasValue)
{
newWeldReportMain.JOT_WeldDate = weldDate.Value;
}
else
{
newWeldReportMain.JOT_WeldDate = System.DateTime.Now;
}
//if (this.drpCHT_Tabler.SelectedValue != BLL.Const._Null)
//{
// newWeldReportMain.CHT_Tabler = this.drpCHT_Tabler.SelectedValue;
//}
if (!string.IsNullOrEmpty(this.CurrUser.UserId))
{
newWeldReportMain.CHT_Tabler = this.CurrUser.UserId;
}
newWeldReportMain.CHT_TableDate = Funs.GetNewDateTime(this.txtCHT_TableDate.Text);
newWeldReportMain.JOT_Remark = this.txtJOT_Remark.Text.Trim();
if (!string.IsNullOrEmpty(this.DReportID))
{
newWeldReportMain.JOT_DailyReportNo = this.hdDailyReportNo.Text.Trim();
newWeldReportMain.DReportID = this.DReportID;
BLL.WeldReportService.UpdateWeldReport(newWeldReportMain);
BLL.LogService.AddSys_Log(this.CurrUser, newWeldReportMain.JOT_DailyReportNo, this.DReportID, BLL.Const.HJGL_WeldReportMenuId, "修改焊接日报信息");
}
else
{
#region
var workAreaCode = string.Empty;
var welderCode = string.Empty;
string jotId = GetWeldReportItem.FirstOrDefault().JOT_ID;
if (!string.IsNullOrEmpty(jotId))
{
var jotInfo = BLL.PW_JointInfoService.GetJointInfoByJotID(jotId);
if (jotInfo != null)
{
if (!string.IsNullOrEmpty(jotInfo.ISO_ID))
{
var isoInfo = BLL.PW_IsoInfoService.GetIsoInfoByIsoInfoId(jotInfo.ISO_ID);
if (isoInfo != null)
{
workAreaCode = BLL.WorkAreaService.GetWorkAreaCodeByWorkAreaId(isoInfo.WorkAreaId);
}
}
}
}
string welderId = GetWeldReportItem.FirstOrDefault().JOT_CellWelder;
if (!string.IsNullOrEmpty(welderId))
{
welderCode = BLL.WelderService.GetWelderById(welderId).WED_Code;
}
string perfix = workAreaCode + "-" + welderCode + "-";
newWeldReportMain.JOT_DailyReportNo = BLL.SQLHelper.RunProcNewId("SpGetNewCode5ByProjectId", "dbo.BO_WeldReportMain", "JOT_DailyReportNo", this.CurrUser.LoginProjectId, perfix);
#endregion
this.DReportID = SQLHelper.GetNewID(typeof(Model.BO_WeldReportMain));
newWeldReportMain.DReportID = this.DReportID;
BLL.WeldReportService.AddWeldReport(newWeldReportMain);
BLL.LogService.AddSys_Log(this.CurrUser, newWeldReportMain.JOT_DailyReportNo, this.DReportID, BLL.Const.HJGL_WeldReportMenuId, "添加焊接日报信息");
}
foreach (var item in GetWeldReportItem)
{
Model.PW_JointInfo jot = BLL.PW_JointInfoService.GetJointInfoByJotID(item.JOT_ID);
jot.DReportID = newWeldReportMain.DReportID;
jot.JOT_CellWelder = item.JOT_CellWelder;
jot.JOT_FloorWelder = item.JOT_FloorWelder;
jot.WLO_Code = item.WLO_Code == "安装" ? "F" : "S";
jot.JOT_JointAttribute = item.JOT_JointAttribute;
jot.JOT_Location = item.JOT_Location;
jot.JOT_DoneDin = item.JOT_DoneDin;
jot.JOT_Electricity = item.JOT_Electricity;
jot.JOT_Voltage = item.JOT_Voltage;
jot.JOT_JointStatus = "100";
jot.WeldingSpeed = item.WeldingSpeed;
jot.JOT_PrepareTemp = item.JOT_PrepareTemp;
jot.ActualPrepareTemp = item.ActualPrepareTemp;
jot.JOT_CellTemp = item.JOT_CellTemp;
jot.JOT_LastTemp = item.JOT_LastTemp;
BLL.PW_JointInfoService.UpdateJointInfoByDReport(jot);
//更新焊口号 修改固定焊口号后 +G
BLL.PW_JointInfoService.UpdateJointNoAddG(item.JOT_ID, item.JOT_JointAttribute, "Add");
}
ShowNotify("提交成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region Grid页面信息
/// <summary>
/// 收集Grid页面信息
/// </summary>
/// <returns></returns>
private List<Model.View_JointInfo> CollectGridJointInfo()
{
List<Model.View_JointInfo> GetWeldReportItem = null;
List<Model.View_JointInfo> getNewWeldReportItem = new List<Model.View_JointInfo>();
if (!string.IsNullOrEmpty(this.hdItemsString.Text))
{
GetWeldReportItem = BLL.WeldReportService.GetWeldReportAddItem(this.hdItemsString.Text);
}
else if (string.IsNullOrEmpty(this.hdItemsString.Text) && this.DReportID != null)
{
GetWeldReportItem = BLL.WeldReportService.GetDistinctWeldReportItem(this.DReportID);
}
JArray mergedData = Grid1.GetMergedData();
foreach (JObject mergedRow in mergedData)
{
string status = mergedRow.Value<string>("status");
JObject values = mergedRow.Value<JObject>("values");
string rowID = values.Value<string>("JOT_ID").ToString();
var item = GetWeldReportItem.FirstOrDefault(x => x.JOT_ID == rowID);
if (item != null)
{
var cellWelderCode = (from x in Funs.DB.BS_Welder
where x.ProjectId == this.CurrUser.LoginProjectId && x.WED_Code == values.Value<string>("WED_Code1")
select x).FirstOrDefault();
if (cellWelderCode != null)
{
item.WED_Code1 = cellWelderCode.WED_Code;
item.JOT_CellWelder = cellWelderCode.WED_ID;
}
var floorWelderCode = (from x in Funs.DB.BS_Welder
where x.ProjectId == this.CurrUser.LoginProjectId && x.WED_Code == values.Value<string>("WED_Code2")
select x).FirstOrDefault();
if (floorWelderCode != null)
{
item.WED_Code2 = floorWelderCode.WED_Code;
item.JOT_FloorWelder = floorWelderCode.WED_ID;
}
if (values.Value<string>("WLO_Code").ToString() == "安装")
{
item.WLO_Code = "安装";
}
else
{
item.WLO_Code = "预制";
}
item.JOT_JointAttribute = values.Value<string>("JOT_JointAttribute").ToString();
item.JOT_Location = values.Value<string>("JOT_Location").ToString();
item.JOT_DoneDin = Funs.GetNewDecimalOrZero(values.Value<string>("JOT_DoneDin").ToString());
item.JOT_Electricity = values.Value<string>("JOT_Electricity");
item.JOT_Voltage = values.Value<string>("JOT_Voltage");
item.WeldingSpeed = values.Value<string>("WeldingSpeed");
item.JOT_PrepareTemp = Funs.GetNewDecimal(values.Value<string>("JOT_PrepareTemp"));
item.ActualPrepareTemp = Funs.GetNewDecimal(values.Value<string>("ActualPrepareTemp"));
item.JOT_CellTemp = Funs.GetNewDecimal(values.Value<string>("JOT_CellTemp"));
item.JOT_LastTemp = Funs.GetNewDecimal(values.Value<string>("JOT_LastTemp"));
getNewWeldReportItem.Add(item);
}
}
return getNewWeldReportItem;
}
#endregion
#region Grid
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
List<string> list = Funs.GetStrListByStr(hdItemsString.Text, '#');
if (list.Count() == 2)
{
string welderLists = list[0];
List<string> welder = Funs.GetStrListByStr(welderLists, '|');
string jotLists = list[1];
List<string> jot = Funs.GetStrListByStr(jotLists, '|');
//if (welder.Count() > 0 && jot.Count() > 0)
//{
// this.SetDailyReportNo(jot[0], welder[0]);
//}
}
List<Model.View_JointInfo> GetWeldReportItem = BLL.WeldReportService.GetWeldReportAddItem(this.hdItemsString.Text);
this.BindGrid(GetWeldReportItem);
//SetDrpByDrpUnitChange();
//this.hdItemsString.Text = string.Empty;
}
#endregion
#region
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
List<Model.View_JointInfo> 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.JOT_ID == rowID);
if (item != null)
{
GetWeldReportItem.Remove(item);
}
Model.PW_JointInfo jot = BLL.PW_JointInfoService.GetJointInfoByJotID(rowID);
if (!string.IsNullOrEmpty(jot.DReportID))
{
jot.DReportID = null;
jot.JOT_CellWelder = null;
jot.JOT_FloorWelder = null;
jot.JOT_DoneDin = null;
jot.JOT_Electricity = null;
jot.JOT_Voltage = null;
jot.WeldingSpeed = null;
jot.JOT_PrepareTemp = null;
jot.ActualPrepareTemp = null;
jot.JOT_CellTemp = null;
jot.JOT_LastTemp = null;
BLL.PW_JointInfoService.UpdateJointInfoByDReport(jot);
}
}
BindGrid(GetWeldReportItem);
ShowNotify("操作完成!", MessageBoxIcon.Success);
}
}
#endregion
#region
/// <summary>
/// 查找未焊接焊口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ckSelect_Click(object sender, EventArgs e)
{
string jotIds = string.Empty;
for (int i = 0; i < Grid1.Rows.Count; i++)
{
string jotId = Grid1.DataKeys[i][0].ToString();
jotIds = jotIds + jotId + "|";
}
if (jotIds != string.Empty)
{
jotIds = jotIds.Substring(0, jotIds.Length - 1);
}
//if (!string.IsNullOrEmpty(this.drpUnit.SelectedValue) && this.drpUnit.SelectedValue != BLL.Const._Null)
if (!string.IsNullOrEmpty(this.CurrUser.UnitId) && this.drpInstallation.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpInstallation.SelectedValue))
{
string strList = this.CurrUser.LoginProjectId + "|" + this.drpUnit.SelectedValue + "|" + this.DReportID + "|" + this.drpInstallation.SelectedValue;
string window = String.Format("WeldReportItemEdit.aspx?strList={0}&jotIds={1}", strList, jotIds, "编辑 - ");
PageContext.RegisterStartupScript(Window1.GetSaveStateReference(hdItemsString.ClientID) + Window1.GetShowReference(window));
}
else
{
Alert.ShowInTop("请选择装置!", MessageBoxIcon.Warning);
}
}
#endregion
protected void drpUnit_SelectedIndexChanged(object sender, EventArgs e)
{
BLL.Project_InstallationService.InitInstallationListDownList(this.drpInstallation, this.CurrUser.LoginProjectId, this.drpUnit.SelectedValue, true);
this.drpInstallation.SelectedValue = BLL.Const._Null;
///盖面焊工
this.drpCellWelderCode.Items.Clear();
///打底焊工
this.drpFloorWelderCode.Items.Clear();
if (this.drpUnit.SelectedValue != BLL.Const._Null)
{
drpCellWelderCode.DataTextField = "Text";
drpCellWelderCode.DataValueField = "Value";
drpCellWelderCode.DataSource = BLL.WelderService.GetWelderCodeListByProjectIdAndUnitId(this.CurrUser.LoginProjectId, this.drpUnit.SelectedValue);
drpCellWelderCode.DataBind();
drpFloorWelderCode.DataTextField = "Text";
drpFloorWelderCode.DataValueField = "Value";
drpFloorWelderCode.DataSource = BLL.WelderService.GetWelderCodeListByProjectIdAndUnitId(this.CurrUser.LoginProjectId, this.drpUnit.SelectedValue);
drpFloorWelderCode.DataBind();
}
}
}
}