示例#1
0
        private void Main_Load(object sender, EventArgs e)
        {
            //get activecomponents
            string sActiveComponents = "hh";

                sActiveComponents = ConfigurationSettings.AppSettings.Get("ActiveComponents");

                if (sActiveComponents == null)
                {
                    if (MessageBox.Show("Please specify ActiveComponents Parameters in Config file", "ActiveComponents Parameters", MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK)
                    {
                        Application.Exit();

                    }
                }
            if (sActiveComponents == "0")
                aActiveComponents = new string[6] { "1", "0", "0", "0", "0", "0" };
            if (sActiveComponents == "1")
                aActiveComponents = new string[6] { "0", "1", "0", "0", "0", "0" };
            if (sActiveComponents == "2")
                aActiveComponents = new string[6] { "0", "0", "1", "0", "0", "0" };
            if (sActiveComponents == "3")
                aActiveComponents = new string[6] { "0", "0", "0", "1", "0", "0" };
            if (sActiveComponents == "4")
                aActiveComponents = new string[6] { "0", "0", "0", "0", "1", "0" };
            if (sActiveComponents == "5")
                aActiveComponents = new string[6] { "0", "0", "0", "0", "0", "1" };
            //aActiveComponents = new string[6] { "0", "0", "0", "0", "0", "1" };
            // 0 = POS
            // 1 = Manufacturing
            // 2 = BUS
            // 3 = Sync
            // 4 = POS - Site Fasilities (Kings Hire)
            // 5 = DSNJHB

            if (Global.sLogedInUserName != "`1")
            {
                foreach (ToolStripMenuItem toolMenuItem in menuStrip1.Items)
                {
                    if (toolMenuItem != fileToolStripMenuItem)
                    {
                        toolMenuItem.Visible = false;

                        foreach (ToolStripDropDownItem toolMenuDropDownItem in toolMenuItem.DropDownItems)
                        {
                            toolMenuDropDownItem.Visible = false;
                            HideMenuItems(toolMenuDropDownItem);

                        }
                    }
                }
            }

            Generate clGenrate = new Generate();
            Global.sCurrFinPeriod = clGenrate.GetPeriodValue(DateTime.Now);
            Global.bUserMaxNewNumber = true;
            Global.sGlobalDefaultRule = "";
            Global.sGlobalDefaultRuleID = "";
            Global.bUseCalculationRules = false;

            helpToolStripMenuItem1.Visible = true;
            updatesToolStripMenuItem.Visible = true;
            aboutToolStripMenuItem.Visible = true;

            if (aActiveComponents[0].ToString() == "1") //POS
            {
                //Documents
                documentsToolStripMenuItem.Visible = true;
                salesOrderToolStripMenuItem.Visible = true;
                invoicesToolStripMenuItem.Visible = true;
                //Customer
                customersToolStripMenuItem.Visible = true;
                addCustomerToolStripMenuItem.Visible = true;
                //Administrator
                AdministratorToolStripMenuItem.Visible = true;
                workshopMovementToolStripMenuItem.Visible = true;
                bulkInvoicingToolStripMenuItem.Visible = true;
                kitItemSetupToolStripMenuItem.Visible = true;
                dailyTurnoverToolStripMenuItem.Visible = true;
                sendMOSReportsToolStripMenuItem.Visible = true;
                overLimitCustomersToolStripMenuItem.Visible = true;
                itemCodeManagerToolStripMenuItem.Visible = true;
                //Reports
                reportsToolStripMenuItem.Visible = true;
                assetsOnSiteToolStripMenuItem.Visible = true;
                salesOrderToolStripMenuItem1.Visible = true;
                openOrderxToolStripMenuItem.Visible = true;
                itemHistoryToolStripMenuItem.Visible = true;

                if (Global.sLogedInUserType == "1") //Administrator
                {
                    //Administrator
                    addUserToolStripMenuItem.Visible = true;
                    addAttachmentsToolStripMenuItem.Visible = true;
                    //Setup
                    setupToolStripMenuItem.Visible = true;
                    companySetupToolStripMenuItem.Visible = true;
                    closedOrderUtilityToolStripMenuItem.Visible = true;
                    emailAndFaxSendingToolStripMenuItem.Visible = true;
                    publicHolidaySetupToolStripMenuItem.Visible = true;

                    //Reports
                    quickReportsToolStripMenuItem.Visible = true;
                    avgTurnoverPerCustomerToolStripMenuItem.Visible = true;
                    itemHistoryToolStripMenuItem.Visible = true;
                }

            }

            if (aActiveComponents[1].ToString() == "1") //Manu JR13 04/07/2011
            {
                //Documents
                documentsToolStripMenuItem.Visible = true;
                supplierDocumentsToolStripMenuItem.Visible = true;
                customerInvoiceToolStripMenuItem1.Visible = true;

                //Manufacturing
                manufacturingToolStripMenuItem.Visible = true;
                tsmInvtAdjustments.Visible = true;
                stockIssueDocumentToolStripMenuItem.Visible = true;
                productionDocumentToolStripMenuItem.Visible = true;
                producedInventoryManagementToolStripMenuItem.Visible = true;

                //Setup
                setupToolStripMenuItem.Visible = true;
                //printUtilityBarcodesToolStripMenuItem.Visible = true;
                //reportsToolStripMenuItem.Visible = true;
                //manufacturingToolStripMenuItem1.Visible = true;
                //rawItemStockLevelToolStripMenuItem.Visible = true;

                //Reports
                reportsToolStripMenuItem.Visible = true;
                manufacturingToolStripMenuItem1.Visible = true;
                productionSummaryToolStripMenuItem.Visible = true;

                invoicesToolStripMenuItem1.Visible = false;
                assetCostingToolStripMenuItem.Visible = false;
                assetLocationToolStripMenuItem.Visible = false;
                assetsOnSiteToolStripMenuItem.Visible = false;
                salesOrderToolStripMenuItem.Visible = false;
                rawItemStockLevelToolStripMenuItem.Visible = false;
                invoicesToolStripMenuItem.Visible = false;
                liquidAccessComparisonToolStripMenuItem.Visible = false;

                //itemHistoryToolStripMenuItem.Visible = true;

                quickReportsToolStripMenuItem.Visible = false;
                invoicesToolStripMenuItem1.Visible = false;
                liquidAccessComparisonToolStripMenuItem.Visible = false;
                itemHistoryToolStripMenuItem.Visible = false;
                dailyTurnoverToolStripMenuItem.Visible = false;

                if (Global.sLogedInUserType == "1") //Administrator
                {
                    //Manufacturing

                    //Batch Setup

                    //Administrator
                    AdministratorToolStripMenuItem.Visible = true;
                    addUserToolStripMenuItem.Visible = true;
                    addAttachmentsToolStripMenuItem.Visible = true;

                    //Setup
                    companySetupToolStripMenuItem.Visible = true;
                }

            }

            if (aActiveComponents[2].ToString() == "1") //BUS
            {
                //Documents
                documentsToolStripMenuItem.Visible = true;
                supplierDocumentsToolStripMenuItem.Visible = true;
                //Maintenance
                maintenanceToolStripMenuItem.Visible = true;
                addEditAssetToolStripMenuItem.Visible = true;
                issueInventoryForAssetsToolStripMenuItem.Visible = true;
                returnAssetFromAssetToolStripMenuItem.Visible = true;
                //Reports
                reportsToolStripMenuItem.Visible = true;
                assetLocationToolStripMenuItem.Visible = true;
                itemHistoryToolStripMenuItem.Visible = true;

                if (Global.sLogedInUserType == "1") //Administrator
                {
                    //Administrator
                    AdministratorToolStripMenuItem.Visible = true;
                    addUserToolStripMenuItem.Visible = true;
                    //Setup
                    setupToolStripMenuItem.Visible = true;
                    companySetupToolStripMenuItem.Visible = true;
                    //Reports
                    assetCostingToolStripMenuItem.Visible = true;
                    itemHistoryToolStripMenuItem.Visible = true;
                }
            }

            if (aActiveComponents[3].ToString() == "1") //Sync
            {
                //Transfer
                documentTransferToolStripMenuItem.Visible = true;
                documentTransferToolStripMenuItem1.Visible = true;
                errorManagementToolStripMenuItem.Visible = true;

                if (Global.sLogedInUserType == "1") //Administrator
                {
                    //Administrator
                    AdministratorToolStripMenuItem.Visible = true;
                    addUserToolStripMenuItem.Visible = true;
                    //Setup
                    setupToolStripMenuItem.Visible = true;
                    companySetupToolStripMenuItem.Visible = true;
                    tranferSetupToolStripMenuItem.Visible = true;
                    testToolStripMenuItem.Visible = true; //GLCodeSyncSetup
                    inventorySyncSetupToolStripMenuItem.Visible = true;
                    //Sync
                    syncToolStripMenuItem.Visible = true;
                    gLCodeSyncToolStripMenuItem.Visible = true;
                    inventoryItemsToolStripMenuItem.Visible = true;
                }
            }

            if (aActiveComponents[4].ToString() == "1") //POS - Site Fasilities
            {
                //Documents
                documentsToolStripMenuItem.Visible = true;
                salesOrderToolStripMenuItem.Visible = true;
                invoicesToolStripMenuItem.Visible = true;
                //Customer
                customersToolStripMenuItem.Visible = true;
                addCustomerToolStripMenuItem.Visible = true;
                //Administrator
                AdministratorToolStripMenuItem.Visible = true;
                workshopMovementToolStripMenuItem.Visible = true;
                bulkInvoicingToolStripMenuItem.Visible = true;
                addAttachmentsToolStripMenuItem.Visible = true;
                //Reports
                reportsToolStripMenuItem.Visible = true;
                assetsOnSiteToolStripMenuItem.Visible = true;
                salesOrderToolStripMenuItem1.Visible = true;
                openOrderxToolStripMenuItem.Visible = true;
                emailAndFaxSendingToolStripMenuItem.Visible = true;
                publicHolidaySetupToolStripMenuItem.Visible = true;
                liquidAccessComparisonToolStripMenuItem.Visible = true;
                itemHistoryToolStripMenuItem.Visible = true;
                journalToolStripMenuItem.Visible = true;
                supplierJournalToolStripMenuItem.Visible = true;

                //qoutesToolStripMenuItem.Visible = true;
                projectManagementToolStripMenuItem.Visible = true;

                if (Global.sLogedInUserType == "1") //Administrator
                {
                    //Administrator
                    addUserToolStripMenuItem.Visible = true;
                    addAttachmentsToolStripMenuItem.Visible = true;
                    //Setup
                    setupToolStripMenuItem.Visible = true;
                    companySetupToolStripMenuItem.Visible = true;
                    closedOrderUtilityToolStripMenuItem.Visible = true;
                    ruleSetupToolStripMenuItem.Visible = true;
                    //Reports
                    quickReportsToolStripMenuItem.Visible = true;
                    avgTurnoverPerCustomerToolStripMenuItem.Visible = true;
                    liquidMassConverterToolStripMenuItem.Visible = true;
                    liquidAccessComparisonToolStripMenuItem.Visible = true;
                    itemHistoryToolStripMenuItem.Visible = true;
                    setupToolStripMenuItem2.Visible = true;
                    accountDetailsToolStripMenuItem.Visible = true;
                    estimatedTrunoverToolStripMenuItem.Visible = true;
                    marketingToolStripMenuItem.Visible = true;

                }

                Global.bUseCalculationRules = true;
            }

            if (aActiveComponents[5].ToString() == "1") //DSN JHB
            {
                qoutesToolStripMenuItem.Visible = true;

                documentsToolStripMenuItem.Visible = true;
                AdministratorToolStripMenuItem.Visible = true;
                setupToolStripMenuItem.Visible = true;
                companySetupToolStripMenuItem.Visible = true;
                deliveryNoteToolStripMenuItem.Visible = true;
                returnNoteToolStripMenuItem.Visible = true;
                pickingSlipsToolStripMenuItem.Visible = true;
                projectManagementToolStripMenuItem1.Visible = true;
                if (Global.sLogedInUserType == "1") //Administrator
                {
                    //Administrator
                    AdministratorToolStripMenuItem.Visible = true;
                    addUserToolStripMenuItem.Visible = true;
                    //Setup
                    setupToolStripMenuItem.Visible = true;
                    companySetupToolStripMenuItem.Visible = true;
                    projectManagementToolStripMenuItem2.Visible = true;
                }
            }
            //invoicesToolStripMenuItem1.Visible = true;

            Solsage_Pastel_API.solPastelSDK clsSDK = new Solsage_Pastel_API.solPastelSDK();
            string sRet =	clsSDK.invokeSDK(Global.sDataPath);//Initialise the sdk
            if (sRet != "0")
            {
            MessageBox.Show("Error Retrieving Data Files \r\n\r\n" + sRet, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            Application.Restart();
            }

            using (PsqlConnection oConn = new PsqlConnection(Solsage_Process_Management_System.Classes.Connect.sConnStr))
            {
                oConn.Open();
                string sSql = "Select * from SOLCS";

                PsqlDataReader rdReader = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sSql, oConn).ExecuteReader();
                while (rdReader.Read())
                {
                    Global.sCompanyName = rdReader["GroupName"].ToString().Trim();
                    Global.sRegName = rdReader["CompanyName"].ToString().Trim();
                    Global.sVAT = rdReader["VATNumber"].ToString().Trim();
                    Global.sReg = rdReader["RegistrationNum"].ToString().Trim();
                    Global.sCompanyTel = rdReader["TelephoneNumber"].ToString().Trim();
                    Global.sCompanyFax = rdReader["FaxNumber"].ToString().Trim();
                    Global.sCompanyAd1 = rdReader["Physical1"].ToString().Trim();
                    Global.sCompanyAd2 = rdReader["Physical2"].ToString().Trim();
                    Global.sCompanyAd3 = rdReader["Physical3"].ToString().Trim();
                    Global.sCompanyPostAd1 = rdReader["Postal1"].ToString().Trim();
                    Global.sCompanyPostAd2 = rdReader["Postal2"].ToString().Trim();
                    Global.sCompanyPostAd3 = rdReader["PostalZip"].ToString().Trim();
                    Global.sDeliveryNoteCompany = rdReader["DeliveryNoteCompany"].ToString();
                    Global.sInvoiceContactName = rdReader["InvoiceContactName"].ToString();
                    Global.sInvoiceContactNumber = rdReader["InvoiceContactNumber"].ToString();
                    Global.sDefaultStore = rdReader["StoreDefault"].ToString().Trim();
                    Global.sQuotePath = rdReader["QuotePath"].ToString().Trim();
                    try
                    {
                        Global.sSalesOrderType = rdReader["SalesOrderType"].ToString().Trim();
                        if (Global.sSalesOrderType == "Long Term AND Short Term")
                            Global.bUseCalculationRules = true;
                    }
                    catch
                    {
                        Global.sSalesOrderType = "";
                    }
                    try
                    {
                        Global.sTermsAndConditions = rdReader["DeliveryNoteTerms"].ToString().Trim();
                    }
                    catch
                    {
                        Global.sTermsAndConditions = "";
                    }

                    try
                    {
                        if (ConfigurationSettings.AppSettings.Get("UseQuantityMeasure") == "1")
                            Global.bUseQuantityMeasure = true;
                    }
                    catch
                    {
                        Global.bUseQuantityMeasure = false;
                    }

                    try
                    {
                        Global.sDefaultSlipPrinter = ConfigurationSettings.AppSettings.Get("SlipPrinter");
                    }
                    catch
                    {
                        Global.sDefaultSlipPrinter = rdReader["DefaultSlipPrinter"].ToString().Trim();
                    }
                    try
                    {
                        Global.sDefaultDocPrinter = ConfigurationSettings.AppSettings.Get("DocumentPrinter");
                    }
                    catch
                    {
                        Global.sDefaultDocPrinter = rdReader["DefaultDocPrinter"].ToString().Trim();
                    }
                    try
                    {
                        Global.sDeliveryNoteFirstPrintCopies = ConfigurationSettings.AppSettings.Get("DeliveryNoteFirstPrintCopies");
                    }
                    catch
                    {
                        Global.sDeliveryNoteFirstPrintCopies = rdReader["DellNoteFirst"].ToString().Trim();
                    }
                    try
                    {
                        Global.sDeliveryNoteDuplicatePrintCopies = ConfigurationSettings.AppSettings.Get("DeliveryNoteDuplicatePrintCopies");
                    }
                    catch
                    {
                        Global.sDeliveryNoteDuplicatePrintCopies = rdReader["DellNoteDuplicate"].ToString().Trim();
                    }
                    try
                    {
                        Global.sInvoiceFirstPrintCopies = ConfigurationSettings.AppSettings.Get("InvoiceFirstPrintCopies");
                    }
                    catch
                    {
                        Global.sInvoiceFirstPrintCopies = rdReader["InvoiceFirst"].ToString().Trim();
                    }
                    try
                    {
                        Global.sInvoiceDuplicatePrintCopies = ConfigurationSettings.AppSettings.Get("InvoiceDuplicatePrintCopies");
                    }
                    catch
                    {
                        Global.sInvoiceDuplicatePrintCopies = rdReader["InvoiceDuplicate"].ToString().Trim();
                    }

                    try
                    {
                        Global.sEmailAddressFrom1 = ConfigurationSettings.AppSettings.Get("MailAddressFrom1");
                    }
                    catch
                    {
                        Global.sEmailAddressFrom1 = "*****@*****.**";
                    }
                    try
                    {
                        Global.sEmailAddressFrom2 = ConfigurationSettings.AppSettings.Get("MailAddressFrom2");
                    }
                    catch
                    {
                        Global.sEmailAddressFrom2 = "*****@*****.**";
                    }
                    try
                    {
                        Global.sEmailAddressFrom3 = ConfigurationSettings.AppSettings.Get("MailAddressFrom3");
                    }
                    catch
                    {
                        Global.sEmailAddressFrom3 = "*****@*****.**";
                    }
                    try
                    {
                        Global.sEmailPasswordFrom1 = ConfigurationSettings.AppSettings.Get("MailPasswordFrom1");
                    }
                    catch
                    {
                        Global.sEmailPasswordFrom1 = "";
                    }
                    try
                    {
                        Global.sEmailPasswordFrom2 = ConfigurationSettings.AppSettings.Get("MailPasswordFrom2");
                    }
                    catch
                    {
                        Global.sEmailPasswordFrom2 = "";
                    }
                    try
                    {
                        Global.sEmailPasswordFrom3 = ConfigurationSettings.AppSettings.Get("MailPasswordFrom3");
                    }
                    catch
                    {
                        Global.sEmailPasswordFrom3 = "";
                    }
                    try
                    {
                        Global.sSmtpClient = ConfigurationSettings.AppSettings.Get("SmtpClient");
                    }
                    catch
                    {
                        Global.sSmtpClient = "smtp.axxess.co.za";
                    }

                    try
                    {
                        Global.sSmtpClientPort = ConfigurationSettings.AppSettings.Get("SmtpClientPort");
                    }
                    catch
                    {
                        Global.sSmtpClientPort = "25";
                    }
                    try
                    {
                        Global.sEmailBody = ConfigurationSettings.AppSettings.Get("MailBody");
                    }
                    catch
                    {
                        Global.sEmailBody = "";
                    }
                    try
                    {
                        if (ConfigurationSettings.AppSettings.Get("Manufacturing") == "1")
                        {
                            Global.bManufacturing = true;
                        }
                        else
                        {
                            Global.bManufacturing = false;
                        }
                    }
                      catch
                    {
                        Global.bManufacturing = false;
                    }
                    try
                    {
                        if (ConfigurationSettings.AppSettings.Get("LogCreateDocument") == "1")
                        {
                            Global.bLogCreateDocument = true;
                        }
                        else
                        {
                            Global.bLogCreateDocument = false;
                        }
                    }
                    catch
                    {
                        Global.bLogCreateDocument = false;
                    }
                    Global.sDeliveryNoteTemplate = rdReader["DeliveryNoteTemplate"].ToString().Trim();
                    Global.sInvoiceTemplate = rdReader["InvoiceTemplate"].ToString().Trim();
                    Global.sQuoteTemplate = rdReader["QuoteTemplate"].ToString().Trim();
                    if( rdReader["DefaultSDKUser"].ToString().Trim() != "")
                    {
                        Global.iPastelSdkUser = Convert.ToInt32(rdReader["DefaultSDKUser"].ToString().Trim());
                    }
                    else
                    {
                         Global.iPastelSdkUser =0;
                    }
                    if (rdReader["AutoInvoiceOnReturn"].ToString() == "1")
                    {
                        Global.bAutoInvoiceOnReturn = true;
                    }
                    else
                    {
                        Global.bAutoInvoiceOnReturn = false;
                    }

                    if (aActiveComponents[4].ToString() == "1") //POS - Site Fasilities
                    {
                        Global.sGlobalDefaultRule = rdReader["sDefaultRuleName"].ToString().Trim();
                        Global.sGlobalDefaultRuleID = rdReader["iDefaultRuleId"].ToString().Trim();
                    }
                    else
                    {
                        Global.sGlobalDefaultRule = "";
                        Global.sGlobalDefaultRuleID = "";
                    }

                    if (rdReader["GenerateZeroInv"].ToString() == "True")
                    {
                        Global.bGenerateZeroInvoice = true;
                    }
                    else
                    {
                        Global.bGenerateZeroInvoice = false;
                    }

                    if (rdReader["AutoBlockCust"].ToString() == "True")
                    {
                        Global.bAutoBlockCustomer = true;
                    }
                    else
                    {
                        Global.bAutoBlockCustomer = false;
                    }

                    //JR 13 6/9/2011
                    if (rdReader["LiquidHandlesInvt"].ToString() == "True")
                        Global.bLiquidHandlesInvt = true;
                    else
                        Global.bLiquidHandlesInvt = false;

                    //********
                }
                //get returnitem status of user
                //check to see whether logged in user is allowed to return item?
                try
                {
                    string sSqlRI = "Select ReturnItem from SOLUS where Code = '" + Global.sLogedInUserCode + "'";
                    Global.iReturnItem = Convert.ToInt16(Connect.getDataCommand(sSqlRI, oConn).ExecuteScalar().ToString());
                    oConn.Dispose();
                }
                catch
                {
                    Global.iReturnItem = 0;
                    oConn.Dispose();
                }

                rdReader.Close();
                oConn.Dispose();
            }
            if (Global.bUseBackground)
            {
                this.BackgroundImage = global::Solsage_Process_Management_System.Properties.Resources._09;
                this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            }
               this.Text = "Liquid [" + Global.sActiveCompanyName + "]";
        }
示例#2
0
 private string findCustomerDelivery()
 {
     string[] aKeyValues = new string[5];
     aKeyValues[0] = txtAccountCode.Text;
     aKeyValues[1] ="   ";
     Solsage_Pastel_API.solPastelSDK clsSDK = new Solsage_Pastel_API.solPastelSDK();
     return (clsSDK.Read_Record("ACCDELIV", 4,0, aKeyValues,Global.sDataPath));
 }
示例#3
0
 private string findCustomerHeader()
 {
     string[] aKeyValues = new string[5];
     aKeyValues[0] = txtCustomerCode.Text;
     Solsage_Pastel_API.solPastelSDK clsSDK = new Solsage_Pastel_API.solPastelSDK();
     return (clsSDK.Read_Record("ACCMASD", 2, 0, aKeyValues, Global.sDataPath));
 }
示例#4
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            Cursor = System.Windows.Forms.Cursors.WaitCursor;

            // Field Completed Validations
            if (txtAccountCode.Text == "")
            {
                MessageBox.Show("Account Code is a compulsory fields. Please supply a value.", "Compulsory Field", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtAccountCode.Focus();
            }
            else if(txtContact.Text == "")
            {
                MessageBox.Show("Contact Name is a compulsory fields. Please supply a value.", "Compulsory Field", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtContact.Focus();
            }
            else if (txtID.Text == "")
            {
                MessageBox.Show("ID Number is a compulsory fields. Please supply a value.", "Compulsory Field", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtID.Focus();
            }
            else
            {
                //Check if Customer with this ID exists
                string sCustCode = "";
                bool iIDExist = false;

                using (PsqlConnection oConn = new PsqlConnection(Solsage_Process_Management_System.Classes.Connect.sPastelConnStr))
                {
                    oConn.Open();

                    string sCheckIDSql = "SELECT CustomerCode FROM CustomerMaster WHERE LTRIM(RTRIM(UserDefined01)) = '" + txtID.Text.Trim() + "' and CustomerCode != '" + txtAccountCode.Text.Trim() + "'";

                    PsqlDataReader rdReader = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sCheckIDSql, oConn).ExecuteReader();
                    if (rdReader.HasRows)
                    {
                        iIDExist = true;
                        while (rdReader.Read())
                        {
                            sCustCode += rdReader["CustomerCode"].ToString() +"|";
                        }
                    }
                    else
                    {
                        iIDExist = false;
                    }

                    oConn.Dispose();
                }

                bool bSave = true;
                if (iIDExist)
                {
                    sCustCode = sCustCode.Substring(0, sCustCode.Length - 1);
                    sCustCode = sCustCode.Replace("|", ",");
                    if (MessageBox.Show("Customer(s) (" +sCustCode +") with this ID Number already exist. Do you want to continue?", "Existing ID Number", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                    {
                        bSave = false;
                    }
                }

                if (bSave)
                {
                    //Format Discount - Pastel Format
                    double dCorrectDiscount = (Convert.ToDouble(txtDiscount.Text));

                    //Import Customer To Pastel
                    string sSaveString = txtAccountCode.Text + "|";   //account code
                    sSaveString += txtDescription.Text + "|"; //description

                    //Postal address
                    sSaveString += txtPostAdd1.Text + "|"; // Post Address 1
                    sSaveString += txtPostAd2.Text + "|"; // Post Address 2
                    sSaveString += txtPostAd3.Text + "|"; // Post Address 3
                    sSaveString += txtPostAd4.Text + "||"; // Post Address 4  + 5

                    sSaveString += txtTelephone.Text + "|"; // Telephone
                    sSaveString += txtFax.Text + "|"; // Fax
                    sSaveString += txtContact.Text + "|"; // Contact
                    sSaveString += "N|"; // Tax Exemp
                    sSaveString += "|"; // Early Payments
                    sSaveString += "|"; // Price List
                    sSaveString += txtSalesPerson.Text + "|"; // Sales Analysie Code

                    sSaveString += txtDelAd1.Text + "|"; // Delivery Address 1
                    sSaveString += txtDelAd2.Text + "|"; // Delivery Address 2
                    sSaveString += txtDelAd3.Text + "|"; // Delivery Address 3
                    sSaveString += txtDelAd4.Text + "||"; // Delivery Address 4 + 5

                    sSaveString += "N|"; // Blocked
                    sSaveString += dCorrectDiscount.ToString("N2") + "|"; // Discount
                    sSaveString += "Y|"; // Exclusive
                    sSaveString += "|"; // Statements
                    if (rdOpenItem.Checked)
                        sSaveString += "Y|"; // Open Item
                    else
                        sSaveString += "N|"; // Balance Forward

                    // Customer Category
                    string sCustomerCategory = "";
                    if (selCustomerCategory.Text != "")
                    {
                        sCustomerCategory = Convert.ToInt16(selCustomerCategory.Text.Substring(0, selCustomerCategory.Text.IndexOf('-'))).ToString("00");
                    }
                    sSaveString += sCustomerCategory + "|"; // Customer Category

                    sSaveString += "00|"; // Currency

                    // Payment Terms
                    string sPayment = "";
                    switch (selPaymentTerms.Text)
                    {
                        case "Current":
                            sPayment = "0";
                            break;
                        case "30 Days":
                            sPayment = "30";
                            break;
                        case "60 Days":
                            sPayment = "60";
                            break;
                        case "90 Days":
                            sPayment = "90";
                            break;
                        case "120 Days":
                            sPayment = "12";
                            break;
                    }

                    sSaveString += sPayment + "|";

                    sSaveString += txtCreditLimit.Text + "|"; // Credit Limit
                    sSaveString += txtID.Text + "|"; // Use User Field 1 for ID
                    sSaveString += txtRegistration.Text + "|"; // Use User Field 2 for Registration Number
                    sSaveString += txtDebtorsContact.Text + "|"; // Use User Field 3 for Registration Number
                    sSaveString += txtUserDefined4.Text +"|"; // Use User Field 4 for Registration Number
                    sSaveString += txtKingsContract.Text + "|"; // Use User Field 5 for Registration Number
                    sSaveString += "M|"; //Month or Day

                    //Stat Print or Email
                    string sStatPrintMail = "";
                    switch (selStatePrinting.Text)
                    {
                        case "Print Statement":
                            sStatPrintMail = "1";
                            break;
                        case "Email Statement":
                            sStatPrintMail = "2";
                            break;
                        case "Print & Email Statement":
                            sStatPrintMail = "3";
                            break;
                        case "Don't Print/Email Statement":
                            sStatPrintMail = "4";
                            break;
                    }
                    sSaveString += sStatPrintMail + "|"; //Stat Print or Email

                    //Doc Print or Email
                    string sDocPrintMail = "";
                    switch (selDocPrinting.Text)
                    {
                        case "Print Document":
                            sDocPrintMail = "1";
                            break;
                        case "Email Document":
                            sDocPrintMail = "2";
                            break;
                        case "Print & Email Document":
                            sDocPrintMail = "3";
                            break;
                    }
                    sSaveString += sDocPrintMail + "|"; //Doc Print or Email

                    sSaveString += txtMobile.Text + "|"; // Cellphone
                    sSaveString += txtEmail.Text + "|"; // Email
                    sSaveString += "|"; // Freight
                    sSaveString += "|"; // Ship
                    sSaveString += txtVAT.Text + "|"; // Tax Reference

                    string sCash = "N";
                    if (chkCash.Checked)
                    {
                        sCash = "Y";
                    }
                    sSaveString += sCash; // Cash Customer
                    Solsage_Pastel_API.solPastelSDK clsSDK = new Solsage_Pastel_API.solPastelSDK();

                    string sReturn = clsSDK.AddCustomer(sSaveString,Global.sDataPath);
                    if (sReturn != "0")
                    {
                        MessageBox.Show(sReturn, "Error on save", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        cmdSave.Enabled = false;
                    }

                    Cursor = System.Windows.Forms.Cursors.Default;

                    if (bCloseOnSave)
                    {
                        sResult = txtAccountCode.Text;
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                }
            }

            //save marketing detail.
            using (PsqlConnection oConn = new PsqlConnection(Solsage_Process_Management_System.Classes.Connect.sConnStr))
            {
                bool bUseSite = false;
                if (chkUseSite.Checked == true)
                    bUseSite = true;

                oConn.Open();
                string delSql = "delete From SOLMARKCUSTDET where CustomerCode  = '" + txtAccountCode.Text.Trim() + "' AND SiteName = 'MAIN'";
                int delRet = Solsage_Process_Management_System.Classes.Connect.getDataCommand(delSql, oConn).ExecuteNonQuery();

                string sSql = "Insert Into SOLMARKCUSTDET (CustomerCode,MarketingCategory,CommissionFloor, Marketer,SiteName, UseSite)";
                sSql += " Values ('" + txtAccountCode.Text.Trim() + "','" + txtMarketingCategory.Text.Trim() + "','" + txtCommissionFloor.Text.Trim() + "','" + txtMarketer.Text.Trim() + "','MAIN'," + Convert.ToInt16(bUseSite) + ")";

                int iRet = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sSql, oConn).ExecuteNonQuery();
                oConn.Dispose();
            }

            Cursor = System.Windows.Forms.Cursors.Default;
        }