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; } } }