Files
2026-07-10 15:25:05 +08:00

132 lines
4.6 KiB
C#

namespace LSFileClient
{
using LSServerService;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
public partial class frmSmartClient : FrmBase
{
public frmSmartClient() : this(null, "", "", "1")
{
}
public frmSmartClient(LSClientMain _clientMain, string _serverIP, string _databaseName, string _isConsumer) : base(_clientMain, _serverIP, _databaseName, _isConsumer)
{
//MessageBox.Show("OK");
this.components = null;
this.isConsumer = _isConsumer;
this.InitializeComponent();
}
private void frmSmartClient_FormClosed(object sender, FormClosedEventArgs e)
{
base.clientMain.clientSocket.CloseSocket();
base.clientMain.FreeAllResouce();
}
private void frmSmartClient_Load(object sender, EventArgs e)
{
base.Width = base.Height = 0;
LSGlobleVariable.masterForm = this;
LSGlobleVariable.hWndMain = base.Handle;
FrmBase.SendMessage(LSParamsFormatter.mainHandle, 1298, base.Handle, IntPtr.Zero);
base.clientMain.clientSocket.SocketCloseEvent += new LSASyncSocket.SocketCloseEventHandle(this.onClientSocketClose);
C2S_SmartClientLogin structObj = new C2S_SmartClientLogin(true);
structObj.header.dwUserId = (uint) LSParamsFormatter.userId;
try
{
base.clientMain.Send(structObj);
}
catch (Exception exception)
{
PubUtils.WriteLog("LSClientMain.frmSmartClient_Load error: {0}", new object[] { exception });
FrmBase.SendMessage(LSParamsFormatter.mainHandle, 1305, base.Handle, IntPtr.Zero);
}
}
protected override bool hasParsedMsg(byte[] byteData, LSSocket client, MsgHeader header)
{
if (header.dwType == 69634)
{
try
{
C2S2C_SmartResponse structure = (C2S2C_SmartResponse) PubUtils.BytesToStruct(byteData, typeof(C2S2C_SmartResponse));
FrmBase.COPYDATASTRUCT lParam = new FrmBase.COPYDATASTRUCT {
dwData = (IntPtr) structure.dwFieldCount,
cbData = ((int) structure.dwDataLen) + 1
};
int index = Marshal.SizeOf(structure);
lParam.lpData = Encoding.Default.GetString(byteData, index, (int) structure.dwDataLen);
FrmBase.SendCopyData(LSParamsFormatter.mainHandle, 74, IntPtr.Zero, ref lParam);
}
catch (Exception exception)
{
PubUtils.WriteLog("LSClientMain.hasParsedMsg error: {0}", new object[] { exception });
}
return true;
}
return false;
}
private void onClientSocketClose(LSASyncSocket AsyncSocket)
{
try
{
FrmBase.SendMessage(LSParamsFormatter.mainHandle, LSCustomWinMsg.READYTOCLOSE, IntPtr.Zero, IntPtr.Zero);
base.Close();
}
catch (Exception exception)
{
PubUtils.WriteLog("LSClientMain.onClientSocketClose error: {0},", new object[] { exception });
}
}
private void reConnect()
{
PubUtils.WriteLog("LSClientMain.reConnect error: 链接被关闭,即将重链", new object[0]);
for (int i = 0; i < 1000000; i++)
{
base.clientMain.clientSocket.reConnect();
int num2 = 0;
while (num2 < 20)
{
if (base.clientMain.checkSocketState())
{
break;
}
num2++;
Thread.Sleep(1000);
}
}
}
private void timer1_Tick(object sender, EventArgs e)
{
this.timer1.Enabled = false;
base.Visible = false;
}
protected override void WndProc(ref Message msg)
{
if (msg.Msg == LSCustomWinMsg.CONNECT_ERROR)
{
MessageBox.Show("连接服务器失败,请联系管理员!");
FrmBase.SendMessage(LSParamsFormatter.mainHandle, 1305, base.Handle, IntPtr.Zero);
base.Close();
}
else
{
base.WndProc(ref msg);
}
}
}
}