예제 #1
0
// - code for update
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (tbxGroupItem.Text.Equals(string.Empty))
            {
                showMessageBox _MsgBox = new showMessageBox(this.Page, "Error no item", "Please enter a Group Item Name");
            }
            else
            {
                TrackerDotNet.control.ItemTypeTbl _ITT = new ItemTypeTbl();

                SysDataTbl _SysData = new SysDataTbl();

                _ITT.ItemDesc            = tbxGroupItem.Text;
                _ITT.ItemDetail          = tbxGroupDesc.Text;
                _ITT.ItemEnabled         = true;
                _ITT.ItemsCharacteritics = "Group Item-update";
                _ITT.ItemShortName       = tbxGroupShortName.Text;
                _ITT.ServiceTypeID       = _SysData.GetGroupItemTypeID();
                _ITT.SortOrder           = ItemTypeTbl.CONST_NEEDDESCRIPTION_SORT_ORDER + 5;
                _ITT.ItemTypeID          = Convert.ToInt32(lblGroupItemID.Text);
                bool           _success = _ITT.UpdateItem(_ITT);
                showMessageBox _MsgBox  = new showMessageBox(this.Page, "Status", _success ? "Group item update" : "Error updating group item");
                ReturnToPrevPage();
            }
        }
예제 #2
0
        protected void accAddDetailsButton_Click(object sender, EventArgs e)
        {
            CustomersAccInfoTbl _NewAccInfo = GetAccDataFromForm();

            if (_NewAccInfo.CustomersAccInfoID == 0) // it should be otherwise this button should have been disabled
            {
                string _err = _NewAccInfo.Insert(_NewAccInfo);

                if (string.IsNullOrEmpty(_err))
                {
                    showMessageBox _msg = new showMessageBox(this.Page, "Insert", "Customer Account Info Inserted");
                    accAddDetailsButton.Enabled = false;
                    accUpdateButton.Enabled     = true;
                    dvCustomersAccInfoUpdatePanel.Update();
                }
                else
                {
                    // we got an error, have they been added by someone else?  The the Customer ID exists.
                    CustomersAccInfoTbl _CustomersAccInfo = _NewAccInfo.GetByCustomerID(_NewAccInfo.CustomerID);
                    if (!_CustomersAccInfo.CustomersAccInfoID.Equals(0))
                    {
                        _NewAccInfo.CustomersAccInfoID = _CustomersAccInfo.CustomersAccInfoID;
                        UpdateAccountInfo(_NewAccInfo);
                    }
                    else
                    {
                        showMessageBox _msg = new showMessageBox(this.Page, "Insert", "Error inserting: " + _err);
                    }
                }
            }
        }
예제 #3
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (tbxGroupItem.Text.Equals(string.Empty))
            {
                showMessageBox _MsgBox = new showMessageBox(this.Page, "Error no item", "Please enter a Group Item Name");
            }
            else
            {
                TrackerDotNet.control.ItemTypeTbl _ITT = new ItemTypeTbl();

                if (_ITT.GroupOfThisNameExists(tbxGroupItem.Text))
                {
                    showMessageBox _MsgBox = new showMessageBox(this.Page, "name exists", "Group Name: " + tbxGroupItem.Text + " Exists. Please enter a different Group Item Name");
                }
                else
                {
                    SysDataTbl _SysData = new SysDataTbl();

                    _ITT.ItemDesc            = tbxGroupItem.Text;
                    _ITT.ItemDetail          = tbxGroupDesc.Text;
                    _ITT.ItemEnabled         = true;
                    _ITT.ItemsCharacteritics = "Group Item";
                    _ITT.ItemShortName       = tbxGroupShortName.Text;
                    _ITT.ServiceTypeID       = _SysData.GetGroupItemTypeID();
                    _ITT.SortOrder           = ItemTypeTbl.CONST_NEEDDESCRIPTION_SORT_ORDER + 5;

                    bool           _success = _ITT.InsertItem(_ITT);
                    showMessageBox _MsgBox  = new showMessageBox(this.Page, "Status", _success ? "Group item added" : "Error adding group item");
                    ReturnToPrevPage();
                }
            }
        }
예제 #4
0
        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);
        }
