using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Lskj.Control; using Lskj.Util; using Lskj.Model; using Lskj.Control.Model; using Lskj.Business.Impl; using Lskj.Business; using System.Web; using System.Runtime.InteropServices; using Lskj.IPersonnelConnection; namespace Lskj.PubBrower2 { public partial class FrmMain : BaseForm { public DynamicPubBrowerModel PubBrowerModel; public FrmMain() { InitializeComponent(); } /// /// 说明:窗体加载时 /// 创建人:龚宇超 /// 创建日期:2017-09-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The instance containing the event data. public void OnLoad() { WaitForm.ShowForm(); try { if (PubBrowerModel.isCalSize) { this.Height = Convert.ToInt32(Lskj.Main.Model.Manager.frmHeight * PubBrowerModel.PerHeight); this.Width = Convert.ToInt32(Screen.PrimaryScreen.WorkingArea.Width * PubBrowerModel.PerWidth); this.Location = new Point((Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2, (Lskj.Main.Model.Manager.frmHeight - this.Height) / 2); } bool isPostFlag = this.PubBrowerModel.isPostFlag == 1; this.PubBrowerModel.Privilege = PubBrowerModel.ModuleId > 0 ? BaseImpl.GetUserPurviewsByMenuId(PubBrowerModel.ModuleId + "") + "" : BaseImpl.GetUserPurviewsByMenuCode(PubBrowerModel.ModuleCode) + ""; string urlEnd = string.Empty; if (isPostFlag) { urlEnd = string.IsNullOrEmpty(PubBrowerModel.UrlParame) ? "" : HttpUtility.UrlEncode(PubBrowerModel.UrlParame); } else { urlEnd = string.IsNullOrEmpty(PubBrowerModel.UrlParame) ? ReplaceHelper.ReplaceUserInfo(PubBrowerModel.ModuleCode) : HttpUtility.UrlEncode(PubBrowerModel.UrlParame); } string url = PubBrowerModel.BetweenDLLCoid != null && PubBrowerModel.BetweenDLLCoid.StartsWith("http") ? PubBrowerModel.BetweenDLLCoid + urlEnd : urlEnd.StartsWith("http") ? PubBrowerModel.BetweenDLLCoid + urlEnd : SystemInfo.Instance.OAUrl + PubBrowerModel.BetweenDLLCoid + urlEnd; if (url.Contains("{iPersonnelAllowInformation}") || url.Contains("{iPersonnelEncryptedMessage}")) { //url = ReplaceHelper.ReplaceIPersonnel(url, SystemInfo.Instance.iPersonnelAllowInformation, SystemInfo.Instance.iPersonnelCustomerId, SystemInfo.Instance.iPersonnelPrivateKey); url = PersonnelReplaceHelper.UrlEncryption(url, SystemInfo.Instance.iPersonnelAllowInformation, SystemInfo.Instance.iPersonnelCustomerId, SystemInfo.Instance.iPersonnelPrivateKey, ERPInfo.Instance.UserLinkPhone); } if (url.Contains("{CDSBLimsLoginNo}")) { url = PersonnelReplaceHelper.CDSBLimsUrlEncryption(url, ERPInfo.Instance.LoginAccount, SystemInfo.Instance.CDSBLimsPrivateKey); } bool downLoadFlag = this.PubBrowerModel.downLoadFlag == 1; int RightKeyFlag = this.PubBrowerModel.RightKeyFlag; if (downLoadFlag) { this.Close(); url = HttpUtility.UrlDecode(url); url = url.Replace("%2f", "/"); url = url.Replace("#", "%23"); //WebBrowser browserNew = new WebBrowser();//点击下载的页面 //browserNew.Navigate(url); string[] newurl = url.Split('?'); string szFilename = newurl[0].Substring(newurl[0].LastIndexOf('/') + 1);//简单处理文件名,实际中还需要单独处理,这里有BUG //string SzFileName = HttpUtility.UrlDecode(szFilename); string[] szName = szFilename.Split('/'); string fileTitle = szName[szName.Length - 1]; Download(url, fileTitle); } else { this.Opacity = 100D; previewFrm previewFrm = new previewFrm(); previewFrm.moduleWebView.PubBrowerModel = this.PubBrowerModel; previewFrm.Dock = DockStyle.Fill; previewFrm.OnLoad(url, RightKeyFlag); this.Controls.Add(previewFrm); } } catch (Exception ex) { LogHelper.Instance.WriteError(ex, "浏览器dll"); //MessageUtil.Show(ex.Message + "\r\n" + ex.StackTrace); string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } finally { Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(this); } WaitForm.HideForm(); } #region 内存回收 [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")] public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize); /// /// 说明:释放内存 /// 创建人:王一帆 /// 创建日期:2021-09-29 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// /// public static void ClearMemory() { GC.Collect(); GC.WaitForPendingFinalizers(); if (Environment.OSVersion.Platform == PlatformID.Win32NT) { //FrmMian为我窗体的类名 FrmMain.SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1); } } #endregion /// /// 说明:定义服务器文件地址,含文件名。客户端接收地址及文件名由客户端自行定义 /// 创建人:王一帆 /// 创建日期: /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The URL. /// Name of the file. public static void Download(string URL, string FileName) { FrmSelectDownload frmSelectDownload = new FrmSelectDownload(); frmSelectDownload.URL = URL; frmSelectDownload.FileName = FileName; // frmSelectDownload.TopMost = true; frmSelectDownload.ShowDialog(); //SaveFileDialog saveFileDialog = new SaveFileDialog(); //saveFileDialog.FileName = FileName; //saveFileDialog.Title = "下载模板文件到"; //saveFileDialog.RestoreDirectory = true; ////点了保存按钮进入 //if (saveFileDialog.ShowDialog() == DialogResult.OK) //{ // string localFilePath = System.IO.Path.GetFullPath(saveFileDialog.FileName);//获得文件路径,含文件名 // string fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1);//获取文件名,不带路径 // string FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));//获取文件路径,不带文件名 // FrmDownload frm = new FrmDownload(URL, FileName, localFilePath); // frm.Show(); //} } } }