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

200 lines
7.5 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using CommonLib;
using LSServerService;
namespace LSFileClient
{
public partial class frmDelete : LSFileClient.FrmBase
{
public frmDelete()
{
this.components = null;
InitializeComponent();
}
private string serverIP;
private string databaseName;
//public frmDelete(LSClientMain _clientMain, string _serverIP, string _databaseName)
// : base(_clientMain, _serverIP, _databaseName)
//{
// this.components = null;
// serverIP = _serverIP;
// databaseName = _databaseName;
// InitializeComponent();
//}
public frmDelete(LSClientMain _clientMain, string _serverIP, string _databaseName, string _isConsumer)
: base(_clientMain, _serverIP, _databaseName, _isConsumer)
{
this.components = null;
//this.isConsumer = _isConsumer;
serverIP = _serverIP;
databaseName = _databaseName;
try
{
string file = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)), "SystemResources.ini");
string connectionStr = "";
if (File.Exists(file))
{
string lastIPPort = string.Format("{0}:{1}", IniUtil.Read(file, "LocalLastIP"), IniUtil.Read(file, "LocalLastPort"));
string downloadAESStrKey = string.Format("DownloadAESStr_{0}", lastIPPort);
string[] downloadAESStrValue = IniUtil.Read(file, downloadAESStrKey).Split('^');
string downloadAESStr = downloadAESStrValue.Length == 2 ? downloadAESStrValue[1] : "";
string configFlag = IniUtil.Read(file, "FrmConfigFlag");
if (configFlag.Equals("1"))
{
//string args = AESUtil.Decrypt(File.ReadAllText(file));
if (!string.IsNullOrEmpty(downloadAESStr))
{
string args = AESUtil.Decrypt(downloadAESStr);
string[] controlAfgs = args.Split('^');
if (controlAfgs != null && controlAfgs.Length == 5)
{
connectionStr = "Server=" + controlAfgs[0] + ";Database=" + controlAfgs[1] + ";Persist Security Info=True;User ID=" + controlAfgs[2] + ";Password=" + controlAfgs[3] + ";Connection Timeout=5;MultipleActiveResultSets=true";
}
}
}
else
{
connectionStr = DBConfig.Instance.GetConStr();
}
}
if (string.IsNullOrEmpty(connectionStr))
{
connectionStr = DBConfig.Instance.GetConStr();
}
DBConfig.Instance.CreateNewConnection(connectionStr);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
this.isConsumer = _isConsumer;
this.InitializeComponent();
}
private void frmDelete_Load(object sender, EventArgs e)
{
base.Width = base.Height = 0;
C2S_DeleteFile structObj = new C2S_DeleteFile(true);
int succCount = 0;
int failCount = 0;
try
{
if (SqlHelper.CreateConnection(serverIP, databaseName))
{
foreach (int ids in LSParamsFormatter.fileIds)
{
structObj.dwFileId = ids;
if (base.clientMain.clientSocket.Send(structObj))
{
succCount += 1;
try
{
int result = SqlHelper.ExecuteNonQuery(CommandType.Text, string.Format("delete P_fm_FileTab where fileid='{0}'", ids));
}
catch (Exception)
{
}
}
else
failCount += 1;
}
}
SqlHelper.conn.Close();
MessageBox.Show("删除文件完成" + succCount.ToString() + "个成功," + failCount.ToString() + "个失败");
}
catch (Exception ex)
{
//MessageBox.Show("删除出错!"+ex.Message);
FrmBase.SendMessage(LSParamsFormatter.mainHandle, LSCustomWinMsg.DELETEERROR, IntPtr.Zero, IntPtr.Zero);
}
FrmBase.SendMessage(LSParamsFormatter.mainHandle, LSCustomWinMsg.DELETECOMPLETED, IntPtr.Zero, IntPtr.Zero);
FrmBase.SendMessage(LSGlobleVariable.hWndMain, LSCustomWinMsg.CLOSE_WINDOW, IntPtr.Zero, IntPtr.Zero);
this.Close();
this.Dispose();
}
protected override void WndProc(ref Message msg)
{
if (msg.Msg == LSCustomWinMsg.SUCCESS_MESSAGE)
{
base.setItemState(2);
}
else
{
int wParam;
if (msg.Msg == LSCustomWinMsg.FAIL_MESSAGE)
{
wParam = (int)msg.WParam;
if (wParam == ErrorType.FILE_BEEN_LOCKED)
{
base.setItemState(3, "附件已经被锁定,");
}
else
{
base.setItemState(3);
}
}
else if (msg.Msg == LSCustomWinMsg.CONNECT_ERROR)
{
MessageBox.Show("连接服务器失败,请联系管理员!");
}
else
{
if (msg.Msg == LSCustomWinMsg.DELETEFILE_MESSAGE)
{
wParam = (int)msg.WParam;
int lParam = (int)msg.LParam;
if (wParam > 0)
{
if (wParam == ErrorType.FILE_BEEN_LOCKED)
{
MessageBox.Show("附件已经被锁定,请联系管理员!");
}
else
{
MessageBox.Show("删除出错!");
}
}
else
{
//base.m_currentNodeData = base.getDataById(lParam);
//if (base.m_currentNodeData != null)
//{
// ListViewItem item = base.m_currentNodeData.item;
// base.removeItem(item);
//}
//MessageBox.Show("删除成功.");
}
}
base.WndProc(ref msg);
}
}
}
private void frmDelete_FormClosed(object sender, FormClosedEventArgs e)
{
base.clientMain.clientSocket.CloseSocket();
base.clientMain.FreeAllResouce();
}
}
}