Exemplo n.º 1
0
    private void CheckAvailbilityOfOptionsofProducts()
    {
        txtError.Text = string.Empty;
        try
        {
            if (!string.IsNullOrEmpty(txtCbBranch.SelectedValue) && !string.IsNullOrEmpty(txtCbProduct.SelectedValue) && !string.IsNullOrEmpty(txtCbAdonType.SelectedValue))
            {
                int   branchid   = int.Parse(txtCbBranch.SelectedValue);
                int   productid  = int.Parse(txtCbProduct.SelectedValue);
                short adontypeid = short.Parse(txtCbAdonType.SelectedValue);

                AdOnTypeInProduct adontypeproduct = (from otp in entities.AdOnTypeInProducts
                                                     join bp in entities.ProductsInBranches on otp.BrachProductID equals bp.BranchProductID
                                                     where otp.AdonType.AdOnTypeId == adontypeid && bp.BranchID == branchid && bp.ProductID == productid
                                                     select otp).FirstOrDefault();
                if (adontypeproduct != null)
                {
                    txtPrice.Value = Convert.ToDouble(adontypeproduct.Price);
                }
            }
        }
        catch (Exception ex)
        {
            txtError.Text = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
        }
    }
Exemplo n.º 2
0
 protected void txtAdonsList_ItemDataBound(object sender, RadListViewItemEventArgs e)
 {
     if (e.Item is RadListViewDataItem)
     {
         RadListViewDataItem item  = e.Item as RadListViewDataItem;
         AdOnTypeInProduct   obj   = item.DataItem as AdOnTypeInProduct;
         RadListView         adons = item.FindControl("txtAdons") as RadListView;
         Panel AdonHeading         = item.FindControl("AdonHeading") as Panel;
         Panel NoneFullHeading     = item.FindControl("NoneFullHeading") as Panel;
         adons.DataSource = obj.ProductAdons.OrderBy(pd => pd.Adon.AdOnName);
         adons.DataBind();
         if (obj.DisplayFormat == 1)
         {
             AdonHeading.Visible = true;
         }
         else if (obj.DisplayFormat == 4)
         {
             NoneFullHeading.Visible = true;
         }
     }
 }
Exemplo n.º 3
0
    private void Set_AdonTypeInProducts_LocalObject()
    {
        if (!string.IsNullOrEmpty(txtCbBranch.SelectedValue) && !string.IsNullOrEmpty(txtCbProduct.SelectedValue) && !string.IsNullOrEmpty(txtCbAdonType.SelectedValue))
        {
            int   branchid   = int.Parse(txtCbBranch.SelectedValue);
            int   productid  = int.Parse(txtCbProduct.SelectedValue);
            short adontypeid = short.Parse(txtCbAdonType.SelectedValue);

            atPObj = (from otp in entities.AdOnTypeInProducts
                      join bp in entities.ProductsInBranches on otp.BrachProductID equals bp.BranchProductID
                      where otp.AdonType.AdOnTypeId == adontypeid && bp.BranchID == branchid && bp.ProductID == productid
                      select otp).FirstOrDefault();
            if (atPObj != null)
            {
                if (atPObj.Price != null)
                {
                    txtPrice.Text = atPObj.Price.Value.ToString();
                }
                txtCbDisplayFormat.SelectedValue = atPObj.DisplayFormat.Value.ToString();
            }
        }
    }
