| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- 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;
- using Infragistics.Win.UltraWinGrid;
- using Infragistics.Win;
- using CoreFS.CA06;
- using Pur.Entity;
- using Core.Mes.Client.Comm.Control;
- using Core.Mes.Client.Comm;
- using Core.Mes.Client.Comm.Tool;
- using Pur.Entity.configureEntity;
- using Infragistics.Win.UltraWinTree;
- using Core.Mes.Client.Comm.Server;
- using Pur.Pop_upWindow;
- using com.hnshituo.pur.vo;
- using Pur.configure;
- using System.Collections;
- using Infragistics.Win.UltraWinToolTip;
- using Pur.require_plan;
- using Infragistics.Win.UltraWinEditors;
- using Pur.PublicTools;
- namespace Pur.Pop_upWindow
- {
- public partial class frmPop_updPrice : FrmPmsBase
- {
- public frmPop_updPrice(string strItemName,string strItemCode,string dPrice,OpeBase ob)
- {
- InitializeComponent();
- this.ob = ob;
- }
- public frmPop_updPrice()
- {
- InitializeComponent();
- }
- private void frmPop_updPrice_Load(object sender, EventArgs e)
- {
- PublicPur.InitCellEdit(new UltraGrid[] { GridMat }, new string[] { "Check", "newPrice" });
- PublicPur.InitCellPositionRight(new UltraGrid[] { GridMat }, new string[] { "newPrice" });
- PublicPur.InitColumnShowLength(new UltraGrid[] { GridMat }, 0, new string[] { "newPrice" }, 2, false);
- QtimeB.Value = System.DateTime.Now.AddYears(-1).AddDays(-3);
- QtimeE.Value = DateTime.Now.AddDays(-3);
- QueryNum.SelectedIndex = 0;//每页显示数量
- GridHelper.SetExcludeColumnsActive(GridMat.DisplayLayout.Bands[0], new string[] { "Check", "newPrice" });
- if (selectType == "1")
- {
- GridHelper.HidenColumns(GridMat.DisplayLayout.Bands[0], new string[] { "Check" });
- }
- //查询物料分类树
- GetPUR_MAT_Class();
- ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[0];
- }
- public double dPrice = 0;
- MatEntity Q_mat = null;
- String selectType = "0";//0:全选,1:单个选
- Boolean QClickCellOrQuery = false;//是否点击查询按钮或grid数据单元格,控制是否刷新右侧物料数据,true为不刷新
- DataTable dt_Purmatclass = null;
- UltraTreeNode qUltraNode = null;
- public ArrayList List_item=new ArrayList();
- public String selectedItemCode="";
- public String SelectedItemName="";
- public string tips="0";
- #region toolbar工具栏
- public override void ToolBar_Click(object sender, string ToolbarKey)
- {
- switch (ToolbarKey)
- {
- case "Query":
- doQuery();
- break;
- case "conFirmation":
- doSure();
- break;
- case "updByClass"://按分类修改
- {
- MessageUtil.ShowTips("无权限");
- return;
- GridMat.UpdateData();
- UltraTreeNode nd = ulTreeMat.ActiveNode;
- if (nd == null)
- {
- MessageUtil.ShowTips("请选择物料分类");
- return;
- }
- ArrayList a3 = new ArrayList();
- MatEntity m = new MatEntity();
- m.ArcCode = nd.Key;
- m.LastPrice = 1;
- if (QtimeB.Value != null)
- {
- m.UpdateTime = (DateTime)QtimeB.Value;
- }
- else
- {
- MessageUtil.ShowTips("请选择加权平均价格计算区间");
- return;
- }
- if (QtimeE.Value != null)
- {
- m.CreateTime = (DateTime)QtimeE.Value;
- }
- else
- {
- MessageUtil.ShowTips("请选择加权平均价格计算区间");
- return;
- }
- //m.BugPrice = double.Parse(a2[i].ToString());
- a3.Add(m);
- if (comm.ConfirmOption("注:修改新计划价格为到货合同加权平均价,如果合同加权平均价为空,则默认为原计划价。\n确定按物料分类【" + nd.Text + "】批量修改物料计划价"))
- {
- CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.configure.service.MatService", "updateBugPrice", new object[] { a3 });//更新操作
- if (crt.Resultcode != 0)
- {
- MessageUtil.ShowTips("更新失败 " + crt.Resultmsg);
- return;
- }
- MessageUtil.ShowTips("更新成功");
- if (Q_mat != null)
- getMat(Q_mat);//刷新物料
- }
- break;
- }
- case "ESC":
- {
- this.Close();
- }
- break;
- case "doExcel":
- {
- doExcel();
- }
- break;
- }
- }
- private void doSure()
- {
- GridMat.UpdateData();
- ArrayList a3 = new ArrayList();
- DataRow[] arr = DTmat.Select("Check = 'True'");
- foreach (DataRow row in arr)
- {
- MatEntity m = new MatEntity();
- m.ItemCode = row["itemCode"].ToString().Trim();
- m.BugPrice = double.Parse(row["newPrice"].ToString().Trim());
- m.CreateName = UserInfo.GetUserName();
- m.CreateUserid = UserInfo.GetUserID();
- m.CreateTime = DateTime.Now;
- a3.Add(m);
- }
- if (comm.ConfirmOption("注:新计划价格为合同加权库存平均价,如果合同加权平均价为空,则默认为原计划价。\n确定修改物料计划价"))
- {
- CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.configure.service.MatService", "updateNewPrice", new object[] { a3 });//更新操作
- if (crt.Resultcode != 0)
- {
- MessageUtil.ShowTips("更新失败: " + crt.Resultmsg);
- return;
- }
- MessageUtil.ShowTips("更新成功");
- if (Q_mat != null)
- getMat(Q_mat);//刷新物料
- }
- }
- private void doQuery()
- {
- if (ultraTabControl1.SelectedTab.Key == "1")
- {
- QClickCellOrQuery = true;
- GetPUR_MAT_Class();
- if (GridMat.Rows.Count > 0)
- {
- ulTreeMat.CollapseAll();
- UltraTreeNode uttNode = ulTreeMat.GetNodeByKey(GridMat.Rows[0].Cells["ARCCODE"].Value.ToString());
- ulTreeMat.ActiveNode = uttNode;
- if (uttNode == null)
- {
- MessageUtil.ShowTips("物料名称:" + GridMat.Rows[0].Cells["ITEMNAME"].Value.ToString() + " 未找到相应的分类:" + GridMat.Rows[0].Cells["ARCCODE"].Value.ToString());
- }
- else
- {
- while (ulTreeMat.ActiveNode != uttNode)
- {
- ulTreeMat.ActiveNode = uttNode;
- }
- uttNode.Expanded = true;
- //展开分类
- while (uttNode.Parent != null)
- {
- uttNode = uttNode.Parent;
- uttNode.Expanded = true;
- }
- }
- QClickCellOrQuery = false;//设置未点击
- }
- }
- else
- {
- DTrecord.Clear();
- MatBugpirceRecord record = new MatBugpirceRecord();
- record.ItemCode = QitemCode_record.Text.Trim();
- record.ItemName = QitemName_record.Text.Trim();
- DataTable dt11 = this.execute<DataTable>("com.hnshituo.pur.configure.service.MatBugpirceRecordService", "find", new object[] { record, 0, 0 });
- GridHelper.CopyDataToDatatable(ref dt11, ref DTrecord, true);//绑定物料分类表
- GridHelper.RefreshAndAutoSize(GridRecord);
- }
- }
- private void doExcel()
- {
- try
- {
- this.Cursor = Cursors.Default;
- if (ultraTabControl1.SelectedTab.Key == "1")
- {
- if (GridMat.ActiveRow == null)
- {
- MessageUtil.ShowTips("请选择需导出物料!");
- return;
- }
- String strclass = "";
- if (ulTreeMat.ActiveNode != null && !String.IsNullOrEmpty(ulTreeMat.ActiveNode.Text))
- {
- strclass = ulTreeMat.ActiveNode.Text + "_";
- }
- ArrayList alUltraGrid = new ArrayList();
- alUltraGrid.Add(GridMat);
- ArrayList alSheeft = new ArrayList();
- alSheeft.Add(strclass + "物料计划价格清单");
- GridHelper.ulGridToExcel(alUltraGrid, alSheeft, strclass + "物料计划价格清单");
- }
- else
- {
- if (GridRecord.Rows.Count <= 0)
- {
- MessageUtil.ShowTips("无可导出记录!");
- return;
- }
- ArrayList alUltraGrid = new ArrayList();
- alUltraGrid.Add(GridRecord);
- ArrayList alSheeft = new ArrayList();
- alSheeft.Add("计划价格修改记录");
- GridHelper.ulGridToExcel(alUltraGrid, alSheeft, "计划价格修改记录");
- }
- }
- catch (Exception e)
- {
- MessageUtil.ShowTips("导出失败" + e.Message);
- }
- finally
- {
- this.Cursor = Cursors.Default;
- }
- }
- #endregion
- #region 加载物料分类树
- /// <summary>
- /// 查询物料分类和物料
- /// </summary>
- public void GetPUR_MAT_Class()
- {
- //查询物料分类
- PurmatclassEntity matclassEntity = new PurmatclassEntity();
- matclassEntity.Validflag = "1";
- DataTable dt = this.execute<DataTable>("com.hnshituo.pur.configure.service.MatClassService", "getMatClass", new object[] { matclassEntity });
- dt_Purmatclass = dt;
- getultree(dt);//绑定物料分类表
- //查询物料
- MatEntity mat = new MatEntity();
- mat.Validflag = "1";
- //物料分类
- if (checkBox1.Checked)
- {
- mat.UpdateName = txt_ARC_CODE.Text;
- }
- mat.ItemCode = txt_wlbm.Text;
- string strItemName = txt_wlmc.Text.Trim();
- while (strItemName.Contains(" "))
- {
- strItemName = strItemName.Replace(" ", " ");
- }
- mat.MatItems = strItemName.Split(' ');
- getMat(mat);
- }
- /// <summary>
- /// 获取物料分类树形结构
- /// </summary>
- public void getultree(DataTable dt)
- {
- ulTreeMat.Nodes.Clear();
- if (dt == null || dt.Rows.Count < 1)
- {
- return;
- }
- dt_Purmatclass = dt;//保存物料分类全局变量
- DataTable dt_A = new DataTable();//物料分类
- //筛选出根节点
- DataRow[] rows = dt.Select("PARENTCODE='' or PARENTCODE is null");
- dt_A = dt.Clone(); //克隆A的结构
- foreach (DataRow row in rows)
- {
- dt_A.ImportRow(row);//复制行数据
- }
- //添加物料大类
- for (int j = 0; j < dt_A.Rows.Count; j++)
- {
- UltraTreeNode Ultnode = ulTreeMat.Nodes.Add(dt_A.Rows[j]["BASECODE"].ToString(), dt_A.Rows[j]["BASENAME"].ToString());
- getChildNodes(Ultnode);
- }
- }
- /// <summary>
- /// 递归查询父节点下的所有子节点
- /// </summary>
- /// <param name="Tnode"></param>
- public void getChildNodes(UltraTreeNode Tnode)
- {
- DataTable dt_A = dt_Purmatclass.Clone();//物料分类
- DataRow[] rows = dt_Purmatclass.Select("PARENTCODE='" + Tnode.Key + "'");
- foreach (DataRow row in rows)
- {
- dt_A.ImportRow(row);//复制行数据
- }
- //添加物料分类
- for (int j = 0; j < dt_A.Rows.Count; j++)
- {
- UltraTreeNode Ultnode = Tnode.Nodes.Add(dt_A.Rows[j]["BASECODE"].ToString(), dt_A.Rows[j]["BASENAME"].ToString());
- getChildNodes(Ultnode);//利用递归将当前节点的子节点添加进去
- }
- }
- private void ulTreeMat_AfterActivate(object sender, NodeEventArgs e)
- {
- if (!QClickCellOrQuery)//如果不是点击查询按钮或单击grig行数据,刷新右侧数据
- {
- MatEntity eMat = new MatEntity();
- ulTreeMat.ActiveNode.Expanded = true;
- qUltraNode = ulTreeMat.ActiveNode;
- eMat.ArcCode = qUltraNode.Key;
- eMat.Validflag = "1";
- getMat(eMat);
- }
- txt_ARC_CODE.Text = ulTreeMat.ActiveNode.Key;
- txt_ARC_ITEM.Text = ulTreeMat.ActiveNode.Text;
- }
- #endregion
- #region 物料查询
- /// <summary>
- /// 查询物料
- /// </summary>
- private void getMat(MatEntity mat)
- {
- DTmat.Clear();
- //查询合同加权平均价
- if (QtimeB.Value != null)
- {
- mat.UpdateTime = (DateTime)QtimeB.Value;
- }
- if (QtimeE.Value != null)
- {
- mat.CreateTime = (DateTime)QtimeE.Value;
- }
- mat.LastPrice = 1;
- mat.ItemUomConefficient = double.Parse(QueryNum.Value.ToString());
- DataTable dt_mat = this.execute<DataTable>("com.hnshituo.pur.configure.service.MatService", "getMat", new object[] { mat });
- GridHelper.CopyDataToDatatable(ref dt_mat, ref DTmat, true);//绑定物料分类表
- GridHelper.RefreshAndAutoSize(GridMat);
- }
- #endregion
- private void ultraTabControl1_SelectedTabChanged(object sender, Infragistics.Win.UltraWinTabControl.SelectedTabChangedEventArgs e)
- {
- if (ultraTabControl1.SelectedTab.Key == "2")
- {
- this.ToolBarItemEnable(this, "conFirmation", false);
- this.ToolBarItemEnable(this, "updByClass", false);
- }
- else
- {
- this.ToolBarItemEnable(this, "conFirmation", true);
- this.ToolBarItemEnable(this, "updByClass", true);
- }
- }
- private void frmPop_updPrice_Shown(object sender, EventArgs e)
- {
- this.ToolBarItemEnable(this, "conFirmation", true);
- this.ToolBarItemEnable(this, "updByClass", true);
- }
- }
- }
|