123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- using LogoForceTestApp.Modules.MainModule.Models;
- using Newtonsoft.Json;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Mvvm;
- using Prism.Services.Dialogs;
- using Repository;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Forms;
- using System.Windows.Media.Imaging;
- using System.Xml.Linq;
- using static System.Net.Mime.MediaTypeNames;
- namespace LogoForceTestApp.Modules.MainModule.ViewModels
- {
- public class SopPageViewModel : BindableBase
- {
- IDialogService dialogService;
- private readonly IRepository repository;
- private readonly IEventAggregator eventAggregator;
- public string ProName { get; set; }
- public DelegateCommand AddCommand1 { get; set; }
- public DelegateCommand AddCommand2 { get; set; }
- public DelegateCommand AddCommand3 { get; set; }
- public DelegateCommand SaveSopCmm { get; set; }
- public DelegateCommand ClearChart { get; set; }
- public ObservableCollection<LocalFile> FileInfos { get; set; }
- public ObservableCollection<LocalFile2> FileInfos2 { get; set; }
- public ObservableCollection<LocalFile3> FileInfos3 { get; set; }
- public DelegateCommand AddPic { get; set; }
- public SopPageViewModel(IDialogService dialogService, IRepository repository, IEventAggregator eventAggregator)
- {
- FileInfos = new ObservableCollection<LocalFile>();
- FileInfos2 = new ObservableCollection<LocalFile2>();
- FileInfos3 = new ObservableCollection<LocalFile3>();
- AddCommand1 = new DelegateCommand(Add1);
- AddCommand2 = new DelegateCommand(Add2);
- AddCommand3 = new DelegateCommand(Add3);
- ClearChart = new DelegateCommand(ClearCha);
- AddPic = new DelegateCommand(OpenPicFile);
- this.dialogService = dialogService;
- this.repository = repository;
- this.eventAggregator = eventAggregator;
- SaveSopCmm = new DelegateCommand(SaveSop);
- }
- public void ClearCha()
- {
- FileInfos.Clear();
- FileInfos2.Clear();
- FileInfos3.Clear();
- System.Windows.Controls.DataGrid dataGrid = new System.Windows.Controls.DataGrid();
- dataGrid.Items.Clear();
- }
- private void SaveSop()
- {
- Task.Run(() =>
- {
- #region 数据库之间的关联
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #endregion
- GenaralFile genaralFile = new GenaralFile();
- genaralFile.FileInfos = FileInfos.ToList();
- genaralFile.FileInfos2 = FileInfos2.ToList();
- genaralFile.FileInfos3 = FileInfos3.ToList();
- genaralFile.ProductName = ProName;
- var json = JsonConvert.SerializeObject(genaralFile, Formatting.Indented);
- string sPath = @"D:\作业指导书\";
- if (!Directory.Exists(sPath))
- {
- Directory.CreateDirectory(sPath);
- }
- var path = sPath + $"{ProName}.json";
- using (var sw = new StreamWriter(path))
- {
- sw.Write(json);
- sw.Close();
- }
- System.Windows.Forms.MessageBox.Show("保存成功:" + ProName);
- eventAggregator.GetEvent<FileChangedEvent>().Publish();
-
- });
- }
- #region 添加表格
-
-
-
- private void Add3()
- {
- dialogService.ShowDialog("ChartPage3", c =>
- {
- var param = c.Parameters;
- var equipment = param.GetValue<string>("c1");
- var before = param.GetValue<string>("c2");
- var inn = param.GetValue<string>("c3");
- var after = param.GetValue<string>("c4");
- var lookOut = param.GetValue<string>("c5");
- if (c.Result.ToString() == "OK")
- {
- FileInfos3.Add(new LocalFile3
- {
- Equipment = equipment,
- Before = before,
- Inn = inn,
- After = after,
- LookOut = lookOut
- });
-
-
-
-
-
-
-
-
-
-
-
-
- }
- });
- }
- private void Add2()
- {
- dialogService.ShowDialog("ChartPage2", c =>
- {
- var param = c.Parameters;
- var num = param.GetValue<string>("c1");
- var materialNum = param.GetValue<string>("c2");
- var materialName = param.GetValue<string>("c3");
- var count = param.GetValue<string>("c4");
- var unit = param.GetValue<string>("c5");
- if (c.Result.ToString() == "OK")
- {
- FileInfos2.Add(new LocalFile2
- {
- Num = num,
- MaterialNum = materialNum,
- MaterialName = materialName,
- Count = count,
- Unit = unit
- });
-
-
-
-
-
-
-
-
-
-
-
- }
- });
- }
- private void Add1()
- {
- dialogService.ShowDialog("ChartPage1", c =>
- {
- var param = c.Parameters;
- var fileNum = param.GetValue<string>("c1");
- var edition = param.GetValue<string>("c2");
- var date = param.GetValue<string>("c3");
- var type = param.GetValue<string>("c4");
- var people = param.GetValue<string>("c5");
- var name = param.GetValue<string>("c6");
- var process = param.GetValue<string>("c7");
- var workTime = param.GetValue<string>("c8");
- if (c.Result.ToString() == "OK")
- {
- FileInfos.Add(new LocalFile
- {
- FileNum = fileNum,
- Edition = edition,
- Date = date,
- Type = type,
- People = people,
- Name = name,
- Process = process,
- WorkTime = workTime
- });
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- });
- }
- #endregion
- #region 显示图片
- public void OpenPicFile()
- {
- FolderBrowserDialog dialog = new FolderBrowserDialog();
- dialog.Description = "请选择文件路径";
- string imgPath = "";
- if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- imgPath = dialog.SelectedPath + @"\";
- LoadPicture(imgPath);
- }
- }
- private ObservableCollection<PictureInfo> imageList = new ObservableCollection<PictureInfo>();
- public ObservableCollection<PictureInfo> ImageList
- {
- get { return imageList; }
- set { imageList = value; }
- }
- object lockobj = new object();
-
-
-
-
- public void LoadPicture(string strPath)
- {
- ImageList.Clear();
- BindingOperations.EnableCollectionSynchronization(ImageList, lockobj);
- string folderFullName = strPath;
- Task.Run(() =>
- {
- DirectoryInfo TheFolder = new DirectoryInfo(folderFullName);
- var res = TheFolder.GetFiles();
- for (int i = 0; i < res.Length; i++)
- {
- PictureInfo pictureInfo = new PictureInfo();
- pictureInfo.PicturePath = res[i].DirectoryName + @"\" + res[i].Name;
- Uri uri = new Uri(pictureInfo.PicturePath, UriKind.Absolute);
-
- pictureInfo.Info = res[i].Name;
- ImageList.Add(pictureInfo);
- }
- });
- }
- #endregion
-
-
-
-
-
- public static void CopyFolder(string sourceFolder, string destFolder)
- {
-
- if (!Directory.Exists(destFolder))
- {
- Directory.CreateDirectory(destFolder);
- }
-
- string[] files = Directory.GetFiles(sourceFolder);
-
- foreach (string file in files)
- {
-
- FileInfo fileInfo = new FileInfo(file);
-
- string newPath = Path.Combine(destFolder, fileInfo.Name);
-
- File.Copy(file, newPath, true);
- }
-
- string[] dirs = Directory.GetDirectories(sourceFolder);
-
- foreach (string dir in dirs)
- {
-
- string dirName = Path.GetFileName(dir);
-
- string newDirPath = Path.Combine(destFolder, dirName);
-
- CopyFolder(dir, newDirPath);
- }
- }
- }
- public class LocalFile : BindableBase
- {
- public string FileNum { get; set; }
- public string Edition { get; set; }
- public string Date { get; set; }
- public string Type { get; set; }
- public string People { get; set; }
- public string Name { get; set; }
- public string Process { get; set; }
- public string WorkTime { get; set; }
- }
- public class LocalFile2 : BindableBase
- {
- public string Num { get; set; }
- public string MaterialNum { get; set; }
- public string MaterialName { get; set; }
- public string Count { get; set; }
- public string Unit { get; set; }
- }
- public class LocalFile3 : BindableBase
- {
- public string Equipment { get; set; }
- public string Before { get; set; }
- public string Inn { get; set; }
- public string After { get; set; }
- public string LookOut { get; set; }
- }
- public class GenaralFile
- {
- public string ProductName { get; set; }
- public List<LocalFile> FileInfos { get; set; }
- public List<LocalFile2> FileInfos2 { get; set; }
- public List<LocalFile3> FileInfos3 { get; set; }
- }
- }
|