xinjiang/SGGL/FineUIPro.Web/HJGL/PersonManage/PersonItem.aspx.cs

308 lines
11 KiB
C#

using BLL;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
namespace FineUIPro.Web.HJGL.PersonManage
{
public partial class PersonItem : PageBase
{
#region
/// <summary>
/// 焊工id
/// </summary>
public string WED_ID
{
get
{
return (string)ViewState["WED_ID"];
}
set
{
ViewState["WED_ID"] = value;
}
}
/// <summary>
/// 焊接材质集合
/// </summary>
private static List<string> BS_SteelList = new List<string>();
/// <summary>
/// 焊接位置集合
/// </summary>
private static List<string> BS_WeldPositionList = new List<string>();
/// <summary>
/// 焊接方法集合
/// </summary>
private static List<string> BS_WeldMethodList = new List<string>();
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.WED_ID = Request.Params["welderId"];
var welder = BLL.WelderService.GetWelderById(this.WED_ID);
if (welder != null)
{
this.lbWelderName.Text = welder.WED_Name;
//焊接材质初始化
this.Tab2Load();
//焊接方法初始化
this.Tab4Load();
}
else
{
Alert.ShowInTop("焊工信息不正确!", MessageBoxIcon.Error);
}
}
}
#endregion
#region
#region
/// <summary>
/// 材质初始化
/// </summary>
protected void Tab2Load()
{
BS_SteelList = new List<string>();
var items = from x in Funs.DB.BS_WelderItem where x.WED_ID == this.WED_ID select x.STE_ID;
if (items.Count() > 0)
{
foreach (var item in items)
{
BS_SteelList.Add(item);
}
}
gvBS_SteelBindGrid();
}
#endregion
#region
/// <summary>
/// 绑定数据
/// </summary>
private void gvBS_SteelBindGrid()
{
string strSql = @"SELECT steel.STE_ID,STE_Code,STE_Name,STE_SteelType,STE_Remark,"
+ @" (CASE WHEN STE_SteelType='1' THEN '碳钢'
WHEN STE_SteelType='2' THEN '不锈钢'
WHEN STE_SteelType='3' THEN '鉻目钢'
WHEN STE_SteelType='4' THEN '低合金钢'
WHEN STE_SteelType='5' THEN '镍合金钢'
WHEN STE_SteelType='6' THEN '钛合金钢'
WHEN STE_SteelType='7' THEN '其他'
WHEN STE_SteelType='8' THEN '异种钢接头'
WHEN STE_SteelType='9' THEN '低温钢'
WHEN STE_SteelType='10' THEN '复合钢' END) AS STE_SteelTypeName,
item.ThicknessMax,
item.ThicknessMin,
item.SizesMax,
item.SizesMin"
+ @" FROM BS_Steel as steel"
+ @" left join BS_WelderItem as item on item.STE_ID = steel.STE_ID WHERE 1=1 ";
List<SqlParameter> listStr = new List<SqlParameter>();
if (!string.IsNullOrEmpty(this.txtSTE_Name.Text.Trim()))
{
strSql += " AND STE_Name LIKE @STE_Name";
listStr.Add(new SqlParameter("@STE_Name", "%" + this.txtSTE_Name.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.txtSTE_Code.Text.Trim()))
{
strSql += " AND STE_Code LIKE @STE_Code";
listStr.Add(new SqlParameter("@STE_Code", "%" + this.txtSTE_Code.Text.Trim() + "%"));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(gvBS_Steel, tb1);
gvBS_Steel.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(gvBS_Steel.FilteredData, tb);
var table = this.GetPagedDataTable(gvBS_Steel, tb);
gvBS_Steel.DataSource = table;
gvBS_Steel.DataBind();
if (BS_SteelList.Count() > 0)
{
List<string> lists = new List<string>();
for (int i = 0; i < gvBS_Steel.Rows.Count; i++)
{
string id = gvBS_Steel.DataKeys[i][0].ToString();
if (BS_SteelList.Contains(id))
{
lists.Add(id);
}
}
gvBS_Steel.SelectedRowIDArray = lists.ToArray();
}
}
#endregion
#region
/// <summary>
/// 焊接材质保存方法
/// </summary>
private void SaveTab2Data()
{
BLL.WelderItemService.DeleteItemByWenId(this.WED_ID);
foreach (var item in gvBS_Steel.SelectedRowIDArray)
{
Model.BS_WelderItem welderItem = new Model.BS_WelderItem();
welderItem.WEDItem_ID = SQLHelper.GetNewID(typeof(Model.BS_WelderItem));
welderItem.WED_ID = this.WED_ID;
welderItem.STE_ID = item;
//增加焊接壁厚、焊接尺寸
JArray EditorPMArr = gvBS_Steel.GetMergedData();
if (EditorPMArr.Count > 0)
{
JArray mergedData = gvBS_Steel.GetMergedData();
int i = 0;
foreach (JObject mergedRow in EditorPMArr)
{
string steId = gvBS_Steel.DataKeys[i][0].ToString();
JObject values = mergedRow.Value<JObject>("values");
if (steId == item)
{
welderItem.ThicknessMin = Funs.GetNewDecimal(values.Value<string>("ThicknessMin").ToString());
welderItem.ThicknessMax = Funs.GetNewDecimal(values.Value<string>("ThicknessMax").ToString());
welderItem.SizesMin = Funs.GetNewDecimal(values.Value<string>("SizesMin").ToString());
welderItem.SizesMax = Funs.GetNewDecimal(values.Value<string>("SizesMax").ToString());
}
i++;
}
}
BLL.WelderItemService.AddWelderItem(welderItem);
}
}
#endregion
#endregion
#region
#region
/// <summary>
/// 方法初始化
/// </summary>
protected void Tab4Load()
{
BS_WeldMethodList = new List<string>();
var items = from x in Funs.DB.BS_WeldMethodItem where x.WED_ID == this.WED_ID select x.WME_ID;
if (items.Count() > 0)
{
foreach (var item in items)
{
BS_WeldMethodList.Add(item);
}
}
gvBS_WeldMethodBindGrid();
}
#endregion
#region
/// <summary>
/// 绑定数据
/// </summary>
private void gvBS_WeldMethodBindGrid()
{
string strSql = @"SELECT WeldingMethodId,WeldingMethodCode,WeldingMethodName,Remark"
+ @" FROM [dbo].[Base_WeldingMethod] WHERE 1=1";
List<SqlParameter> listStr = new List<SqlParameter>();
if (!string.IsNullOrEmpty(this.txtWME_Name.Text.Trim()))
{
strSql += " AND WeldingMethodName LIKE @WME_Name";
listStr.Add(new SqlParameter("@WME_Name", "%" + this.txtWME_Name.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.txtWME_Code.Text.Trim()))
{
strSql += " AND WeldingMethodCode LIKE @WME_Code";
listStr.Add(new SqlParameter("@WME_Code", "%" + this.txtWME_Code.Text.Trim() + "%"));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(gvBS_WeldMethod, tb1);
gvBS_WeldMethod.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(gvBS_WeldMethod.FilteredData, tb);
var table = this.GetPagedDataTable(gvBS_WeldMethod, tb);
gvBS_WeldMethod.DataSource = table;
gvBS_WeldMethod.DataBind();
if (BS_WeldMethodList.Count() > 0)
{
List<string> lists = new List<string>();
for (int i = 0; i < gvBS_WeldMethod.Rows.Count; i++)
{
string id = gvBS_WeldMethod.DataKeys[i][0].ToString();
if (BS_WeldMethodList.Contains(id))
{
lists.Add(id);
}
}
gvBS_WeldMethod.SelectedRowIDArray = lists.ToArray();
}
}
#endregion
#region
/// <summary>
/// 焊接方法保存方法
/// </summary>
private void SaveTab4Data()
{
BLL.WeldMethodItemService.DeleteWeldMethodItem(this.WED_ID);
foreach (var item in gvBS_WeldMethod.SelectedRowIDArray)
{
Model.BS_WeldMethodItem weldMethodItem = new Model.BS_WeldMethodItem();
weldMethodItem.WeldMethodItemId = SQLHelper.GetNewID(typeof(Model.BS_WeldMethodItem));
weldMethodItem.WED_ID = this.WED_ID;
weldMethodItem.WME_ID = item;
BLL.WeldMethodItemService.AddWeldMethodItem(weldMethodItem);
}
}
#endregion
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
/// 焊接材质保存方法
this.SaveTab2Data();
/// 焊接方法保存方法
this.SaveTab4Data();
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.gvBS_SteelBindGrid();
this.gvBS_WeldMethodBindGrid();
}
#endregion
}
}