Exemplo n.º 1
0
 /* a supporting method that take a BPvalues object and display the value on the controls */
 private void ShowResult(BPvalues display)
 {
     resultPhoneTextbox.Text   = display.Phone;
     resultEmailTextbox.Text   = display.Email;
     resultCompanyTextbox.Text = display.Company;
 }
Exemplo n.º 2
0
        /* search button click that search the customer from brightpearl database from the given information */
        protected void searchButton_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            // set warning invisible
            tooManyResultLabel.Visible = false;

            // get data from textboxes
            string firstName = searchFirstNameTextbox.Text;
            string lastName  = searchLastNameTextbox.Text;
            string company   = searchCompanyTextbox.Text;
            string email     = searchEmailTextbox.Text;

            #region Error Checking
            // the case if user haven't provide any thing about customer
            if (firstName.Equals("") && lastName.Equals("") && company.Equals("") && email.Equals(""))
            {
                const string script = "<script>alert(\"Please provide some information about the customer\");</script>";
                Page.ClientScript.RegisterStartupScript(GetType(), "Scripts", script);
                searchPopup.Show();

                return;
            }
            #endregion

            #region Searching and Adding
            // supporting local field -> [0] name, [1] contact info
            BPvalues[][] list = new BPvalues[2][];

            // search with name
            if (firstName != "" && lastName != "")      // the case both firstname and lastname are supplied
            {
                list[0] = bp.GetCustomerWithName(firstName, lastName, 3);
            }
            else if (firstName != "" && lastName == "") // the case only firstname is supplied
            {
                list[0] = bp.GetCustomerWithName(firstName, null, 1);
            }
            else if (firstName == "" && lastName != "") // the case only lastname is supplied
            {
                list[0] = bp.GetCustomerWithName(null, lastName, 2);
            }
            else
            {
                list[0] = null;
            }

            // search with contact info
            if (company != "" && email != "")           // the case both company and email are supplied
            {
                list[1] = bp.GetCustomerWithInfo(email, company, 3);
            }
            else if (company != "" && email == "")      // the case only company is supplied
            {
                list[1] = bp.GetCustomerWithInfo(null, company, 2);
            }
            else if (company == "" && email != "")      // the case only email is supplied
            {
                list[1] = bp.GetCustomerWithInfo(email, null, 1);
            }
            else
            {
                list[1] = null;
            }

            // allocating data
            if (list[0] != null && list[1] != null)
            {
                value = list[0].Length < list[1].Length ? list[0] : list[1];
            }
            else if (list[0] == null)
            {
                value = list[1];
            }
            else if (list[1] == null)
            {
                value = list[0];
            }
            #endregion

            // the case if there is no result or there are too many result
            if (value == null)
            {
                const string script = "<script>alert(\"There is no result of this customer. Please enter information manually\");</script>";
                Page.ClientScript.RegisterStartupScript(GetType(), "Scripts", script);
                searchPopup.Show();

                return;
            }
            if (value[0].FirstName == "-1")
            {
                tooManyResultLabel.Visible = true;
                searchPopup.Show();

                return;
            }

            // sort array by first name
            value = value.OrderBy(s => s.FirstName).ToArray();

            // show all the result
            listbox.Items.Clear();
            foreach (BPvalues result in value)
            {
                ListItem item = new ListItem(result.FirstName + ' ' + result.LastName);
                listbox.Items.Add(item);
            }
            ShowResult(value[0]);

            // show result panel
            searchPopup.Hide();
            resultPopup.Show();

            // save viewstate
            ViewState["Value"] = value;
        }
