Пример #1
0
        public void displayAllCustomers()
        {
            ClassLibrary.Customer customer = new ClassLibrary.Customer();

            dtCustomers = customer.GetAll().Tables[0];

            //set the customer_id column as primary key so you can search the table later
            dtCustomers.PrimaryKey   = new DataColumn[] { dtCustomers.Columns["CUSTOMER_id"] };
            dataGridView1.DataSource = dtCustomers;

            dataGridView1.Columns["CUSTOMER_id"].HeaderText      = "ID";
            dataGridView1.Columns["CUSTOMER_name"].HeaderText    = "Name";
            dataGridView1.Columns["CUSTOMER_phone"].HeaderText   = "Phone";
            dataGridView1.Columns["CUSTOMER_email"].HeaderText   = "Email";
            dataGridView1.Columns["CUSTOMER_address"].HeaderText = "Address";
            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
        }
Пример #2
0
        //----------------------------------------------------------------------------------------------
        private void frmAddOrderCustomer_Load(object sender, EventArgs e)
        {
            //make order list
            ord = new BindingList <OrderDetails>();

            //add customers to the combobox
            ClassLibrary.Customer customer = new ClassLibrary.Customer();
            dsCustomer = customer.GetAll();
            dtCustomer = dsCustomer.Tables[0];
            cmbCustomers.DataSource    = dtCustomer;
            cmbCustomers.DisplayMember = "CUSTOMER_name";
            cmbCustomers.ValueMember   = "CUSTOMER_id";

            //add products to the combobox
            ClassLibrary.Product product = new ClassLibrary.Product();
            dsProduct = product.GetAll();
            dtProduct = dsProduct.Tables[0];
            cmbProducts.DataSource    = dtProduct;
            cmbProducts.DisplayMember = "PRODUCT_name";

            //ADDING MODE
            if (drOrder == null)
            {
                dateTimePicker1.Enabled = false;
            }
            //EDITING MODE
            else
            {
                //if orderid is in the sorder table
                ClassLibrary.SupplierOrder sorder = new ClassLibrary.SupplierOrder();
                sorder.OrderId = Convert.ToInt32(drOrder.ItemArray[0]);
                DataTable dt = sorder.GetSorderByOrderId().Tables[0];

                //disables forms items
                if (dt.Rows.Count != 0)
                {
                    MakeOrderUnEditable();
                    saveDeliveryDate        = true;
                    dateTimePicker1.Enabled = true;
                }

                //select the customer combobox
                string custId = drOrder.ItemArray[1].ToString();
                try
                {
                    cmbCustomers.SelectedIndex = cmbCustomers.FindStringExact(custId);
                }
                catch (Exception ex)
                {
                }
                //display date
                dateTimePicker1.Text = drOrder.ItemArray[5].ToString();

                //display total price
                totalPrice     = Convert.ToDecimal(drOrder.ItemArray[3]);
                txtPrice.Text  = String.Format("{0:c}", totalPrice);
                txtStatus.Text = drOrder.ItemArray[4].ToString();

                //display orderdetails
                ClassLibrary.CustomerOrderDetails orderdetails = new ClassLibrary.CustomerOrderDetails();
                orderdetails.OrderId = Convert.ToInt32(drOrder.ItemArray[0]);

                DataTable thisTable = orderdetails.GetOrderDetailsByOrderId().Tables[0];

                try
                {
                    foreach (DataRow row in thisTable.Rows)
                    {
                        string price = String.Format("{0:c}", Convert.ToDecimal(row.ItemArray[3]));
                        //add to generic list
                        ord.Add(new OrderDetails
                        {
                            ProductID   = Convert.ToInt32(row.ItemArray[0]),
                            ProductName = row.ItemArray[1].ToString(),
                            Quantity    = Convert.ToInt32(row.ItemArray[2]),
                            Price       = price,
                        });
                    }
                    dataGridView1.DataSource = ord;
                }
                catch (Exception ex)
                {
                }
            }
        }