Ejemplo n.º 1
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            string _ErrorStr = "Connection not openned";

            OrderTbl _OrderTbl = new OrderTbl();

            OrderHeaderData _OrderHeaderData = Get_dvOrderHeaderData(false);
            OrderTblData    _OrderData       = new OrderTblData();

            // first summary data
            _OrderData.CustomerId      = _OrderHeaderData.CustomerID;
            _OrderData.OrderDate       = _OrderHeaderData.OrderDate;
            _OrderData.RoastDate       = _OrderHeaderData.RoastDate;
            _OrderData.RequiredByDate  = _OrderHeaderData.RequiredByDate;
            _OrderData.ToBeDeliveredBy = Convert.ToInt32(_OrderHeaderData.ToBeDeliveredBy);
            _OrderData.PurchaseOrder   = _OrderHeaderData.PurchaseOrder;
            _OrderData.Confirmed       = _OrderHeaderData.Confirmed;
            _OrderData.InvoiceDone     = _OrderHeaderData.InvoiceDone;
            _OrderData.Done            = _OrderHeaderData.Done;
            _OrderData.PurchaseOrder   = _OrderHeaderData.PurchaseOrder;
            _OrderData.Notes           = _OrderHeaderData.Notes;

            // Now line data
            TrackerTools _TT = new TrackerTools();

            _OrderData.ItemTypeID      = Convert.ToInt32(ddlNewItemDesc.SelectedValue);
            _OrderData.ItemTypeID      = _TT.ChangeItemIfGroupToNextItemInGroup(_OrderData.CustomerId, _OrderData.ItemTypeID, _OrderData.RequiredByDate);
            _OrderData.QuantityOrdered = Convert.ToDouble(tbxNewQuantityOrdered.Text);
            _OrderData.PackagingID     = Convert.ToInt32(ddlNewPackaging.SelectedValue);

            _ErrorStr       = _OrderTbl.InsertNewOrderLine(_OrderData);
            ltrlStatus.Text = (String.IsNullOrWhiteSpace(_ErrorStr) ? "Item Added" : "Error adding item: " + _ErrorStr);
            HideNewOrderItemPanel();
        }
Ejemplo n.º 2
0
        protected bool AddNewOrderLine(int pNewItemID, double pNewQuantityOrdered, int pNewPackagingID)
        {
            string _ErrorStr = "";

            OrderTblData _OrderData = new OrderTblData();
            OrderTbl     _OrderTbl  = new OrderTbl();

            _OrderData.CustomerId      = Convert.ToInt64(ddlContacts.SelectedValue);
            _OrderData.OrderDate       = Convert.ToDateTime(tbxOrderDate.Text).Date;
            _OrderData.RoastDate       = Convert.ToDateTime(tbxRoastDate.Text).Date;
            _OrderData.RequiredByDate  = Convert.ToDateTime(tbxRequiredByDate.Text).Date;
            _OrderData.ToBeDeliveredBy = Convert.ToInt32(ddlToBeDeliveredBy.SelectedValue);
            _OrderData.PurchaseOrder   = tbxPurchaseOrder.Text;
            _OrderData.Confirmed       = Convert.ToBoolean(cbxConfirmed.Checked);
            _OrderData.InvoiceDone     = cbxInvoiceDone.Checked;
            _OrderData.Done            = Convert.ToBoolean(cbxDone.Checked);
            _OrderData.Notes           = tbxNotes.Text;
            // Now line data
            Session[OrderHeaderData.CONST_BOUNDOLDDELIVERYDATE] = _OrderData.RequiredByDate.Date;
            TrackerTools _TT = new TrackerTools();

            _OrderData.ItemTypeID      = _TT.ChangeItemIfGroupToNextItemInGroup(_OrderData.CustomerId, pNewItemID, _OrderData.RequiredByDate);
            _OrderData.QuantityOrdered = pNewQuantityOrdered;
            _OrderData.PackagingID     = pNewPackagingID;

            _ErrorStr = _OrderTbl.InsertNewOrderLine(_OrderData);

            BindRowQueryParameters();

            return(String.IsNullOrEmpty(_ErrorStr));
        }
Ejemplo n.º 3
0
        private bool LogARepair(RepairsTbl pRepair, bool pCalcOrderData)
        {
            bool _Success = false;
            // create a new order for delivery [RoastDate]
            OrderTblData _OrderData      = new OrderTblData();
            DateTime     _RequiredByDate = DateTime.Now.Date.AddDays(7);

            // add the default data to order
            _OrderData.CustomerId      = pRepair.CustomerID;
            _OrderData.ItemTypeID      = ItemTypeTbl.CONST_SERVICEITEMID;
            _OrderData.QuantityOrdered = 1;
            _OrderData.Notes           = "Collect/Swop out Machine for Service";

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

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

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

            return(_Success);
        }
