Ejemplo n.º 1
0
        public static Response UpdateProduct(int id, string name, int price, int stock, int productTypeId)
        {
            ProductType pt = ProductTypeHandler.GetProductTypeById(productTypeId);

            if (name == "")
            {
                return(new Response(false, "must be filled"));
            }
            else if (stock < 1)
            {
                return(new Response(false, "input must be 1 or more"));
            }
            else if (price < 1000)
            {
                return(new Response(false, "input must be above 1000"));
            }
            else if (price % 1000 != 0)
            {
                return(new Response(false, "input must be multiply of 1000"));
            }
            else if (pt == null)
            {
                return(new Response(false, "product type does not exist"));
            }
            else
            {
                ProductHandler.UpdateProduct(id, name, price, stock, productTypeId);
                return(new Response(true));
            }
        }
Ejemplo n.º 2
0
        private void SetLabelText(int productTypeId)
        {
            ProductType pt = ProductTypeHandler.GetProductType(productTypeId);

            prodName.Text = pt.Name;
            prodDesc.Text = pt.Description;
        }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //Set Dropdown
                ProductType_ddl.DataSource     = ProductTypeHandler.GetProductTypes();
                ProductType_ddl.DataTextField  = "Name";
                ProductType_ddl.DataValueField = "ID";
                ProductType_ddl.SelectedIndex  = -1;
                ProductType_ddl.DataBind();

                ProductType_ddl.Items.Insert(0, new ListItem("--Select Product Type--", "-1"));

                //fill data in repeater
                RptProductListByType.DataSource = new ProductHandler().GetAllProduct();
                RptProductListByType.DataBind();
            }
            //jika admin
            if (Session.Keys.Count != 0)
            {
                if (Session["RoleID"].ToString().Equals("1"))
                {
                    Btn_InsertNewProd.Visible = true;
                }
            }
        }
        public static string insertProductType(string name, string description)
        {
            if (name.Length < 5)
            {
                return("Name must at least 5 characters!");
            }
            else if (description.Length <= 0)
            {
                return("Description must not be empty!");
            }
            else if (!ProductTypeHandler.validateProductTypeName(name))
            {
                return("These product type name has already taken!");
            }

            try
            {
                ProductTypeHandler.addProductType(name, description);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return("Database update on server failure, please try again!");
            }
            return("");
        }
        public static Response UpdateProductType(int id, string name, string desc)
        {
            ProductType getName = ProductTypeHandler.GetName(name);

            if (name.Length < 5)
            {
                return(new Response(false, "must consist of 5 characters or more"));
            }
            else if (name == "")
            {
                return(new Response(false, "must be filled"));
            }
            else if (getName != null)
            {
                return(new Response(false, "must be unique"));
            }
            else if (desc == "")
            {
                return(new Response(false, "must be filled"));
            }
            else
            {
                ProductTypeHandler.UpdateProductType(id, name, desc);
                return(new Response(true));
            }
        }
        public static string updateProductType(ProductType pt, string name, string description)
        {
            if (name.Length < 5)
            {
                return("Name must at least 5 characters!");
            }
            else if (description.Length <= 0)
            {
                return("Description must not be empty!");
            }
            else if (!name.Equals(pt.Name) && !ProductTypeHandler.validateProductTypeName(name))
            {
                return(String.Format("These product type name has already taken! " +
                                     "Use old name: '{0}' or other non-existent product type instead.", pt.Name));
            }

            try
            {
                ProductTypeHandler.updateProductType(pt.ID, name, description);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return("Database update on server failure, please try again!");
            }
            return("");
        }
