屠宰场客户端
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.

201 lines
5.5 KiB

using ButcherManage.BO;
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.HotPickSelector_
{
public partial class HotPickSelector : Form, IWithRoleForm
{
#region IWithRoleForm
public List<short> RoleName
{
get { return new List<short> { (short).线 }; }
}
public Form Generate()
{
return this;
}
#endregion
List<HotPick> list;
List<HotPick_Detail> records;
DateTime date = DateTime.Today;
HotPick current;
public HotPickSelector()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
datePicker.Text = date.ToString("yyyy-MM-dd");
BindGrid();
FillNumberPad();
}
void RefreshRecordGrid()//bindgrid、numberclick
{
if (current == null)
return;
records = HotPickBL.GetSecondOrderDetails(current.ID);
var row = records.Count % 5;
if (records.Count % 5 == 0)
{
records.Add(new HotPick_Detail() { SecondOrder_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();
hotNumLbl.Text = list.Sum(x => x.HotFadeNumber).ToString();
}
private void BindGrid()//onload、query、finish
{
list = HotPickBL.GetSecondOrderList(date).OrderBy(x => x.Order).OrderBy(x => x.Finish).ToList();
orderGrid.DataSource = list;
current = list.FirstOrDefault();
foreach (DataGridViewRow row in orderGrid.Rows)
{
if ((bool)row.Cells["L_Finish"].Value)
row.Cells[orderGrid.Columns.Count - 1] = new DataGridViewTextBoxCell();
}
orderGrid.Refresh();
orderLbl.Text = current == null ? "0" : current.Order.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 HotPick_Detail();
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.SecondOrder_ID = current.ID;
detail.Number = number;
records.Add(detail);
}
else
{
detail = records[idx];
detail.Number = number;
}
HotPickBL.Insert(detail, current);
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 HotPick_Detail() { SecondOrder_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_HotFadeNumber"].Value = v;
current.HotFadeNumber = 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[1].Value;
if (id == current.OrderDetail_ID)
return;
current = list.First(x => x.OrderDetail_ID == id);
orderLbl.Text = current.Order.ToString();
RefreshRecordGrid();
}
private void orderGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex != orderGrid.Columns.Count - 1 || e.RowIndex == -1)
return;
HotPickBL.SetFinish(current);
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];
var v = (bool)dgrSingle.Cells["L_Finish"].Value;
if (v)
dgrSingle.DefaultCellStyle.BackColor = Color.YellowGreen;
}
}
}