Ejemplo n.º 4
0
        bool SendReminder(SendCheckEmailTextsData pEmailTextData, ContactToRemindWithItems pContact, string pOrderType)
#endif
        {
            const string CONST_SERVERURL          = "http://tracker.quaffee.co.za/QonT/";
            const string CONST_HTMLBREAK          = "<br /><br />";
            const string CONST_ADDORDERURL        = "Internal: Order Ref <a href='" + CONST_SERVERURL + "{0}'>here</a>.";
            const string CONST_DISABLECUSTOMERURL = "If you would prefer to be disabled then click <a href='" + CONST_SERVERURL + "DisableClient.aspx?CoID={0}'>disable me</a>";

            bool _ReminderSent = false;
            bool _HasAutoFulfilElements = false, _HasReoccuringElements = false, _HadError = false;
            SentRemindersLogTbl _ReminderLog = new SentRemindersLogTbl();

            #region CreateAndPopulateUsageSummaryTable

            string _EmailBodyTable = UsageSummaryTableHeader(pContact);
            string _OrderType      = (String.IsNullOrEmpty(pOrderType)) ? "a reminder only" : pOrderType;
            // send a reminder
            // build up Table
            _EmailBodyTable += String.Format(CONST_SUMMARYTABLEHEADER, "Company/Contact", pContact.CompanyName);
            _EmailBodyTable += String.Format(CONST_SUMMARYTABLBODYROW2COL, "Next estimate prep date", String.Format("{0:d MMM, ddd}", pContact.NextPrepDate));
            _EmailBodyTable += String.Format(CONST_SUMMARYTABLBODYALTROW2COL, "Next estimate dispatch date", String.Format("{0:d MMM, ddd}", pContact.NextDeliveryDate));
            _EmailBodyTable += String.Format(CONST_SUMMARYTABLBODYALTROW2COL, "Type", _OrderType);
            if (pContact.ItemsContactRequires.Count > 0)
            {
                _EmailBodyTable += String.Format(CONST_SUMMARYTABLBODYROW3COL, "<b>List of Items</b>");

                for (int j = 0; j < pContact.ItemsContactRequires.Count; j++)
                {
                    _EmailBodyTable += CONST_SUMMARYTABLEBODYROWSTART + AddLastOrderTableRow(pContact.ItemsContactRequires[j], (j % 2 == 0)) + CONST_SUMMARYTABLEBODYROWEND;
                }
            }
            _EmailBodyTable += CONST_SUMMARYTABLEBODYEND;
            #endregion
            // add to orders if it is a autofulful or
            #region AddOrderLines
            if (!String.IsNullOrWhiteSpace(pOrderType))
            {
                OrderTblData _OrderData = new OrderTblData();

                _HasAutoFulfilElements     = true;
                _OrderData.CustomerId      = pContact.CustomerID;
                _OrderData.OrderDate       = DateTime.Now.Date;
                _OrderData.RoastDate       = pContact.NextPrepDate.Date;
                _OrderData.RequiredByDate  = pContact.NextDeliveryDate.Date;
                _OrderData.ToBeDeliveredBy = (pContact.PreferedAgentID < 0) ? TrackerTools.CONST_DEFAULT_DELIVERYBYID : pContact.PreferedAgentID; // the prefered person is the delivery agent
                _OrderData.Confirmed       = false;                                                                                               // we have not confirmed the order, it is a reoccuring or auto order
                _OrderData.InvoiceDone     = false;                                                                                               // we have not confirmed the order, it is a reoccuring or auto order
                _OrderData.PurchaseOrder   = string.Empty;                                                                                        // we have not confirmed the order, it is a reoccuring or auto order
                _OrderData.Notes           = pOrderType;

                ReoccuringOrderDAL _Reoccur   = new ReoccuringOrderDAL(); // to set the last date
                OrderTbl           _OrderTbl  = new OrderTbl();
                string             _InsertErr = String.Empty;
                int j = 0;
                // insert each itm that is Reoccuing or auto
                while ((j < pContact.ItemsContactRequires.Count) && String.IsNullOrEmpty(_InsertErr))
                {
                    _OrderData.ItemTypeID      = pContact.ItemsContactRequires[j].ItemID;
                    _OrderData.QuantityOrdered = pContact.ItemsContactRequires[j].ItemQty;
                    _OrderData.PackagingID     = pContact.ItemsContactRequires[j].ItemPackagID;
                    _OrderData.PrepTypeID      = pContact.ItemsContactRequires[j].ItemPrepID;
                    _InsertErr = _OrderTbl.InsertNewOrderLine(_OrderData);

                    // mark a reoccuring item as done with the current prep date
                    if (pContact.ItemsContactRequires[j].ReoccurOrder)
                    {
                        _Reoccur.SetReoccuringOrdersLastDate(pContact.NextPrepDate, pContact.ItemsContactRequires[j].ReoccurID);
                        _HasReoccuringElements = true;
                    }

                    j++;
                }
                // add a record into the log to say it was sent
                _HadError = !String.IsNullOrEmpty(_InsertErr);
                if (_HadError)
                {
                    showMessageBox _MsgBox = new showMessageBox(this.Page, "Error Inserting order for :" + pContact.CompanyName, _InsertErr);
                }
                else
                {
                    pEmailTextData.Footer += CONST_HTMLBREAK + "Items added to orders.";
                }
            }
            else /// we are not autoadding so lets append a "LastOrder Equiv to the message"
            {
                string _AddOrder = String.Format("Pages/NewOrderDetail.aspx?Z&{0}={1}", NewOrderDetail.CONST_URL_REQUEST_CUSTOMERID, pContact.CustomerID);
                for (int j = 0; j < pContact.ItemsContactRequires.Count; j++)
                {
                    _AddOrder += String.Format("&SKU{0}={1}&SKUQty{2}={3}", j + 1, GetItemSKU(pContact.ItemsContactRequires[j].ItemID), j + 1,
                                               pContact.ItemsContactRequires[j].ItemQty);
                }

                pEmailTextData.Footer += CONST_HTMLBREAK + String.Format(CONST_ADDORDERURL, _AddOrder);

                pEmailTextData.Footer += CONST_HTMLBREAK + String.Format(CONST_DISABLECUSTOMERURL, pContact.CustomerID);
            }
            #endregion

#if _DEBUG
            pContact.EmailAddress    = "*****@*****.**";
            pContact.AltEmailAddress = "";
#endif

            #region SendEmail

            string _FromEmail = ConfigurationManager.AppSettings[EmailCls.CONST_APPSETTING_FROMEMAILKEY];
            string _Greetings = String.Empty;

            EmailCls _Email = new EmailCls();
            _Email.SetEmailFrom(_FromEmail);
            _Email.SetEmailSubject(tbxEmailSubject.Text);

            if (pContact.EmailAddress.Contains("@"))
            {
                _Email.SetEmailTo(pContact.EmailAddress, true);
                _Greetings = String.IsNullOrWhiteSpace(pContact.ContactFirstName) ? "<p>Hi Coffee Lover,</p>" : "<p>Hi " + pContact.ContactFirstName + ",</p>";

                _Email.MsgBody = _Greetings + "<p>" + pEmailTextData.Header + "</p><p>" + pEmailTextData.Body + "</p><br />" +
                                 _EmailBodyTable + "<br /><br />" + pEmailTextData.Footer;

#if _DEBUG
                _ReminderSent = true;
                //if ((pReminderCount < 5) || (!String.IsNullOrWhiteSpace(pOrderType)))
                //  _ReminderSent = _Email.SendEmail();
                //else
                //  _ReminderSent = true;
#else
                _ReminderSent = _Email.SendEmail();
#endif
            }
            if (pContact.AltEmailAddress.Contains("@"))
            {
                _Email.SetEmailTo(pContact.AltEmailAddress, true);
                _Greetings     = String.IsNullOrWhiteSpace(pContact.ContactAltFirstName) ? "<p>Hi Coffee Lover,</p>" : "<p>Hi " + pContact.ContactAltFirstName + ",</p>";
                _Email.MsgBody = _Greetings + "<p>" + pEmailTextData.Header + "</p><p>" + pEmailTextData.Body + "</p><br />" +
                                 _EmailBodyTable + CONST_HTMLBREAK + pEmailTextData.Footer;

#if _DEBUG
                _ReminderSent = true;
#else
                _ReminderSent = (_ReminderSent) || (_Email.SendEmail());
#endif
            }

            #endregion

            /// cipy values across and add to database
            _ReminderLog.CustomerID        = pContact.CustomerID;
            _ReminderLog.DateSentReminder  = System.DateTime.Now.Date;
            _ReminderLog.NextPrepDate      = pContact.NextCoffee.Date; // use the coffee date
            _ReminderLog.ReminderSent      = _ReminderSent;
            _ReminderLog.HadAutoFulfilItem = _HasAutoFulfilElements;
            _ReminderLog.HadReoccurItems   = _HasReoccuringElements;

            _ReminderLog.InsertLogItem(_ReminderLog);

            return(_ReminderSent);
        }