protected void grdPromotionCode_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.InitInsertCommandName)
        {
            Response.Redirect("PromotionCodeAdd.aspx");
        }
        else if (e.CommandName == RadGrid.EditCommandName)
        {
            GridEditableItem item = e.Item as GridEditableItem;
            int id = (int)item.GetDataKeyValue("PromotionCodeId");
            Response.Redirect("PromotionCodeAdd.aspx?id=" + id);
        }
        else if (e.CommandName == RadGrid.DeleteCommandName)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;

            if (editedItem != null)
            {
                try
                {
                    Telerik.Web.UI.DataKey key = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex];
                    int id = (int)key["PromotionCodeId"];
                    _promoCodeManage.DeletePromotionCode(id);
                }
                catch (Exception ex)
                {
                }
                GetPromotionCodes();
            }
        }
    }
    protected void grdProductAdon_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.DeleteCommandName)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;

            if (editedItem != null)
            {
                Label error = editedItem.FindControl("error") as Label;

                try
                {
                    Telerik.Web.UI.DataKey key = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex];
                    short id = (short)key["AdOnID"];
                    _adonManager.Deletedon(id);
                }
                catch (Exception ex)
                {
                    error.Text = ex.Message;
                }
                BindData();
            }
        }
    }
    protected void grdOptionTypes_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.PerformInsertCommandName)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;

            if (editedItem != null)
            {
                RadTextBox name        = editedItem.FindControl("txtOptionTypeName") as RadTextBox;
                RadTextBox displaytext = editedItem.FindControl("txtOptionTypeDispllayText") as RadTextBox;
                Label      error       = editedItem.FindControl("error") as Label;
                if (!string.IsNullOrEmpty(name.Text) && !string.IsNullOrEmpty(displaytext.Text))
                {
                    try
                    {
                        OptionType optionType = new OptionType();
                        optionType.OptionTypeName    = name.Text;
                        optionType.OptionDisplayText = displaytext.Text;

                        entities.OptionTypes.Add(optionType);
                        int value = entities.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        RadAjaxManager1.Alert("Error occured while adding option type. Error Detail ->" + ex.Message);
                    }
                }
                else
                {
                    error.Text = "Enter required valid values.";
                    e.Canceled = true;
                }
                BindData();
            }
        }
        else if (e.CommandName == RadGrid.UpdateCommandName)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;

            if (editedItem != null)
            {
                RadTextBox name        = editedItem.FindControl("txtOptionTypeName") as RadTextBox;
                RadTextBox displaytext = editedItem.FindControl("txtOptionTypeDispllayText") as RadTextBox;
                Label      error       = editedItem.FindControl("error") as Label;
                if (!string.IsNullOrEmpty(name.Text) && !string.IsNullOrEmpty(displaytext.Text))
                {
                    try
                    {
                        Telerik.Web.UI.DataKey key = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex];
                        short      id         = (short)key["OptionTypeID"];
                        OptionType optiontype = (from ot in entities.OptionTypes
                                                 where ot.OptionTypeID == id
                                                 select ot).FirstOrDefault();
                        if (optiontype != null)
                        {
                            using (TransactionScope transaction = new TransactionScope())
                            {
                                optiontype.OptionTypeName    = name.Text;
                                optiontype.OptionDisplayText = displaytext.Text;
                                entities.SaveChanges();
                                transaction.Complete();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        RadAjaxManager1.Alert("Error occured while updating option type. Error Detail ->" + ex.Message);
                    }
                }
                else
                {
                    error.Text = "Enter required valid values.";
                    e.Canceled = true;
                }
                BindData();
            }
        }
    }
    protected void grdProducts_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.InitInsertCommandName)
        {
            Response.Redirect("AddProductInBranch.aspx");
        }
        else if (e.CommandName == RadGrid.DeleteCommandName)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            if (editedItem != null)
            {
                Telerik.Web.UI.DataKey key = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex];
                long id = (long)key["BranchProductID"];
                using (TransactionScope transaction = new TransactionScope())
                {
                    List <ProductAdon> productAdonList = (from productAdon in entities.ProductAdons
                                                          join productTypeAdon in entities.AdOnTypeInProducts on productAdon.ProductAdonTypeID equals productTypeAdon.ProductsAdOnTypeId
                                                          where productTypeAdon.BrachProductID == id
                                                          select productAdon).ToList();
                    List <AdOnTypeInProduct> productAdonTypeList = (from productTypeAdon in entities.AdOnTypeInProducts
                                                                    where productTypeAdon.BrachProductID == id
                                                                    select productTypeAdon).ToList();
                    if (productAdonList.Count > 0)
                    {
                        foreach (ProductAdon productAdon in productAdonList)
                        {
                            entities.ProductAdons.Remove(productAdon);
                        }
                    }

                    if (productAdonTypeList.Count > 0)
                    {
                        foreach (AdOnTypeInProduct productAdonType in productAdonTypeList)
                        {
                            entities.AdOnTypeInProducts.Remove(productAdonType);
                        }
                    }

                    List <ProductOptionsInProduct> productOptionList = (from productOption in entities.ProductOptionsInProducts
                                                                        join productOptionType in entities.OptionTypesInProducts on productOption.ProductsOptionTypeId equals productOptionType.ProductsOptionTypeId
                                                                        where productOptionType.BranchProductID == id
                                                                        select productOption).ToList();
                    List <OptionTypesInProduct> productOptionTypeList = (from productOptionType in entities.OptionTypesInProducts
                                                                         where productOptionType.BranchProductID == id
                                                                         select productOptionType).ToList();
                    if (productOptionList.Count > 0)
                    {
                        foreach (ProductOptionsInProduct productAdon in productOptionList)
                        {
                            entities.ProductOptionsInProducts.Remove(productAdon);
                        }
                    }

                    if (productOptionTypeList.Count > 0)
                    {
                        foreach (OptionTypesInProduct productAdonType in productOptionTypeList)
                        {
                            entities.OptionTypesInProducts.Remove(productAdonType);
                        }
                    }
                    ProductsInBranch productInBranch = (from productBranch in entities.ProductsInBranches where productBranch.BranchProductID == id select productBranch).FirstOrDefault();
                    entities.ProductsInBranches.Remove(productInBranch);
                    entities.SaveChanges();
                    transaction.Complete();
                }
            }
        }
    }
    protected void grdProductAdonType_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.PerformInsertCommandName)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;

            if (editedItem != null)
            {
                RadTextBox name     = editedItem.FindControl("txtAdOnTypeName") as RadTextBox;
                CheckBox   chk      = editedItem.FindControl("txtFree") as CheckBox;
                FileUpload txtImage = editedItem.FindControl("txtImage") as FileUpload;
                Label      error    = editedItem.FindControl("error") as Label;

                if (!string.IsNullOrEmpty(name.Text))
                {
                    try
                    {
                        AdonType adOnType = new AdonType();
                        adOnType.AdOnTypeName   = name.Text;
                        adOnType.IsFreeAdonType = chk.Checked;
                        string filename = string.Empty;
                        if (txtImage.HasFile)
                        {
                            filename = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(txtImage.FileName);
                        }

                        adOnType.ImageName = filename;
                        Int16 result = _adonTypeManager.AddAdonType(adOnType);
                        if (result > 0)
                        {
                            if (txtImage.HasFile)
                            {
                                String path = Server.MapPath("~/Products/AdonTypeImage/");
                                txtImage.SaveAs(path + filename);
                                ThumbImage(path + filename, path + filename, 60, 60);
                            }
                            name.Text = string.Empty;
                        }
                    }
                    catch (Exception ex)
                    {
                        // RadAjaxManager1.Alert("Error occured while Adding new Record. Error Detail ->" + ex.Message);
                    }
                }
            }
        }
        else if (e.CommandName == RadGrid.UpdateCommandName)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;

            if (editedItem != null)
            {
                RadTextBox name     = editedItem.FindControl("txtAdOnTypeName") as RadTextBox;
                CheckBox   chk      = editedItem.FindControl("txtFree") as CheckBox;
                FileUpload txtImage = editedItem.FindControl("txtImage") as FileUpload;
                Label      error    = editedItem.FindControl("error") as Label;
                if (!string.IsNullOrEmpty(name.Text))
                {
                    try
                    {
                        Telerik.Web.UI.DataKey key = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex];
                        short    id       = (short)key["AdOnTypeId"];
                        AdonType adOnType = new AdonType();
                        adOnType.AdOnTypeId     = id;
                        adOnType.AdOnTypeName   = name.Text;
                        adOnType.IsFreeAdonType = chk.Checked;
                        string filename = string.Empty;
                        if (txtImage.HasFile)
                        {
                            filename = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(txtImage.FileName);
                        }

                        adOnType.ImageName = filename;
                        Int32 result = _adonTypeManager.UpdateAdonType(adOnType);
                        if (result > 0)
                        {
                            if (txtImage.HasFile)
                            {
                                String path = Server.MapPath("~/Products/AdonTypeImage/");
                                txtImage.SaveAs(path + filename);
                                ThumbImage(path + filename, path + filename, 60, 60);
                            }
                            name.Text = string.Empty;
                        }
                    }
                    catch (Exception ex)
                    {
                        //RadAjaxManager1.Alert("Error occured while updating Record. Error Detail ->" + ex.Message);
                    }
                }
                else
                {
                    error.Text = "Enter required valid values.";
                    e.Canceled = true;
                }
                BindData();
            }
        }
    }
