public void DeleteCommodityType(CommodityType commodityType)
 {
     using (ISession session = HibernateProvider.Factory.OpenSession())
     {
         session.Delete(commodityType);
         session.Flush();
     }
 }
 public void DeleteCommodityType(CommodityType commodityType)
 {
     using (ISession session = HibernateProvider.Factory.OpenSession())
     {
         session.Delete(commodityType);
         session.Flush();
     }
 }
 public void InsertCommodityType(CommodityType commodityType)
 {
     using (ISession session = HibernateProvider.Factory.OpenSession())
     {
         session.SaveOrUpdate(commodityType);
         session.Flush();
     }
 }
        public int DeleteCommodityType(CommodityType comm)
        {
            int result = 0;

            /* TODO:this
            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 void InsertCommodityType(CommodityType commodityType)
 {
     using (ISession session = HibernateProvider.Factory.OpenSession())
     {
         session.SaveOrUpdate(commodityType);
         session.Flush();
     }
 }
        public int UpdateCommodityType(CommodityType comm)
        {
            int result = 0;
            /* TODO:THIS
            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<CommodityType> LoadCommodityTypes(string whereClause)
        {
            List<CommodityType> commodityTypeList = new List<CommodityType>();

            string sqlQuery = "SELECT * FROM " + CommodityType._tableName;
            sqlQuery += ((whereClause != null && whereClause.Length > 0) ? " WHERE " + whereClause : "");

            try
            {
                OleDbCommand sqlCommand = new OleDbCommand(sqlQuery, _accessConnection);
                OleDbDataReader reader = sqlCommand.ExecuteReader();

                while (reader.Read())
                {
                    CommodityType newComm = new CommodityType();
                    newComm.Load(reader);
                    commodityTypeList.Add(newComm);
                }
            }
            catch (Exception e)
            {
            }

            return commodityTypeList;
        }
        public bool InsertCommodityType(ref CommodityType comm)
        {
            bool retVal = false;

            /* TODO:THIS
            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;
        }
 /// <summary>
 /// Create a new CommodityType object.
 /// </summary>
 /// <param name="typeID">Initial value of the TypeID property.</param>
 /// <param name="typeCode">Initial value of the TypeCode property.</param>
 /// <param name="description">Initial value of the Description property.</param>
 public static CommodityType CreateCommodityType(global::System.Int32 typeID, global::System.String typeCode, global::System.String description)
 {
     CommodityType commodityType = new CommodityType();
     commodityType.TypeID = typeID;
     commodityType.TypeCode = typeCode;
     commodityType.Description = description;
     return commodityType;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the CommodityTypes EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCommodityTypes(CommodityType commodityType)
 {
     base.AddObject("CommodityTypes", commodityType);
 }