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(); }