孙世强
2025-11-20 c82db51f2df281afe54c08dd55cb049693e5a889
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using 补片.DAL;
 
namespace 补片
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }
 
        bool isShow = true;
 
        private void Button_MouseEnter(object sender, EventArgs e)
        {
            ((Control)sender).BackColor = Color.FromArgb(213, 234, 255);
            ((Control)sender).ForeColor = Color.FromArgb(92, 173, 254);
        }
        private void Button_MouseLeave(object sender, EventArgs e)
        {
            ((Control)sender).BackColor = Color.FromArgb(92, 173, 254);
            ((Control)sender).ForeColor = Color.FromArgb(213, 234, 255);
        }
 
        private void FrmMain_Load(object sender, EventArgs e)
        {
            LoadSet();
            txtShow("", 1);
            this.Text = BuPianBll.MainName;
            lblTitle.Text = BuPianBll.MainName;
        }
 
        private void lblSend_Click(object sender, EventArgs e)
        {
            try
            {
                BuPianBll.updatebupian();
                txtShow("补片信息下发成功!",0,2,true);
                #region 工程记录
                gongchenglog.Insert(new gongchenglog
                {
                    gongchengNo = "",
                    caozuo = "补片程序:补片信息下发",
 
                    caozuoxiangqing = "补片信息下发成功",
                });
                #endregion
            }
            catch (Exception ex)
            {
                txtShow(ex.Message, 0, 1);
                txtShow("补片信息下发失败!", 0, 1, true);
                #region 工程记录
                gongchenglog.Insert(new gongchenglog
                {
                    gongchengNo = "",
                    caozuo = "补片程序:补片信息下发",
                    caozuoxiangqing = "补片信息下发失败!!!",
                    StrRemark = ex.Message.ToString().Replace('\'', '_').Replace('@', '^')
                });
                #endregion
                return;
            }
        }
 
        void txtShow(string msg,int typeN = 0,int colorIndex = 5,bool isBold = false)
        {
            if (typeN == 0)
            {
                //string showMsg = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "  消息:" + msg + "\r\n";
                ////向textbox追加内容
                //txtSendMSG.AppendText(showMsg);
 
                InsertControl(msg,colorIndex, isBold);
            }
            else
            {
                
                //InsertControl("服务器IP:" + BuPianBll.ServerIP, colorIndex);
                //InsertControl("MES服务器IP:" + BuPianBll.MesServerIP, colorIndex);
                InsertControl("所在位置:" + BuPianBll.Position, colorIndex);
                //InsertControl("版本号:" + BuPianBll.Version, colorIndex);
                InsertControl("程序标题:" + BuPianBll.MainName + "   版本号:" + BuPianBll.Version, colorIndex );
                if (isShow)
                {
                    InsertControl("程序配置信息", 2,true);
                    isShow = false;
                }
            }
        }
 
        
 
        private void lblSetParam_Click(object sender, EventArgs e)
        {
            //txtShow("点击了设置");
            FrmSet fs = new FrmSet();
            fs.ShowDialog();
            if (fs.DialogResult == DialogResult.OK)
            {
                lblTitle.Text = BuPianBll.MainName;
                this.Text = BuPianBll.MainName;
                txtShow("",1);
                txtShow("设置成功",0,2,true);
            }
            
        }
 
        private void txtSendMSG_TextChanged(object sender, EventArgs e)
        {
            this.txtSendMSG.SelectionStart = this.txtSendMSG.Text.Length;
            this.txtSendMSG.SelectionLength = 0;
            this.txtSendMSG.ScrollToCaret();
        }
 
        Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        void LoadSet()
        {
            BuPianBll.MesServerIP = cfa.AppSettings.Settings["MesServerIP"].Value;
            BuPianBll.ServerIP = cfa.AppSettings.Settings["ServerIP"].Value;
            BuPianBll.MainName = cfa.AppSettings.Settings["MainName"].Value;
            BuPianBll.Version = cfa.AppSettings.Settings["Version"].Value;
            BuPianBll.Position = cfa.AppSettings.Settings["Position"].Value;
        }
 
        private void btnClose_Click(object sender, EventArgs e)
        {
            CloseFrom();
        }
 
        static bool EntryDilag(string message, string cap = "操作确认提示", int icon = 0)
        {
            return System.Windows.Forms.MessageBox.Show(message, cap, System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes;
        }
 
 
        void InsertControl(string msg, int colortype = 5, bool isBold = false)
        {
            Color cl = new Color();
            switch (colortype)
            {
                case 1:
                    cl = Color.Red;
                    break;
                case 2:
                    cl = Color.Green;
                    break;
                case 3:
                    cl = Color.Orange;
                    break;
                default:
                    cl = Color.FromArgb(92, 173, 254);
                    break;
            }
            Panel pl = new Panel();
            //pl.Width = palContent.Width;
            pl.Height = 30;
            pl.Dock = DockStyle.Top;
            //pl.BorderStyle = BorderStyle.FixedSingle;
 
            Label lb2 = new Label();
            lb2.Text = msg;
            //lb2.BackColor = Color.Blue;
            lb2.ForeColor = cl;
            lb2.Dock = DockStyle.Fill;
            if (isBold) { 
            lb2.Font = new Font(this.Font, FontStyle.Bold);
            }
            //lb2.AutoSize = true;
            
 
            Label lb = new Label();
            lb.Text = DateTime.Now.ToString("MM-dd HH:mm:ss");
            //lb.BackColor = Color.Black;
            lb.ForeColor = Color.Black;
            lb.Dock = DockStyle.Left;
            lb.AutoSize = true;
            
            pl.Controls.Add(lb2);
            pl.Controls.Add(lb);
 
            palContent.Controls.Add(pl);
        }
 
        private void lblTitle_Click(object sender, EventArgs e)
        {
           
        }
 
        private void lblTitle_DoubleClick(object sender, EventArgs e)
        {
            btnSet.Visible = !btnSet.Visible;
        }
 
        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if(!CloseFrom())
                e.Cancel = true;
        }
 
        bool CloseFrom() {
            if (EntryDilag("是否确认退出当前程序?"))
            {
                #region 工程记录
                gongchenglog.Insert(new gongchenglog
                {
                    gongchengNo = "",
                    caozuo = "补片程序:程序退出",
                    caozuoxiangqing = "补片程序:程序退出",
                    StrRemark = "程序名:" + BuPianBll.MainName + " MESIP:" + BuPianBll.MesServerIP + "  ERPIP:" + BuPianBll.ServerIP + " 版本号:" + BuPianBll.Version + " 位置信息:" + BuPianBll.Position
                }) ;
                #endregion
 
                System.Environment.Exit(0);
            }
            return false;
 
        }
    }
}