示例#1
0
        /// <summary>
        /// Get the next roast day using the customer's default city / area
        /// </summary>
        /// <param name="_CustID">CusotmerID as per Client Table</param>
        /// <param name="_deliveryDelay">Delivery days delay</param>
        /// <returns>The next roast day</returns>
        public DateTime GetNextRoastDateByCustomerID(long pCustID, ref DateTime pDelivery)
        {
            // prep the TTools connection, if it has not already been preped
            if (!IsNextRoastDateByCityTodays())
            {
                SetNextRoastDateByCity();   // The next roast days have not been calcualted, calculate them and save. When customers city is found save the details
            }
            NextRoastDateByCityTbl _NextRoast = new NextRoastDateByCityTbl();

            _NextRoast = _NextRoast.GetPrepDataForCustomer(pCustID);

            pDelivery = _NextRoast.DeliveryDate;
            return(_NextRoast.PrepDate);

            //
            // DateTime = _NextRoastDate;
            // string _CustID = pCustID.ToString();

            // get the customers City
            //string _sqlStr = "SELECT City FROM CustomersTbl WHERE CustomerID = " + _CustID;
            //OleDbCommand _Cmd = new OleDbCommand(_sqlStr,TToolCon);                                   // for SQL we would use       SqlCommand _Cmd = new SqlCommand(_sqlStr);
            //OleDbDataReader _Reader = _Cmd.ExecuteReader();                                 //  for SQL we would use       SqlDataReader _sqlReader = _Cmd.ExecuteReader();

            //if (_Reader.Read())
            //  _CityID = _Reader["City"].ToString();
            //_Reader.Close();
            //_Cmd.Dispose();     // kill this so we can create a new one

            // find out if todays next roast date has been calculated

            //// the next roast days have been calcualted already today query table to find the details using the cutomer city
            //_Cmd = new OleDbCommand("SELECT PreperationDate, DeliveryDate FROM NextRoastDateByCityTbl WHERE CityID = " + _CityID, TToolCon);
            //// TToolCon.Open();   // opens the connection
            //_Reader = _Cmd.ExecuteReader();
            //if (_Reader.Read())
            //{
            //  DateTime _dt = (DateTime)(_Reader["PreperationDate"]);
            //  _NextRoastDate = _dt.Date;
            //  _dt = (DateTime)_Reader["DeliveryDate"];
            //  pDelivery = _dt.Date;
            //}

            //// kill memory used
            //_Cmd.Dispose();
            //_Reader.Close();
            //_Reader.Dispose();

//      return _NextRoastDate;
        }
示例#2
0
        protected void btnMove_Click(object sender, EventArgs e)
        {
            DateTime _OldDate = Convert.ToDateTime(OldDeliveryDateDDL.SelectedValue);
            DateTime _NewDate = Convert.ToDateTime(NewDeliveryDateTextBox.Text);

            if ((_OldDate == System.DateTime.MinValue) || (_NewDate == System.DateTime.MinValue))
            {
                StatusLiteral.Text = "new and old dates must be valid";
            }
            else
            {
                control.NextRoastDateByCityTbl _NRD = new NextRoastDateByCityTbl();
                int    _numRecs = 0;
                string _result  = _NRD.MoveDeliveryDate(_OldDate, _NewDate, ref _numRecs);

                if (String.IsNullOrEmpty(_result))
                {
                    List <int> _NRDIDs = _NRD.GetAllIDsByDate(_OldDate);
                    foreach (int _NRDID in _NRDIDs)
                    {
                        _result += _NRD.UpdateDeliveryDateByID(_NRDID, _OldDate);
                        _numRecs++;
                    }
                    if (!String.IsNullOrEmpty(_result))
                    {
                        StatusLiteral.Text = "ERROR: " + _result;
                    }
                    else
                    {
                        StatusLiteral.Text = String.Format("Move done: {0}record(s) updated.", _numRecs);
                    }

                    gvPrepData.DataBind();
                    OldDeliveryDateDDL.DataBind();
                }
                else
                {
                    StatusLiteral.Text = "ERROR: " + _result;
                }
            }
        }
示例#3
0
        private string UpdateOrInsertCityNextRstDate(int pCityID, PrepAndDeliveryData pThisPrepAndDeliveryData, PrepAndDeliveryData pNextPrepAndDeliveryData) // (int pCityID, DateTime pPrepDate, DateTime pDeliveryDate, short pOrder)
        {
            string _result = String.Empty;
            NextRoastDateByCityTbl _NextRoastDateByCityTbl = new NextRoastDateByCityTbl();

            _NextRoastDateByCityTbl.CityID           = pCityID;
            _NextRoastDateByCityTbl.PrepDate         = pThisPrepAndDeliveryData.PrepDate;
            _NextRoastDateByCityTbl.DeliveryDate     = pThisPrepAndDeliveryData.DeliveryDate;
            _NextRoastDateByCityTbl.DeliveryOrder    = pThisPrepAndDeliveryData.SortOrder;
            _NextRoastDateByCityTbl.NextPrepDate     = pNextPrepAndDeliveryData.PrepDate;
            _NextRoastDateByCityTbl.NextDeliveryDate = pNextPrepAndDeliveryData.DeliveryDate;

            TrackerDb   _TrackerDb = new TrackerDb();
            IDataReader _Reader    = _TrackerDb.ExecuteSQLGetDataReader("SELECT CityID FROM NextRoastDateByCityTbl WHERE CityID = " + pCityID);

            if ((_Reader != null) && (_Reader.Read()))
            {
                _result = _NextRoastDateByCityTbl.UpdatePrepDataForCity(pCityID, _NextRoastDateByCityTbl);
                _Reader.Close();
            }
            else
            {
                _result = _NextRoastDateByCityTbl.InsertPrepDataForCity(_NextRoastDateByCityTbl);
            }

            _TrackerDb.Close();
            return(_result);

            //bool _Success = false;
            //string _sqlStr = "SELECT CityID FROM NextRoastDateByCityTbl WHERE CityID = " + pCityID;
            //OleDbCommand _Cmd = new OleDbCommand(_sqlStr, TToolCon);
            //OleDbDataReader _Reader = _Cmd.ExecuteReader();

            //// if a record exists update command otherwise insert
            //if (_Reader.Read())
            //  _sqlStr = CITYNEXTRT_UPDATE;
            //else
            //  _sqlStr = CITYNEXTRT_INS;
            //// close the reader
            //_Reader.Close();

            //_Cmd.CommandText = _sqlStr;    // Set the SQL string
            //_Cmd.Parameters.Add(new OleDbParameter { Value = pPrepDate, DbType = System.Data.DbType.Date });
            //_Cmd.Parameters.Add(new OleDbParameter { Value = pDeliveryDate, DbType = System.Data.DbType.Date });
            //_Cmd.Parameters.Add(new OleDbParameter { Value = pOrder, DbType = System.Data.DbType.Int16 });
            //_Cmd.Parameters.Add(new OleDbParameter { Value = pCityID, DbType = System.Data.DbType.Int32 });
            //try
            //{
            //  _Success = _Cmd.ExecuteNonQuery() > 0;
            //}
            //catch (Exception E)
            //{
            //  if (E.Message != "")
            //    throw;
            //}
            //finally
            //{
            //  _Cmd.Dispose();
            //}

            //return _Success;
        }