예제 #5
0
        protected void btnInsert_Click(object sender, EventArgs e)
        {
            string       _ErrorStr     = String.Empty;
            CustomersTbl _customerData = GetDataFromForm();

            //CustomersTbl _ctd = new CustomersTbl();
            //      ClientScriptManager _csm = Page.ClientScript;

            if (_customerData.InsertCustomer(_customerData, ref _ErrorStr))
            {
                _customerData = _customerData.GetCustomerByName(_customerData.CompanyName);

                if (_customerData.CustomerID > 0)
                {
                    CustomersAccInfoTbl _CustomersAccInfo = CopyCompanyData2AccInfo(_customerData);

                    _CustomersAccInfo.Enabled = true;

                    string _msg = _CustomersAccInfo.Insert(_CustomersAccInfo);
                    if (string.IsNullOrEmpty(_msg))
                    {
                        showMessageBox _showMsg = new showMessageBox(this.Page, "Insert", "Customer account info added, please edit.");

                        Response.Redirect(String.Format("{0}?{1}={2}&{3}=Y", Page.ResolveUrl("~/Pages/CustomerDetails.aspx"), CONST_URL_REQUEST_CUSTOMERID,
                                                        _customerData.CustomerID, CONST_URL_REQUEST_CUSTOMERACCFOCUS));

                        /*
                         *          SetButtonStatus(true);
                         *          tabcCustomer.Visible = true;
                         *          tabcCustomer.ActiveTabIndex = 0;
                         *          lblCustomerID.Text = _CustomersAccInfo.CustomerID.ToString();
                         *          PlaceAccDataOnForm(_CustomersAccInfo);
                         *          this.Page.SetFocus(accFullCoNameTextBox);
                         *          uppnlTabContainer.Update();
                         */
                    }
                    else
                    {
                        showMessageBox _showErrMsg = new showMessageBox(this.Page, "Insert", "Error inserting customer account info");
                    }

                    ltrlStatus.Text = "Customer Added";
                }
                else
                {
                    string _ScriptToRun = "redirect('" + String.Format("{0}?CompanyName={1}", Page.ResolveUrl("~/Pages/Customers.aspx"), _customerData.CompanyName) + "');";
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "CustomerInserted", _ScriptToRun, true);
                }
            }
            else
            {
                //        _msgBox.ShowSuccess("Error " + _ErrorStr + ". Customer not added.");

                ltrlStatus.Text = "ERROR: " + _ErrorStr;
            }
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        protected void UpdateAccountInfo(CustomersAccInfoTbl pUpdateAccInfo)
        {
            string _err = pUpdateAccInfo.Update(pUpdateAccInfo);

            if (string.IsNullOrEmpty(_err))
            {
                showMessageBox _msg = new showMessageBox(this.Page, "Update", "Customer Account Info Updated");
            }
            else
            {
                showMessageBox _msg = new showMessageBox(this.Page, "Update", "Error updating: " + _err);
            }
        }
예제 #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                long     _BoundCustomerId   = 1;
                DateTime _BoundDeliveryDate = DateTime.Now.Date;
                String   _BoundNotes        = String.Empty;

                if (Request.QueryString[CONST_QRYSTR_CUSTOMERID] != null)
                {
                    _BoundCustomerId = Convert.ToInt32(Request.QueryString[CONST_QRYSTR_CUSTOMERID].ToString());
                }
                if (Request.QueryString[CONST_QRYSTR_DELIVERYDATE] != null)
                {
                    _BoundDeliveryDate = Convert.ToDateTime(Request.QueryString[CONST_QRYSTR_DELIVERYDATE]).Date;
                }
                if (Request.QueryString[CONST_QRYSTR_NOTES] != null)
                {
                    _BoundNotes = Request.QueryString[CONST_QRYSTR_NOTES].ToString();
                }

                Session[OrderHeaderData.CONST_BOUNDCUSTOMERID]   = _BoundCustomerId;
                Session[OrderHeaderData.CONST_BOUNDDELIVERYDATE] = _BoundDeliveryDate.Date;
                Session[OrderHeaderData.CONST_BOUNDNOTES]        = _BoundNotes;
                Session[CONST_ORDERHEADERVALUES] = null;

                OrderItemTbl mine_ = new OrderItemTbl();

                // set the permissions
                MembershipUser _currMember = Membership.GetUser();
                btnOrderCancelled.Enabled = (_currMember.UserName.ToLower() == "warren");

                bool _EnableNew = User.IsInRole("Administrators") || User.IsInRole("AgentManager") || User.IsInRole("Agents");

                btnNewItem.Enabled = _EnableNew;
                TrackerTools _TT = new TrackerTools();

                _TT.SetTrackerSessionErrorString(string.Empty);
                if (Request.QueryString[CONST_QRYSTR_INVOICED] != null)
                {
                    if (Request.QueryString[CONST_QRYSTR_INVOICED].Equals("Y"))
                    {
                        MarkItemAsInvoiced();
                    }
                }
                else if (Request.QueryString[CONST_QRYSTR_DELIVERED] != null)
                {
                    if (Request.QueryString[CONST_QRYSTR_DELIVERED].Equals("Y"))
                    {
                        btnOrderDelivered_Click(sender, e);
                    }
                }
            }
            else
            {
                TrackerTools _TT       = new TrackerTools();
                string       _ErrorStr = _TT.GetTrackerSessionErrorString();
                if (!string.IsNullOrEmpty(_ErrorStr))
                {
                    showMessageBox _MsgBox = new showMessageBox(this.Page, "Tracker Error", "ERROR: " + _ErrorStr);
                    _TT.SetTrackerSessionErrorString(string.Empty);
                }
            }
        }
