예제 #1
0
    public void InsertBrand(string name, string description)
    {
        try
        {
            name        = name.TrimEnd().TrimStart();
            description = description.TrimEnd().TrimStart();
        }
        catch (Exception)
        {
            throw new Exception("No es posible registrar la Marca");
        }

        BrandsDAO    dao    = new BrandsDAO();
        List <Brand> brands = GetAllBrands();

        if (brands.FindAll(b => b.name.ToUpperInvariant().Equals(name.ToUpperInvariant())).Count > 0)
        {
            throw new Exception("Ya existe una Marca con este nombre");
        }

        Brand newBrand = new Brand();

        newBrand.name        = name;
        newBrand.description = description;
        int result = dao.CreateBrand(newBrand);

        if (result < 1)
        {
            throw new Exception("No es posible registrar la Marca");
        }
    }
예제 #2
0
    public List <Brand> GetAllBrands()
    {
        List <Brand> brands = new List <Brand>();
        BrandsDAO    dao    = new BrandsDAO();

        brands = dao.GetAllBrands();
        return(brands);
    }
예제 #3
0
        private void ListBrands()
        {
            BrandsDAO             brandsDAO  = new BrandsDAO();
            var                   brands     = brandsDAO.Listagem();
            List <SelectListItem> brandsList = new List <SelectListItem>();

            brandsList.Add(new SelectListItem("Selecione uma marca", "0"));

            foreach (var brand in brands)
            {
                SelectListItem item = new SelectListItem(brand.Name, brand.Id.ToString());
                brandsList.Add(item);
            }
            ViewBag.Brands = brandsList;
        }
예제 #4
0
    public void DeleteBrand(int id)
    {
        BrandsDAO dao         = new BrandsDAO();
        Brand     deleteBrand = dao.GetBrand(id);

        if (deleteBrand != null)
        {
            int result = dao.DeleteBrand(deleteBrand);
            if (result < 1)
            {
                throw new Exception("No es posible eliminar la Marca, por favor verificar que no existen Productos asociados a la Marca");
            }
        }
        else
        {
            throw new Exception("El id de la Marca a actualizar no es válido");
        }
    }
예제 #5
0
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        try
        {
            Brand   objBrand = new Brand();
            DataSet ds;
            objBrand.BrandName = txtBrandName.Text.Trim();
            if (objBrand.BrandName != String.Empty)
            {
                objBrand.SearchBrands();
                ds = objBrand.DsCategories;
            }
            else
            {
                ds = new BrandsDAO().GetAllBrands();
            }

            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                gvBrands.DataSource = ds;
                gvBrands.DataBind();
                trGrid.Visible      = true;
                trNoRecords.Visible = false;
            }
            else
            {
                trNoRecords.Visible = true;
                trGrid.Visible      = false;
            }
        }
        catch (Exception ex)
        {
            ex.Data.Add("UILayerException", this.GetType().ToString() + Constant.Error_Seperator + "protected void btnSearch_Click(object sender, EventArgs e)");
            if (Master.LoggedUser != null && Master.LoggedUser.UserName != null && Master.LoggedUser.UserName != string.Empty)
            {
                Response.Redirect("Error.aspx?LogId=" + LankaTilesExceptions.WriteEventLogs(ex, Constant.Database_Connection_Name, Master.LoggedUser.UserName), false);
            }
            else
            {
                Response.Redirect("Error.aspx?LogId=" + LankaTilesExceptions.WriteEventLogs(ex, Constant.Database_Connection_Name, "Annonimous"), false);
            }
        }
    }
예제 #6
0
    public void UpdateBrand(int id, string name, string description)
    {
        try
        {
            name        = name.TrimEnd().TrimStart();
            description = description.TrimEnd().TrimStart();
        }
        catch (Exception)
        {
            throw new Exception("No es posible actualizar la Marca");
        }

        BrandsDAO dao = new BrandsDAO();
        //Brand updateBrand = dao.GetBrand(id);
        List <Brand> brands      = GetAllBrands();
        Brand        updateBrand = brands.Find(b => b.id.Equals(id));

        if (updateBrand != null)
        {
            if (brands.FindAll(b => (b.name.Equals(name.ToUpperInvariant())) && (b.id != id)).Count > 0)
            {
                throw new Exception("Ya existe una Marca con este nombre");
            }

            updateBrand.name        = name;
            updateBrand.description = description;
            int result = dao.UpdateBrand(updateBrand);
            if (result < 1)
            {
                throw new Exception("No es posible actualizar la Marca");
            }
        }
        else
        {
            throw new Exception("El id de la Marca a actualizar no es válido");
        }
    }
