using BO.BO;
|
|
using BO.Utils;
|
|
using BO.Utils.BillRpc;
|
|
using ButcherManageClient;
|
|
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 ButcherWeight
|
|
{
|
|
public partial class WeightForm : Form, IAfterLogin
|
|
{
|
|
#region IAfterLogin Member
|
|
public string RoleName
|
|
{
|
|
get { return "_1"; }
|
|
}
|
|
|
|
public Form Generate()
|
|
{
|
|
return this;
|
|
}
|
|
#endregion
|
|
|
|
public WeightForm()
|
|
{
|
|
InitializeComponent();
|
|
supplierSelect.Init("BaseInfoRpc/GetSupplierList");
|
|
purchaseTypeSelect.Init("BaseInfoRpc/GetPurchaseTypeList");
|
|
carSelect.Init("BaseInfoRpc/GetCarList");
|
|
liveVarietiesSelect.Init("BaseInfoRpc/GetLiveVarietiesList");
|
|
employeeSelect.Init("BaseInfoRpc/GetEmployeeList");
|
|
hogGradeSelect.Init("BaseInfoRpc/GetHogGradeList");
|
|
zoneSelect.Init("BaseInfoRpc/GetZoneList");
|
|
farmerSelect.Init("BaseInfoRpc/GetFarmerList");
|
|
farmerSelect.EnableTopItem = false;
|
|
weightTimeSelect.Date = DateTime.Now;
|
|
testTimeInput.Date = DateTime.Now;
|
|
dmoList = WeightBillRpc.GetWeightBillList();
|
|
billGrid.AutoGenerateColumns = false;
|
|
farmerGrid.AutoGenerateColumns = false;
|
|
weightGrid.AutoGenerateColumns = false;
|
|
houseGird.AutoGenerateColumns = false;
|
|
abnormalGrid.AutoGenerateColumns = false;
|
|
BindWeightBill();
|
|
}
|
|
|
|
void BindWeightBill()
|
|
{
|
|
billGrid.DataSource = dmoList.OrderBy(x => x.FinishCreate).ToList();
|
|
billGrid.Refresh();
|
|
}
|
|
|
|
private List<WeightBill> dmoList = new List<WeightBill>();
|
|
private WeightBill Dmo = new WeightBill();
|
|
private List<WeightBill_FarmerDetail> _farmerDetails = new List<WeightBill_FarmerDetail>();
|
|
private List<WeightBill_Detail> _details = new List<WeightBill_Detail>();
|
|
|
|
|
|
private void exitBtn_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void commitBtn_Click(object sender, EventArgs e)
|
|
{
|
|
GetFromUI();
|
|
Dmo.Details.Clear();
|
|
Dmo.Details.AddRange(_details.ToList());
|
|
|
|
Dmo.FarmerDetails.Clear();
|
|
Dmo.FarmerDetails.AddRange(_farmerDetails.ToList());
|
|
|
|
var isNew = Dmo.ID == 0;
|
|
var result = WeightBillRpc.Send(Dmo);
|
|
if (isNew)
|
|
dmoList.Add(Dmo);
|
|
BindWeightBill();
|
|
if (result)
|
|
MessageBox.Show("保存成功!");
|
|
}
|
|
|
|
private void createBtn_Click(object sender, EventArgs e)
|
|
{
|
|
Dmo = new WeightBill();
|
|
Dmo.WeighTime = DateTime.Now;
|
|
AppToUI();
|
|
}
|
|
|
|
private void readMaoBtn_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void readPiBtn_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void farmerSelect_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (farmerSelect.IsEmpty)
|
|
return;
|
|
var detail = new WeightBill_FarmerDetail();
|
|
detail.Farmer_ID = farmerSelect.LongValue.Value;
|
|
if (_farmerDetails.Any(x => x.Farmer_ID == detail.Farmer_ID))
|
|
return;
|
|
detail.Farmer_Name = farmerSelect.DisplayValue;
|
|
_farmerDetails.Add(detail);
|
|
detail.Index = _farmerDetails.Max(x => x.Index) + 1;
|
|
detail.WeightBill_ID = Dmo.ID;
|
|
farmerGrid.DataSource = null;
|
|
farmerGrid.DataSource = _farmerDetails;
|
|
farmerGrid.Refresh();
|
|
farmerSelect.Clear();
|
|
}
|
|
|
|
void GetFromUI()
|
|
{
|
|
if (!employeeSelect.IsEmpty)
|
|
{
|
|
Dmo.Employee_ID = long.Parse(employeeSelect.Value);
|
|
Dmo.Employee_Name = employeeSelect.DisplayValue;
|
|
}
|
|
Dmo.WeighTime = weightTimeSelect.Date;
|
|
|
|
if (!supplierSelect.IsEmpty)
|
|
{
|
|
Dmo.Supplier_ID = long.Parse(supplierSelect.Value);
|
|
Dmo.Supplier_Name = supplierSelect.DisplayValue;
|
|
}
|
|
|
|
if (!zoneSelect.IsEmpty)
|
|
{
|
|
Dmo.Zone_ID = long.Parse(zoneSelect.Value);
|
|
Dmo.Zone_Name = zoneSelect.DisplayValue;
|
|
}
|
|
|
|
if (!purchaseTypeSelect.IsEmpty)
|
|
{
|
|
Dmo.PurchaseType_ID = short.Parse(purchaseTypeSelect.Value);
|
|
Dmo.PurchaseType_Name = purchaseTypeSelect.DisplayValue;
|
|
}
|
|
if (!carSelect.IsEmpty)
|
|
{
|
|
Dmo.Car_ID = long.Parse(carSelect.Value);
|
|
Dmo.Car_Name = carSelect.DisplayValue;
|
|
}
|
|
if (!liveVarietiesSelect.IsEmpty)
|
|
{
|
|
Dmo.LiveVarieties_ID = long.Parse(liveVarietiesSelect.Value);
|
|
Dmo.LiveVarieties_Name = liveVarietiesSelect.DisplayValue;
|
|
}
|
|
|
|
if (!hogGradeSelect.IsEmpty)
|
|
{
|
|
Dmo.HogGrade_ID = long.Parse(hogGradeSelect.Value);
|
|
Dmo.HogGrade_Name = hogGradeSelect.DisplayValue;
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(penWeightInput.Text))
|
|
{
|
|
decimal pw = 0;
|
|
if (!decimal.TryParse(penWeightInput.Text.Trim(), out pw))
|
|
throw new Exception("棚前重量输入错误");
|
|
Dmo.ShackWeight = pw;
|
|
}
|
|
if (!string.IsNullOrEmpty(penPriceInput.Text))
|
|
{
|
|
decimal pp = 0;
|
|
if (!decimal.TryParse(penPriceInput.Text.Trim(), out pp))
|
|
throw new Exception("棚前单价输入错误");
|
|
Dmo.ShackPrice = pp;
|
|
}
|
|
if (!string.IsNullOrEmpty(testCardNumberInput.Text))
|
|
Dmo.AnimalTestNumber = testCardNumberInput.Text;
|
|
|
|
if (!string.IsNullOrEmpty(testTimeInput.Text))
|
|
Dmo.AnimalTestDate = testTimeInput.Date;
|
|
|
|
if (!string.IsNullOrEmpty(testManInput.Text))
|
|
Dmo.AnimalTestMan = testManInput.Text;
|
|
|
|
if (!string.IsNullOrEmpty(remarkInput.Text))
|
|
Dmo.Remark = remarkInput.Text;
|
|
|
|
foreach (DataGridViewRow data in farmerGrid.Rows)
|
|
{
|
|
var detail = data.DataBoundItem as WeightBill_FarmerDetail;
|
|
_farmerDetails.First(x => x.Index == detail.Index).Number = detail.Number;
|
|
}
|
|
|
|
foreach (DataGridViewRow data in weightGrid.Rows)
|
|
{
|
|
var detail = data.DataBoundItem as WeightBill_Detail;
|
|
var first = _details.First(x => x.Index == detail.Index);
|
|
first.Number = detail.Number;
|
|
first.MaoWeight = detail.MaoWeight;
|
|
first.PiWeight = detail.PiWeight;
|
|
first.Weight = (detail.MaoWeight ?? 0) - (detail.PiWeight ?? 0);
|
|
}
|
|
}
|
|
|
|
void AppToUI()
|
|
{
|
|
ResetControl();
|
|
if (Dmo.Employee_ID.HasValue)
|
|
employeeSelect.Fill(Dmo.Employee_Name, Dmo.Employee_ID.ToString());
|
|
|
|
if (Dmo.WeighTime.HasValue)
|
|
weightTimeSelect.Date = Dmo.WeighTime;
|
|
|
|
if (Dmo.Supplier_ID.HasValue)
|
|
supplierSelect.Fill(Dmo.Supplier_Name, Dmo.Supplier_ID.ToString());
|
|
|
|
if (Dmo.Zone_ID.HasValue)
|
|
zoneSelect.Fill(Dmo.Zone_Name, Dmo.Zone_ID.ToString());
|
|
|
|
if (Dmo.PurchaseType_ID.HasValue)
|
|
purchaseTypeSelect.Fill(Dmo.PurchaseType_Name, Dmo.PurchaseType_ID.ToString());
|
|
|
|
if (Dmo.Car_ID.HasValue)
|
|
carSelect.Fill(Dmo.Car_Name, Dmo.Car_ID.ToString());
|
|
|
|
if (Dmo.LiveVarieties_ID.HasValue)
|
|
liveVarietiesSelect.Fill(Dmo.LiveVarieties_Name, Dmo.LiveVarieties_ID.ToString());
|
|
|
|
if (Dmo.HogGrade_ID.HasValue)
|
|
hogGradeSelect.Fill(Dmo.HogGrade_Name, Dmo.HogGrade_ID.ToString());
|
|
|
|
if (Dmo.ShackWeight.HasValue)
|
|
penWeightInput.Text = Dmo.ShackWeight.Value.ToString();
|
|
|
|
if (Dmo.ShackPrice.HasValue)
|
|
penPriceInput.Text = Dmo.ShackPrice.Value.ToString();
|
|
|
|
if (Dmo.ShackMoney.HasValue)
|
|
penMoneyInput.Text = Dmo.ShackMoney.Value.ToString();
|
|
|
|
if (!string.IsNullOrEmpty(Dmo.AnimalTestNumber))
|
|
testCardNumberInput.Text = Dmo.AnimalTestNumber;
|
|
|
|
if (Dmo.AnimalTestDate.HasValue)
|
|
testTimeInput.Date = Dmo.AnimalTestDate.Value;
|
|
|
|
if (!string.IsNullOrEmpty(Dmo.AnimalTestMan))
|
|
testManInput.Text = Dmo.AnimalTestMan;
|
|
|
|
if (!string.IsNullOrEmpty(Dmo.Remark))
|
|
remarkInput.Text = Dmo.Remark;
|
|
|
|
_farmerDetails = Dmo.FarmerDetails.ToList();
|
|
_details = Dmo.Details.ToList();
|
|
|
|
farmerGrid.DataSource = _farmerDetails;
|
|
weightGrid.DataSource = _details;
|
|
}
|
|
|
|
void ResetControl()
|
|
{
|
|
employeeSelect.Clear();
|
|
weightTimeSelect.Date = null;
|
|
supplierSelect.Clear();
|
|
zoneSelect.Clear();
|
|
purchaseTypeSelect.Clear();
|
|
carSelect.Clear();
|
|
liveVarietiesSelect.Clear();
|
|
hogGradeSelect.Clear();
|
|
penWeightInput.Text = null;
|
|
penPriceInput.Text = null;
|
|
penMoneyInput.Text = null;
|
|
testCardNumberInput.Text = null;
|
|
testTimeInput.Date = null;
|
|
testManInput.Text = null;
|
|
remarkInput.Text = null;
|
|
farmerGrid.DataSource = null;
|
|
weightGrid.DataSource = null;
|
|
}
|
|
|
|
private void billGrid_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if (e.RowIndex < 0)
|
|
return;
|
|
|
|
var id = Convert.ToInt64(billGrid.CurrentRow.Cells["M_ID"].Value);
|
|
Dmo = dmoList.First(x => x.ID == id);
|
|
AppToUI();
|
|
}
|
|
}
|
|
}
|