コード例 #1
0
        internal static void DeleteOrder(int id)
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (var transaction = session.BeginTransaction())
                {
                    order ord = session.Load <order>(id);

                    int eventId = ord.orderEvent.id;

                    var queryString = string.Format("delete {0} where id = :id", typeof(order));
                    session.CreateQuery(queryString)
                    .SetParameter("id", id)
                    .ExecuteUpdate();

                    transaction.Commit();

                    InventoryAvailability.Set(eventId);
                }
            }
        }
コード例 #2
0
        /*
         * static public IList<order> GetItemList(int id)
         * {
         *
         * }
         */

        static public string[] GetItemList()
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (session.BeginTransaction())
                {
                    IList <bom> parentItem = session.CreateCriteria(typeof(bom)).List <bom>();

                    var ListItems = (from I in parentItem
                                     select I.item).Distinct().ToList();

                    //ListItems.Insert(0, "-- inventory item --");

                    //ListItems.Insert(1, "Test");

                    string[] myitems = ListItems.ToArray();

                    return(myitems);
                }
            }
        }
コード例 #3
0
        static public void saveAll(events evt)
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (session.BeginTransaction())
                {
                    foreach (order o in evt.orderList)
                    {
                        o.checkin    = evt.checkIn;
                        o.checkout   = evt.checkOut;
                        o.orderEvent = evt;
                    }


                    session.SaveOrUpdate(evt);

                    /*
                     * foreach (order ord in ords)
                     * {
                     *  session.Update(ord);
                     * }
                     */

                    session.Transaction.Commit();

                    InventoryAvailability.Set(evt.id);
                }
            }
        }
コード例 #4
0
        static public events GetEvent(int EventId)
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            events evt = null;

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (session.BeginTransaction())
                {
                    try
                    {
                        // This never worked. I would use entity framework next time.
                        evt = session.CreateCriteria(typeof(events))
                              .Add(NHibernate.Criterion.Restrictions.Eq("id", EventId))
                              .UniqueResult <events>();
                        //evt =  session.Get<events>(EventId);
                    }
                    catch (Exception Ex)
                    { // for some reason doesn't take the first time!!
                      //  return session.CreateCriteria(typeof(events)).List<events>();
                        string msg = Ex.ToString();
                        return(null);
                    }
                }
            }

            Mapper.CreateMap <events, events>();
            events evt2 = Mapper.Map <events, events>(evt);

            return(evt2);
        }
コード例 #5
0
ファイル: bomRepository.cs プロジェクト: SteveRutz/Loane
        static public string saveBOM(List <bom> BOM)
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                try{
                    using (session.BeginTransaction())
                    {
                        foreach (bom Part in BOM)
                        {
                            session.SaveOrUpdate(Part);
                        }


                        session.Transaction.Commit();

                        return("BOM saved. ");
                    }
                }
                catch (Exception ex)
                {
                    return("Inventory update FAILURE. " + ex.Message + ex.InnerException);
                }
            }
        }
コード例 #6
0
ファイル: bomRepository.cs プロジェクト: SteveRutz/Loane
        static public IList <inventory> GetMasterItems()
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (session.BeginTransaction())
                {
                    IList <inventory> BOM = session.CreateCriteria(typeof(inventory)).List <inventory>();

                    return(BOM.Where(x => x.master == true).ToList());
                }
            }
        }
コード例 #7
0
        internal static void InsertItem(inventory Item)
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (var transaction = session.BeginTransaction())
                {
                    session.SaveOrUpdate(Item);

                    transaction.Commit();
                }
            }
        }
コード例 #8
0
        static public void save(ref inventory Item)
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (session.BeginTransaction())
                {
                    session.Save(Item);

                    session.Transaction.Commit();
                }
            }
        }
コード例 #9
0
        static public IList <inventory> GetInventory()
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (session.BeginTransaction())
                {
                    IList <inventory> Inventory = session.CreateCriteria(typeof(inventory)).List <inventory>();

                    return((from I in Inventory
                            orderby I.item
                            select I).ToList());
                }
            }
        }
コード例 #10
0
        static public inventory GetInventoryItem(int ItemId)
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (session.BeginTransaction())
                {
                    var Inventory = from myItem in session.QueryOver <inventory>()
                                    where myItem.id == ItemId
                                    select myItem;

                    return(Inventory.SingleOrDefault <inventory>());
                }
            }
        }
