public void DeleteCommodity(Commodity commodity) { using (ISession session = HibernateProvider.Factory.OpenSession()) { session.Delete(commodity); session.Flush(); } }
public int DeleteCommodity(Commodity comm) { int result = 0; string sqlQuery = "DELETE FROM Commodities WHERE InventoryID = " + comm.InventoryID; try { OleDbCommand sqlCommand = new OleDbCommand(sqlQuery, _accessConnection); result = sqlCommand.ExecuteNonQuery(); } catch (Exception e) { //TODO: how to handle this? } return result; }
public CommodityEditorViewModel(IInventoryManagementModel inventoryManagementModel) { _inventoryManagementModel = inventoryManagementModel; //event handling _inventoryManagementModel.GetVendorsComplete += _inventoryManagementModel_GetVendorsComplete; _inventoryManagementModel.GetCommodityTypesComplete += _inventoryManagementModel_GetCommodityTypesComplete; _inventoryManagementModel.GetUnitOfMeasuresComplete += _inventoryManagementModel_GetUnitOfMeasuresComplete; _currentCommodityCache = null; VendorEntries = null; _inventoryManagementModel.GetVendorsAsync(); CommodityTypeEntries = null; _inventoryManagementModel.GetCommodityTypesAsync(); UnitOfMeasureEntries = null; _inventoryManagementModel.GetUnitOfMeasuresAsync(); // register for EditCommodity AppMessages.EditCommodityMessage.Register(this, OnEditCommodityMessage); }
public void InsertCommodity(Commodity commodity) { using (ISession session = HibernateProvider.Factory.OpenSession()) { session.SaveOrUpdate(commodity); session.Flush(); } }
public static void Send(Commodity commodity) { Messenger.Default.Send(commodity, MessageTypes.EditCommodity); }
public bool InsertCommodity(ref Commodity comm) { bool retVal = false; string sqlQuery = "INSERT INTO Commodities ("; StringBuilder sbColDefs = new StringBuilder(); StringBuilder sbColValues = new StringBuilder(); foreach (ColumnDefinition columnDef in comm.ColumnDefs()) { if (!columnDef.ColumnName.Equals("InventoryID")) { if (sbColDefs.Length > 0) { sbColDefs.Append(", "); sbColValues.Append(", "); } sbColDefs.Append(columnDef.ColumnName); sbColValues.Append(comm.GetInsertableValue(columnDef)); } } sqlQuery += sbColDefs.ToString() + ") VALUES (" + sbColValues.ToString() + ")"; try { OleDbCommand sqlCommand = new OleDbCommand(sqlQuery, _accessConnection); int result = sqlCommand.ExecuteNonQuery(); if (result == 1) { OleDbCommand identityCommand = new OleDbCommand("SELECT @@IDENTITY", _accessConnection); int newMaxNumKey = (int)identityCommand.ExecuteScalar(); comm.InventoryID = newMaxNumKey; retVal = true; } } catch (Exception e) { //TODO: how to handle this? } return retVal; }
public int UpdateCommodity(Commodity comm) { int result = 0; string sqlQuery = "UPDATE Commodities SET "; StringBuilder sbColValues = new StringBuilder(); StringBuilder sbWhereClause = new StringBuilder(); foreach (KeyValuePair<int, object> columnValue in comm.GetColumnValues()) { ColumnDefinition columnDef = null; foreach (ColumnDefinition colDef in comm.ColumnDefs()) { if (colDef.ColumnIndex == columnValue.Key) { columnDef = colDef; break; } } if (columnDef == null) { //TODO: LOG THIS! return result; } if (!columnDef.ColumnName.Equals("InventoryID")) { if (sbColValues.Length > 0) { sbColValues.Append(", "); } sbColValues.Append(columnDef.ColumnName + " = " + comm.GetInsertableValue(columnDef)); } else { sbWhereClause.Append(" WHERE " + columnDef.ColumnName + " = " + comm.GetInsertableValue(columnDef)); } } if (sbColValues.Length > 0 && sbWhereClause.Length > 0) { try { sqlQuery += sbColValues.ToString() + sbWhereClause.ToString(); OleDbCommand sqlCommand = new OleDbCommand(sqlQuery, _accessConnection); result = sqlCommand.ExecuteNonQuery(); } catch (Exception e) { //TODO: how to handle this? } } return result; }
public List<Commodity> LoadCommodities(string whereClause) { List<Commodity> commodityList = new List<Commodity>(); string sqlQuery = "SELECT * FROM Commodities"; sqlQuery += ((whereClause != null && whereClause.Length > 0) ? " WHERE " + whereClause : ""); try { OleDbCommand sqlCommand = new OleDbCommand(sqlQuery, _accessConnection); OleDbDataReader reader = sqlCommand.ExecuteReader(); while (reader.Read()) { Commodity newComm = new Commodity(); newComm.Load(reader); commodityList.Add(newComm); } } catch (Exception e) { } return commodityList; }
/// <summary> /// Create a new Commodity object. /// </summary> /// <param name="inventoryID">Initial value of the InventoryID property.</param> /// <param name="partNumber">Initial value of the PartNumber property.</param> /// <param name="inventoryType">Initial value of the InventoryType property.</param> /// <param name="partDescription">Initial value of the PartDescription property.</param> /// <param name="unitOfMeasureID">Initial value of the UnitOfMeasureID property.</param> /// <param name="reorderLevel">Initial value of the ReorderLevel property.</param> /// <param name="vendor">Initial value of the Vendor property.</param> /// <param name="discontinued">Initial value of the Discontinued property.</param> public static Commodity CreateCommodity(global::System.Int32 inventoryID, global::System.String partNumber, global::System.Int32 inventoryType, global::System.String partDescription, global::System.Byte unitOfMeasureID, global::System.Int32 reorderLevel, global::System.Int32 vendor, global::System.Boolean discontinued) { Commodity commodity = new Commodity(); commodity.InventoryID = inventoryID; commodity.PartNumber = partNumber; commodity.InventoryType = inventoryType; commodity.PartDescription = partDescription; commodity.UnitOfMeasureID = unitOfMeasureID; commodity.ReorderLevel = reorderLevel; commodity.Vendor = vendor; commodity.Discontinued = discontinued; return commodity; }
/// <summary> /// Deprecated Method for adding a new object to the Commodities EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCommodities(Commodity commodity) { base.AddObject("Commodities", commodity); }
private void OnEditCommodityMessage(Commodity editCommodity) { if (editCommodity == null) return; // check whether this issue is read-only or not //TODO: will this ever apply? //AppMessages.ReadOnlyIssueMessage.Send(editIssue.IsIssueReadOnly()); AssignCurrentCommodity(editCommodity); }
/// <summary> /// Assign edit commodity only after all ComboBox are ready /// </summary> /// <param name="editIssue"></param> private void AssignCurrentCommodity(Commodity editCommodity) { if (editCommodity != null) { // this call is coming from OnEditIssueMessage() if (CommodityTypeEntries != null && VendorEntries != null && UnitOfMeasureEntries != null) { // if all ComboBox are ready, we set CurrentCommodity CurrentCommodity = editCommodity; _currentCommodityCache = null; } else _currentCommodityCache = editCommodity; } else { // this call is coming from one of the complete event handlers if (_currentCommodityCache != null && CommodityTypeEntries != null && VendorEntries != null && UnitOfMeasureEntries != null) { // if all ComboBox are ready, we set CurrentCommodity CurrentCommodity = _currentCommodityCache; _currentCommodityCache = null; } } }