Example #1
0
        protected void lstItem_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
        {
            Common            Common         = new Common();
            HtmlInputCheckBox chkList        = (HtmlInputCheckBox)e.Item.FindControl("chkList");
            HyperLink         lnkProductCode = (HyperLink)e.Item.FindControl("lnkProductCode");

            string stParam = "?task=" + Common.Encrypt("list", Session.SessionID) + "&prodid=" + Common.Encrypt(chkList.Value, Session.SessionID);

            switch (e.CommandName)
            {
            case "imgProductTag":
            {
                ImageButton imgProductTag = (ImageButton)e.Item.FindControl("imgProductTag");
                Products    clsProduct    = new Products();

                if (imgProductTag.ToolTip == "Tag this product as INACTIVE.")
                {
                    clsProduct.TagInactive(long.Parse(chkList.Value));
                }
                else
                {
                    clsProduct.TagActive(long.Parse(chkList.Value));
                }

                clsProduct.CommitAndDispose();
                LoadList();
            }
            break;

            case "cmdSaveVariationClick":
            {
                DropDownList cboVariationType = (DropDownList)e.Item.FindControl("cboVariationType");
                SaveVariation(long.Parse(chkList.Value), int.Parse(cboVariationType.SelectedItem.Value), cboVariationType.SelectedItem.Text);
                ProductVariations clsVariation = new ProductVariations();
                cboVariationType.DataTextField  = "VariationType";
                cboVariationType.DataValueField = "VariationID";
                cboVariationType.DataSource     = clsVariation.AvailableVariationsDataTable(long.Parse(chkList.Value), "VariationType", SortOption.Ascending).DefaultView;
                cboVariationType.DataBind();
                cboVariationType.SelectedIndex = cboVariationType.Items.Count - 1;
                clsVariation.CommitAndDispose();
            }
            break;

            case "imgSaveVariationClick":
            {
                DropDownList cboVariationType = (DropDownList)e.Item.FindControl("cboVariationType");
                SaveVariation(long.Parse(chkList.Value), int.Parse(cboVariationType.SelectedItem.Value), cboVariationType.SelectedItem.Text);
                ProductVariations clsVariation = new ProductVariations();
                cboVariationType.DataTextField  = "VariationType";
                cboVariationType.DataValueField = "VariationID";
                cboVariationType.DataSource     = clsVariation.AvailableVariationsDataTable(long.Parse(chkList.Value), "VariationType", SortOption.Ascending).DefaultView;
                cboVariationType.DataBind();
                cboVariationType.SelectedIndex = cboVariationType.Items.Count - 1;
                clsVariation.CommitAndDispose();
            }
            break;

            case "imgVariationsClick":
                stParam = "?task=" + Common.Encrypt("list", Session.SessionID) + "&prodid=" + Common.Encrypt(chkList.Value, Session.SessionID);
                Response.Redirect(Constants.ROOT_DIRECTORY + "/MasterFiles/_Product/_Variations/Default.aspx" + stParam);
                break;

            case "imgVariationsMatrixClick":
                stParam = "?task=" + Common.Encrypt("list", Session.SessionID) + "&prodid=" + Common.Encrypt(chkList.Value, Session.SessionID);
                Response.Redirect(Constants.ROOT_DIRECTORY + "/MasterFiles/_Product/_VariationsMatrix/Default.aspx" + stParam);
                break;

            case "imgUnitsMatrixClick":
                stParam = "?task=" + Common.Encrypt("list", Session.SessionID) + "&prodid=" + Common.Encrypt(chkList.Value, Session.SessionID);
                Response.Redirect(Constants.ROOT_DIRECTORY + "/MasterFiles/_Product/_UnitsMatrix/Default.aspx" + stParam);
                break;

            case "imgVariationsAddClick":
                stParam = "?task=" + Common.Encrypt("add", Session.SessionID) +
                          "&prodid=" + Common.Encrypt(chkList.Value, Session.SessionID);
                Response.Redirect(Constants.ROOT_DIRECTORY + "/MasterFiles/_Product/_Variations/Default.aspx" + stParam);
                break;

            case "imgVariationsMatrixAddClick":
                stParam = "?task=" + Common.Encrypt("add", Session.SessionID) +
                          "&prodid=" + Common.Encrypt(chkList.Value, Session.SessionID);
                Response.Redirect(Constants.ROOT_DIRECTORY + "/MasterFiles/_Product/_VariationsMatrix/Default.aspx" + stParam);
                break;

            case "imgUnitsMatrixAddClick":
                stParam = "?task=" + Common.Encrypt("add", Session.SessionID) +
                          "&prodid=" + Common.Encrypt(chkList.Value, Session.SessionID);
                Response.Redirect(Constants.ROOT_DIRECTORY + "/MasterFiles/_Product/_UnitsMatrix/Default.aspx" + stParam);
                break;

            case "imgPackageMatrixAddClick":
                stParam = "?task=" + Common.Encrypt("add", Session.SessionID) +
                          "&prodid=" + Common.Encrypt(chkList.Value, Session.SessionID);
                Response.Redirect(Constants.ROOT_DIRECTORY + "/MasterFiles/_Product/_Package/Default.aspx" + stParam);
                break;

            case "imgInventoryAdjustmentClick":
                stParam = "?task=" + Common.Encrypt("invadjustment", Session.SessionID) +
                          "&productcode=" + Common.Encrypt(Server.UrlEncode(lnkProductCode.Text), Session.SessionID);
                Response.Redirect(Constants.ROOT_DIRECTORY + "/Inventory/Default.aspx" + stParam);
                break;

            case "imgProductHistoryClick":
                stParam = "?task=" + Common.Encrypt("producthistory", Session.SessionID) +
                          "&productcode=" + Common.Encrypt(Server.UrlEncode(lnkProductCode.Text), Session.SessionID);
                Response.Redirect(Constants.ROOT_DIRECTORY + "/Reports/Default.aspx" + stParam);
                break;

            case "imgProductPriceHistoryClick":
                stParam = "?task=" + Common.Encrypt("pricehistory", Session.SessionID) +
                          "&productcode=" + Common.Encrypt(Server.UrlEncode(lnkProductCode.Text), Session.SessionID);
                Response.Redirect(Constants.ROOT_DIRECTORY + "/Reports/Default.aspx" + stParam);
                break;

            case "imgChangePriceClick":
                stParam = "?task=" + Common.Encrypt("changeprice", Session.SessionID) +
                          "&productcode=" + Common.Encrypt(Server.UrlEncode(lnkProductCode.Text), Session.SessionID);
                Response.Redirect("Default.aspx" + stParam);
                break;

            case "imgFinanceClick":
                stParam = "?task=" + Common.Encrypt("finance", Session.SessionID) +
                          "&prodid=" + Common.Encrypt(chkList.Value, Session.SessionID);
                Response.Redirect(Constants.ROOT_DIRECTORY + "/MasterFiles/_Product/Default.aspx" + stParam);
                break;

            case "imgEditNowClick":
                stParam = "?task=" + Common.Encrypt("edit", Session.SessionID) + "&id=" + Common.Encrypt(chkList.Value, Session.SessionID);
                Response.Redirect("Default.aspx" + stParam);
                break;
            }
        }
