lu
2025-03-15 aa8f2ab61f7c87640de7817b77758c78e9c45792
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
using DevExpress.Utils;
using DevExpress.Utils.DirectXPaint;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraPrinting.Native;
using DevExpress.XtraRichEdit.Layout;
using Gs.DevApp.DevFrm.QC;
using Gs.DevApp.Entity;
using Gs.DevApp.ToolBox;
using Gs.DevApp.UserControl;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Net;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
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 void GvMx1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            // 判断单元格是否符合条件 && e.CellValue.ToString() == "YourCondition"
            bool _bl = false;
            string _FieldName = e.Column.FieldName;
            //if (e.Column.FieldName == "样本数")
            //{
            //    _bl = true;
            //}
            //e.Appearance.BackColor = Color.LightBlue; // 设置背景色
            if (_FieldName.Contains("样"))
            {
                if (_FieldName == "样本数")
                    _bl = true;
                else
                {
                    string _maxYbs = (gvMx1.GetRowCellValue(e.RowHandle, "样本数").ToString());
                    string _seqYb = _FieldName.Replace("样本", "");
                    if (int.Parse(_seqYb) > int.Parse(_maxYbs))
                        _bl = false;
                    else
                        _bl = true;
                }
            }
            else
            {
                _bl = false;
            }
            if (_bl) { 
              e.Appearance.BackColor = Color.Azure;
                e.Column.MinWidth = 50;
             //e.Appearance.BackColor2 = Color.LightSkyBlue;
            }
            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<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    string _strYbNo = _rtn.rtnData.outNo;
                    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 _FieldName = view.FocusedColumn.FieldName;
            if (view.FocusedColumn.FieldName.Contains("样"))
            {
                if (_FieldName == "样本数")
                    e.Cancel = false;
                else
                {
                    string _maxYbs = (gvMx1.GetRowCellValue(view.FocusedRowHandle, "样本数").ToString());
                    string _seqYb = _FieldName.Replace("样本", "");
                    if (int.Parse(_seqYb) > int.Parse(_maxYbs))
                        e.Cancel = true;
                }
            }
            else
            {
                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<DataTable> _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();
                    }
                    else
                    {
                        Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx1, gvMx1);
                    }
                    gvMx1.Columns["guid"].Visible = false;
                    gvMx1.Columns["parentGuid"].Visible = false;
                }
                else
                    ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            }
        }
    }
}