using ButcherFactory.BO;
|
|
using ButcherFactory.BO.LocalBL;
|
|
using ButcherFactory.BO.Utils;
|
|
using ButcherFactory.Controls;
|
|
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;
|
|
|
|
namespace ButcherFactory.SegmentStockUp_
|
|
{
|
|
public partial class SegmentStockUpForm : FormTemplate, IWithRoleForm
|
|
{
|
|
#region IWithRoleForm
|
|
public List<short> RoleName
|
|
{
|
|
get { return new List<short> { (short)设备类别.销售备货 }; }
|
|
}
|
|
|
|
public Form Generate()
|
|
{
|
|
return this;
|
|
}
|
|
#endregion
|
|
|
|
DateTime sendTime = DateTime.Today;
|
|
List<StockUpEntity> allMain;
|
|
List<StockUpDetail> allDetail;
|
|
BindingList<StockUpEntity> mainList;
|
|
BindingList<StockUpDetail> detailList;
|
|
|
|
public SegmentStockUpForm()
|
|
{
|
|
InitializeComponent();
|
|
allMain = new List<StockUpEntity>();
|
|
allDetail = new List<StockUpDetail>();
|
|
dataPicker.Text = sendTime.ToString("yyyy-MM-dd");
|
|
uScanPanel1.AfterScan += uScanPanel1_AfterScan;
|
|
}
|
|
|
|
void uScanPanel1_AfterScan()
|
|
{
|
|
var code = uScanPanel1.TextBox.Text;
|
|
if (string.IsNullOrEmpty(code))
|
|
return;
|
|
if (allDetail.Any(x => x.BarCode == code))
|
|
{
|
|
InfoBox.Show("错误", "条码已使用过", Color.Green, 1);
|
|
return;
|
|
}
|
|
if (SegmentStockUpBL.CheckBarCodeUsed(code))
|
|
{
|
|
InfoBox.Show("错误", "条码已使用过", Color.Green, 1);
|
|
return;
|
|
}
|
|
var info = SegmentStockUpBL.StockUpScan(code);
|
|
if (info == null)
|
|
{
|
|
InfoBox.Show("错误", "条码未入库", Color.Blue, 1);
|
|
return;
|
|
}
|
|
if (!allMain.Any(x => x.Goods_Code == info.StringExt1 && x.Date == sendTime))
|
|
{
|
|
var gt = SegmentStockUpBL.GetStockUpEntity(sendTime, info.StringExt1);
|
|
allMain.AddRange(gt);
|
|
var first = gt.Where(x => !x.Finishd).OrderBy(x => x.SequenceNumber).FirstOrDefault();
|
|
if (first != null)
|
|
FillAllDetail(sendTime, first.DeliverGoodsLine_ID, first.Goods_ID);
|
|
else
|
|
{
|
|
InfoBox.Show("提示", "没有订单", Color.Red, 1);
|
|
return;
|
|
}
|
|
}
|
|
InsertDetail(info);
|
|
}
|
|
|
|
void InsertDetail(ExtensionObj scan)
|
|
{
|
|
var first = allMain.Where(x => x.Date == sendTime && x.Goods_Code == scan.StringExt1 && !x.Finishd).OrderBy(x => x.SequenceNumber).FirstOrDefault();
|
|
if (first == null)
|
|
{
|
|
InfoBox.Show("提示", "没有订单", Color.Red, 1);
|
|
return;
|
|
}
|
|
var detail = new StockUpDetail();
|
|
detail.BarCode = uScanPanel1.TextBox.Text;
|
|
detail.Date = sendTime;
|
|
detail.DeliverGoodsLine_ID = first.DeliverGoodsLine_ID;
|
|
detail.DeliverGoodsLine_Name = first.DeliverGoodsLine_Name;
|
|
detail.Goods_Code = first.Goods_Code;
|
|
detail.Goods_ID = first.Goods_ID;
|
|
detail.Goods_Name = first.Goods_Name;
|
|
detail.Goods_Spec = first.Goods_Spec;
|
|
detail.UnitNumber = scan.DecimalExt1;
|
|
if (detail.UnitNumber.HasValue && first.Rate.HasValue)
|
|
detail.SecondNumber = detail.UnitNumber * first.Rate;
|
|
var customer = SegmentStockUpBL.InsertStockUpDetail(detail);
|
|
if (string.IsNullOrEmpty(customer))
|
|
{
|
|
InfoBox.Show("提示", "没有订单", Color.Red, 1);
|
|
return;
|
|
}
|
|
allDetail.Add(detail);
|
|
first.SSecondNumber = (first.SSecondNumber ?? 0) + (detail.SecondNumber ?? 0);
|
|
first.SUnitNum = (first.SUnitNum ?? 0) + (detail.UnitNumber ?? 0);
|
|
BindMainGrid(sendTime, first.Goods_ID);
|
|
if (printCk.Checked)
|
|
SegmentStockUpPrint.Print(detail, customer);
|
|
}
|
|
|
|
void FillAllDetail(DateTime date, long driverLineID, long goodsID)
|
|
{
|
|
if (allDetail.Any(x => x.Date == date && x.DeliverGoodsLine_ID == driverLineID && x.Goods_ID == goodsID))
|
|
return;
|
|
var n = SegmentStockUpBL.GetDetails(date, driverLineID, goodsID);
|
|
allDetail.AddRange(n);
|
|
}
|
|
|
|
void BindMainGrid(DateTime date, long goodsID)
|
|
{
|
|
var main = allMain.Where(x => x.Date == date && x.Goods_ID == goodsID).OrderBy(x => x.Finishd).OrderBy(x => x.SequenceNumber);
|
|
mainList = new BindingList<StockUpEntity>(main.ToList());
|
|
|
|
mainGridView.DataSource = mainList;
|
|
mainGridView.Refresh();
|
|
BindDetail(main.FirstOrDefault());
|
|
}
|
|
|
|
void BindDetail(StockUpEntity first)
|
|
{
|
|
if (first != null)
|
|
{
|
|
driveLineLbl.Text = first.DeliverGoodsLine_Name;
|
|
goodsLbl.Text = first.Goods_Name;
|
|
|
|
dhNumberLbl.Text = string.Format("{0:#0.##}", first.SecondNumber);
|
|
dhUnitNumLbl.Text = string.Format("{0:#0.##}", first.UnitNum);
|
|
bhNumberLbl.Text = string.Format("{0:#0.##}", first.SSecondNumber);
|
|
bhUnitNumLbl.Text = string.Format("{0:#0.##}", first.SUnitNum);
|
|
if (!allDetail.Any(x => x.Date == first.Date && x.DeliverGoodsLine_ID == first.DeliverGoodsLine_ID && x.Goods_ID == first.Goods_ID))
|
|
allDetail.AddRange(SegmentStockUpBL.GetDetails(first.Date, first.DeliverGoodsLine_ID, first.Goods_ID));
|
|
var detail = allDetail.Where(x => x.Date == first.Date && x.DeliverGoodsLine_ID == first.DeliverGoodsLine_ID && x.Goods_ID == first.Goods_ID).OrderByDescending(x => x.ID);
|
|
detailList = new BindingList<StockUpDetail>(detail.ToList());
|
|
}
|
|
else
|
|
{
|
|
driveLineLbl.Text = string.Empty;
|
|
goodsLbl.Text = string.Empty;
|
|
dhNumberLbl.Text = string.Empty;
|
|
dhUnitNumLbl.Text = string.Empty;
|
|
bhNumberLbl.Text = string.Empty;
|
|
bhUnitNumLbl.Text = string.Empty;
|
|
|
|
detailList = new BindingList<StockUpDetail>();
|
|
}
|
|
detailGridView.DataSource = detailList;
|
|
detailGridView.Refresh();
|
|
}
|
|
|
|
private void refresh_Click(object sender, EventArgs e)
|
|
{
|
|
if (mainList == null || !mainList.Any())
|
|
return;
|
|
allMain = SegmentStockUpBL.RefreshList(sendTime, allMain.Select(x => x.Goods_ID).Distinct());
|
|
allDetail.Clear();
|
|
BindMainGrid(sendTime, mainList.First().Goods_ID);
|
|
}
|
|
|
|
private void dataPicker_Click(object sender, EventArgs e)
|
|
{
|
|
var cs = new CalendarSelecter();
|
|
if (cs.ShowDialog() == true)
|
|
{
|
|
sendTime = cs.Result;
|
|
dataPicker.Text = sendTime.ToString("yyyy-MM-dd");
|
|
}
|
|
}
|
|
|
|
private void mainGridView_CellClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if (e.RowIndex < 0)
|
|
return;
|
|
var item = mainGridView.CurrentRow.DataBoundItem as StockUpEntity;
|
|
BindDetail(item);
|
|
}
|
|
|
|
private void mainGridView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
|
|
{
|
|
DataGridViewRow dgrSingle = mainGridView.Rows[e.RowIndex];
|
|
var v = (bool)dgrSingle.Cells["D_Finishd"].Value;
|
|
if (v)
|
|
{
|
|
dgrSingle.DefaultCellStyle.BackColor = Color.YellowGreen;
|
|
}
|
|
}
|
|
}
|
|
}
|