using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace AyaNova.PlugIn.QBOI { public partial class SetQBImportInventoryAccounts : Form { public SetQBImportInventoryAccounts() { InitializeComponent(); } public bool ImportPartAsInventory { get; set; } private void SetQBImportInventoryAccounts_Load(object sender, EventArgs e) { if (Util.QUSA) { ckTaxable.Checked = Util.QDat.ImportItemTaxable; } else { //populate tax codes combo cbTaxCode.BindingContext = new BindingContext();//Ensure unique binding context so multiple combo boxes bound to same datasource can be selected independantly cbTaxCode.DisplayMember = "FullName"; cbTaxCode.ValueMember = "ID"; cbTaxCode.DataSource = Util.QBTaxCodes; cbTaxCode.SelectedIndex = 0; if (!string.IsNullOrEmpty(Util._ImportPartToQBDefaultTaxCodeId)) cbTaxCode.SelectedValue = Util._ImportPartToQBDefaultTaxCodeId; //Hide taxable checkbox and show tax codes combo box and title ckTaxable.Visible = false; lblTaxCodes.Visible = true; cbTaxCode.Visible = true; } this.btnCancel.Image = Util.AyaImage("Cancel24"); this.btnOK.Image = Util.AyaImage("OK24"); this.Icon = Util.AyaIcon("Part16icon"); //Fill combo's and select defaults if (Util.QBSupportsInventory) //case 3296 { //can do inventory so enable checkboxes rdImportAsNonInventoryItem.Enabled = true; rdImportAsInventoryItem.Enabled = true; rdImportAsInventoryItem.Checked = true; cbAsset.BindingContext = new BindingContext();//Ensure unique binding context so multiple combo boxes bound to same datasource can be selected independantly cbAsset.DisplayMember = "FullName"; cbAsset.ValueMember = "ID"; cbAsset.DataSource = Util.QBAccounts; if (!string.IsNullOrEmpty(Util.QDat.QBInventoryAssetAccountRef)) cbAsset.SelectedValue = Util.QDat.QBInventoryAssetAccountRef; cbCogs.BindingContext = new BindingContext(); cbCogs.DisplayMember = "FullName"; cbCogs.ValueMember = "ID"; cbCogs.DataSource = Util.QBAccounts; if (!string.IsNullOrEmpty(Util.QDat.QBInventoryCOGSAccountRef)) cbCogs.SelectedValue = Util.QDat.QBInventoryCOGSAccountRef; } else { //can't do inventory so disable the checkboxes and show explanation rdImportAsNonInventoryItem.Checked = true; rdImportAsNonInventoryItem.Enabled = false; rdImportAsInventoryItem.Enabled = false; tbInventoryNotSupportedLabel.Text = Util.QOfferingSku + "\r\nDoes not allow inventory"; tbInventoryNotSupportedLabel.Visible = true; cbAsset.Enabled = false; cbCogs.Enabled = false; } cbIncome.BindingContext = new BindingContext(); cbIncome.DisplayMember = "FullName"; cbIncome.ValueMember = "ID"; cbIncome.DataSource = Util.QBAccounts; if (!string.IsNullOrEmpty(Util.QDat.QBInventoryIncomeAccountReference)) cbIncome.SelectedValue = Util.QDat.QBInventoryIncomeAccountReference; } private void btnOK_Click(object sender, EventArgs e) { //case 3296 this.ImportPartAsInventory = false; if (Util.QBSupportsInventory && rdImportAsInventoryItem.Checked) { this.ImportPartAsInventory = true; Util.QDat.QBInventoryAssetAccountRef = cbAsset.SelectedValue.ToString(); Util.QDat.QBInventoryCOGSAccountRef = cbCogs.SelectedValue.ToString(); } Util.QDat.QBInventoryIncomeAccountReference = cbIncome.SelectedValue.ToString(); if (Util.QUSA) { Util.QDat.ImportItemTaxable = ckTaxable.Checked; } else { object o = cbTaxCode.SelectedValue; if (o == null) { Util._ImportPartToQBDefaultTaxCodeId = string.Empty; } else { Util._ImportPartToQBDefaultTaxCodeId = o.ToString(); } } Util.SaveQBIData(); this.DialogResult = DialogResult.OK; this.Close(); } private void rdImportAs_CheckedChanged(object sender, EventArgs e) { if (rdImportAsInventoryItem.Checked) { cbAsset.Enabled = true; cbCogs.Enabled = true; } else { cbAsset.Enabled = false; cbCogs.Enabled = false; } } } }