private void CreateNewItemStockInNote() { if (mEditMode != EditMode.CreateNew) { return; } String itemSku = this.textBoxItemSKU.Text; if (itemSku == "") { MessageBox.Show("商品sku错误!", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } InventoryItemType item = ItemDAL.GetItemBySKU(itemSku); if (item == null) { MessageBox.Show("无此sku商品!", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } String sourcingNoteIdStr = this.textBoxSourcingNoteId.Text; String stockInNumStr = this.textBoxStockInNum.Text; int stockInNum = 0; if (stockInNumStr == "" || !Int32.TryParse(stockInNumStr, out stockInNum)) { MessageBox.Show("商品入库数量错误!", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DateTime stockInDate = this.dateTimePickerStockInTime.Value; ItemStockInNoteType note = new ItemStockInNoteType(); note.ItemSKU = itemSku; note.ItemTitle = item.ItemName; note.SourcingNoteId = sourcingNoteIdStr; note.StockInNum = stockInNum; note.StockInDate = stockInDate; note.Comment = textBoxComment.Text; int noteId = ItemStockInNoteDAL.InsertOneItemStockInNote(note); if (noteId <= 0) { MessageBox.Show("创建入库单失败!", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Increase the item stock number. ItemDAL.IncreaseItem(itemSku, stockInNum); MessageBox.Show(String.Format("创建入库单成功,入库单号{0}!", noteId), "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void ToolStripMenuItemDelItemStockInNote_Click(object sender, EventArgs e) { if (MessageBox.Show("你确认删除入库单么?\r\n删除后,相应商品的库存将被扣除。", "确认删除?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No) { return; } int rowIdx = this.pagedDgvItem.DgvData.CurrentRow.Index; String noteId = this.pagedDgvItem.DgvData.Rows[rowIdx].Cells[0].Value.ToString(); ItemStockInNoteType note = ItemStockInNoteDAL.GetOneItemStockInNote(noteId); if (note == null) { return; } // Decrease the stock. // First check validity. String itemSKU = note.ItemSKU; InventoryItemType item = ItemDAL.GetItemBySKU(itemSKU); if (item == null) { return; } if (item.ItemStockNum < note.StockInNum) { MessageBox.Show(String.Format("商品{0}的原库存为{1},删除入库单后其库存为{2},非法操作", itemSKU, item.ItemStockNum, item.ItemStockNum - note.StockInNum), "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ItemDAL.DecreaseItem(itemSKU, note.StockInNum); ItemStockInNoteDAL.DeleteOneItemStockInNote(noteId); MessageBox.Show(String.Format("入库单{0}已删除", noteId), "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information); pagedDgvItem.LoadData(); }
public static bool DeleteOneItemStockInNote(String noteId) { bool result = false; ItemStockInNoteType note = ItemStockInNoteDAL.GetOneItemStockInNote(noteId); if (note == null) { return(false); } String sql = string.Format("delete from [ItemStockInNote] where NoteId={0}", noteId); DataFactory.ExecuteSql(sql); result = true; return(result); }