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; using XGL.Models; namespace XGL.UControl { /// /// UCStorageNewx.xaml 的交互逻辑 /// public partial class UCStorageNewx : UserControl { /// /// 小车列表 /// private List CarList { get; set; } public UCStorageNewx() { InitializeComponent(); } public delegate string deletegateSetLocatorMaterial(int locatorid); public deletegateSetLocatorMaterial SetLocatorMaterialEvent; public delegate string deletegateSetCarLocator(string carno); public deletegateSetCarLocator SetCarLocatorEvent; public UCStorageNewx(int locatornum, List list) { InitializeComponent(); this.TotalNum = locatornum; this.CarList = list; } public int LocatorId { get; set; } #region 库存数量 /// /// 缓存区域缓存数量 /// public int TotalNum { get { return (int)GetValue(TotalNumProperty); } set { SetValue(TotalNumProperty, value); } } public static DependencyProperty TotalNumProperty = DependencyProperty.Register("TotalNum", typeof(int), typeof(UCStorageNewx), 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 UCStorageNewx; // var panel = uccontrol.FindName("StoreCars") as StackPanel; for (int i = 0; i < totalnum; i++) { if (uccontrol.StoreCars.FindName("locator_" + i) == null) { TextBlock label = new TextBlock(); label.Width = 100; 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(UCStorageNewx), 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 UCStorageNewx; int hadNum = 0; for (int j = 0; j < uccontrol.TotalNum; j++) { TextBlock label = uccontrol.StoreCars.FindName("locator_" + j) as TextBlock; label.TextWrapping = TextWrapping.Wrap; label.TextAlignment = TextAlignment.Center; if (j < CarList.Count) { label.Tag = CarList[j].CarNo; if (CarList[j].IsOutLocator == 1) { label.Background = new SolidColorBrush(Colors.LawnGreen); } else { label.Background = new SolidColorBrush(Colors.Blue); } // label.Content = CarList[j].CarNo + "\r\n" + CarList[j].MaterialNo; label.Text = "车号: " + CarList[j].CarNo + "\r\n" + CarList[j].MaterialBarNo; hadNum++; } else { label.Tag = ""; label.Text = ""; label.Background = new SolidColorBrush(Colors.Gray); } } int person = hadNum * 100 / uccontrol.TotalNum; uccontrol.txtStoreLoad.Text = hadNum +"/"+ uccontrol.TotalNum; uccontrol.bBg.Background = new SolidColorBrush(CommonHelper.GetColor((double)person)); uccontrol.bBg.Height = hadNum * 70 / uccontrol.TotalNum; } 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(UCStorageNewx), new PropertyMetadata("", new PropertyChangedCallback(StorageNmValuePropertyChanged))); //属性默认值 private static void StorageNmValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { try { var control = d as UCStorageNewx; 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 StorageTypeNm { get { return (string)GetValue(StorageTypeNmProperty); } set { SetValue(StorageTypeNmProperty, value); } } public static DependencyProperty StorageTypeNmProperty = DependencyProperty.Register("StorageTypeNm", typeof(string), typeof(UCStorageNewx), new PropertyMetadata("", new PropertyChangedCallback(StorageTypeNmValuePropertyChanged))); //属性默认值 private static void StorageTypeNmValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { try { var control = d as UCStorageNewx; control.txtStoreType.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(UCStorageNewx), new PropertyMetadata("", new PropertyChangedCallback(StorageTypeValuePropertyChanged))); //属性默认值 private static void StorageTypeValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { try { var control = d as UCStorageNewx; 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) { TextBlock lblcar = obj as TextBlock; if (obj != null && lblcar.Tag.ToString() != "") { SetCarLocatorEvent(lblcar.Tag.ToString()); } } } private void Border_MouseDown(object sender, MouseButtonEventArgs e) { if (SetLocatorMaterialEvent != null) { SetLocatorMaterialEvent(this.LocatorId); } } } }