Example #1
0
        private bool LogARepair(RepairsTbl pRepair, bool pCalcOrderData)
        {
            bool _Success = false;
            // create a new order for delivery [RoastDate]
            OrderCls _OrderData      = new OrderCls();
            DateTime _RequiredByDate = DateTime.Now.Date.AddDays(7);

            // add the default data to order
            _OrderData.HeaderData.CustomerID = pRepair.CustomerID;
            _OrderData.HeaderData.Notes      = "Collect/Swop out Machine for Service";

            List <OrderDetailData> orderDetailDatas = new List <OrderDetailData>();
            OrderDetailData        orderDetailData  = new OrderDetailData();

            orderDetailData.ItemTypeID      = ItemTypeTbl.CONST_SERVICEITEMID;
            orderDetailData.QuantityOrdered = 1;


            // Calculate the Data from the customer details
            if (pCalcOrderData)
            {
                TrackerTools _TT = new TrackerTools();
                _OrderData.HeaderData.RoastDate = _TT.GetNextRoastDateByCustomerID(pRepair.CustomerID, ref _RequiredByDate);
                TrackerTools.ContactPreferedItems _ContactPreferedItems = _TT.RetrieveCustomerPrefs(pRepair.CustomerID);

                _OrderData.HeaderData.OrderDate      = DateTime.Now.Date;
                _OrderData.HeaderData.RequiredByDate = _RequiredByDate;
                if (_ContactPreferedItems.RequiresPurchOrder)
                {
                    _OrderData.HeaderData.PurchaseOrder = TrackerTools.CONST_POREQUIRED;
                }
                _OrderData.HeaderData.ToBeDeliveredBy = _ContactPreferedItems.DeliveryByID;
            }
            else
            {
                _OrderData.HeaderData.RoastDate      = _OrderData.HeaderData.OrderDate = DateTime.Now.Date;
                _OrderData.HeaderData.RequiredByDate = _RequiredByDate;
            }
            // save the data to the orders
            OrderTbl _Order = new OrderTbl();

            _Order.InsertNewOrderLine(_OrderData);
            pRepair.RelatedOrderID = _Order.GetLastOrderAdded(_OrderData.HeaderData.CustomerID, _OrderData.HeaderData.OrderDate, ItemTypeTbl.CONST_SERVICEITEMID);

            return(_Success);
        }
        public List <OrderDetailData> LoadOrderDetailData(Int64 CustomerId, DateTime DeliveryDate, String Notes, int MaximumRows, int StartRowIndex)
        {
            List <OrderDetailData> oDetails = new List <OrderDetailData>();
            TrackerDb _TDB    = new TrackerDb();
            string    _sqlCmd = "SELECT [ItemTypeID], [QuantityOrdered], [PackagingID], [OrderID] FROM [OrdersTbl] WHERE ";

            if (CustomerId == 9) //CustomersTbl.CONST_CUSTOMERID_GENERALOROTHER)
            {
//                _sqlCmd += "([CustomerId] = " + CustomersTbl.CONST_STR_CUSTOMERID_GENERALOROTHER + ") AND ([RequiredByDate] = ?) AND ([Notes] = ?)";
                _sqlCmd += "([CustomerId] = 9) AND ([RequiredByDate] = ?) AND ([Notes] = ?)";

                _TDB.AddWhereParams(DeliveryDate, DbType.Date, "@RequiredByDate");
                _TDB.AddWhereParams(Notes, DbType.String, "@Notes");
            }
            else
            {
                _sqlCmd += "([CustomerId] = ?) AND ([RequiredByDate] = ?)";
                _TDB.AddWhereParams(CustomerId, DbType.Int64, "@CustomerId");
                _TDB.AddWhereParams(DeliveryDate, DbType.Date, "@RequiredByDate");
            }
            IDataReader _DataReader = _TDB.ExecuteSQLGetDataReader(_sqlCmd);

            if (_DataReader != null)
            {
                while (_DataReader.Read())
                {
                    OrderDetailData od = new OrderDetailData();

                    od.ItemTypeID      = (_DataReader["ItemTypeID"] == DBNull.Value) ? 0 : (Int32)_DataReader["ItemTypeID"];
                    od.PackagingID     = (_DataReader["PackagingID"] == DBNull.Value) ? 0 : (Int32)_DataReader["PackagingID"];
                    od.OrderID         = (Int32)_DataReader["OrderId"]; // this is the PK cannot be null
                    od.QuantityOrdered = (_DataReader["QuantityOrdered"] == DBNull.Value) ? 1 : Math.Round(Convert.ToDouble(_DataReader["QuantityOrdered"]), 2);

                    oDetails.Add(od);
                }
                _DataReader.Close();
            }
            _TDB.Close();

            return(oDetails);
        }