Пример #1
0
        public string AddModQBInvoice(string szCustomerName, string szInvoiceQuickbookID, InvoiceItem invoiceItem1, DateTime jobDate, string itemA_ID)
        {
            bool sessionBegun = false;
            bool connectionOpen = false;
            QBSessionManager sessionManager = null;
            string invoiceID = "";
            bool bItemInvoice1 = false;

            try
            {
                //DateTime curDate = DateTime.Now;
                DateTime curDate = jobDate;

                //otherwise find for the lastest one
                /*
                int prevMonth = DateTime.Today.AddMonths(-1).Month;
                int curMonth = DateTime.Today.Month;
                int nextMonth = DateTime.Today.AddMonths(1).Month;
                int year = DateTime.Today.Year;
                */

                //int prevMonth = curDate.AddMonths(-1).Month;
                int curMonth = curDate.Month;
                int nextMonth = curDate.AddMonths(1).Month;
                int year = curDate.Year;
                int nextyear = curDate.AddYears(1).Year;

                DateTime fromDate;
                DateTime toDate;
                Item item1 = pQBitems1[ItemComboBox1.SelectedIndex];

                //Create the session Manager object
                sessionManager = new QBSessionManager();

                //Create the message set request object to hold our request
                IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 8, 0);
                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
                sessionManager.OpenConnection(MMSUtility.QBAppID, MMSUtility.QBAppName);

                connectionOpen = true;
                sessionManager.BeginSession("", ENOpenMode.omDontCare);
                sessionBegun = true;

                //find the customer information
                ICustomerQuery search = requestMsgSet.AppendCustomerQueryRq();
                search.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameFilter.MatchCriterion.SetValue(ENMatchCriterion.mcStartsWith);
                search.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameFilter.Name.SetValue(szCustomerName);

                IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                IResponse response = responseMsgSet.ResponseList.GetAt(0);
                ICustomerRetList customerRetList = (ICustomerRetList)response.Detail;
                if (customerRetList == null)
                {
                    //MessageBox.Show("Cannot find customer in QB!\nPlease check QB for Customer Name.");
                    return invoiceID;
                }

                ICustomerRet customerRet = customerRetList.GetAt(0);
                Customer customer = new Customer();
                customer.Name = customerRet.Name.GetValue();
                customer.QuickBooksID = customerRet.ListID.GetValue();
                customer.EditSequence = customerRet.EditSequence.GetValue();
                if (customerRet.FirstName != null) customer.FirstName = customerRet.FirstName.GetValue();
                if (customerRet.LastName != null) customer.LastName = customerRet.LastName.GetValue();

                bool notFound = true;
                if (szInvoiceQuickbookID.Length > 0)
                {
                    //get the lastest associated invoices for the particular customer
                    requestMsgSet.ClearRequests();
                    IInvoiceQuery invoiceQueryRq = requestMsgSet.AppendInvoiceQueryRq();
                    invoiceQueryRq.IncludeLineItems.SetValue(true);

                    //if invoiceID exist, use that
                    invoiceQueryRq.ORInvoiceQuery.TxnIDList.Add(szInvoiceQuickbookID);
                    //Send the request and get the response from QuickBooks
                    responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                    response = responseMsgSet.ResponseList.GetAt(0);
                    IInvoiceRetList invoiceRetList1 = (IInvoiceRetList)response.Detail;

                    if (invoiceRetList1 != null)
                    {
                        notFound = false;
                    }
                }

                // there is no existing invoice based on id, then search for invoice on date
                if (notFound)
                {
                    //get the from prevmonth to curmonth invoice
                    if ((curDate.Day >= 1) && (curDate.Day <= 19))
                    {
                        fromDate = new DateTime(year, curMonth, 1);
                        toDate = new DateTime(year, curMonth, 20);
                    }
                    //get curmonth to nextmonth invoice
                    else
                    {
                        if (nextMonth == 1)
                        {
                            fromDate = new DateTime(year, curMonth, 21);
                            toDate = new DateTime(nextyear, nextMonth, 20);
                        }
                        else
                        {
                            //if next month is jan, then account for next year
                            fromDate = new DateTime(year, curMonth, 21);
                            toDate = new DateTime(year, nextMonth, 20);
                        }
                    }

                    //get the lastest associated invoices for the particular customer
                    requestMsgSet.ClearRequests();
                    IInvoiceQuery invoiceQueryRq = requestMsgSet.AppendInvoiceQueryRq();
                    invoiceQueryRq.IncludeLineItems.SetValue(true);

                    invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.EntityFilter.OREntityFilter.FullNameList.Add(szCustomerName);
                    invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.TxnDateRangeFilter.ORTxnDateRangeFilter.TxnDateFilter.FromTxnDate.SetValue(fromDate);
                    invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.TxnDateRangeFilter.ORTxnDateRangeFilter.TxnDateFilter.ToTxnDate.SetValue(toDate);
                    //ENPaidStatus status = ENPaidStatus.psNotPaidOnly;
                    //invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.PaidStatus.SetValue(status);

                }

                //Send the request and get the response from QuickBooks
                responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                response = responseMsgSet.ResponseList.GetAt(0);
                IInvoiceRetList invoiceRetList = (IInvoiceRetList)response.Detail;

                //check for FC
                int numIndex = -1;
                if (invoiceRetList != null)
                {
                    numIndex = 0;
                    IInvoiceRet invoiceRet1 = invoiceRetList.GetAt(numIndex);
                    string refNum = invoiceRet1.RefNumber.GetValue();
                    if (refNum.StartsWith("FC"))
                    {
                        //get the next one
                        if (invoiceRetList.Count > 1) numIndex = 1;
                        else numIndex = -1;
                    }
                }

                //if need new invoice
                if ((invoiceRetList == null) || (numIndex == -1))
                {
                    Invoice invoice = new Invoice();
                    invoice.Customer = customer;
                    requestMsgSet.ClearRequests();
                    IInvoiceAdd invoiceAddRq = requestMsgSet.AppendInvoiceAddRq();

                    //get the current month
                    DateTime invoiceDate;
                    if ((curDate.Day >= 1) && (curDate.Day <= 19))
                    {
                        invoiceDate = new DateTime(year, curMonth, 20);
                    }
                    //get next month
                    else
                    {
                        if (nextMonth == 1)
                        {
                            invoiceDate = new DateTime(nextyear, nextMonth, 20);
                        }
                        else
                        {
                            //if next month is jan, then account for next year
                            invoiceDate = new DateTime(year, nextMonth, 20);
                        };
                    }

                    invoiceAddRq.TxnDate.SetValue(invoiceDate);
                    invoiceAddRq.CustomerRef.ListID.SetValue(invoice.Customer.QuickBooksID);

                    /////////////////////////////////////////////////////////////////////////////////
                    if (invoiceItem1.Amount >= 0)
                    {
                        if (invoiceItem1.Amount == 0)
                        {
                            string msg = "Warning: Invoice = $0 for" + szCustomerName;
                            MMSUtility.LogFile(msg, "", "AddModQBInvoice", 0, "QBBatchInvoiceDialog");
                        }

                        IORInvoiceLineAdd orInvoiceLineAdd1 = invoiceAddRq.ORInvoiceLineAddList.Append();
                        orInvoiceLineAdd1.InvoiceLineAdd.ItemRef.ListID.SetValue(item1.QuickBooksID);
                        orInvoiceLineAdd1.InvoiceLineAdd.ServiceDate.SetValue(invoiceItem1.Date);
                        orInvoiceLineAdd1.InvoiceLineAdd.Amount.SetValue(invoiceItem1.Amount);
                        orInvoiceLineAdd1.InvoiceLineAdd.Quantity.SetValue(invoiceItem1.Quantity);
                        orInvoiceLineAdd1.InvoiceLineAdd.Desc.SetValue(invoiceItem1.Description);
                        bItemInvoice1 = true;
                    }
                    //Send the request and get the response from QuickBooks
                    responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                    response = responseMsgSet.ResponseList.GetAt(0);
                    IInvoiceRet invoiceRet = (IInvoiceRet)response.Detail;

                    if (bItemInvoice1)
                        invoiceItem1.QuickBooksID = invoiceRet.ORInvoiceLineRetList.GetAt(0).InvoiceLineRet.TxnLineID.GetValue();

                    invoice.QuickBooksID = invoiceRet.TxnID.GetValue();
                    invoiceID = invoice.QuickBooksID;
                }
                else
                {
                    //get the latest invoice
                    IInvoiceRet invoiceRet = invoiceRetList.GetAt(numIndex);
                    var invoice = new Invoice
                    {
                        Customer = customer,
                        QuickBooksID = invoiceRet.TxnID.GetValue(),
                        EditSequence = invoiceRet.EditSequence.GetValue()
                    };
                    //invoiceRet.TxnNumber.GetValue();

                    requestMsgSet.ClearRequests();
                    IInvoiceMod invoiceModRq = requestMsgSet.AppendInvoiceModRq();
                    invoiceModRq.TxnID.SetValue(invoice.QuickBooksID);
                    invoiceModRq.EditSequence.SetValue(invoice.EditSequence);

                    //if no assocated item, then add new item to the current invoice //andy change this
                    if (invoiceRet.ORInvoiceLineRetList != null)
                    {
                        for (int j = 0; j < invoiceRet.ORInvoiceLineRetList.Count; j++)
                        {
                            IORInvoiceLineRet ORInvoiceLineRet = invoiceRet.ORInvoiceLineRetList.GetAt(j);

                            if (itemA_ID != ORInvoiceLineRet.InvoiceLineRet.TxnLineID.GetValue())
                            {
                                IORInvoiceLineMod ORinvoicemod1 = invoiceModRq.ORInvoiceLineModList.Append();
                                ORinvoicemod1.InvoiceLineMod.TxnLineID.SetValue(ORInvoiceLineRet.InvoiceLineRet.TxnLineID.GetValue());
                            }
                        }
                    }

                    //this add the new line
                    if (invoiceItem1.Amount >= 0)
                    {
                        if (invoiceItem1.Amount == 0) {
                            string msg = "Warning: Invoice = $0 for" + szCustomerName;
                            MMSUtility.LogFile(msg, "", "AddModQBInvoice", 0, "QBBatchInvoiceDialog");
                        }

                        IORInvoiceLineMod ORinvoicemod1 = invoiceModRq.ORInvoiceLineModList.Append();
                        ORinvoicemod1.InvoiceLineMod.TxnLineID.SetValue("-1");
                        ORinvoicemod1.InvoiceLineMod.ServiceDate.SetValue(invoiceItem1.Date);
                        ORinvoicemod1.InvoiceLineMod.ItemRef.ListID.SetValue(item1.QuickBooksID);
                        ORinvoicemod1.InvoiceLineMod.Amount.SetValue(invoiceItem1.Amount);
                        ORinvoicemod1.InvoiceLineMod.Quantity.SetValue(invoiceItem1.Quantity);
                        ORinvoicemod1.InvoiceLineMod.Desc.SetValue(invoiceItem1.Description);
                        bItemInvoice1 = true;

                    }

                    //Send the request and get the response from QuickBooks
                    responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                    response = responseMsgSet.ResponseList.GetAt(0);
                    invoiceRet = (IInvoiceRet)response.Detail;

                    invoice.QuickBooksID = invoiceRet.TxnID.GetValue();
                    invoiceID = invoice.QuickBooksID;

                    int nIndex = invoiceRet.ORInvoiceLineRetList.Count - 1;
                    if (bItemInvoice1)
                        invoiceItem1.QuickBooksID = invoiceRet.ORInvoiceLineRetList.GetAt(nIndex).InvoiceLineRet.TxnLineID.GetValue();

                }

            }
            catch (Exception ex)
            {
                MMSUtility.LogFile(ex.Message, "", "AddModQBInvoice", ex.LineNumber(), "QBBatchInvoiceDialog");
                MessageBox.Show(ex.Message, "Error");
            }
            finally
            {
                //End the session and close the connection to QuickBooks
                if (sessionBegun)
                {
                    sessionManager.EndSession();
                }
                if (connectionOpen)
                {
                    sessionManager.CloseConnection();
                }
            }
            return invoiceID;
        }
