using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using Core.StlMes.Client.SaleOrder.BLL; using CoreFS.CA06; using Core.Mes.Client.Comm.Tool; using CoreFS.SA06; using Infragistics.Win.UltraWinGrid; using Core.StlMes.Client.Qcm; using Core.Mes.Client.Comm.Server; using Core.Mes.Client.Comm.Control; using System.IO; namespace Core.StlMes.Client.SaleOrder.Control { public partial class CraftFileLv2Ctrl : UserControl { private CraftFileLv2BLL _craftFileLv2BLL; private CraftOrdDesignBLL _craftOrdDesignBLL; private OpeBase _ob; private string _msc = ""; private string _processCode = ""; public CraftFileLv2Ctrl(System.Windows.Forms.Control container, OpeBase ob, string msc, string processCode) { InitializeComponent(); _ob = ob; _craftFileLv2BLL = new CraftFileLv2BLL(ob); _craftOrdDesignBLL = new CraftOrdDesignBLL(ob); _msc = msc; _processCode = processCode; container.Controls.Add(this); this.Dock = DockStyle.Fill; EntityHelper.ShowGridCaption(ultraGrid1.DisplayLayout.Bands[0]); BindComboBox(); } private void BindComboBox() { DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreControlPointBasics.GetProcess", null, _ob); ultraComboEditor1.DataSource = dt; ultraComboEditor1.DisplayMember = "PROCESS_DESC"; ultraComboEditor1.ValueMember = "PROCESS_CODE"; } private string _craftNoLv2 = ""; private string _validflag = ""; public void Query(string craftNoLv2, string validflag) { _craftNoLv2 = craftNoLv2; _validflag = validflag; List sourceData = _craftFileLv2BLL.Query( craftNoLv2, validflag, _msc, _processCode); craftFileLv2EntityBindingSource.DataSource = sourceData; foreach (var row in ultraGrid1.Rows) { GridEdite(row); if (row.GetValue("VALIDFLAG") == "无效") { row.Appearance.ForeColor = Color.Red; } } } public void QueryAll() { _isFilter = true; craftFileLv2EntityBindingSource.DataSource = _craftFileLv2BLL.QueryAll(); } private bool _isFilter = false; public void FilterCraftFileLv2(string designKey, string processCode, string craftNoLv2, string validflag, string craftFileLv2Pks, string craftNo, string msc) { ultraGrid1.BeginUpdate(); ultraTextEditor2.ButtonsRight.Clear(); this.craftFileLv2EntityBindingSource.DataSource = _craftFileLv2BLL.FilterCraftFileLv2( designKey, processCode, craftNoLv2, validflag, craftNo, msc); string[] craftFileLv2PkAry = craftFileLv2Pks.Split(';'); foreach (var row in ultraGrid1.Rows) { if (craftFileLv2PkAry.Contains(row.GetValue("Pk"))) { row.Cells["Chk"].Value = true; } } GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[0], "Chk"); _isFilter = true; ultraGrid1.EndUpdate(); ultraGrid1.UpdateData(); } public void Save(CraftFileLv2CCtrl fileLv2CCtrl) { ultraGrid1.UpdateData(); var rows = ultraGrid1.Rows.AsQueryable().Where(a => a.GetValue("Chk") == "True"); int chkCnt = rows.Count() + fileLv2CCtrl.UltraGrid1.Rows.AsQueryable().Where(a => a.GetValue("Chk") == "True").Count(); if (chkCnt == 0) { MessageUtil.ShowWarning("请选择记录保存!"); return; } var parms = new List(); string pk = ""; foreach (var row in rows) { var craftFileLv2 = EntityHelper.CopyEntity(row.ListObject); if (craftFileLv2.ProcessCode == "") { MessageUtil.ShowWarning("选择适用工序!"); row.SetCellActive("ProcessCode"); return; } //if (craftFileLv2.CraftPath == "") //{ // MessageUtil.ShowWarning("请上传二级工艺文件!"); // row.SetCellActive("CraftPath"); // return; //} craftFileLv2.CreateName = CoreUserInfo.UserInfo.GetUserName(); craftFileLv2.UpdateName = CoreUserInfo.UserInfo.GetUserName(); craftFileLv2.ProcessDesc = row.GetText("ProcessCode"); if (craftFileLv2.Msc == "") { craftFileLv2.Msc = _msc; } parms.Add(craftFileLv2); pk = craftFileLv2.Pk; } var fileLv2CParms = fileLv2CCtrl.GetSaveParms(); if (fileLv2CParms == null) return; if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == DialogResult.No) { return; } string[] results = (string[])_craftFileLv2BLL.Save(parms, fileLv2CParms); MessageUtil.ShowTips("保存成功!"); Relocate(results[0]); fileLv2CCtrl.Relocate(results[1]); return; } public void UpdateValidflag(string flag, CraftFileLv2CCtrl fileLv2CCtrl) { ultraGrid1.UpdateData(); var rows = ultraGrid1.Rows.AsQueryable().Where(a => a.GetValue("Chk") == "True"); int chkCnt = rows.Count() + fileLv2CCtrl.UltraGrid1.Rows.Where(a=>a.GetValue("Chk") == "True").Count(); if (chkCnt == 0) { MessageUtil.ShowWarning("请选择记录!"); return; } var parms = new List(); string pk = ""; foreach (var row in rows) { var craftFileLv2 = EntityHelper.CopyEntity(row.ListObject); craftFileLv2.CreateName = CoreUserInfo.UserInfo.GetUserName(); craftFileLv2.UpdateName = CoreUserInfo.UserInfo.GetUserName(); parms.Add(craftFileLv2); pk = craftFileLv2.Pk; } string tip = flag == "1" ? "恢复" : "作废"; if (MessageUtil.ShowYesNoAndQuestion("是否确认" + tip + "记录?") == DialogResult.No) return; var craftFileLv2CParms = fileLv2CCtrl.GetUpdateValidflagParms(); _craftFileLv2BLL.UpdateValidflag(parms, craftFileLv2CParms, flag); MessageUtil.ShowTips(tip + "成功!"); Relocate(pk); if (craftFileLv2CParms.Count > 0) { fileLv2CCtrl.Relocate(craftFileLv2CParms[0].Pk); } } private void Relocate(string pk) { Query(_craftNoLv2, _validflag); var row = ultraGrid1.Rows.AsQueryable().Where(a => a.GetValue("Pk") == pk).FirstOrDefault(); if (row != null) { row.Activate(); } } private void GridEdite(UltraGridRow row) { if (row.GetValue("Chk") == "True") { foreach (UltraGridCell cell in row.Cells) { if (cell.Column.CellActivation == Activation.AllowEdit) { cell.Activation = Activation.AllowEdit; } } } else { foreach (UltraGridCell cell in row.Cells) { if (cell.Column.Key == "Chk") continue; if (cell.Column.CellActivation == Activation.AllowEdit) { cell.Activation = Activation.ActivateOnly; } } } ultraGrid1.UpdateData(); } private void ultraGrid1_CellChange(object sender, CellEventArgs e) { e.Cell.Row.Update(); if (e.Cell.Column.Key == "ProcessCode") { e.Cell.Row.SetValue("ProcessDesc", e.Cell.Text); e.Cell.Row.SetValue("PlineName", ""); e.Cell.Row.SetValue("PlineCode", ""); } if (!_isFilter) { if (e.Cell.Column.Key == "Chk") { GridEdite(e.Cell.Row); UltraGridRow chkRow = e.Cell.Row; foreach (UltraGridRow row in ultraGrid1.Rows) { if (row.Cells["Chk"].Value.ToString() == "True" && row != chkRow) { row.Cells["Chk"].Value = false; row.Update(); } } } } } private void ultraTextEditor1_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e) { ComBasePlineChoice plineChoice; try { this.Cursor = Cursors.WaitCursor; string plineCodes = ultraGrid1.ActiveRow.GetValue("PlineCode"); string processCode = ultraGrid1.ActiveRow.GetValue("ProcessCode"); plineChoice = new ComBasePlineChoice(plineCodes, processCode, _ob); } finally { this.Cursor = Cursors.Default; } if (plineChoice.ShowDialog() == DialogResult.OK) { ultraGrid1.ActiveRow.SetValue("PlineName", plineChoice.PlineNames); ultraGrid1.ActiveRow.SetValue("PlineCode", plineChoice.PlineCodes); } } private void ultraTextEditor2_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e) { CraftFileLv2Entity fileLv2Entity = (CraftFileLv2Entity)ultraGrid1.ActiveRow.ListObject; if (fileLv2Entity.Validflag == "") { MessageUtil.ShowWarning("请先保存记录,然后再上传工艺文件!"); return; } string path = "Qcm/CraftLv2/" + fileLv2Entity.Pk + "/"; List updateParms = new List(); if (e.Button.Key == "Query") { FormFileDown down = new FormFileDown(_ob, path); if (_isFilter) { down.DeleteButton.Visible = false; } down.ShowDialog(); if (down.CtrlFileDown1.List.Count == 0) { CraftFileLv2Entity parm = (CraftFileLv2Entity)ultraGrid1.ActiveRow.ListObject; parm.CraftNoLv2 = ""; parm.CraftPath = ""; updateParms.Add(parm); _craftFileLv2BLL.Update(updateParms); ultraGrid1.ActiveRow.Cells["CraftPath"].Value = ""; } } if (e.Button.Key == "Upload") { var serverFileList = FileHelper.Download(path); if (serverFileList.Count > 0) { MessageUtil.ShowWarning("该记录已存在一份文件,请删除后再重新上传!"); return; } List list = new List(); FileBean bean = new FileBean(); OpenFileDialog file = new OpenFileDialog(); file.Multiselect = false; DialogResult drStat; drStat = file.ShowDialog(); if (drStat == DialogResult.OK) { string filePath = file.FileName; string fileName = System.IO.Path.GetFileName(filePath); CraftFileLv2Entity parm = (CraftFileLv2Entity)ultraGrid1.ActiveRow.ListObject; int exist = _craftFileLv2BLL.IsExistCraftLv2(fileName.Remove(fileName.LastIndexOf('.')), parm.Pk); if (exist > 0) { MessageUtil.ShowWarning("上传失败,系统已存在相同的工艺文件号!"); return; } bean = new FileBean(); bean.setFileName(fileName); bean.setPathName(path); bean.setFile(FileHelper.FileToArray(filePath)); list.Add(bean); bool isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list); if (isSuccess) { parm.UpdateName = CoreUserInfo.UserInfo.GetUserName(); parm.CraftNoLv2 = fileName.Remove(fileName.LastIndexOf('.')); parm.CraftPath = path + fileName; updateParms.Add(parm); _craftFileLv2BLL.Update(updateParms); ultraGrid1.ActiveRow.Cells["CraftPath"].Value = path + fileName; MessageUtil.ShowTips("上传成功!"); Relocate(parm.Pk); } else { MessageUtil.ShowTips("上传失败,请重试!"); } } } } private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e) { e.Row.SetValue("Msc", _msc); e.Row.SetValue("ProcessCode", _processCode); } } }