示例#1
0
        //initialize form area
        private void Form1_Load(object sender, EventArgs e)//initialize form
        {
            //initiallize recorders from Prodcuts,Suppliers and Product_supplier three TABLES
            Products  = ProductDB.GetAllProducts();                  // LIST of Prodcut :  get all prodcuts from product TABLE to Prodcut List
            Suppliers = SupplierDB.GetAllsuppliers();                //List of Supplier:get all suppliers from supplier TABLE
            allPS     = ProductSupplierDB.GetAllProductsSuppliers(); //List of PS: get all of products and corresponding suppliers from PRODUCTS_SUPPLIERS TABLE


            var allProductName = from pro in Products                                                  //get each row in List of Prodcuts
                                 orderby pro.ProdName
                                 select new { ProductId = pro.ProductID, ProductName = pro.ProdName }; //

            //initialzie datasour for lstProducts to display each product come from products TABLE
            lstProducts.SelectedIndexChanged -= lstProducts_SelectedIndexChanged; //

            lstProducts.DataSource            = allProductName.ToList();          //display all of product
            lstProducts.ValueMember           = "ProductId";                      //set Product ID as value
            lstProducts.DisplayMember         = "ProductName";                    //set product name as display
            lstProducts.SelectedIndex         = -1;
            lstProducts.SelectedIndexChanged += lstProducts_SelectedIndexChanged;
            //initialize button status,before select product row or (PS row ),none of buttons are available!
            btnAdd.Enabled    = false;
            btnUpdate.Enabled = false;
            btnDelete.Enabled = false;
            btnSave.Enabled   = false;
            panel2.Visible    = false;
            lblSave.Visible   = false;
        }
示例#2
0
        private void UpdateAvailableSupplier()//method to update new available supplier to current supplier for a specific row
        {
            //when update,only select one available supplier to update old one,available suppliers is same to add function
            currentPS = ProductSupplierDB.GetAllSuppliersForSelectedProduct(currentUpdateProductId);                                  //select all of suppliers for this current ProductID
            List <Supplier> Suppliers             = SupplierDB.GetAllsuppliers();                                                     //access DB by select statement and return rows
            var             availableSupplierName = from allsupplier in Suppliers
                                                    where !(from c in currentPS select c.SupplierID).Contains(allsupplier.SupplierId) //select sullpiers which has no any relationship with current product
                                                    orderby allsupplier.SupName
                                                    select new { Supplierid = allsupplier.SupplierId, SupplierName = allsupplier.SupName };


            cklstProductSupplier.DataSource    = availableSupplierName.ToList();
            cklstProductSupplier.DisplayMember = "SupplierName";
            cklstProductSupplier.ValueMember   = "Supplierid";
            for (int i = 0; i < cklstProductSupplier.Items.Count; i++)
            {
                if (cklstProductSupplier.GetItemChecked(i))
                {
                    cklstProductSupplier.SetItemChecked(i, false);
                }
            }
        }
示例#3
0
        private void AddAvailableSupplier()//method to load available suppliers'name to checkedlistbox
        {
            // currentPS  is generated in Method of loadProSupplier
            Suppliers = SupplierDB.GetAllsuppliers();                                                                     //get all of suppliers in SUPPLIERS TABLE
            var availableSupplierName = from allsupplier in Suppliers                                                     //get each row in sUppliers TABle
                                        where !(from c in currentPS select c.SupplierID).Contains(allsupplier.SupplierId) // current row from currentPS doesnt included same supplierid to allsupplier
                                        orderby allsupplier.SupName
                                        select new { Supplierid = allsupplier.SupplierId, SupplierName = allsupplier.SupName };


            cklstProductSupplier.DataSource    = availableSupplierName.ToList();
            cklstProductSupplier.DisplayMember = "SupplierName";
            cklstProductSupplier.ValueMember   = "Supplierid";
            // this section modify the bug of checkedlistbox
            for (int i = 0; i < cklstProductSupplier.Items.Count; i++)
            {
                if (cklstProductSupplier.GetItemChecked(i))
                {
                    cklstProductSupplier.SetItemChecked(i, false);
                }
            }
        }