锐腾搅拌上料功能
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

346 lines
15 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.Utils;
using DevExpress.XtraTab;
using System.IO;
using ICSSoft.Base.Config.AppConfig;
using ICSSoft.Frame.Data.BLL;
using ICSSoft.Frame.Common;
using ICSSoft.Frame.Data.Entity;
using PdfiumViewer;
namespace ICSSoft.Frame.APP
{
public partial class FormKodTree : XtraForm
{
private static FormKodTree _f1 = null;
private static object Singleton_Lock = new object();
KODFolder KodSetting = null;
private FormKodTree()
{
InitializeComponent();
}
private FormKodTree(string ITEMCODE, string CustITEMCODE)
{
InitializeComponent();
//获取api,文件夹设置信息(此处用不到文件夹信息)
KodSetting = ICSKODFOLDERBLL.SelectFolderInfo(AppConfig.WorkPointCode, AppConfig.AppConnectString);
KodSetting.PWD = AppConfig.FromMd5(KodSetting.PWD);
string sourceid = System.Text.RegularExpressions.Regex.Replace(KodSetting.PATH, @"[^0-9]+", "");
//标准全路径 URL/Dispalypath/物料1~3/物料4~6_物料1~3/客户料号/图纸文件夹/图纸.pdf
//定位到(物料4~6_物料1~3)
//string name = ITEMCODE.Substring(3, 3) + "_" + ITEMCODE.Substring(0, 3);
//2022-04-13定位到(客户料号)
string parentName = ITEMCODE.Substring(3, 3) + "_" + ITEMCODE.Substring(0, 3);
string name = CustITEMCODE;
this.Text = "可道云浏览=>物料:" + ITEMCODE + ",位置:" + parentName + "/.../" + name;
//获取目录结构
DataTable dtNodes = ICSKodDbApiBLL.GetFileDirectory(AppConfig.AppConnectString, AppConfig.WorkPointCode, sourceid, name, parentName);
//初始化TreeList
InitTreeListControl(dtNodes);
//
//tabControlMian.LookAndFeel.SetFlatStyle();
//tabControlMian.AppearancePage.HeaderActive.BackColor = Color.DodgerBlue;
tabControlMian.AppearancePage.HeaderActive.ForeColor = Color.Red;
tabControlMian.TabPages.Clear();
}
public static FormKodTree CreateInstance(string ITEMCODE, string CustITEMCODE)
{
if (_f1 == null || _f1.IsDisposed)
{
lock (Singleton_Lock)
{
if (_f1 == null || _f1.IsDisposed)
{
_f1 = new FormKodTree(ITEMCODE, CustITEMCODE);
}
}
}
return _f1;
}
void InitTreeListControl(DataTable source)
{
#region 设置列头、节点指示器面板、表格线样式
treeList.OptionsView.ShowColumns = false; //隐藏列标头
treeList.OptionsView.ShowIndicator = false; //隐藏节点指示器面板
treeList.OptionsView.ShowHorzLines = false; //隐藏水平表格线
treeList.OptionsView.ShowVertLines = false; //隐藏垂直表格线
treeList.OptionsView.ShowIndentAsRowStyle = true;
#endregion
#region 选中
treeList.OptionsView.ShowFocusedFrame = false; //设置显示焦点框
treeList.OptionsSelection.EnableAppearanceFocusedCell = true; //禁用单元格选中
treeList.OptionsSelection.EnableAppearanceFocusedRow = false; //禁用正行选中
// 设置选中时节点的背景色
treeList.Appearance.FocusedCell.BackColor = System.Drawing.Color.DodgerBlue;
//treeList.Appearance.FocusedCell.BackColor2 = System.Drawing.Color.Blue;
treeList.Appearance.FocusedCell.Options.UseBackColor = true;
// 选中时会把节点中没显示完全的信息全部显示
treeList.Appearance.FocusedCell.Options.UseTextOptions = true;
treeList.Appearance.FocusedCell.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
#endregion
#region 设置TreeList的展开折叠按钮样式和树线样式
treeList.OptionsView.ShowButtons = true; //显示展开折叠按钮
treeList.LookAndFeel.UseDefaultLookAndFeel = true; //禁用默认外观与感觉
treeList.LookAndFeel.UseWindowsXPTheme = false; //使用WindowsXP主题
treeList.TreeLineStyle = DevExpress.XtraTreeList.LineStyle.Percent50; //设置树线的样式
#endregion
#region 添加单列
DevExpress.XtraTreeList.Columns.TreeListColumn colNode = new DevExpress.XtraTreeList.Columns.TreeListColumn();
colNode.Caption = "文件夹/文件名";
colNode.Name = string.Format("Node-{0}", colNode.Caption);
colNode.FieldName = "name";
colNode.VisibleIndex = 0;
colNode.Visible = true;
colNode.OptionsColumn.AllowEdit = false; //是否允许编辑
colNode.OptionsColumn.AllowMove = false; //是否允许移动
colNode.OptionsColumn.AllowMoveToCustomizationForm = false; //是否允许移动至自定义窗体
colNode.OptionsColumn.AllowSort = false; //是否允许排序
colNode.OptionsColumn.FixedWidth = false; //是否固定列宽
colNode.OptionsColumn.ReadOnly = true; //是否只读
colNode.OptionsColumn.ShowInCustomizationForm = true; //移除列后是否允许在自定义窗体中显示
treeList.Columns.Clear();
treeList.Columns.AddRange(new DevExpress.XtraTreeList.Columns.TreeListColumn[] { colNode });
#endregion
#region 图标
ImageCollection imgc = new ImageCollection();
imgc.AddImage(Properties.Resources.folder);
imgc.AddImage(Properties.Resources.open_folder);
imgc.AddImage(Properties.Resources.doc);
imgc.AddImage(Properties.Resources.xls);
imgc.AddImage(Properties.Resources.pdf);
imgc.AddImage(Properties.Resources.unknown_file);
#endregion
//绑定图标
treeList.SelectImageList = imgc;
//简单绑定
treeList.DataSource = source;
//主键字段名称
treeList.KeyFieldName = "sourceID";
//父级字段名称
treeList.ParentFieldName = "parentID";
//展开所有节点
//treeList.ExpandAll();
//
treeList.BestFitColumns();
}
private DataTable InitDataTable4Test()
{
DataTable dt = new DataTable();
dt.Columns.Add("parentID", typeof(Int32));
dt.Columns.Add("sourceID", typeof(Int32));
dt.Columns.Add("parentLevel", typeof(string));
dt.Columns.Add("isFolder", typeof(bool));
dt.Columns.Add("fileType", typeof(string));
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("localpath", typeof(string));
dt.Rows.Add(new object[] { "0", "1", ",0,1,", true, "", "wadwa", "" });//添加行
dt.Rows.Add(new object[] { "1", "2", ",0,1,2,", true, "", "我天天", "" });//添加行
dt.Rows.Add(new object[] { "1", "7", ",0,1,7,", true, "", "退票1111", "" });//添加行
dt.Rows.Add(new object[] { "1", "4", ",0,1,4,", true, "", "ABC", "" });//添加行
dt.Rows.Add(new object[] { "2", "21", ",0,1,2,21,", "file", "xls", "说明文档", "" });//添加行
dt.Rows.Add(new object[] { "2", "22", ",0,1,2.22,", "file", "pdf", "图纸1", @"D:\Users\AllenWalker\Desktop\3AAM1087001_A.pdf" });//添加行
dt.Rows.Add(new object[] { "2", "23", ",0,1,2,23,", "file", "html", "index", "" });//添加行
dt.Rows.Add(new object[] { "2", "24", ",0,1,2,24,", "file", "doc", "偏高奖品我哪", "" });//添加行
dt.Rows.Add(new object[] { "4", "5", ",0,1,4,5,", true, "", "100000", "" });//添加行
dt.Rows.Add(new object[] { "5", "6", ",0,1,4,5,6,", "file", "pdf", "坎坎坷坷扩", @"D:\Users\AllenWalker\Desktop\3AAM1087001_B.pdf" });//添加行
dt.Rows.Add(new object[] { "7", "8", ",0,1,7,8,", true, "", "123456" });//添加行
dt.Rows.Add(new object[] { "8", "9", ",0,1,7,8,9,", true, "", "啊wwrawg网77" });//添加行
dt.Rows.Add(new object[] { "9", "10", ",0,1,7,8,9,10,", "file", "xls", "1-2-1" });//添加行
return dt;
}
private void treeList_CustomDrawNodeImages(object sender, DevExpress.XtraTreeList.CustomDrawNodeImagesEventArgs e)
{
bool isFolder = Convert.ToBoolean(e.Node.GetValue("isFolder"));
string fileType = e.Node.GetValue("fileType").ToString();
if (e.Node.Nodes.Count > 0)
{
if (isFolder)
{
if (e.Node.Expanded)
{
e.SelectImageIndex = 1;
}
else
{
e.SelectImageIndex = 0;
}
}
}
else
{
if (isFolder)
{
e.SelectImageIndex = 0;
return;
}
switch (fileType)
{
case "doc":
case "docx":
e.SelectImageIndex = 2;
break;
case "xls":
case "xlsx":
e.SelectImageIndex = 3;
break;
case "pdf":
e.SelectImageIndex = 4;
break;
default:
e.SelectImageIndex = 5;
break;
}
}
}
List<string> fileTypeList = new List<string>() { "pdf", "xls", "xlsx", "doc", "docx" };
private void treeList_MouseDoubleClick(object sender, MouseEventArgs e)
{
bool isFolder = Convert.ToBoolean(treeList.FocusedNode.GetValue("isFolder"));
string sourceID = treeList.FocusedNode.GetValue("sourceID").ToString();
string name = treeList.FocusedNode.GetValue("name").ToString();
string fileType = treeList.FocusedNode.GetValue("fileType").ToString();
string path = treeList.FocusedNode.GetValue("parentLevel").ToString().Trim(new char[] { ',' }).Replace(",", @"\");
if (isFolder)
{
return;
}
if (!fileTypeList.Contains(fileType))
{
ICSBaseSimpleCode.AppshowMessageBox("您只能查看以下文件类型:" + string.Join(",", fileTypeList));
return;
}
try
{
path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "awit", path);
//下载文件,绑定path
File4Kod.DownLoad(KodSetting, "{source:" + sourceID + "}/", path, name);
string localpath = Path.Combine(path, name);
treeList.FocusedNode.SetValue("localpath", localpath);
if (fileType == "pdf")
{
foreach (XtraTabPage item in tabControlMian.TabPages)
{
if ((string)item.Tag == localpath)
{
tabControlMian.SelectedTabPage = item;
//PDFviewerControl pdfv = item.Controls[0] as PDFviewerControl;
PdfiumViewer.PdfViewer40 pdfv = new PdfiumViewer.PdfViewer40();
pdfv.LoadFile(localpath);
return;
}
}
XtraTabPage page = new XtraTabPage();
page.Name = name + "(" + sourceID + ")";
page.Text = sourceID;
page.Tag = localpath;
//PDFviewerControl pdf = new PDFviewerControl();
PdfiumViewer.PdfViewer40 pdf = new PdfiumViewer.PdfViewer40();
pdf.Name = "axAcroPDF:" + sourceID + "," + name;
pdf.Dock = DockStyle.Fill;
page.Controls.Add(pdf);
tabControlMian.TabPages.Add(page);
tabControlMian.SelectedTabPage = page;
pdf.LoadFile(localpath);
//AxAcroPDFLib.AxAcroPDF pdf = new AxAcroPDFLib.AxAcroPDF();
//pdf.Name = "axAcroPDF:" + sourceID + "," + name;
//pdf.Dock = DockStyle.Fill;
//page.Controls.Add(pdf);
//tabControlMian.TabPages.Add(page);
//tabControlMian.SelectedTabPage = page;
//pdf.Dock = DockStyle.Fill;
//pdf.LoadFile(path);
//pdf.setShowToolbar(false);
//pdf.setShowScrollbars(false);
//pdf.setPageMode("none");//thumbs
//pdf.setLayoutMode("SinglePage");
//pdf.setView("Fit");
//pdf.Show();
}
else
{
try
{
System.Diagnostics.Process.Start(localpath);
}
catch (Exception)
{
}
}
}
catch (Exception ex)
{
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
}
}
private void tabControlMian_CloseButtonClick(object sender, EventArgs e)
{
int pageindex = 0;
DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs args = (DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs)e;
string text = args.Page.Text;
if (text == "首页") return;
foreach (XtraTabPage page in tabControlMian.TabPages)
{
if (page.Text == text)
{
pageindex = page.TabIndex;
tabControlMian.TabPages.Remove(page);
foreach (Control t in page.Controls)
{
if (t is PdfViewer40)
(t as PdfViewer40).Close();
}
page.Dispose();
tabControlMian.SelectedTabPageIndex = pageindex - 1;
break;
}
}
}
public static void CloseForm()
{
if (_f1 != null)
{
_f1.Close();
}
}
}
}