using ButcherManage.BO;
|
|
using ButcherManage.BO.Bill;
|
|
using ButcherManage.BO.Enums;
|
|
using ButcherManage.BO.LocalBL;
|
|
using ButcherManage.BO.Utils;
|
|
using ButcherManage.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 ButcherManage.OrderConfirm_
|
|
{
|
|
public partial class OrderConfirmForm : Form, IWithRoleForm
|
|
{
|
|
#region IWithRoleForm
|
|
public List<short> RoleName
|
|
{
|
|
get { return new List<short> { (short)设备类别.上线确认 }; }
|
|
}
|
|
|
|
public Form Generate()
|
|
{
|
|
return this;
|
|
}
|
|
#endregion
|
|
|
|
IList<OrderDetail> list;
|
|
List<OrderConfirmDetail> records;
|
|
DateTime date = DateTime.Today;
|
|
OrderDetail current;
|
|
|
|
public OrderConfirmForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
base.OnLoad(e);
|
|
datePicker.Text = date.ToString("yyyy-MM-dd");
|
|
BindGrid();
|
|
FillNumberPad();
|
|
}
|
|
|
|
void RefreshRecordGrid()
|
|
{
|
|
if (current == null)
|
|
return;
|
|
records = OrderConfirmBL.GetRecords(current.ID);
|
|
var row = records.Count % 5;
|
|
if (records.Count % 5 == 0)
|
|
{
|
|
records.Add(new OrderConfirmDetail() { OrderDetail_ID = current.ID });
|
|
row = 0;
|
|
}
|
|
BindRecorGrid();
|
|
BindLabel();
|
|
recordGrid.Rows[records.Count / 5].Cells[row].Selected = true;
|
|
}
|
|
|
|
void BindLabel()
|
|
{
|
|
countLbl.Text = records.Where(x => x.Number > 0).Count().ToString();
|
|
numberLbl.Text = records.Sum(x => x.Number).ToString();
|
|
}
|
|
|
|
private void BindGrid()
|
|
{
|
|
list = OrderConfirmBL.GetOrderDetail(date).OrderBy(x => x.Order).OrderBy(x => x.Doing).ToList();
|
|
orderGrid.DataSource = list;
|
|
|
|
current = list.FirstOrDefault();
|
|
foreach (DataGridViewRow row in orderGrid.Rows)
|
|
{
|
|
var state = (int)row.Cells["L_OrderState"].Value;
|
|
if (state == 20)
|
|
{
|
|
row.Cells[orderGrid.Columns.Count - 1] = new DataGridViewTextBoxCell();
|
|
row.Cells[orderGrid.Columns.Count - 2] = new DataGridViewTextBoxCell();
|
|
}
|
|
else
|
|
{
|
|
row.Cells[orderGrid.Columns.Count - 2].Value = state == 0 ? "开始" : "取消";
|
|
if (state == 10)
|
|
{
|
|
var btnCell = ((DataGridViewButtonCell)row.Cells[orderGrid.Columns.Count - 2]);
|
|
btnCell.Style.BackColor = Color.LightSkyBlue;
|
|
btnCell.Style.SelectionBackColor = Color.LightSkyBlue;
|
|
}
|
|
}
|
|
}
|
|
orderGrid.Refresh();
|
|
orderLabel.Text = current == null ? "0" : current.Order.ToString();
|
|
finishNumberLabel.Text = list.Where(x => x.OrderState == 20).Sum(x => x.PlanNumber).ToString();
|
|
RefreshRecordGrid();
|
|
}
|
|
|
|
private void FillNumberPad()
|
|
{
|
|
for (var i = 1; i < 10; i++)
|
|
CreateBtn(i.ToString());
|
|
}
|
|
|
|
void CreateBtn(string content)
|
|
{
|
|
var btn = new NButton() { Width = 100, Height = 60, Text = content, Font = new Font("宋体", 15), Margin = new Padding(18, 10, 18, 20), PlaySound = true };
|
|
btn.Click += NumberBtnClick;
|
|
numPad.Controls.Add(btn);
|
|
}
|
|
|
|
private void NumberBtnClick(object sender, EventArgs e)
|
|
{
|
|
if (current == null)
|
|
{
|
|
NMessageBox.ShowDialog("没有待处理的数据");
|
|
return;
|
|
}
|
|
var number = int.Parse((sender as NButton).Text);
|
|
var cell = recordGrid.CurrentCell;
|
|
if (cell.Value == null && number == 0)
|
|
return;
|
|
var idx = cell.RowIndex * 5 + cell.ColumnIndex;
|
|
var detail = new OrderConfirmDetail();
|
|
if (idx > records.Count - 1)
|
|
{
|
|
if (cell.RowIndex != records.Count / 5 || cell.ColumnIndex != records.Count % 5)
|
|
cell = recordGrid.Rows[records.Count / 5].Cells[records.Count % 5];
|
|
detail.OrderDetail_ID = current.ID;
|
|
detail.Number = number;
|
|
records.Add(detail);
|
|
}
|
|
else
|
|
{
|
|
detail = records[idx];
|
|
detail.Number = number;
|
|
}
|
|
OrderConfirmBL.SaveRecord(detail);
|
|
cell.Value = number;
|
|
var row = records.Count % 5;
|
|
if (records[records.Count - 1].Number == null)
|
|
row -= 1;
|
|
if (records.Count % 5 == 0)
|
|
{
|
|
records.Add(new OrderConfirmDetail() { OrderDetail_ID = current.ID });
|
|
row = 0;
|
|
BindRecorGrid();
|
|
}
|
|
recordGrid.Rows[records.Count / 5].Cells[row].Selected = true;
|
|
var v = records.Sum(x => x.Number ?? 0);
|
|
orderGrid.CurrentRow.Cells["L_ConfirmNumber"].Value = v;
|
|
current.ConfirmNumber = v;
|
|
BindLabel();
|
|
}
|
|
|
|
void BindRecorGrid()
|
|
{
|
|
recordGrid.DataSource = EntityExpand.Build(records);
|
|
recordGrid.Refresh();
|
|
}
|
|
|
|
private void colseBtn_Click(object sender, EventArgs e)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
private void orderGrid_CellClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if (e.RowIndex < 0)
|
|
return;
|
|
var id = (long)orderGrid.CurrentRow.Cells[0].Value;
|
|
if (id == current.ID)
|
|
return;
|
|
current = list.First(x => x.ID == id);
|
|
orderLabel.Text = current.Order.ToString();
|
|
RefreshRecordGrid();
|
|
}
|
|
|
|
private void orderGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if (e.ColumnIndex < orderGrid.Columns.Count - 2 || e.RowIndex == -1)
|
|
return;
|
|
if (e.ColumnIndex == orderGrid.Columns.Count - 1)
|
|
OrderConfirmBL.SetOrderState(current.ID, 20);
|
|
else
|
|
{
|
|
OrderConfirmBL.SetOrderState(current.ID, current.OrderState == 0 ? 10 : 0);
|
|
finishNumberLabel.Text = list.Where(x => x.OrderState == 20).Sum(x => x.PlanNumber).ToString();
|
|
}
|
|
BindGrid();
|
|
}
|
|
|
|
private void datePicker_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
var cs = new CalendarSelecter();
|
|
if (cs.ShowDialog() == true)
|
|
{
|
|
date = cs.Result;
|
|
datePicker.Text = date.ToString("yyyy-MM-dd");
|
|
}
|
|
}
|
|
|
|
private void queryBtn_Click(object sender, EventArgs e)
|
|
{
|
|
BindGrid();
|
|
}
|
|
|
|
private void orderGrid_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
|
|
{
|
|
DataGridViewRow dgrSingle = orderGrid.Rows[e.RowIndex];
|
|
if ((bool)dgrSingle.Cells["L_SecondarySplit"].Value)
|
|
dgrSingle.DefaultCellStyle.BackColor = Color.YellowGreen;
|
|
else if ((bool)dgrSingle.Cells["L_IsHurryButcher"].Value)
|
|
dgrSingle.DefaultCellStyle.BackColor = Color.LightBlue;
|
|
}
|
|
|
|
string code = string.Empty;
|
|
bool start = false;
|
|
private void OrderConfirmForm_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
switch (e.KeyChar)
|
|
{
|
|
case (char)Keys.S:
|
|
start = true;
|
|
code = string.Empty;
|
|
break;
|
|
case (char)Keys.E:
|
|
if (!start)
|
|
break;
|
|
InsertDetail();
|
|
start = false;
|
|
code = string.Empty;
|
|
break;
|
|
default:
|
|
if (start)
|
|
code += e.KeyChar.ToString();
|
|
break;
|
|
}
|
|
}
|
|
|
|
void InsertDetail()
|
|
{
|
|
long id = 0;
|
|
if (!long.TryParse(code, out id))
|
|
throw new Exception(string.Format("接收扫码输入错误 {0}", code));
|
|
var entity = OrderConfirmBL.GetHurryRecord(id);
|
|
if (entity.ToOrderDetail_ID.HasValue)
|
|
throw new Exception("该条码已插入过,不能重复插入");
|
|
var currentOrder = 0;
|
|
if (!setTop.Checked)
|
|
{
|
|
if (current != null)
|
|
currentOrder = OrderConfirmBL.GetCurrentOrder(current.ID);
|
|
else
|
|
currentOrder = OrderConfirmBL.GetMaxOrder(date);
|
|
currentOrder++;
|
|
}
|
|
else
|
|
{
|
|
setTop.Checked = false;
|
|
var l = list.OrderBy(x => x.Order).OrderBy(x => x.Doing).FirstOrDefault();
|
|
if (l != null)
|
|
currentOrder = l.Order;
|
|
else
|
|
currentOrder = 1;
|
|
}
|
|
var order = new OrderDetail();
|
|
order.Order = currentOrder;
|
|
order.LiveColonyHouse_Name = entity.LiveColonyHouse_Name;
|
|
order.PlanNumber = entity.HurryNumber;
|
|
order.WeightBill_ID = entity.WeightBill_ID;
|
|
order.B3WeighBill_ID = entity.B3WeighBill_ID;
|
|
order.Date = date;
|
|
order.IsHurryButcher = true;
|
|
OrderConfirmBL.InsertByHurryRecord(order, id);
|
|
BindGrid();
|
|
}
|
|
}
|
|
}
|