private void UpdateDeletedMark(MyOrderRow order, bool mark) { order.BeginEdit(); order.Deleted = mark; order.EndEdit(); try { if (order.RowState != DataRowState.Unchanged) // 不用管Deleted,Detached不會發生 { m_OrderTableAdapter.Update(order); order.AcceptChanges(); // Update應該隱含AcceptChanges } } catch (Exception E) { if (E.GetType() != typeof(System.Data.DBConcurrencyException)) { MessageBox.Show(E.Message + "Update(CurrentOrder) 出錯"); } else { MessageBox.Show("Update(Order)發生並行違例,可能是別台己經改過這張單子,或新Order有初值未設定!"); MessageBox.Show("請重啟程式,你必需重新修改!"); } } }
private bool ShowOrder(MyOrderRow order) { var items = order.GetOrderItemRows(); lvItems.Items.Clear(); decimal total = 0; int count = 0;; foreach (var item in items) { if (item.RowState == DataRowState.Deleted) { continue; } if (item.IsNoNull()) { continue; } if (item.IsProductIDNull()) { continue; } if (item.IsPriceNull()) { item.Price = 0m; } decimal no = item.No; decimal money = item.Price * no; int productID = item.ProductID; ListViewItem lvItem = lvItems.Items.Add(productID.ToString()); lvItem.SubItems.Add(FindNameFromProduct(productID)); lvItem.SubItems.Add(no.ToString("N0")); lvItem.SubItems.Add(money.ToString("N0")); total += money; count++; } // 計算折扣 if (!order.IsDiscountRateNull()) { decimal discountRate = order.DiscountRate; if (discountRate != 0m && discountRate != 1m) { total = Math.Floor(total * discountRate); } } lvItems.Columns[1].Text = "ID " + PureIDStr(order.ID) + (order.Deleted ? " deleted" : ""); lvItems.Columns[2].Text = count.ToString(); lvItems.Columns[3].Text = total.ToString("N0"); labelReturned.Visible = false; labelMemberID.Visible = false; if (!order.IsIncomeNull()) { if (!order.IsDeductNull()) { if (order.Income < 0) { total += order.Deduct; } else { total -= order.Deduct; } } decimal income = Math.Round(order.Income, 2); if (total != order.Income) { if (order.Income < 0 && total == (-order.Income)) { labelReturned.Text = "收銀" + order.CashierID + " 授權" + order.RCashierID.ToString() + " 退單" + order.OldID.ToString(); labelReturned.Visible = true; return(true); } MessageBox.Show("計算金額<" + total.ToString() + ">不符 " + income.ToString()); return(false); } else { labelReturned.Text = "收銀 " + order.CashierID; if (!order.IsPrintTimeNull()) { labelReturned.Text += " 時間 " + order.PrintTime.ToString("HH:mm:ss"); } labelReturned.Visible = true; } } if (!order.IsMemberIDNull() && order.MemberID != "") { labelMemberID.Text = "会员" + order.MemberID; labelMemberID.Visible = true; } return(true); }
void CreateLabel(TabPage tabPage, int x, int y, MyOrderRow Row, int WidthX, int HeightY) { if (Row == null) { return; } string mark = "St" + tabPage.Name + DateTime.Now.Ticks.ToString(); //避免多次進入,label重名了 int xx, yy; xx = MyLayout.OffsetX + x * WidthX; yy = MyLayout.OffsetY + y * HeightY; TextBox b = new TextBox(); b.MouseClick += new MouseEventHandler(b_MouseClick); b.MouseDoubleClick += new MouseEventHandler(b_MouseDoubleClick); b.Multiline = true; b.Font = SystemFonts.MenuFont; b.AutoSize = false; b.Location = new System.Drawing.Point(xx, yy); b.Name = mark + "X" + x.ToString() + "Y" + y.ToString(); b.Size = new System.Drawing.Size(WidthX - MyLayout.NoWidth - 2, HeightY - 2); b.TabIndex = 0; b.BackColor = tabPage.BackColor; if (!Row.IsPrintTimeNull()) { b.Text = Row.PrintTime.ToString("mm:ss"); } b.Text += "\r\n" + PurePosNoStr(Row.ID) + "-" + PureIDStr(Row.ID); if (!Row.IsPayByNull()) { if (Row.PayBy == "B") { b.Text += "卡"; } else if (Row.PayBy == "C") { b.Text += "支"; } else if (Row.PayBy == "D") { b.Text += "A"; } else if (Row.PayBy == "E") { b.Text += "微"; } else if (Row.PayBy == "F") { b.Text += "B"; } } decimal income = 0; if (!Row.IsIncomeNull()) { income = Math.Round(Row.Income, 2); } b.Text += "\r\n" + income.ToString("N0") + "元"; if (!Row.IsDeletedNull() && Row.Deleted) { b.BackColor = Color.Green; } else if (income < 0) { b.BackColor = Color.Pink; } else if (!Row.IsDeductNull() && Row.Deduct != 0) { b.BackColor = Color.Azure; } b.Tag = Row; b.TextAlign = HorizontalAlignment.Center; b.BorderStyle = BorderStyle.Fixed3D; tabPage.Controls.Add(b); }