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
{
///
/// BaseInfo.xaml 的交互逻辑
///
public partial class BaseInfo : UserControl
{
public Labware labware { get; set; }
private ObservableCollection 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(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);
}
///
/// 检查数据
///
///
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
}
}