using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using BLL;
namespace FineUIPro.Web.HJGL.WeldingManage
{
public partial class MatchedProcedureMaterial : PageBase
{
#region 加载页面
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
// 绑定表格
BindGrid();
}
}
///
/// 绑定数据
///
private void BindGrid()
{
string strSql = "SELECT MatchedProcedureMaterial.MatchedProcedureMaterialId"
+ @",MatchedProcedureMaterial.ProjectId"
+ @",MatchedProcedureMaterial.STE_ID1"
+ @",MatchedProcedureMaterial.STE_Name1"
+ @",MatchedProcedureMaterial.STE_ID2"
+ @",MatchedProcedureMaterial.STE_Name2"
+ @",MatchedProcedureMaterial.MaterialClass1"
+ @",MatchedProcedureMaterial.MaterialClass2"
+ @",MatchedProcedureMaterial.MaterialGroup1"
+ @",MatchedProcedureMaterial.MaterialGroup2"
+ @",MatchedProcedureMaterial.Specifications"
+ @",MatchedProcedureMaterial.WeldingMethodId"
+ @",MatchedProcedureMaterial.WME_Name"
+ @",MatchedProcedureMaterial.Thickness"
+ @",MatchedProcedureMaterial.Dia"
+ @",MatchedProcedureMaterial.IsHotTreatment"
+ @",MatchedProcedureMaterial.IsHotTreatmentName"
+ @",MatchedProcedureMaterial.WeldingProcedureId"
+ @",MatchedProcedureMaterial.WeldingPosition"
+ @",MatchedProcedureMaterial.WeldingProcedureCode"
+ @",MatchedProcedureMaterial.EvaluationCriteria"
+ @",MatchedProcedureMaterial.WeldingProcessCardId"
+ @",MatchedProcedureMaterial.WeldingProcessCardCode"
+ @",MatchedProcedureMaterial.State"
+ @",MatchedProcedureMaterial.Remark"
+ @" FROM HJGL_View_MatchedProcedureMaterial AS MatchedProcedureMaterial "
+ @" WHERE 1=1 ";
List listStr = new List();
if (!string.IsNullOrEmpty(this.txtSteels.Text.Trim()))
{
strSql += " AND (MatchedProcedureMaterial.STE_Name1 LIKE @Steels) OR (MatchedProcedureMaterial.STE_Name2 LIKE @Steels) ";
listStr.Add(new SqlParameter("@Steels", "%" + this.txtSteels.Text.Trim() + "%"));
}
if (this.rbState.SelectedValue == "0")
{
strSql += " AND MatchedProcedureMaterial.WeldingProcedureId is null ";
}
else
{
strSql += " AND MatchedProcedureMaterial.WeldingProcedureId is not null";
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
#region 表头过滤
protected void Grid1_FilterChange(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region 页索引改变事件
///
/// 页索引改变事件
///
///
///
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
#endregion
#region 排序
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
#endregion
#region 分页选择下拉改变事件
///
/// 分页选择下拉改变事件
///
///
///
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
#endregion
#region 弹出编辑窗口关闭事件
///
/// 弹出编辑窗体关闭事件
///
///
///
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#endregion
#region 查询
///
/// 查询
///
///
///
protected void TextBox_TextChanged(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region 匹配/未匹配筛选事件
///
/// 匹配/未匹配选择事件
///
///
///
protected void rbState_SelectedIndexChanged(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region 工艺评定匹配
///
/// 双击Grid事件
///
///
///
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
///
/// 编辑按钮
///
///
///
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
this.EditData();
}
///
/// 编辑数据方法
///
private void EditData()
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string id = Grid1.SelectedRowID;
if (!string.IsNullOrEmpty(id))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SelectWeldingProcedure.aspx?MatchedProcedureMaterialId={0}", id, "编辑 - ")));
}
}
#endregion
#region 删除
///
/// 右键删除事件
///
///
///
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
this.DeleteData();
}
///
/// 删除方法
///
private void DeleteData()
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_MatchedProcedureMaterialMenuId, BLL.Const.BtnDelete))
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
bool isShow = false;
if (Grid1.SelectedRowIndexArray.Length == 1)
{
isShow = true;
}
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
if (this.judgementDelete(rowID, isShow))
{
var matchprocedure = BLL.HJGL_MatchedProcedureMaterialService.GetMatchedProcedureMaterialById(rowID);
if (matchprocedure != null && string.IsNullOrEmpty(matchprocedure.WeldingProcedureId))
{
BLL.HJGL_MatchedProcedureMaterialService.DeleteMatchedProcedureMaterialById(rowID);
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除材料匹配工艺评定");
}
else
{
Alert.ShowInTop("已匹配工艺评定的节点不能删除!");
return;
}
}
}
this.BindGrid();
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
}
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
///
/// 判断是否可删除
///
///
///
///
private bool judgementDelete(string rowID, bool isShow)
{
string content = string.Empty;
if (string.IsNullOrEmpty(content))
{
return true;
}
else
{
if (isShow)
{
Alert.ShowInTop(content);
}
return false;
}
}
#endregion
}
}