| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using Core.Mes.Client.Comm.Server;
- using Core.Mes.Client.Comm.Tool;
- using Core.StlMes.Client.PnCost.Models;
- using CoreFS.CA06;
- using Infragistics.Win.UltraWinTree;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace Core.StlMes.Client.PnCost
- {
- public partial class frmPurMat : FrmBase
- {
- #region 定义变量
- public frmPurMat(OpeBase ob)
- {
- InitializeComponent();
- this.ob = ob;
- }
- private string matCode = "";
- public string MatCode
- {
- get { return matCode; }
- set { matCode = value; }
- }
- private string matName = "";
- public string MatName
- {
- get { return matName; }
- set { matName = value; }
- }
- #endregion
- #region 初始化
- private void frmPurMat_Load(object sender, EventArgs e)
- {
- ultraCheckEditor1.Checked = false;
- ultraTextEditor1.Enabled = false;
- Query("first");
- EntityHelper.ShowGridCaption<PurMatEntity>(ultraGrid1.DisplayLayout.Bands[0]);
- }
- #endregion
- #region 方法
- private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
- {
- switch (e.Tool.Key)
- {
- case "确定":
- Right();
- break;
- case "query":
- Query("again");
- break;
- case "关闭":
- this.Close();
- break;
- }
- }
- /// 查询方法
- /// <summary>
- /// 查询方法
- /// </summary>
- private void Query(string flag)
- {
- //物料描述
- string strPei = "";
- if (ultraCheckEditor1.Checked)//物料描述是否选择
- {
- if (ultraTextEditor1.Text == "")//物料描述是否输入
- {
- MessageUtil.ShowWarning("请输入物料描述!");
- return;
- }
- else
- {
- strPei = ultraTextEditor1.Text.Trim();//物料描述
- }
- }
- if (flag == "first")
- {
- DataTable dt = ServerHelper.GetData("com.steering.pss.pncost.base.ComBaseMetalGrade.queryHejin", new object[] { }, ob);
- Bind_Tv(dt, ultraTree1.Nodes, null, "BASECODE", "PARENTCODE", "BASENAME");
- }
- else
- {
- if (strPei=="")
- {
- if (MessageUtil.ShowYesNoAndQuestion("要查询的数据过大,是否先输入物料描述?") == System.Windows.Forms.DialogResult.Yes)
- {
- return;
- }
- }
- List<PurMatEntity> data = EntityHelper.GetData<PurMatEntity>(
- "com.steering.pss.pncost.base.ComBaseMetalGrade.queryPurNew", new object[] { strPei }, ob);
- purMatEntityBindingSource.DataSource = data;
- if (ultraGrid1.Rows.Count == 0)
- {
- return;
- }
- this.ultraGrid1.Rows[0].Activate();
- }
- }
- /// 确定方法
- /// <summary>
- /// 确定方法
- /// </summary>
- private void Right()
- {
- if (ultraGrid1.Rows.Count == 0)
- {
- return;
- }
- if (ultraGrid1.ActiveRow == null)
- {
- MessageUtil.ShowWarning("请选择物料!");
- return;
- }
- if (ultraGrid1.ActiveRow != null)
- {
- matCode = ultraGrid1.ActiveRow.Cells["ITEMCODE"].Value.ToString();
- matName = ultraGrid1.ActiveRow.Cells["ITEMNAME"].Value.ToString();
- this.DialogResult = System.Windows.Forms.DialogResult.OK;
- }
- }
- /// 绑定TreeView(利用TreeNodeCollection)
- /// <summary>
- /// 绑定TreeView(利用TreeNodeCollection)
- /// </summary>
- /// <param name="tnc">TreeNodeCollection(TreeView的节点集合)</param>
- /// <param name="pid_val">父id的值</param>
- /// <param name="id">数据库 id 字段名</param>
- /// <param name="pid">数据库 父id 字段名</param>
- /// <param name="text">数据库 文本 字段值</param>
- private void Bind_Tv(DataTable dt, TreeNodesCollection tnc, string pid_val, string id, string pid, string text)
- {
- DataView dv = new DataView(dt);//将DataTable存到DataView中,以便于筛选数据
- UltraTreeNode tn;//建立TreeView的节点(TreeNode),以便将取出的数据添加到节点中
- //以下为三元运算符,如果父id为空,则为构建“父id字段 is null”的查询条件,否则构建“父id字段=父id字段值”的查询条件
- string filter = string.IsNullOrEmpty(pid_val) ? pid + " is null" : string.Format(pid + "='{0}'", pid_val);
- dv.RowFilter = filter;//利用DataView将数据进行筛选,选出相同 父id值 的数据
- foreach (DataRowView drv in dv)
- {
- tn = new UltraTreeNode();//建立一个新节点(学名叫:一个实例)
- tn.Tag = drv[id].ToString();//节点的Value值,一般为数据库的id值
- tn.Text = drv[text].ToString();//节点的Text,节点的文本显示
- tnc.Add(tn);//将该节点加入到TreeNodeCollection(节点集合)中
- Bind_Tv(dt, tn.Nodes, tn.Tag.ToString(), id, pid, text);//递归(反复调用这个方法,直到把数据取完为止)
- }
- }
- #endregion
- #region 事件
- /// 标记事件
- /// <summary>
- /// 标记事件
- /// </summary>
- private void ultraTree1_AfterActivate(object sender, NodeEventArgs e)
- {
- string strChan = e.TreeNode.Tag.ToString2();
- List<PurMatEntity> data = EntityHelper.GetData<PurMatEntity>(
- "com.steering.pss.pncost.base.ComBaseMetalGrade.queryPur", new object[] { strChan }, ob);
- purMatEntityBindingSource.DataSource = data;
- if (ultraGrid1.Rows.Count == 0)
- {
- return;
- }
- this.ultraGrid1.Rows[0].Activate();
- }
- #endregion
- private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e)
- {
- ultraTextEditor1.Enabled = this.ultraCheckEditor1.Checked;
- }
- }
- }
|