예제 #10
0
        //protected void MarkTempOrdersItemsAsDone(long pCustomerID)
        //{
        //  string _SQLUpdate = "UPDATE OrdersTbl SET OrdersTbl.Done = True WHERE CustomderId = " + pCustomerID.ToString() +
        //                         "AND EXISTS (SELECT RequiredByDate FROM TempOrdersHeaderTbl " +
        //                         "            WHERE (RequiredByDate = OrdersTbl.RequiredByDate))";

        //  TrackerDb _TrackerDb = new TrackerDb();
        //  _TrackerDb.ExecuteNonQuerySQL(_SQLUpdate);

        //  // ResetCustomerReminderCount(pCustomerId);
        //  //'''''''''''''
        //  //' mark orders as done - should do this last
        //  //'''
        //  //lblStatus.Caption = "Marking orders as done"
        //  //dbs.Execute ("UPDATE OrdersTbl SET OrdersTbl.Done = True " + _
        //  //             "WHERE (((Exists (Select TempOrdersTbl.OrderId from TempOrdersTbl where  " + _
        //  //                       "TempOrdersTbl.OrderId = OrdersTbl.OrderId))<>False))")
        //  //'''''''
        //  //'  Resetting count and enable, only if coffee item
        //  //'
        //  //dbs.Execute ("UPDATE DISTINCTROW CustomersTbl SET ReminderCount = 0, enabled = True WHERE CustomerID=" + lblCustomerID.Caption)
        //}

        // Logic for processing order as done:
        // 1. move items consumed from temp aable to the items consumed for the contact
        // 2. using the summary of the data on the form do calculations around predictions
        //    on when the contact needs items again.
        // 3. Notify client of items deliverred (add option to contacts table)
        // 4. return to the previous page.
        protected void btnDone_Click(object sender, EventArgs e)
        {
            const long MAXQTYINSTOCK = 50;

            TrackerTools _TrackerTools = new TrackerTools();

            _TrackerTools.SetTrackerSessionErrorString(string.Empty);

            Label    _CustomerIDLabel   = (Label)(fvOrderDone.FindControl("CustomerIDLabel"));
            Label    _CustomerNameLabel = (Label)(fvOrderDone.FindControl("CompanyNameLabel"));
            long     _CustomerID        = Convert.ToInt64(_CustomerIDLabel.Text);
            TextBox  _OrderDateLabel    = (TextBox)(fvOrderDone.FindControl("ByDateTextBox"));
            DateTime _OrderDate         = Convert.ToDateTime(_OrderDateLabel.Text);
            double   _CoffeeStock       = 0;
            // store the current data for display later:
            ClientUsageTbl _OriginalUsageDAL  = new ClientUsageTbl();
            ClientUsageTbl _OriginalUsageData = _OriginalUsageDAL.GetUsageData(_CustomerID);

            if (!string.IsNullOrEmpty(_TrackerTools.GetTrackerSessionErrorString()))
            {
                Response.Write(_TrackerTools.GetTrackerSessionErrorString());
            }

            TempOrdersDAL _TempOrdersDAL        = new TempOrdersDAL(); //
            bool          _HasCoffeeInTempOrder = _TempOrdersDAL.HasCoffeeInTempOrder();

            if (!string.IsNullOrEmpty(_TrackerTools.GetTrackerSessionErrorString()))
            {
                Response.Write(_TrackerTools.GetTrackerSessionErrorString());
            }

            /* NEED TO ADD Code to check for zzname */

            // check cup count not in wrong place
            if ((tbxStock.Text.Length > 0) && (Convert.ToDouble(tbxStock.Text) > MAXQTYINSTOCK))
            {
                showMessageBox _MsgBox = new showMessageBox(this.Page, "Stock seems high",
                                                            "The stock quantity appears very high please check that you have enterred the correct value in kilograms.</b>");
            }
            else
            {
                _CoffeeStock = String.IsNullOrEmpty(tbxStock.Text) ? 0 : Math.Round(Convert.ToDouble(tbxStock.Text), 2);

                // First we must get the latest cup count
                ltrlStatus.Text = "Calculating the latest cup count";
                GeneralTrackerDbTools _GeneralTrackerDb = new GeneralTrackerDbTools();

                GeneralTrackerDbTools.LineUsageData _LatestCustomerData = _GeneralTrackerDb.GetLatestUsageData(_CustomerID, TrackerTools.CONST_SERVTYPECOFFEE);
                if (!string.IsNullOrEmpty(_TrackerTools.GetTrackerSessionErrorString()))
                {
                    showMessageBox _smb = new showMessageBox(this.Page, "Tracker Session Error", _TrackerTools.GetTrackerSessionErrorString());
                }
                bool _bIsActual = (tbxCount.MaxLength > 0); // if there is a cup count
                long _lCupCount = 0;
                if (tbxCount.MaxLength > 0)
                {
                    _lCupCount = Convert.ToInt64(tbxCount.Text);
                }

                // Calculate the cup count if we do not have it on the form or they entered a value that makes no sense
                if ((_lCupCount < 1) || (_lCupCount < _LatestCustomerData.LastCount))
                {
                    ltrlStatus.Text = "Calculating the latest est cup count";
                    _lCupCount      = _GeneralTrackerDb.CalcEstCupCount(_CustomerID, _LatestCustomerData, _HasCoffeeInTempOrder);
                    _bIsActual      = false;
                }
                // clear any repairs that may have been logged
                RepairsTbl _Repairs = new RepairsTbl();
                _Repairs.SetStatusDoneByTempOrder();

                //' add items to consumption log
                _lCupCount = AddItemsToClientUsageTbl(_CustomerID, _bIsActual, _lCupCount, _CoffeeStock, _OrderDate);

                // update the last cup count for the client
                if (!_OriginalUsageDAL.UpdateUsageCupCount(_CustomerID, _lCupCount))
                {
                    showMessageBox _smb = new showMessageBox(this.Page, "Error", "Error updating last count");
                    ltrlStatus.Text = "error updating last count";
                }

                // now update the predictions
                _GeneralTrackerDb.UpdatePredictions(_CustomerID, _lCupCount);

                // update all items in the order table as done that are done
                _TempOrdersDAL.MarkTempOrdersItemsAsDone();

                // reset count and enable client
                _GeneralTrackerDb.ResetCustomerReminderCount(_CustomerID, _HasCoffeeInTempOrder);
                if (_HasCoffeeInTempOrder)
                {
                    _GeneralTrackerDb.SetClientCoffeeOnlyIfInfo(_CustomerID);
                }
                // may need to add another check here to handle if they have ordered maintenance stuff.


                switch (rbtnSendConfirm.SelectedValue)
                {
                case "none":
                    break;

                case "postbox":
                    SendDeliveredEmail(_CustomerID, "placed your order in the your post box.");
                    break;

                case "dispatched":
                    SendDeliveredEmail(_CustomerID, "dispatched you order.");
                    break;

                case "done":
                    SendDeliveredEmail(_CustomerID, "delivered your order and it has signed for.");
                    break;

                default:
                    break;
                }
                // destroy the temp table that we used to create this temp orders
                _TempOrdersDAL.KillTempOrdersData();

                ShowResults(_CustomerNameLabel.Text, _CustomerID, _OriginalUsageData);
            }
        }
