锐腾搅拌上料功能
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.

345 lines
15 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using DevExpress.XtraEditors;
  9. using DevExpress.Skins;
  10. using DevExpress.LookAndFeel;
  11. using DevExpress.UserSkins;
  12. using DevExpress.Utils;
  13. using DevExpress.XtraTab;
  14. using System.IO;
  15. using ICSSoft.Base.Config.AppConfig;
  16. using ICSSoft.Frame.Data.BLL;
  17. using ICSSoft.Frame.Common;
  18. using ICSSoft.Frame.Data.Entity;
  19. using PdfiumViewer;
  20. namespace ICSSoft.Frame.APP
  21. {
  22. public partial class FormKodTree : XtraForm
  23. {
  24. private static FormKodTree _f1 = null;
  25. private static object Singleton_Lock = new object();
  26. KODFolder KodSetting = null;
  27. private FormKodTree()
  28. {
  29. InitializeComponent();
  30. }
  31. private FormKodTree(string ITEMCODE, string CustITEMCODE)
  32. {
  33. InitializeComponent();
  34. //获取api,文件夹设置信息(此处用不到文件夹信息)
  35. KodSetting = ICSKODFOLDERBLL.SelectFolderInfo(AppConfig.WorkPointCode, AppConfig.AppConnectString);
  36. KodSetting.PWD = AppConfig.FromMd5(KodSetting.PWD);
  37. string sourceid = System.Text.RegularExpressions.Regex.Replace(KodSetting.PATH, @"[^0-9]+", "");
  38. //标准全路径 URL/Dispalypath/物料1~3/物料4~6_物料1~3/客户料号/图纸文件夹/图纸.pdf
  39. //定位到(物料4~6_物料1~3)
  40. //string name = ITEMCODE.Substring(3, 3) + "_" + ITEMCODE.Substring(0, 3);
  41. //2022-04-13定位到(客户料号)
  42. string parentName = ITEMCODE.Substring(3, 3) + "_" + ITEMCODE.Substring(0, 3);
  43. string name = CustITEMCODE;
  44. this.Text = "可道云浏览=>物料:" + ITEMCODE + ",位置:" + parentName + "/.../" + name;
  45. //获取目录结构
  46. DataTable dtNodes = ICSKodDbApiBLL.GetFileDirectory(AppConfig.AppConnectString, AppConfig.WorkPointCode, sourceid, name, parentName);
  47. //初始化TreeList
  48. InitTreeListControl(dtNodes);
  49. //
  50. //tabControlMian.LookAndFeel.SetFlatStyle();
  51. //tabControlMian.AppearancePage.HeaderActive.BackColor = Color.DodgerBlue;
  52. tabControlMian.AppearancePage.HeaderActive.ForeColor = Color.Red;
  53. tabControlMian.TabPages.Clear();
  54. }
  55. public static FormKodTree CreateInstance(string ITEMCODE, string CustITEMCODE)
  56. {
  57. if (_f1 == null || _f1.IsDisposed)
  58. {
  59. lock (Singleton_Lock)
  60. {
  61. if (_f1 == null || _f1.IsDisposed)
  62. {
  63. _f1 = new FormKodTree(ITEMCODE, CustITEMCODE);
  64. }
  65. }
  66. }
  67. return _f1;
  68. }
  69. void InitTreeListControl(DataTable source)
  70. {
  71. #region 设置列头、节点指示器面板、表格线样式
  72. treeList.OptionsView.ShowColumns = false; //隐藏列标头
  73. treeList.OptionsView.ShowIndicator = false; //隐藏节点指示器面板
  74. treeList.OptionsView.ShowHorzLines = false; //隐藏水平表格线
  75. treeList.OptionsView.ShowVertLines = false; //隐藏垂直表格线
  76. treeList.OptionsView.ShowIndentAsRowStyle = true;
  77. #endregion
  78. #region 选中
  79. treeList.OptionsView.ShowFocusedFrame = false; //设置显示焦点框
  80. treeList.OptionsSelection.EnableAppearanceFocusedCell = true; //禁用单元格选中
  81. treeList.OptionsSelection.EnableAppearanceFocusedRow = false; //禁用正行选中
  82. // 设置选中时节点的背景色
  83. treeList.Appearance.FocusedCell.BackColor = System.Drawing.Color.DodgerBlue;
  84. //treeList.Appearance.FocusedCell.BackColor2 = System.Drawing.Color.Blue;
  85. treeList.Appearance.FocusedCell.Options.UseBackColor = true;
  86. // 选中时会把节点中没显示完全的信息全部显示
  87. treeList.Appearance.FocusedCell.Options.UseTextOptions = true;
  88. treeList.Appearance.FocusedCell.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
  89. #endregion
  90. #region 设置TreeList的展开折叠按钮样式和树线样式
  91. treeList.OptionsView.ShowButtons = true; //显示展开折叠按钮
  92. treeList.LookAndFeel.UseDefaultLookAndFeel = true; //禁用默认外观与感觉
  93. treeList.LookAndFeel.UseWindowsXPTheme = false; //使用WindowsXP主题
  94. treeList.TreeLineStyle = DevExpress.XtraTreeList.LineStyle.Percent50; //设置树线的样式
  95. #endregion
  96. #region 添加单列
  97. DevExpress.XtraTreeList.Columns.TreeListColumn colNode = new DevExpress.XtraTreeList.Columns.TreeListColumn();
  98. colNode.Caption = "文件夹/文件名";
  99. colNode.Name = string.Format("Node-{0}", colNode.Caption);
  100. colNode.FieldName = "name";
  101. colNode.VisibleIndex = 0;
  102. colNode.Visible = true;
  103. colNode.OptionsColumn.AllowEdit = false; //是否允许编辑
  104. colNode.OptionsColumn.AllowMove = false; //是否允许移动
  105. colNode.OptionsColumn.AllowMoveToCustomizationForm = false; //是否允许移动至自定义窗体
  106. colNode.OptionsColumn.AllowSort = false; //是否允许排序
  107. colNode.OptionsColumn.FixedWidth = false; //是否固定列宽
  108. colNode.OptionsColumn.ReadOnly = true; //是否只读
  109. colNode.OptionsColumn.ShowInCustomizationForm = true; //移除列后是否允许在自定义窗体中显示
  110. treeList.Columns.Clear();
  111. treeList.Columns.AddRange(new DevExpress.XtraTreeList.Columns.TreeListColumn[] { colNode });
  112. #endregion
  113. #region 图标
  114. ImageCollection imgc = new ImageCollection();
  115. imgc.AddImage(Properties.Resources.folder);
  116. imgc.AddImage(Properties.Resources.open_folder);
  117. imgc.AddImage(Properties.Resources.doc);
  118. imgc.AddImage(Properties.Resources.xls);
  119. imgc.AddImage(Properties.Resources.pdf);
  120. imgc.AddImage(Properties.Resources.unknown_file);
  121. #endregion
  122. //绑定图标
  123. treeList.SelectImageList = imgc;
  124. //简单绑定
  125. treeList.DataSource = source;
  126. //主键字段名称
  127. treeList.KeyFieldName = "sourceID";
  128. //父级字段名称
  129. treeList.ParentFieldName = "parentID";
  130. //展开所有节点
  131. //treeList.ExpandAll();
  132. //
  133. treeList.BestFitColumns();
  134. }
  135. private DataTable InitDataTable4Test()
  136. {
  137. DataTable dt = new DataTable();
  138. dt.Columns.Add("parentID", typeof(Int32));
  139. dt.Columns.Add("sourceID", typeof(Int32));
  140. dt.Columns.Add("parentLevel", typeof(string));
  141. dt.Columns.Add("isFolder", typeof(bool));
  142. dt.Columns.Add("fileType", typeof(string));
  143. dt.Columns.Add("name", typeof(string));
  144. dt.Columns.Add("localpath", typeof(string));
  145. dt.Rows.Add(new object[] { "0", "1", ",0,1,", true, "", "wadwa", "" });//添加行
  146. dt.Rows.Add(new object[] { "1", "2", ",0,1,2,", true, "", "我天天", "" });//添加行
  147. dt.Rows.Add(new object[] { "1", "7", ",0,1,7,", true, "", "退票1111", "" });//添加行
  148. dt.Rows.Add(new object[] { "1", "4", ",0,1,4,", true, "", "ABC", "" });//添加行
  149. dt.Rows.Add(new object[] { "2", "21", ",0,1,2,21,", "file", "xls", "说明文档", "" });//添加行
  150. dt.Rows.Add(new object[] { "2", "22", ",0,1,2.22,", "file", "pdf", "图纸1", @"D:\Users\AllenWalker\Desktop\3AAM1087001_A.pdf" });//添加行
  151. dt.Rows.Add(new object[] { "2", "23", ",0,1,2,23,", "file", "html", "index", "" });//添加行
  152. dt.Rows.Add(new object[] { "2", "24", ",0,1,2,24,", "file", "doc", "偏高奖品我哪", "" });//添加行
  153. dt.Rows.Add(new object[] { "4", "5", ",0,1,4,5,", true, "", "100000", "" });//添加行
  154. dt.Rows.Add(new object[] { "5", "6", ",0,1,4,5,6,", "file", "pdf", "坎坎坷坷扩", @"D:\Users\AllenWalker\Desktop\3AAM1087001_B.pdf" });//添加行
  155. dt.Rows.Add(new object[] { "7", "8", ",0,1,7,8,", true, "", "123456" });//添加行
  156. dt.Rows.Add(new object[] { "8", "9", ",0,1,7,8,9,", true, "", "啊wwrawg网77" });//添加行
  157. dt.Rows.Add(new object[] { "9", "10", ",0,1,7,8,9,10,", "file", "xls", "1-2-1" });//添加行
  158. return dt;
  159. }
  160. private void treeList_CustomDrawNodeImages(object sender, DevExpress.XtraTreeList.CustomDrawNodeImagesEventArgs e)
  161. {
  162. bool isFolder = Convert.ToBoolean(e.Node.GetValue("isFolder"));
  163. string fileType = e.Node.GetValue("fileType").ToString();
  164. if (e.Node.Nodes.Count > 0)
  165. {
  166. if (isFolder)
  167. {
  168. if (e.Node.Expanded)
  169. {
  170. e.SelectImageIndex = 1;
  171. }
  172. else
  173. {
  174. e.SelectImageIndex = 0;
  175. }
  176. }
  177. }
  178. else
  179. {
  180. if (isFolder)
  181. {
  182. e.SelectImageIndex = 0;
  183. return;
  184. }
  185. switch (fileType)
  186. {
  187. case "doc":
  188. case "docx":
  189. e.SelectImageIndex = 2;
  190. break;
  191. case "xls":
  192. case "xlsx":
  193. e.SelectImageIndex = 3;
  194. break;
  195. case "pdf":
  196. e.SelectImageIndex = 4;
  197. break;
  198. default:
  199. e.SelectImageIndex = 5;
  200. break;
  201. }
  202. }
  203. }
  204. List<string> fileTypeList = new List<string>() { "pdf", "xls", "xlsx", "doc", "docx" };
  205. private void treeList_MouseDoubleClick(object sender, MouseEventArgs e)
  206. {
  207. bool isFolder = Convert.ToBoolean(treeList.FocusedNode.GetValue("isFolder"));
  208. string sourceID = treeList.FocusedNode.GetValue("sourceID").ToString();
  209. string name = treeList.FocusedNode.GetValue("name").ToString();
  210. string fileType = treeList.FocusedNode.GetValue("fileType").ToString();
  211. string path = treeList.FocusedNode.GetValue("parentLevel").ToString().Trim(new char[] { ',' }).Replace(",", @"\");
  212. if (isFolder)
  213. {
  214. return;
  215. }
  216. if (!fileTypeList.Contains(fileType))
  217. {
  218. ICSBaseSimpleCode.AppshowMessageBox("您只能查看以下文件类型:" + string.Join(",", fileTypeList));
  219. return;
  220. }
  221. try
  222. {
  223. path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "awit", path);
  224. //下载文件,绑定path
  225. File4Kod.DownLoad(KodSetting, "{source:" + sourceID + "}/", path, name);
  226. string localpath = Path.Combine(path, name);
  227. treeList.FocusedNode.SetValue("localpath", localpath);
  228. if (fileType == "pdf")
  229. {
  230. foreach (XtraTabPage item in tabControlMian.TabPages)
  231. {
  232. if ((string)item.Tag == localpath)
  233. {
  234. tabControlMian.SelectedTabPage = item;
  235. //PDFviewerControl pdfv = item.Controls[0] as PDFviewerControl;
  236. PdfiumViewer.PdfViewer40 pdfv = new PdfiumViewer.PdfViewer40();
  237. pdfv.LoadFile(localpath);
  238. return;
  239. }
  240. }
  241. XtraTabPage page = new XtraTabPage();
  242. page.Name = name + "(" + sourceID + ")";
  243. page.Text = sourceID;
  244. page.Tag = localpath;
  245. //PDFviewerControl pdf = new PDFviewerControl();
  246. PdfiumViewer.PdfViewer40 pdf = new PdfiumViewer.PdfViewer40();
  247. pdf.Name = "axAcroPDF:" + sourceID + "," + name;
  248. pdf.Dock = DockStyle.Fill;
  249. page.Controls.Add(pdf);
  250. tabControlMian.TabPages.Add(page);
  251. tabControlMian.SelectedTabPage = page;
  252. pdf.LoadFile(localpath);
  253. //AxAcroPDFLib.AxAcroPDF pdf = new AxAcroPDFLib.AxAcroPDF();
  254. //pdf.Name = "axAcroPDF:" + sourceID + "," + name;
  255. //pdf.Dock = DockStyle.Fill;
  256. //page.Controls.Add(pdf);
  257. //tabControlMian.TabPages.Add(page);
  258. //tabControlMian.SelectedTabPage = page;
  259. //pdf.Dock = DockStyle.Fill;
  260. //pdf.LoadFile(path);
  261. //pdf.setShowToolbar(false);
  262. //pdf.setShowScrollbars(false);
  263. //pdf.setPageMode("none");//thumbs
  264. //pdf.setLayoutMode("SinglePage");
  265. //pdf.setView("Fit");
  266. //pdf.Show();
  267. }
  268. else
  269. {
  270. try
  271. {
  272. System.Diagnostics.Process.Start(localpath);
  273. }
  274. catch (Exception)
  275. {
  276. }
  277. }
  278. }
  279. catch (Exception ex)
  280. {
  281. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  282. }
  283. }
  284. private void tabControlMian_CloseButtonClick(object sender, EventArgs e)
  285. {
  286. int pageindex = 0;
  287. DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs args = (DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs)e;
  288. string text = args.Page.Text;
  289. if (text == "首页") return;
  290. foreach (XtraTabPage page in tabControlMian.TabPages)
  291. {
  292. if (page.Text == text)
  293. {
  294. pageindex = page.TabIndex;
  295. tabControlMian.TabPages.Remove(page);
  296. foreach (Control t in page.Controls)
  297. {
  298. if (t is PdfViewer40)
  299. (t as PdfViewer40).Close();
  300. }
  301. page.Dispose();
  302. tabControlMian.SelectedTabPageIndex = pageindex - 1;
  303. break;
  304. }
  305. }
  306. }
  307. public static void CloseForm()
  308. {
  309. if (_f1 != null)
  310. {
  311. _f1.Close();
  312. }
  313. }
  314. }
  315. }