Beispiel #1
0
        public void AddProductTest()
        {
            var product = ProductDB.GetProduct(_testProduct.Code);

            Assert.AreEqual(_testProduct, product);
        }
        //public static List<Product> ListOfProducts()
        //{
        //    return ProductDB.List(1, -1 , "");
        //}

        public static Product GetProduct(int productId)
        {
            return(ProductDB.Get(productId));
        }
 public static bool UpdateProduct(Product data)
 {
     return(ProductDB.Update(data));
 }
 public ActionResult Delete(int?id)
 {
     //TODO: check if ID is null
     ProductDB.DeleteProductById(id.Value);
     return(RedirectToAction("Index"));
 }
 /// <summary>
 /// Author: Robert Clements
 /// Purpose: displays all of the products from database in data grid view
 /// </summary>
 private void DisplayProducts()
 {
     products = ProductDB.GetAllProduct(); //getting all products from the database
     productDataGridView.DataSource = products;
 }
Beispiel #6
0
 public Product GetProduct([FromUri] int id)
 {
     return(ProductDB.GetProduct(id));
 }
Beispiel #7
0
 public Product UpdateProduct([FromBody] Product product)
 {
     return(ProductDB.UpdateProduct(product));
 }
 public bool saveauthorbook(AuthorBook authBook)
 {
     return(ProductDB.saveauthBook(authBook));
 }
Beispiel #9
0
 /// <summary>
 /// Đếm số products
 /// </summary>
 /// <param name="searchValue"></param>
 /// <returns></returns>
 public static int Product_Count(string searchValue, string categoryID, string supplierID)
 {
     return(ProductDB.Count(searchValue, categoryID, supplierID));
 }
        public decimal sumCost;           //total consume money
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache); //clear cache
            Response.Cache.SetExpires(DateTime.Now.AddDays(-1));      //set Session Expires
            Response.Cache.SetNoStore();


            if (Session["custid"] == null)       //tell whether login or not
            {
                Response.Redirect("logIn.aspx"); //if session[] is killed ,then go to login.aspx
            }

            if (!IsPostBack)//for first time to load this page
            {
                try
                {
                    int custid;
                    custid    = Convert.ToInt32(Session["custid"]);
                    custcosts = ProductDB.AccountByProduct(custid);//load related booking info accroding to custid
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                if (custcosts.Count != 0)//if returning is not null
                {
                    var details = from cs in custcosts
                                  orderby cs.ProductName //return booking and cost details order by productname
                                  select new
                    {
                        ProductName = cs.ProductName,
                        Baseprice   = cs.PackageBasePrice.ToString("c"),
                        Admission   = cs.PackageAgencyCommission.ToString("c"),
                        Traveler    = cs.TravelerCount.ToString(),
                        TotalCost   = (cs.PackageBasePrice * cs.TravelerCount + cs.PackageAgencyCommission).ToString("c")            //
                    };
                    grvCostDetails.DataSource = details.ToList();
                    grvCostDetails.DataBind();
                    var summarys = from cs in custcosts                                                                 //sumary LINQ according to group by productname
                                   group cs by cs.ProductName into pn
                                   orderby pn.Sum(x => x.PackageBasePrice *x.TravelerCount + x.PackageAgencyCommission) //get cost for each package
                                   select new
                    {
                        Productname = pn.Key,
                        Sumcost     = pn.Sum(x => x.PackageBasePrice * x.TravelerCount + x.PackageAgencyCommission).ToString("c")
                    };

                    foreach (var ls in summarys.ToList())                            //sum up all costs
                    {
                        sumCost += decimal.Parse(ls.Sumcost, NumberStyles.Currency); // Get total cost
                    }
                    grvCostSum.DataSource = summarys.ToList();
                    grvCostSum.DataBind();
                    txtTotal.Text = "TotalCost is " + sumCost.ToString("c");
                    // lblTotalCot.Text = "TotalCost is " + sumCost.ToString("c");
                    //set pie chart configuration
                    //  ChartSum.Width = Unit.Percentage(100);
                    ChartSum.DataSource                  = summarys.ToList();        //set datasource to piechart
                    ChartSum.Series[0].XValueMember      = "Productname";            //set category name
                    ChartSum.Series[0].YValueMembers     = "Sumcost";                //set display value
                    ChartSum.Series[0].Label             = "#VALX" + "#PERCENT{P0}"; //set dispaly format
                    ChartSum.Series[0].Font              = new Font("Arial", 15, FontStyle.Bold);
                    ChartSum.Series[0]["DoughnutRadius"] = "60";
                    ChartSum.DataBind();
                }
                else
                {
                    lblInfo.Text     = Session["Custuser"].ToString() + " has no relative booking record !";
                    ChartSum.Visible = false;
                    txtTotal.Visible = false;
                }
            }
        }
 private void btnRefreshProds_Click(object sender, EventArgs e)
 {
     productsDataGridView.DataSource = ProductDB.GetProducts();
 }