예제 #11
0
        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);
        }
예제 #12
0
        /// <summary>
        /// Handle the send button click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSend_Click(object sender, EventArgs e)
        {
            uprgSendEmail.DisplayAfter = 0;
            string            _OrderType         = "";
            TempCoffeeCheckup _TempCoffeeCheckup = new TempCoffeeCheckup();
            // get all the contacts that need to be reminded
            List <ContactToRemindWithItems> _ContactsToRemind = _TempCoffeeCheckup.GetAllContactAndItems();
            SendCheckEmailTextsData         _EmailTextData    = new SendCheckEmailTextsData();
            CustomersTbl _Customer = new CustomersTbl();
            int          _RemindersSent = 0, _RemindersFailed = 0;

            for (int i = 0; i < _ContactsToRemind.Count; i++)
            {
                try
                {
                    _EmailTextData.Header = tbxEmailIntro.Text;
                    _EmailTextData.Footer = tbxEmailFooter.Text;
                    if (String.Concat(_ContactsToRemind[i].EmailAddress, _ContactsToRemind[i].AltEmailAddress).Contains("@"))
                    {
                        // customer has an email address
                        _ContactsToRemind[i].ReminderCount++;
                        if (_ContactsToRemind[i].ReminderCount < CONST_MAXREMINDERS)
                        {
                            _EmailTextData.Body = PersonalizeBodyText(_ContactsToRemind[i]);
                            // look through items to see if this is a reoccuring or auto order
                            _OrderType = GetTheOrderType(_ContactsToRemind[i]);
                            // if auto fulfil add to orders with auto add in the note
                            if (String.IsNullOrWhiteSpace(_OrderType))
                            {
                                _EmailTextData.Body += "We will only place an order on your request, no order has been added, this just a reminder.";
                            }
                            else
                            {
                                _EmailTextData.Body += "This is a" + (IsVowel(_OrderType[0]) ? "n " : " ") + _OrderType + ", please respond to cancel.";
                            }
                            if (_ContactsToRemind[i].ReminderCount == CONST_MAXREMINDERS - 1)
                            {
                                _EmailTextData.Body = String.Concat("This is your last reminder email. Next time reminders will be disabled until you order again.", _EmailTextData.Body);
                            }
                            // else next reminder in week*reminder count???

#if _DEBUG
                            if (SendReminder(_EmailTextData, _ContactsToRemind[i], _OrderType, _RemindersSent))
#else
                            if (SendReminder(_EmailTextData, _ContactsToRemind[i], _OrderType))
#endif
                            { _RemindersSent++; }
                            else
                            {
                                _RemindersFailed++;
                            }

                            //--- delay reminders for those that have too many, and update reminder count for all
                            if (_ContactsToRemind[i].ReminderCount >= CONST_FORCEREMINDERDELAYCOUNT)
                            {
                                DateTime _ForceDate = _ContactsToRemind[i].NextPrepDate.AddDays(10 * (_ContactsToRemind[i].ReminderCount - CONST_FORCEREMINDERDELAYCOUNT + 1));

                                ClientUsageTbl _ClientUsage = new ClientUsageTbl();
                                _ClientUsage.ForceNextCoffeeDate(_ForceDate, _ContactsToRemind[i].CustomerID);
                            }
                            // icrement count and set last date
                            _Customer.SetSentReminderAndIncrementReminderCount(DateTime.Now.Date, _ContactsToRemind[i].CustomerID);

                            ////---- check the last sent date?
                        }
                        else
                        {
                            _Customer.DisableCustomer(_ContactsToRemind[i].CustomerID);
                            _RemindersFailed++;
                        }
#if _DEBUG
//          if (_RemindersSent > 5) break;
#endif
                    }
                }
                catch (Exception _Ex)
                {
                    // just incse we have an error we normally do not have
                    showMessageBox _ExMsg = new showMessageBox(this.Page, "Error sending...", _Ex.Message);
                    _RemindersFailed++;
                }
            }

            showMessageBox _MsgBox = new showMessageBox(this.Page, "Reminder emails status", String.Format("Reminders processed. Sent: {0}; Failed: {1}", _RemindersSent, _RemindersFailed));

            string _RedirectURL = String.Format("{0}?LastSentDate={1:d}",
                                                ResolveUrl("~/Pages/SentRemindersSheet.aspx"), DateTime.Now.Date);
            Response.Redirect(_RedirectURL);
            PrepPageData();
        }
