private void PutDataFromForm(long pReoccuringOrderID) { // place data on form using ID as a Key ReoccuringOrderDAL _DAL = new ReoccuringOrderDAL(); ReoccuringOrderTbl _ReoccuringOrderData = _DAL.GetByReoccuringOrderByID(pReoccuringOrderID); if (_ReoccuringOrderData != null) { ReoccuringOrderIDLabel.Text = _ReoccuringOrderData.ReoccuringOrderID.ToString(); // if (ddlCompanyName.Items.FindByValue(_ReoccuringOrderData.CustomerID.ToString()) != null) ddlCompanyName.SelectedValue = _ReoccuringOrderData.CustomerID.ToString(); ValueTextBox.Text = _ReoccuringOrderData.ReoccuranceValue.ToString(); // if (ddlReoccuranceType.Items.FindByValue(_ReoccuringOrderData.ReoccuranceTypeID.ToString()) != null) ddlReoccuranceType.SelectedValue = _ReoccuringOrderData.ReoccuranceTypeID.ToString(); // if (ddlItemType.Items.FindByValue(_ReoccuringOrderData.ItemRequiredID.ToString()) != null) ddlItemType.SelectedValue = _ReoccuringOrderData.ItemRequiredID.ToString(); QuantityTextBox.Text = _ReoccuringOrderData.QtyRequired.ToString(); UntilDateTextBox.Text = String.Format("{0:d}", _ReoccuringOrderData.RequireUntilDate); LastDateTextBox.Text = String.Format("{0:d}", _ReoccuringOrderData.DateLastDone); NextDateLabel.Text = String.Format("{0:d}", _ReoccuringOrderData.NextDateRequired); ddlPackagingTypes.SelectedValue = _ReoccuringOrderData.PackagingID.ToString(); EnabledCheckBox.Checked = _ReoccuringOrderData.Enabled; NotesTextBox.Text = _ReoccuringOrderData.Notes; } }
void UpdateRecord() { ReoccuringOrderDAL _DAL = new ReoccuringOrderDAL(); string _resultStr = (_DAL.UpdateReoccuringOrder(GetDataFromForm(), Convert.ToInt64(ReoccuringOrderIDLabel.Text))); ltrlStatus.Text = (_resultStr == "") ? "Reoccuring Item Updated" : _resultStr; showMessageBox _smb = new showMessageBox(this.Page, "Reoccurring Order Update", ltrlStatus.Text); }
protected void btnDelete_Click(object sender, EventArgs e) { ReoccuringOrderDAL _DAL = new ReoccuringOrderDAL(); string _resultStr = _DAL.DeleteReoccuringOrder(Convert.ToInt64(ReoccuringOrderIDLabel.Text)); ltrlStatus.Text = (_resultStr == "") ? "Reoccuring Item Deleted" : _resultStr; showMessageBox _smb = new showMessageBox(this.Page, "Reoccurring Order Deleted", ltrlStatus.Text); ReturnToPrevPage(true); }
protected void btnInsert_Click(object sender, EventArgs e) { ReoccuringOrderDAL _DAL = new ReoccuringOrderDAL(); string _resultStr = _DAL.InsertReoccuringOrder(GetDataFromForm()); ltrlStatus.Text = (_resultStr == "") ? "Reoccuring Item Inserted" : "Error inserting: " + _resultStr; showMessageBox _smb = new showMessageBox(this.Page, "Reoccurring Order Insert", ltrlStatus.Text); ReturnToPrevPage(true); }
private List <ContactToRemindWithItems> GetReocurringContacts() { // General VAR definitions List <ContactToRemindWithItems> _ContactsToRemind = new List <ContactToRemindWithItems>(); TrackerTools _TrackerTools = new classes.TrackerTools(); // . from TrackerDotNet.classes. DateTime _dtTemp = DateTime.MinValue; DateTime _dtNextRoast = DateTime.MinValue; // get the syustem minimum date for if we are closed SysDataTbl _SysData = new SysDataTbl(); DateTime _MinDate = _SysData.GetMinReminderDate(); // 1. // make sure the dates in the Reoccuring table match the last delivery date ReoccuringOrderDAL _ReoccuringOrderDAL = new ReoccuringOrderDAL(); // Need to add this to the classs if (!_ReoccuringOrderDAL.SetReoccuringItemsLastDate()) { showMessageBox _smb = new showMessageBox(this.Page, "Set Reoccuring Item Last Date", "Could not set the re-occuring last date"); return(_ContactsToRemind); } // if we get here we could set the last date ?????????????? /* 2. For each enabled record in the ReoccuringTbl: * if the LastDatePerItem + DateAdd(ReocurranceType) < NextCityDeliveryDate * then add them into the temporary reminder table, but set the value in the tempoary reminder table to remember that it is a reoccuring and an auto fulfil. */ // now make sure that only records the are enbabled and need to be added from Reoccuring Are added List <ReoccuringOrderExtData> _ReoccuringOrders = _ReoccuringOrderDAL.GetAll(ReoccuringOrderDAL.CONST_ENABLEDONLY, "CustomersTbl.CustomerID"); // -1 is all re ///////////// perhaps we should return all details in the above query? for (int i = 0; i < _ReoccuringOrders.Count; i++) { switch (_ReoccuringOrders[i].ReoccuranceTypeID) { case ReoccuranceTypeTbl.CONST_WEEKTYPEID: _ReoccuringOrders[i].NextDateRequired = _ReoccuringOrders[i].DateLastDone.AddDays(_ReoccuringOrders[i].ReoccuranceValue * 7).Date; break; case ReoccuranceTypeTbl.CONST_DAYOFMONTHID: _ReoccuringOrders[i].NextDateRequired = _ReoccuringOrders[i].DateLastDone.AddMonths(1).Date; _ReoccuringOrders[i].NextDateRequired = new DateTime(_ReoccuringOrders[i].NextDateRequired.Year, _ReoccuringOrders[i].NextDateRequired.Month, _ReoccuringOrders[i].ReoccuranceValue).Date; break; default: break; // not a type we know so exit } // disable the order if this is the last time if ((_ReoccuringOrders[i].RequireUntilDate > TrackerTools.STATIC_TrackerMinDate) && (_ReoccuringOrders[i].NextDateRequired > _ReoccuringOrders[i].RequireUntilDate)) { _ReoccuringOrders[i].Enabled = false; } _dtNextRoast = _TrackerTools.GetNextRoastDateByCustomerID(_ReoccuringOrders[i].CustomerID, ref _dtTemp); // check if the the Next roast date is less than the system Minimum date if (_dtNextRoast < _MinDate) { _dtNextRoast = _MinDate; } // if DateNext < NextDeliveryDate for client the add to list if (_ReoccuringOrders[i].NextDateRequired <= _dtNextRoast) { // we have a winner we need to add this item but first check if there is an order for this item type. OrderCheck _orderCheck = new OrderCheck(); List <OrderCheckData> _OrdersToCheck = _orderCheck.GetSimilarItemInOrders(_ReoccuringOrders[i].CustomerID, _ReoccuringOrders[i].ItemRequiredID, DateTimeExtensions.GetFirstDayOfWeek(_dtNextRoast), DateTimeExtensions.GetLastDayOfWeek(_dtNextRoast)); if (_OrdersToCheck == null) { // there are no orders that have the same item type ItemContactRequires _ItemRequired = new ItemContactRequires(); _ItemRequired.CustomerID = _ReoccuringOrders[i].CustomerID; _ItemRequired.AutoFulfill = false; // it is a reoccuring order not auto ff _ItemRequired.ReoccurID = _ReoccuringOrders[i].ReoccuringOrderID; _ItemRequired.ReoccurOrder = true; // remember it is from reoccuring _ItemRequired.ItemID = _ReoccuringOrders[i].ItemRequiredID; _ItemRequired.ItemQty = _ReoccuringOrders[i].QtyRequired; _ItemRequired.ItemPackagID = _ReoccuringOrders[i].PackagingID; // check if the customer exists if (!_ContactsToRemind.Exists(x => x.CustomerID == _ItemRequired.CustomerID)) { ContactToRemindWithItems _ContactToRemind = new ContactToRemindWithItems(); _ContactToRemind = _ContactToRemind.GetCustomerDetails(_ItemRequired.CustomerID); _ContactToRemind.ItemsContactRequires.Add(_ItemRequired); _ContactsToRemind.Add(_ContactToRemind); } else { int _ContactIdx = _ContactsToRemind.FindIndex(x => x.CustomerID == _ItemRequired.CustomerID); _ContactsToRemind[_ContactIdx].ItemsContactRequires.Add(_ItemRequired); } } else { List <OrderCheckData> _OrderCheckData = null; // store that and order has identified if (Session[CONST_SESSIONVAR_EXISTINGORDERS] == null) { _OrderCheckData = new List <OrderCheckData>(); } else { _OrderCheckData = (List <OrderCheckData>)Session[CONST_SESSIONVAR_EXISTINGORDERS]; } for (int j = 0; j < _OrdersToCheck.Count; j++) { _OrderCheckData.Add(_OrdersToCheck[j]); } // this.gvReminderOfOrdersPlaced.DataSource = _OrderCheckData; // this.gvReminderOfOrdersPlaced.DataBind(); // Session[CONST_SESSIONVAR_EXISTINGORDERS] = _OrderCheckData; } } /// we found an item in reoccuring that we need to send a reminder too } return(_ContactsToRemind); }
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); }