int DownloadDataFile( IWin32Window owner, string strFileName, string strCfgFileDir, out string strLocalFilePath, out string strError) { strError = ""; string strUrl = "http://dp2003.com/dp2Circulation/report_def/" + strFileName; PathUtil.CreateDirIfNeed(strCfgFileDir); strLocalFilePath = Path.Combine(strCfgFileDir, strFileName); string strTempFileName = Path.Combine(strCfgFileDir, "~temp_download_webfile"); if (File.Exists(strLocalFilePath) == true) { #if NO DialogResult result = MessageBox.Show(this, "本地配置文件 " + strLocalFilePath + " 已经存在,从 dp2003.com 下载同名配置文件会覆盖它。" + "\r\n\r\n确实要下载并覆盖此文件?", "ReportForm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == System.Windows.Forms.DialogResult.No) { strError = "放弃下载"; return(-1); } #endif return(0); } int nRet = WebFileDownloadDialog.DownloadWebFile( owner, strUrl, strLocalFilePath, strTempFileName, out strError); if (nRet == -1) { return(-1); } strError = "下载" + strFileName + "文件成功 :\r\n" + strUrl + " --> " + strLocalFilePath; return(0); }
// 为一个统计窗安装若干方案 // parameters: // projects 待安装的方案。注意有可能包含不适合安装到本窗口的方案 // return: // -1 出错 // >=0 安装的方案数 int InstallProjects( object form, string strWindowName, List <ProjectItem> projects, string strSource, out string strError) { strError = ""; int nInstallCount = 0; int nRet = 0; dynamic o = form; o.EnableControls(false); try { /* * string strTypeName = form.GetType().ToString(); * nRet = strTypeName.LastIndexOf("."); * if (nRet != -1) * strTypeName = strTypeName.Substring(nRet + 1); */ string strTypeName = GetTypeName(form); foreach (ProjectItem item in projects) { if (strTypeName != item.Host) { continue; } string strLocalFileName = ""; string strLastModified = ""; if (strSource == "!url") { strLocalFileName = this.DataDir + "\\~install_project.projpack"; string strTempFileName = this.DataDir + "\\~temp_download_webfile"; nRet = WebFileDownloadDialog.DownloadWebFile( this, item.Url, strLocalFileName, strTempFileName, "", out strLastModified, out strError); if (nRet == -1) { return(-1); } } else { string strLocalDir = strSource; // Uri uri = new Uri(item.Url); /* * string strPath = item.Url; // uri.LocalPath; * nRet = strPath.LastIndexOf("/"); * if (nRet != -1) * strPath = strPath.Substring(nRet); * */ string strPureFileName = ScriptManager.GetFileNameFromUrl(item.Url); strLocalFileName = PathUtil.MergePath(strLocalDir, strPureFileName); FileInfo fi = new FileInfo(strLocalFileName); if (fi.Exists == false) { strError = "目录 '" + strLocalDir + "' 中没有找到文件 '" + strPureFileName + "'"; return(-1); } strLastModified = DateTimeUtil.Rfc1123DateTimeString(fi.LastWriteTimeUtc); } // 安装Project // return: // -1 出错 // 0 没有安装方案 // >0 安装的方案数 nRet = o.ScriptManager.InstallProject( o is Form ? o : this, strWindowName, strLocalFileName, strLastModified, out strError); if (nRet == -1) { return(-1); } nInstallCount += nRet; } } finally { o.EnableControls(true); } return(nInstallCount); }
// 从 dp2003.com 安装全部方案 void InstallStatisProjects() { string strError = ""; int nRet = -1; int nInstallCount = 0; bool bDebugger = false; if (Control.ModifierKeys == Keys.Control) { bDebugger = true; } // 下载projects.xml文件 string strLocalFileName = PathUtil.MergePath(this.DataDir, "~temp_projects.xml"); string strTempFileName = PathUtil.MergePath(this.DataDir, "~temp_download_projects.xml"); try { File.Delete(strLocalFileName); } catch { } try { File.Delete(strTempFileName); } catch { } nRet = WebFileDownloadDialog.DownloadWebFile( this, "http://dp2003.com/dp2circulation/projects/projects.xml", strLocalFileName, strTempFileName, out strError); if (nRet == -1) { goto ERROR1; } // 列出已经安装的方案的URL List <string> installed_urls = new List <string>(); List <Form> newly_opened_forms = new List <Form>(); List <Form> forms = new List <Form>(); List <Type> types = new List <Type>(); types.Add(typeof(Iso2709StatisForm)); types.Add(typeof(OperLogStatisForm)); types.Add(typeof(ReaderStatisForm)); types.Add(typeof(ItemStatisForm)); types.Add(typeof(OrderStatisForm)); types.Add(typeof(BiblioStatisForm)); types.Add(typeof(XmlStatisForm)); types.Add(typeof(PrintOrderForm)); foreach (Type type in types) { // bool bNewOpened = false; var form = GetTopChildWindow(type); if (form == null) { form = (Form)Activator.CreateInstance(type); form.MdiParent = this; form.WindowState = FormWindowState.Minimized; form.Show(); newly_opened_forms.Add(form); Application.DoEvents(); } forms.Add(form); dynamic o = form; List <string> urls = new List <string>(); nRet = o.ScriptManager.GetInstalledUrls(out urls, out strError); if (nRet == -1) { goto ERROR1; } installed_urls.AddRange(urls); } // 凭条打印 { List <string> urls = new List <string>(); nRet = this.OperHistory.ScriptManager.GetInstalledUrls(out urls, out strError); if (nRet == -1) { goto ERROR1; } installed_urls.AddRange(urls); } // 框架窗口 { List <string> urls = new List <string>(); nRet = this.ScriptManager.GetInstalledUrls(out urls, out strError); if (nRet == -1) { goto ERROR1; } installed_urls.AddRange(urls); } try { SelectInstallProjectsDialog dlg = new SelectInstallProjectsDialog(); MainForm.SetControlFont(dlg, this.DefaultFont); dlg.XmlFilename = strLocalFileName; dlg.InstalledUrls = installed_urls; if (bDebugger == true) { dlg.Category = "debugger"; } dlg.StartPosition = FormStartPosition.CenterScreen; this.AppInfo.LinkFormState(dlg, "SelectInstallProjectsDialog_state"); dlg.ShowDialog(this); this.AppInfo.UnlinkFormState(dlg); if (dlg.DialogResult == System.Windows.Forms.DialogResult.Cancel) { return; } // 分宿主进行安装 foreach (Form form in forms) { // 为一个统计窗安装若干方案 // parameters: // projects 待安装的方案。注意有可能包含不适合安装到本窗口的方案 // return: // -1 出错 // >=0 安装的方案数 nRet = InstallProjects( form, GetWindowName(form), dlg.SelectedProjects, "!url", out strError); if (nRet == -1) { goto ERROR1; } nInstallCount += nRet; } // 凭条打印 { nRet = InstallProjects( this.OperHistory, "凭条打印", dlg.SelectedProjects, "!url", out strError); if (nRet == -1) { goto ERROR1; } nInstallCount += nRet; } // MainForm { nRet = InstallProjects( this, "框架窗口", dlg.SelectedProjects, "!url", out strError); if (nRet == -1) { goto ERROR1; } nInstallCount += nRet; } } finally { // 关闭本次新打开的窗口 foreach (Form form in newly_opened_forms) { form.Close(); } } MessageBox.Show(this, "共安装方案 " + nInstallCount.ToString() + " 个"); return; ERROR1: MessageBox.Show(this, strError); }