예제 #13
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);
        }
예제 #14
0
        private void SetListOfContactsToSendReminderTo() // ref List<string> strs, ref List<DateTime> dts)
        {
//      strs.Add("first get a list of contact that are on the reoccuringlist");
//      dts.Add(DateTime.Now);
            // first get a list of contact that are on the reoccuringlist
            List <ContactToRemindWithItems> _ContactsToRemind = GetReocurringContacts();

//      strs.Add("add the clients to that list that probably need in the next sechduled delivery period");
//      dts.Add(DateTime.Now);
            // now add the clients to that list that probably need in the next sechduled delivery period
            AddAllContactsToRemind(ref _ContactsToRemind);                                  //, ref strs, ref dts);

            _ContactsToRemind.Sort((a, b) => String.Compare(a.CompanyName, b.CompanyName)); // need to sort by name

//      strs.Add("write data to the table so it can be displayed");
//      dts.Add(DateTime.Now);
            /// write data to the table so it can be displayed
            TempCoffeeCheckup _TempCoffeeCheckup = new TempCoffeeCheckup();
            bool _CouldDelete = (_TempCoffeeCheckup.DeleteAllContactRecords()) && (_TempCoffeeCheckup.DeleteAllContactItems());

            if (!_CouldDelete)
            {
                showMessageBox _smb = new showMessageBox(this.Page, "Old Temp Table delete", "Error deleting old temp tables");
            }
            else
            {
                ItemTypeTbl _ITT             = new ItemTypeTbl();
                List <int>  _OnlyCoffeeItems = _ITT.GetAllItemIDsofServiceType(TrackerTools.CONST_SERVTYPECOFFEE);
                // also the group items - since they are coffee too.
                _OnlyCoffeeItems.AddRange(_ITT.GetAllItemIDsofServiceType(TrackerTools.CONST_SERVTYPEGROUPITEM));

                bool _AllAdded = false;
                bool _DoAdd    = false;
                int  j         = 0;
                for (int i = 0; i < _ContactsToRemind.Count; i++)
                {
                    // only insert client if the contain coffee item
                    _DoAdd = false;
                    j      = 0;
                    while ((j < _ContactsToRemind[i].ItemsContactRequires.Count) && (!_DoAdd))
                    {
                        _DoAdd = _OnlyCoffeeItems.Contains(_ContactsToRemind[i].ItemsContactRequires[j].ItemID);
                        j++;
                    }
                    if (_DoAdd)
                    {
                        _AllAdded = _TempCoffeeCheckup.InsertContacts(_ContactsToRemind[i]) || _AllAdded;

                        foreach (ItemContactRequires _Item in _ContactsToRemind[i].ItemsContactRequires) // (int j = 0; j < _ContactsToRemind[i].ItemsContactRequires.Count; j++)
                        {
                            _AllAdded = _TempCoffeeCheckup.InsertContactItems(_Item) || _AllAdded;
                        }
                    }
                }
                if (!_AllAdded)
                {
                    showMessageBox _smb = new showMessageBox(this.Page, "Not all records added to Temp Table", "Error adding some records added to Temp Table");
                }
            }
//      gvCustomerCheckup.DataSource = _ContactsToRemind;
//      gvCustomerCheckup.DataBind();
        }