Example #2
0
        protected void lstItem_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Header)
            {
                LoadSortFieldOptions(e);
            }
            else if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                string      stParam = string.Empty;
                Common      Common  = new Common();
                DataRowView dr      = (DataRowView)e.Item.DataItem;

                HtmlInputCheckBox chkList = (HtmlInputCheckBox)e.Item.FindControl("chkList");
                chkList.Value = dr[ProductColumnNames.ProductID].ToString();

                ImageButton imgProductTag = (ImageButton)e.Item.FindControl("imgProductTag");
                if (Boolean.Parse(dr[ProductColumnNames.Active].ToString()))
                {
                    imgProductTag.ImageUrl = Constants.ROOT_DIRECTORY + "/_layouts/images/prodtagact.gif";
                    imgProductTag.ToolTip  = "Tag this product as INACTIVE.";
                }
                else //if (clsProductListFilterType == ProductListFilterType.ShowInactiveOnly)
                {
                    imgProductTag.ImageUrl = Constants.ROOT_DIRECTORY + "/_layouts/images/prodtaginact.gif";
                    imgProductTag.ToolTip  = "Tag this product as ACTIVE.";
                }

                //HyperLink lnkVariations = (HyperLink)e.Item.FindControl("lnkVariations");
                stParam = "?task=" + Common.Encrypt("list", Session.SessionID) + "&prodid=" + Common.Encrypt(chkList.Value, Session.SessionID);

                HyperLink lnkPackage = (HyperLink)e.Item.FindControl("lnkPackage");
                lnkPackage.NavigateUrl = Constants.ROOT_DIRECTORY + "/MasterFiles/_Product/_Package/Default.aspx" + stParam;

                HyperLink lnkBarCode = (HyperLink)e.Item.FindControl("lnkBarCode");
                lnkBarCode.Text        = dr[ProductColumnNames.BarCode].ToString();
                lnkBarCode.NavigateUrl = "Default.aspx?task=" + Common.Encrypt("details", Session.SessionID) + "&id=" + Common.Encrypt(chkList.Value, Session.SessionID);

                HyperLink lnkProductCode = (HyperLink)e.Item.FindControl("lnkProductCode");
                lnkProductCode.Text        = dr[ProductColumnNames.ProductCode].ToString();
                lnkProductCode.NavigateUrl = "Default.aspx?task=" + Common.Encrypt("details", Session.SessionID) + "&id=" + Common.Encrypt(chkList.Value, Session.SessionID);

                HyperLink lnkDescription = (HyperLink)e.Item.FindControl("lnkDescription");
                lnkDescription.Text        = dr[ProductColumnNames.ProductDesc].ToString();
                lnkDescription.NavigateUrl = "Default.aspx?task=" + Common.Encrypt("details", Session.SessionID) + "&id=" + Common.Encrypt(dr["ProductID"].ToString(), Session.SessionID);

                HyperLink lnkGroup = (HyperLink)e.Item.FindControl("lnkGroup");
                lnkGroup.Text        = dr[ProductColumnNames.ProductGroupCode].ToString();
                lnkGroup.NavigateUrl = Constants.ROOT_DIRECTORY + "/MasterFiles/_ProductGroup/Default.aspx?task=" + Common.Encrypt("details", Session.SessionID) + "&id=" + Common.Encrypt(dr[ProductColumnNames.ProductGroupID].ToString(), Session.SessionID);;

                HyperLink lnkUnit = (HyperLink)e.Item.FindControl("lnkUnit");
                lnkUnit.Text        = dr[ProductColumnNames.BaseUnitCode].ToString();
                lnkUnit.NavigateUrl = Constants.ROOT_DIRECTORY + "/MasterFiles/_Unit/Default.aspx?task=" + Common.Encrypt("details", Session.SessionID) + "&id=" + Common.Encrypt(dr[ProductColumnNames.BaseUnitID].ToString(), Session.SessionID);;

                Label lblPrice = (Label)e.Item.FindControl("lblPrice");
                lblPrice.Text = Convert.ToDecimal(dr[ProductColumnNames.Price].ToString()).ToString("#,##0.#0");

                Label lblPurchasePrice = (Label)e.Item.FindControl("lblPurchasePrice");
                lblPurchasePrice.Text = Convert.ToDecimal(dr[ProductColumnNames.PurchasePrice].ToString()).ToString("#,##0.#0");

                Label   lblMargin = (Label)e.Item.FindControl("lblMargin");
                decimal decMargin = Convert.ToDecimal(dr[ProductColumnNames.Price].ToString()) - Convert.ToDecimal(dr[ProductColumnNames.PurchasePrice].ToString());
                lblMargin.Text = decMargin.ToString("#,##0.##0");

                try { decMargin = decMargin / Convert.ToDecimal(dr[ProductColumnNames.PurchasePrice].ToString()); }
                catch { decMargin = 1; }
                decMargin       = decMargin * 100;
                lblMargin.Text += " (" + decMargin.ToString("#,##0.##0") + "%)";

                Label lnkSubGroup = (Label)e.Item.FindControl("lnkSubGroup");
                lnkSubGroup.Text = dr[ProductColumnNames.ProductSubGroupCode].ToString();

                Label lblQuantity = (Label)e.Item.FindControl("lblQuantity");
                lblQuantity.Text += dr[ProductColumnNames.ConvertedQuantity].ToString();
                //if (dr[ProductColumnNames.ConvertedMainQuantity].ToString().Split(';').Length > 0)
                //{ lblQuantity.Text += " (" + dr[ProductColumnNames.ConvertedMainQuantity].ToString() + ") "; }
                //else
                //{ lblQuantity.Text = Convert.ToDecimal(dr[ProductColumnNames.MainQuantity].ToString()).ToString("#,##0.#0"); }

                HyperLink lnkSupplierName = (HyperLink)e.Item.FindControl("lnkSupplierName");
                lnkSupplierName.Text        = dr[ProductColumnNames.SupplierName].ToString();
                lnkSupplierName.NavigateUrl = Constants.ROOT_DIRECTORY + "/MasterFiles/_Contact/Default.aspx" + "?task=" + Common.Encrypt("details", Session.SessionID) + "&id=" + Common.Encrypt(dr[ProductColumnNames.SupplierID].ToString(), Session.SessionID);

                CheckBox chkIncludeInSubtotalDiscount = (CheckBox)e.Item.FindControl("chkIncludeInSubtotalDiscount");
                chkIncludeInSubtotalDiscount.Checked = (bool)dr[ProductColumnNames.IncludeInSubtotalDiscount];

                Label lblVAT = (Label)e.Item.FindControl("lblVAT");
                lblVAT.Text = Convert.ToDecimal(dr[ProductColumnNames.VAT].ToString()).ToString("#,##0.#0") + " %";

                Label lblEVAT = (Label)e.Item.FindControl("lblEVAT");
                lblEVAT.Text = Convert.ToDecimal(dr[ProductColumnNames.EVAT].ToString()).ToString("#,##0.#0") + " %";

                Label lblLocalTax = (Label)e.Item.FindControl("lblLocalTax");
                lblLocalTax.Text = Convert.ToDecimal(dr[ProductColumnNames.LocalTax].ToString()).ToString("#,##0.#0") + " %";

                //For anchor
                HtmlGenericControl divInsertVariation = (HtmlGenericControl)e.Item.FindControl("divInsertVariation");
                HtmlAnchor         imgVariationsAdd   = (HtmlAnchor)e.Item.FindControl("imgVariationsAdd");
                imgVariationsAdd.HRef = "javascript:ToggleDiv('" + divInsertVariation.ClientID + "')";

                DropDownList      cboVariationType = (DropDownList)e.Item.FindControl("cboVariationType");
                ProductVariations clsVariation     = new ProductVariations();
                cboVariationType.DataTextField  = "VariationType";
                cboVariationType.DataValueField = "VariationID";
                cboVariationType.DataSource     = clsVariation.AvailableVariationsDataTable(long.Parse(chkList.Value), "VariationType", SortOption.Ascending).DefaultView;
                cboVariationType.DataBind();
                cboVariationType.SelectedIndex = cboVariationType.Items.Count - 1;
                clsVariation.CommitAndDispose();

                imgProductTag.Enabled = cmdEdit.Visible;

                LinkButton cmdSaveVariation = (LinkButton)e.Item.FindControl("cmdSaveVariation");
                cmdSaveVariation.Enabled = Convert.ToBoolean(Convert.ToInt16(lblVariationsAccess.Text));

                ImageButton imgSaveVariation = (ImageButton)e.Item.FindControl("imgSaveVariation");
                imgSaveVariation.Enabled = Convert.ToBoolean(Convert.ToInt16(lblVariationsAccess.Text));
                if (!imgSaveVariation.Enabled)
                {
                    imgSaveVariation.ImageUrl = Constants.ROOT_DIRECTORY + "/_layouts/images/blank.gif";
                }

                ImageButton imgVariations = (ImageButton)e.Item.FindControl("imgVariations");
                imgVariations.Enabled = Convert.ToBoolean(Convert.ToInt16(lblVariationsAccess.Text));
                if (!imgVariations.Enabled)
                {
                    imgVariations.ImageUrl = Constants.ROOT_DIRECTORY + "/_layouts/images/blank.gif";
                }

                ImageButton imgVariationsMatrix = (ImageButton)e.Item.FindControl("imgVariationsMatrix");
                imgVariationsMatrix.Enabled = Convert.ToBoolean(Convert.ToInt16(lblVariationsAccess.Text));
                if (!imgVariationsMatrix.Enabled)
                {
                    imgVariationsMatrix.ImageUrl = Constants.ROOT_DIRECTORY + "/_layouts/images/blank.gif";
                }

                ImageButton imgUnitsMatrix = (ImageButton)e.Item.FindControl("imgUnitsMatrix");
                imgUnitsMatrix.Enabled = Convert.ToBoolean(Convert.ToInt16(lblUnitMatrixAccess.Text));
                if (!imgUnitsMatrix.Enabled)
                {
                    imgUnitsMatrix.ImageUrl = Constants.ROOT_DIRECTORY + "/_layouts/images/blank.gif";
                }

                imgVariationsAdd.Visible = Convert.ToBoolean(Convert.ToInt16(lblVariationsAccess.Text));

                ImageButton imgVariationsMatrixAdd = (ImageButton)e.Item.FindControl("imgVariationsMatrixAdd");
                imgVariationsMatrixAdd.Enabled = Convert.ToBoolean(Convert.ToInt16(lblVariationsAccess.Text));
                if (!imgVariationsMatrixAdd.Enabled)
                {
                    imgVariationsMatrixAdd.ImageUrl = Constants.ROOT_DIRECTORY + "/_layouts/images/blank.gif";
                }

                ImageButton imgUnitsMatrixAdd = (ImageButton)e.Item.FindControl("imgUnitsMatrixAdd");
                imgUnitsMatrixAdd.Enabled = Convert.ToBoolean(Convert.ToInt16(lblUnitMatrixAccess.Text));
                if (!imgUnitsMatrixAdd.Enabled)
                {
                    imgUnitsMatrixAdd.ImageUrl = Constants.ROOT_DIRECTORY + "/_layouts/images/blank.gif";
                }

                lnkPackage.Enabled = Convert.ToBoolean(Convert.ToInt16(lblProductPackageAccess.Text));
                if (!lnkPackage.Enabled)
                {
                    lnkPackage.ImageUrl = Constants.ROOT_DIRECTORY + "/_layouts/images/blank.gif";
                }

                ImageButton imgPackageAdd = (ImageButton)e.Item.FindControl("imgPackageAdd");
                imgPackageAdd.Enabled = Convert.ToBoolean(Convert.ToInt16(lblProductPackageAccess.Text));
                if (!imgPackageAdd.Enabled)
                {
                    imgPackageAdd.ImageUrl = Constants.ROOT_DIRECTORY + "/_layouts/images/blank.gif";
                }

                ImageButton imgInventoryAdjustment = (ImageButton)e.Item.FindControl("imgInventoryAdjustment");
                imgInventoryAdjustment.Enabled = Convert.ToBoolean(Convert.ToInt16(lblInvAdjustmentAccess.Text));
                if (!imgInventoryAdjustment.Enabled)
                {
                    imgInventoryAdjustment.ImageUrl = Constants.ROOT_DIRECTORY + "/_layouts/images/blank.gif";
                }

                ImageButton imgProductHistory = (ImageButton)e.Item.FindControl("imgProductHistory");
                imgProductHistory.Enabled = Convert.ToBoolean(Convert.ToInt16(lblProductsListReportAccess.Text));
                if (!imgProductHistory.Enabled)
                {
                    imgProductHistory.ImageUrl = Constants.ROOT_DIRECTORY + "/_layouts/images/blank.gif";
                }

                ImageButton imgProductPriceHistory = (ImageButton)e.Item.FindControl("imgProductPriceHistory");
                imgProductPriceHistory.Enabled = Convert.ToBoolean(Convert.ToInt16(lblPricesReportAccess.Text));
                if (!imgProductPriceHistory.Enabled)
                {
                    imgProductPriceHistory.ImageUrl = Constants.ROOT_DIRECTORY + "/_layouts/images/blank.gif";
                }

                ImageButton imgChangePrice = (ImageButton)e.Item.FindControl("imgChangePrice");
                imgChangePrice.Enabled = Convert.ToBoolean(Convert.ToInt16(lblChangePriceAccess.Text));
                if (!imgChangePrice.Enabled)
                {
                    imgChangePrice.ImageUrl = Constants.ROOT_DIRECTORY + "/_layouts/images/blank.gif";
                }

                ImageButton imgEditNow = (ImageButton)e.Item.FindControl("imgEditNow");
                imgEditNow.Enabled = cmdEdit.Visible;
                if (!imgEditNow.Enabled)
                {
                    imgEditNow.ImageUrl = Constants.ROOT_DIRECTORY + "/_layouts/images/blank.gif";
                }
            }
        }