using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Data; using BLL; namespace FineUIPro.Web.WeldMat.BaseInfo { public partial class WeldInfo : PageBase { #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); //焊材类型 this.drpWeldTypeId.DataTextField = "WeldTypeName"; this.drpWeldTypeId.DataValueField = "WeldTypeId"; this.drpWeldTypeId.DataSource = BLL.WeldTypeService.GetWeldTypeList(); this.drpWeldTypeId.DataBind(); Funs.FineUIPleaseSelect(this.drpWeldTypeId); // 钢材类型 this.ddlSteelType.DataTextField = "Text"; this.ddlSteelType.DataValueField = "Value"; this.ddlSteelType.DataSource = BLL.DropListService.HJGL_GetSteTypeList(); this.ddlSteelType.DataBind(); Funs.FineUIPleaseSelect(this.ddlSteelType); Funs.FineUIPleaseSelect(this.drpWeldSpec); // 绑定表格 BindGrid(); } } #endregion #region 绑定数据 /// /// 绑定数据 /// private void BindGrid() { string strSql = @"SELECT WeldInfo.WeldId, WeldInfo.WeldCode, WeldInfo.WeldName, WeldInfo.WeldSpec,WeldInfo.SteelType, WeldInfo.ConvertValue, WeldInfo.WarnAmount,WeldInfo.WeldTypeId,WeldType.WeldTypeName, WeldType.WeldUnit, c.UserName AS CreateMan,m.UserName AS ModifyMan FROM Weld_WeldInfo AS WeldInfo LEFT JOIN Weld_WeldType AS WeldType ON WeldType.WeldTypeId =WeldInfo.WeldTypeId LEFT JOIN dbo.Sys_User c ON c.UserId=WeldInfo.CreateMan LEFT JOIN dbo.Sys_User m ON m.UserId=WeldInfo.ModifyMan WHERE 1=1 "; List listStr = new List(); if (!string.IsNullOrEmpty(this.txtCode.Text.Trim())) { strSql += " AND WeldCode LIKE @WeldCode"; listStr.Add(new SqlParameter("@WeldCode", "%" + this.txtCode.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtName.Text.Trim())) { strSql += " AND WeldName LIKE @WeldName"; listStr.Add(new SqlParameter("@WeldName", "%" + this.txtName.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_WeldInfoMenuId, Const.BtnDelete)) { if (judgementDelete(hfFormID.Text, true)) { BLL.WeldInfoService.DeleteWeldInfoById(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_WeldInfoMenuId, 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.WeldInfoService.DeleteWeldInfoById(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_WeldInfoMenuId, 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 weldInfo = BLL.WeldInfoService.GetWeldInfoById(Id); if (weldInfo != null) { this.txtWeldCode.Text = weldInfo.WeldCode; this.txtWeldName.Text = weldInfo.WeldName; if (!string.IsNullOrEmpty(weldInfo.WeldTypeId)) { this.drpWeldTypeId.SelectedValue = weldInfo.WeldTypeId; Model.Weld_WeldType weldType = BLL.WeldTypeService.GetWeldTypeById(this.drpWeldTypeId.SelectedValue); if (weldType != null) { this.txtWeldUnit.Text = weldType.WeldUnit; } //规格 this.drpWeldSpec.Items.Clear(); this.drpWeldSpec.DataTextField = "Specifications"; this.drpWeldSpec.DataValueField = "SpecificationsId"; this.drpWeldSpec.DataSource = BLL.SpecificationsService.GetSpecificationsByWeldTypeId(weldInfo.WeldTypeId); this.drpWeldSpec.DataBind(); Funs.FineUIPleaseSelect(this.drpWeldSpec); if (!string.IsNullOrEmpty(weldInfo.WeldSpec)) { var spec = BLL.SpecificationsService.GetSpecificationsByWeldTypeIdSpec(weldInfo.WeldTypeId, weldInfo.WeldSpec); if (spec!=null) { this.drpWeldSpec.SelectedValue = spec.SpecificationsId; } } } if (!string.IsNullOrEmpty(weldInfo.SteelType)) { ddlSteelType.SelectedValue = weldInfo.SteelType; } if (weldInfo.ConvertValue.HasValue) { this.txtConvertValue.Text = weldInfo.ConvertValue.ToString(); } if (weldInfo.WarnAmount.HasValue) { this.txtWarnAmount.Text = weldInfo.WarnAmount.ToString(); } hfFormID.Text = Id; this.btnDelete.Enabled = true; } } #endregion #region Grid行点击事件 /// /// Grid行点击事件 /// /// /// protected void Grid1_RowClick(object sender, GridRowClickEventArgs e) { this.EditData(); } #endregion #region 提交按钮 /// /// 提交按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.CLGL_WeldInfoMenuId, Const.BtnSave)) { string strRowID = hfFormID.Text; if (BLL.WeldInfoService.IsExitWeld(this.txtWeldName.Text.Trim(),this.drpWeldSpec.SelectedText, strRowID)) { Alert.ShowInTop("此焊材的牌号和规格已存在!", MessageBoxIcon.Warning); return; } if (this.drpWeldTypeId.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择焊材类型!", MessageBoxIcon.Warning); return; } if (this.drpWeldSpec.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择焊材规格!", MessageBoxIcon.Warning); return; } if (ddlSteelType.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择钢材类型!", MessageBoxIcon.Warning); return; } Model.Weld_WeldInfo weld = new Model.Weld_WeldInfo(); weld.WeldCode = this.txtWeldCode.Text.Trim(); weld.WeldName = this.txtWeldName.Text.Trim(); weld.WeldSpec = this.drpWeldSpec.SelectedText; //weld.WeldSpec = this.txtWeldSpec.Text.Trim(); if (this.drpWeldTypeId.SelectedValue != BLL.Const._Null) { weld.WeldTypeId = this.drpWeldTypeId.SelectedValue; } if (ddlSteelType.SelectedValue != BLL.Const._Null) { weld.SteelType = ddlSteelType.SelectedValue; } weld.ConvertValue = Funs.GetNewDecimal(this.txtConvertValue.Text.Trim()); weld.WarnAmount = 20; //if (this.txtWarnAmount.Text.Trim() != "") //{ // weld.WarnAmount = Funs.GetNewDecimal(this.txtWarnAmount.Text.Trim()); //} //else //{ // weld.WarnAmount = 20; //} if (string.IsNullOrEmpty(strRowID)) { strRowID = SQLHelper.GetNewID(typeof(Model.Weld_WeldInfo)); weld.WeldId = strRowID; weld.CreateMan = CurrUser.UserId; BLL.WeldInfoService.AddWeldInfo(weld); BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "添加焊材信息"); } else { weld.WeldId = strRowID; weld.ModifyMan = CurrUser.UserId; BLL.WeldInfoService.UpdateWeldInfo(weld); 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.ProjectPlanService.GetProjectPlanNumByWeldId(id) > 0) { content = "项目计划中已经使用了该焊材,不能删除!"; } if (BLL.StockInitService.GetStockInitByWeldId(id) > 0) { content = "库存初始化中已经使用了该焊材,不能删除!"; } if (BLL.StockInService.GetStockInByWeldId(id) > 0) { content = "焊材入库录入中已经使用了该焊材,不能删除!"; } if (BLL.UsingPlanService.GetUsingPlanByWeldId(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 DropDownList下拉选择事件 /// /// 焊材类型下拉框选择时间 /// /// /// protected void drpWeldTypeId_SelectedIndexChanged(object sender, EventArgs e) { this.drpWeldSpec.Items.Clear(); if (this.drpWeldTypeId.SelectedValue != BLL.Const._Null) { var weldType = BLL.WeldTypeService.GetWeldTypeById(this.drpWeldTypeId.SelectedValue); if (weldType != null) { this.txtWeldUnit.Text = weldType.WeldUnit; } else { this.txtWeldUnit.Text = string.Empty; } //this.drpWeldSpec.DataTextField = "ConstText"; //this.drpWeldSpec.DataValueField = "ConstValue"; //if (this.drpWeldTypeId.SelectedText == "焊丝") //{ // this.drpWeldSpec.DataSource = BLL.ConstValue.drpConstItemList(BLL.ConstValue.Group_WeldStick); //} //else if (this.drpWeldTypeId.SelectedText == "焊条") //{ // this.drpWeldSpec.DataSource = BLL.ConstValue.drpConstItemList(BLL.ConstValue.Group_Electrode); //} //else if (this.drpWeldTypeId.SelectedText == "焊带") //{ // this.drpWeldSpec.DataSource = BLL.ConstValue.drpConstItemList(BLL.ConstValue.Group_WeldingTape); //} //else if (this.drpWeldTypeId.SelectedText == "焊剂") //{ // this.drpWeldSpec.DataSource = BLL.ConstValue.drpConstItemList(BLL.ConstValue.Group_WeldSold); //} //this.drpWeldSpec.DataBind(); //Funs.FineUIPleaseSelect(this.drpWeldSpec); this.drpWeldSpec.DataTextField = "Specifications"; this.drpWeldSpec.DataValueField = "SpecificationsId"; this.drpWeldSpec.DataSource = BLL.SpecificationsService.GetSpecificationsByWeldTypeId(this.drpWeldTypeId.SelectedValue); this.drpWeldSpec.DataBind(); Funs.FineUIPleaseSelect(this.drpWeldSpec); this.drpWeldSpec.SelectedIndex = 0; } else { this.txtWeldUnit.Text = string.Empty; Funs.FineUIPleaseSelect(this.drpWeldSpec); this.drpWeldSpec.SelectedIndex = 0; } } #endregion #region 导入 /// /// 导入 /// /// /// protected void btnIn_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.CLGL_WeldInfoMenuId, Const.BtnIn)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeldInfoIn.aspx", "导入 - "))); } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } #endregion #region 弹出编辑窗口关闭事件 /// /// 弹出编辑窗体关闭事件 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #endregion } }