schangxiang@126.com
2025-11-04 f5ed29dc26c7cd952d56ec5721a2efc43cd25992
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using Microsoft.Win32;
using NPOI.HSSF.Record;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;
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.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using XCommon.Log;
using XHandler.Class;
using XHandler.Class.DataEx;
using XImagingXhandler.XDAL;
 
namespace XHandler.View.Consumables
{
    /// <summary>
    /// BaseInfo.xaml 的交互逻辑
    /// </summary>
    public partial class BaseInfo : UserControl
    {
        public Labware labware { get; set; }
 
        private ObservableCollection<LabwareType> labwareTypes;
        public BaseInfo()
        {
            InitializeComponent();
 
            labwareTypes = DataModule.getInstance().GetLabwareTypes();
            cbConsumableType.ItemsSource = labwareTypes;
            cbConsumableType.SelectedIndex = 0;
        }
 
        public void SetLabware(Labware lb)
        {
            try
            {
                labware = lb;
                LabwareType lt = labwareTypes.FirstOrDefault<LabwareType>(s => s.labwaretype_name == lb.labware_type);
                if (lt != null)
                    cbConsumableType.SelectedItem = lt;
                this.DataContext = labware;
 
                if (string.IsNullOrEmpty(lb.labware_picture))
                    imageConsumable.Source = BitmapFrame.Create(new Uri("pack://application:,,,./Assets/Consumables/无图片.png"), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                else
                {
                    string folderName = ConfigurationManager.AppSettings["ImgPath"].ToString();
                    string imgPath = folderName + "\\" + lb.labware_picture;
                    imageConsumable.Source = BitmapFrame.Create(new Uri(imgPath), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
 
        private void btnUpload_Click(object sender, RoutedEventArgs e)
        {
            if (labware == null)
                return;
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "Image files(*.jpg,*.gif,*.png)|*.jpg;*.gif;*.png|All files|*.*";
            dlg.FilterIndex = 1;
            dlg.RestoreDirectory = true;
            if(dlg.ShowDialog()==true)
            {
                string imgFile = dlg.FileNames[0];
                string folder = ConfigurationManager.AppSettings["ImgPath"].ToString();
                if(!Directory.Exists(folder))
                    Directory.CreateDirectory(folder);
 
                string ext = System.IO.Path.GetExtension(imgFile);
                string destName = DateTime.Now.ToString("yyyyMMddTHHmmssms") +ext;
                string destFile = folder + "\\" + destName;
                File.Copy(imgFile, destFile, true);
 
                imageConsumable.Source = BitmapFrame.Create(new Uri(destFile), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
 
                labware.labware_picture = destName;
            }
 
        }
 
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (labware == null)
                return;
            labware.labware_picture = "";
 
            imageConsumable.Source = BitmapFrame.Create(new Uri("pack://application:,,,./Assets/Consumables/无图片.png"), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
        }
 
        /// <summary>
        /// 检查数据
        /// </summary>
        /// <returns></returns>
        public bool CheckData()
        {
            if (string.IsNullOrEmpty(labware.labware_name))
            {
                MessageBox.Show(Properties.Resources.strPlsInputLabwareName, "Tips");
                return false;
            }
            return true;
        }
 
        #region 类型改变切换基础数据字段
        private void cbConsumableType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cbConsumableType.SelectedIndex <= 0)
                return;
            string typeName = (cbConsumableType.SelectedItem as LabwareType).labwaretype_name;
            string typeId = (cbConsumableType.SelectedItem as LabwareType).labwaretype_id;
            if (labware != null)
            {
                labware.labware_type_id = typeId;
                labware.labware_type = typeName;
            }
        }
        #endregion
    }
}