Пример #2
0
        private void QBUpdateCustomerRecord(Customer theCustomer)
        {
            bool sessionBegun = false;
            bool connectionOpen = false;
            QBSessionManager sessionManager = null;

            try
            {
                //Create the session Manager object
                sessionManager = new QBSessionManager();

                //Create the message set request object to hold our request
                IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 2, 0);
                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

                sessionManager.OpenConnection(MMSUtility.QBAppID, MMSUtility.QBAppName);
                connectionOpen = true;
                sessionManager.BeginSession("", ENOpenMode.omDontCare);
                sessionBegun = true;

                //modify the info
                ICustomerMod customerModRq = requestMsgSet.AppendCustomerModRq();
                //if (theCustomer.FirstName.Length > 0)
                customerModRq.Name.SetValue(theCustomer.Name);
                //if (theCustomer.FirstName.Length > 0)
                customerModRq.FirstName.SetValue(theCustomer.FirstName);
                //if (theCustomer.LastName.Length > 0)
                customerModRq.LastName.SetValue(theCustomer.LastName);
                //if (theCustomer.Address.Length > 0)
                string szName = theCustomer.FirstName + " " + theCustomer.LastName;
                customerModRq.BillAddress.Addr1.SetValue(szName);
                customerModRq.BillAddress.Addr2.SetValue(theCustomer.Address);
                //if (theCustomer.City.Length > 0)
                customerModRq.BillAddress.City.SetValue(theCustomer.City);
                //if (theCustomer.State.Length > 0)
                customerModRq.BillAddress.State.SetValue(theCustomer.State);
                //if (theCustomer.Zip.Length > 0)
                customerModRq.BillAddress.PostalCode.SetValue(theCustomer.Zip);
                //if (theCustomer.Phone.Length > 0)
                customerModRq.Phone.SetValue(theCustomer.Phone);
                //if (theCustomer.Email.Length > 0)
                customerModRq.Email.SetValue(theCustomer.Email);
                //if (theCustomer.Company.Length > 0)
                customerModRq.CompanyName.SetValue(theCustomer.Company);
                //if (theCustomer.Terms.Length > 0) customerModRq.TermsRef.FullName.SetValue(theCustomer.Terms);
                customerModRq.ListID.SetValue(theCustomer.QuickBooksID);
                customerModRq.EditSequence.SetValue(theCustomer.EditSequence);
                //customerModRq.IsActive.SetValue(true);

                //Send the request to QuickBooks
                IMsgSetResponse responsMsgSet = sessionManager.DoRequests(requestMsgSet);
            }
            catch (Exception exe)
            {
                MMSUtility.LogFile(exe.Message, "", "QBUpdateCustomerRecord", exe.LineNumber(), "CustomerView");
                MessageBox.Show(exe.Message, "Error: Failed to Update");
            }
            finally
            {
                //End the session and close the connection to QuickBooks
                if (sessionBegun)
                {
                    sessionManager.EndSession();
                }
                if (connectionOpen)
                {
                    sessionManager.CloseConnection();
                }
            }
        }
