init lserp cs 5.0

This commit is contained in:
cyf
2026-07-10 15:25:05 +08:00
commit 90f3fda86a
3799 changed files with 976868 additions and 0 deletions
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xilium.CefGlue;
namespace Lskj.MyControl.BrowserSetting
{
public class BsClient : CefClient
{
public event EventHandler OnCreated;
private readonly CefLifeSpanHandler lifeSpanHandler;
private readonly CefDownloadHandler downloadHandler;
private readonly CefKeyboardHandler keyboardHandler;
private readonly CefFocusHandler focusHandler;
private readonly CefRequestHandler requestHandler;
public BsClient()
{
lifeSpanHandler = new BsLifeSpanHandler(this);
downloadHandler = new BsDownloadHandler();
keyboardHandler = new BsKeyboardHandler();
focusHandler = new BsFocusHandler();
requestHandler = new BsRequestHandler();
}
protected override CefLifeSpanHandler GetLifeSpanHandler()
{
return lifeSpanHandler;
}
protected override CefDownloadHandler GetDownloadHandler()
{
return downloadHandler;
}
protected override CefKeyboardHandler GetKeyboardHandler()
{
return keyboardHandler;
}
protected override CefFocusHandler GetFocusHandler()
{
return focusHandler;
}
protected override CefRequestHandler GetRequestHandler()
{
return requestHandler;
}
public void Created(CefBrowser cefBrowser)
{
if (OnCreated != null)
{
OnCreated(cefBrowser, EventArgs.Empty);
}
}
}
}
@@ -0,0 +1,245 @@
using CommonLib;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using System.Windows.Forms;
using Xilium.CefGlue;
namespace Lskj.MyControl.BrowserSetting
{
public class BsDownloadHandler : CefDownloadHandler
{
public bool isfirstDownLoad = true;
protected override void OnBeforeDownload(CefBrowser browser, CefDownloadItem downloadItem, string suggestedName, CefBeforeDownloadCallback callback)
{
//callback.Continue(string.Empty, true);
try
{
string tipMsg = string.Empty; int vsNum = 0;
if (string.IsNullOrWhiteSpace(downloadItem.SuggestedFileName))
{
browser.GetHost().CloseBrowser();
return;
}
string szFilename = downloadItem.Url.Substring(downloadItem.Url.LastIndexOf('/') + 1);//简单处理文件名,实际中还需要单独处理,这里有BUG
string SzFileName = HttpUtility.UrlDecode(szFilename);
string[] szName = SzFileName.Split('/');
string fileTitle = szName[szName.Length - 1];
//downfile(e.Url, e.Filename, tempPath);
if (fileTitle.Contains("?")) fileTitle = fileTitle.Substring(0, fileTitle.LastIndexOf('?'));
DataRow rowItem = GetTempletFile(fileTitle);
string topname = downloadItem.SuggestedFileName.Substring(0, downloadItem.SuggestedFileName.LastIndexOf(".") - 1);
bool isMultipleLoad = downloadItem.Url.Contains("downLoadTemp") && Regex.IsMatch(topname, @"^[+-]?\d*[.]?\d*$");
if (downloadItem.Url.StartsWith("blob"))
{
Download(downloadItem.Url, fileTitle);
return;
}
else if (rowItem != null || isMultipleLoad)
{
try
{
bool success = rowItem != null ? CheckAttachOperation(2, "", Convert.ToInt32(rowItem["fileId"]), "", 0, out tipMsg) == 1 : isMultipleLoad;
if (success)
{
Download(downloadItem.Url, fileTitle);
return;
}
else
{
MessageBox.Show(tipMsg);
//MessageUtil.Show(tipMsg);
}
}
catch (Exception ex)
{
MessageBox.Show("下载失败!\r\n" + ex.Message);
//MessageUtil.Show("下载失败!\r\n" + ex.Message);
}
}
else
{
MessageBox.Show("未找到下载项");
}
//browser.GetHost().CloseBrowser();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
protected override void OnDownloadUpdated(CefBrowser browser, CefDownloadItem downloadItem, CefDownloadItemCallback callback)
{
//if (downloadItem.IsComplete)
//{
// MessageBox.Show("下载成功");
// if (browser.IsPopup && !browser.HasDocument)
// {
// //browser.GetHost().ParentWindowWillClose();
// browser.GetHost().CloseBrowser();
// }
//}
//downloadItem.IsComplete
//if (downloadItem.IsComplete) {
// string tipMsg = string.Empty; int vsNum = 0;
// DataRow rowItem = AttachImpl.GetTempletFile(downloadItem.SuggestedFileName);
// string topname = downloadItem.SuggestedFileName.Substring(0, downloadItem.SuggestedFileName.LastIndexOf(".") - 1);
// bool isMultipleLoad = downloadItem.Url.Contains("downLoadTemp") && Regex.IsMatch(topname, @"^[+-]?\d*[.]?\d*$");
// if (rowItem != null || isMultipleLoad)
// {
// try
// {
// bool success = rowItem != null ? AttachImpl.CheckAttachOperation(2, "", Convert.ToInt32(rowItem["fileId"]), "", 0, out tipMsg) == 1 : isMultipleLoad;
// if (success)
// {
// string szFilename = downloadItem.Url.Substring(downloadItem.Url.LastIndexOf('/') + 1);//简单处理文件名,实际中还需要单独处理,这里有BUG
// string SzFileName = HttpUtility.UrlDecode(szFilename);
// string[] szName = SzFileName.Split('/');
// //downfile(e.Url, e.Filename, tempPath);
// Download(downloadItem.Url, szName[szName.Length - 1]);
// return;
// }
// else
// {
// MessageUtil.Show(tipMsg);
// }
// }
// catch (Exception ex)
// {
// MessageUtil.Show("下载失败!\r\n" + ex.Message);
// }
// }
// else
// {
// MessageUtil.Show("未找到下载项");
// }
// //browser.GetHost().CloseBrowser();
//}
}
/// <summary>
/// <para>说明:定义服务器文件地址,含文件名。客户端接收地址及文件名由客户端自行定义</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期: </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="URL">The URL.</param>
/// <param name="FileName">Name of the file.</param>
public static void Download(string URL, string FileName)
{
FrmSelectDownload frmSelectDownload = new FrmSelectDownload();
frmSelectDownload.URL = URL;
frmSelectDownload.FileName = FileName;
frmSelectDownload.Show();
//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();
//}
}
/// <summary>
/// <para>说明:根据附件名字获取附件</para>
/// <para>创建人:王一帆</para>
/// <para>创建日期:2019-12-13 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <returns>DataTable.</returns>
public static DataRow GetTempletFile(string sName)
{
string sqlValue = "select * from P_fm_FileTab where sName=@sName";
DataTable dt = SqlHelper.ExecuteDataTable(sqlValue, new SqlParameter[] { new SqlParameter("@sName", sName) });
return dt.Rows.Count > 0 ? dt.Rows[0] : null;
}
/// <summary>
/// <para>说明:</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2018-01-17 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="operType">1=上传,2=下载,3=删除,4=锁定,5=解除锁定 必填</param>
/// <param name="speciesNo">The species no.</param>
/// <param name="fileId">The file id.</param>
/// <param name="fileName">Name of the file.</param>
/// <param name="fileSize">Size of the field.</param>
/// <param name="tipMsg">返回提示信息</param>
/// <returns>System.Int32.</returns>
/// <exception cref="System.NotImplementedException"></exception>
public static int CheckAttachOperation(int operType, string speciesNo, int fileId, string fileName, int fileSize, out string tipMsg)
{
try
{
SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000);
pMsg.Direction = ParameterDirection.Output;
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4);
returnValue.Direction = ParameterDirection.ReturnValue;
SqlParameter[] param =
{
new SqlParameter("@opertype",SqlDbType.Int),
new SqlParameter("@operatorid",SqlDbType.Int),
new SqlParameter("@operatorname",SqlDbType.VarChar,50),
new SqlParameter("@fileSpecisNo",SqlDbType.VarChar,50),
new SqlParameter("@fileid",SqlDbType.Int),
new SqlParameter("@filename",SqlDbType.VarChar,200),
new SqlParameter("@filesize",SqlDbType.Int),
pMsg,
returnValue
};
param[0].Value = operType;
param[1].Value = ERPInfo.Instance.EmployeeId;
param[2].Value = ERPInfo.Instance.EmployeeName;
param[3].Value = speciesNo;
param[4].Value = fileId;
param[5].Value = fileName;
param[6].Value = fileSize;
DataSet ds = SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "p_SystemAttachOperation", "attach", param);
tipMsg = pMsg.Value + "";
return Convert.ToInt32(returnValue.Value + "");
}
catch (Exception)
{
}
tipMsg = string.Empty;
return 1;
}
}
}
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xilium.CefGlue;
namespace Lskj.MyControl.BrowserSetting
{
class BsFocusHandler : CefFocusHandler
{
protected override bool OnSetFocus(CefBrowser browser, CefFocusSource source)
{
return true;//返回 false 以允许设置焦点,或返回 true 以取消设置焦点
}
}
}
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Xilium.CefGlue;
namespace Lskj.MyControl.BrowserSetting
{
public class BsKeyboardHandler : CefKeyboardHandler
{
protected override bool OnKeyEvent(CefBrowser browser, CefKeyEvent keyEvent, IntPtr osEvent)
{
switch (keyEvent.WindowsKeyCode)
{
case 123://功能键 F12 的KeyCode
if (keyEvent.EventType.Equals(CefKeyEventType.RawKeyDown))
{
//创建 CefWindowInfo 对象
var wi = CefWindowInfo.Create();
//开发者工具以独立窗口弹出 窗口名 DevTools
wi.SetAsPopup(IntPtr.Zero, "DevTools");
//弹出开发者工具
browser.GetHost().ShowDevTools(wi, new BsClient(), new CefBrowserSettings(), new CefPoint(0, 0));
}
break;
case 116://功能键 F5 的KeyCode
if (keyEvent.EventType.Equals(CefKeyEventType.RawKeyDown))
{
//刷新
browser.Reload();
}
break;
case 27:
if (keyEvent.EventType.Equals(CefKeyEventType.RawKeyDown))
{
browser.GetMainFrame().ExecuteJavaScript("{document.webkitExitFullscreen()}", browser.GetMainFrame().Url, 0);
}
break;
case 113://功能键 F2 的KeyCode
if (keyEvent.EventType.Equals(CefKeyEventType.RawKeyDown))
{
try
{
//弹出当前网址
string NUrl = browser.GetMainFrame().Url + "";
MessageBox.Show(string.Format("Url:{0}已复制到粘贴板", NUrl));
System.Windows.Forms.Clipboard.SetText(NUrl);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
break;
}
return false;
}
}
}
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xilium.CefGlue;
namespace Lskj.MyControl.BrowserSetting
{
public class BsLifeSpanHandler : CefLifeSpanHandler
{
private BsClient BsClient;
public BsLifeSpanHandler(BsClient bsClient)
{
BsClient = bsClient;
}
protected override void OnAfterCreated(Xilium.CefGlue.CefBrowser browser)
{
base.OnAfterCreated(browser);
BsClient.Created(browser);
}
protected override void OnBeforeClose(CefBrowser browser)
{
base.OnBeforeClose(browser);
}
}
}
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xilium.CefGlue;
namespace Lskj.MyControl.BrowserSetting
{
public class BsRequestHandler : CefRequestHandler
{
protected override CefResourceRequestHandler GetResourceRequestHandler(CefBrowser browser, CefFrame frame, CefRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
{
return null;
}
protected override bool OnBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, bool userGesture, bool isRedirect)
{
//DemoApp.BrowserMessageRouter.OnBeforeBrowse(browser, frame);
return base.OnBeforeBrowse(browser, frame, request, userGesture, isRedirect);
}
protected override void OnRenderProcessTerminated(CefBrowser browser, CefTerminationStatus status)
{
//browser.StopLoad();
browser.Reload();
//DemoApp.BrowserMessageRouter.OnRenderProcessTerminated(browser);
}
}
}
@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
namespace Lskj.MyControl.BrowserSetting
{
public static class HttpTools
{
public static CookieContainer cookie = new CookieContainer(); // 用于记录访问网页时cookie数据
public static CookieCollection cookieCollection;
private static string ContentType = string.Empty;// "application/x-www-form-urlencoded";
private static string Accept = string.Empty;//"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
private static string UserAgent = string.Empty;//"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14";
public enum Method
{
POST = 0,
GET = 1
}
public static void setting(string contentType, string accept, string userAgent)
{
ContentType = contentType;
Accept = accept;
UserAgent = userAgent;
}
/// <summary>
/// post数据到指定的网址,获取cookie数据,和返回页
/// </summary>
public static HttpWebResponse Post(string url, string postData, Dictionary<string, string> dic, Method method)
{
return Post(url, postData, dic, method, out cookieCollection);
}
/// <summary>
/// post数据到指定的网址,获取cookie数据,和返回页
/// </summary>
public static HttpWebResponse Post(string url, string postData, Dictionary<string, string> dic, Method method, out CookieCollection cookieCollection)
{
HttpWebResponse httpWebResponse = null;
try
{
HttpWebRequest httpWebRequest;
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.CookieContainer = cookie;
httpWebRequest.ContentType = ContentType;
httpWebRequest.Referer = url;
httpWebRequest.Accept = Accept;
httpWebRequest.UserAgent = UserAgent;
httpWebRequest.Method = method == Method.POST ? "POST" : "GET";
byte[] byteRequest = null;
if (!string.IsNullOrEmpty(postData))
{
byteRequest = Encoding.Default.GetBytes(postData);
httpWebRequest.ContentLength = byteRequest.Length;
}
else
{
StringBuilder builder = new StringBuilder();
int i = 0;
foreach (var item in dic)
{
if (i > 0)
builder.Append("&");
builder.AppendFormat("{0}={1}", item.Key, item.Value);
i++;
}
byteRequest = Encoding.UTF8.GetBytes(builder.ToString());
httpWebRequest.ContentLength = byteRequest.Length;
}
Stream stream = httpWebRequest.GetRequestStream();
stream.Write(byteRequest, 0, byteRequest.Length);
stream.Close();
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);
string html = streamReader.ReadToEnd();
streamReader.Close();
responseStream.Close();
cookieCollection = cookie.GetCookies(new Uri(url));
return httpWebResponse;
}
catch (Exception ex)
{
cookieCollection = null;
return httpWebResponse;
}
}
}
}
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Lskj.MyControl.BrowserSetting
{
public class NativeMethod
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
}
}