Пример #1
0
        public void Customers_Load()
        {
            BookingSystemEntities context = new BookingSystemEntities();

            string _id =  DataCache.System_MainWindow.Get_CustomerID();
            this.customer = (from x in context.Customers
                             where x.ID == _id
                             select x).FirstOrDefault();

            txtCustomerID.Enabled = false;
            txtCustomerID.Text = customer.ID;
            txtCustomerName.Text = customer.Name;
            CboDepartment.Text = customer.Department;
            rtbAddress.Text = customer.Address;
            txtEmail.Text = customer.Email;
            txtPhoneNo.Text = customer.PhoneNumber;
            txtPostalCode.Text = customer.PostalCode;
        }
Пример #2
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;
            }
        }
Пример #3
0
        private void UpdateCustomer()
        {
            BookingSystemEntities context = new BookingSystemEntities();

            //var updateQuery = from x in context.Customers
            //                where x.ID  == txtCustomerID.Text
            //                select x;

            // Execute the query, and change the column values
            // you want to change.

            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;

            context.SaveChanges();
            this.customer = null;
            // Insert any additional changes to column values.
        }
Пример #4
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;
        }