Ejemplo n.º 7
0
        protected void Btn_SubmitProductTypeID(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    int          ID                 = Convert.ToInt32(HdnProductTypeId.Value);
                    string       Name               = NameTxt.Text.ToString();
                    string       Desc               = DescTxt.Text.ToString();
                    ProductTypes productType        = ProductTypeFactory.CreateProductType(ID, Name, Desc);
                    ProductTypes updatedProductType = ProductTypeHandler.UpdateProductType(productType);

                    if (productType == null)
                    {
                        throw new Exception();
                    }

                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "Data Updated Succesfully" + "');", true);
                        Response.Redirect("ViewProductType.aspx");
                    }
                }

                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Ejemplo n.º 8
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session[Constant.Keys.AUTH] != null)
     {
         User user = (User)Session[Constant.Keys.AUTH];
         if (user.RoleID == 2)
         {
             int     id = Int32.Parse(Request.QueryString["id"]);
             Product p  = ProductHandler.get(id);
             updateCartNameTxt.Text        = p.Name;
             updateCartPriceTxt.Text       = p.Price.ToString();
             updateCartStockTxt.Text       = p.Stock.ToString();
             updateCartProductTypeTxt.Text = ProductTypeHandler.getProductType(p.ProductTypeID);
         }
         else
         {
             var redirecTo = Constant.Routes.HOME_ROUTE;
             Response.Redirect(redirecTo);
         }
     }
     else
     {
         var redirecTo = Constant.Routes.HOME_ROUTE;
         Response.Redirect(redirecTo);
     }
 }
Ejemplo n.º 9
0
        public void validateUpdateProductType(TextBox txtProductType, TextBox txtDescription, Label lblErrorProductType, Label lblSuccess)
        {
            int    ID          = Convert.ToInt32(HttpContext.Current.Request.QueryString["producttypeid"]);
            string name        = txtProductType.Text;
            string description = txtDescription.Text;

            List <ProductType> check = new ProductTypeHandler().GetSameNameUpdate(name);
            int flag = 0;

            foreach (var item in check)
            {
                if (item.ID != ID)
                {
                    flag = 1;
                    break;
                }
            }
            if (flag == 1)
            {
                lblErrorProductType.Visible = true;
                return;
            }

            ProductType newProductType = new ProductTypeFactory().CreateProduct(name, description);

            new ProductTypeHandler().UpdateProductType(newProductType, ID);

            lblSuccess.Visible          = true;
            lblErrorProductType.Visible = false;
        }
Ejemplo n.º 10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int         id = Int32.Parse(Request.QueryString["id"]);
            ProductType p  = ProductTypeHandler.get(id);

            oldNameType.Text        = p.Name;
            oldDescriptionType.Text = p.Description;
        }
Ejemplo n.º 11
0
        public void initPage(DropDownList ddlProductType)
        {
            List <ProductType> dataPT = new ProductTypeHandler().GetAllProductType();

            ddlProductType.DataSource     = dataPT;
            ddlProductType.DataTextField  = "Name";
            ddlProductType.DataValueField = "ID";
            ddlProductType.DataBind();
        }
Ejemplo n.º 12
0
        public static void updateProductType(int id, string productTypeName, string description, out string errorMessage)
        {
            bool success = checkConstraintProductType(productTypeName, description, out errorMessage);

            if (success == true)
            {
                ProductTypeHandler.doUpdateProductType(id, productTypeName, description);
            }
        }
Ejemplo n.º 13
0
        public void initPage(TextBox txtProductType, TextBox txtDescription)
        {
            int ID = Convert.ToInt32(HttpContext.Current.Request.QueryString["producttypeid"]);

            ProductType currentData = new ProductTypeHandler().GetProductTypeByID(ID);

            txtProductType.Text = currentData.Name;
            txtDescription.Text = currentData.Description;
        }
Ejemplo n.º 14
0
        public static ProductType createProductType(String name, String description)
        {
            ProductType productType = new ProductType();

            productType.ID          = ProductTypeHandler.getLastProductTypeID() + 1;
            productType.Name        = name;
            productType.Description = description;
            return(productType);
        }
