private void ListviewItemDoubleClick(object sender, MouseButtonEventArgs e) { if (lstInventory.SelectedItem == null) { return; } int currentIndex = lstInventory.SelectedIndex; Warehouse_Inventory inventory = lstInventory.SelectedItem as Warehouse_Inventory; InventoryInfoWindow window = new InventoryInfoWindow(inventory); window.Owner = this; bool?result = window.ShowDialog().Value; if (result.HasValue && result == true) { Decorator border = VisualTreeHelper.GetChild(lstInventory, 0) as Decorator; ScrollViewer scrollViewer = null; double theOffset = 0; if (border != null) { scrollViewer = border.Child as ScrollViewer; if (scrollViewer != null) { theOffset = scrollViewer.VerticalOffset; } } Window_Loaded(null, null); scrollViewer.ScrollToVerticalOffset(theOffset); } }
/// <summary> /// 获取项目列表 /// </summary> public List <Warehouse_Inventory> GetInventoryList() { List <Warehouse_Inventory> Inventorys = null; string cmdText = "SELECT * FROM View_Warehouse_Inventory"; using (SqlDataReader reader = DBHelper.ExecuteReader(cmdText, CommandType.Text)) { if (reader.HasRows) { Inventorys = new List <Warehouse_Inventory>(); while (reader.Read()) { Warehouse_Inventory inventory = new Warehouse_Inventory() { InventoryID = Convert.ToInt32(reader["InventoryID"]), WarehouseID = Convert.ToInt32(reader["WarehouseID"]), WarehouseName = reader["WarehouseName"] as string, Quantity = Convert.ToInt32(reader["Quantity"]), MinStorage = Convert.ToInt32(reader["MinStorage"]), GoodsID = Convert.ToInt32(reader["GoodsID"]) }; inventory.Goods = new Warehouse_Goods() { GoodsID = Convert.ToInt32(reader["GoodsID"]), GoodsName = reader["GoodsName"] as string, Specification = reader["Specification"] as string, Unit = reader["Unit"] as string }; Inventorys.Add(inventory); } } } return(Inventorys); }
private void textBox1_MouseDoubleClick(object sender, MouseButtonEventArgs e) { PickGoodsWindow window = new PickGoodsWindow(); window.Owner = this; bool?result = window.ShowDialog(); if (result.HasValue && result == true) { List <Warehouse_Goods> goodsList = window.SelectedGoodsList; if (inventoryList == null) { this.inventoryList = new List <Warehouse_Inventory>(); } Warehouse_Inventory inventory = null; foreach (Warehouse_Goods goods in goodsList) { inventory = new Warehouse_Inventory() { WarehouseID = Convert.ToInt32(cboWarehouse.SelectedValue), Quantity = 0, MinStorage = 0, Goods = goods, }; this.inventoryList.Add(inventory); } dgInventory.ItemsSource = this.inventoryList; } }
public InventoryInfoWindow(Warehouse_Inventory inventory) { InitializeComponent(); btnAdd.Visibility = Visibility.Collapsed; btnEdit.Visibility = Visibility.Visible; this.inventoryList = new List <Warehouse_Inventory>(); this.inventoryList.Add(inventory); dgInventory.ItemsSource = this.inventoryList; }
/// <summary> /// 修改项目 /// </summary> /// <param name="inventory">需修改项目</param> public int UpdateInventory(Warehouse_Inventory inventory) { string cmdText = @"UPDATE [EasySystem].[dbo].[Warehouse_Inventory] SET [WarehouseID] = @WarehouseID ,[GoodsID] = @GoodsID ,[Quantity] = @Quantity ,[MinStorage] = @MinStorage WHERE [InventoryID] = @InventoryID"; SqlParameter[] parameters = new SqlParameter[5] { new SqlParameter("@WarehouseID", inventory.WarehouseID), new SqlParameter("@GoodsID", inventory.GoodsID), new SqlParameter("@Quantity", inventory.Quantity), new SqlParameter("@MinStorage", inventory.MinStorage), new SqlParameter("@InventoryID", inventory.InventoryID) }; return(DBHelper.ExecuteNonQuery(cmdText, parameters, CommandType.Text)); }
/// <summary> /// 新增项目 /// </summary> /// <param name="inventory">待新增项目</param> public int AddInventory(Warehouse_Inventory inventory) { int result = 0; string cmdText = @"Proc_AddInventory"; SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@WarehouseID", inventory.WarehouseID), new SqlParameter("@GoodsID", inventory.GoodsID), new SqlParameter("@Quantity", inventory.Quantity), new SqlParameter("@MinStorage", inventory.MinStorage), new SqlParameter("@Result", DbType.Int32) }; parameters[4].Direction = ParameterDirection.Output; DBHelper.ExecuteNonQuery(cmdText, parameters, CommandType.StoredProcedure); if (parameters[4].Value != null) { inventory.InventoryID = Convert.ToInt32(parameters[4].Value); return(1); } return(-1); }