using BBWY.Client.APIServices; using BBWY.Client.Models; using BBWY.Client.Models.FallWare; using BBWY.Controls; using System; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; using WebSocketSharp; namespace BBWY.Client.Views.FallWare { /// /// SetJDWareBoxWindow2.xaml 的交互逻辑 /// public partial class SetJDWareBoxWindow2 : BWindow { public JDWareBoxModel JDWareBoxModel { get; set; } private SealBoxService sealBoxService; private Action reflashWindow; public WareType wareType { get; set; } public bool IsEnabled { get; set; } public bool IsLoading { get => isLoading; set { Set(ref isLoading, value); } } private bool isLoading; public SetJDWareBoxWindow2(JDWareBoxModel model, SealBoxService sealBoxService, WareType wareType, Action reflashWindow, bool isEnabled = true) { InitializeComponent(); this.sealBoxService = sealBoxService; this.wareType = wareType; this.reflashWindow = reflashWindow; JDWareBoxModel = model; this.IsEnabled = isEnabled; this.DataContext = this; switch (wareType) { case WareType.京仓: btn_yuncang.IsEnabled = false; btn_jushuitang.IsEnabled = false; panel_jingcang.Visibility= Visibility.Visible; panel_yuncang.Visibility= Visibility.Collapsed; panel_jst.Visibility= Visibility.Collapsed; break; case WareType.云仓: btn_jingcang.IsEnabled = false; btn_jushuitang.IsEnabled = false; panel_jingcang.Visibility = Visibility.Collapsed; panel_yuncang.Visibility = Visibility.Visible; panel_jst.Visibility = Visibility.Collapsed; break; case WareType.商家仓: break; case WareType.聚水潭齐越仓: btn_yuncang.IsEnabled = false; btn_jingcang.IsEnabled = false; panel_jingcang.Visibility = Visibility.Collapsed; panel_yuncang.Visibility = Visibility.Collapsed; panel_jst.Visibility = Visibility.Visible; break; default: break; } } private void btn_save_Click(object sender, System.Windows.RoutedEventArgs e) { if (wareType == WareType.京仓) { if (string.IsNullOrEmpty(JDWareBoxModel.ProductTitle) || string.IsNullOrEmpty(JDWareBoxModel.PrewOrder) || string.IsNullOrEmpty(JDWareBoxModel.PurchaseOrder)) { MessageBox.Show("信息不完整", "提示"); return; } IsLoading = true; Task.Factory.StartNew(() => { var getDetailResponse = sealBoxService.GetJDSupplierNameAndStoreName(JDWareBoxModel.PurchaseOrder); if (!getDetailResponse.Success) { IsLoading = false; this.Dispatcher.Invoke(() => MessageBox.Show(getDetailResponse.Msg, "提示")); return; } var res = sealBoxService.SetFallWareConfigure(JDWareBoxModel.SealBoxId, JDWareBoxModel.ProductTitle, JDWareBoxModel.PurchaseOrder, JDWareBoxModel.PrewOrder, JDWareBoxModel.WaybillNo, getDetailResponse.Data.SupplierName, getDetailResponse.Data.StoreName); if (!res.Success) { IsLoading = false; this.Dispatcher.Invoke(() => MessageBox.Show(res.Msg, "提示")); return; } IsLoading = false; this.Dispatcher.Invoke(() => { reflashWindow?.Invoke(); this.Close(); }); }); return; } if (wareType == WareType.云仓|| wareType == WareType.聚水潭齐越仓) { if (JDWareBoxModel.PurchaseOrder.IsNullOrEmpty()) { MessageBox.Show("采购单号不能为空"); return; } if (wareType == WareType.云仓 ) { if (!JDWareBoxModel.PurchaseOrder.ToUpper().StartsWith("CPL")) { MessageBox.Show("CLPS采购单号必须以CPL开头"); return; } var number = JDWareBoxModel.PurchaseOrder.ToUpper().Substring(3); var result = long.TryParse(number, out long res); if (!result||number.Length!=13) { MessageBox.Show("CLPS采购单号必须以CPL开头,且后面为13位数字"); return; } } Task.Factory.StartNew(() => { var res = sealBoxService.SetFallWareConfigure(JDWareBoxModel.SealBoxId, JDWareBoxModel.ProductTitle, JDWareBoxModel.PurchaseOrder.ToUpper(), JDWareBoxModel.PrewOrder, JDWareBoxModel.WaybillNo, null, null); if (!res.Success) { IsLoading = false; this.Dispatcher.Invoke(() => MessageBox.Show(res.Msg, "提示")); return; } IsLoading = false; this.Dispatcher.Invoke(() => { reflashWindow?.Invoke(); this.Close(); }); }); } } } }