301 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			301 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C#
		
	
	
	
| using BLL;
 | |
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Data;
 | |
| using System.Data.SqlClient;
 | |
| using System.Linq;
 | |
| 
 | |
| namespace FineUIPro.Web.TestRun.DriverGoods
 | |
| {
 | |
|     public partial class GoodsBuy : PageBase
 | |
|     {
 | |
|         #region 加载页面
 | |
|         protected void Page_Load(object sender, EventArgs e)
 | |
|         {
 | |
|             if (!IsPostBack)
 | |
|             {
 | |
|                 GetButtonPower();
 | |
|                 InitTree();//加载类别树
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         #region 绑定方案类别
 | |
|         /// <summary>
 | |
|         /// 绑定方案树节点
 | |
|         /// </summary>
 | |
|         private void InitTree()
 | |
|         {
 | |
|             this.tvDataTypeInit.Nodes.Clear();
 | |
|             TreeNode node = new TreeNode();
 | |
|             node.Text = "开车物资材料管理";
 | |
|             node.NodeID = "0";
 | |
|             node.Expanded = true;
 | |
|             this.tvDataTypeInit.Nodes.Add(node);
 | |
|             var types = BLL.GoodsBuyService.GetBugType();
 | |
|             foreach (var q in types)
 | |
|             {
 | |
|                 TreeNode newNode = new TreeNode();
 | |
|                 newNode.ToolTip = q.Text;
 | |
|                 newNode.Text = q.Text;
 | |
|                 newNode.NodeID = q.Value;
 | |
|                 newNode.EnableExpandEvent = true;
 | |
|                 newNode.EnableClickEvent = true;
 | |
|                 node.Nodes.Add(newNode);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 展开树
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         //protected void trWBS_NodeExpand(object sender, TreeNodeEventArgs e)
 | |
|         //{
 | |
|         //    e.Node.Nodes.Clear();
 | |
|         //    var types = from x in Funs.DB.DriverPrepare_DriverDataType
 | |
|         //                where x.ProjectId == this.CurrUser.LoginProjectId && x.ParentId == e.Node.NodeID
 | |
|         //                select x;
 | |
|         //    if (types.Count() > 0)
 | |
|         //    {
 | |
|         //        foreach (var type in types)
 | |
|         //        {
 | |
|         //            TreeNode newNode = new TreeNode();
 | |
|         //            newNode.ToolTip = type.DriverDataTypeName;
 | |
|         //            newNode.Text = type.DriverDataTypeName;
 | |
|         //            newNode.NodeID = type.DriverDataTypeId;
 | |
|         //            newNode.EnableExpandEvent = true;
 | |
|         //            newNode.EnableClickEvent = true;
 | |
|         //            e.Node.Nodes.Add(newNode);
 | |
|         //            var childTypes = from x in Funs.DB.DriverPrepare_DriverDataType where x.ParentId == type.DriverDataTypeId select x;
 | |
|         //            if (childTypes.Count() > 0)
 | |
|         //            {
 | |
|         //                TreeNode temp = new TreeNode();
 | |
|         //                temp.Text = "";
 | |
|         //                temp.NodeID = "";
 | |
|         //                newNode.Nodes.Add(temp);
 | |
|         //            }
 | |
|         //        }
 | |
|         //    }
 | |
|         //}
 | |
|         #endregion
 | |
|         #endregion
 | |
| 
 | |
|         #region 树点击事件
 | |
|         /// <summary>
 | |
|         /// 资料库类别树点击事件
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void tvDataTypeInit_NodeCommand(object sender, TreeCommandEventArgs e)
 | |
|         {
 | |
|             BindGrid();
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 数据绑定
 | |
|         /// <summary>
 | |
|         /// 数据绑定
 | |
|         /// </summary>
 | |
|         public void BindGrid()
 | |
|         {
 | |
|             string strSql = @"SELECT chec.GoodsBuyId,chec.ProjectId,chec.Code,chec.BuyName,chec.BuyCode,"
 | |
|                               + @" chec.CompileMan,chec.ApprovalDate,chec.UnitCode,"
 | |
|                               + @" u.userName as CompileManName"
 | |
|                               + @" FROM DriverGoods_GoodsBuy chec "
 | |
|                               + @" left join sys_User u on u.userId = chec.CompileMan"
 | |
|                               + @" where chec.ProjectId=@ProjectId and chec.BuyCode=@BuyCode";
 | |
|             List<SqlParameter> listStr = new List<SqlParameter>();
 | |
|             listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
 | |
|             listStr.Add(new SqlParameter("@BuyCode", this.tvDataTypeInit.SelectedNodeID));
 | |
|             SqlParameter[] parameter = listStr.ToArray();
 | |
|             DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
 | |
|             Grid1.RecordCount = tb.Rows.Count;
 | |
|             tb = GetFilteredTable(Grid1.FilteredData, tb);
 | |
|             var table = GetPagedDataTable(Grid1, tb);
 | |
|             Grid1.DataSource = table;
 | |
|             Grid1.DataBind();
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 分页
 | |
|         /// <summary>
 | |
|         /// 分页索引事件
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
 | |
|         {
 | |
|             BindGrid();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 分页下拉框事件
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
 | |
|         {
 | |
|             Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
 | |
|             BindGrid();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 排序
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
 | |
|         {
 | |
|             Grid1.SortDirection = e.SortDirection;
 | |
|             Grid1.SortField = e.SortField;
 | |
|             BindGrid();
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 查询
 | |
|         /// <summary>
 | |
|         /// 查询
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param> 
 | |
|         protected void btnSearch_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             BindGrid();
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 关闭弹出窗口
 | |
|         /// <summary>
 | |
|         /// 关闭弹出窗口
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Window1_Close(object sender, WindowCloseEventArgs e)
 | |
|         {
 | |
|             InitTree();
 | |
|             BindGrid();
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 增加按钮
 | |
|         /// <summary>
 | |
|         /// 增加
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void btnNew_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             if (this.tvDataTypeInit.SelectedNode != null)
 | |
|             {
 | |
|                 //if (this.trWBS.SelectedNode.Nodes.Count == 0)   //末级节点
 | |
|                 if (this.tvDataTypeInit.SelectedNodeID != "0")
 | |
|                 {
 | |
|                     PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("GoodsBuyEdit.aspx?BuyCode={0}", this.tvDataTypeInit.SelectedNode.NodeID, "新增 - ")));
 | |
|                 }
 | |
|                 else
 | |
|                 {
 | |
|                     Alert.ShowInTop("请选择请购单类别!", MessageBoxIcon.Warning);
 | |
|                 }
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 Alert.ShowInTop("请选择树节点!", MessageBoxIcon.Warning);
 | |
|             }
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 编辑
 | |
|         protected void btnMenuModify_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             EditData();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// Grid行双击事件
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
 | |
|         {
 | |
|             EditData();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 编辑
 | |
|         /// </summary>
 | |
|         private void EditData()
 | |
|         {
 | |
|             if (Grid1.SelectedRowIndexArray.Length == 0)
 | |
|             {
 | |
|                 Alert.ShowInTop("请至少选择一条记录", MessageBoxIcon.Warning);
 | |
|                 return;
 | |
|             }
 | |
|             PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("GoodsBuyEdit.aspx?GoodsBuyId={0}", Grid1.SelectedRowID, "编辑 - ")));
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 删除
 | |
|         /// <summary>
 | |
|         /// 右键删除
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void btnMenuDel_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             if (Grid1.SelectedRowIndexArray.Length > 0)
 | |
|             {
 | |
|                 foreach (int rowIndex in Grid1.SelectedRowIndexArray)
 | |
|                 {
 | |
|                     string rowID = Grid1.DataKeys[rowIndex][0].ToString();
 | |
|                     BLL.GoodsBuyItemService.DeleteGoodsBuyItemByGoodsBuyId(rowID);
 | |
|                     BLL.GoodsBuyService.DeleteGoodsBuy(rowID);
 | |
|                 }
 | |
|                 BindGrid();
 | |
|                 ShowNotify("删除数据成功!", MessageBoxIcon.Success);
 | |
|             }
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region Grid行点击事件
 | |
|         /// <summary>
 | |
|         /// Grid行点击事件
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
 | |
|         {
 | |
|             string id = Grid1.DataKeys[e.RowIndex][0].ToString();
 | |
|             if (e.CommandName == "AttachUrl")
 | |
|             {
 | |
|                 PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/TestRun/DriverGoods/GoodsBuy&menuId={1}", id, BLL.Const.GoodsBuyMenuId)));
 | |
|             }
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 权限设置
 | |
|         /// <summary>
 | |
|         /// 权限设置
 | |
|         /// </summary>
 | |
|         private void GetButtonPower()
 | |
|         {
 | |
|             var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.GoodsBuyMenuId);
 | |
|             if (buttonList.Count() > 0)
 | |
|             {
 | |
|                 if (buttonList.Contains(BLL.Const.BtnAdd))
 | |
|                 {
 | |
|                     this.btnNew.Hidden = false;
 | |
|                 }
 | |
|                 if (buttonList.Contains(BLL.Const.BtnModify))
 | |
|                 {
 | |
|                     this.btnMenuModify.Hidden = false;
 | |
|                     this.Grid1.EnableRowDoubleClickEvent = true;
 | |
|                 }
 | |
|                 if (buttonList.Contains(BLL.Const.BtnDelete))
 | |
|                 {
 | |
|                     this.btnMenuDel.Hidden = false;
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         #endregion
 | |
|     }
 | |
| } |