예제 #15
0
        /// <summary>
        /// Send email to the current client to confirm the items in the current order, and the deliver date
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnConfirmOrder_Click(object sender, EventArgs e)
        {
            DropDownList _ddlThisContact = (DropDownList)dvOrderHeader.FindControl("ddlContacts");

            ContactEmailDetails _thisContact = GetEmailDetails(_ddlThisContact.SelectedItem.Value);

            if (_thisContact != null)
            {
                EmailCls     _email         = new EmailCls();
                DropDownList _ddlDeliveryBy = (DropDownList)dvOrderHeader.FindControl("ddlToBeDeliveredBy"); // who is delivering this

                string _DeliveryDate  = dvOrderHeaderGetLabelValue("lblRequiredByDate");                     // date it will be dispatched / delivered"
                string _PurchaseOrder = dvOrderHeaderGetLabelValue("lblPurchaseOrder");
                string _Notes         = dvOrderHeaderGetLabelValue("lblNotes");

                if (_thisContact.EmailAddress != "")
                {
                    _email.SetEmailFromTo(CONST_FROMEMAIL, _thisContact.EmailAddress);
                    if (_thisContact.altEmailAddress != "")
                    {
                        _email.SetEmailCC(_thisContact.altEmailAddress);
                    }
                }
                else if (_thisContact.altEmailAddress != "")
                {
                    _email.SetEmailFromTo(CONST_FROMEMAIL, _thisContact.altEmailAddress);
                }
                else
                {
                    ltrlStatus.Text = "no email address found";
                    TrackerDotNet.classes.showMessageBox _NoMsgBx = new classes.showMessageBox(this.Page, "Email FAILED: ", ltrlStatus.Text);
                    upnlNewOrderItem.Update();
                    return; // no email address so quit
                }
                // send a BCC to orders to confirm
                _email.SetEmailBCC(CONST_FROMEMAIL);
                // set subject and body
                _email.SetEmailSubject("Order Confirmation");

                string _AddressedTo = "Coffee Lover";
                if (_thisContact.FirstName != "")
                {
                    _AddressedTo = _thisContact.FirstName.Trim();
                    if (_thisContact.altFirstName != "")
                    {
                        _AddressedTo += " and " + _thisContact.altFirstName.Trim();
                    }
                }
                else if (_thisContact.altFirstName != "")
                {
                    _AddressedTo = _thisContact.altFirstName.Trim();
                }

                _email.AddStrAndNewLineToBody("Dear " + _AddressedTo + ",<br />");
                if (_ddlThisContact.SelectedValue.Equals(NewOrderDetail.CONST_ZZNAME_DEFAULTID))
                {
                    _email.AddStrAndNewLineToBody("We confirm you order below:");
                }
                else
                {
                    _email.AddStrAndNewLineToBody("We confirm the following order for " + _ddlThisContact.SelectedItem.Text + ":");
                }
                _email.AddToBody("<ul>");
                foreach (GridViewRow _gv in gvOrderLines.Rows)
                {
                    DropDownList _gvItemDLL       = (DropDownList)_gv.FindControl("ddlItemDesc");
                    Label        _gvItemQty       = (Label)_gv.FindControl("lblQuantityOrdered");
                    DropDownList _gvItemPackaging = (DropDownList)_gv.FindControl("ddlPackaging");
                    // need to check for serivce / note and add the note using the same logic as we have for the delivery sheet
                    if (GetItemSortOrderID(_gvItemDLL.SelectedValue) == ItemTypeTbl.CONST_NEEDDESCRIPTION_SORT_ORDER)
                    {
                        // if we are already use the notes field for name, check if there is a ":" seperator, and then only use what is after
                        if (_Notes.Contains(":"))
                        {
                            _Notes = _Notes.Substring(_Notes.IndexOf(":") + 1).Trim();
                        }

                        int _Start = _Notes.IndexOf(OrderDetail.CONST_EMAILDELIMITERSTART);
                        if (_Start >= 0)
                        {
                            int _End = _Notes.IndexOf(OrderDetail.CONST_EMAILDELIMITEREND);
                            if (_End >= 0)
                            {
                                _Notes = String.Concat(_Notes.Substring(0, _Start), ";", _Notes.Substring(_End + 2));
                            }
                        }

                        _email.AddFormatToBody("<li>{0}</li>", _Notes);
                    }
                    else
                    {
                        string _UnitsAndQty = AddUnitsToQty(_gvItemDLL.SelectedValue, _gvItemQty.Text);
                        if (_gvItemPackaging.SelectedIndex == 0)
                        {
                            _email.AddFormatToBody("<li>{0} of {1}</li>", _UnitsAndQty, _gvItemDLL.SelectedItem.Text);
                        }
                        else
                        {
                            _email.AddFormatToBody("<li>{0} of {1} - Preperation note: {2}</li>", _UnitsAndQty, _gvItemDLL.SelectedItem.Text, _gvItemPackaging.SelectedItem.Text);
                        }
                    }
                }
                _email.AddStrAndNewLineToBody("</ul>");

                if (!string.IsNullOrEmpty(_PurchaseOrder))
                {
                    if (_PurchaseOrder.EndsWith(TrackerTools.CONST_POREQUIRED))
                    {
                        _email.AddStrAndNewLineToBody("<b>NOTE</b>: We are still waiting for a Purchase Order number from you.<br />");
                    }
                    else
                    {
                        _email.AddStrAndNewLineToBody(string.Format("This order has purchase order: {0}, allocated to it.<br />", _PurchaseOrder));
                    }
                }
                if (_ddlDeliveryBy.SelectedItem.Text == CONST_DELIVERYTYPEISCOLLECTION)
                {
                    _email.AddStrAndNewLineToBody("The order will be ready for collection on: " + _DeliveryDate);
                }
                else if (_ddlDeliveryBy.SelectedItem.Text == CONST_DELIVERYTYPEISCOURIER)
                {
                    _email.AddStrAndNewLineToBody("The order will be dispatched on: " + _DeliveryDate + ".");
                }
                else
                {
                    _email.AddStrAndNewLineToBody("The order will be delivered on: " + _DeliveryDate + ".");
                }

                // Add a footer
                MembershipUser _currMember = Membership.GetUser();
                string         _from       = string.IsNullOrEmpty(_currMember.UserName) ? "the Quaffee Team" : " from the Quaffee Team (" + UpCaseFirstLetter(_currMember.UserName) + ")";

                _email.AddStrAndNewLineToBody("<br />Sent automatically by Quaffee's order and tracking System.<br /><br />Sincerely " + _from + " ([email protected])");
                if (_email.SendEmail())
                {
                    ltrlStatus.Text = "Email Sent to: " + _AddressedTo;
                }
                else
                {
                    showMessageBox _msg = new showMessageBox(this.Page, "error", "error sending email: " + _email.myResults);
                    ltrlStatus.Text = "Email was not sent!";
                }

                TrackerDotNet.classes.showMessageBox _MsgBx = new classes.showMessageBox(this.Page, "Email Confirmation", ltrlStatus.Text);
                upnlNewOrderItem.Update();
            }
        }