Ejemplo n.º 15
0
        protected void tableProductType_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int    index     = e.RowIndex;
            string productId = tableProductType.Rows[index].Cells[2].Text;

            int id = Int32.Parse(productId);

            ProductTypeHandler.DeleteProductType(id);
            Response.Redirect(Request.RawUrl);
        }
Ejemplo n.º 16
0
        public static string delete(int ID)
        {
            string error = "";

            if (ProductTypeHandler.isProductTypeReferenced(ID))
            {
                error = "Failed to delete selected product type";
            }
            return(error);
        }
Ejemplo n.º 17
0
        public void GetProductInformation(string productID, Label Name, Label Price, Label Stock, Label ProductTypeLabel)
        {
            int     ProductID  = Int32.Parse(productID);
            Product NewProduct = new ProductHandler().GetProductByID(ProductID);

            Name.Text  = NewProduct.Name;
            Price.Text = NewProduct.Price.ToString();
            Stock.Text = NewProduct.Stock.ToString();
            ProductType NewProductType = new ProductTypeHandler().GetProductTypeByID(NewProduct.ID);

            ProductTypeLabel.Text = NewProductType.Name;
        }
        public static Response DeleteProductType(int id)
        {
            ProductType pt = ProductTypeHandler.DeleteProductType(id);

            if (pt == null)
            {
                return(new Response(false, "to-be-delete product cannot be referenced in another table in the database"));
            }
            else
            {
                return(new Response(true));
            }
        }
Ejemplo n.º 19
0
        public static Response InsertProductType(string productType, string desc)
        {
            if (productType.Length < 5)
            {
                return(new Response(false, "Product type must be over 5 characters"));
            }
            else if (desc == "")
            {
                return(new Response(false, "Description must be filled."));
            }
            Response response = ProductTypeHandler.InsertProductType(productType, desc);

            return(response);
        }
Ejemplo n.º 20
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //ProductType_ddl.DataSource = ProductHandler
                ProductType_ddl.DataSource     = ProductTypeHandler.GetProductTypes();
                ProductType_ddl.DataTextField  = "Name";
                ProductType_ddl.DataValueField = "ID";
                ProductType_ddl.SelectedIndex  = 0;
                ProductType_ddl.DataBind();

                //ProductType_ddl.Items.Insert(0, new ListItem("--Select Item Product--", "-1"));
            }
        }
Ejemplo n.º 21
0
        protected void ValidateProductTypeName(object sender, ServerValidateEventArgs args)
        {
            args.IsValid = true;
            string name          = args.Value.ToString();
            int    ProductTypeID = Convert.ToInt32(HdnProductTypeId.Value.ToString());

            if (name.Length < 5 || !ProductTypeHandler.CheckProductNameAvailability(name))
            {
                if (!ProductTypeRepository.Find(ProductTypeID).Name.Equals(name))
                {
                    args.IsValid = false;
                }
            }
        }
        public static string deleteProductType(ProductType pt)
        {
            try
            {
                ProductTypeHandler.deleteProductType(pt.ID);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return("Database update on server failure, please try again!");
            }

            return("");
        }
Ejemplo n.º 23
0
        protected void insertProductType_Click(object sender, EventArgs e)
        {
            String ProductTypeName = insTypeNameTxt.Text, Description = insDescriptionTxt.Text, messageError = "";

            messageError = ProductTypeController.insert(ProductTypeName, Description);

            if (messageError != "")
            {
                insLabelTypeError.Text = messageError;
            }
            else
            {
                ProductTypeHandler.insertProductType(ProductTypeName, Description);
                insLabelTypeError.Text = "Your product type has been added";
            }
        }
Ejemplo n.º 24
0
        public void DeleteProductType(object sender, Label lblErrorDelete, GridView gridProductType)
        {
            GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
            int         ID  = Convert.ToInt32(row.Cells[0].Text);

            bool check = new ProductTypeHandler().GetReferencedProduct(ID);

            if (check == true)
            {
                lblErrorDelete.Visible = true;
                return;
            }

            new ProductTypeHandler().DeleteProductType(ID);
            UpdateGridData(gridProductType);
        }
