using BO.BO.Bill; using BO.Utils; using BO.Utils.BillRpc; using BWP.WinFormControl; 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 OutHouseView { public partial class BeforeDeathConfirm : Form, IAfterLogin { public List RoleName { get { return new List() { "收购业务.窒晕确认" }; } } public Form Generate() { return this; } private delegate void InvokeHandler(); List orderList; Thread syncThread; public BeforeDeathConfirm() { InitializeComponent(); AddKeyPad(); orderGrid.AutoGenerateColumns = false; orderGrid.DataSource = null; this.FormClosing += delegate { if (syncThread != null && syncThread.IsAlive) syncThread.Abort(); }; } private void closeBtn_Click(object sender, EventArgs e) { this.Close(); } private void AddKeyPad() { for (var i = 1; i < 10; i++) { var btn = new Button() { Name = "_" + i, Text = i.ToString(), Size = new Size(85, 85), TextAlign = ContentAlignment.MiddleCenter, Margin = new Padding { All = 15 }, Font = new Font("宋体", 15) }; btn.Click += (sender, e) => { if (orderGrid.CurrentRow == null) return; var c = orderGrid.CurrentRow.DataBoundItem as OutHouseObj; var btnNumber = int.Parse(btn.Text); var total = (int.Parse(numLbl.Text) + btnNumber); numLbl.Text = total.ToString(); if (total > c.Number) UMessageBox.Show("头数合计超过排宰头数!", "警告"); var entity = new BeforeDeathDetail(); entity.Main_ID = c.ID; entity.Number = btnNumber; entity.Time = DateTime.Now; OrderDetailRpc.InsertBeforeDeathDetail(entity); }; keyPanel.Controls.Add(btn); } } private void OutHouseFrom_Load(object sender, EventArgs e) { syncThread = new Thread(SyncTask); syncThread.Start(); } private void SyncTask() { while (true) { this.Invoke(new InvokeHandler(delegate() { BindOrderGrid(); })); Thread.Sleep(5000); } } private void BindOrderGrid() { orderList = OrderDetailRpc.GetUnFinishList("AlreadyDeath"); orderGrid.DataSource = orderList.OrderBy(x => x.Order).ToList(); orderGrid.Refresh(); } private void orderGrid_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) return; if (e.ColumnIndex < orderGrid.ColumnCount - 1) return; var id = (long)orderGrid.CurrentRow.Cells["C_ID"].Value; var view = new ViewDetail(id); if (view.ShowDialog() == DialogResult.OK) { numLbl.Text = view.TotalNumber.ToString(); orderGrid.Refresh(); } } private void kbBtn_Click(object sender, EventArgs e) { if (orderGrid.CurrentRow == null) return; var c = orderGrid.CurrentRow.DataBoundItem as OutHouseObj; var n = int.Parse(numLbl.Text); if (n != c.Number) UMessageBox.Show(string.Format("头数合计 {0}于 排宰头数!", n > c.Number ? "大" : "小"), "警告"); OrderDetailRpc.SetOrderFinish(c.ID, "AlreadyDeath"); BindOrderGrid(); } } }