예제 #16
0
        protected void btnSetClientType_Click(object sender, EventArgs e)
        {
            pnlSetClinetType.Visible = true;
            gvCustomerTypes.Visible  = true;

            List <ContactsUpdated> _ContactsUpdated = new List <ContactsUpdated>();

            ClientUsageLinesTbl _ClientUsageLines = new ClientUsageLinesTbl();
            ItemUsageTbl        _ItemUsageTbl     = new ItemUsageTbl();
            ContactType         _Customer         = new ContactType();

            string _fName = "c:\\temp\\" + String.Format("SetClientType_{0:ddMMyyyy hh mm}.txt", DateTime.Now);

            _ColsStream = new StreamWriter(_fName, false); // create new file
            _ColsStream.WriteLine("Task, Company Name, origType, newType, PredDisabled");
            List <ContactType> _Customers = null;
            int i = 0;

            try
            {
                _Customers = _Customer.GetAllContacts("CompanyName"); // get all client sort by Company name
//        _Customers.RemoveAll(x => !x.IsEnabled);   // delete all the disabled clients

                List <int> _CoffeeClients     = GetAllCoffeeClientTypes();
                List <int> _ServiceOnlyClient = GetAllServiceOnlyClientTypes();

                // for each client check if they have ordered stuff and if so then set them as a particular client

                while (i < _Customers.Count)
                {
                    ContactsUpdated _Contact = new ContactsUpdated();
                    // only if they are enabled and not set to info only
                    if (_Customers[i].CustomerTypeID != CustomerTypeTbl.CONST_INFO_ONLY)
                    {
                        _Contact.ContactName        = _Customers[i].CompanyName;
                        _Contact.ContactTypeID      = _Customers[i].CustomerTypeID;
                        _Contact.origContactTypeID  = _Customers[i].CustomerTypeID;
                        _Contact.PredictionDisabled = _Customers[i].PredictionDisabled;

                        if (_Contact.ContactTypeID == 0) // type not set then assume coffee client.
                        {
                            _Contact.ContactTypeID = CustomerTypeTbl.CONST_COFFEE_ONLY;
                        }
                        // if they are currently marked as coffee client then check if they have ordered since their install date and with in the last year
                        if (_CoffeeClients.Contains(_Contact.ContactTypeID))
                        {
                            _Contact = CheckCoffeeCustomerIsOne(_Customers[i], _Contact);
                        }
                        else // customer is set to only be info or something so lets check if that is true
                        {
                            _Contact = CheckNoneCoffeeCustomer(_Customers[i], _Contact);
                        }
                        /// Has it changed? is fo update
                        if (!_Contact.ContactTypeID.Equals(_Contact.origContactTypeID))
                        {
                            // copy the values that could have change across since C cannot clone with out a class def so we use the temp class instead
                            _Customers[i].CustomerTypeID     = _Contact.ContactTypeID;
                            _Customers[i].PredictionDisabled = _Contact.PredictionDisabled;
                            string _Result = _Customers[i].UpdateContact(_Customers[i]);
                            _ContactsUpdated.Add(_Contact);
                            if (String.IsNullOrEmpty(_Result))
                            {
                                _ColsStream.WriteLine("Added {0}-{1}: {2}, {3}, {4}, {5}", i, _ContactsUpdated.Count, _Contact.ContactName, _Contact.origContactTypeID, _Contact.ContactTypeID, _Contact.PredictionDisabled);
                            }
                            else
                            {
                                _ColsStream.WriteLine("Error {0} Adding: {1}, {2}, {3}, {4}, {5}", _Result, i, _Result, _Contact.ContactName, _Contact.origContactTypeID, _Contact.ContactTypeID, _Contact.PredictionDisabled);
                            }
                        }
                    }
                    i++;
                }
            }
            catch (Exception _ex)
            {
                string _errStr = _ex.Message;

                TrackerTools _TT    = new TrackerTools();
                string       _TTErr = _TT.GetTrackerSessionErrorString();
                if (!String.IsNullOrWhiteSpace(_TTErr))
                {
                    _errStr += " TTError: " + _TTErr;
                }

                showMessageBox _exMsg = new showMessageBox(this.Page, "Error", _errStr);
                if (_Customers != null)
                {
                    _ColsStream.WriteLine("ERROR AT: {0}, Name: {1}, ID: {2}, Pred: {3}", i, _Customers[i].CompanyName, _Customers[i].CustomerTypeID, _Customers[i].PredictionDisabled);
                }
                else
                {
                    _ColsStream.WriteLine("null customers");
                }
                _ColsStream.WriteLine("Error:" + _errStr);
                throw;
            }
            finally
            {
                _ColsStream.Close();
            }

            showMessageBox _sMsg = new showMessageBox(this.Page, "Info", String.Format("A Total of {0}, contacts were updated", _ContactsUpdated.Count));

            ltrlStatus.Text        = String.Format("A Total of {0}, contacts were updated", _ContactsUpdated.Count);
            ltrlStatus.Visible     = true;
            ResultsTitleLabel.Text = "Set client type results";
            gvResults.DataSource   = _ContactsUpdated;
            gvResults.DataBind();
            // upnlSystemToolsButtons.Update();
        }