Ejemplo n.º 25
0
        protected void lblDeletes_Click(object sender, EventArgs e)
        {
            int    ID           = Int32.Parse((sender as LinkButton).CommandArgument);
            string messageError = ProductTypeController.delete(ID);

            if (messageError != "")
            {
                lblErrorDeleteType.Text = messageError;
            }
            else
            {
                ProductTypeHandler.remove(ID);
                loadData();
                lblErrorDeleteType.Text = "Product type has been deleted";
            }
        }
Ejemplo n.º 26
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session[Constant.Keys.AUTH] != null)
     {
         User user = (User)Session[Constant.Keys.AUTH];
         if (user.RoleID != 1)
         {
             Response.Redirect(Constant.Routes.HOME_ROUTE);
         }
         else
         {
             allProductTypeData.DataSource = ProductTypeHandler.getAllProductType();
             allProductTypeData.DataBind();
         }
     }
 }
Ejemplo n.º 27
0
        public void validateInsertPaymentType(TextBox txtPaymentType, Label lblErrorPaymentType)
        {
            string name = txtPaymentType.Text;

            bool check = new ProductTypeHandler().GetSameNameInsert(name);

            if (check == true)
            {
                lblErrorPaymentType.Text = "Must be unique";
                return;
            }
            PaymentType newPaymentType = new PaymentTypeFactory().CreatePaymentType(name);

            new PaymentTypeHandler().InsertPaymentType(newPaymentType);
            lblErrorPaymentType.Text = "";
            txtPaymentType.Text      = "";
        }
Ejemplo n.º 28
0
        public static Response UpdateProductType(int id, string name, string desc)
        {
            if (name == "" || name.Length < 5)
            {
                return(new Response(false, "Please insert the name and a minimum of 5 character"));
            }
            if (ProductTypeRepository.isUnique(name) == false)
            {
                return(new Response(false, "Product Type Must Be Unique"));
            }
            if (desc == "")
            {
                return(new Response(false, "Please insert the description"));
            }

            return(new Response(ProductTypeHandler.UpdateProductType(id, name, desc), "Product Type has been inserted"));
        }
Ejemplo n.º 29
0
        public static string insert(string name, string stock, string price, string productTypeID)
        {
            string error = "";
            int    stockProduct, priceProduct, currentProductTypeID;
            bool   flag = true;

            try
            {
                stockProduct         = int.Parse(stock);
                priceProduct         = int.Parse(price);
                currentProductTypeID = int.Parse(productTypeID);
            }
            catch (Exception ex)
            {
                if (ex != null)
                {
                    flag  = false;
                    error = "Input stock, product type, and price must be a number";
                }
            }
            if (flag)
            {
                if (name == "")
                {
                    error = "Product name must be filled";
                }
                else if (int.Parse(stock) < 1)
                {
                    error = "Stock must be 1 or more";
                }
                else if (int.Parse(price) <= 1000)
                {
                    error = "Product price must be more than 1000";
                }
                else if (int.Parse(price) % 1000 != 0)
                {
                    error = "Product price must be multiply of 1000";
                }
                else if (!ProductTypeHandler.checkIfInsertedProductTypeIDValid(int.Parse(productTypeID)))
                {
                    error = "Product type id is invalid";
                }
            }
            return(error);
        }
Ejemplo n.º 30
0
        public static Response UpdateProductType(int protypeid, string name, string desc)
        {
            if (name == "" || name.Length < 5)
            {
                return(new Response(false, "Product Type must be filled and consists of 5 characters or more"));
            }

            if (desc == "")
            {
                return(new Response(false, "Description ust be filled."));
            }



            Response response = ProductTypeHandler.UpdateProductType(protypeid, name, desc);

            return(response);
        }