private void butOK_Click(object sender, System.EventArgs e) { #region Validation //if clinics are not enabled and the PayConnect program link is enabled, make sure there is a username and password set //if clinics are enabled, the program link can be enabled with blank username and/or password fields for some clinics //clinics with blank username and/or password will essentially not have PayConnect enabled //if 'Enable terminal processing' is checked then the practice/clinic will not need a username and password. if (checkEnabled.Checked && !checkTerminal.Checked && !PrefC.HasClinicsEnabled && (textUsername.Text == "" || textPassword.Text == "")) { MsgBox.Show(this, "Please enter a username and password first."); return; } if (checkEnabled.Checked && //if PayConnect is enabled comboPaymentType.SelectedIndex < 0 && //and the payment type is not set (!PrefC.HasClinicsEnabled || //and either clinics are not enabled (meaning this is the only set of username, password, payment type values) (textUsername.Text != "" && textPassword.Text != ""))) //or clinics are enabled and this clinic's link has a username and password set { MsgBox.Show(this, "Please select a payment type first."); return; } if (checkEnabled.Checked && //if PayConnect is enabled comboDefaultProcessing.SelectedIndex < 0) { MsgBox.Show(this, "Please select a default processing method type first."); return; } SynchWithHQ(); //if the user changes the HQ credentials, any clinic that had the same credentials will be kept in synch with HQ long clinicNum = 0; if (PrefC.HasClinicsEnabled) { clinicNum = _listUserClinicNums[comboClinic.SelectedIndex]; } UpdateListProgramPropertiesForClinic(clinicNum); string payTypeCur; //make sure any other clinics with PayConnect enabled also have a payment type selected for (int i = 0; i < _listUserClinicNums.Count; i++) { if (!checkEnabled.Checked) //if program link is not enabled, do not bother checking the payment type selected { break; } payTypeCur = ProgramProperties.GetPropValFromList(_listProgProps, "PaymentType", _listUserClinicNums[i]); //if the program is enabled and the username and password fields are not blank, //PayConnect is enabled for this clinic so make sure the payment type is also set if (((ProgramProperties.GetPropValFromList(_listProgProps, "Username", _listUserClinicNums[i]) != "" && //if username set ProgramProperties.GetPropValFromList(_listProgProps, "Password", _listUserClinicNums[i]) != "") || //and password set ProgramProperties.GetPropValFromList(_listProgProps, "TerminalProcessingEnabled", _listUserClinicNums[i]) == "1") && //or terminal enabled !_listPaymentTypeDefs.Any(x => x.DefNum.ToString() == payTypeCur)) //and paytype is not a valid DefNum { MsgBox.Show(this, "Please select the payment type for all clinics with PayConnect username and password set."); return; } } #endregion Validation #region Save if (_progCur.Enabled != checkEnabled.Checked) //only update the program if the IsEnabled flag has changed { _progCur.Enabled = checkEnabled.Checked; Programs.Update(_progCur); } ProgramProperties.Sync(_listProgProps, _progCur.ProgramNum); //Find all clinics that have PayConnect online payments enabled _listProgProps.FindAll(x => x.PropertyDesc == PayConnect.ProgramProperties.PatientPortalPaymentsEnabled && PIn.Bool(x.PropertyValue)).ForEach(x => { //Find all XWeb program properties that we saved in this session. Only clinics that have changes will have an XWeb property in memory. //This is needed to ensure that we don't disable XWeb online payments if someone // checks to use PayConnect online payments and then decides to keep it disabled during the same session. ProgramProperty ppXWebOnlinePayments = _listXWebWebPayProgProps.FirstOrDefault(y => y.ClinicNum == x.ClinicNum); if (ppXWebOnlinePayments != null) { ProgramProperties.UpdateProgramPropertyWithValue(ppXWebOnlinePayments, POut.Bool(false)); } }); #endregion Save DataValid.SetInvalid(InvalidType.Programs); DialogResult = DialogResult.OK; }
private void butOK_Click(object sender, System.EventArgs e) { #region Validation //if clinics are not enabled and the PayConnect program link is enabled, make sure there is a username and password set //if clinics are enabled, the program link can be enabled with blank username and/or password fields for some clinics //clinics with blank username and/or password will essentially not have PayConnect enabled //if 'Enable terminal processing' is checked then the practice/clinic will not need a username and password. if (checkEnabled.Checked && !checkTerminal.Checked && !PrefC.HasClinicsEnabled && (textUsername.Text == "" || textPassword.Text == "")) { MsgBox.Show(this, "Please enter a username and password first."); return; } if (checkEnabled.Checked && //if PayConnect is enabled comboPaymentType.SelectedIndex < 0 && //and the payment type is not set (!PrefC.HasClinicsEnabled || //and either clinics are not enabled (meaning this is the only set of username, password, payment type values) (textUsername.Text != "" && textPassword.Text != ""))) //or clinics are enabled and this clinic's link has a username and password set { MsgBox.Show(this, "Please select a payment type first."); return; } if (checkEnabled.Checked && //if PayConnect is enabled comboDefaultProcessing.SelectedIndex < 0) { MsgBox.Show(this, "Please select a default processing method type first."); return; } SynchWithHQ(); //if the user changes the HQ credentials, any clinic that had the same credentials will be kept in synch with HQ long clinicNum = 0; if (PrefC.HasClinicsEnabled) { clinicNum = _listUserClinicNums[comboClinic.SelectedIndex]; } string payTypeSelected = ""; if (comboPaymentType.SelectedIndex > -1) { payTypeSelected = _listPaymentTypeDefs[comboPaymentType.SelectedIndex].DefNum.ToString(); } string processingMethodSelected = comboDefaultProcessing.SelectedIndex.ToString(); //set the values in the list for this clinic _listProgProps.FindAll(x => x.ClinicNum == clinicNum && x.PropertyDesc == "Username") .ForEach(x => x.PropertyValue = textUsername.Text); //always 1 item; null safe _listProgProps.FindAll(x => x.ClinicNum == clinicNum && x.PropertyDesc == "Password") .ForEach(x => x.PropertyValue = textPassword.Text); //always 1 item; null safe _listProgProps.FindAll(x => x.ClinicNum == clinicNum && x.PropertyDesc == "PaymentType") .ForEach(x => x.PropertyValue = payTypeSelected); //always 1 item; null safe _listProgProps.FindAll(x => x.ClinicNum == clinicNum && x.PropertyDesc == PayConnect.ProgramProperties.DefaultProcessingMethod) .ForEach(x => x.PropertyValue = processingMethodSelected); _listProgProps.FindAll(x => x.ClinicNum == clinicNum && x.PropertyDesc == "TerminalProcessingEnabled") .ForEach(x => x.PropertyValue = POut.Bool(checkTerminal.Checked)); //always 1 item; null safe _listProgProps.FindAll(x => x.ClinicNum == clinicNum && x.PropertyDesc == PayConnect.ProgramProperties.PayConnectForceRecurringCharge) .ForEach(x => x.PropertyValue = POut.Bool(checkForceRecurring.Checked)); //Patient portal payments with PayConnect are currently not supported, checkWebPayEnabled is never visible, so always set to 0, //but we'll leave this here for future functionality //_listProgProps.FindAll(x => x.ClinicNum==clinicNum && x.PropertyDesc=="IsOnlinePaymentsEnabled") // .ForEach(x => x.PropertyValue=POut.Bool(checkWebPayEnabled.Checked));//always 1 item; null safe string payTypeCur; //make sure any other clinics with PayConnect enabled also have a payment type selected for (int i = 0; i < _listUserClinicNums.Count; i++) { if (!checkEnabled.Checked) //if program link is not enabled, do not bother checking the payment type selected { break; } payTypeCur = ProgramProperties.GetPropValFromList(_listProgProps, "PaymentType", _listUserClinicNums[i]); //if the program is enabled and the username and password fields are not blank, //PayConnect is enabled for this clinic so make sure the payment type is also set if (((ProgramProperties.GetPropValFromList(_listProgProps, "Username", _listUserClinicNums[i]) != "" && //if username set ProgramProperties.GetPropValFromList(_listProgProps, "Password", _listUserClinicNums[i]) != "") || //and password set ProgramProperties.GetPropValFromList(_listProgProps, "TerminalProcessingEnabled", _listUserClinicNums[i]) == "1") && //or terminal enabled !_listPaymentTypeDefs.Any(x => x.DefNum.ToString() == payTypeCur)) //and paytype is not a valid DefNum { MsgBox.Show(this, "Please select the payment type for all clinics with PayConnect username and password set."); return; } } #endregion Validation #region Save if (_progCur.Enabled != checkEnabled.Checked) //only update the program if the IsEnabled flag has changed { _progCur.Enabled = checkEnabled.Checked; Programs.Update(_progCur); } ProgramProperties.Sync(_listProgProps, _progCur.ProgramNum); #endregion Save DataValid.SetInvalid(InvalidType.Programs); DialogResult = DialogResult.OK; }
///<summary>Saves form data to the dict and then removes any clinics from the dict that exactly match the HQ clinic details. If editing a clinic ///other than HQ and there are no props for that clinic and the form values are different than HQ, a new list is added to the dict.</summary> private void SyncWithHQ() { List <ProgramProperty> listHqProps = _dictClinicListProgProps[0]; //dict guaranteed to contain ClinicNum 0 List <ProgramProperty> listPropsCur; if (!_dictClinicListProgProps.TryGetValue(_selectedClinicNum, out listPropsCur)) { //if there isn't a list of props for the clinic, create a new list for comparison and possibly for inserting for the clinic listPropsCur = listHqProps.Select(x => new ProgramProperty() { ProgramNum = x.ProgramNum, ClinicNum = _selectedClinicNum, PropertyDesc = x.PropertyDesc }).ToList(); } //these are the props that will be synced with HQ and used to determine whether a clinic's props should be deleted or used instead of the HQ props //the disable advert and disable advert HQ props are only for the HQ clinic and will be ignored for syncing a clinic string[] listSyncedProps = new[] { "SftpServerAddress", "SftpServerPort", "SftpUsername", "SftpPassword", "ClientIdAccelerator", "ClientIdCollection", "IsThankYouLetterEnabled", "SelectedServices", "SyncExcludePosAdjType", "SyncExcludeNegAdjType" }; foreach (ProgramProperty propCur in listPropsCur) //update the currently selected props with the current form values { switch (propCur.PropertyDesc) { case "SftpServerAddress": propCur.PropertyValue = textSftpAddress.Text; continue; case "SftpServerPort": propCur.PropertyValue = textSftpPort.Text; continue; case "SftpUsername": propCur.PropertyValue = textSftpUsername.Text; continue; case "SftpPassword": propCur.PropertyValue = textSftpPassword.Text; continue; case "ClientIdAccelerator": propCur.PropertyValue = textClientIdAccelerator.Text; continue; case "ClientIdCollection": propCur.PropertyValue = textClientIdCollection.Text; continue; case "IsThankYouLetterEnabled": propCur.PropertyValue = POut.Bool(checkThankYouLetter.Checked); continue; case "Disable Advertising": _dictClinicListProgProps.Values.SelectMany(x => x.Where(y => y.PropertyDesc == "Disable Advertising")).ToList() .ForEach(y => y.PropertyValue = POut.Bool(checkHideButtons.Checked)); propCur.PropertyValue = POut.Bool(checkHideButtons.Checked); //in case list is for a new clinic and not in dict continue; case "Disable Advertising HQ": //false if prop is null or if the value is anything but "1" bool isAdvertDisabledHQ = (listHqProps.FirstOrDefault(x => x.PropertyDesc == "Disable Advertising HQ")?.PropertyValue == "1"); _dictClinicListProgProps.Values.SelectMany(x => x.Where(y => y.PropertyDesc == "Disable Advertising HQ")).ToList() .ForEach(x => x.PropertyValue = POut.Bool(isAdvertDisabledHQ)); //in case list is for a new clinic and not in dict propCur.PropertyValue = POut.Bool(isAdvertDisabledHQ); continue; case "SelectedServices": List <int> selectedServices = new List <int>(); if (checkAccelService.Checked) { selectedServices.Add((int)TsiDemandType.Accelerator); } if (checkPRService.Checked) { selectedServices.Add((int)TsiDemandType.ProfitRecovery); } if (checkCollService.Checked) { selectedServices.Add((int)TsiDemandType.Collection); } propCur.PropertyValue = string.Join(",", selectedServices); continue; case "SyncExcludePosAdjType": propCur.PropertyValue = comboPosAdjType.GetSelectedDefNum().ToString(); continue; case "SyncExcludeNegAdjType": propCur.PropertyValue = comboNegAdjType.GetSelectedDefNum().ToString(); continue; } } if (_selectedClinicNum == 0) //if HQ selected { _dictClinicListProgProps.ToList() //go through all clinic properties .RemoveAll(x => x.Key > 0 && //remove the non-HQ clinic props x.Value.All(y => !listSyncedProps.Contains(y.PropertyDesc) || //the prop is an HQ only prop, i.e. the clinic prop is ignored listHqProps.Any(z => z.PropertyDesc == y.PropertyDesc && z.PropertyValue == y.PropertyValue))); //have matching HQ prop desc and value } else { if (listPropsCur.All(x => !listSyncedProps.Contains(x.PropertyDesc) || //if all props for the non-HQ clinic are HQ only props, i.e. the clinic prop is ignored listHqProps.Any(y => y.PropertyDesc == x.PropertyDesc && y.PropertyValue == x.PropertyValue))) //have matching HQ prop desc and value { //remove non-HQ clinic props, they are synced with HQ _dictClinicListProgProps.Remove(_selectedClinicNum); //does not throw exception if dict doesn't contain the key! (according to MSDN) } else if (!_dictClinicListProgProps.ContainsKey(_selectedClinicNum)) //if the clinic is not in the dict (otherwise values are already updated) //add non-HQ clinic to the dict if any prop for the non-HQ clinic is different than the HQ clinic and it's not already in the dict { _dictClinicListProgProps.Add(_selectedClinicNum, listPropsCur); } } }
private void butOK_Click(object sender, System.EventArgs e) { #region Validation //if clinics are not enabled and the PaySimple program link is enabled, make sure there is a username and key set //if clinics are enabled, the program link can be enabled with blank username and/or key fields for some clinics //clinics with blank username and/or key will essentially not have PaySimple enabled if (checkEnabled.Checked && !IsClinicCurSetupDone()) //Also works for offices not using clinics { MsgBox.Show(this, "Please enter a username, key, and/or payment type first."); return; } SynchWithHQ(); //if the user changes the HQ credentials, any clinic that had the same credentials will be kept in synch with HQ long clinicNum = 0; if (PrefC.HasClinicsEnabled) { clinicNum = _listUserClinicNums[comboClinic.SelectedIndex]; } string payTypeCCSelected = ""; if (comboPaymentTypeCC.SelectedIndex > -1) { payTypeCCSelected = comboPaymentTypeCC.GetSelected <Def>().DefNum.ToString(); } string payTypeACHSelected = ""; if (comboPaymentTypeACH.SelectedIndex > -1) { payTypeACHSelected = comboPaymentTypeACH.GetSelected <Def>().DefNum.ToString(); } //set the values in the list for this clinic _listProgProps.FindAll(x => x.ClinicNum == clinicNum && x.PropertyDesc == PaySimple.PropertyDescs.PaySimpleApiUserName) .ForEach(x => x.PropertyValue = textUsername.Text); //always 1 item; null safe _listProgProps.FindAll(x => x.ClinicNum == clinicNum && x.PropertyDesc == PaySimple.PropertyDescs.PaySimpleApiKey) .ForEach(x => x.PropertyValue = textKey.Text); //always 1 item; null safe _listProgProps.FindAll(x => x.ClinicNum == clinicNum && x.PropertyDesc == PaySimple.PropertyDescs.PaySimplePayTypeCC) .ForEach(x => x.PropertyValue = payTypeCCSelected); //always 1 item _listProgProps.FindAll(x => x.ClinicNum == clinicNum && x.PropertyDesc == PaySimple.PropertyDescs.PaySimplePayTypeACH) .ForEach(x => x.PropertyValue = payTypeACHSelected); //always 1 item _listProgProps.FindAll(x => x.ClinicNum == clinicNum && x.PropertyDesc == PaySimple.PropertyDescs.PaySimplePreventSavingNewCC) .ForEach(x => x.PropertyValue = POut.Bool(checkPreventSavingNewCC.Checked)); string payTypeCC; string payTypeACH; //make sure any other clinics with PaySimple enabled also have a payment type selected for (int i = 0; i < _listUserClinicNums.Count; i++) { if (!checkEnabled.Checked) //if program link is not enabled, do not bother checking the payment type selected { break; } payTypeCC = ProgramProperties.GetPropValFromList(_listProgProps, PaySimple.PropertyDescs.PaySimplePayTypeCC, _listUserClinicNums[i]); payTypeACH = ProgramProperties.GetPropValFromList(_listProgProps, PaySimple.PropertyDescs.PaySimplePayTypeACH, _listUserClinicNums[i]); //if the program is enabled and the username and key fields are not blank, //PaySimple is enabled for this clinic so make sure the payment type is also set if (ProgramProperties.GetPropValFromList(_listProgProps, PaySimple.PropertyDescs.PaySimpleApiUserName, _listUserClinicNums[i]) != "" && //if username set ProgramProperties.GetPropValFromList(_listProgProps, PaySimple.PropertyDescs.PaySimpleApiKey, _listUserClinicNums[i]) != "" //and key set //and either paytype is not a valid DefNum && (!_listPaymentTypeDefs.Any(x => x.DefNum.ToString() == payTypeCC) || !_listPaymentTypeDefs.Any(x => x.DefNum.ToString() == payTypeACH))) { MsgBox.Show(this, "Please select payment types for all clinics with PaySimple username and key set."); return; } } #endregion Validation #region Save if (_progCur.Enabled != checkEnabled.Checked) //only update the program if the IsEnabled flag has changed { _progCur.Enabled = checkEnabled.Checked; Programs.Update(_progCur); } ProgramProperties.Sync(_listProgProps, _progCur.ProgramNum); #endregion Save DataValid.SetInvalid(InvalidType.Programs); //Webhooks calls validation. This code needs to be under the validation section so people enabling the program for the first time will //be able to save their fields and the program properties will get filled correctly. //get url for webhooks, then create the webhooks if not already present. Has to be done after validation so new user enables are able to save. //for each clinic that has a username and api key, make a call to paysimple's api to see what webhooks this api account has. if (PrefC.HasClinicsEnabled) { foreach (long clinic in _listUserClinicNums) { WebhookHelper(GetUsernameForClinic(clinic), GetKeyForClinic(clinic), clinic); } } else { WebhookHelper(textUsername.Text, textKey.Text, 0); } DialogResult = DialogResult.OK; }