Exemplo n.º 3
0
        /* the event for quote button clicks that will call login panel if the user has not logged in and create quote */
        protected void quoteButton_Click(object sender, ImageClickEventArgs e)
        {
            #region Error Checking
            // get table
            DataTable table = (DataTable)ViewState["DataTable"];

            if (firstNameTextbox.Text == "" || lastNameTextbox.Text == "" || address1Textbox.Text == "" || cityTextbox.Text == "" || dateDeliveryTextbox.Text == "" ||
                provinceTextbox.Text == "" || postalCodeTextbox.Text == "" || countryTextbox.Text == "" || table.Rows.Count < 1)
            {
                const string script = "alert(\"Please provide information on all the necessary fields (*)\");";
                ScriptManager.RegisterStartupScript(Page, GetType(), "ClientScript", script, true);
                return;
            }
            #endregion

            // set new quote created label to invisible
            newQuoteCreatedLabel.Visible = false;

            // local fields for BPvalue generation
            List <string> skuList         = new List <string>();
            List <string> descriptionList = new List <string>();
            List <int>    qtyList         = new List <int>();
            List <double> basePriceList   = new List <double>();
            List <int>    pricingTierList = new List <int>();
            List <bool>   giftBoxList     = new List <bool>();
            int[]         count           = { rushCheckboxList.Items.Cast <ListItem>().Count(li => li.Selected), logoCheckboxList.Items.Cast <ListItem>().Count(li => li.Selected) };

            #region Email
            // get the order detail
            string orderDetail = "Customer Information:\n\r" +
                                 "Name: " + firstNameTextbox.Text + " " + lastNameTextbox.Text + "\nPhone: " + phoneTextbox.Text + "\nEmail: " + emailTextbox.Text + "\nCompany: " + companyTextbox.Text
                                 + "\nAddress1: " + address1Textbox.Text + "\nAddress2: " + address2Textbox.Text + "\nCity: " + cityTextbox.Text + "\nProvince / State: " + provinceTextbox.Text +
                                 "\nPostal Code: " + postalCodeTextbox.Text + "\nCountry: " + countryTextbox.Text + "\n\n\r" +
                                 "Order Detail:\n\r" +
                                 "Rush Order: ";
            if (count[0] > 1)
            {
                orderDetail += "Yes, No\n";
            }
            else if (rushCheckboxList.SelectedIndex == 0)
            {
                orderDetail += "Yes\n";
            }
            else
            {
                orderDetail += "No\n";
            }
            orderDetail += "With Logo: ";
            if (count[1] > 1)
            {
                orderDetail += "Yes, No";
            }
            else if (logoCheckboxList.SelectedIndex == 1)
            {
                orderDetail += "No";
            }
            else
            {
                orderDetail += "Yes";
            }
            for (int i = 0; i < table.Rows.Count; i++)
            {
                orderDetail += "\n\nItem " + (i + 1) + ": " + table.Rows[i][0] + "\nShort Description: " + table.Rows[i][1] + "\nGift Box: " + table.Rows[i][2] + "\nQuantity: " + table.Rows[i][3];

                // adding item to the lists
                skuList.Add(table.Rows[i][0].ToString());
                descriptionList.Add(table.Rows[i][1].ToString());
                giftBoxList.Add(Convert.ToBoolean(table.Rows[i][2]));
                qtyList.Add(Convert.ToInt32(table.Rows[i][3]));
                basePriceList.Add(Convert.ToDouble(table.Rows[i][4]));
                pricingTierList.Add(Convert.ToInt32(table.Rows[i][5]));
            }
            orderDetail += "\n\nDelivery Date: " + dateDeliveryTextbox.Text + "\n\nAdditional Info:\n" + additionalInfoTextbox.Text;

            // send message
            var mail   = new System.Net.Mail.MailMessage();
            var client = new System.Net.Mail.SmtpClient("smtp.gmail.com");

            mail.From = new System.Net.Mail.MailAddress("*****@*****.**");
            mail.To.Add("*****@*****.**");
            mail.To.Add(staffDropdownlist.SelectedValue.Substring(staffDropdownlist.SelectedValue.IndexOf(';') + 1));
            mail.Subject = "NEW ORDER QUOTE";
            mail.Body    = orderDetail;

            client.Port        = 587;
            client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "AshlinIntern2");
            client.EnableSsl   = true;
            client.Send(mail);
            #endregion

            #region Brightpearl
            // declare BPvalues object
            BPvalues bpValue = new BPvalues(firstNameTextbox.Text, lastNameTextbox.Text, companyTextbox.Text, phoneTextbox.Text, emailTextbox.Text, address1Textbox.Text, address2Textbox.Text, cityTextbox.Text, provinceTextbox.Text,
                                            postalCodeTextbox.Text, countryTextbox.Text, staffDropdownlist.SelectedValue.Remove(staffDropdownlist.SelectedValue.IndexOf(';')), skuList, descriptionList, qtyList, basePriceList, pricingTierList, giftBoxList,
                                            true, false, additionalInfoTextbox.Text, DateTime.ParseExact(dateDeliveryTextbox.Text, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));

            // price list determination
            if (count[0] > 1)
            {
                if (count[1] > 1)
                {
                    // 4 cases
                    // 1 st case
                    bpValue.Rush = true;
                    bpValue.Logo = true;
                    bp.PostOrder(bpValue);
                    // 2nd case
                    bpValue.Rush = true;
                    bpValue.Logo = false;
                    bp.PostOrder(bpValue);
                    // 3rd case
                    bpValue.Rush = false;
                    bpValue.Logo = true;
                    bp.PostOrder(bpValue);
                    // 4th case
                    bpValue.Rush = false;
                    bpValue.Logo = false;
                    bp.PostOrder(bpValue);
                }
                else if (logoCheckboxList.SelectedIndex == 1)
                {
                    // 2 cases
                    // 1st case
                    bpValue.Rush = true;
                    bpValue.Logo = false;
                    bp.PostOrder(bpValue);
                    // 2nd case
                    bpValue.Rush = false;
                    bpValue.Logo = false;
                    bp.PostOrder(bpValue);
                }
                else
                {
                    // 2 cases
                    // 1st case
                    bpValue.Rush = true;
                    bpValue.Logo = true;
                    bp.PostOrder(bpValue);
                    // 2nd case
                    bpValue.Rush = false;
                    bpValue.Logo = true;
                    bp.PostOrder(bpValue);
                }
            }
            else if (rushCheckboxList.SelectedIndex == 0)
            {
                if (count[1] > 1)
                {
                    // 2 cases
                    // 1 st case
                    bpValue.Rush = true;
                    bpValue.Logo = true;
                    bp.PostOrder(bpValue);
                    // 2nd case
                    bpValue.Rush = true;
                    bpValue.Logo = false;
                    bp.PostOrder(bpValue);
                }
                else if (logoCheckboxList.SelectedIndex == 1)
                {
                    // 1 case
                    bpValue.Rush = true;
                    bpValue.Logo = false;
                    bp.PostOrder(bpValue);
                }
                else
                {
                    // 1 case
                    bpValue.Rush = true;
                    bpValue.Logo = true;
                    bp.PostOrder(bpValue);
                }
            }
            else
            {
                if (count[1] > 1)
                {
                    // 2 cases
                    // 1 st case
                    bpValue.Rush = false;
                    bpValue.Logo = true;
                    bp.PostOrder(bpValue);
                    // 2nd case
                    bpValue.Rush = false;
                    bpValue.Logo = false;
                    bp.PostOrder(bpValue);
                }
                else if (logoCheckboxList.SelectedIndex == 1)
                {
                    // 1 case
                    bpValue.Rush = false;
                    bpValue.Logo = false;
                    bp.PostOrder(bpValue);
                }
                else
                {
                    // 1 case
                    bpValue.Rush = false;
                    bpValue.Logo = true;
                    bp.PostOrder(bpValue);
                }
            }
            #endregion

            // set new quote created label to visible
            newQuoteCreatedLabel.Visible = true;
        }