예제 #7
0
    public void LoadInitialData()
    {
        try
        {
            //
            // category
            //
            DataSet dsCategory = (new CategoryDAO()).GetAllCategories();
            if (dsCategory == null || dsCategory.Tables.Count == 0)
            {
                ddlCatCode.Items.Add(new ListItem("--No Data Found--", "-1"));
            }
            else
            {
                Master.BindDropdown("CategoryType", "CategoryId", dsCategory, ddlCatCode);
                ddlCatCode.Items.Add(new ListItem("--Please Select--", "-1"));
                ddlCatCode.SelectedValue = "-1";
            }

            //
            // Brand
            //
            DataSet dsBrands = new BrandsDAO().GetAllBrands();
            if (dsBrands == null || dsBrands.Tables.Count == 0)
            {
                ddlBrandCode.Items.Add(new ListItem("--No Data Found--", "-1"));
            }
            else
            {
                Master.BindDropdown("BrandName", "BrandId", dsBrands, ddlBrandCode);
                ddlBrandCode.Items.Add(new ListItem("--Please Select--", "-1"));
                ddlBrandCode.SelectedValue = "-1";
            }

            //
            // Status
            //
            ListItem[] status = { new ListItem("--Please Select--", "-1"), new ListItem("Active", "1"), new ListItem("InActive", "0") };
            ddlStatus.Items.AddRange(status);
            ddlStatus.SelectedValue = "1";

            //
            // Types
            //
            DataSet dsTypes = (new TypesDAO()).GetAllTypes();
            if (dsTypes == null || dsTypes.Tables.Count == 0)
            {
                ddlType.Items.Add(new ListItem("--No Data Found--", "-1"));
            }
            else
            {
                Master.BindDropdown("TypeName", "TypeId", dsTypes, ddlType);
                ddlType.Items.Add(new ListItem("--Please Select--", "-1"));
                ddlType.SelectedValue = "-1";
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
예제 #8
0
    /// <summary>
    /// Fill the default details for the controls
    /// </summary>
    public void LoadInitialData()
    {
        try
        {
            //
            // category
            //
            DataSet dsCategory = (new CategoryDAO()).GetAllCategories();
            if (dsCategory == null || dsCategory.Tables.Count == 0)
            {
                ddlCategory.Items.Add(new ListItem("--No Data Found--", "-1"));
            }
            else
            {
                Master.BindDropdown("CategoryType", "CategoryId", dsCategory, ddlCategory);
                ddlCategory.Items.Add(new ListItem("All", "-1"));
                ddlCategory.SelectedValue = "-1";
            }

            //
            // Add Branch
            //
            DataSet dsRoles = (new LocationsDAO()).GetAllBranches();
            if (dsRoles == null || dsRoles.Tables.Count == 0)
            {
                ddlBranch.Items.Add(new ListEditItem("--No Records--", "-1"));
            }
            else
            {
                //Master.BindDropdown("BranchCode", "BranchId", dsRoles, ddlBranch);
                ddlBranch.DataSource = dsRoles;
                ddlBranch.TextField  = "BranchCode";
                ddlBranch.ValueField = "BranchId";
                ddlBranch.DataBind();

                ddlBranch.Items.Add(new ListEditItem("All", "-1"));
                ddlBranch.SelectedIndex = ddlBranch.Items.FindByValue(-1).Index;
                //ddlBranch.SelectedItem.Value = -1;
            }

            //
            // Suppliers
            //
            DataSet dsSuppliers = (new SupplierDAO()).GetAllSuppliers();
            if (dsSuppliers == null || dsSuppliers.Tables.Count == 0)
            {
                ddlSupplier.Items.Add(new ListItem("--No Records--", "-1"));
            }
            else
            {
                Master.BindDropdown("Sup_Code", "SupId", dsSuppliers, ddlSupplier);
                ddlSupplier.Items.Add(new ListItem("All", "-1"));
                ddlSupplier.SelectedValue = "-1";
            }


            //
            // Brand
            //
            DataSet dsBrands = new BrandsDAO().GetAllBrands();
            if (dsBrands == null || dsBrands.Tables.Count == 0)
            {
                ddlBrands.Items.Add(new ListItem("--No Data Found--", "-1"));
            }
            else
            {
                Master.BindDropdown("BrandName", "BrandId", dsBrands, ddlBrands);
                ddlBrands.Items.Add(new ListItem("All", "-1"));
                ddlBrands.SelectedValue = "-1";
            }

            //
            // Status
            //
            ListItem[] status = { new ListItem("All", "-1"), new ListItem("Active", "1"), new ListItem("InActive", "0") };
            ddlStatus.Items.AddRange(status);
        }
        catch (Exception ex)
        {
            ex.Data.Add("UILayerException", this.GetType().ToString() + Constant.Error_Seperator + "public void LoadInitialData()");
            if (Master.LoggedUser != null && Master.LoggedUser.UserName != null && Master.LoggedUser.UserName != string.Empty)
            {
                Response.Redirect("Error.aspx?LogId=" + LankaTilesExceptions.WriteEventLogs(ex, Constant.Database_Connection_Name, Master.LoggedUser.UserName), false);
            }
            else
            {
                Response.Redirect("Error.aspx?LogId=" + LankaTilesExceptions.WriteEventLogs(ex, Constant.Database_Connection_Name, "Annonimous"), false);
            }
        }
    }
예제 #9
0
 public BrandController()
 {
     DAO           = new BrandsDAO();
     GeraProximoId = true;
 }