コード例 #1
0
        private void saveBtn_Click(object sender, EventArgs e)
        {
            var tempId   = 0;
            var name     = nameIn.Text;
            var address  = addressIn.Text;
            var address2 = address2In.Text;
            var city     = cityIn.Text;

            switch (city)
            {
            case "Phoenix":
                city = "1";
                break;

            case "New York":
                city = "2";
                break;

            case "London":
                city = "3";
                break;
            }
            var postal  = postalIn.Text;
            var country = countryIn.Text;

            switch (country)
            {
            case "USA":
                country = "1";
                break;

            case "United Kingdom":
                country = "2";
                break;
            }
            var phone = phoneIn.Text.ToString();

            Customers add = new Customers(tempId, name, address, address2, postal, city, country, phone);

            if (Repo.AddCustomer(add))
            {
                CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.TwoLetterISOLanguageName);
                MessageBox.Show(rm.GetString("cust add", ci));
                ci.ClearCachedData();
                this.Close();
                CustomerScreen customerScreen = new CustomerScreen();
                customerScreen.Show();
                ci.ClearCachedData();
            }
            else
            {
                CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.TwoLetterISOLanguageName);
                MessageBox.Show(rm.GetString("cust not added", ci));
                ci.ClearCachedData();
            }
        }
コード例 #2
0
        public ActionResult Create(CustomerModel customer)
        {
            try
            {
                // TODO: Add insert logic here
                var cust = new CustomerImp
                {
                    FirstName      = customer.FirstName,
                    LastName       = customer.LastName,
                    DefaultStoreId = customer.DefaultStoreId
                };

                TempData["Current Customer"] = _db.Customers.Max(c => c.CustomerId) + 1;

                Repo.AddCustomer(cust);
                return(RedirectToAction("Index", "Orders"));
            }
            catch
            {
                return(View(customer));
            }
        }
コード例 #3
0
ファイル: Menu.cs プロジェクト: 1909-sep30-net/sam-project0
        /// <summary>
        /// Customer menu include searching current customer and adding new customer
        /// After that will go to placing order menu.
        /// </summary>
        public void CustomerMenu()
        {
            int poMenu = 0;

            Console.WriteLine("If you are a new customer, press 1");
            Console.WriteLine("to add new customer.");
            Console.WriteLine("Or press 2 to search your name.");;
            Console.WriteLine("--------");
            Console.WriteLine("press 0 to back to Mainmenu.");
            Console.WriteLine("----------------------");
            Console.WriteLine("Please Enter: ");
            try
            {
                poMenu = Int32.Parse(Console.ReadLine());
            }
            catch (FormatException ex)
            {
                logger.Error("(Customer Menu)Invalid input format  " + ex.Message);
                poMenu = InputCheckInt(-1, 2);
            }

            switch (poMenu)
            {
            ///<summary>
            ///Function to add new customer, then pass it to data access project
            ///include firtname, last name, phone number and favorite store.
            ///</summary>
            case 1:
                Console.WriteLine("Please Enter your first name:");
                string fNameInput = Console.ReadLine();
                string fName      = NameFormat(fNameInput);
                Console.WriteLine("Please Enter your last name: ");
                string lNameInput = Console.ReadLine();
                string lName      = NameFormat(lNameInput);
                Console.WriteLine("Please enter your 10 digit phone number ");
                Console.WriteLine("without () or - :   ");
                string phone = Console.ReadLine();
                phone = PhoneCheck(phone);
                Console.WriteLine("Please enter your default store: ");
                int favStore = 0;
                try
                {
                    favStore = Int32.Parse(Console.ReadLine());
                }
                catch (FormatException ex)
                {
                    logger.Error("(New Customer)Invalid input format: " + ex.Message);
                    favStore = InputCheckInt(favStore, 999999);
                }
                Repo  newGuys    = new Repo();
                Store storeFound = newGuys.CheckIfStoreExists(favStore);
                if (storeFound != null)
                {
                    Console.WriteLine($"Your first name is     {fName}");
                    Console.WriteLine($"Your last name is      {lName}");
                    Console.WriteLine($"Your phone number is   {phone}");
                    Console.WriteLine($"Your favorite Store is {storeFound.StoreName}");
                    Console.WriteLine($"Is That correct?(y/n):   ");

                    string confirm = "";
                    bool   confirmCheck;

                    do
                    {
                        confirm      = Console.ReadLine();
                        confirmCheck = confirm != "n" && confirm != "y";
                        if (confirmCheck)
                        {
                            Console.WriteLine("The input must be y or n");
                            Console.WriteLine("Plese type again(y/n):  ");
                            logger.Warn($"(New Customer)Invalid Input:  {confirmCheck}");
                        }
                    } while (confirmCheck);

                    if (confirm == "y")
                    {
                        Customer customerNew = new Customer(fName, lName, phone, favStore);
                        newGuys.AddCustomer(customerNew);
                        logger.Info("New Customer is added into database.");
                        Console.WriteLine("");
                        //PlaceOrder(customerNew, newGuys);
                    }
                }
                else
                {
                    Console.WriteLine("Sorry! The Store ID doesn't not exist.");
                    Console.WriteLine("Please press Enter to back to main menu.");
                    string back = Console.ReadLine();
                }
                break;

            ///<summary>
            ///Function to search a existed customer
            ///Via his/her first name and last name
            ///then pass them to data access project to get the result
            ///</summary>
            ///<remark>
            ///if the result is more then 1, add new input(phone number or id to get the exact one.
            ///</remark>
            case 2:
                Console.WriteLine("Please Enter your first name:");
                fNameInput = Console.ReadLine();
                fName      = NameFormat(fNameInput);
                Console.WriteLine("");
                Console.WriteLine("Please Enter your last name: ");
                lNameInput = Console.ReadLine();
                lName      = NameFormat(lNameInput);
                Console.WriteLine("");

                Customer customerOld = new Customer(fName, lName);

                Repo            oldGuys       = new Repo();
                List <Customer> customerFound = oldGuys.SearchCustomer(customerOld).ToList();
                if (customerFound.Count > 0)
                {
                    for (int i = 0; i < customerFound.Count; i++)
                    {
                        Console.WriteLine($"Your First Name is:     {customerFound[i].FirstName}");
                        Console.WriteLine($"Your Last Name is:      {customerFound[i].LastName}");
                        Console.WriteLine($"Your Phone Number is:   {customerFound[i].PhoneNumber}");
                        Console.WriteLine($"Your Favorite Store is: {customerFound[i].FavoriteStore}");
                        Console.WriteLine("----------");
                        Console.WriteLine($"Is that correct?(y/n)");

                        string confirm = "";
                        bool   confirmCheck;

                        do
                        {
                            confirm      = Console.ReadLine();
                            confirmCheck = confirm != "n" && confirm != "y";
                            if (confirmCheck)
                            {
                                Console.WriteLine("");
                                Console.WriteLine("The input must be y or n");
                                Console.WriteLine("Plese type again(y/n):  ");
                                logger.Warn($"(Existed Customer)Invalid Input:  {confirmCheck}");
                            }
                        } while (confirmCheck);

                        if (confirm == "y")
                        {
                            PlaceOrder(customerFound[i], oldGuys);
                            break;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Sorry! We don't have your record.");
                    Console.WriteLine("Press enter to back to main menu");
                    string back = Console.ReadLine();
                }
                break;

            default:
                break;
            }

            Console.Clear();
        }