Beispiel #6
0
    protected void grdSliderImage_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.PerformInsertCommandName)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;

            if (editedItem != null)
            {
                RadTextBox     name        = editedItem.FindControl("txtImageName") as RadTextBox;
                RadTextBox     description = editedItem.FindControl("txtDescription") as RadTextBox;
                RadAsyncUpload image       = editedItem.FindControl("txtImage") as RadAsyncUpload;
                CheckBox       chk         = editedItem.FindControl("txtIsEnabled") as CheckBox;
                Label          error       = editedItem.FindControl("error") as Label;

                if (!string.IsNullOrEmpty(name.Text) && image.UploadedFiles.Count > 0)
                {
                    try
                    {
                        SliderImage slider = new SliderImage();
                        slider.ImageName   = name.Text.Trim();
                        slider.Description = description.Text.Trim();
                        slider.ImagePath   = image.UploadedFiles[0].FileName;
                        slider.IsEnabled   = chk.Checked;
                        _sliderImageManager.AddUpdateImageSlider(slider);
                        image.UploadedFiles[0].SaveAs(Server.MapPath("~/Sliders/" + slider.ImagePath));
                    }
                    catch (Exception ex)
                    {
                        RadAjaxManager1.Alert("Error occured while Adding new Record. Error Detail ->" + ex.Message);
                    }
                }
                else
                {
                    RadAjaxManager1.Alert("Image Name and Image File are required.");
                }
            }
        }
        else if (e.CommandName == RadGrid.UpdateCommandName)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;

            if (editedItem != null)
            {
                Telerik.Web.UI.DataKey key = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex];

                RadTextBox     name        = editedItem.FindControl("txtImageName") as RadTextBox;
                RadTextBox     description = editedItem.FindControl("txtDescription") as RadTextBox;
                RadAsyncUpload image       = editedItem.FindControl("txtImage") as RadAsyncUpload;
                CheckBox       chk         = editedItem.FindControl("txtIsEnabled") as CheckBox;
                Label          error       = editedItem.FindControl("error") as Label;

                if (!string.IsNullOrEmpty(name.Text))
                {
                    try
                    {
                        SliderImage slider = new SliderImage();
                        slider.SliderImageId = (Int32)key["SliderImageId"];
                        slider.ImageName     = name.Text.Trim();
                        slider.Description   = description.Text.Trim();
                        if (image.UploadedFiles.Count > 0)
                        {
                            slider.ImagePath = image.UploadedFiles[0].FileName;
                        }
                        else
                        {
                            slider.ImagePath = String.Empty;
                        }
                        slider.IsEnabled = chk.Checked;
                        _sliderImageManager.AddUpdateImageSlider(slider);
                        if (image.UploadedFiles.Count > 0)
                        {
                            image.UploadedFiles[0].SaveAs(Server.MapPath("~/Sliders/" + slider.ImagePath));
                        }
                    }
                    catch (Exception ex)
                    {
                        RadAjaxManager1.Alert("Error occured while Adding new Record. Error Detail ->" + ex.Message);
                    }
                }
                else
                {
                    RadAjaxManager1.Alert("Image Name and Image File are required.");
                }
                BindData();
            }
        }
        else if (e.CommandName == RadGrid.DeleteCommandName)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;

            if (editedItem != null)
            {
                Telerik.Web.UI.DataKey key = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex];
                Int32 id     = (Int32)key["SliderImageId"];
                Int32 result = _sliderImageManager.DeleteSliderImage(id);
                if (result > 0)
                {
                    BindData();
                }
            }
        }
    }
    protected void grdProductCategory_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.PerformInsertCommandName)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;

            if (editedItem != null)
            {
                RadTextBox name                 = editedItem.FindControl("txtCategoryName") as RadTextBox;
                RadTextBox description          = editedItem.FindControl("txtDescription") as RadTextBox;
                CheckBox   enable               = editedItem.FindControl("txtEnabled") as CheckBox;
                RadTextBox displayOrder         = editedItem.FindControl("txtDisplayOrder") as RadTextBox;
                FileUpload txtImage             = editedItem.FindControl("txtImage") as FileUpload;
                CheckBox   txtDisplayOnHomePage = editedItem.FindControl("txtDisplayOnHomePage") as CheckBox;
                CheckBox   txtDisplayOnWebSite  = editedItem.FindControl("txtDisplayOnWebSite") as CheckBox;
                CheckBox   txtDisplayOnDesktop  = editedItem.FindControl("txtDisplayOnDesktop") as CheckBox;

                if (!string.IsNullOrEmpty(name.Text))
                {
                    try
                    {
                        ProductCategory category = new ProductCategory();
                        category.Name              = name.Text;
                        category.Description       = description.Text;
                        category.IsActive          = enable.Checked;
                        category.DisplayOrder      = Convert.ToInt16(displayOrder.Text);
                        category.DisplayOnHomePage = txtDisplayOnHomePage.Checked;
                        category.WebCategory       = txtDisplayOnWebSite.Checked;
                        category.DesktopCategory   = txtDisplayOnDesktop.Checked;
                        string filename = string.Empty;
                        if (txtImage.HasFile)
                        {
                            filename = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(txtImage.FileName);
                        }

                        category.ImagePath = filename;
                        entities.ProductCategories.Add(category);
                        int value = entities.SaveChanges();
                        if (value > 0)
                        {
                            if (txtImage.HasFile)
                            {
                                String path = Server.MapPath("~/Products/Category/");
                                txtImage.SaveAs(path + filename);
                                ThumbImage(path + filename, path + "S_" + filename, 60, 60);
                                ThumbImage(path + filename, path + "M_" + filename, 200, 110);
                                ThumbImage(path + filename, path + "L_" + filename, 280, 180);
                            }
                        }
                        ShowMessage("Product category has been saved successfully.", MessageType.Success);
                    }
                    catch (Exception ex)
                    {
                        //RadAjaxManager1.Alert("Error occured while updating Category Record. Error Detail ->" + ex.Message);
                    }
                }
            }
        }
        else if (e.CommandName == RadGrid.UpdateCommandName)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;

            if (editedItem != null)
            {
                RadTextBox name                 = editedItem.FindControl("txtCategoryName") as RadTextBox;
                RadTextBox description          = editedItem.FindControl("txtDescription") as RadTextBox;
                CheckBox   enable               = editedItem.FindControl("txtEnabled") as CheckBox;
                RadTextBox displayOrder         = editedItem.FindControl("txtDisplayOrder") as RadTextBox;
                FileUpload txtImage             = editedItem.FindControl("txtImage") as FileUpload;
                CheckBox   txtDisplayOnHomePage = editedItem.FindControl("txtDisplayOnHomePage") as CheckBox;
                CheckBox   txtDisplayOnWebSite  = editedItem.FindControl("txtDisplayOnWebSite") as CheckBox;
                CheckBox   txtDisplayOnDesktop  = editedItem.FindControl("txtDisplayOnDesktop") as CheckBox;
                Label      error                = editedItem.FindControl("error") as Label;

                if (!string.IsNullOrEmpty(name.Text))
                {
                    try
                    {
                        Telerik.Web.UI.DataKey key = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex];
                        short           id         = (short)key["CategoryID"];
                        ProductCategory category   = (from c in entities.ProductCategories
                                                      where c.CategoryID == id
                                                      select c).FirstOrDefault();
                        if (category != null)
                        {
                            using (TransactionScope transaction = new TransactionScope())
                            {
                                category.Name              = name.Text;
                                category.Description       = description.Text;
                                category.IsActive          = enable.Checked;
                                category.DisplayOrder      = Convert.ToInt16(displayOrder.Text);
                                category.DisplayOnHomePage = txtDisplayOnHomePage.Checked;
                                category.WebCategory       = txtDisplayOnWebSite.Checked;
                                category.DesktopCategory   = txtDisplayOnDesktop.Checked;
                                string filename = string.Empty;
                                if (txtImage.HasFile)
                                {
                                    filename = Guid.NewGuid().ToString() +
                                               System.IO.Path.GetExtension(txtImage.FileName);

                                    category.ImagePath = filename;
                                }
                                int value = entities.SaveChanges();
                                transaction.Complete();

                                if (value > 0)
                                {
                                    if (txtImage.HasFile)
                                    {
                                        String path = Server.MapPath("~/Products/Category/");
                                        txtImage.SaveAs(path + filename);
                                        ThumbImage(path + filename, path + "S_" + filename, 60, 60);
                                        ThumbImage(path + filename, path + "M_" + filename, 200, 110);
                                        ThumbImage(path + filename, path + "L_" + filename, 280, 180);
                                    }
                                }
                                ShowMessage("Product category has been saved successfully.", MessageType.Success);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        //RadAjaxManager1.Alert("Error occured while updating Category Record. Error Detail ->" + ex.Message);
                    }
                }
                else
                {
                    error.Text = "Enter required valid values.";
                    e.Canceled = true;
                }
                BindData();
            }
        }
        else if (e.CommandName == RadGrid.DeleteCommandName)
        {
            GridEditableItem item = e.Item as GridEditableItem;
            Int16            id   = (Int16)item.GetDataKeyValue("CategoryID");
            try
            {
                int result = _categoryManager.DeleteProductCategory(id);
                if (result > 0)
                {
                    BindData();
                }
            }
            catch (Exception ex)
            {
                txtError.Text = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
            }
        }
    }