Пример #3
0
        private bool QBGetCustomerRecord(Customer theCustomer)
        {
            bool sessionBegun = false;
            bool connectionOpen = false;
            QBSessionManager sessionManager = null;
            bool nFound = false;

            try
            {
                //Create the session Manager object
                sessionManager = new QBSessionManager();

                //Create the message set request object to hold our request
                IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 2, 0);
                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

                sessionManager.OpenConnection(MMSUtility.QBAppID, MMSUtility.QBAppName);
                connectionOpen = true;
                sessionManager.BeginSession("", ENOpenMode.omDontCare);
                sessionBegun = true;

                //find the customer info
                ICustomerQuery search = requestMsgSet.AppendCustomerQueryRq();
                search.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameFilter.MatchCriterion.SetValue(ENMatchCriterion.mcStartsWith);
                search.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameFilter.Name.SetValue(theCustomer.Name);

                IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                IResponse response = responseMsgSet.ResponseList.GetAt(0);
                ICustomerRetList customerRetList = (ICustomerRetList)response.Detail;
                if (customerRetList != null)
                {
                    ICustomerRet customerRet = customerRetList.GetAt(0);
                    if (customerRet.ListID != null) theCustomer.QuickBooksID = customerRet.ListID.GetValue();
                    if (customerRet.EditSequence != null) theCustomer.EditSequence = customerRet.EditSequence.GetValue();
                    if (customerRet.FirstName != null) theCustomer.FirstName = customerRet.FirstName.GetValue();
                    if (customerRet.LastName != null) theCustomer.LastName = customerRet.LastName.GetValue();
                    if (customerRet.BillAddress != null)
                    {
                        if (customerRet.BillAddress.Addr1 != null) theCustomer.Address = customerRet.BillAddress.Addr1.GetValue();
                        if (customerRet.BillAddress.City != null) theCustomer.City = customerRet.BillAddress.City.GetValue();
                        if (customerRet.BillAddress.State != null) theCustomer.State = customerRet.BillAddress.State.GetValue();
                        if (customerRet.BillAddress.PostalCode != null) theCustomer.Zip = customerRet.BillAddress.PostalCode.GetValue();
                    }
                    if (customerRet.Phone != null) theCustomer.Phone = customerRet.Phone.GetValue();
                    if (customerRet.Email != null) theCustomer.Email = customerRet.Email.GetValue();
                    if (customerRet.CompanyName != null) theCustomer.Company = customerRet.CompanyName.GetValue();
                    if (customerRet.IsActive != null) theCustomer.Active = customerRet.IsActive.GetValue();
                    if (customerRet.TermsRef != null) theCustomer.Terms = customerRet.TermsRef.FullName.GetValue();
                    nFound = true;
                }
                else
                {
                    nFound = false;
                }
            }
            catch (Exception exe)
            {
                string thename = theCustomer.FirstName + " " + theCustomer.LastName;
                MMSUtility.LogFile(exe.Message, thename, "QBGetCustomerRecord", exe.LineNumber(), "CustomerView");
                MessageBox.Show(exe.Message, "Error");
            }
            finally
            {
                //End the session and close the connection to QuickBooks
                if (sessionBegun)
                {
                    sessionManager.EndSession();
                }
                if (connectionOpen)
                {
                    sessionManager.CloseConnection();
                }
            }
            return nFound;
        }
