using Gs.DevApp.Entity; using Gs.DevApp.ToolBox; using Newtonsoft.Json; using System; using System.Data; using System.Drawing; using System.Windows.Forms; namespace Gs.DevApp.DevFrm.QC { public partial class Frm_MesQaItemsDetect01Input : DevExpress.XtraEditors.XtraForm { string _webServiceName = "MesQaItemsDetect01Manager/"; private string dt01Guid = ""; public Frm_MesQaItemsDetect01Input(string _dt01Guid) { InitializeComponent(); this.dt01Guid = _dt01Guid; Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gvMx1); getModel(); gvMx1.CellValueChanged += GvMx1_CellValueChanged; gvMx1.ShowingEditor += GvMx1_ShowingEditor; gvMx1.CustomDrawCell += GvMx1_CustomDrawCell; } /// /// 判断单元格的编辑性 /// /// /// /// private bool ckCol(string ColumnName, string _maxYbs) { string _FieldName = ColumnName; if (!_FieldName.Contains("样本")) return false; if (_FieldName == "样本数") return true; if (string.IsNullOrEmpty(_maxYbs)) return false; string _seqYb = _FieldName.Replace("样本", ""); if (int.Parse(_seqYb) > int.Parse(_maxYbs)) return false; return true; } private void GvMx1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { string _maxYbs = (gvMx1.GetRowCellValue(e.RowHandle, "样本数").ToString()); bool _bl = ckCol(e.Column.FieldName, _maxYbs); if (_bl) { e.Appearance.BackColor = Color.Azure; e.Column.MinWidth = 50; } else { e.Appearance.BackColor = Color.LightGray; } } private void GvMx1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { // 获取行句柄 int rowHandle = e.RowHandle; // 获取列 // GridColumn col = gvMx1.Columns[e.Column.Name]; // 获取新值 object newValue = e.Value; // 获取旧值 // object oldValue = gvMx1.GetRowCellValue(rowHandle, col); // MessageBox.Show(newValue.ToString()); // getModel(); // 在这里执行你的逻辑,例如: // MessageBox.Show($"行 {rowHandle},列 {col.FieldName} 的值已从 {oldValue} 改为 {newValue}"); string dt05Guid = gvMx1.GetRowCellValue(e.RowHandle, "guid").ToString(); string dtCol = e.Column.FieldName; gvMx1.CloseEditor(); gvMx1.PostEditor(); gvMx1.UpdateCurrentRow(); var _obj = new { dt05Guid = dt05Guid, fSeq = dtCol, fVal = newValue, }; try { string strJson = UtilityHelper.HttpPost("", _webServiceName + "EditYangLi", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) { string _strYbNo = _rtn.rtnData.outNo; string _outMsg = _rtn.rtnData.outMsg; string _outSum = _rtn.rtnData.outSum; if (string.IsNullOrEmpty(_outSum)) _outSum = "-1"; if (int.Parse(_outSum) < 0) { MessageBox.Show(_outMsg); } if (_strYbNo == "样本数") getModel(); //lbGuid.Text = _rtn.rtnData.outGuid; //txt_hNo.Text = _rtn.rtnData.outNo; //toolBarMenu1.isSetBtn = true; } else ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } private void GvMx1_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e) { DevExpress.XtraGrid.Views.Grid.GridView view = sender as DevExpress.XtraGrid.Views.Grid.GridView; string _maxYbs = (gvMx1.GetRowCellValue(view.FocusedRowHandle, "样本数").ToString()); bool _bl = ckCol(view.FocusedColumn.FieldName, _maxYbs); if (!_bl) e.Cancel = true; } private void getModel() { gcMx1.DataSource = null; gvMx1.Columns.Clear(); var _obj = new { dt01Guid = this.dt01Guid }; try { string strJson = UtilityHelper.HttpPost("", _webServiceName + "GetYangLi", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToList(strJson); if (_rtn.rtnCode > 0) { DataTable dt = _rtn.rtnData; if (dt.Rows.Count > 0) { gcMx1.BindingContext = new BindingContext(); gcMx1.DataSource = dt; gcMx1.ForceInitialize(); gvMx1.BestFitColumns(); gvMx1.Columns["guid"].Visible = false; gvMx1.Columns["parentGuid"].Visible = false; } else { Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx1, gvMx1); } } else ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } } }