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; namespace LYFZ.Software.MainBusiness.CameraControlBook { public partial class frmContractManagement : LYFZ.Software.UI.CameraControlBook.frmContractManagement { LYFZ.BLL.BLL_ErpOrder orderBll = new BLL.BLL_ErpOrder(); public frmContractManagement() { this.likbtnUpload.Click += LikbtnUpload_Click; this.likbtnDelete.Click += LikbtnDelete_Click; this.Shown += FrmContractManagement_Shown; this.listBoxEx1.DoubleClick += ListBoxEx1_DoubleClick; } private void ListBoxEx1_DoubleClick(object sender, EventArgs e) { if (this.listBoxEx1.SelectedItem != null) { string Ord_UploadPath = this.listBoxEx1.SelectedItem.ToString(); if (!string.IsNullOrEmpty(Ord_UploadPath)) { string resData = ""; string downFilePath = Application.StartupPath + "\\Temp\\UploadFile\\" + System.IO.Path.GetFileName(Ord_UploadPath); LYFZ.ComponentLibrary.FrmLoadHandling.ExecutionDoWorkMethod(delegate (object obj, System.ComponentModel.BackgroundWorker backgroundWorker) { LYFZ.Software.MainBusiness.TCPFileTransfer tcpFile = new MainBusiness.TCPFileTransfer(); resData = tcpFile.DownloadFile(downFilePath, Ord_UploadPath, backgroundWorker); }); System.Diagnostics.Process.Start(downFilePath); } else { MessageBoxCustom.Show("未上传预约单!"); } } } private void FrmContractManagement_Shown(object sender, EventArgs e) { LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker) { backgroundWorker.ReportProgress(0, "正在加载数据..."); if (!String.IsNullOrEmpty(this._OrdNumber)) { string[] tempPaths = this.orderBll.GetContractList(this._OrdNumber); if (tempPaths != null) { this.ContractList.AddRange(tempPaths); } } }); BindContractList(); } private void LikbtnDelete_Click(object sender, EventArgs e) { string retmsg = ""; if (this.listBoxEx1.SelectedItem != null) { string Ord_UploadPath = this.listBoxEx1.SelectedItem.ToString(); if (!String.IsNullOrEmpty(Ord_UploadPath)) { LYFZ.ComponentLibrary.FrmLoadHandling.ExecutionDoWorkMethod(delegate (object obj, System.ComponentModel.BackgroundWorker backgroundWorker) { try { this.ContractList.Remove(Ord_UploadPath); if (this.orderBll.SaveContractList(this._OrdNumber, ContractList.ToArray())) { LYFZ.Software.MainBusiness.TCPFileTransfer tcpFile = new MainBusiness.TCPFileTransfer(); retmsg = tcpFile.DeleteFile(Ord_UploadPath, backgroundWorker); } else { retmsg = "更新合约数据时失败"; } } catch (Exception ex) { retmsg = ex.Message; } }); } else { retmsg = "选择的合约不正确"; } } else { retmsg = "请选择你要删除的合约文件"; } if (retmsg.Contains("成功")) { BindContractList(); } if(String.IsNullOrEmpty(retmsg)) MessageBoxCustom.Show(retmsg); } string _OrdNumber = ""; /// /// 订单号 /// public string OrdNumber { get { return _OrdNumber; } set { _OrdNumber = value; } } /// /// 当前合约集合 /// List ContractList = new List(); private void LikbtnUpload_Click(object sender, EventArgs e) { OpenFileDialog openDlg = new OpenFileDialog(); openDlg.Multiselect = false; if (openDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { DateTime startime = DateTime.Now; string filePath = openDlg.FileName.Trim(); if (filePath.Length > 0) { bool b = false; string retmsg = ""; string servicePath =String.Format("UploadFiles\\ReservationForm\\{0}\\{1}", this._OrdNumber, System.IO.Path.GetFileName(filePath)); LYFZ.ComponentLibrary.FrmLoadHandling.ExecutionDoWorkMethod(delegate (object obj, System.ComponentModel.BackgroundWorker backgroundWorker) { try { LYFZ.Software.MainBusiness.TCPFileTransfer tcpFile = new MainBusiness.TCPFileTransfer(); retmsg = tcpFile.UploadFileToServer(filePath, servicePath, backgroundWorker); if (!ContractList.Any(p => p.ToLower() == servicePath.ToLower())) { ContractList.Add(servicePath); b = this.orderBll.SaveContractList(this._OrdNumber, ContractList.ToArray()); if (!b) { retmsg = "保存合约数据时失败"; } } else { b = true; } } catch (Exception ex) { retmsg = ex.Message; b = false; } }); if (b) { BindContractList(); MessageBoxCustom.Show( retmsg + "\r\n" + "上传完成" ); } else { MessageBoxCustom.Show( "上传失败\r\n" + retmsg ); } } } } void BindContractList() { this.listBoxEx1.Items.Clear(); foreach (string filePath in ContractList) { this.listBoxEx1.Items.Add(filePath); } } } }