예제 #1
0
        public void DisplayAllProducts()
        {
            ClassLibrary.Product product = new ClassLibrary.Product();
            dtProducts = product.GetAll().Tables[0];
            dataGridView1.DataSource = dtProducts;

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

            dataGridView1.Columns["PRODUCT_picture"].Visible = false;
            dataGridView1.Columns["PRODUCT_cost"].DefaultCellStyle.Format  = "c";
            dataGridView1.Columns["PRODUCT_price"].DefaultCellStyle.Format = "c";

            dataGridView1.Columns["PRODUCT_id"].HeaderText          = "ID";
            dataGridView1.Columns["PRODUCT_name"].HeaderText        = "Name";
            dataGridView1.Columns["PRODUCT_cost"].HeaderText        = "Cost";
            dataGridView1.Columns["PRODUCT_price"].HeaderText       = "Price";
            dataGridView1.Columns["PRODUCT_color"].HeaderText       = "Color";
            dataGridView1.Columns["PRODUCT_description"].HeaderText = "Description";
            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)
                {
                }
            }
        }