using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Server; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.Qcm.BLL; using Core.StlMes.Client.Qcm.model; using CoreFS.CA06; using CoreFS.SA06; using Infragistics.Win.UltraWinEditors; using Infragistics.Win.UltraWinGrid; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Linq; using System.Windows.Forms; using Infragistics.Win; namespace Core.StlMes.Client.Qcm.Control { public partial class ComBaseSplineCtrl : UserControl { private OpeBase _ob; private ComBaseSplineBLL _splineBLL; private UltraComboEditor _cmb; private string flag = ""; public string Flag { get { return flag; } set { flag = value; } } //查询条件 string _phyNameMin = ""; string _sampleStyle = ""; string _validflag = ""; string _seamArea = ""; public ComBaseSplineCtrl(System.Windows.Forms.Control container, OpeBase ob) { InitializeComponent(); _ob = ob; _splineBLL = new ComBaseSplineBLL(ob); container.Controls.Add(this); this.Dock = DockStyle.Fill; this.BringToFront(); EntityHelper.ShowGridCaption(ultraGrid1.DisplayLayout.Bands[0]); LoadData(); } private void LoadData() { _cmb = new UltraComboEditor(); _cmb.Visible = false; _cmb.DataSource = _splineBLL.GetComBasePhyC(); _cmb.DisplayMember = "PHY_TYPE"; _cmb.ValueMember = "PHY_CODE"; this.Controls.Add(_cmb); ultraGrid1.DisplayLayout.Bands[0].Columns["PhyCodeMin"].EditorComponent = _cmb; ultraGrid1.DisplayLayout.Bands[0].Columns["PhyCodeMin"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList; ClsBaseInfo.FillComBaseInfo(ultraComboEditor2, "4081", _ob, false); ValueList list = new ValueList(); ValueListItem[] items = new ValueListItem[] { new ValueListItem("0", "天管"), new ValueListItem("1", "天淮"), }; list.ValueListItems.AddRange(items); ultraGrid1.DisplayLayout.Bands[0].Columns["SeamArea"].ValueList = list; } public void Query(string phyNameMin, string sampleStyle, string validflag,string seamArea) { _phyNameMin = phyNameMin; _sampleStyle = sampleStyle; _validflag = validflag; _seamArea = seamArea; comBaseSplineEntityBindingSource.DataSource = _splineBLL.Query(phyNameMin, sampleStyle, validflag, seamArea); foreach (var row in ultraGrid1.Rows) { GridEdite(row); } } public void Query2(string phyCodeMin, string itemCodeF, string itemCodeC, string ordLnPk, string itemCodeW) { comBaseSplineEntityBindingSource.DataSource = _splineBLL.Query2( phyCodeMin, itemCodeF, itemCodeC, ordLnPk, itemCodeW); foreach (var row in ultraGrid1.Rows) { GridEdite(row); } } public void QueryNk(string phyCodeMin, string stdCode, string stdCodeTest, string itemCodeF) { comBaseSplineEntityBindingSource.DataSource = _splineBLL.QueryNk( phyCodeMin, stdCode, stdCodeTest, itemCodeF); foreach (var row in ultraGrid1.Rows) { GridEdite(row); } } public bool Save(List list) { ultraGrid1.UpdateData(); var rows = ultraGrid1.Rows.AsQueryable().Where(a => a.GetValue("Chk") == "True"); //var rows = queryable.Select(a => EntityHelper.CopyEntity(a.ListObject)).ToList(); List splineEntitys = new List(); foreach (var row in rows) { ComBaseSplineEntity2 splineEntity = EntityHelper.CopyEntity(row.ListObject); if (splineEntity.SplineNo == "") { MessageUtil.ShowWarning("请输入试样编号!"); row.Cells["SplineNo"].Activate(); return false; } if (splineEntity.PhyCodeMin == "") { MessageUtil.ShowWarning("请输入取样码!"); row.Cells["PhyCodeMin"].Activate(); return false; } else if (splineEntity.Length == null) { MessageUtil.ShowWarning("请输入毛样长!"); row.Cells["Length"].Activate(); return false; } else if (splineEntity.SizeDesc == "") { MessageUtil.ShowWarning("请输入名义规格!"); row.Cells["SizeDesc"].Activate(); return false; } else if (splineEntity.SampleStyle == "") { MessageUtil.ShowWarning("请输入毛样类型!"); row.Cells["SampleStyle"].Activate(); return false; } else if (splineEntity.SampleStyle == "408101" && splineEntity.Width == null) { MessageUtil.ShowWarning("请输入毛样宽度!"); row.Cells["Width"].Activate(); return false; } else if (splineEntity.SeamArea == "") { MessageUtil.ShowWarning("请输入所属区域!"); row.Cells["SeamArea"].Activate(); return false; } else if (_splineBLL.IsRepeat(splineEntity)) { MessageUtil.ShowWarning("数据重复,请检查后再保存!\r\n唯一性限制:试样组+试验方向+试验尺寸+名义规格"); row.Activate(); return false; } splineEntity.SplineRStds = new List(); var stdCodeS = row.GetValue("StdCodeS").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); var stdNameS = row.GetValue("StdNameS").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < stdCodeS.Length; i++) { splineEntity.SplineRStds.Add(new ComBaseSplineRStdEntity() { StdCode = stdCodeS[i], StdName = stdNameS[i], CreateName = CoreUserInfo.UserInfo.GetUserName(), UpdateName = CoreUserInfo.UserInfo.GetUserName() }); } splineEntity.CreateName = CoreUserInfo.UserInfo.GetUserName(); splineEntity.UpdateName = CoreUserInfo.UserInfo.GetUserName(); splineEntitys.Add(splineEntity); } if (MessageUtil.ShowYesNoAndQuestion("是否确认保存?") == DialogResult.No) { return false; } _splineBLL.Save(splineEntitys, list); if (rows.FirstOrDefault() != null) Relocate(rows.FirstOrDefault().GetValue("eic")); return true; } private void Relocate(string eic) { Query(_phyNameMin, _sampleStyle, _validflag,_seamArea); var row = ultraGrid1.Rows.AsQueryable().Where(a => a.GetValue("eic") == eic).FirstOrDefault(); if (row != null) { row.Activate(); } } public void UpdateValidflag(string flag) { ultraGrid1.UpdateData(); var rows = ultraGrid1.Rows.AsQueryable().Where(a => a.GetValue("Chk") == "True") .Select(a => EntityHelper.CopyEntity(a.ListObject)).ToList(); foreach (var row in rows) { row.DeleteName = CoreUserInfo.UserInfo.GetUserName(); row.UpdateName = CoreUserInfo.UserInfo.GetUserName(); } _splineBLL.UpdateValidflag(rows, flag); } private void ultraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e) { e.Cell.Row.Update(); if (e.Cell.Column.Key == "PhyCodeMin") { e.Cell.Row.Cells["PhyNameMin"].Value = e.Cell.Text; } else if (e.Cell.Column.Key == "Chk") { GridEdite(e.Cell.Row); } else if (e.Cell.Column.Key == "SampleStyle") { if (e.Cell.Value.ToString() == "408102") { e.Cell.Row.Cells["Width"].Value = null; e.Cell.Row.Cells["Width"].Activation = Activation.ActivateOnly; } else { e.Cell.Row.Cells["Width"].Activation = Activation.AllowEdit; } } if (e.Cell.Column.Key == "Chk") { 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(); } } } if (e.Cell.Column.Key == "Chk3") { UltraGridRow chkRow = e.Cell.Row; foreach (UltraGridRow row in ultraGrid1.Rows) { if (row.Cells["Chk3"].Value.ToString() == "True" && row != chkRow) { row.Cells["Chk3"].Value = "False"; row.Update(); } } } } 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.Contains("Chk")) continue; if (cell.Column.CellActivation == Activation.AllowEdit) { cell.Activation = Activation.ActivateOnly; } } } if (row.Cells["SampleStyle"].Value.ToString() == "408102") { row.Cells["Width"].Value = null; row.Cells["Width"].Activation = Activation.ActivateOnly; } ultraGrid1.UpdateData(); } private void ultraTextEditor1_EditorButtonClick(object sender, EditorButtonEventArgs e) { ComBaseSplineEntity splineEntity = (ComBaseSplineEntity)ultraGrid1.ActiveRow.ListObject; if (splineEntity.Validflag == "") { MessageUtil.ShowWarning("请先保存记录,然后再上传图片!"); return; } string path = "Qcm/Spline/" + splineEntity.Eic + "/"; if (e.Button.Key == "View") { FormFileDown down = new FormFileDown(_ob, path); if (flag == "试样关系") { down.DeleteButton.Visible = false; } down.ShowDialog(); if (down.CtrlFileDown1.List.Count == 0) { _splineBLL.UpdateFilePosition("", splineEntity.Eic); ultraGrid1.ActiveRow.Cells["FilePosition"].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); 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) { _splineBLL.UpdateFilePosition(path + fileName, splineEntity.Eic); MessageUtil.ShowTips("上传成功!"); Relocate(splineEntity.Eic); } else { MessageUtil.ShowTips("上传失败,请重试!"); } } } } private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { if (e.Row.GetValue("Validflag") == "无效") { e.Row.Appearance.ForeColor = Color.Red; } } private void ultraTextEditor2_EditorButtonClick(object sender, EditorButtonEventArgs e) { if (ultraGrid1.ActiveCell.Column.Key == "StdNameS") { this.Cursor = Cursors.WaitCursor; var actRow = ultraGrid1.ActiveRow; ComBaseStdChoice baseStdChoice = new ComBaseStdChoice(new string[] { "S" }, actRow.GetValue("StdCodeS"), _ob); this.Cursor = Cursors.Default; if (baseStdChoice.ShowDialog() == DialogResult.OK) { actRow.SetValue("StdCodeS", baseStdChoice.ChoiceStdCodes); actRow.SetValue("StdNameS", baseStdChoice.ChoiceStdNames); } } else if (ultraGrid1.ActiveCell.Column.Key == "ItemNameF") { string phyCodeMin = ultraGrid1.ActiveRow.GetValue("PhyCodeMin"); DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseQuery.geComBasePhyRItem", new object[] { phyCodeMin }, _ob); dt.Columns["ITEM_NAME_F"].Caption = "试验方向"; dt.Columns["ITEM_NAME_C"].Caption = "试验尺寸"; BaseInfoPopup baseInfoPopup = new BaseInfoPopup(dt, "ITEM_NAME_F", "ITEM_CODE_F", "ITEM_CODE_C"); baseInfoPopup.Text = "试验选择"; baseInfoPopup.LabelTextBox1.Caption = "试验方向"; baseInfoPopup.Shown += new EventHandler((c, d) => { IQueryable rows = baseInfoPopup.UltraGrid1.Rows.AsQueryable().Where( a => a.GetValue("ITEM_CODE_F") == ultraGrid1.ActiveRow.GetValue("ItemCodeF") && a.GetValue("ITEM_CODE_C") == ultraGrid1.ActiveRow.GetValue("ItemCodeS")); if (rows.Count() > 0) { rows.First().Activate(); } }); if (baseInfoPopup.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ultraGrid1.ActiveRow.SetValue("ItemNameF", baseInfoPopup.ChoicedRow.GetValue("ITEM_NAME_F")); ultraGrid1.ActiveRow.SetValue("ItemCodeF", baseInfoPopup.ChoicedRow.GetValue("ITEM_CODE_F")); ultraGrid1.ActiveRow.SetValue("ItemNameS", baseInfoPopup.ChoicedRow.GetValue("ITEM_NAME_C")); ultraGrid1.ActiveRow.SetValue("ItemCodeS", baseInfoPopup.ChoicedRow.GetValue("ITEM_CODE_C")); } } } } }