cdk
2025-10-30 5d0080eecc63a8ea1feac3f4f248549eb68d2c5e
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
using DevExpress.XtraRichEdit.Fields;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using System;
using System.Windows.Forms;
using System.Text.RegularExpressions;
 
namespace Gs.DevApp.DevFrm.BasicData
{
    public partial class Frm_MesItemsShow : DevExpress.XtraEditors.XtraForm
    {
        string guidList = "";
        public Frm_MesItemsShow(string _guidList)
        {
            InitializeComponent();
            this.guidList = _guidList;
            this.Text = "设置提前送货日期:" + guidList;
            this.btnCancel.Click += BtnCancel_Click;
            this.btnSave.Click += BtnSave_Click;
        }
 
        /// <summary>
        /// 验证超采率输入值
        /// </summary>
        private bool ValidateLossPercent()
        {
            if (txt_lossPercent.EditValue == null || string.IsNullOrWhiteSpace(txt_lossPercent.Text))
            {
                txt_lossPercent.EditValue = 0.0;
                return true;
            }
 
            if (double.TryParse(txt_lossPercent.EditValue.ToString(), out double value))
            {
                if (value < 0.0 || value > 1.0)
                {
                    MsgHelper.ShowError("超采率必须在0到1之间!");
                    txt_lossPercent.Focus();
                    return false;
                }
 
                // 格式化显示,保留适当的小数位数
                txt_lossPercent.EditValue = Math.Round(value, 4);
                return true;
            }
            else
            {
                MsgHelper.ShowError("请输入有效的数字!");
                txt_lossPercent.EditValue = 0.0;
                txt_lossPercent.Focus();
                return false;
            }
        }
 
        /// <summary>
        /// 验证提前到货天数必须为大于0的整数
        /// </summary>
        private bool ValidateDay()
        {
            var text = txt_day.Text?.Trim();
            if (string.IsNullOrWhiteSpace(text))
            {
                // 允许为空,表示不设置提前天数
                txt_day.EditValue = null;
                return true;
            }
 
            if (int.TryParse(text, out int days))
            {
                if (days <= 0)
                {
                    MsgHelper.ShowError("提前到货天数必须为大于0的整数。");
                    txt_day.Focus();
                    return false;
                }
 
                // 规范化显示为整数
                txt_day.EditValue = days;
                return true;
            }
            else
            {
                MsgHelper.ShowError("请输入有效的整数天数。");
                txt_day.Focus();
                return false;
            }
        }
 
        private void BtnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateDay())
                return;
 
            string _bz10 = txt_day.Text;
            string _percent = txt_lossPercent.Text;
            string _bz09 = txt_bz09.Text;
            // 保存前验证超采率
            if (!string.IsNullOrEmpty(_percent) && !ValidateLossPercent())
            {
                return;
            }
            var _obj = new
            {
                guidList = this.guidList,
                bz10 = _bz10,//提前到货天数
                percent = _percent,
                bz09 = _bz09,//后来改为iqc称重属性1要称重0不称重
            };
            try
            {
                var strJson = UtilityHelper.HttpPost("", "MesItemsManager/SetDays",
                    JsonConvert.SerializeObject(_obj));
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    MsgHelper.ShowInformation("提示:" + _rtn.rtnMsg);
                    DialogResult = DialogResult.OK;
                    Close();
                }
                else
                {
                    MsgHelper.ShowError("提示:" + _rtn.rtnMsg);
                    DialogResult = DialogResult.None;
                }
            }
            catch (Exception ex)
            {
                DialogResult = DialogResult.Cancel;
                MsgHelper.ShowError("提示:" + ex.Message);
            }
        }
 
        private void BtnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}