예제 #17
0
        protected void GoButton_Click(object sender, EventArgs e)
        {
            List <SQLCommand> _SQLCommands = new List <SQLCommand>();
            string            _FileName    = FileNameTextBox.Text;

            _FileName = _FileName.Replace(@"\", @"\\");

            XmlReader _XmlReader = XmlReader.Create(_FileName);

            try
            {
                while (_XmlReader.Read())
                {
                    if ((_XmlReader.NodeType == XmlNodeType.Element) && (_XmlReader.Name == "command"))
                    {
                        SQLCommand _SQLCommand = new SQLCommand();

                        _SQLCommand.type = _XmlReader.GetAttribute("type");
                        _XmlReader.Read();                                    // next should be value
                        _SQLCommand.sql = _XmlReader.Value.Replace("\n", ""); // remove new line characters

                        _SQLCommands.Add(_SQLCommand);
                    }
                }
                _XmlReader.Close();

                for (int i = 0; i < _SQLCommands.Count; i++)
                {
                    if (_SQLCommands[i].type == "select")
                    {
                        GridView            _gvSelectResult = new GridView();
                        System.Data.DataSet _ds             = RunSelect(_SQLCommands[i].sql);

                        _SQLCommands[i].result = (_ds != null);

                        _gvSelectResult.DataSource = _ds;

                        _gvSelectResult.DataBind();
                        pnlSQLResults.Controls.Add(_gvSelectResult);
                    }
                    else if (_SQLCommands[i].type != "disabled")
                    {
                        _SQLCommands[i].errString = RunCommand(_SQLCommands[i].sql);
                        _SQLCommands[i].result    = String.IsNullOrWhiteSpace(_SQLCommands[i].errString);
                    }

                    TrackerTools _TT  = new TrackerTools();
                    string       _err = _TT.GetTrackerSessionErrorString();
                    if (!string.IsNullOrEmpty(_err))
                    {
                        showMessageBox _msg = new showMessageBox(this.Page, "err", _err);
                        _TT.SetTrackerSessionErrorString("");
                    }
                }
                // assign resutls to result panel
                gvSQLResults.DataSource = _SQLCommands;
                gvSQLResults.DataBind();
            }
            catch (Exception _ex)
            {
                showMessageBox _showMsg = new showMessageBox(this.Page, "Error", "File access error: \n" + _ex.Message);
            }
            finally
            {
                _XmlReader.Close();
            }
        }