private void CheckUpdate() { picUpdateMsg.BackgroundImage = Properties.Resources.dot_orange; lblUpdateMsg.Text = "正在测试网络连接..."; //Thread.Sleep(6 * 1000);//测试用 //JZUpgrade.Logger log = new JZUpgrade.Logger(); //log.Logfolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log"); //log.IsUseLog = true; //log.QueueBufferSize = 5; JZUpgrade.UpdateHelperClient uhc = new JZUpgrade.UpdateHelperClient("8"); if (Yqun.Services.Agent.TestNetwork() == true) { TimerShowType = 1;//检查更新 lblUpdateMsg.Text = "正在检查更新..."; tmShow.Enabled = true; tmShow.Start(); if (uhc.IsNewest() == false) { #region 更新 tmShow.Stop(); tmShow.Enabled = false; text_Pass.Enabled = false; com_User.Enabled = false; Boolean flag = true; tmShow.Stop(); tmShow.Enabled = false; TimerShowType = 2;//下载更新 //tmShow = new System.Timers.Timer(); picUpdateMsg.BackgroundImage = Properties.Resources.dot_orange; lblUpdateMsg.Text = "正在获取更新..."; tmShow.Enabled = true; tmShow.Start(); //Thread.Sleep(6 * 1000);//测试用 #region 载更新文件 try { DataTable dt = uhc.GetNewUpdate(); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { lblUpdateMsg.Text = "正在获取更新..."; String subFolder = uhc.GetSubFolder(dt.Rows[i]["FileType"].ToString()); String path = Path.Combine(Application.StartupPath, "update\\" + subFolder); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } String file = Path.Combine(path, dt.Rows[i]["FileName"].ToString()); logger.Info(file); byte[] bytes = uhc.GetUpdateFileByID(new Guid(dt.Rows[i]["ID"].ToString())); lblUpdateMsg.Text = "正在保存更新..."; if (bytes != null) { File.WriteAllBytes(file, bytes); uhc.SaveUpdateInfo(dt.Rows[i]["ID"].ToString(), dt.Rows[i]["FileName"].ToString(), dt.Rows[i]["FileType"].ToString(), System.Convert.ToDateTime(dt.Rows[i]["CreatedServerTime"]).ToString("yyyy-MM-dd HH:mm:ss.fff")); flag = true; } if (i == dt.Rows.Count - 1) { lblUpdateMsg.Text = "获取更新完毕"; } } } else { lblUpdateMsg.Text = "获取更新完毕"; } } catch (Exception ex) { flag = false; logger.Error(ex.Message); } #endregion tmShow.Stop(); tmShow.Enabled = false; if (flag == true) { picUpdateMsg.BackgroundImage = Properties.Resources.dot_orange; lblUpdateMsg.Text = "请点击更新按钮开始更新"; button_OK.Text = "更新"; button_OK.Enabled = true; IsUpdate = true; } else { picUpdateMsg.BackgroundImage = Properties.Resources.dot_red; lblUpdateMsg.Text = "更新失败,请和管理员联系"; IsUpdate = false; } #endregion } else { tmShow.Stop(); tmShow.Enabled = false; picUpdateMsg.BackgroundImage = Properties.Resources.dot_green; lblUpdateMsg.Text = "当前系统是最新版本,请登录"; //lblUpdateMsg.Visible = false; text_Pass.Enabled = true; com_User.Enabled = true; button_OK.Text = "登录"; button_OK.Enabled = true; IsUpdate = false; } } else { tmShow.Stop(); tmShow.Enabled = false; text_Pass.Enabled = true; com_User.Enabled = true; button_OK.Text = "登录"; button_OK.Enabled = true; IsUpdate = false; picUpdateMsg.BackgroundImage = Properties.Resources.dot_red; lblUpdateMsg.Text = "网络连接失败,请检查网络配置"; } }
private void InitUpdate() { SetThreadControlEnabled(btnLogin, false); if (_CaijiCommHelper.TestServerConnection()) { bNetWorkIsConnected = true; } else { bNetWorkIsConnected = false; } SetThreadControlText(btnLogin, "更新"); ChangSYS: SetThreadControlText(lblUpdateStatus, "初始化连接服务器....."); if (bNetWorkIsConnected) { JZUpgrade.UpdateHelperClient uhc = new JZUpgrade.UpdateHelperClient("5"); if (!uhc.IsNewest()) { DataTable dt = uhc.GetNewUpdate(); bool flag = false; try { if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { SetThreadControlText(lblUpdateStatus, "正在获取更新..."); String subFolder = uhc.GetSubFolder(dt.Rows[i]["FileType"].ToString()); String path = Path.Combine(Application.StartupPath, "update\\" + subFolder); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } String file = Path.Combine(path, dt.Rows[i]["FileName"].ToString()); byte[] bytes = uhc.GetUpdateFileByID(new Guid(dt.Rows[i]["ID"].ToString())); SetThreadControlText(lblUpdateStatus, "正在保存更新..."); if (bytes != null) { File.WriteAllBytes(file, bytes); uhc.SaveUpdateInfo(dt.Rows[i]["ID"].ToString(), dt.Rows[i]["FileName"].ToString(), dt.Rows[i]["FileType"].ToString(), System.Convert.ToDateTime(dt.Rows[i]["CreatedServerTime"]).ToString("yyyy-MM-dd HH:mm:ss.fff")); } if (i == dt.Rows.Count - 1) { SetThreadControlText(lblUpdateStatus, "更新文件获取成功!"); } } SetThreadControlText(lblUpdateStatus, "获取更新完毕"); flag = true; } else { SetThreadControlText(lblUpdateStatus, "获取更新完毕"); flag = true; } } catch (Exception ex) { _Log.WriteLog(ex.StackTrace, false, true); } timerUpdate.Enabled = false; PICUpdateStatus.BackgroundImage = Properties.Resources.dot_green; IsUpdate = false; if (flag == true) { SetThreadControlText(lblUpdateStatus, "请点击更新按钮开始更新"); SetThreadControlEnabled(btnLogin, true); IsUpdate = true; } else { PICUpdateStatus.BackgroundImage = Properties.Resources.dot_red; SetThreadControlText(lblUpdateStatus, "更新失败,请和管理员联系"); IsUpdate = false; } } else { #region 工管中心MD5验证 SetThreadControlText(lblUpdateStatus, "工管中心文件验证....."); if (_CaijiCommHelper.GetIsRemotCheck()) { string ErrMsg = string.Empty; if (!GetMD5(_CaijiCommHelper.GetECode(_Module.SpecialSetting.MachineCode), out ErrMsg)) { MessageBox.Show(ErrMsg, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); SetThreadControlText(lblUpdateStatus, "系统验证失败,请联系管理员!"); return; } else { _Log.WriteLog("系统验证成功", false, false); } } #endregion SetThreadControlText(btnLogin, "登陆"); SetThreadControlEnabled(btnLogin, true); IsUpdate = false; PICUpdateStatus.Image = Kingrocket.CJ.Components.Properties.Resources.dot_green; SetThreadControlText(lblUpdateStatus, "当前是最新版本"); } } else { ChangAddress(); if (bNetWorkIsConnected) { goto ChangSYS; } else { SetThreadControlEnabled(btnLogin, true); SetThreadControlText(btnLogin, "登陆"); Yqun.Common.ContextCache.ApplicationContext.Current.ISLocalService = true; SetThreadControlText(lblUpdateStatus, "网络连接失败,转到本地登录,请联系管理员"); Yqun.Common.ContextCache.ApplicationContext.Current.ISLocalService = true; } } }