private void UnpickItem() { try { int selectedItem = this.lvPickedItems.SelectedIndices[0]; int selectedItemId = Convert.ToInt32(lvPickedItems.Items[selectedItem].Text); ShippingOrderLineItem currentItem = _myOrderDetails.GetLineItem(selectedItemId, _myOrderId); Boolean success = _myOrderDetails.UpdatePickedFalse(currentItem); if (success == true) { PopulateLineItemLists(); } else { MessageBox.Show("Action could not be completed", "Error"); } if (lvItemsForPick.Items.Count > 0) { btnComplete.Enabled = false; } } catch { MessageBox.Show("Please select an item from the list", "No Item Selected"); } }
}//End of LineItems sets/gets. public bool Insert(ShippingOrderLineItem lineItem) { if (lineItem == null) { throw new ApplicationException("ShippingOrderLineItem is null"); } return(ShippingOrderLineItemDAL.AddShippingOrderLineItems(lineItem, _connection)); }//End of Insert(.)
}//End of Insert(.) public bool Update(ShippingOrderLineItem lineItem, ShippingOrderLineItem originalLineItem) { if (lineItem == null) { throw new ApplicationException("ShippingOrderLineItem is null"); } return(ShippingOrderLineItemDAL.UpdateShippingOrderLineItem(lineItem, originalLineItem, _connection)); }//End of Update(..)
public void Setup() { _shippingOrderLineItem = new ShippingOrderLineItem(2, 4) { ProductName = "Test Monitor", Quantity = 3, ProductLocation = "Place", IsPicked = false }; }
} //end UnpickShippingOrderLineItem(..) public static List <ShippingOrderLineItem> GetAllShippingOrderLineItems(SqlConnection myConnection) { var shippingOrderLineItemList = new List <ShippingOrderLineItem>(); myConnection = myConnection ?? GetInventoryDbConnection(); try { var mySqlCommand = new SqlCommand("proc_GetAllShippingOrderLineItems", myConnection) { CommandType = CommandType.StoredProcedure }; myConnection.Open(); var mySqlReader = mySqlCommand.ExecuteReader(); if (mySqlReader.HasRows) { while (mySqlReader.Read()) { // shippingOrderId and productId added in construction below var shippingLineItem = new ShippingOrderLineItem(mySqlReader.GetInt32(0), mySqlReader.GetInt32(1)) { ProductName = mySqlReader.GetString(2), Quantity = mySqlReader.GetInt32(3), ProductLocation = mySqlReader[4] as string, IsPicked = mySqlReader.GetBoolean(5) }; shippingOrderLineItemList.Add(shippingLineItem); } //end while } // end if mySqlReader.Close(); } catch (DataException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("DatabaseException"), ex); } catch (SqlException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("SqlException"), ex); } catch (Exception ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("Exception"), ex); } finally { myConnection.Close(); } return(shippingOrderLineItemList); } //end GetAllShippingOrderLineItems(.)
} //end GetShippingOrderLineItemsById(..) public static ShippingOrderLineItem GetShippingOrderLineItemById(int productId, int shippingOrderID, SqlConnection myConnection) { var shippingLineItem = new ShippingOrderLineItem(); myConnection = myConnection ?? GetInventoryDbConnection(); try { var mySqlCommand = new SqlCommand("proc_GetShippingOrderLineItem", myConnection); mySqlCommand.Parameters.AddWithValue("@productID", productId); mySqlCommand.Parameters.AddWithValue("@shippingOrderID", shippingOrderID); mySqlCommand.CommandType = CommandType.StoredProcedure; myConnection.Open(); SqlDataReader mySqlReader = mySqlCommand.ExecuteReader(); if (mySqlReader.HasRows) { while (mySqlReader.Read()) { shippingLineItem = new ShippingOrderLineItem(mySqlReader.GetInt32(0), mySqlReader.GetInt32(1)) { ProductName = mySqlReader.GetString(2), Quantity = mySqlReader.GetInt32(3), ProductLocation = mySqlReader[4] as string, IsPicked = mySqlReader.GetBoolean(5) }; } } // End If mySqlReader.Close(); } catch (DataException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("DatabaseException"), ex); } catch (SqlException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("SqlException"), ex); } catch (Exception ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("Exception"), ex); } finally { myConnection.Close(); } return(shippingLineItem); }
} // end AddShippingOrderLineItems(..) public static bool UpdateShippingOrderLineItem(ShippingOrderLineItem lineItem, ShippingOrderLineItem origLineItem, SqlConnection myConnection) { myConnection = myConnection ?? GetInventoryDbConnection(); try { var mySqlCommand = new SqlCommand("proc_UpdateShippingOrderLineItem", myConnection) { CommandType = CommandType.StoredProcedure }; mySqlCommand.Parameters.AddWithValue("@shippingOrderID", lineItem.ShippingOrderID); mySqlCommand.Parameters.AddWithValue("@productID", lineItem.ProductId); mySqlCommand.Parameters.AddWithValue("@quantity", lineItem.Quantity); mySqlCommand.Parameters.AddWithValue("@picked", lineItem.IsPicked ? 1 : 0); mySqlCommand.Parameters.AddWithValue("@orig_ShippingOrderID", origLineItem.ShippingOrderID); mySqlCommand.Parameters.AddWithValue("@orig_ProductID", origLineItem.ProductId); mySqlCommand.Parameters.AddWithValue("@orig_Quantity", origLineItem.Quantity); mySqlCommand.Parameters.AddWithValue("@orig_picked", origLineItem.IsPicked ? 1 : 0); myConnection.Open(); if (mySqlCommand.ExecuteNonQuery() == 1) { return(true); } } catch (DataException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("DatabaseException"), ex); } catch (SqlException ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("SqlException"), ex); } catch (Exception ex) { Console.WriteLine(ex.Message); throw new ApplicationException(Messeges.GetMessage("Exception"), ex); } finally { myConnection.Close(); } return(false); } // end UpdateShippingOrderLineItem(...)
}//End of GetLineItems() public ShippingOrderLineItem GetLineItem(int productID, int shippingOrderID) { //Need to do error checking... Try/Catch. LineItem = ShippingOrderLineItemDAL.GetShippingOrderLineItemById(productID, shippingOrderID, _connection); return(LineItem); }//End of GetLineItem(.)
}//End of UpdatePickedTrue(.) //When would this be called? public bool UpdatePickedFalse(ShippingOrderLineItem lineItem) { //Need to do error checking... Try/Catch. return(ShippingOrderLineItemDAL.UnpickShippingOrderLineItem(lineItem, _connection)); //Need to increment available inventory for this line item by the quantity. }//End of UpdatePickedFalse(.)
void UpdateLineItemNullDel() { ShippingOrderLineItem differentLineItem = null; _shippingOrderLineItemManager.Update(differentLineItem, _shippingOrderLineItem); }
void InsertLineItemNullDel() { _shippingOrderLineItem = null; _shippingOrderLineItemManager.Insert(_shippingOrderLineItem); }
public void TearDown() { _shippingOrderLineItem = null; }