コード例 #11
0
        internal static void InsertEvent(ref events Event)
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (var transaction = session.BeginTransaction())
                {
                    session.SaveOrUpdate(Event);

                    transaction.Commit();

                    //Event.id = myEvent.id;
                }
            }
        }
コード例 #12
0
        internal static void DeleteTruck(string Name)
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (var transaction = session.BeginTransaction())
                {
                    var queryString = string.Format("delete {0} where name = :name", typeof(truck));
                    session.CreateQuery(queryString)
                    .SetParameter("name", Name)
                    .ExecuteUpdate();

                    transaction.Commit();
                }
            }
        }
コード例 #13
0
        internal static void DeleteInventoryItem(int itemId)
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (var transaction = session.BeginTransaction())
                {
                    var queryString = string.Format("delete {0} where id = :id", typeof(inventory));
                    session.CreateQuery(queryString)
                    .SetParameter("id", itemId)
                    .ExecuteUpdate();

                    transaction.Commit();
                }
            }
        }
コード例 #14
0
        internal static void AddTruck(string Name)
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (var transaction = session.BeginTransaction())
                {
                    truck Truck = new truck();
                    Truck.name = Name;

                    session.Save(Truck);

                    transaction.Commit();
                }
            }
        }
コード例 #15
0
        static public IList <order> GetDetail(int EventId)
        {
            // create our NHibernate session factory

            InventoryAvailability.Set(EventId);

            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (session.BeginTransaction())
                {
                    events evt = session.Load <events>(EventId);

                    IList <order> ord = evt.orderList.ToList();

                    return(ord);
                }
            }
        }
コード例 #16
0
        /*
         * static public IList<order> GetTruckList(int id)
         * {
         *
         * }
         */

        static public string[] GetTruckList()
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (session.BeginTransaction())
                {
                    IList <truck> Truck = session.CreateCriteria(typeof(truck)).List <truck>();

                    var ListItems = (from I in Truck
                                     select I.name).Distinct().ToList();

                    //ListItems.Insert(0, "-- Load Truck --");

                    string[] myitems = ListItems.ToArray();

                    return(myitems);
                }
            }
        }
コード例 #17
0
        static public void saveAll(List <order> ords)
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (session.BeginTransaction())
                {
                    session.Update(ords[0].orderEvent);

                    foreach (order ord in ords)
                    {
                        session.Update(ord);
                    }

                    InventoryAvailability.Set(ords[0].orderEvent.id);

                    session.Transaction.Commit();
                }
            }
        }
コード例 #18
0
/*
 *      static public IList<order> GetDetails()
 *      {
 *
 *          // create our NHibernate session factory
 *          var sessionFactory = FluentNHibernate.CreateSessionFactory();
 *
 *          using (var session = sessionFactory.OpenSession())
 *          {
 *              // retreive all stores and display them
 *              using (session.BeginTransaction())
 *              {
 *
 *                  return InventoryAvailability.Set();
 *
 *
 *                      //return ord.ToList();
 *
 *              }
 *          }
 *
 *
 *      }
 */

        //static public void save (int EventId, order newOrder)
        static public void save(order newOrder)
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (session.BeginTransaction())
                {
                    events evt = session.Load <events>(newOrder.orderEvent.id);

                    // newOrder.orderEvent = null;

                    evt.addOrder(newOrder);

                    session.SaveOrUpdate(evt);

                    //InventoryAvailability.checkInventoryAndSave(newOrder, session);

                    /* Should get saved during the checkAvialbility */

                    //session.SaveOrUpdate(evt);

                    //session.Save(newOrder.orderEvent);

                    session.Transaction.Commit();

                    //newOrder.orderEvent = null;
                }

                // closing session causes problem of Lazy Loading?!

                //session.Close();
            }
        }
