| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- 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<CraftFileLv2Entity>(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<CraftFileLv2Entity> 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<CraftFileLv2Entity>();
- string pk = "";
- foreach (var row in rows)
- {
- var craftFileLv2 = EntityHelper.CopyEntity<CraftFileLv2Entity>(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<CraftFileLv2Entity>();
- string pk = "";
- foreach (var row in rows)
- {
- var craftFileLv2 = EntityHelper.CopyEntity<CraftFileLv2Entity>(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<CraftFileLv2Entity> updateParms = new List<CraftFileLv2Entity>();
- 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<FileBean> list = new List<FileBean>();
- 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);
- }
- }
- }
|