Beispiel #12
0
 public SaleItem(decimal quantity, ProductDB product)
 {
     this.Quantity = quantity;
     this.Product  = product;
 }
Beispiel #13
0
 public static bool UpdateProduct(Product product)
 {
     return(ProductDB.Update(product));
 }
Beispiel #14
0
 public static int AddProduct(Product product)
 {
     return(ProductDB.Add(product));
 }
Beispiel #15
0
 public Main()
 {
     InitializeComponent();
     database = new ProductDB();
     //database.create(new Product(0, "Leche Lala", 5, 18, 0));
 }
Beispiel #16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public static int Product_Add(Product data)
 {
     return(ProductDB.Add(data));
 }
Beispiel #17
0
 public List <Product> GetProducts([FromUri] int?parentId = null, [FromUri] int?productCategoryId = null, [FromUri] string filter = null, [FromUri] ActiveStatusEnum active = ActiveStatusEnum.Active)
 {
     return(ProductDB.GetProducts(parentId, productCategoryId, filter, active));
 }
Beispiel #18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static Product Product_Get(string id)
 {
     return(ProductDB.Get(id));
 }
Beispiel #19
0
 public Product CreateProduct([FromBody] Product product)
 {
     return(ProductDB.CreateProduct(product));
 }
Beispiel #20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="productIDs"></param>
 /// <returns></returns>
 public static bool Product_Delete(int[] productIDs)
 {
     return(ProductDB.Delete(productIDs));
 }
Beispiel #21
0
 public void DeleteProduct([FromUri] int id)
 {
     ProductDB.DeleteProduct(id);
 }
Beispiel #22
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="productID"></param>
 /// <returns></returns>
 public static List <ProductAttributes> Product_GetAttribute(string productID)
 {
     return(ProductDB.GetAttribute(productID));
 }
Beispiel #23
0
        public async Task <IActionResult> Delete(int id)
        {
            Product p = await ProductDB.GetProductAsync(_context, id);

            return(View(p));
        }
