using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using System.Data.SqlClient;
using System.Data;
namespace FineUIPro.Web.WeldMat.BaseInfo
{
public partial class Specifications : PageBase
{
#region 加载页面
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
//焊材类型(查询)
this.drpWeldTypeIdS.DataTextField = "WeldTypeName";
this.drpWeldTypeIdS.DataValueField = "WeldTypeId";
this.drpWeldTypeIdS.DataSource = BLL.WeldTypeService.GetWeldTypeList();
this.drpWeldTypeIdS.DataBind();
Funs.FineUIPleaseSelect(this.drpWeldTypeIdS);
//焊材类型
this.drpWeldTypeId.DataTextField = "WeldTypeName";
this.drpWeldTypeId.DataValueField = "WeldTypeId";
this.drpWeldTypeId.DataSource = BLL.WeldTypeService.GetWeldTypeList();
this.drpWeldTypeId.DataBind();
Funs.FineUIPleaseSelect(this.drpWeldTypeId);
// 绑定表格
BindGrid();
}
}
#endregion
#region 绑定数据
///
/// 绑定数据
///
private void BindGrid()
{
string strSql = @"SELECT spec.SpecificationsId, spec.Specifications, spec.WeldTypeId,WeldType.WeldTypeName,spec.Remark,
spec.MaxUsingNum,c.UserName AS CreateMan,m.UserName AS ModifyMan
FROM Weld_Specifications AS spec
LEFT JOIN Weld_WeldType AS WeldType ON WeldType.WeldTypeId = spec.WeldTypeId
LEFT JOIN dbo.Sys_User c ON c.UserId=spec.CreateMan
LEFT JOIN dbo.Sys_User m ON m.UserId=spec.ModifyMan
WHERE 1=1";
List listStr = new List();
if (this.drpWeldTypeIdS.SelectedValue!=BLL.Const._Null)
{
strSql += " AND Specifications.WeldTypeId = @WeldTypeId";
listStr.Add(new SqlParameter("@WeldTypeId", this.drpWeldTypeIdS.SelectedValue));
}
if (!string.IsNullOrEmpty(this.txtSpecificationsS.Text.Trim()))
{
strSql += " AND Specifications.Specifications LIKE @Specifications";
listStr.Add(new SqlParameter("@Specifications", "%" + this.txtSpecificationsS.Text.Trim() + "%"));
}
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();
}
#endregion
#region 分页排序
///
///
///
///
///
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
///
/// 分页下拉选择
///
///
///
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
///
///
///
///
///
protected void Grid1_FilterChange(object sender, EventArgs e)
{
BindGrid();
}
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
#endregion
#region 删除事件
///
/// 删除
///
///
///
protected void btnDelete_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.CLGL_SpecificationsMenuId, Const.BtnDelete))
{
if (judgementDelete(hfFormID.Text, true))
{
BLL.SpecificationsService.DeleteSpecificationsById(hfFormID.Text);
BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除规格");
// 重新绑定表格,并模拟点击[新增按钮]
BindGrid();
PageContext.RegisterStartupScript("onNewButtonClick();");
}
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
///
/// 右键删除事件
///
///
///
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.CLGL_SpecificationsMenuId, Const.BtnDelete))
{
this.DeleteData();
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
///
/// 删除方法
///
private void DeleteData()
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
bool isShow = true;
if (Grid1.SelectedRowIndexArray.Length > 1)
{
isShow = false;
}
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
if (judgementDelete(rowID, isShow))
{
BLL.SpecificationsService.DeleteSpecificationsById(rowID);
BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除规格设置");
ShowNotify("删除完成!", MessageBoxIcon.Success);
}
}
BindGrid();
PageContext.RegisterStartupScript("onNewButtonClick();");
}
}
#endregion
#region 编辑
///
/// 右键编辑事件
///
///
///
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.CLGL_SpecificationsMenuId, Const.BtnModify))
{
this.EditData();
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
///
/// 编辑数据方法
///
private void EditData()
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string Id = Grid1.SelectedRowID;
var specifications = BLL.SpecificationsService.GetSpecificationsById(Id);
if (specifications != null)
{
if (!string.IsNullOrEmpty(specifications.WeldTypeId))
{
this.drpWeldTypeId.SelectedValue = specifications.WeldTypeId;
}
this.txtSpecifications.Text = specifications.Specifications;
if (specifications.MaxUsingNum != null)
{
numMaxUsingNum.Text = specifications.MaxUsingNum.ToString();
}
this.txtRemark.Text = specifications.Remark;
hfFormID.Text = Id;
this.btnDelete.Enabled = true;
}
}
#endregion
#region 提交按钮
///
/// 提交按钮
///
///
///
protected void btnSave_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.CLGL_SpecificationsMenuId, Const.BtnSave))
{
string strRowID = hfFormID.Text;
if (this.drpWeldTypeId.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("焊材类型不能为空!", MessageBoxIcon.Warning);
return;
}
if (BLL.SpecificationsService.IsExitSpecifications(this.drpWeldTypeId.SelectedValue, this.txtSpecifications.Text.Trim(), strRowID))
{
Alert.ShowInTop("此规格已存在!", MessageBoxIcon.Warning);
return;
}
Model.Weld_Specifications specifications = new Model.Weld_Specifications();
specifications.WeldTypeId = this.drpWeldTypeId.SelectedValue;
specifications.Specifications = this.txtSpecifications.Text.Trim();
if (!string.IsNullOrEmpty(numMaxUsingNum.Text))
{
specifications.MaxUsingNum = Funs.GetNewDecimal(numMaxUsingNum.Text);
}
specifications.Remark = this.txtRemark.Text.Trim();
if (string.IsNullOrEmpty(strRowID))
{
strRowID = SQLHelper.GetNewID(typeof(Model.Weld_Specifications));
specifications.SpecificationsId = strRowID;
specifications.CreateMan = CurrUser.UserId;
BLL.SpecificationsService.AddSpecifications(specifications);
BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "添加规格设置");
}
else
{
specifications.SpecificationsId = strRowID;
specifications.ModifyMan = CurrUser.UserId;
BLL.SpecificationsService.UpdateSpecifications(specifications);
BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "修改规格设置");
}
// 重新绑定表格,并点击当前编辑或者新增的行
BindGrid();
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript("onNewButtonClick();");
//PageContext.RegisterStartupScript(String.Format("F('{0}').selectRow('{1}');", Grid1.ClientID, UnitQualitySort.UnitQualitySortId));
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region 判断是否可删除
///
/// 判断是否可以删除
///
///
private bool judgementDelete(string id, bool isShow)
{
string content = string.Empty;
//if (BLL.WeldInfoService.GetWeldInfoByWeldTypeId(id) > 0)
//{
// content = "焊材信息设置中已经使用了该焊材类型,不能删除!";
//}
if (string.IsNullOrEmpty(content))
{
return true;
}
else
{
if (isShow)
{
Alert.ShowInTop(content, MessageBoxIcon.Error);
}
return false;
}
}
#endregion
#region 查询
///
/// 查询
///
///
///
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#endregion
#region Grid行点击事件
///
/// Grid行点击事件
///
///
///
protected void Grid1_RowClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
#endregion
}
}