Пример #4
0
        private void QBAddCustomer(Customer theCustomer)
        {
            bool sessionBegun = false;
            bool connectionOpen = false;
            QBSessionManager sessionManager = null;

            try
            {
                //Create the session Manager object
                sessionManager = new QBSessionManager();

                //Create the message set request object to hold our request
                IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 2, 0);
                requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;

                sessionManager.OpenConnection(MMSUtility.QBAppID, MMSUtility.QBAppName);
                connectionOpen = true;
                sessionManager.BeginSession("", ENOpenMode.omDontCare);
                sessionBegun = true;

                ICustomerAdd customerAddRq = requestMsgSet.AppendCustomerAddRq();
                customerAddRq.Name.SetValue(theCustomer.Name);
                customerAddRq.FirstName.SetValue(theCustomer.FirstName);
                customerAddRq.LastName.SetValue(theCustomer.LastName);

                string szName = theCustomer.FirstName + " " + theCustomer.LastName;
                customerAddRq.BillAddress.Addr1.SetValue(szName);
                customerAddRq.BillAddress.Addr2.SetValue(theCustomer.Address);
                customerAddRq.BillAddress.City.SetValue(theCustomer.City);
                customerAddRq.BillAddress.State.SetValue(theCustomer.State);
                customerAddRq.BillAddress.PostalCode.SetValue(theCustomer.Zip);
                customerAddRq.Phone.SetValue(theCustomer.Phone);
                customerAddRq.Email.SetValue(theCustomer.Email);
                customerAddRq.CompanyName.SetValue(theCustomer.Company);
                customerAddRq.IsActive.SetValue(theCustomer.Active);
                customerAddRq.TermsRef.FullName.SetValue(theCustomer.Terms);

                //Send the request and get the response from QuickBooks
                IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
                IResponse response = responseMsgSet.ResponseList.GetAt(0);
                ICustomerRet customerRet = (ICustomerRet)response.Detail;
                theCustomer.QuickBooksID = customerRet.ListID.GetValue();
            }
            catch (Exception exe)
            {
                string theName = theCustomer.LastName + "," + theCustomer.FirstName
                    + "," + theCustomer.Address + ",C:" + theCustomer.City + ",S:" + theCustomer.State + "'Z:" + theCustomer.Zip
                    + ",P" + theCustomer.Phone + ",E" + theCustomer.Email + ",A" + theCustomer.Active + ",T" + theCustomer.Terms;
                MMSUtility.LogFile(exe.Message, theName, "QBAddCustomer", exe.LineNumber(), "CustomerView");
                MessageBox.Show(exe.Message, "Error");

            }
            finally
            {
                //End the session and close the connection to QuickBooks
                if (sessionBegun)
                {
                    sessionManager.EndSession();
                }
                if (connectionOpen)
                {
                    sessionManager.CloseConnection();
                }
            }
        }