Exemplo n.º 4
0
        public OrderDetailSubProduct GetOrderDetailSubProduct()
        {
            Double productPrice = 0, toppingPrice = 0;
            bool   CalculateAdonPrice = false;
            List <OrderDetailSubProductAdon>   orderDetailAdonList    = new List <OrderDetailSubProductAdon>();
            List <OrderDetailSubProductOption> orderDetailOptionsList = new List <OrderDetailSubProductOption>();

            #region Order Detail Sub Product

            OrderDetailSubProduct orderDetailSubProduct = new OrderDetailSubProduct();
            orderDetailSubProduct.ProductId     = _product.ProductID;
            orderDetailSubProduct.Quantity      = 1;
            orderDetailSubProduct.ProductName   = _product.Name;
            orderDetailSubProduct.RecipientName = String.Empty;
            orderDetailSubProduct.Comments      = String.Empty;
            orderDetailSubProduct.OrderDetailSubProductAdons   = new List <OrderDetailSubProductAdon>();
            orderDetailSubProduct.OrderDetailSubProductOptions = new List <OrderDetailSubProductOption>();

            #endregion

            #region Options


            for (int i = 0; i < lbOptions.Items.Count; i++)
            {
                DependencyObject obj = lbOptions.ItemContainerGenerator.ContainerFromIndex(i);
                if (obj != null)
                {
                    ContentPresenter     optionTypeContentPresenter = FindVisualChild <ContentPresenter>(obj);
                    OptionTypesInProduct optionType = (OptionTypesInProduct)optionTypeContentPresenter.Content;
                    ListBox OptionList = FindVisualChild <ListBox>(obj);
                    if (optionType.IsSamePrice && !optionType.IsMultiSelect)
                    {
                        CalculateAdonPrice = true;
                        for (int j = 0; j < OptionList.Items.Count; j++)
                        {
                            DependencyObject obj1 = OptionList.ItemContainerGenerator.ContainerFromIndex(j);
                            // Getting the ContentPresenter of myListBoxItem
                            ContentPresenter myContentPresenter = FindVisualChild <ContentPresenter>(obj1);
                            // Finding textBlock from the DataTemplate that is set on that ContentPresenter
                            DataTemplate myDataTemplate = myContentPresenter.ContentTemplate;
                            RadioButton  selectedOption = (RadioButton)myDataTemplate.FindName("SelectedOption", myContentPresenter);
                            if (selectedOption.IsChecked.Value)
                            {
                                ProductOptions productOptions = (ProductOptions)myContentPresenter.Content;
                                OrderDetailSubProductOption orderdetailoption = new OrderDetailSubProductOption();
                                orderdetailoption.ProductOptionId   = productOptions.OptionID;
                                orderdetailoption.ProductOptionName = productOptions.OptionName;
                                orderdetailoption.Price             = Convert.ToDouble(productOptions.Price);

                                orderDetailSubProduct.OrderDetailSubProductOptions.Add(orderdetailoption);
                            }
                        }
                    }
                    else if (!optionType.IsSamePrice && !optionType.IsMultiSelect)
                    {
                        CalculateAdonPrice = true;
                        if (OptionList.Items.Count == 1)
                        {
                            DependencyObject obj1 = OptionList.ItemContainerGenerator.ContainerFromIndex(0);
                            // Getting the ContentPresenter of myListBoxItem
                            ContentPresenter myContentPresenter = FindVisualChild <ContentPresenter>(obj1);
                            // Finding textBlock from the DataTemplate that is set on that ContentPresenter
                            DataTemplate myDataTemplate = myContentPresenter.ContentTemplate;

                            ProductOptions productOptions = (ProductOptions)myContentPresenter.Content;
                            OrderDetailSubProductOption orderdetailoption = new OrderDetailSubProductOption();
                            orderdetailoption.ProductOptionId   = productOptions.OptionID;
                            orderdetailoption.ProductOptionName = productOptions.OptionName;
                            orderdetailoption.Price             = productOptions.Price;
                            orderDetailSubProduct.OrderDetailSubProductOptions.Add(orderdetailoption);
                            if (_defaultAdonPrice == 0)
                            {
                                _defaultAdonPrice = productOptions.ToppingPrice;
                            }
                        }
                        else
                        {
                            for (int j = 0; j < OptionList.Items.Count; j++)
                            {
                                DependencyObject obj1 = OptionList.ItemContainerGenerator.ContainerFromIndex(j);
                                // Getting the ContentPresenter of myListBoxItem
                                ContentPresenter myContentPresenter = FindVisualChild <ContentPresenter>(obj1);
                                // Finding textBlock from the DataTemplate that is set on that ContentPresenter
                                DataTemplate myDataTemplate = myContentPresenter.ContentTemplate;
                                RadioButton  selectedOption = (RadioButton)myDataTemplate.FindName("SelectedOption", myContentPresenter);
                                if (selectedOption.IsChecked.Value)
                                {
                                    ProductOptions productOptions = (ProductOptions)myContentPresenter.Content;
                                    OrderDetailSubProductOption orderdetailoption = new OrderDetailSubProductOption();
                                    orderdetailoption.ProductOptionId   = productOptions.OptionID;
                                    orderdetailoption.ProductOptionName = productOptions.OptionName;
                                    orderdetailoption.Price             = productOptions.Price;
                                    orderDetailSubProduct.OrderDetailSubProductOptions.Add(orderdetailoption);
                                }
                            }
                        }
                    }
                }
            }

            #endregion

            #region Toppings
            if (CalculateAdonPrice)
            {
                Int16 freeToppingCount = 0;

                for (int i = 0; i < lbToppings.Items.Count; i++)
                {
                    DependencyObject obj = lbToppings.ItemContainerGenerator.ContainerFromIndex(i);
                    if (obj != null)
                    {
                        ContentPresenter  adonTypeContentPresenter = FindVisualChild <ContentPresenter>(obj);
                        AdOnTypeInProduct adonType = (AdOnTypeInProduct)adonTypeContentPresenter.Content;
                        ListBox           AdonList = FindVisualChild <ListBox>(obj);
                        for (int j = 0; j < AdonList.Items.Count; j++)
                        {
                            DependencyObject obj1 = AdonList.ItemContainerGenerator.ContainerFromIndex(j);
                            // Getting the ContentPresenter of myListBoxItem
                            ContentPresenter myContentPresenter = FindVisualChild <ContentPresenter>(obj1);
                            // Finding textBlock from the DataTemplate that is set on that ContentPresenter
                            DataTemplate myDataTemplate  = myContentPresenter.ContentTemplate;
                            Int16        SelectedTopping = Convert.ToInt16(((TextBlock)myDataTemplate.FindName("SelectedTopping", myContentPresenter)).Text);
                            if (SelectedTopping != 0)
                            {
                                if (!adonType.IsFreeAdonType)
                                {
                                    Adon adon = (Adon)myContentPresenter.Content;

                                    OrderDetailSubProductAdon orderdetailadon = new OrderDetailSubProductAdon();
                                    orderdetailadon.AdOnId             = adon.AdOnID;
                                    orderdetailadon.AdonName           = adon.AdOnName;
                                    orderdetailadon.AdonTypeName       = adon.AdOnTypeName;
                                    orderdetailadon.SelectedAdonOption = SelectedTopping;

                                    orderDetailSubProduct.OrderDetailSubProductAdons.Add(orderdetailadon);
                                    if (freeToppingCount == _product.NumberOfFreeTopping)
                                    {
                                        if (adon.DefaultSelected != SelectedTopping)
                                        {
                                            if (_defaultAdonPrice > 0)
                                            {
                                                productPrice += _defaultAdonPrice;
                                            }
                                            else
                                            {
                                                productPrice += (Double)adonType.Price;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        freeToppingCount++;
                                    }
                                }
                                else
                                {
                                    Adon adon = (Adon)myContentPresenter.Content;

                                    OrderDetailSubProductAdon orderdetailadon = new OrderDetailSubProductAdon();
                                    orderdetailadon.AdOnId             = adon.AdOnID;
                                    orderdetailadon.AdonName           = adon.AdOnName;
                                    orderdetailadon.AdonTypeName       = adon.AdOnTypeName;
                                    orderdetailadon.SelectedAdonOption = SelectedTopping;

                                    orderDetailSubProduct.OrderDetailSubProductAdons.Add(orderdetailadon);
                                }
                            }
                        }
                    }
                }
            }

            #endregion

            orderDetailSubProduct.Price = productPrice;
            return(orderDetailSubProduct);
        }
Exemplo n.º 5
0
        public Double GetPrice()
        {
            Double productPrice = 0;


            if (_optionPrice == 0)
            {
                productPrice = _product.UnitPrice;
            }
            else
            {
                productPrice = _optionPrice;
            }
            for (int i = 0; i < lbOptions.Items.Count; i++)
            {
                DependencyObject obj = lbOptions.ItemContainerGenerator.ContainerFromIndex(i);
                if (obj != null)
                {
                    ContentPresenter     adonTypeContentPresenter = FindVisualChild <ContentPresenter>(obj);
                    OptionTypesInProduct optionType = (OptionTypesInProduct)adonTypeContentPresenter.Content;
                    ListBox Options = FindVisualChild <ListBox>(obj);

                    if (!optionType.IsMultiSelect && optionType.IsSamePrice)
                    {
                    }
                }
            }
            Int16 freeToppingCount = 0;

            for (int i = 0; i < lbToppings.Items.Count; i++)
            {
                DependencyObject obj = lbToppings.ItemContainerGenerator.ContainerFromIndex(i);
                if (obj != null)
                {
                    ContentPresenter  adonTypeContentPresenter = FindVisualChild <ContentPresenter>(obj);
                    AdOnTypeInProduct adonType = (AdOnTypeInProduct)adonTypeContentPresenter.Content;
                    ListBox           AdonList = FindVisualChild <ListBox>(obj);

                    for (int j = 0; j < AdonList.Items.Count; j++)
                    {
                        DependencyObject obj1 = AdonList.ItemContainerGenerator.ContainerFromIndex(j);
                        // Getting the ContentPresenter of myListBoxItem
                        ContentPresenter myContentPresenter = FindVisualChild <ContentPresenter>(obj1);
                        // Finding textBlock from the DataTemplate that is set on that ContentPresenter
                        DataTemplate myDataTemplate  = myContentPresenter.ContentTemplate;
                        Int16        SelectedTopping = Convert.ToInt16(((TextBlock)myDataTemplate.FindName("SelectedTopping", myContentPresenter)).Text);
                        if (SelectedTopping != 0)
                        {
                            if (!adonType.IsFreeAdonType)
                            {
                                if (freeToppingCount == _product.NumberOfFreeTopping)
                                {
                                    Adon adon = (Adon)myContentPresenter.Content;
                                    if (adon.DefaultSelected != SelectedTopping)
                                    {
                                        if (_defaultAdonPrice > 0)
                                        {
                                            productPrice += _defaultAdonPrice;
                                        }
                                        else
                                        {
                                            productPrice += (Double)adonType.Price;
                                        }
                                    }
                                }
                                else
                                {
                                    freeToppingCount++;
                                }
                            }
                        }
                    }
                }
            }
            return(productPrice);
        }
Exemplo n.º 6
0
    private void GetOrderAdons(BusinessEntities.OrderDetails orderdetail, decimal adonpricefromOptionType)
    {
        RadListViewDataItemCollection            adoncollection = txtAdonsList.Items;
        List <BusinessEntities.OrderDetailAdOns> list           = new List <BusinessEntities.OrderDetailAdOns>();

        foreach (RadListViewDataItem mainitem in adoncollection)
        {
            Label             txtAdonType       = mainitem.FindControl("txtAdonTypeName") as Label;
            RadListView       txtAdons          = mainitem.FindControl("txtAdons") as RadListView;
            long              productadontypeid = (long)mainitem.GetDataKeyValue("ProductsAdOnTypeId");
            AdOnTypeInProduct adontypeinproduct = (from ATP in entities.AdOnTypeInProducts
                                                   where ATP.ProductsAdOnTypeId == productadontypeid
                                                   select ATP).FirstOrDefault();

            RadListViewDataItemCollection childadoncollection = txtAdons.Items;
            foreach (RadListViewDataItem childitem in childadoncollection)
            {
                long        id             = (long)childitem.GetDataKeyValue("ProductAdOnID");
                ProductAdon productadonObj = (from PA in entities.ProductAdons
                                              where PA.ProductAdOnID == id
                                              select PA).FirstOrDefault();
                if (productadonObj != null)
                {
                    BusinessEntities.OrderDetailAdOns orderdetailadon = new BusinessEntities.OrderDetailAdOns();
                    orderdetailadon.AdOnId       = productadonObj.Adon.AdOnID;
                    orderdetailadon.AdonName     = productadonObj.Adon.AdOnName;
                    orderdetailadon.AdonTypeName = txtAdonType.Text;

                    if (productadonObj.AdOnTypeInProduct.DisplayFormat == 1)
                    {
                        HiddenField SelectedSize = childitem.FindControl("SelectedSize") as HiddenField;
                        HiddenField IsDouble = childitem.FindControl("IsDouble") as HiddenField;
                        short       selectedoption = 0, isDouble = 0;


                        selectedoption = short.Parse(SelectedSize.Value);
                        isDouble       = short.Parse(IsDouble.Value);
                        if (selectedoption != 0)
                        {
                            orderdetailadon.SelectedAdonOption = (BusinessEntities.SelectedOption)selectedoption;
                            if (productadonObj.DefaultSelected == 0 && (selectedoption == 1 || selectedoption == 2 || selectedoption == 3))
                            {
                                if (!productadonObj.Adon.AdonType1.IsFreeAdonType)
                                {
                                    if (isDouble == 1)
                                    {
                                        if (adonpricefromOptionType > 0)
                                        {
                                            orderdetail.Price += Convert.ToDouble(2 * adonpricefromOptionType);
                                        }
                                        else
                                        {
                                            orderdetail.Price += Convert.ToDouble(2 * (decimal)adontypeinproduct.Price);
                                        }
                                        orderdetailadon.IsDoubleSelected = true;
                                    }
                                    else
                                    {
                                        if (adonpricefromOptionType > 0)
                                        {
                                            orderdetail.Price += Convert.ToDouble(adonpricefromOptionType);
                                        }
                                        else
                                        {
                                            orderdetail.Price += Convert.ToDouble((decimal)adontypeinproduct.Price);
                                        }
                                        orderdetailadon.IsDoubleSelected = false;
                                    }
                                }
                                else
                                {
                                    orderdetail.Price += Convert.ToDouble(adontypeinproduct.Price);
                                }
                                list.Add(orderdetailadon);
                            }
                            else if (isDouble == 1)
                            {
                                if (adonpricefromOptionType > 0)
                                {
                                    orderdetail.Price += Convert.ToDouble(adonpricefromOptionType);
                                }
                                else
                                {
                                    orderdetail.Price += Convert.ToDouble((decimal)adontypeinproduct.Price);
                                }
                                orderdetailadon.IsDoubleSelected = true;
                                list.Add(orderdetailadon);
                            }
                            else if (productadonObj.DefaultSelected == 1)
                            {
                                orderdetail.Price += 0;
                                orderdetailadon.IsDoubleSelected = false;
                                list.Add(orderdetailadon);
                            }
                        }
                    }
                    else if (productadonObj.AdOnTypeInProduct.DisplayFormat == 2)
                    {
                        list.Add(orderdetailadon);
                    }
                    else if (productadonObj.AdOnTypeInProduct.DisplayFormat == 4)
                    {
                        HiddenField SelectedSize   = childitem.FindControl("SelectedSize") as HiddenField;
                        short       selectedoption = 0;
                        selectedoption = short.Parse(SelectedSize.Value);

                        orderdetailadon.SelectedAdonOption = (BusinessEntities.SelectedOption)selectedoption;
                        if (productadonObj.DefaultSelected == 0 && selectedoption == 1)
                        {
                            if (!productadonObj.Adon.AdonType1.IsFreeAdonType)
                            {
                                orderdetail.Price += Convert.ToDouble((decimal)adontypeinproduct.Price);
                            }
                        }
                        list.Add(orderdetailadon);
                    }
                }
            }
        }
        SessionOrderAdonList.Add(list);
    }
Exemplo n.º 7
0
    private void GetPrice()
    {
        try
        {
            long             branchproductid = long.Parse(Request.QueryString["BPID"]);
            ProductsInBranch bpObj           = (from bp in entities.ProductsInBranches
                                                where bp.BranchProductID == branchproductid
                                                select bp).FirstOrDefault();
            if (bpObj != null)
            {
                if (bpObj.AddToCheckOut != null && bpObj.AddToCheckOut.Value)
                {
                    productprice = (Decimal)bpObj.CheckOutPrice;
                }
                else
                {
                    productprice = (Decimal)bpObj.Price;
                }

                #region Options

                RadListViewDataItemCollection optioncollection = txtOptions.Items;
                decimal adonpricefromOptionType = 0;
                foreach (RadListViewDataItem item in optioncollection)
                {
                    long id = (long)item.GetDataKeyValue("ProductsOptionTypeId");
                    OptionTypesInProduct OTP = (from otp in entities.OptionTypesInProducts
                                                where otp.ProductsOptionTypeId == id
                                                select otp).FirstOrDefault();

                    if (OTP.IsSamePrice)
                    {
                        if (OTP.IsProductPriceChangeType)
                        {
                            productprice = (decimal)OTP.ProductOptionsInProducts.ToList()[0].Price;
                        }
                    }
                    else
                    {
                        if (OTP.IsMultiSelect)
                        {
                            CheckBoxList chkList = item.FindControl("CheckBoxList") as CheckBoxList;
                            foreach (ListItem listitem in chkList.Items)
                            {
                                if (listitem.Selected)
                                {
                                    long POP_ID = long.Parse(listitem.Value); ////Product Option In Product ID
                                    ProductOptionsInProduct POP_obj = (from pop in entities.ProductOptionsInProducts
                                                                       where pop.ProductOptionsInProductID == POP_ID
                                                                       select pop).FirstOrDefault();
                                    productprice += (decimal)POP_obj.Price;
                                }
                            }
                        }
                        else
                        {
                            RadioButtonList radioList = item.FindControl("RadioButtonList") as RadioButtonList;
                            foreach (ListItem listitem in radioList.Items)
                            {
                                if (listitem.Selected)
                                {
                                    long POP_ID = long.Parse(listitem.Value); ////Product Option In Product ID
                                    ProductOptionsInProduct POP_obj = (from pop in entities.ProductOptionsInProducts
                                                                       where pop.ProductOptionsInProductID == POP_ID
                                                                       select pop).FirstOrDefault();

                                    if ((bool)OTP.IsProductPriceChangeType)
                                    {
                                        productprice = (decimal)POP_obj.Price;
                                        if (POP_obj.ToppingPrice != null)
                                        {
                                            adonpricefromOptionType = (decimal)POP_obj.ToppingPrice;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                #endregion

                RadListViewDataItemCollection adoncollection = txtAdonsList.Items;
                foreach (RadListViewDataItem mainitem in adoncollection)
                {
                    RadListView       txtAdons          = mainitem.FindControl("txtAdons") as RadListView;
                    long              productadontypeid = (long)mainitem.GetDataKeyValue("ProductsAdOnTypeId");
                    AdOnTypeInProduct adontypeinproduct = (from ATP in entities.AdOnTypeInProducts
                                                           where ATP.ProductsAdOnTypeId == productadontypeid
                                                           select ATP).FirstOrDefault();

                    RadListViewDataItemCollection childadoncollection = txtAdons.Items;
                    foreach (RadListViewDataItem childitem in childadoncollection)
                    {
                        long        id             = (long)childitem.GetDataKeyValue("ProductAdOnID");
                        ProductAdon productadonObj = (from PA in entities.ProductAdons
                                                      where PA.ProductAdOnID == id
                                                      select PA).FirstOrDefault();
                        if (productadonObj != null)
                        {
                            if (productadonObj.AdOnTypeInProduct.DisplayFormat == 1)
                            {
                                HiddenField SelectedSize = childitem.FindControl("SelectedSize") as HiddenField;
                                HiddenField IsDouble = childitem.FindControl("IsDouble") as HiddenField;
                                short       selectedoption = 0, isDouble = 0;


                                selectedoption = short.Parse(SelectedSize.Value);
                                isDouble       = short.Parse(IsDouble.Value);

                                if (selectedoption != 0)
                                {
                                    if (productadonObj.DefaultSelected == 0 && (selectedoption == 1 || selectedoption == 2 || selectedoption == 3))
                                    {
                                        if (!productadonObj.Adon.AdonType1.IsFreeAdonType)
                                        {
                                            if (isDouble == 1)
                                            {
                                                if (adonpricefromOptionType > 0)
                                                {
                                                    productprice += 2 * adonpricefromOptionType;
                                                }
                                                else
                                                {
                                                    productprice += (2 * (decimal)adontypeinproduct.Price);
                                                }
                                            }
                                            else
                                            {
                                                if (adonpricefromOptionType > 0)
                                                {
                                                    productprice += adonpricefromOptionType;
                                                }
                                                else
                                                {
                                                    productprice += (decimal)adontypeinproduct.Price;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (isDouble == 1)
                                            {
                                                if (adonpricefromOptionType > 0)
                                                {
                                                    productprice += adonpricefromOptionType;
                                                }
                                                else
                                                {
                                                    productprice += (decimal)adontypeinproduct.Price;
                                                }
                                            }
                                        }
                                    }
                                    else if (isDouble == 1)
                                    {
                                        if (adonpricefromOptionType > 0)
                                        {
                                            productprice += adonpricefromOptionType;
                                        }
                                        else
                                        {
                                            productprice += (decimal)adontypeinproduct.Price;
                                        }
                                    }
                                }
                                else
                                {
                                    ImageButton Double = childitem.FindControl("Double") as ImageButton;
                                    IsDouble        = childitem.FindControl("IsDouble") as HiddenField;
                                    Double.ImageUrl = "~/image/Double_NotSelected.png";
                                    IsDouble.Value  = "0";
                                }
                                UnSelectOtherSize(childitem, selectedoption);
                            }
                            else if (productadonObj.AdOnTypeInProduct.DisplayFormat == 2 || productadonObj.AdOnTypeInProduct.DisplayFormat == 3)
                            {
                                if (!productadonObj.Adon.AdonType1.IsFreeAdonType)
                                {
                                    if (adonpricefromOptionType > 0)
                                    {
                                        productprice += adonpricefromOptionType;
                                    }
                                    else
                                    {
                                        productprice += (decimal)adontypeinproduct.Price;
                                    }
                                }
                            }
                            else if (productadonObj.AdOnTypeInProduct.DisplayFormat == 4)
                            {
                                HiddenField SelectedSize = childitem.FindControl("SelectedSize") as HiddenField;
                                HiddenField IsDouble = childitem.FindControl("IsDouble") as HiddenField;
                                short       selectedoption = 0, isDouble = 0;

                                selectedoption = short.Parse(SelectedSize.Value);
                                isDouble       = short.Parse(IsDouble.Value);

                                if (productadonObj.DefaultSelected == 0 && selectedoption == 1)
                                {
                                    if (!productadonObj.Adon.AdonType1.IsFreeAdonType)
                                    {
                                        productprice += (decimal)adontypeinproduct.Price;
                                    }
                                }
                                UnSelectOtherSize(childitem, selectedoption);
                            }
                        }
                    }
                }
                txtNetPrice.Text = Decimal.Round(productprice, 2).ToString();
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
Exemplo n.º 8
0
    protected void SaveBtn_Click(object sender, EventArgs e)
    {
        if (checkValues())
        {
            int              branchid      = int.Parse(txtCbBranch.SelectedValue);
            int              productid     = int.Parse(txtCbProduct.SelectedValue);
            short            optiontypeid  = short.Parse(txtCbAdonType.SelectedValue);
            short            displayFormat = Convert.ToInt16(txtCbDisplayFormat.SelectedValue);
            ProductsInBranch productbranch = (from pb in entities.ProductsInBranches
                                              where pb.BranchID == branchid && pb.ProductID == productid
                                              select pb).FirstOrDefault();
            if (productbranch != null)
            {
                AdOnTypeInProduct adontypeproduct = null;
                if (atPObj != null)
                {
                    adontypeproduct = atPObj;
                }
                else
                {
                    adontypeproduct = new AdOnTypeInProduct();
                }
                GridItemCollection collection = grdAdons.Items;
                bool flag = true;
                if (atPObj == null)
                {
                    foreach (GridItem item in collection)
                    {
                        CheckBox         chk          = item.FindControl("txtSelected") as CheckBox;
                        GridEditableItem editableItem = item as GridEditableItem;
                        short            adonid       = (short)editableItem.GetDataKeyValue("AdOnID");
                        if (chk.Checked)
                        {
                            ProductAdon productadon = new ProductAdon();
                            productadon.AdonID = adonid;
                            CheckBox enable = item.FindControl("txtEnabled") as CheckBox;
                            productadon.Enable = enable.Checked;
                            RadComboBox defaultSeleted = item.FindControl("txtCbDefault") as RadComboBox;
                            productadon.DefaultSelected = short.Parse(defaultSeleted.SelectedValue);
                            adontypeproduct.ProductAdons.Add(productadon);
                        }
                    }
                }
                else
                {
                    foreach (GridItem item in collection)
                    {
                        CheckBox         chk          = item.FindControl("txtSelected") as CheckBox;
                        GridEditableItem editableItem = item as GridEditableItem;
                        short            adonid       = (short)editableItem.GetDataKeyValue("AdOnID");

                        if (chk.Checked)
                        {
                            ProductAdon productadon = null;
                            bool        isNew       = false;
                            productadon = atPObj.ProductAdons.Where(pa => pa.AdonID == adonid).FirstOrDefault();
                            if (productadon == null)
                            {
                                productadon        = new ProductAdon();
                                productadon.AdonID = adonid;
                                isNew = true;
                            }
                            CheckBox enable = item.FindControl("txtEnabled") as CheckBox;
                            productadon.Enable = enable.Checked;
                            RadComboBox defaultSeleted = item.FindControl("txtCbDefault") as RadComboBox;
                            productadon.DefaultSelected = short.Parse(defaultSeleted.SelectedValue);
                            if (isNew)
                            {
                                adontypeproduct.ProductAdons.Add(productadon);
                            }
                            else
                            {
                                adontypeproduct.ProductAdons.Remove(productadon);
                                adontypeproduct.ProductAdons.Add(productadon);
                            }
                        }
                        else
                        {
                            ProductAdon padon = atPObj.ProductAdons.Where(pa => pa.AdonID == adonid).FirstOrDefault();
                            if (padon != null)
                            {
                                atPObj.ProductAdons.Remove(padon);
                                entities.ProductAdons.Remove(padon);
                            }
                        }
                    }
                }

                if (adontypeproduct.ProductAdons.Count > 0)
                {
                    using (TransactionScope transaction = new TransactionScope())
                    {
                        try
                        {
                            if (txtPrice.Value != null)
                            {
                                adontypeproduct.Price = Convert.ToDecimal(txtPrice.Value);
                            }
                            else
                            {
                                adontypeproduct.Price = new Nullable <decimal>();
                            }
                            adontypeproduct.DisplayFormat = displayFormat;
                            if (atPObj == null)
                            {
                                adontypeproduct.AdonTypeID     = optiontypeid;
                                adontypeproduct.BrachProductID = productbranch.BranchProductID;
                                entities.AdOnTypeInProducts.Add(adontypeproduct);
                            }
                            entities.SaveChanges();
                            transaction.Complete();
                            ShowMessage("Product adons have been saved successfully. ", MessageType.Error);
                        }
                        catch (Exception ex)
                        {
                            txtError.Text = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
                        }
                    }
                }
                else if (flag)
                {
                    ShowMessage("You have selected no Adon. You must select Adon to proceed.", MessageType.Error);
                }
            }
        }
    }