Beispiel #24
0
 public MyPageModel()
 {
     productDB = new ProductDB();
 }
 public static List <Product> ListOfProducts()
 {
     return(ProductDB.List(1, -1, "", "", ""));
 }
        /// <summary>
        /// On clicking delete respond based on tab selected
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            switch (tbMain.SelectedTab.Name)
            {
            case "tabPackages":     //take the currently selected package
                Package      package = packages[dgPackages.CurrentRow.Index];
                DialogResult result  = MessageBox.Show("Delete " + package.Name + "? \nThis will delete the entire package and its components",
                                                       "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)     //if user confirms delete
                {
                    try
                    {
                        if (!PackagesDB.DeletePackage(package))
                        {
                            //Check for optimistic concurrency
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that package.", "Database Error");
                        }
                        else
                        {
                            //Delete successful, refresh the tables
                            dgPackageProductSuppliers.ClearSelection();
                            this.displayAll(0, 0);
                        }
                    }
                    catch (SqlException ex)
                    {
                        switch (ex.Errors[0].Number)
                        {
                        //if foriegn key error from db
                        case 547:
                            MessageBox.Show("You do not have the priviledge to delete this package", "Priviledge Error");
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        //any other errors
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }

                break;

            case "tabProducts":
                int          rowIndexProd  = dgProducts.CurrentRow.Index;
                Products     product       = products[rowIndexProd];
                DialogResult resultProduct = MessageBox.Show("Delete " + product.ProdName + "?",
                                                             "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (resultProduct == DialogResult.Yes)
                {
                    try
                    {
                        if (!ProductDB.DeleteProduct(product))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that product.", "Database Error");
                        }
                        else
                        {
                            dgProd.ClearSelection();
                        }
                        rowIndexProd = rowIndexProd - 1;         //leave selection on the last product
                        this.displayAll(0, rowIndexProd);
                    }
                    catch (SqlException ex)
                    {
                        switch (ex.Errors[0].Number)
                        {
                        //if foreign key error from datbase
                        case 547:
                            MessageBox.Show("Please Remove " + product.ProdName + " from all packages before deleting ",
                                            "Link Violation");
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }

                break;

            case "tabSuppliers":
                Suppliers    supplier       = suppliers[dgSuppliers.CurrentRow.Index];
                DialogResult resultSupplier = MessageBox.Show("Delete " + supplier.SupName + "?",
                                                              "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (resultSupplier == DialogResult.Yes)
                {
                    try
                    {
                        if (!SuppliersDB.DeleteSupplier(supplier))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that supplier.", "Database Error");
                        }
                        else
                        {
                            this.displayAll();
                        }
                    }
                    catch (SqlException ex)
                    {
                        switch (ex.Errors[0].Number)
                        {
                        // if foriegn key error from database
                        case 547:
                            MessageBox.Show("You cannot delete this supplier as it is linked to a package", "Link Violation");
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }

                break;

            case "tabPackageProductSupplier":
                int          rowIndex    = dgPackageProductSuppliers.CurrentRow.Index;
                Package      packageProd = packages[rowIndex];
                DialogResult resultProd  = MessageBox.Show("Delete " + packageProd.Name + "? \nThis will delete the entire package and its components",
                                                           "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (resultProd == DialogResult.Yes)
                {
                    try
                    {
                        if (!PackagesDB.DeletePackage(packageProd))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that package.", "Database Error");
                        }
                        else
                        {
                            dgPackageProductSuppliers.ClearSelection();
                            rowIndex -= 1;
                            this.displayAll(rowIndex, 0);
                        }
                    }
                    catch (SqlException ex)
                    {
                        switch (ex.Errors[0].Number)
                        {
                        //if foriegn key error from dataabase
                        case 547:
                            MessageBox.Show("You do not have the priviledge to delete this package", "Priviledge Error");
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }

                break;
            }
        }
 public static int AddProduct(Product data)
 {
     return(ProductDB.Add(data));
 }
        /// <summary>
        /// If user is adding a product, the dropdowns should be blank.
        /// If user is modifying a product, the dropdowns should reflect
        /// the product user is modifying.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmPSAddModify_Load(object sender, EventArgs e)
        {
            foreach (string product in ProductDB.GetAllProducts())
            {
                cmbProduct.Items.Add(product);
            }

            //Set form appearance, and update title lable with package name.
            cmbProduct.DropDownStyle  = ComboBoxStyle.DropDownList;
            cmbSupplier.DropDownStyle = ComboBoxStyle.DropDownList;

            //If user tries to submit a duplicate record, a message will tell
            //the user, "STOP, YOU CANNOT SUBMIT THIS."
            //This message is not required at Form_Load.
            lblGandalf.Visible = false;

            //If no product was selected when user launched this form dialog,
            //then user is adding a product to the package.
            //If user is adding, clear the combo box selections.
            if (mainForm.currentlyDGVSelectedProductName == "" && mainForm.currentlyDGVSelectedSupplierName == "")
            {
                isAddAndNotModify        = true;
                btnSubmit.Text           = "Add";
                cmbProduct.SelectedIndex = 0;
                cmbSupplier.Enabled      = false;
            }

            //If user is modifying, have the combo boxes select the product and supplier
            //user had selected in the Packages form.
            else
            {
                isAddAndNotModify   = false;
                btnSubmit.Text      = "Update";
                originalProduct     = mainForm.currentlyDGVSelectedProductName;
                newlyPickedProduct  = mainForm.currentlyDGVSelectedProductName;
                originalSupplier    = mainForm.currentlyDGVSelectedSupplierName;
                newlyPickedSupplier = mainForm.currentlyDGVSelectedSupplierName;

                cmbProduct.SelectedItem = mainForm.currentlyDGVSelectedProductName;

                //The currently selected Supplier will probably be in the middle of the combo
                //box list. When user opens the list on the combo box, it will scroll down
                //the list to where the currently selected Supplier is. I do not want it
                //to scroll down. I want user to see the list from the beginning. Therefore,
                //add the currently selected Supplier to the list before adding the complete
                //list of suppliers. That way, it will be at the top of the combo box list,
                //and the list will not have to scroll down to it.
                cmbSupplier.Items.Clear();
                cmbSupplier.Items.Add(mainForm.currentlyDGVSelectedSupplierName);
                cmbSupplier.Items.Add("");

                foreach (string supplier in SupplierDB.GetUnlinkedSuppliers(mainForm.currentlyDGVSelectedProductName))
                {
                    cmbSupplier.Items.Add(supplier);
                }

                overrideEventSupplier_SelectedIndexChanged = true;
                cmbSupplier.SelectedIndex = 0;

                lblGandalf.Visible = false;
            }
        }
 public static int DeleteProducts(int[] productIDs)
 {
     return(ProductDB.Delete(productIDs));
 }
Beispiel #30
0
 public void CleanupTest()
 {
     ProductDB.DeleteProduct(_testProduct);
 }