using CommonFunc; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; 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; namespace XGL.UControl { /// /// UCStorage.xaml 的交互逻辑 /// public partial class UCStorage : UserControl { /// /// 小车列表 /// private List CarList { get; set; } public UCStorage() { InitializeComponent(); } public delegate string deletegateSetCarLocator(string carno); public deletegateSetCarLocator SetCarLocatorEvent; public UCStorage(int locatornum, List list) { InitializeComponent(); this.TotalNum = locatornum; this.CarList = list; } #region 库存数量 /// /// 缓存区域缓存数量 /// public int TotalNum { get { return (int)GetValue(TotalNumProperty); } set { SetValue(TotalNumProperty, value); } } public static DependencyProperty TotalNumProperty = DependencyProperty.Register("TotalNum", typeof(int), typeof(UCStorage), new PropertyMetadata(0, new PropertyChangedCallback(TotalNumPropertyChanged))); //属性默认值 private static void TotalNumPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { try { int totalnum = Convert.ToInt32(e.NewValue); var uccontrol = d as UCStorage; // var panel = uccontrol.FindName("StoreCars") as StackPanel; for (int i = 0; i < totalnum; i++) { if (uccontrol.StoreCars.FindName("locator_" + i) == null) { Label label = new Label(); label.Width = 40; label.Margin = new Thickness(7, 5, 7, 5); label.FontSize = 15; label.Foreground = new SolidColorBrush(Colors.White); label.Background = new SolidColorBrush(Colors.Gray); label.MouseDown += new MouseButtonEventHandler(uccontrol.CarClick); uccontrol.RegisterName("locator_" + i, label); uccontrol.StoreCars.Children.Add(label); } } } catch (Exception ex) { MethodInfo method = (MethodInfo)MethodBase.GetCurrentMethod(); Common.Log.Error(method.DeclaringType.FullName + "-" + method.Name + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); } } #endregion #region 产品小车 /// /// 产品型号 /// public List ProductCar { get { return (List)GetValue(ProductCarProperty); } set { SetValue(ProductCarProperty, value); } } public static DependencyProperty ProductCarProperty = DependencyProperty.Register("ProductCar", typeof(List), typeof(UCStorage), new PropertyMetadata(null, new PropertyChangedCallback(ProductCarPropertyChanged))); //属性默认值 private static void ProductCarPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { try { List CarList = e.NewValue as List; var uccontrol = d as UCStorage; int hadNum = 0; for (int j = 0; j < uccontrol.TotalNum; j++) { Label label = uccontrol.StoreCars.FindName("locator_" + j) as Label; if (j < CarList.Count) { label.Tag = CarList[j].CarNo; label.Background = new SolidColorBrush(Colors.Blue); // label.Content = CarList[j].CarNo + "\r\n" + CarList[j].MaterialNo; hadNum++; } else { label.Tag = ""; label.Content = ""; label.Background = new SolidColorBrush(Colors.Gray); } } } catch (Exception ex) { MethodInfo method = (MethodInfo)MethodBase.GetCurrentMethod(); Common.Log.Error(method.DeclaringType.FullName + "-" + method.Name + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); } } #endregion #region 库区名称 /// /// 库区名称 /// public string StorageNm { get { return (string)GetValue(StorageNmProperty); } set { SetValue(StorageNmProperty, value); } } public static DependencyProperty StorageNmProperty = DependencyProperty.Register("StorageNm", typeof(string), typeof(UCStorage), new PropertyMetadata("", new PropertyChangedCallback(StorageNmValuePropertyChanged))); //属性默认值 private static void StorageNmValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { try { var control = d as UCStorage; control.txtStoreNm.Text = e.NewValue.ToString(); } catch (Exception ex) { MethodInfo method = (MethodInfo)MethodBase.GetCurrentMethod(); Common.Log.Error(method.DeclaringType.FullName + "-" + method.Name + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); } } #endregion #region 库位类型 /// /// 库位类型 /// public string AreaType { get { return (string)GetValue(StorageTypeProperty); } set { SetValue(StorageTypeProperty, value); } } public static DependencyProperty StorageTypeProperty = DependencyProperty.Register("AreaType", typeof(string), typeof(UCStorage), new PropertyMetadata("", new PropertyChangedCallback(StorageTypeValuePropertyChanged))); //属性默认值 private static void StorageTypeValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { try { var control = d as UCStorage; int type = string.IsNullOrEmpty(e.NewValue.ToString()) ? 0 : Convert.ToInt32(e.NewValue); if (type == 1) { //如果库 0 是从右向左 ,1 是 从左向右 control.StoreCars.FlowDirection = FlowDirection.RightToLeft; } } catch (Exception ex) { MethodInfo method = (MethodInfo)MethodBase.GetCurrentMethod(); Common.Log.Error(method.DeclaringType.FullName + "-" + method.Name + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); } } #endregion private void CarClick(object obj, MouseButtonEventArgs e) { if (SetCarLocatorEvent != null) { Label lblcar = obj as Label; if (obj != null && lblcar.Tag.ToString() != "") { SetCarLocatorEvent(lblcar.Tag.ToString()); } } } } }