123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using WFtpClient;
- namespace LYFZ.Software.MainBusiness.MultipleFileImport
- {
- public partial class frmMultipleFileImport : LYFZ.ComponentLibrary.BaseContentsFormMain
- {
- string selectType = "";
- delegate void FormShowMessage(enumImportMultipFieForm StatusCode, object objectData);
- FormShowMessage delegateMessage;
- public frmMultipleFileImport()
- {
- InitializeComponent();
- this.Shown += frmMultipleFileImport_Shown;
- this.FormClosing += FrmMultipleFileImport_FormClosing;
- btn_Faild.Click += btn_Click;
- btn_Detail.Click += btn_Click;
- btn_Start.Click += btn_Click;
- btn_Stop.Click += btn_Click;
- btn_AllStart.Click += btn_Click;
- btn_AllStop.Click += btn_Click;
- btn_Delete.Click += btn_Click;
- /*(btn_All.Click += btn_Click;
-
- btn_Success.Click += btn_Click;
- btn_upLoad.Click += btn_Click;*/
- //frmMultipFileImportThread.GetSingleton().SingletonThreadImportFileFormEvent += frmMultipleFileImport_SingletonThreadImportFileFormEvent;
- delegateMessage = new FormShowMessage(FormShowMessageHandler);
- cb_AutoCheck.Click += cb_AutoCheck_Click;
- cb_AutoCheck.Checked = Properties.Settings.Default.bImportAutoUp;
- cb_AutoShutDown.Click += Cb_AutoShutDown_Click;
-
- }
- private void FrmMultipleFileImport_FormClosing(object sender, FormClosingEventArgs e)
- {
- NewMultipFileImport.NewMultipFileImport.RemoveAction("DetailInfo");
- }
- private void Cb_AutoShutDown_Click(object sender, EventArgs e)
- {
- Model.Model_Config.bAutoShutDown = cb_AutoShutDown.Checked;
- }
- void cb_AutoCheck_Click(object sender, EventArgs e)
- {
- Properties.Settings.Default.bImportAutoUp = cb_AutoCheck.Checked;
- Properties.Settings.Default.Save();
-
- }
- void FormShowMessageHandler(enumImportMultipFieForm StatusCode, object objectData)
- {
- switch (StatusCode)
- {
- case enumImportMultipFieForm.AddList:
- ReLoadData(selectType);
- break;
- case enumImportMultipFieForm.BackNext:
- BindDataInfo(objectData);
- break;
- }
- BindDeleteButtonShowOrHide();
- }
- void MultipFileDataHandler(NewMultipFileImport.MultipFileReport report)
- {
- switch (report.importMultipType)
- {
- case NewMultipFileImport.EnumImportMultipType.AddList:
- ReLoadData(selectType);
- break;
- case NewMultipFileImport.EnumImportMultipType.BackNext:
- BindDataInfo(report.currentGroupMod);
-
- break;
- }
- BindDeleteButtonShowOrHide();
- }
- //void frmMultipleFileImport_SingletonThreadImportFileFormEvent(enumImportMultipFieForm StatusCode, object objectData)
- //{
- // try
- // {
- // this.Invoke(delegateMessage, StatusCode, objectData);
- // }
- // catch
- // {
- // }
- //}
- void frmMultipleFileImport_Shown(object sender, EventArgs e)
- {
- ReLoadData("ALL");
- NewMultipFileImport.NewMultipFileImport.AddAction("DetailInfo", MultipFileDataHandler);
- }
- private void frmMultipleFileImport_Load(object sender, EventArgs e)
- {
-
- }
- void BindDeleteButtonShowOrHide()
- {
- if (LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.multipFileReport.bStartThread)
- {
- btn_Delete.Enabled = false;
- }
- else
- {
- btn_Delete.Enabled = true;
- }
- }
- void btn_Click(object sender, EventArgs e)
- {
- //ReLoadData(((LYFZ.ComponentLibrary.ButtonEx)sender).Tag.ToString());
- List<frmFileImportModel> temp_Pools;
- switch(((LYFZ.ComponentLibrary.ButtonEx)sender).Tag.ToString())
- {
- case "Error":
- LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.multipFileReport.SetClearErrorData();
- ReLoadData("ALL");
- break;
- case "Delete":
- if (listViewEx1.SelectedItems.Count > 0)
- {
- if (MessageBoxCustom.Show("是否确定删除当前导片队列?", "提示", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
- {
- LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.multipFileReport.DeleteModel((frmFileImportModel)listViewEx1.SelectedItems[0].Tag);
- ReLoadData("ALL");
- }
- }
- break;
- case "Detail":
- if(listViewEx1.SelectedItems.Count>0)
- {
- frmMultipleFileImportDetail detail = new frmMultipleFileImportDetail();
- detail.BindImportModel((frmFileImportModel)listViewEx1.SelectedItems[0].Tag);
- detail.StartPosition = FormStartPosition.CenterScreen;
- detail.Show();
- }
- else
- {
- MessageBoxCustom.Show("请选择相应的栏目查看详情");
- }
- break;
- case "Stop":
- if (listViewEx1.SelectedItems.Count > 0)
- {
- btn_Delete.Enabled = true;
- ((frmFileImportModel)listViewEx1.SelectedItems[0].Tag).errorMsg = "暂停上传";
- foreach (var path in ((frmFileImportModel)listViewEx1.SelectedItems[0].Tag).local_Path)
- {
- if (path.upload_Msg == "正在上传" || path.code == 1)
- {
- continue;
- }
- else if (path.code == 0)
- {
- path.code = -1;
- path.upload_Msg = "暂停上传";
- }
- }
- LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.RestartThread(((frmFileImportModel)listViewEx1.SelectedItems[0].Tag));
- }
- else
- {
- MessageBoxCustom.Show("请选择进行中的队列进行暂停导片!");
- }
- //frmMultipFileImportThread.GetSingleton().
- break;
- case "Start":
- if (listViewEx1.SelectedItems.Count > 0)
- {
-
- ((frmFileImportModel)listViewEx1.SelectedItems[0].Tag).Success=false;
- ((frmFileImportModel)listViewEx1.SelectedItems[0].Tag).errorMsg = "";
- foreach (var path in ((frmFileImportModel)listViewEx1.SelectedItems[0].Tag).local_Path)
- {
- if ((path.upload_Msg == "暂停上传" && path.code == -1))
- {
- path.code = 0;
- path.upload_Msg = "等待上传";
- }
- else
- {
- }
- }
- NewMultipFileImport.NewMultipFileImport.StartThread();
- //frmMultipFileImportThread.GetSingleton().RestartThread((frmFileImportModel)listViewEx1.SelectedItems[0].Tag);
- }
- else
- {
- MessageBoxCustom.Show("请选择指定队列进行导片!");
- }
- break;
- case "AllStart":
- temp_Pools = NewMultipFileImport.NewMultipFileImport.GetFileImportList();
- foreach (frmFileImportModel mod in temp_Pools)
- {
- mod.Success = false;
- mod.errorMsg = "";
- foreach (var path in mod.local_Path)
- {
- if (path.upload_Msg == "暂停上传" && path.code == -1)
- {
- path.code = 0;
- path.upload_Msg = "";
- }
- else
- {
- }
- }
- }
- btn_Delete.Enabled = false;
- //frmMultipFileImportThread.GetSingleton().RestartThread(null);
- NewMultipFileImport.NewMultipFileImport.StartThread();
-
- break;
- case "AllStop":
- btn_Delete.Enabled = true;
- temp_Pools = NewMultipFileImport.NewMultipFileImport.GetFileImportList();
- foreach (frmFileImportModel mod in temp_Pools)
- {
- mod.errorMsg = "暂停上传";
- foreach (var path in mod.local_Path)
- {
- if (path.upload_Msg == "正在上传" || path.code == 1)
- {
- continue;
- }
- else if (path.code == 0)
- {
- path.code = -1;
- path.upload_Msg = "暂停上传";
- }
- }
- }
- //frmMultipFileImportThread.GetSingleton().threadStart = false;
- //frmMultipFileImportThread.GetSingleton().RestartThread(null);
- NewMultipFileImport.NewMultipFileImport.multipFileReport.bStartThread = false;
- break;
- }
- }
- /// <summary>
- /// 重新绑定数据
- /// </summary>
- /// <param name="typeName"></param>
- public void ReLoadData(string typeName)
- {
- selectType = typeName;
- List<frmFileImportModel> mianList = new List<frmFileImportModel>();
- List<frmFileImportModel> tempList = null;
- switch(typeName)
- {
- case "ALL":
- mianList = LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.GetFileImportList();
- break;
- case "Complete":
- tempList = LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.GetFileImportList();
- for (int i = 0; i < tempList.Count;i++ )
- {
- frmFileImportModel inListModel = GetModel(tempList[i],1);
-
- if(inListModel!=null)
- {
- mianList.Add(inListModel);
- }
- }
- break;
- case "Error":
- tempList = LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.GetFileImportList();
- for (int i = 0; i < tempList.Count; i++)
- {
- frmFileImportModel inListModel = GetModel(tempList[i], -1);
-
- if(inListModel!=null)
- {
- mianList.Add(inListModel);
- }
- }
- break;
- case "upLoad":
- tempList = LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.GetFileImportList();
- for (int i = 0; i < tempList.Count; i++)
- {
- frmFileImportModel inListModel = GetModel(tempList[i], 0);
-
- if(inListModel!=null)
- {
- mianList.Add(inListModel);
- }
- }
- break;
- }
- LoadDataInfo(mianList);
- }
- /// <summary>
- /// 通过编码获取实体
- /// </summary>
- /// <param name="tempModel"></param>
- /// <param name="code"></param>
- /// <returns></returns>
- public frmFileImportModel GetModel(frmFileImportModel tempModel ,int code)
- {
- frmFileImportModel inListModel = null;
- for (int q = 0; q < tempModel.local_Path.Count; q++)
- {
- if (tempModel.local_Path[q].code == code)
- {
- if (inListModel == null)
- {
- inListModel = new frmFileImportModel()
- {
- service_Path = tempModel.service_Path,
- sPh = tempModel.sPh,
- local_Path = new List<frmFileImportItemModel>(),
- directoryType = tempModel.directoryType,
- erpDigOrder = tempModel.erpDigOrder,
- erpOrder = tempModel.erpOrder,
- takenName = tempModel.takenName
- };
- }
- inListModel.local_Path.Add(tempModel.local_Path[q]);
- }
- }
- return inListModel;
- }
- /// <summary>
- /// 绑定更新进度条
- /// </summary>
- /// <param name="model"></param>
- public void BindDataInfo(object model)
- {
- List<frmFileImportModel> mianList = LYFZ.Software.MainBusiness.MultipleFileImport.NewMultipFileImport.NewMultipFileImport.GetFileActionImportList();
- if (mianList.Count != this.listViewEx1.Items.Count)
- {
- ReLoadData("ALL");
- }
- foreach (var mod in this.listViewEx1.Items)
- {
- bool bStartBind = false;
- int processBar = 0;
- int errorNumber = 0;
- int stopNumber = 0;
- int totalCount = 0;
- int upCount = 0;
- stopNumber = ((frmFileImportModel)((ListViewItem)mod).Tag).local_Path.FindAll(p => p.code == -1 && p.upload_Msg == "暂停上传").Count;
- if (((frmFileImportModel)((ListViewItem)mod).Tag).local_Path.Count > 0)
- {
- upCount = (((frmFileImportModel)((ListViewItem)mod).Tag).local_Path.FindAll(p => p.code != 0 && p.upload_Msg != "暂停上传").Count);
- totalCount = ((frmFileImportModel)((ListViewItem)mod).Tag).local_Path.Count;
- processBar = (((frmFileImportModel)((ListViewItem)mod).Tag).local_Path.FindAll(p => p.code != 0 && p.upload_Msg != "暂停上传").Count * 100 / ((frmFileImportModel)((ListViewItem)mod).Tag).local_Path.Count);
- }
- if(((ListViewItem)mod).Tag == model)
- {
- frmFileImportModel tempModel = (frmFileImportModel)model;
- bStartBind = tempModel.local_Path.FindAll(p => p.code == 0).Count > 0;
-
- errorNumber = tempModel.local_Path.FindAll(p => p.code == -1 && p.upload_Msg != "暂停上传").Count;
-
-
- ((ListViewItem)mod).SubItems[1].Text = processBar + "%";
- ((ListViewItem)mod).SubItems[2].Text = (errorNumber > 0 ? "报错数:" + errorNumber : stopNumber > 0 ? "暂停上传" : processBar < 100 ? "传输" : "完成")+"("+ (upCount + "/" + totalCount) + ")";
-
- }
- if (((frmFileImportModel)((ListViewItem)mod).Tag).local_Path.Count == 0)
- {
- ((ListViewItem)mod).SubItems[1].Text = "没有找到本地文件,传输失败";
- }
- else if (processBar < 100)
- {
- if (model != null)
- {
- ((ListViewItem)mod).SubItems[2].Text = (stopNumber > 0 ? "暂停上传" : ((frmFileImportModel)model).errorMsg != "正在上传" ? "传输" : ((frmFileImportModel)model).errorMsg) + "(" + (upCount + "/" + totalCount) + ")";
- }
- }
- else if (processBar >= 100)
- {
- //((ListViewItem)mod).SubItems[2].Text = "完成";
- }
- }
- BindDeleteButtonShowOrHide();
- }
- /// <summary>
- /// 数据重新绑定
- /// </summary>
- /// <param name="groupList"></param>
- public void LoadDataInfo(List<frmFileImportModel> groupList)
- {
- this.listViewEx1.Items.Clear();
- this.listViewEx1.Groups.Clear();
- bool bStartBind = false;
- int processBar=0;
- int errorNumber=0;
- int upCount = 0;
- int totalCount = 0;
- for (int i = 0; i < groupList.Count; i++)
- {
- bStartBind = groupList[i].local_Path.FindAll(p => p.code <= 0).Count > 0;
- if (groupList[i].local_Path.Count > 0)
- {
- upCount = groupList[i].local_Path.FindAll(p => p.code != 0 && p.upload_Msg != "暂停上传").Count;
- totalCount = groupList[i].local_Path.Count;
- processBar = (groupList[i].local_Path.FindAll(p => p.code != 0 && p.upload_Msg != "暂停上传").Count * 100 / groupList[i].local_Path.Count);
- }
- else
- {
- processBar=-1;
- }
- errorNumber = groupList[i].local_Path.FindAll(p => p.code == -1 && p.upload_Msg != "暂停上传").Count;
- if (bStartBind)
- {
- ListViewItem group = new ListViewItem(new string[]{
- "订单号:" + groupList[i].erpOrder.Ord_SinceOrderNumber + " ["+groupList[i].cusName + "] " + groupList[i].takenName + "[" + groupList[i]. directoryTypeDis() + "]" + "组上传",
- processBar==-1?"没有找到本地文件,传输失败":processBar+"%",
-
- (errorNumber > 0 ? "报错数:" + errorNumber : groupList[i].errorMsg)
- +"("+ (upCount+"/"+totalCount)+")"
- });
- group.Tag = groupList[i];
- this.listViewEx1.Items.Add(group);
- }
- }
- BindDeleteButtonShowOrHide();
- /*pan_UpfileData.Controls.Clear();
- for(int i=0;i<groupList.Count;i++)
- {
- UCGroupItems group = new UCGroupItems();
- pan_UpfileData.Controls.Add(group);
- group.GroupNameText = groupList[i].takenName;
- for (int q = 0; q < groupList[i].local_Path.Count; q++)
- {
- UCItems item = new UCItems(groupList[i].local_Path[q].local_Path, 0);
- group.Add(item);
- }
-
- }*/
- }
- private void tb_LogInfo_Click(object sender, EventArgs e)
- {
- string[] files = Directory.GetFiles(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "/Logs/ImportThread/");
- frmMultipleFileLogs frmLog = new frmMultipleFileLogs();
- frmLog.LoadFileList(files);
- frmLog.Show();
- }
- }
- }
|