using System; using System.Collections.Generic; using System.Data; using System.Web.UI; using BLL; using System.Linq; namespace FineUIPro.Web.HJGL.Match { public partial class MatchSet : PageBase { #region 定义项 /// /// 选择字符串 /// public List listSelects { get { return (List)ViewState["listSelects"]; } set { ViewState["listSelects"] = value; } } #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.listSelects = new List(); this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); this.BindGrid(); ////初始化页面 } } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid() { List toDoMatterList = BLL.HJGL_Match_PipeMaterialService.GetViewMatchPipeMaterial(this.CurrUser.LoginProjectId, this.rbMatch.SelectedValue); DataTable tb = this.LINQToDataTable(toDoMatterList); // 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(); } /// /// 对GV 赋值 /// /// private void ShowGridItem() { for (int i = 0; i < Grid1.Rows.Count; i++) { Grid1.Rows[i].Values[0] = BLL.Const._False; ////操作点口焊口信息 foreach (var items in listSelects) { if (items == Grid1.DataKeys[i][0].ToString()) { Grid1.Rows[i].Values[0] = BLL.Const._True; } } } } #endregion #region 分页排序 #region 页索引改变事件 /// /// 页索引改变事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { this.CollectGridJointInfo(); this.BindGrid(); this.ShowGridItem(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { this.CollectGridJointInfo(); this.BindGrid(); this.ShowGridItem(); } #endregion #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); this.CollectGridJointInfo(); this.BindGrid(); this.ShowGridItem(); } #endregion #endregion #region 组成件匹配 提交事件 /// /// 编辑组成件匹配 /// /// /// protected void btnGenerate_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_MatchSetMenuId, Const.BtnSave)) { this.CollectGridJointInfo(); if (listSelects.Count == 0) { Alert.ShowInTop("请选择材料匹配结果", MessageBoxIcon.Warning); return; } var viewList = BLL.HJGL_Match_PipeMaterialService.GetViewMatchPipeMaterialList(); ////生成出料单 Model.HJGL_Match_OutStorage newOutStorage = new Model.HJGL_Match_OutStorage(); newOutStorage.OutStorageId = BLL.SQLHelper.GetNewID(typeof(Model.HJGL_Match_OutStorage)); string date = string.Format("{0:yyyy-MM-dd}", System.DateTime.Now).Replace("-", ""); newOutStorage.OutStorageCode = BLL.SQLHelper.RunProcNewIdByProjectId("SpGetNewCode3ByProjectId", "HJGL_Match_OutStorage", "OutStorageCode", this.CurrUser.LoginProjectId, date + "-"); newOutStorage.ProjectId = this.CurrUser.LoginProjectId; newOutStorage.UnitId = this.CurrUser.UnitId; newOutStorage.OutTime = System.DateTime.Now; newOutStorage.CompileMan = this.CurrUser.UserId; Funs.DB.HJGL_Match_OutStorage.InsertOnSubmit(newOutStorage); Funs.DB.SubmitChanges(); ////循环所勾选的列表项 foreach (var itemId in listSelects) { var viewItem = viewList.FirstOrDefault(x => x.PipeMaterialId == itemId); if (viewItem != null) { var pipeMaterial = Funs.DB.HJGL_Match_PipeMaterial.FirstOrDefault(x => x.PipeMaterialId == viewItem.PipeMaterialId); if (pipeMaterial != null) { if (pipeMaterial.UsedCount.HasValue) { pipeMaterial.UsedCount += viewItem.MatchCount; ////回写管线材料表 已领用数量 } else { pipeMaterial.UsedCount = viewItem.MatchCount; ////回写管线材料表 已领用数量 } Funs.DB.SubmitChanges(); } ////生成出料单明细 Model.HJGL_Match_OutStorageItem newOutStorageItem = new Model.HJGL_Match_OutStorageItem(); newOutStorageItem.OutStorageItemId = BLL.SQLHelper.GetNewID(typeof(Model.HJGL_Match_OutStorageItem)); newOutStorageItem.OutStorageId = newOutStorage.OutStorageId; newOutStorageItem.MaterialId = viewItem.MaterialId; newOutStorageItem.ISO_ID = viewItem.ISO_ID; newOutStorageItem.OutCount = viewItem.MatchCount; Funs.DB.HJGL_Match_OutStorageItem.InsertOnSubmit(newOutStorageItem); Funs.DB.SubmitChanges(); ////回写库存表 var storage = Funs.DB.HJGL_Match_Storage.FirstOrDefault(x => x.MaterialId == viewItem.MaterialId); if (storage != null) { if (storage.OutCount.HasValue) { storage.OutCount += viewItem.MatchCount; ////回写管线材料表 已领用数量 } else { storage.OutCount = viewItem.MatchCount; ////回写管线材料表 已领用数量 } BLL.HJGL_Match_StorageService.UpdateHJGL_Match_Storage(storage); } } } this.listSelects = new List(); this.BindGrid(); Alert.ShowInTop("已生成单号为:" + newOutStorage.OutStorageCode + "的出料单", MessageBoxIcon.Success); } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } #endregion #region 收集Grid页面信息 /// /// 收集Grid页面信息 /// /// private void CollectGridJointInfo() { for (int i = 0; i < Grid1.Rows.Count; i++) { string rowID = Grid1.DataKeys[i][0].ToString(); CheckBoxField checkField = (CheckBoxField)Grid1.FindColumn("ckbIsSelected"); if (listSelects != null && listSelects.Contains(rowID)) { listSelects.Remove(rowID); } if (checkField.GetCheckedState(i)) { listSelects.Add(rowID); } } } #endregion #region Grid 明细操作事件 /// /// 全选 /// /// /// protected void btnAllSelect_Click(object sender, EventArgs e) { for (int i = 0; i < Grid1.Rows.Count; i++) { string rowID = Grid1.DataKeys[i][0].ToString(); if (!listSelects.Contains(rowID)) { listSelects.Add(rowID); } } this.ShowGridItem(); } /// /// 全不选 /// /// /// protected void btnNoSelect_Click(object sender, EventArgs e) { for (int i = 0; i < Grid1.Rows.Count; i++) { string rowID = Grid1.DataKeys[i][0].ToString(); if (listSelects.Contains(rowID)) { listSelects.Remove(rowID); } } this.ShowGridItem(); } #endregion /// /// 匹配类型 /// /// /// protected void rbMatch_SelectedIndexChanged(object sender, EventArgs e) { this.listSelects = new List(); this.BindGrid(); } } }