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;
|
|
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<SaleOutStoreInfo> allMain;
|
|
List<SegmentStockUp> allDetail;
|
|
BindingList<SaleOutStoreInfo> mainList;
|
|
BindingList<SegmentStockUp> detailList;
|
|
Thread uploadData;
|
|
Thread refreshFromServer;
|
|
|
|
public SegmentStockUpForm()
|
|
{
|
|
InitializeComponent();
|
|
allMain = new List<SaleOutStoreInfo>();
|
|
allDetail = new List<SegmentStockUp>();
|
|
// dataPicker.Text = sendTime.ToString("yyyy-MM-dd");
|
|
uScanPanel1.AfterScan += uScanPanel1_AfterScan;
|
|
this.FormClosing += delegate
|
|
{
|
|
if (uploadData != null && uploadData.IsAlive)
|
|
uploadData.Abort();
|
|
if (refreshFromServer != null && refreshFromServer.IsAlive)
|
|
refreshFromServer.Abort();
|
|
};
|
|
}
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
var initTask = new Thread(LoadBind);
|
|
initTask.Start();
|
|
uploadData = new Thread(UpLoadLocalData);
|
|
uploadData.Start();
|
|
refreshFromServer = new Thread(RefreshFromServer);
|
|
refreshFromServer.Start();
|
|
base.OnLoad(e);
|
|
}
|
|
|
|
private void LoadBind()
|
|
{
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
SegmentStockUpBL.DeleteOld();
|
|
allDetail = SegmentStockUpBL.GetLocalList(sendTime);
|
|
}));
|
|
}
|
|
|
|
private void UpLoadLocalData()
|
|
{
|
|
while (true)
|
|
{
|
|
this.Invoke(new Action(() =>
|
|
{
|
|
SegmentStockUpBL.SyncToServer();
|
|
}));
|
|
Thread.Sleep(5000);
|
|
}
|
|
}
|
|
|
|
private void RefreshFromServer()
|
|
{
|
|
while (true)
|
|
{
|
|
RefreshData();
|
|
Thread.Sleep(2 * 60 * 1000);
|
|
}
|
|
}
|
|
|
|
void RefreshData()
|
|
{
|
|
try
|
|
{
|
|
allMain = SegmentStockUpBL.GetSaleOutStoreList(sendTime);
|
|
foreach (var g in allDetail.GroupBy(x => x.DetailID))
|
|
{
|
|
var first = allMain.FirstOrDefault(x => x.DetailID == g.Key);
|
|
if (first != null)
|
|
{
|
|
first.SUnitNum = g.Sum(x => x.UnitNumber ?? 0);
|
|
first.SSecondNumber = g.Sum(x => x.SecondNumber ?? 0);
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
#if DEBUG
|
|
throw;
|
|
#endif
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
var info = SegmentStockUpBL.StockUpScan(code);
|
|
if (info == null)
|
|
{
|
|
InfoBox.Show("错误", "条码未入库", Color.Blue, 1);
|
|
return;
|
|
}
|
|
var first = allMain.FirstOrDefault(x => !x.Finishd && x.Goods_Code == info.StringExt1);
|
|
if (first == null)
|
|
{
|
|
InfoBox.Show("提示", "没有订单", Color.Red, 1);
|
|
return;
|
|
}
|
|
InsertDetail(info, first);
|
|
}
|
|
|
|
void InsertDetail(ExtensionObj scan,SaleOutStoreInfo saleOutStore)
|
|
{
|
|
var detail = new SegmentStockUp();
|
|
detail.BarCode = uScanPanel1.TextBox.Text;
|
|
detail.Date = sendTime;
|
|
detail.DetailID = saleOutStore.DetailID;
|
|
detail.DeliverGoodsLine_Name = saleOutStore.DeliverGoodsLine_Name;
|
|
detail.Goods_Name = saleOutStore.Goods_Name;
|
|
detail.BillID = saleOutStore.BillID;
|
|
detail.UnitNumber = scan.DecimalExt1;
|
|
if (detail.UnitNumber.HasValue && saleOutStore.Rate.HasValue)
|
|
detail.SecondNumber = detail.UnitNumber * saleOutStore.Rate;
|
|
SegmentStockUpBL.Insert(detail);
|
|
allDetail.Add(detail);
|
|
if (printCk.Checked)
|
|
SegmentStockUpPrint.Print(detail, saleOutStore.Customer_Name);
|
|
saleOutStore.SSecondNumber = (saleOutStore.SSecondNumber ?? 0) + (detail.SecondNumber ?? 0);
|
|
saleOutStore.SUnitNum = (saleOutStore.SUnitNum ?? 0) + (detail.UnitNumber ?? 0);
|
|
BindMainGrid(saleOutStore);
|
|
}
|
|
|
|
void BindMainGrid(SaleOutStoreInfo saleOutStore)
|
|
{
|
|
var main = new List<SaleOutStoreInfo>();
|
|
foreach (var g in allMain.Where(x => x.Goods_Name == saleOutStore.Goods_Name).GroupBy(x => x.DeliverGoodsLine_Name))
|
|
{
|
|
var item = new SaleOutStoreInfo();
|
|
var f = g.First();
|
|
main.Add(item);
|
|
item.DeliverGoodsLine_Name = g.Key;
|
|
item.Goods_Name = f.Goods_Name;
|
|
item.Goods_Spec = f.Goods_Spec;
|
|
item.SecondNumber = g.Sum(x => x.SecondNumber ?? 0);
|
|
item.UnitNum = g.Sum(x => x.UnitNum ?? 0);
|
|
item.SSecondNumber = g.Sum(x => x.SSecondNumber ?? 0);
|
|
item.SUnitNum = g.Sum(x => x.SUnitNum ?? 0);
|
|
}
|
|
mainList = new BindingList<SaleOutStoreInfo>(main.OrderBy(x => x.Finishd).ToList());
|
|
|
|
mainGridView.DataSource = mainList;
|
|
mainGridView.Refresh();
|
|
BindDetail(main.Where(x => x.DeliverGoodsLine_Name == saleOutStore.DeliverGoodsLine_Name).First());
|
|
}
|
|
|
|
void BindDetail(SaleOutStoreInfo 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);
|
|
var detail = allDetail.Where(x => x.DeliverGoodsLine_Name == first.DeliverGoodsLine_Name && x.Goods_Name == first.Goods_Name).OrderByDescending(x => x.ID);
|
|
detailList = new BindingList<SegmentStockUp>(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<SegmentStockUp>();
|
|
//}
|
|
detailGridView.DataSource = detailList;
|
|
detailGridView.Refresh();
|
|
}
|
|
|
|
private void refresh_Click(object sender, EventArgs e)
|
|
{
|
|
RefreshData();
|
|
}
|
|
|
|
//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 SaleOutStoreInfo;
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|