コード例 #1
0
        public Customers(object sender)
        {
            InitializeComponent();

            this.CboDepartment.Items.Add("Business");
            this.CboDepartment.Items.Add("Computing");
            this.CboDepartment.Items.Add("Dentistry");
            this.CboDepartment.Items.Add("Enginnering");
            this.CboDepartment.Items.Add("Law");
            this.CboDepartment.Items.Add("Music");
            this.CboDepartment.Items.Add("Science");
            this.CboDepartment.Items.Add("Yale-NUS College");

            Button _button = sender as Button;
            if (_button.Text != "New")
            {
                this.NewOrNot = false;
                Customers_Load();
            }
            else
            {
                BookingSystemEntities context = new BookingSystemEntities();
                Customer customer = new Customer();

                var custQuery = from x in context.Customers
                                select x;

                customer = custQuery.ToList().Last();

                //string lastCustID = customer.PrimaryKey;
                Customer newcustomer = new Customer();
                newcustomer.ID = "A" + (Convert.ToInt32(customer.ID.Substring(1, customer.ID.Length - 1)) + 1).ToString().PadLeft(8, '0');

                txtCustomerID.Enabled = false;
                txtCustomerID.Text = newcustomer.ID;

                this.NewOrNot = true;
            }
        }
コード例 #2
0
        private Customer SaveNew()
        {
            BookingSystemEntities context = new BookingSystemEntities();
            Customer customer = new Customer();

            customer.ID = txtCustomerID.Text;
            customer.Name = txtCustomerName.Text;
            customer.Department = CboDepartment.Text;
            customer.Address = rtbAddress.Text;
            customer.Email = txtEmail.Text;
            customer.PhoneNumber = txtPhoneNo.Text;
            customer.PostalCode = txtPostalCode.Text;

            //BookingSystemEntities context = new BookingSystemEntities();
            context.Customers.Add(customer);
            context.SaveChanges();

            return customer;
        }