You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

303 lines
10 KiB

using B3DealerClient.BL;
using B3DealerClient.BO;
using B3DealerClient.Control;
using B3DealerClient.Dialogs;
using B3DealerClient.Utils;
using System;
using System.Collections.Generic;
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.Shapes;
namespace B3DealerClient.Windows.CarcassSaleOutWindow_
{
/// <summary>
/// CarcassSaleOutWindow.xaml 的交互逻辑
/// </summary>
public partial class CarcassSaleOutWindow : Window
{
CarcassSaleOutContext context;
CarcassSaleOutConfig config;
int pageSize;
int pageIndex;
public CarcassSaleOutWindow()
{
InitializeComponent();
Rect rc = SystemParameters.WorkArea;//获取工作区大小
this.Width = rc.Width;
this.Height = rc.Height;
context = new CarcassSaleOutContext();
this.DataContext = context;
this.Loaded += CarcassSaleOutWindow_Loaded;
this.weightControl.ReceivedValue += weightControl_ReceivedValue;
weightControl.weightSwitch.Click += weightSwitch_Click;
}
void weightSwitch_Click(object sender, RoutedEventArgs e)
{
if (!weightControl.SwitchOn)
context.Weight = 0;
}
void weightControl_ReceivedValue(decimal weight)
{
context.Weight = weight;
}
void CarcassSaleOutWindow_Loaded(object sender, RoutedEventArgs e)
{
config = XmlUtil.DeserializeFromFile<CarcassSaleOutConfig>();
if (config.Store != null)
context.Store.Fill(config.Store);
context.HookWeight = config.HookWeight;
pageSize = (int)customerPanel.ActualHeight / 60;
}
private void NumberBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
var numberPad = new NumberPad(this);
if (numberPad.ShowDialog() == true)
{
decimal value = 0;
if (!string.IsNullOrEmpty(numberPad.Result) && !decimal.TryParse(numberPad.Result, out value))
throw new Exception("输入错误");
var name = (sender as TextBox).Name;
switch (name)
{
case "hook":
context.HookWeight = value;
config.HookWeight = value;
break;
//case "number":
// context.Number = value;
// config.Number = value;
// break;
}
XmlUtil.SerializerObjToFile(config);
}
}
private void BaseInfoBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
var tb = sender as FrameworkElement;
var dig = new BaseInfoDialog(tb.Name);
if (dig.ShowDialog() == true)
{
switch (tb.Name)
{
case "DriverGoodsLine":
context.DriverGoodsLine.Fill(dig.Result);
pageIndex = 0;
BindCustomerPanel();
break;
case "Store":
context.Store.Fill(dig.Result);
config.Store = dig.Result;
XmlUtil.SerializerObjToFile(config);
break;
}
}
}
void BindCustomerPanel()
{
context.CustomerList = CarcassSaleOutBL.GetCustomers(new
{
Date = context.Date,
Store_ID = context.Store.ID,
DeliverGoodsLine_ID = context.DriverGoodsLine.ID,
PageIndex = pageIndex,
PageSize = pageSize
});
}
private void PageBtn_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
var tag = (sender as Button).Tag.ToString();
if (tag == "0")
{
if (pageIndex == 0)
return;
pageIndex -= 1;
BindCustomerPanel();
}
else
{
if (context.CustomerList == null || context.CustomerList.Count < pageSize)
return;
pageIndex += 1;
BindCustomerPanel();
}
}
private void NumberBtn_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
var c = (sender as Button).Content.ToString();
switch (c)
{
case "0":
context.StrNumber = "0";
break;
case "./点":
if (string.IsNullOrEmpty(context.StrNumber))
context.StrNumber = "0.";
else if (context.StrNumber.Contains('.'))
return;
else
context.StrNumber += ".";
break;
default:
if (context.StrNumber == "0")
context.StrNumber = c;
else
context.StrNumber += c;
break;
}
}
private void CustomerBtn_PriviewMouseDown(object sender, MouseButtonEventArgs e)
{
if (context.Dmo != null)
context.Dmo = null;
if (context.Detail != null)
context.Detail = null;
if (context.Details.Any())
context.Details.Clear();
var obj = (sender as ListBoxItem).DataContext as CustomerObj;
context.DmoList = CarcassSaleOutBL.GetDmoList(new
{
Date = context.Date,
Customer_ID = obj.ID,
Store_ID = context.Store.ID,
AssignFinished = obj.Finished
});
foreach (var item in context.CustomerList)
{
if (item.Selected && !item.Equals(obj))
item.Selected = false;
else if (!item.Selected && item.Equals(obj))
item.Selected = true;
}
}
private void MainGridFocus(object sender, MouseButtonEventArgs e)
{
var row = sender as DataGridRow;
context.Dmo = row.Item as CarcassSaleOut;
foreach (var item in context.DmoList)
{
if (item.Selected && item.ID != context.Dmo.ID)
item.Selected = false;
else if (item.Selected && item.ID == context.Dmo.ID)
context.Dmo.Selected = true;
}
MainSelected();
}
void MainSelected()
{
context.Details.Clear();
var details = CarcassSaleOutBL.GetDetailRecords(context.Dmo.DetailID);
foreach (var item in details)
context.Details.Add(item);
context.Detail = context.Details.FirstOrDefault();
DetailSelected();
}
private void DetailGridFocus(object sender, MouseButtonEventArgs e)
{
var row = sender as DataGridRow;
context.Detail = row.Item as CarcassSaleOut_Record;
DetailSelected();
}
void DetailSelected()
{
if (context.Detail == null)
return;
foreach (var item in context.Details)
{
if (item.Selected && item.ID != context.Detail.ID)
item.Selected = false;
else if (!item.Selected && item.ID == context.Detail.ID)
item.Selected = true;
}
}
private void DeleteBtn_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
var confirm = MessageBox.Show("确定要删除选中记录吗?", "删除确认", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (confirm == MessageBoxResult.OK)
{
CarcassSaleOutBL.Delete(context.Detail.ID);
context.Details.Remove(context.Detail);
context.Dmo.AlreadyNumber = (context.Dmo.AlreadyNumber ?? 0) - context.Detail.NetWeight;
context.Dmo.AlreadySecondNumber = (context.Dmo.AlreadySecondNumber ?? 0) - context.Detail.SecondNumber;
context.Detail = context.Details.FirstOrDefault();
DetailSelected();
}
}
private void SaveBtn_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
var record = new CarcassSaleOut_Record();
record.MainID = context.Dmo.ID;
record.DetailID = context.Dmo.DetailID;
record.Goods_Name = context.Dmo.Goods_Name;
record.Weight = context.Weight;
record.SecondNumber = context.Number;
record.Discont = (context.HookWeight ?? 0) * Math.Ceiling(record.SecondNumber);
record.NetWeight = record.Weight - record.Discont;
record.Date = DateTime.Now;
record.Selected = true;
CarcassSaleOutBL.InsertRecord(record);
context.Details.Add(record);
context.Dmo.AlreadyNumber = (context.Dmo.AlreadyNumber ?? 0) + record.NetWeight;
context.Dmo.AlreadySecondNumber = (context.Dmo.AlreadySecondNumber ?? 0) + record.SecondNumber;
context.Detail = record;
DetailSelected();
weightControl.Weight = 0;
context.Weight = 0;
context.StrNumber = string.Empty;
}
private void ViewBtn_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
new RecordViewDialog(context.Dmo.ID).ShowDialog();
}
private void FinishBtn_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
var targets = context.DmoList.Where(x => x.ID == context.Dmo.ID);
var needConfirm = targets.Any(x => (x.AlreadyNumber ?? 0) == 0 || (x.SecondNumber ?? 0) == 0);
if (needConfirm)
{
var confirm = MessageBox.Show("存在未配货的明细,确认配货完成?", "配货完成确认", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (confirm != MessageBoxResult.OK)
return;
}
var r = MessageBox.Show("确认配货完成?", "配货完成确认", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (r != MessageBoxResult.OK)
return;
CarcassSaleOutBL.FinishAssign(context.Dmo.ID);
foreach (var item in targets)
item.AssignFinished = true;
context.Dmo = context.Dmo;
MessageBox.Show("配货完成");
}
}
}