using framework_business;
using framework_library;
using ICSharpCode.SharpZipLib.Zip;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
using Telerik.Web.UI;
public partial class controls_admin_setup : System.Web.UI.UserControl
{
#region properties
///
/// Company Details, License Info and Notes split into panels, only visible to certain users via menu
///
public string ActivePanel
{
get
{
if (ViewState["activePanel"] == null)
return "mycompanydetails";
else
return ViewState["activePanel"].ToString();
}
set
{
ViewState["activePanel"] = value;
}
}
#endregion
#region methods
public void ReloadControl()
{
TogglePanels(this.ActivePanel);
}
///
/// Bind Versions
///
private void BindVersions()
{
try
{
ArrayList versions = xData.GetTypedByCriteriaSpecific("recId", typeof(oRelease), "isAvailable", "1", "versionNo DESC", "pal_", true);
ddVersions.DataSource = versions;
ddVersions.DataTextField = "versionNo";
ddVersions.DataValueField = "versionNo";
ddVersions.DataBind();
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// Bind Themes
///
private void BindThemes()
{
try
{
ddlThemes.DataSource = Enum.GetNames(typeof(pNums.Theme));
ddlThemes.DataBind();
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// Populate Form Values
///
///
private void PopulatePageFormValues(ref oSetup _Setup)
{
try
{
txtTradingAs.Value = _Setup.tradingAs;
txtCustomer.Value = _Setup.customer;
txtPrimaryPerson.Value = _Setup.primaryPerson;
txtTel.Value = _Setup.tel;
txtEmail.Value = _Setup.email;
txtCommunicationEmail.Value = _Setup.communicationEmail;
txtSendingEmailName.Value = _Setup.sendingEmailName;
txtLicensedDate.Value = _Setup.licenceDate.ToString("yyyy-MM-dd");
txtVersion.Value = _Setup.versionNo;
txtversionDate.Value = _Setup.versionDate.ToString("yyyy-MM-dd");
txtMobileNumber.Value = _Setup.contactMobile;
rcbBusinessType.SelectedIndex = 0;
if (rcbBusinessType.Items.FindItemByValue(_Setup.typeOfBusiness) != null)
{
rcbBusinessType.SelectedValue = _Setup.typeOfBusiness;
txtBusinessTypeOther.Enabled = false;
reqBusinessTypeOther.Enabled = false;
}
else if (rcbBusinessType.Items.FindItemByValue("Other") != null)
{
rcbBusinessType.SelectedValue = "Other";
txtBusinessTypeOther.Text = _Setup.typeOfBusiness;
txtBusinessTypeOther.Enabled = true;
reqBusinessTypeOther.Enabled = true;
}
ddlCountries.SelectedIndex = 0;
if (ddlCountries.Items.FindByValue(_Setup.country) != null)
ddlCountries.SelectedValue = _Setup.country;
ddlThemes.SelectedIndex = 0;
if (ddlThemes.Items.FindByValue(_Setup.theme) != null)
ddlThemes.SelectedValue = _Setup.theme;
txtCountryCode.Value = _Setup.countryCode;
ddlTimeZone.SelectedIndex = 0;
if (ddlTimeZone.Items.FindByValue(_Setup.gmtTimeZone) != null)
ddlTimeZone.SelectedValue = _Setup.gmtTimeZone;
txtStreetName_Postal.Value = _Setup.postalStreet;
txtSuburbName_Postal.Value = _Setup.postalSuburb;
txtCity_Postal.Value = _Setup.postalCity;
txtProvinceState_Postal.Value = _Setup.postalProvinceState;
txtCountry_Postal.Value = _Setup.postalCountry;
txtPostalCode_Postal.Value = _Setup.postalCode;
if (_Setup.vatRegistered)
rbVatRegistered.SelectedIndex = 0; // yes
else
rbVatRegistered.SelectedIndex = 1; // no
txtVatRegNumber.Value = _Setup.vatRegistrationNumber;
txtVatRate.Value = _Setup.vatRate.ToString("N2");
ddlFinancialYearEnd.SelectedIndex = 0;
if (ddlFinancialYearEnd.Items.FindByValue(_Setup.financialYearEnd) != null)
ddlFinancialYearEnd.SelectedValue = _Setup.financialYearEnd;
ddlVatPeriodStartMonth.SelectedIndex = 0;
if (ddlVatPeriodStartMonth.Items.FindByValue(_Setup.vatPeriodStartMonth) != null)
ddlVatPeriodStartMonth.SelectedValue = _Setup.vatPeriodStartMonth;
txtStreetName_Physical.Value = _Setup.physicalStreet;
txtSuburbName_Physical.Value = _Setup.physicalSuburb;
txtCityName_Physical.Value = _Setup.physicalCity;
txtProvinceState_Physical.Value = _Setup.physicalProvinceState;
txtCountry_Physical.Value = _Setup.physicalCountry;
txtPostalCode_Physical.Value = _Setup.physicalCode;
//GR site configuration
chkIsWebsite.Checked = _Setup.isWebsite;
chkHideFooter.Checked = _Setup.hideFooter;
chkAllowBillingCopy.Checked = _Setup.billingAllowCopy;
chkLoyalty.Checked = _Setup.isLoyalty;
chkIsGoogleSignIn.Checked = _Setup.isGoogleSignIn;
chkIsMediswitch.Checked = _Setup.isMediswitch;
chkIsTransactionLock.Checked = _Setup.isTransactionLock;
txtTransactionLockDay.Text = _Setup.transactionLockDay.ToString();
//if (_Setup.securePath != string.Empty)
txtSecurePath.Value = _Setup.securePath;
//else
// txtSecurePath.Value = "https://" + _Setup.code.ToLower() + ".evolvemybusiness.com";
//GR Sales values
/* CVH 2016-09-14 Add number length and preview */
txtQTEPrefix.Text = _Setup.saleQTEPrefix;
txtQTENext.Text = _Setup.saleQTENextNum.ToString();
//CVH Don't set object value now, just textbox, when updating, need to set it to 1 and know that it is update (to check existing numbers in database)
if (_Setup.saleQTENextNum <= 0)
txtQTENext.Text = "1";
txtQTELength.Text = _Setup.saleQTENumLength.ToString();
txtQTEPreview.Value = xSales.BuildNextTransactionNumber(_Setup.saleQTEPrefix, _Setup.saleQTENumLength, _Setup.saleQTENextNum);
txtINVPrefix.Text = _Setup.saleINVPrefix;
txtINVNext.Text = _Setup.saleINVNextNum.ToString();
if (_Setup.saleINVNextNum <= 0)
txtINVNext.Text = "1";
txtINVLength.Text = _Setup.saleINVNumLength.ToString();
txtINVPreview.Value = xSales.BuildNextTransactionNumber(_Setup.saleINVPrefix, _Setup.saleINVNumLength, _Setup.saleINVNextNum);
txtRCTPrefix.Text = _Setup.saleRCTPrefix;
txtRCTNext.Text = _Setup.saleRCTNextNum.ToString();
if (_Setup.saleRCTNextNum <= 0)
txtRCTNext.Text = "1";
txtRCTLength.Text = _Setup.saleRCTNumLength.ToString();
txtRCTPreview.Value = xSales.BuildNextTransactionNumber(_Setup.saleRCTPrefix, _Setup.saleRCTNumLength, _Setup.saleRCTNextNum);
txtCRNPrefix.Text = _Setup.saleCRNPrefix;
txtCRNNext.Text = _Setup.saleCRNNextNum.ToString();
if (_Setup.saleCRNNextNum <= 0)
txtCRNNext.Text = "1";
txtCRNLength.Text = _Setup.saleCRNNumLength.ToString();
txtCRNPreview.Value = xSales.BuildNextTransactionNumber(_Setup.saleCRNPrefix, _Setup.saleCRNNumLength, _Setup.saleCRNNextNum);
if (_Setup.logoUploaded != String.Empty)
{
lblCurrentGallery.Text = _Setup.logoUploaded.Replace(" ", "");
//populate preview
imgGalleryPreview.Visible = true;
imgGalleryPreview.Width = 350;
imgGalleryPreview.ImageUrl = "~/upload/image/" + _Setup.logoUploaded;
}
else
{
imgGalleryPreview.Visible = false;
lblCurrentGallery.Text = "Current: none";
}
//get latest version no from service
foreach (oRelease ver in xData.GetTypedByCriteriaSpecific("recId", typeof(oRelease), "isAvailable", "1", "versionNo DESC", "pal_", true))
{
txtLatestVersion.Value = ver.versionNo.ToString();
ddVersions.SelectedValue = ver.versionNo.ToString();
break;
}
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("/error", false);
}
}
private string ValidateTransactionNumbers()
{
try
{
string error = "";
//if number has been changed, get next number from company setup in database
//(it is updated with each transaction save) and verify that new number is greater than current number
//get up to date setup from database, not utils method
//get saved db setup (updated from sales)
oSetup currSetup = new oSetup();
ArrayList list = xData.GetTypedCollection("recId", typeof(oSetup), "recId DESC");
if (list != null && list.Count > 0)
currSetup = (oSetup)list[0];
//get numbers to save
int qte = 0, inv = 0, rct = 0, crn = 0;
int.TryParse(txtQTENext.Text, out qte);
int.TryParse(txtINVNext.Text, out inv);
int.TryParse(txtRCTNext.Text, out rct);
int.TryParse(txtCRNNext.Text, out crn);
if (qte <= 0)
qte = 1;
if (inv <= 0)
inv = 1;
if (rct <= 0)
rct = 1;
if (crn <= 0)
crn = 1;
if (qte != 0 && qte != 1 && currSetup.saleQTENextNum > qte)
{
error += "Next Quote Number must be creater than highest quote number saved in the system. ";
txtQTENext.Text = currSetup.saleQTENextNum.ToString();
}
if (inv != 0 && inv != 1 && currSetup.saleINVNextNum > inv)
{
error += "Next Invoice Number must be creater than highest invoice number saved in the system. ";
txtINVNext.Text = currSetup.saleINVNextNum.ToString();
}
if (rct != 0 && rct != 1 && currSetup.saleRCTNextNum > rct)
{
error += "Next Receipt Number must be creater than highest receipt number saved in the system. ";
txtRCTNext.Text = currSetup.saleRCTNextNum.ToString();
}
if (crn != 0 && crn != 1 && currSetup.saleCRNNextNum > crn)
{
error += "Next Credit Note Number must be creater than highest credit note number saved in the system. ";
txtCRNNext.Text = currSetup.saleCRNNextNum.ToString();
}
return error;
}
catch (Exception ex)
{
return ex.Message;
}
}
///
/// Save Form Values
///
///
private void SavePageFormValues(ref oSetup _Setup)
{
try
{
_Setup.tradingAs = txtTradingAs.Value;
_Setup.primaryPerson = txtPrimaryPerson.Value;
_Setup.email = txtEmail.Value;
_Setup.communicationEmail = txtCommunicationEmail.Value;
_Setup.sendingEmailName = txtSendingEmailName.Value;
_Setup.tel = txtTel.Value;
_Setup.dateUpdated = DateTime.Now;
_Setup.contactMobile = txtMobileNumber.Value;
if (rcbBusinessType.SelectedValue != null && rcbBusinessType.SelectedValue == "Other")
_Setup.typeOfBusiness = txtBusinessTypeOther.Text;
else if (rcbBusinessType.SelectedItem != null)
_Setup.typeOfBusiness = rcbBusinessType.SelectedItem.Text;
_Setup.country = ddlCountries.SelectedItem.Text; // ddlCountries.SelectedIndex.ToString(); //
_Setup.countryCode = txtCountryCode.Value;
_Setup.gmtTimeZone = ddlTimeZone.SelectedItem.Text; // ddlTimeZone.SelectedIndex.ToString(); //
if (_Setup.gmtTimeZone == "none selected")
_Setup.gmtTimeZone = "(GMT+02:00) Harare, Pretoria";
_Setup.postalStreet = txtStreetName_Postal.Value;
_Setup.postalSuburb = txtSuburbName_Postal.Value;
_Setup.postalCity = txtCity_Postal.Value;
_Setup.postalProvinceState = txtProvinceState_Postal.Value;
_Setup.postalCountry = txtCountry_Postal.Value;
/* CVH 2016-08-15 Default to South Africa when blank */
if (_Setup.postalCountry == String.Empty)
_Setup.postalCountry = "South Africa";
_Setup.postalCode = txtPostalCode_Postal.Value;
_Setup.theme = ddlThemes.SelectedItem.Text;
bool blnVatReg = false;
if (rbVatRegistered.SelectedIndex == 0) { blnVatReg = true; }
_Setup.vatRegistered = blnVatReg; // rbVatRegistered.SelectedItem.Value; // Check yes/no value
_Setup.vatRegistrationNumber = txtVatRegNumber.Value;
_Setup.vatRate = Convert.ToDecimal(txtVatRate.Value);
_Setup.financialYearEnd = ddlFinancialYearEnd.SelectedItem.Text; // ddlFinancialYearEnd.SelectedIndex.ToString(); //
_Setup.vatPeriodStartMonth = ddlVatPeriodStartMonth.SelectedItem.Text; // ddlVatPeriodStartMonth.SelectedIndex.ToString(); //
_Setup.physicalStreet = txtStreetName_Physical.Value;
_Setup.physicalSuburb = txtSuburbName_Physical.Value;
_Setup.physicalCity = txtCityName_Physical.Value;
_Setup.physicalProvinceState = txtProvinceState_Physical.Value;
_Setup.physicalCountry = txtCountry_Physical.Value;
/* CVH 2016-08-15 Default to South Africa when blank */
if (_Setup.physicalCountry == String.Empty)
_Setup.physicalCountry = "South Africa";
_Setup.physicalCode = txtPostalCode_Physical.Value;
//GR site configuration
_Setup.isWebsite = chkIsWebsite.Checked;
_Setup.hideFooter = chkHideFooter.Checked;
_Setup.billingAllowCopy = chkAllowBillingCopy.Checked;
_Setup.isLoyalty = chkLoyalty.Checked;
_Setup.isGoogleSignIn = chkIsGoogleSignIn.Checked;
_Setup.isMediswitch = chkIsMediswitch.Checked;
_Setup.isTransactionLock = chkIsTransactionLock.Checked;
_Setup.transactionLockDay = Convert.ToInt32(txtTransactionLockDay.Text);
_Setup.securePath = txtSecurePath.Value;
//GR 2016-09-07 Sales values for prefixes and starting numbers
/* CVH 2016-09-14 Add length */
_Setup.saleQTEPrefix = txtQTEPrefix.Text;
int QTEStartNum = 0;
int.TryParse(txtQTENext.Text, out QTEStartNum);
_Setup.saleQTENextNum = QTEStartNum;
int QTENumLength = 0;
int.TryParse(txtQTELength.Text, out QTENumLength);
_Setup.saleQTENumLength = QTENumLength;
_Setup.saleINVPrefix = txtINVPrefix.Text;
int INVStartNum = 0;
int.TryParse(txtINVNext.Text, out INVStartNum);
_Setup.saleINVNextNum = INVStartNum;
int INVNumLength = 0;
int.TryParse(txtINVLength.Text, out INVNumLength);
_Setup.saleINVNumLength = INVNumLength;
_Setup.saleRCTPrefix = txtRCTPrefix.Text;
int RCTStartNum = 0;
int.TryParse(txtRCTNext.Text, out RCTStartNum);
_Setup.saleRCTNextNum = RCTStartNum;
int RCTNumLength = 0;
int.TryParse(txtRCTLength.Text, out RCTNumLength);
_Setup.saleRCTNumLength = RCTNumLength;
_Setup.saleCRNPrefix = txtCRNPrefix.Text;
int CRNStartNum = 0;
int.TryParse(txtCRNNext.Text, out CRNStartNum);
_Setup.saleCRNNextNum = CRNStartNum;
int CRNNumLength = 0;
int.TryParse(txtCRNLength.Text, out CRNNumLength);
_Setup.saleCRNNumLength = CRNNumLength;
UploadFiles(ref _Setup);
/*
if (fuGallery.FileContent.Length > 0)
{
_Setup.logoUploaded = utils.RandomString(9, true) + fuGallery.FileName.Substring(fuGallery.FileName.IndexOf("."));
//upload file
string uploadPath = Server.MapPath("~/upload/image/");
utils.validateFolder(Server.MapPath(uploadPath));
string destDir = Server.MapPath(uploadPath);
//upload file
fuGallery.SaveAs(destDir + _Setup.logoUploaded);
}
else
_Setup.logoUploaded = lblCurrentGallery.Text;
*/
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("/error", false);
}
}
private void SaveNoteFormValues(ref oSetup _setup)
{
try
{
if (ddEmailNotes.SelectedItem != null && ddEmailNotes.SelectedValue != "0")
{
switch (ddEmailNotes.SelectedItem.Text)
{
case "Quote":
_setup.notesQuotes = edNote.Content;
break;
case "Invoice":
_setup.notesInvoices = edNote.Content;
break;
case "Receipt":
_setup.notesReceipts = edNote.Content;
break;
case "Credit Note":
_setup.notesCreditNotes = edNote.Content;
break;
case "Statement":
_setup.notesStatements = edNote.Content;
break;
}
}
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("/error", false);
}
}
private void TogglePanels(string panelName)
{
switch (panelName)
{
case "mycompanydetails":
lblSetupHeader.Text = "Company Details";
pnlMyCompanySetup.Visible = true;
pnlLicenseInfo.Visible = false;
pnlNotes.Visible = false;
pnlEmailTemplates.Visible = false;
break;
case "licenseinformation":
lblSetupHeader.Text = "License Information";
pnlMyCompanySetup.Visible = false;
pnlLicenseInfo.Visible = true;
pnlNotes.Visible = false;
pnlEmailTemplates.Visible = false;
break;
case "notes":
lblSetupHeader.Text = "Notes";
pnlMyCompanySetup.Visible = false;
pnlLicenseInfo.Visible = false;
pnlNotes.Visible = true;
pnlEmailTemplates.Visible = false;
break;
case "emailtemplates":
lblSetupHeader.Text = "Email Templates";
pnlMyCompanySetup.Visible = false;
pnlLicenseInfo.Visible = false;
pnlNotes.Visible = false;
pnlEmailTemplates.Visible = true;
break;
}
//clear result
pnlResult.Visible = false;
}
///
/// Bas-Pro-16 - Toggle the visibility of the VAT Registration Field based on the radio button selection
///
private void ToggleVatRegistrationField()
{
// bool blnVatRegistered = false;
// if (rbVatRegistered.SelectedIndex == 0)
//blnVatRegistered = true;
//txtVatRegNumber.Style.Add("key", "value"); //.Enabled = blnVatRegistered;
//lblVatRegNumber.Visible = blnVatRegistered;
}
///
/// Bas-Pro-59 - Add Business Types pick list
///
private void LoadBusinessTypes()
{
rcbBusinessType.Items.Clear();
oBusinessType _businessType = new oBusinessType();
DataTable dt = xData.GetDynamicByCriteriaSpecific("recId", typeof(oBusinessType), "isActive", "1", "sequence");
rcbBusinessType.DataSource = dt;
rcbBusinessType.DataTextField = "businessType";
rcbBusinessType.DataValueField = "businessType";
rcbBusinessType.DataBind();
rcbBusinessType.Items.Insert(0, new RadComboBoxItem("none selected", "0"));
rcbBusinessType.Items.Add(new RadComboBoxItem("Other (Specify)", "Other"));
}
private void LoadBanks()
{
ddlBank.Items.Clear();
ddlBank.Items.Add("none selected");
oBank _bank = new oBank();
foreach (oBank item in xData.GetTypedByCriteriaSpecific("recId", typeof(oBank), "", ""))
{
ListItem lstItem = new ListItem();
lstItem.Text = item.BankName;
lstItem.Value = item.BankName;
ddlBank.Items.Add(lstItem);
}
}
///
/// Bas-Pro-60 - Get Countries via Web Service
///
private void GetCountriesViaWebService()
{
try
{
//JR check config to see if webservice to be used
if (ConfigurationManager.AppSettings["getCountriesFromWebService"] != null &&
ConfigurationManager.AppSettings["getCountriesFromWebService"] == "1")
{
if (ConfigurationManager.AppSettings["CountryNameWebService"] != null)
{
var url = ConfigurationManager.AppSettings["CountryNameWebService"]; // Use webservicex.net web service
var webRequest = (HttpWebRequest)System.Net.WebRequest.Create(url);
using (var response = webRequest.GetResponse())
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
var result = reader.ReadToEnd();
XmlDocument x = new XmlDocument();
x.LoadXml(result);
utils.validateFolder(Server.MapPath("~/upload/data/"));
utils.ConvertStringtoHTMLFile(x.InnerText, Server.MapPath("~/upload/data/countries.xml"));
DataSet ds = utils.ConvertXMLToDataSet(Server.MapPath("~/upload/data/"), "countries.xml");
int iValue = -1;
#region Bind ddlCountries Combobox
ddlCountries.Items.Clear(); // Dem-Pro-14 - Dirk Strauss - 8 Aug 2016 - (Comment: Hide Country - Default to South Africa)
foreach (DataRow row in ds.Tables[0].Rows)
{
if (row[0].ToString().Equals("South Africa")) // Dem-Pro-14 - Dirk Strauss - 8 Aug 2016 - (Comment: Hide Country - Default to South Africa)
{
iValue += 1; // might need the value
ListItem lstItem = new ListItem();
lstItem.Text = row[0].ToString();
lstItem.Value = row[0].ToString();
ddlCountries.Items.Add(lstItem);
}
}
#endregion
ddlCountries.Enabled = false;
}
}
}
}
else
{
ddlCountries.Items.Clear();
ddlCountries.Items.Add(new ListItem("South Africa"));
ddlCountries.Enabled = false;
}
}
catch (Exception ex)
{
exception.HandleException("Releases:", MethodBase.GetCurrentMethod().Name, ex, Session["release"]);
//Response.Redirect("/error", false);
}
}
///
/// Bas-Pro-61 - Dirk Strauss - 20 July 2016 - (Comment: Get the currency code by country selected)
/// Bas-Pro-62 - Dirk Strauss - 20 July 2016 - (Comment: Get the country code by country selected)
///
private void GetCountryDetailsByCountrySelected(string countrySelected)
{
try
{
//JR check config to see if webservice to be used
if (ConfigurationManager.AppSettings["getCountriesFromWebService"] != null &&
ConfigurationManager.AppSettings["getCountriesFromWebService"] == "1")
{
var url = ConfigurationManager.AppSettings["CountryDetailsWebService"] + String.Format("?CountryName={0}", countrySelected); // Use webservicex.net web service
string workingFolder = "~/upload/data/";
string fileName = "countrydetails.xml";
DataSet ds = CallWebService(url, workingFolder, fileName);
if (utils.ValidateDataSet(ds, 0))
{
txtCountryCode.Value = "+27"; //ds.Tables["Table"].Rows[0]["code"].ToString();
txtCurrencyCode.Value = ds.Tables["Table"].Rows[0]["CurrencyCode"].ToString();
}
//GetCountryTimeZoneByCountrySelected(countrySelected);
//txtCountryCode.Attributes.Add("readonly", "readonly");
}
}
catch (Exception ex)
{
exception.HandleException("Releases:", MethodBase.GetCurrentMethod().Name, ex, Session["release"]);
//Response.Redirect("/error", false);
}
}
///
/// Bas-Pro-63 - Dirk Strauss - 20 July 2016 - (Comment: Get the Time Zone from the country selected)
///
///
private void GetCountryTimeZoneByCountrySelected()
{
try
{
var timezoneList = utils.TimeZones();
foreach (var element in timezoneList)
{
ListItem lstItem = new ListItem();
lstItem.Text = element.Value;
lstItem.Value = element.Value;
ddlTimeZone.Items.Add(lstItem);
}
/* CVH 2016-08-12 Default to South Africa */
if (ddlTimeZone.Items.FindByValue("(GMT+02:00) Harare, Pretoria") != null)
ddlTimeZone.Items.FindByValue("(GMT+02:00) Harare, Pretoria").Selected = true;
// Dem-Pro-14 - Dirk Strauss - 8 Aug 2016 - (Comment: Hide Country - Default to South Africa)
// Because Country defaults to South Africa, the time will default to GMT+2 Harare, Pretoria
// Just set Enabled to False
ddlTimeZone.Enabled = false;
}
catch (Exception ex)
{
exception.HandleException("Releases:", MethodBase.GetCurrentMethod().Name, ex, Session["release"]);
//Response.Redirect("/error", false);
}
}
private void BindUnboundDropdowns()
{
ddlFinancialYearEnd.Items.Add("none selected");
ddlFinancialYearEnd.Items.Add("January");
ddlFinancialYearEnd.Items.Add("February");
ddlFinancialYearEnd.Items.Add("March");
ddlFinancialYearEnd.Items.Add("April");
ddlFinancialYearEnd.Items.Add("May");
ddlFinancialYearEnd.Items.Add("June");
ddlFinancialYearEnd.Items.Add("July");
ddlFinancialYearEnd.Items.Add("August");
ddlFinancialYearEnd.Items.Add("September");
ddlFinancialYearEnd.Items.Add("October");
ddlFinancialYearEnd.Items.Add("November");
ddlFinancialYearEnd.Items.Add("December");
ddlVatPeriodStartMonth.Items.Add("none selected");
ddlVatPeriodStartMonth.Items.Add("January");
ddlVatPeriodStartMonth.Items.Add("February");
ddlVatPeriodStartMonth.Items.Add("March");
ddlVatPeriodStartMonth.Items.Add("April");
ddlVatPeriodStartMonth.Items.Add("May");
ddlVatPeriodStartMonth.Items.Add("June");
ddlVatPeriodStartMonth.Items.Add("July");
ddlVatPeriodStartMonth.Items.Add("August");
ddlVatPeriodStartMonth.Items.Add("September");
ddlVatPeriodStartMonth.Items.Add("October");
ddlVatPeriodStartMonth.Items.Add("November");
ddlVatPeriodStartMonth.Items.Add("December");
}
///
/// Call various web services from www.webservicex.net
///
/// The Web Service URL
/// Theworking folder to create the XML file in
/// The XML file name that contains the Web Service data
/// The data ina Data Set from the Web Services at http://www.webservicex.net
private DataSet CallWebService(string url, string workingFolder, string xmlFileName)
{
DataSet dsReturn = new DataSet();
try
{
var webRequest = (HttpWebRequest)System.Net.WebRequest.Create(url);
using (var response = webRequest.GetResponse())
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
var result = reader.ReadToEnd();
XmlDocument x = new XmlDocument();
x.LoadXml(result);
utils.validateFolder(Server.MapPath(workingFolder));
utils.ConvertStringtoHTMLFile(x.InnerText, Server.MapPath(workingFolder + xmlFileName));
dsReturn = utils.ConvertXMLToDataSet(Server.MapPath(workingFolder), xmlFileName);
}
}
}
catch (Exception ex)
{
exception.HandleException("Releases:", MethodBase.GetCurrentMethod().Name, ex, Session["release"]);
//Response.Redirect("/error", false);
}
return dsReturn;
}
private void UploadFiles(ref oSetup _Setup) // int recId, bool isUpdate = false
{
/*
_Setup.logoUploaded = utils.RandomString(9, true) + fuGallery.FileName.Substring(fuGallery.FileName.IndexOf("."));
//upload file
string uploadPath = Server.MapPath("~/upload/image/");
utils.validateFolder(Server.MapPath(uploadPath));
string destDir = Server.MapPath(uploadPath);
//upload file
fuGallery.SaveAs(destDir + _Setup.logoUploaded);
*/
try
{
if (radImageUpload.UploadedFiles.Count > 0)
{
foreach (UploadedFile file in radImageUpload.UploadedFiles)
{
//oPromotionFile promotionFile = new oPromotionFile();
//promotionFile.fileName = file.FileName.Replace(" ", "");
//promotionFile.promotionId = recId;
//promotionFile.isActive = true;
_Setup.logoUploaded = utils.RandomString(9, true) + file.FileName.Substring(file.FileName.IndexOf("."));
string fileName = _Setup.logoUploaded;
string uploadPath = Server.MapPath("~/upload/image/");
//upload file
//string tempPath = Server.MapPath("upload/temp/") + promotionFile.fileName;
//string destDir = Server.MapPath("upload/promotion/" + recId.ToString() + "/");
//utils.validateFolder(Server.MapPath("upload/temp/"));
utils.validateFolder(uploadPath);
//upload file
//promotionFile.path = recId.ToString() + "/" + promotionFile.fileName;
file.SaveAs(uploadPath + fileName);
//resize the file
//utils.ResizeImageMaxWidth(tempPath, destDir, promotionFile.fileName, true, true, 800);
//foreach (oPromotionFile existingFile in xData.GetTypedByCriteriaSpecific("recId", typeof(oPromotionFile), "promotionId,fileName", recId.ToString() + "," + promotionFile.fileName))
//{
// promotionFile.recId = existingFile.recId;
//}
//if (promotionFile.recId > 0)
// xData.UpdateTyped("recId", promotionFile.recId.ToString(), typeof(oPromotionFile), promotionFile);
//else
// xData.SaveTyped("recId", typeof(oPromotionFile), promotionFile);
}
}
}
catch (Exception ex)
{
exception.HandleException("Promotions:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
public void RemoveEditorButtons(RadEditor editor)
{
editor.EnsureToolsFileLoaded();
string buttonsToRemove = "Print,SelectAll,Cut,Copy,Paste,ImageManager,DocumentManager,FlashManager,MediaManager,TemplateManager,LinkManager,Unlink,Superscript,Subscript,InsertGroupbox,InsertHorizontalRule,InsertDate,InsertTime,FormatCodeBlock,AbsolutePosition,InsertFormElement,InsertSnippet,ImageMapDialog,InsertCustomLink,ConvertToLower,ConvertToUpper,ModuleManager,ToggleScreenMode,AboutDialog,AjaxSpellCheck,FindAndReplace,PasteStrip,Undo,Redo,InsertParagraph,FormatBlock,StrikeThrough,JustifyLeft,JustifyCenter,JustifyRight,JustifyFull,JustifyNone,Indent,Outdent,InsertUnorderedList,InsertOrderedList,ToggleTableBorder,XhtmlValidator,ForeColor,BackColor,ApplyClass,FormatCodeBlock,InsertSymbol,InsertTable,Zoom,FormatStripper";
string[] buttons = buttonsToRemove.Split(char.Parse(","));
foreach (string name in buttons)
{
foreach (Telerik.Web.UI.EditorToolGroup group in editor.Tools)
{
Telerik.Web.UI.EditorTool tool = group.FindTool(name);
if (tool != null)
{
group.Tools.Remove(tool);
}
}
}
}
#endregion
#region events
///
/// Page Load Event
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (utils.verifySession("user"))
{
oUser admin = (oUser)Session["user"];
if (!Page.IsPostBack)
{
/* CVH 2016-08-30 Only visible buttons on notes RadEditors: Bold,Underline,Italic,Font Type,Font Size */
RemoveEditorButtons(edNote);
BindVersions();
BindThemes();
oSetup _setup = handler.ReturnSetup(true);
// BAS-Pro-16 - Dirk Strauss - 19 July 2016 - (Comment: Default the VAT Selection)
rbVatRegistered.SelectedIndex = 1;
ToggleVatRegistrationField();
// Bas-Pro-59 - Dirk Strauss - 20 July 2016 - (Comment: Type of Business Picklist to be added)
LoadBusinessTypes();
// Bas-Pro-60 - Dirk Strauss - 20 July 2016 - (Comment: Get Countries by Web Service)
GetCountriesViaWebService();
// Bind Time Zones
GetCountryTimeZoneByCountrySelected();
BindUnboundDropdowns();
// Bind banks
LoadBanks();
/* CVH 2016-08-11 */
TogglePanels(this.ActivePanel);
PopulatePageFormValues(ref _setup);
// Dem-Pro-14 - Dirk Strauss - 8 Aug 2016 - Move this to here to override any previously set Country Code values. This must default to South Africa.
GetCountryDetailsByCountrySelected(ddlCountries.SelectedItem.Text);
Session["Setup"] = _setup;
if (_setup.code == "EVOL-1" && admin.isSetup)
{
//verify code and license key
oLicence lic = licenceHandler.GetLicence(_setup.licenceKey);
if (lic.customerCode == _setup.code)
{ btnCustomers.Visible = true; lnkReleases.Visible = true; }
else
{ btnCustomers.Visible = false; lnkReleases.Visible = false; }
//GR enabled for update on Evol-1 but ONLY scripts get applied
//if (Debugger.IsAttached)
//{
// btnGetVersion.Enabled = false;
// btnGetVersion.CssClass = "btn btn-default";
//}
}
else
{ btnCustomers.Visible = false; lnkReleases.Visible = false; }
}
}
else
{ Response.Redirect("/admin", false); }
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// Customers button
///
///
///
protected void btnCustomers_Click(object sender, EventArgs e)
{
try
{
//go to customers area
Response.Redirect("/Admin_Customers.aspx", false);
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// Go to releases page
///
///
///
protected void lnkReleases_Click(object sender, EventArgs e)
{
try
{
//go to releases area
Response.Redirect("/Admin_Releases.aspx", false);
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// Save Click
///
///
///
protected void btnSave_Click(object sender, EventArgs e)
{
oSetup Setup = new oSetup();
try
{
if (utils.verifySession("Setup"))//update mode
{
Setup = (oSetup)Session["Setup"];
//validate type of business
if (rcbBusinessType.SelectedItem == null)
{
pnlResult.Visible = true;
lblResult.Text = "Invalid: Type of business";
return;
}
/* CVH 2016-09-13 Validate communication email, this will be used as from email address */
if (!utils.validateEmail(txtCommunicationEmail.Value))
{
pnlResult.Visible = true;
lblResult.Text = "Invalid: Communication Email";
return;
}
/* CVH 2016-09-14 Validate next numbers */
string numbersValidation = ValidateTransactionNumbers();
if (numbersValidation != String.Empty)
{
pnlResult.Visible = true;
lblResult.Text = numbersValidation;
return;
}
//save form values
SavePageFormValues(ref Setup);
if (xData.UpdateTyped("recId", Setup.recId.ToString(), typeof(oSetup), Setup))
{
Session["Setup"] = Setup;
Session["osetup"] = Setup;
//updated customer details on service
ArrayList customers = xData.GetTypedByCriteriaSpecific("recId", typeof(oCustomer), "code,licenceKey,isActive", Setup.code + "," + Setup.licenceKey + ",1", "code", "pal_", true);
foreach (oCustomer cust in customers)
{
cust.primaryPerson = Setup.primaryPerson;
cust.email = Setup.email;
cust.communicationEmail = Setup.communicationEmail;
cust.sendingEmailName = Setup.sendingEmailName;
cust.tradingAs = Setup.tradingAs;
cust.tel = Setup.tel;
cust.dateUpdated = DateTime.Now;
/* CVH 2016-09-13 Get Customer details from Setup object, not textboxes */
cust.contactMobile = Setup.contactMobile;
cust.typeOfBusiness = Setup.typeOfBusiness;
cust.country = Setup.country;
cust.countryCode = Setup.countryCode;
cust.gmtTimeZone = Setup.gmtTimeZone;
cust.postalStreet = Setup.postalStreet;
cust.postalSuburb = Setup.postalSuburb;
cust.postalCity = Setup.postalCity;
cust.postalCode = Setup.postalCode;
cust.postalProvinceState = Setup.postalProvinceState;
cust.postalCountry = Setup.postalCountry;
cust.vatRegistered = Setup.vatRegistered;
cust.vatRegistrationNumber = Setup.vatRegistrationNumber;
cust.vatRate = Setup.vatRate;
cust.financialYearEnd = Setup.financialYearEnd;
cust.vatPeriodStartMonth = Setup.vatPeriodStartMonth;
cust.physicalStreet = Setup.physicalStreet;
cust.physicalSuburb = Setup.physicalSuburb;
cust.physicalCity = Setup.physicalCity;
cust.physicalCode = Setup.physicalCode;
cust.physicalProvinceState = Setup.physicalProvinceState;
cust.physicalCountry = Setup.physicalCountry;
cust.logoUploaded = Setup.logoUploaded;
xData.UpdateTyped("recId", cust.recId.ToString(), typeof(oCustomer), cust, "pal_", true);
}
pnlResult.Visible = true;
lblResult.Text = "your changes were updated successfully.";
}
}
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// Save Notes
///
///
///
protected void btnSaveNotes_Click(object sender, EventArgs e)
{
oSetup Setup = new oSetup();
try
{
if (utils.verifySession("Setup"))//update mode
{
Setup = (oSetup)Session["Setup"];
//save form values
SaveNoteFormValues(ref Setup);
if (xData.UpdateTyped("recId", Setup.recId.ToString(), typeof(oSetup), Setup))
{
pnlResult.Visible = true;
lblResult.Text = "your changes were updated successfully.";
}
}
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
protected void btnSaveEmailTemplates_Click(object sender, EventArgs e)
{
try
{
if (ddEmailTemplate.SelectedItem != null && ddEmailTemplate.SelectedValue != "0")
{
//Save email template
ArrayList templates = xData.GetTypedByCriteriaSpecific("recId", typeof(oTemplate), "templateName", "Sales " + ddEmailTemplate.SelectedItem.Text + " E-mail Template");
oTemplate template = new oTemplate();
if (templates == null || templates.Count <= 0)
{
template.templateName = "Sales Quote E-mail Template";
template.templateTypeId = pNums.TemplateType.OutboundResponse.GetHashCode();
template.templateContent = edEmailTemplate.Content;
template.recId = xData.SaveTyped("recId", typeof(oTemplate), template);
}
else
{
template = (oTemplate)templates[0];
template.templateContent = edEmailTemplate.Content;
xData.UpdateTyped("recId", template.recId.ToString(), typeof(oTemplate), template);
}
//save email subject
if (utils.verifySession("Setup"))
{
oSetup Setup = (oSetup)Session["Setup"];
switch (ddEmailTemplate.SelectedItem.Text)
{
case "Quote":
Setup.emailSubjectQuote = txtEmailSubject.Text;
break;
case "Invoice":
Setup.emailSubjectInvoice = txtEmailSubject.Text;
break;
case "Receipt":
Setup.emailSubjectReceipt = txtEmailSubject.Text;
break;
case "Credit Note":
Setup.emailSubjectCreditNote = txtEmailSubject.Text;
break;
case "Statement":
Setup.emailSubjectStatement = txtEmailSubject.Text;
break;
}
if (xData.UpdateTyped("recId", Setup.recId.ToString(), typeof(oSetup), Setup))
{
}
}
pnlResult.Visible = true;
lblResult.Text = "your changes were updated successfully.";
}
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// Get Latest version
///
///
///
protected void btnGetVersion_Click(object sender, EventArgs e)
{
try
{
if (utils.verifySession("Setup"))
{
oSetup _setup = (oSetup)Session["Setup"];
//validate licence
if (licenceHandler.ValidateLicence(_setup.customer, _setup.licenceKey, _setup.licenceDate, _setup.code).successful)
{
//now validate customer
foreach (oCustomer cust in xData.GetTypedByCriteriaSpecific("recId", typeof(oCustomer), "code", _setup.code, "customer", "pal_", true))
{
if (cust.isActive)
{
Stream fs = new MemoryStream();
//we can upgrade customer is active and validated
string versionNo = ddVersions.SelectedValue;
utils.validateFolder(Server.MapPath("~/release/" + versionNo + "/"));
string releasePath = Server.MapPath("~/release/" + versionNo + "/");
//get scripts
byte[] scriptData = xData.GetVersion(_setup.code, _setup.licenceKey, versionNo, "scripts.zip");
//save zip to file
fs = new FileStream(releasePath + "scripts.zip", FileMode.Create, FileAccess.Write);
fs.Write(scriptData, 0, scriptData.Length);
fs.Close();
//extract scripts zip
FastZip fz = new FastZip();
fz.ExtractZip(releasePath + "scripts.zip", releasePath, "");
DirectoryInfo dir = new DirectoryInfo(releasePath);
//provision for failed scripts
bool scriptsSucceeded = true;
oEmail ScriptFailedEmail = new oEmail();
//get files
foreach (FileInfo file in dir.GetFiles("*.sql"))
{
string query = utils.ConvertHTMLFiletoString(file.FullName);
if (!xData.RunCustomQuery(query.Replace("GO", "")))
{
scriptsSucceeded = false;
ScriptFailedEmail.Attachments.Add(file.FullName);
return;
}
else
{
file.Delete();//remove successful script
}
}
if (scriptsSucceeded)//then get files and upgrade files and version number in setup table
{
if (!Debugger.IsAttached)//only apply files for client instances
{
//get files
byte[] fileData = xData.GetVersion(_setup.code, _setup.licenceKey, versionNo, "files.zip");
//save zip to file
fs = new FileStream(releasePath + "files.zip", FileMode.Create, FileAccess.Write);
fs.Write(fileData, 0, fileData.Length);
fs.Close();
//extract files
fz.ExtractZip(releasePath + "files.zip", Server.MapPath("~"), "");
}
//remove surface apps on upgrade
DirectoryInfo surfaceDir = new DirectoryInfo(Server.MapPath("~/controls/surface/"));
foreach (FileInfo app in surfaceDir.GetFiles())
{
if (app.Name.ToLower() != "surface.ascx" && app.Name != "surface.ascx.cs"
&& app.Name != "surface_grid.ascx" && app.Name != "surface_grid.ascx.cs"
&& app.Name != "surface_form.ascx" && app.Name != "surface_form.ascx.cs"
&& app.Name != "surface_view.ascx" && app.Name != "surface_view.ascx.cs")
{
app.Delete();
}
}
//update version number
_setup.versionNo = versionNo;
_setup.versionDate = DateTime.Now;
//update customer values too
cust.versionDate = _setup.versionDate;
cust.versionNo = _setup.versionNo;
if (xData.UpdateTyped("recId", _setup.recId.ToString(), typeof(oSetup), _setup))
{
//update customer on service
if (xData.UpdateTyped("recId", cust.recId.ToString(), typeof(oCustomer), cust, "pal_", true))
{
pnlResult.Visible = true;
lblResult.Text = "The upgrade was applied successfully.";
}
}
}
else
{
string failedBody = utils.ConvertHTMLFiletoString(Server.MapPath("~/templates/internal/UpgradeFailed.html"));
//merge values with customer setup object
utils.MergeHTMData(ref failedBody, utils.BuildFieldCodeList(_setup));
failedBody = failedBody.Replace("src=\"/images", "src=\"" + ConfigurationManager.AppSettings["WebAddy"] + "/images");
failedBody = failedBody.Replace("{WebAddress}", ConfigurationManager.AppSettings["WebAddy"]);
ScriptFailedEmail.Subject = "Upgrade Failed - Script Error " + ConfigurationManager.AppSettings["website"];
ScriptFailedEmail.toAddress = ConfigurationManager.AppSettings["support"];
ScriptFailedEmail.fromAddress = ConfigurationManager.AppSettings["from"];
ScriptFailedEmail.Body = failedBody;
//send failed script notification
communication.SendAnEmail(ScriptFailedEmail);
pnlResult.Visible = true;
lblResult.Text = "The upgrade was not successful, our team have been notified of this, we will be in touch promptly";
}
}
else
{
pnlResult.Visible = true;
lblResult.Text = "Your upgrade cannot be downloaded as your customer account is inactive, please contact our support desk for further assistance.";
}
}
}
else
{
//License not valid so cannot obtain upgrade
pnlResult.Visible = true;
lblResult.Text = "Your upgrade cannot be downloaded as your licence is not valid, please contact our support desk for further assistance.";
}
}
//TO do get latest version
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// View release notes
///
///
///
protected void btnReleaseNotes_Click(object sender, EventArgs e)
{
try
{
string versionNo = ddVersions.SelectedValue;
foreach (oRelease ver in xData.GetTypedByCriteriaSpecific("recId", typeof(oRelease), "isAvailable,versionNo", "1," + versionNo, "versionNo DESC", "pal_", true))
{
lblReleasNotesHeading.Text = "Version " + versionNo + " Released: " + ver.versionDate.ToString("yyyy-MM-dd");
lblReleaseNotes.Text = ver.ReleaseNotes;
upReleaseNotes.Update();
//show modal
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myReleaseNotes", "$('#modReleaseNotes').modal();", true);
}
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// Bas-Pro-13 - Allow the user to copy the Postal Address to the Physical Address
///
///
///
protected void btnSameAsPostal_Click(object sender, EventArgs e)
{
/*
Bas-Pro-13 - Dirk Strauss - 19 July 2016
*/
txtStreetName_Physical.Value = txtStreetName_Postal.Value;
txtSuburbName_Physical.Value = txtSuburbName_Postal.Value;
txtCityName_Physical.Value = txtCity_Postal.Value;
txtPostalCode_Physical.Value = txtPostalCode_Postal.Value;
txtProvinceState_Physical.Value = txtProvinceState_Postal.Value;
txtCountry_Physical.Value = txtCountry_Postal.Value;
}
///
/// Bas-Pro-16 - Change the visibility of the VAT Registration Number, based on the radio button selection
///
///
///
protected void rbVatRegistered_SelectedIndexChanged(object sender, EventArgs e)
{
ToggleVatRegistrationField();
}
///
/// Bas-Pro-17 - Dirk Strauss - 20 July 2016 - (Comment: Logo Upload)
///
///
///
//protected void radReleaseFileUpload_FileUploaded(object sender, Telerik.Web.UI.FileUploadedEventArgs e)
//{
// // ~/upload/image/
// try
// {
// //if (txtVersionNo.Value != String.Empty)
// //{
// //}
// string randomFileName = utils.RandomString(9, true) + e.File.FileName.Substring(e.File.FileName.LastIndexOf("."));
// string uploadPath = Server.MapPath("~/upload/image/");
// //validate the folder
// utils.validateFolder(uploadPath);
// //if (File.Exists(uploadPath + e.File.FileName))
// // File.Delete(uploadPath + e.File.FileName);
// //upload file
// e.File.SaveAs(uploadPath + randomFileName, true);
// }
// catch (Exception ex)
// {
// exception.HandleException("Releases:", MethodBase.GetCurrentMethod().Name, ex, Session["release"]);
// Response.Redirect("/error", false);
// }
//}
///
/// Bas-Pro-61 - Dirk Strauss - 20 July 2016 - (Comment: Pass the selected country to read the currency code)
/// Bas-Pro-62 - Dirk Strauss - 20 July 2016 - (Comment: Pass the selected country to read the country code)
///
///
///
protected void ddlCountries_SelectedIndexChanged(object sender, EventArgs e)
{
if (!(String.IsNullOrWhiteSpace(ddlCountries.SelectedItem.Text)))
{
// Dem-Pro-14 - Dirk Strauss - 8 Aug 2016
//GetCountryDetailsByCountrySelected(ddlCountries.SelectedItem.Text);
}
}
protected void ddEmailTemplate_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (ddEmailTemplate.SelectedItem != null && ddEmailTemplate.SelectedValue != "0")
{
oSetup _setup = null;
if (utils.verifySession("Setup"))
{
_setup = (oSetup)Session["Setup"];
}
else
{
foreach (oSetup setup in xData.GetTypedCollection("recId", typeof(oSetup), ""))
{
_setup = setup;
Session["Setup"] = _setup;
break;
}
}
ArrayList templates = xData.GetTypedByCriteriaSpecific("recId", typeof(oTemplate), "templateName", "Sales " + ddEmailTemplate.SelectedItem.Text + " E-mail Template");
if (templates != null && templates.Count > 0)
edEmailTemplate.Content = ((oTemplate)templates[0]).templateContent;
edEmailTemplate.EditModes = EditModes.All;
txtEmailSubject.Enabled = true;
switch (ddEmailTemplate.SelectedItem.Text)
{
case "Quote":
txtEmailSubject.Text = _setup.emailSubjectQuote;
break;
case "Invoice":
txtEmailSubject.Text = _setup.emailSubjectInvoice;
break;
case "Receipt":
txtEmailSubject.Text = _setup.emailSubjectReceipt;
break;
case "Credit Note":
txtEmailSubject.Text = _setup.emailSubjectCreditNote;
break;
case "Statement":
txtEmailSubject.Text = _setup.emailSubjectStatement;
break;
}
//default subject if blank
if (txtEmailSubject.Text == String.Empty)
txtEmailSubject.Text = ddEmailTemplate.SelectedItem.Text + " {Document Number} from {Company Name}";
if (ddEmailTemplate.SelectedItem.Text == "Statement")
txtEmailSubject.Text = txtEmailSubject.Text.Replace("{Document Number} ", "");
}
else
{
edEmailTemplate.Content = "";
edEmailTemplate.EditModes = EditModes.Preview;
txtEmailSubject.Text = "";
txtEmailSubject.Enabled = false;
}
pnlResult.Visible = false;
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
protected void ddEmailNotes_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (ddEmailNotes.SelectedItem != null && ddEmailNotes.SelectedValue != "0")
{
oSetup _setup = null;
if (utils.verifySession("Setup"))
{
_setup = (oSetup)Session["Setup"];
}
else
{
_setup = handler.ReturnSetup();
Session["Setup"] = _setup;
}
ArrayList templates = xData.GetTypedByCriteriaSpecific("recId", typeof(oTemplate), "templateTypeId", pNums.TemplateType.Sales.GetHashCode().ToString());
foreach (oTemplate template in templates)
{
if (template.templateName.Contains("Recommended Note") && template.templateName.Contains(ddEmailNotes.SelectedItem.Text))
edNoteRecommend.Content = template.templateContent;
if (template.templateName.Contains("Note Description") && template.templateName.Contains(ddEmailNotes.SelectedItem.Text))
lblNoteDesc.Text = template.templateContent;
}
edNote.EditModes = EditModes.All;
switch (ddEmailNotes.SelectedItem.Text)
{
case "Quote":
edNote.Content = _setup.notesQuotes;
break;
case "Invoice":
edNote.Content = _setup.notesInvoices;
break;
case "Receipt":
edNote.Content = _setup.notesReceipts;
break;
case "Credit Note":
edNote.Content = _setup.notesCreditNotes;
break;
case "Statement":
edNote.Content = _setup.notesStatements;
break;
}
}
else
{
edNote.Content = "";
edNote.EditModes = EditModes.Preview;
edNoteRecommend.Content = "";
lblNoteDesc.Text = "";
}
pnlResult.Visible = false;
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
protected void rcbBusinessType_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
try
{
RadComboBox dd = (RadComboBox)sender;
if (dd != null && dd.SelectedValue == "Other")
{
txtBusinessTypeOther.Enabled = true;
reqBusinessTypeOther.Enabled = true;
}
else
{
txtBusinessTypeOther.Text = "";
txtBusinessTypeOther.Enabled = false;
reqBusinessTypeOther.Enabled = false;
}
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
protected void btnCancel_Click(object sender, EventArgs e)
{
try
{
if (this.Parent.Page.ToString().ToLower().Contains("admin_setup_aspx"))
Response.Redirect("Admin.aspx", false);
else
Response.Redirect("/home", false);
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
protected void txtQTENumber_TextChanged(object sender, EventArgs e)
{
try
{
int length = 0;
int next = 0;
int.TryParse(txtQTELength.Text, out length);
int.TryParse(txtQTENext.Text, out next);
txtQTEPreview.Value = xSales.BuildNextTransactionNumber(txtQTEPrefix.Text, length, next);
upSetup.Update();
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("/error", false);
}
}
protected void txtINVNumber_TextChanged(object sender, EventArgs e)
{
try
{
int length = 0;
int next = 0;
int.TryParse(txtINVLength.Text, out length);
int.TryParse(txtINVNext.Text, out next);
txtINVPreview.Value = xSales.BuildNextTransactionNumber(txtINVPrefix.Text, length, next);
upSetup.Update();
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("/error", false);
}
}
protected void txtRCTNumber_TextChanged(object sender, EventArgs e)
{
try
{
int length = 0;
int next = 0;
int.TryParse(txtRCTLength.Text, out length);
int.TryParse(txtRCTNext.Text, out next);
txtRCTPreview.Value = xSales.BuildNextTransactionNumber(txtRCTPrefix.Text, length, next);
upSetup.Update();
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("/error", false);
}
}
protected void txtCRNNumber_TextChanged(object sender, EventArgs e)
{
try
{
int length = 0;
int next = 0;
int.TryParse(txtCRNLength.Text, out length);
int.TryParse(txtCRNNext.Text, out next);
txtCRNPreview.Value = xSales.BuildNextTransactionNumber(txtCRNPrefix.Text, length, next);
upSetup.Update();
}
catch (Exception ex)
{
exception.HandleException("Setup:", MethodBase.GetCurrentMethod().Name, ex, 0);
Response.Redirect("/error", false);
}
}
#endregion
}