コード例 #19
0
        /*
         * static public IList<events> GetEvents()
         * {
         *
         *  // create our NHibernate session factory
         *  var sessionFactory = FluentNHibernate.CreateSessionFactory();
         *
         *  using (var session = sessionFactory.OpenSession())
         *  {
         *      // retreive all stores and display them
         *      using (session.BeginTransaction())
         *      {
         *
         *              IList<events> evts = session.CreateCriteria(typeof(events)).List<events>();
         *
         *              IList<inventory> inv = session.CreateCriteria(typeof(inventory)).List<inventory>();
         *
         *              return evts;
         *
         *      }
         *  }
         *
         *
         * }
         */
        //static public IList<eventItemCount> GetEvents()
        static public IList <events> GetEvents(DateTime AsOf)
        {
            //InventoryAvailability.Set();

            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (session.BeginTransaction())
                {
                    IList <events> evts = session.CreateCriteria(typeof(events))
                                          .Add(NHibernate.Criterion.Restrictions.Ge("eventDate", AsOf))
                                          .List <events>();

                    try
                    {
                        Mapper.CreateMap <events, events>();
                        IList <events> evtList = Mapper.Map <IList <events>, IList <events> >(evts);

                        return(evtList);
                        //Mapper.CreateMap<events, eventItemCount>();
                        //IList<eventItemCount> evtListCnt = Mapper.Map<IList<events>, IList<eventItemCount>>(evts);

                        //return evtListCnt;
                    }
                    catch (Exception Ex) { string exc = Ex.ToString(); }

                    return(evts);
                }
            }

            /*
             * SQLiteCommand cmd = new SQLiteCommand(new SQLiteConnection());
             *
             * cmd.Connection.ConnectionString = string.Format("data source={0}", FluentNHibernate.DbFile);
             *
             * cmd.CommandText = "select "
             + " (Select count(*) from [order] where [order].orderEvent_id = events.id) As Items"
             + ", events.* "
             + " from events ";
             +
             + cmd.Connection.Open();
             +
             + SQLiteDataReader rdr = cmd.ExecuteReader();
             +
             + IList<eventItemCount> evtsItem = new List<eventItemCount>();
             +
             + while (rdr.Read())
             + {
             +  evtsItem.Add(
             +      new eventItemCount
             +      {
             +          available = Int32.Parse(rdr["available"].ToString())
             +         ,
             +          booked = Convert.ToBoolean(rdr["booked"].ToString())
             +         ,
             +          eventDate = Convert.ToDateTime(rdr["eventDate"].ToString())
             +         ,
             +          eventName = rdr["eventName"].ToString()
             +         ,
             +          OrderCnt = Convert.ToInt64(rdr["Items"].ToString())
             +         ,
             +          id = Convert.ToInt64(rdr["id"].ToString())
             +
             +      });
             + }
             +
             + return evtsItem;
             */
        }
コード例 #20
0
        static public string saveAll(List <inventory> Inventory, string masterItem)
        {
            if (masterItem == "undefined")
            {
                masterItem = null;
            }
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                try{
                    using (session.BeginTransaction())
                    {
                        IList <bom> BOM = null;
                        if (masterItem != null)
                        {
                            BOM = session.CreateCriteria(typeof(bom)).List <bom>();
                            BOM = BOM.Where(x => x.item == masterItem).ToList();
                        }

                        if (BOM != null)
                        {
                            foreach (inventory item in Inventory)
                            {
                                bom bomItem = BOM.Where(x => x.component == item.item).FirstOrDefault();
                                if (bomItem == null && item.bomQty > 0)
                                {
                                    bomItem           = new bom();
                                    bomItem.component = item.item;
                                    bomItem.qty       = item.bomQty;
                                    bomItem.item      = masterItem;
                                    session.Save(bomItem);
                                }
                                else if (item.bomQty > 0)
                                {
                                    bomItem.qty = item.bomQty;
                                    session.SaveOrUpdate(bomItem);
                                }
                                else if (item.bomQty == 0 && bomItem != null)
                                {
                                    var queryString = string.Format("delete {0} where id = :id", typeof(bom));
                                    session.CreateQuery(queryString)
                                    .SetParameter("id", bomItem.id)
                                    .ExecuteUpdate();
                                }
                            }
                        }
                        else
                        {
                            foreach (inventory item in Inventory)
                            {
                                session.SaveOrUpdate(item);
                            }
                        }

                        session.Transaction.Commit();

                        return("Inventory saved. ");
                    }
                }
                catch (Exception ex)
                {
                    return("Inventory update FAILURE. " + ex.Message + ex.InnerException);
                }
            }
        }