public static bool UpdateOrder(Order order, string executedBy)
 {
     return OrderDAO.Update(order, executedBy);
 }
 public static List<Order> SearchOrder(Order order, string executedBy)
 {
     return OrderDAO.Search(order, executedBy);
 }
        public static bool Insert(Order order, string executedBy)
        {
            bool rslt = false;

            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constants.DBConnection);
                DbCommand cmd = db.GetStoredProcCommand(Constants.SP_Order_Insert);

                connection = db.CreateConnection();
                connection.Open();
                transaction = connection.BeginTransaction();

                db.AddInParameter(cmd, "CustomerID", DbType.Int32, order.CustomerID);
                db.AddInParameter(cmd, "BranchID", DbType.Int32, order.BranchID);
                db.AddInParameter(cmd, "OrderDate", DbType.DateTime, order.OrderDate);
                db.AddInParameter(cmd, "OrderStatusID", DbType.Int32, order.OrderStatusID);
                db.AddInParameter(cmd, "TotalValue", DbType.Decimal, order.TotalValue);
                db.AddInParameter(cmd, "IsPaid", DbType.Boolean, order.IsPaid);
                db.AddInParameter(cmd, "CreatedBy", DbType.Boolean, order.CreatedBy);

                db.AddOutParameter(cmd, "NewID", DbType.Int32, 4);

                db.ExecuteNonQuery(cmd, transaction);

                int newID = 0;
                int.TryParse(db.GetParameterValue(cmd, "NewID").ToString(), out newID);

                if (newID > 0)
                {
                    bool dtlInserted;
                    foreach (OrderDetail orDtl in order.OrderItems)
                    {
                        dtlInserted = InsertDetail(orDtl, transaction, executedBy);
                        if (dtlInserted == false)
                        {
                            throw new Exception("Failed to insert order detail/s");
                        }
                    }

                    transaction.Commit();
                    rslt = true;
                }
            }

            catch (Exception ex)
            {
                transaction.Rollback();
                rslt = false;
                throw ex;
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }

            return rslt;
        }
 public static bool AddOrder(Order order, string executedBy)
 {
     return OrderDAO.Insert(order, executedBy);
 }
        public static List<Order> Search(Order srchOrder, string executedBy)
        {
            List<Order> orderList = null;

            try
            {
                Database db = DatabaseFactory.CreateDatabase(Constants.DBConnection);
                DbCommand cmd = db.GetStoredProcCommand(Constants.SP_Order_Search);

                db.AddInParameter(cmd, "OrderCode", DbType.String, srchOrder.OrderCode);
                db.AddInParameter(cmd, "CustomerID", DbType.Int32, srchOrder.CustomerID);
                db.AddInParameter(cmd, "BranchID", DbType.Int32, srchOrder.BranchID);
                db.AddInParameter(cmd, "OrderDate", DbType.DateTime, srchOrder.OrderDate);
                db.AddInParameter(cmd, "OrderStatusID", DbType.Int32, srchOrder.OrderStatusID);

                DataSet ds = db.ExecuteDataSet(cmd);
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0] != null)
                {
                    orderList = Utility.DataTableToCollection<Order>(ds.Tables[0]);
                }

            }

            catch (Exception ex)
            {
                orderList = null;
            }

            return orderList;
        }