Exemplo n.º 4
0
        /* asi next button click that search the company info from the user input asi number */
        protected void asiNextButton_Click(object sender, EventArgs e)
        {
            // reset textbox color
            asiTextbox.BackColor = Color.White;

            if (asiTextbox.Text != "")
            {
                // get company information from the asi number that user entered
                BPvalues asiValue = asi.GetCompanyInfo(asiTextbox.Text);

                // the case if the asi number does not exist -> return
                if (asiValue == null)
                {
                    asiTextbox.BackColor = Color.Red;
                    asiPopup.Show();

                    return;
                }

                // search result by company name
                value = bp.GetCustomerWithInfo(null, asiValue.Company, 2);

                #region Error Check
                // the case if there is no result or there are too many result
                if (value == null)
                {
                    // inform user there is not existing cusomter on the database from the company
                    const string script = "<script>alert(\"There is no customer exist from this company. Please enter information manually\");</script>";
                    Page.ClientScript.RegisterStartupScript(GetType(), "Scripts", script);

                    // show company info on the form
                    phoneTextbox.Text      = asiValue.Phone;
                    emailTextbox.Text      = asiValue.Email;
                    companyTextbox.Text    = asiValue.Company;
                    address1Textbox.Text   = asiValue.Address1;
                    address2Textbox.Text   = asiValue.Address2;
                    cityTextbox.Text       = asiValue.City;
                    provinceTextbox.Text   = asiValue.Province;
                    postalCodeTextbox.Text = asiValue.PostalCode;
                    countryTextbox.Text    = asiValue.Country;

                    firstNameTextbox.Text = string.Empty;
                    lastNameTextbox.Text  = string.Empty;

                    return;
                }

                if (value[0].FirstName == "-1")
                {
                    tooManyResultLabel.Visible = true;
                    searchPopup.Show();

                    return;
                }
                #endregion

                // sort array by first name
                value = value.OrderBy(s => s.FirstName).ToArray();

                // show all the result
                listbox.Items.Clear();
                foreach (BPvalues result in value)
                {
                    ListItem item = new ListItem(result.FirstName + ' ' + result.LastName);
                    listbox.Items.Add(item);
                }
                ShowResult(value[0]);

                // show result panel
                asiPopup.Hide();
                resultPopup.Show();

                // save viewstate
                ViewState["Value"] = value;
            }
            else
            {
                // the case if user did not put anything on the textbox -> signal them
                asiTextbox.BackColor = Color.Red;
                asiPopup.Show();
            }
        }