Пример #5
0
        private void editCustButton_Click(object sender, EventArgs e)
        {
            MainForm pParent = (MainForm)this.ParentForm;
            nSavedIndex = this.customerDataGridView1.CurrentRow.Index;

            if (editCustButton.Text == "Edit")
            {
                EnableControls(true);
                editCustButton.Text = "Save";
                addCustButton.Enabled = false;
                bCancelMode = 2;
                editCustButton.BackColor = System.Drawing.Color.Salmon;
                pParent.enableMainButtons(false);
                tabPage2.Enabled = false;

            }
            else  //save
            {

                Cursor.Current = Cursors.WaitCursor;

                lastNameTextBox.Text = lastNameTextBox.Text.Trim();
                firstNameTextBox.Text = firstNameTextBox.Text.Trim();

                addCustButton.Enabled = true;
                editCustButton.Text = "Edit";
                tabPage2.Enabled = true;
                this.Validate();
                this.customerBindingSource.EndEdit();
                this.tableAdapterManager.UpdateAll(this.mMSDataSet);

                EnableControls(false);
                MMSUtility.PlayAcceptSound();
                editCustButton.BackColor = System.Drawing.Color.Transparent;
                pParent.enableMainButtons(true);
                bCancelMode = 0;

                if (MMSUtility.UserPref.QBIntegration)
                {
                    Customer theCustomer = new Customer();
                    theCustomer.FirstName = firstNameTextBox.Text;
                    theCustomer.LastName = lastNameTextBox.Text;
                    if (theCustomer.FirstName.Length > 0)
                        theCustomer.Name = theCustomer.LastName + ", " + theCustomer.FirstName;
                    else
                        theCustomer.Name = theCustomer.LastName;

                    pParent.SetStatusLabelTimer(5, "Customer Updated....");

                    if (QBGetCustomerRecord(theCustomer))
                    {
                        //update info
                        theCustomer.Address = addressTextBox.Text;
                        theCustomer.City = cityTextBox.Text;
                        theCustomer.State = stateTextBox.Text;
                        theCustomer.Zip = zipTextBox.Text;
                        theCustomer.Phone = phone1TextBox.Text;
                        theCustomer.Email = emailTextBox.Text;
                        theCustomer.Company = businessNameTextBox.Text;
                        theCustomer.Active = activeCheckBox.Checked;

                        QBUpdateCustomerRecord(theCustomer);
                        pParent.SetStatusLabelTimer(5, "QB Updated....");
                    }
                    else
                    {
                        string ErroMsg = theCustomer.Name + " - not Found in QuickBooks!!\nPlease Check or press Yes to add to QB";
                        if (MessageBox.Show(ErroMsg, "Error", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            theCustomer.Address = addressTextBox.Text;
                            theCustomer.City = cityTextBox.Text;
                            theCustomer.State = stateTextBox.Text;
                            theCustomer.Zip = zipTextBox.Text;
                            theCustomer.Phone = phone1TextBox.Text;
                            theCustomer.Email = emailTextBox.Text;
                            theCustomer.Company = businessNameTextBox.Text;
                            theCustomer.Active = activeCheckBox.Checked;

                            QBAddCustomer(theCustomer);
                            pParent.SetStatusLabelTimer(5, "QB Updated....");
                      }
                    }
                }
                Cursor.Current = Cursors.Default;
            }
        }
Пример #6
0
        private void addCustButton_Click(object sender, EventArgs e)
        {
            MainForm pParent = (MainForm)this.ParentForm;

            if (addCustButton.Text == "Add")
            {
                clearFilter();

                if (this.customerDataGridView1.CurrentRow != null)
                    nSavedIndex = this.customerDataGridView1.CurrentRow.Index;

                EnableControls(true);
                editCustButton.Enabled = false;
                addCustButton.Text = "Save";
                bCancelMode = 1;

                //customerDataGridView1.ReadOnly = false;
                customerDataGridView1.Enabled = false;
                enablePropertyGrid(false);
                filterTextBox.Enabled = false;
                //custFilterComboBox.Enabled = false;
                //customerBindingNavigator.Enabled = false;

                customerBindingSource.AddNew();
                addCustButton.BackColor = System.Drawing.Color.Salmon;
                pParent.enableMainButtons(false);
            }
            else  //save
            {
                if (lastNameTextBox.Text.Length > 0)
                {
                    Cursor.Current = Cursors.WaitCursor;

                    if (this.customerDataGridView1.CurrentRow != null)
                        nSavedIndex = this.customerDataGridView1.CurrentRow.Index;

                    editCustButton.Enabled = true;
                    addCustButton.Text = "Add";

                    this.Validate();
                    this.customerBindingSource.EndEdit();
                    this.tableAdapterManager.UpdateAll(this.mMSDataSet);
                    EnableControls(false);
                    addCustButton.BackColor = System.Drawing.Color.Transparent;
                    MMSUtility.PlayAcceptSound();

                    filterTextBox.Enabled = true;
                    pParent.enableMainButtons(true);
                    //customerDataGridView1.ReadOnly = true;
                    customerDataGridView1.Enabled = true;
                    customerBindingNavigator.Enabled = true;
                    filterTextBox.Enabled = true;
                    enablePropertyGrid(true);
                    bCancelMode = 0;

                    int index = this.customerDataGridView1.CurrentRow.Index;
                    this.customerDataGridView1.Rows[index].Cells[10].Value = "Current";
                    try
                    {
                        //Add property
                        if (addFirstProperty(index))
                        {
                            pParent.SetStatusLabelTimer(5, "Customer and initial property Added....");

                        }
                        else
                        {
                            MessageBox.Show("First Customer Property addition failed!");
                        }
                    }
                    catch (Exception exe)
                    {
                        MMSUtility.LogFile(exe.Message, e.ToString(), ((Control)sender).Name, exe.LineNumber(), "CustomerView");
                    }

                    //add to QB
                    if (MMSUtility.UserPref.QBIntegration)
                    {
                        Customer theCustomer = new Customer();
                        theCustomer.FirstName = firstNameTextBox.Text;
                        theCustomer.LastName = lastNameTextBox.Text;
                        theCustomer.Address = addressTextBox.Text;
                        theCustomer.City = cityTextBox.Text;
                        theCustomer.State = stateTextBox.Text;
                        theCustomer.Zip = zipTextBox.Text;
                        theCustomer.Phone = phone1TextBox.Text;
                        theCustomer.Email = emailTextBox.Text;
                        theCustomer.Company = businessNameTextBox.Text;
                        theCustomer.Active = activeCheckBox.Checked;
                        theCustomer.Name = theCustomer.LastName + ", " + theCustomer.FirstName;
                        if (theCustomer.FirstName == "") theCustomer.Name = theCustomer.LastName;
                        try
                        {
                            QBAddCustomer(theCustomer);
                        }
                        catch (Exception exe)
                        {
                            MMSUtility.LogFile(exe.Message, e.ToString(), ((Control)sender).Name, exe.LineNumber(), "CustomerView");
                        }

                        pParent.SetStatusLabelTimer(5, "QB Updated....");
                    }
                    Cursor.Current = Cursors.Default;
                }
                else
                {
                    MessageBox.Show("Please fill last name field");
                }
            }
        }