using ButcherFactory.BO; using ButcherFactory.BO.LocalBL; using ButcherFactory.BO.Utils; using ButcherFactory.Dialogs; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using WinFormControl; namespace ButcherFactory.CarcassSaleOut_ { public partial class CarcassSaleOutForm : Form, IWithRoleForm { #region IWithRoleForm public List RoleName { get { return new List { (short)设备类别.白条发货 }; } } public Form Generate() { return this; } #endregion BindingList saleOutStoreList; BindingList details; BindingList weightRecord; internal DateTime sendTime = DateTime.Today; internal long? deliverGoodsLineID; internal long? customerID; internal int billState; internal long? storeID; long? batchID; public CarcassSaleOutForm() { InitializeComponent(); this.Resize += CarcassSaleOutForm_Resize; uWeightControl1.ReceivedValue += uWeightControl1_ReceivedValue; uScanPanel1.AfterScan += uScanPanel1_AfterScan; productBatchSelect.SelectedIndexChanged += delegate { if (productBatchSelect.SelectedValue == null) batchID = null; else batchID = (long)productBatchSelect.SelectedValue; }; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); billState = 0; billStateBox.Text = "未审核"; sendDateBox.Text = sendTime.ToString("yyyy-MM-dd"); this.mainGridView.BorderStyle = BorderStyle.FixedSingle; weightRecord = CarcassSaleOutBL.GetUnSubmitWeightRecord(); sendGridView.DataSource = weightRecord; sendGridView.Refresh(); BindProductBatch(); } private void BindProductBatch() { var batchs = CarcassSaleOutBL.GetBatchFromEMS(); productBatchSelect.DisplayMember = "Name"; productBatchSelect.ValueMember = "ID"; productBatchSelect.DataSource = batchs; var idx = batchs.FindIndex(x => x.Date == DateTime.Today); if (idx > 0) productBatchSelect.SelectedIndex = idx; productBatchSelect.Refresh(); } void CarcassSaleOutForm_Resize(object sender, EventArgs e) { groupBox1.Height = (this.Height - 200) / 2; groupBox2.Height = groupBox1.Height; groupBox2.Location = new Point(groupBox2.Location.X, groupBox1.Height + 100); } static object _lock = new object(); void uWeightControl1_ReceivedValue(decimal weight) { lock (_lock) { this.Invoke(new Action(() => { var detail = CarcassSaleOutBL.Insert(weight); weightRecord.Insert(0, detail); sendGridView.FirstDisplayedScrollingRowIndex = 0; sendGridView.Refresh(); })); } } void uScanPanel1_AfterScan() { var barCode = uScanPanel1.TextBox.Text.Trim(); if (string.IsNullOrEmpty(barCode)) throw new Exception("条码错误"); var first = weightRecord.LastOrDefault(x => !x.Filled); if (first == null) throw new Exception("请先过磅"); CarcassSaleOutBL.FillDetail(first, barCode, batchID); sendGridView.Refresh(); } private void refreshBtn_Click(object sender, EventArgs e) { saleOutStoreList = CarcassSaleOutBL.GetSaleOutStoreList(sendTime, deliverGoodsLineID, customerID, billState, storeID); mainGridView.DataSource = saleOutStoreList; mainGridView.Refresh(); } private void weightRecordBtn_Click(object sender, EventArgs e) { if (orderGridView.CurrentRow == null) throw new Exception("请选择配货明细"); var detailID = (long)orderGridView.CurrentRow.Cells[0].Value; new WeightRecordDialog(detailID).ShowDialog(); } private void goodsFinishBtn_Click(object sender, EventArgs e) { if (mainGridView.CurrentRow == null) throw new Exception("请选择要配货完成的发货单"); var id = (long)mainGridView.CurrentRow.Cells[0].Value; CarcassSaleOutBL.SetGoodsFinish(id); saleOutStoreList.Remove(saleOutStoreList.First(x => x.ID == id)); mainGridView.Refresh(); details.Clear(); orderGridView.Refresh(); UMessageBox.Show("配货完成!"); } private void commitBtn_Click(object sender, EventArgs e) { if (orderGridView.CurrentRow == null) throw new Exception("请选择配货明细"); if (weightRecord.Count == 0) throw new Exception("没有发货明细"); if (weightRecord.Any(x => !x.Filled)) throw new Exception("有未扫码的明细"); var detailID = (long)orderGridView.CurrentRow.Cells[0].Value; var detail = details.First(x => x.ID == detailID); CarcassSaleOutBL.SubmitDetails(weightRecord, detail); weightRecord.Clear(); sendGridView.Refresh(); orderGridView.Refresh(); UMessageBox.Show("提交成功!"); } private void closeBtn_Click(object sender, EventArgs e) { Close(); } private void queryControl_MouseDown(object sender, MouseEventArgs e) { var textBox = sender as TextBox; switch (textBox.Name) { case "sendDateBox": var cs = new CalendarSelecter(); if (cs.ShowDialog() == true) { sendTime = cs.Result; sendDateBox.Text = sendTime.ToString("yyyy-MM-dd"); } break; case "deliverGoodsLineBox": var dgl = new SelectDeliverGoodsLineDialog(); if (dgl.ShowDialog() == DialogResult.OK) { textBox.Text = dgl.Result.Item1; deliverGoodsLineID = dgl.Result.Item2; } break; case "customerBox": var cb = new SelectCustomerDialog(); if (cb.ShowDialog() == DialogResult.OK) { textBox.Text = cb.Result.Item1; customerID = cb.Result.Item2; } break; case "billStateBox": var bs = new SelectBillStateDialog(); if (bs.ShowDialog() == DialogResult.OK) { textBox.Text = bs.Result.Item1; billState = bs.Result.Item2; } break; case "storeBox": var sb = new SelectStoreDialog(); if (sb.ShowDialog() == DialogResult.OK) { textBox.Text = sb.Result.Item1; storeID = sb.Result.Item2; } break; } } private void clearBtn_Click(object sender, EventArgs e) { billState = 0; billStateBox.Text = "未审核"; sendTime = DateTime.Today; sendDateBox.Text = sendTime.ToString("yyyy-MM-dd"); deliverGoodsLineBox.Clear(); deliverGoodsLineID = null; customerBox.Clear(); customerID = null; storeBox.Clear(); storeID = null; } private void mainGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { var id = (long)mainGridView.CurrentRow.Cells[0].Value; var first = saleOutStoreList.First(x => x.ID == id); billIDLabel.Text = id.ToString(); customerLabel.Text = first.Customer_Name; addressLabel.Text = first.Address; carNumberLabel.Text = first.CarNumber; details = CarcassSaleOutBL.GetSaleOutStoreDetailList(id); foreach (var item in details) { item.SaleOutStore_ID = id; item.Customer_Name = first.Customer_Name; } orderGridView.DataSource = details; if (details.Any()) orderGridView.FirstDisplayedScrollingRowIndex = 0; orderGridView.Refresh(); } } }