using ButcherFactory.BO;
|
|
using ButcherFactory.BO.LocalBL;
|
|
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.Dialogs
|
|
{
|
|
public partial class WeightRecordDialog : Form
|
|
{
|
|
static Image CheckImg = System.Drawing.Image.FromFile("Images\\check.png");
|
|
static Image UnCheckImg = System.Drawing.Image.FromFile("Images\\uCheck.png");
|
|
BindingList<CarcassSaleOut_Detail> list;
|
|
SaleOutStore_Detail mDetail;
|
|
long? mBatchID = null;
|
|
public bool Changed = false;
|
|
public bool rolBack = false;
|
|
public WeightRecordDialog(SaleOutStore_Detail detail, bool readOnly,long? batchID)
|
|
{
|
|
InitializeComponent();
|
|
mDetail = detail;
|
|
mBatchID = batchID;
|
|
if (readOnly)
|
|
{
|
|
addBtn.Enabled = false;
|
|
deleteBtn.Enabled = false;
|
|
rollBackBtn.Enabled = false;
|
|
}
|
|
uDataGridView1.BorderStyle = BorderStyle.FixedSingle;
|
|
BindGrid();
|
|
}
|
|
|
|
void BindGrid()
|
|
{
|
|
list = CarcassSaleOutBL.GetWeightRecord(mDetail.ID);
|
|
uDataGridView1.DataSource = list;
|
|
uDataGridView1.Refresh();
|
|
weightLabel.Text = string.Format("{0:#0.######} KG", list.Sum(x => x.Weight));
|
|
}
|
|
|
|
private void addBtn_Click(object sender, EventArgs e)
|
|
{
|
|
if (new AddWeightRecord(mDetail,mBatchID).ShowDialog() == DialogResult.OK)
|
|
{
|
|
BindGrid();
|
|
Changed = true;
|
|
}
|
|
}
|
|
|
|
private void deleteBtn_Click(object sender, EventArgs e)
|
|
{
|
|
if(uDataGridView1.CurrentRow==null)
|
|
return;
|
|
var id = (long)uDataGridView1.CurrentRow.Cells[0].Value;
|
|
var tag = list.First(x => x.ID == id);
|
|
CarcassSaleOutBL.DeleteAndUpdate(tag);
|
|
BindGrid();
|
|
Changed = true;
|
|
}
|
|
|
|
private void closeBtn_Click(object sender, EventArgs e)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
private void uDataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
|
{
|
|
if (e.RowIndex < 0 || e.ColumnIndex != 2)
|
|
return;
|
|
var v = (bool)uDataGridView1.Rows[e.RowIndex].Cells[1].Value;
|
|
e.Value = v ? CheckImg : UnCheckImg;
|
|
}
|
|
|
|
private void uDataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if (e.RowIndex < 0)
|
|
return;
|
|
var id = (long)uDataGridView1.CurrentRow.Cells[0].Value;
|
|
var first = list.First(x => x.ID == id);
|
|
first.Selected = !first.Selected;
|
|
uDataGridView1.Refresh();
|
|
}
|
|
|
|
private void rollBackBtn_Click(object sender, EventArgs e)
|
|
{
|
|
var backList = list.Where(x => x.Selected).ToList();
|
|
if (backList.Count() == 0)
|
|
throw new Exception("没有称重记录");
|
|
if (MessageBox.Show("确定退回选中记录?", "请确认", MessageBoxButtons.OKCancel) != DialogResult.OK)
|
|
return;
|
|
CarcassSaleOutBL.RollBackDetails(backList);
|
|
BindGrid();
|
|
Changed = true;
|
|
rolBack = true;
|
|
}
|
|
}
|
|
}
|