public override void AfterCancelEdit() { context.Refresh(RefreshMode.StoreWins, context.Transfer.First(p => p.TransferID == PrimaryID)); context.Refresh(RefreshMode.StoreWins, context.TransferDetails.Where(p => p.TransferID == PrimaryID)); //取得所有新增的存貨異動單明細 foreach (var AddedEntry in context.ObjectStateManager .GetObjectStateEntries(EntityState.Added)) { if (!AddedEntry.IsRelationship) { if (AddedEntry.Entity is TransferDetails) { var curr = ((TransferDetails)(AddedEntry.Entity)); transferDetailsBindingSource.Remove(curr); } } } //取消後 if (transferIDLabel.Text == String.Empty) { //取消後若無記錄,總計金額清空 amountTextBox.Text = ""; } else { //取消後若有記錄,取得總計金額 //總計金額 amountTextBox.Text = ((Transfer)(transferBindingSource.Current)) .Amount.ToString("#,##0"); } //變更DataGridView控制項的虛擬模式 transferDetailsDataGridView.VirtualMode = false; }
public override void AfterCancelEdit() { context.Refresh(RefreshMode.StoreWins, context.Delivery.First(p => p.DeliveryID == PrimaryID)); context.Refresh(RefreshMode.StoreWins, context.DeliveryDetails.Where(p => p.DeliveryID == PrimaryID)); //取得所有新增的出貨單明細 foreach (var AddedEntry in context.ObjectStateManager .GetObjectStateEntries(EntityState.Added)) { if (!AddedEntry.IsRelationship) { if (AddedEntry.Entity is DeliveryDetails) { var curr = ((DeliveryDetails)(AddedEntry.Entity)); deliveryDetailsBindingSource.Remove(curr); } } } //取消後 if (deliveryIDLabel.Text == String.Empty) { //取消後若無記錄,客戶簡稱、銷售金額、營業稅與總計金額清空 attribNameLabel.Text = ""; subTotalTextBox.Text = ""; valueAddTaxTextBox.Text = ""; amountTextBox.Text = ""; } else { //取消後若有記錄,取得目前客戶的: //客戶簡稱、銷售金額、營業稅與總計金額 //客戶簡稱 attribNameLabel.Text = XIN.GetCustomerAttribName( customerIDTextBox.Text); //銷售金額 subTotalTextBox.Text = ((Delivery)(deliveryBindingSource.Current)) .SubTotal.ToString("#,##0"); //營業稅 valueAddTaxTextBox.Text = ((Delivery)(deliveryBindingSource.Current)) .ValueAddTax.ToString("#,##0"); //總計金額 amountTextBox.Text = ((Delivery)(deliveryBindingSource.Current)) .Amount.ToString("#,##0"); } //變更DataGridView控制項的虛擬模式 deliveryDetailsDataGridView.VirtualMode = false; }
//減少庫存量 public void DecStock(XINEntities _context, string ProductID, int Quantity) { if (ProductID == null) { Exception ex = new Exception("計算庫存量的資料不可以含有空值!"); ex.Source = "null"; throw ex; } //重讀ObjectContext的庫存記錄 _context.Refresh(RefreshMode.StoreWins, _context.Product); //查詢指定品項的庫存量 var qryStock = (from P in _context.Product where P.ProductID == ProductID select P.Stock).FirstOrDefault(); int CurrQty = (int)qryStock; if ((CurrQty - Quantity) < 0) { Exception ex = new Exception(string.Format( "商品編號{0}的庫存量不足,無法出貨!", ProductID)); ex.Source = "Stock"; throw ex; } //定義影響的資料列數 int rowsAffected; //更新庫存量 rowsAffected = _context.ExecuteStoreCommand( "UPDATE Product SET Stock = Stock - {0} " + "WHERE ProductID = {1} ", Quantity, ProductID); //檢查影響的資料列數 if (rowsAffected == 0) { //修改失敗,舉發例外 Exception ex = new Exception("計算庫存量發生不可預期的錯誤!"); ex.Source = "Quantity"; throw ex; } }