Beispiel #1
0
        private void Calculate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                List<priceList> list = new List<priceList>();

                for (int i = 0; i < row; i++)
                {
                    var textbox = (TextBox)OrderItemGrid.Children.Cast<UIElement>().First(e1 => Grid.GetRow(e1) == i && Grid.GetColumn(e1) == 1);
                    var quantity = (TextBox)OrderItemGrid.Children.Cast<UIElement>().First(e1 => Grid.GetRow(e1) == i && Grid.GetColumn(e1) == 3);

                    int item;
                    int intquantity;

                    Int32.TryParse(textbox.Text.ToString(), out item);
                    Int32.TryParse(quantity.Text.ToString(), out intquantity);

                    if (item != 0 && intquantity != 0)
                    {
                        var t = list.Find(item1 => item1.id.Equals(item));
                        var priceTem = DataStore.Store.AllProduct.Find(item1 => item1.ID.Equals(item.ToString()));

                        if (t == null)
                        {
                            priceList pc = new priceList();
                            pc.id = item;
                            pc.quantity = intquantity;
                            pc.price = pc.quantity * Double.Parse(priceTem.Price);

                            list.Add(pc);
                        }
                        else
                        {
                            t.quantity += intquantity;
                            t.price = t.quantity * Double.Parse(priceTem.Price);
                        }
                    }
                }

                double fivePercent;
                double tenPercent;
                double fifteenPercent;
                double twentyPercent;

                double largest = 0;
                string reason = "";

                if (row == 0 || list.Count() == 0)
                    return;

                if (DiscountSchema.Content.Equals("Single Highest Schema"))
                {
                    //5% off if you buy 2 iphone 6 –“Iphone 6 Discount”
                    var temp = list.Find(item1 => item1.id.Equals(1));

                    if (temp.quantity == 2)
                    {
                        var priceTem = DataStore.Store.AllProduct.Find(item1 => item1.ID.Equals("1"));

                        fivePercent = (5 * temp.quantity * Int32.Parse(priceTem.Price)) / 100;
                        largest = fivePercent;
                        reason = "Iphone 6 Discount";
                    }

                    //10% off if its customers birthday on the day of ordering any product. – “Birthday Discount”

                    DateTime today = DateTime.Today;

                    int monthdiff = currentUser.Birthday.Month - today.Month;

                    int daydiff = currentUser.Birthday.Day - today.Day;

                    int yearDiff = currentUser.Birthday.Year - today.Year;

                    double sum = list.Sum(item => item.price);

                    if (monthdiff == 0 && daydiff == 0 && yearDiff != 0)
                    {
                        tenPercent = (10 * sum) / 100;

                        if (tenPercent > largest)
                        {
                            largest = tenPercent;
                            reason = "Birthday Discount";
                        }
                    }

                    //15% off if customer is more than 50 years old  - “Senior Citizen Discount”

                    if (yearDiff > 50)
                    {
                        fifteenPercent = (15 * sum) / 100;

                        if (fifteenPercent > largest)
                        {
                            largest = fifteenPercent;
                            reason = "Senior Citizen Discount";
                        }
                    }

                    //20% off if order total is more than £3000 – “High Value Order Discount”

                    if (sum > 3000)
                    {
                        twentyPercent = (20 * sum) / 100;

                        if (twentyPercent > largest)
                        {
                            largest = twentyPercent;
                            reason = "High Value Order Discount";
                        }
                    }

                    DisList.Text = reason + "\n " + "Single Highest Schema";
                    DisPrice.Text = (sum - largest).ToString();
                }
                else
                {
                    fifteenPercent = 0;
                    tenPercent = 0;
                    fivePercent = 0;
                    twentyPercent = 0;

                    //5% off if you buy 2 iphone 6 –“Iphone 6 Discount”
                    var temp = list.Find(item1 => item1.id.Equals(1));

                    if (temp.quantity == 2)
                    {
                        var priceTem = DataStore.Store.AllProduct.Find(item1 => item1.ID.Equals("1"));

                        fivePercent = (5 * temp.quantity * Int32.Parse(priceTem.Price)) / 100;
                        //largest = fivePercent;
                        reason = "Iphone 6 Discount";
                    }

                    //10% off if its customers birthday on the day of ordering any product. – “Birthday Discount”

                    DateTime today = DateTime.Today;

                    int monthdiff = currentUser.Birthday.Month - today.Month;

                    int daydiff = currentUser.Birthday.Day - today.Day;

                    int yearDiff = currentUser.Birthday.Year - today.Year;

                    double sum = list.Sum(item => item.price);

                    if (monthdiff == 0 && daydiff == 0 && yearDiff != 0)
                    {
                        tenPercent = (10 * sum) / 100;

                        reason += " \n Birthday Discount";
                    }

                    //15% off if customer is more than 50 years old  - “Senior Citizen Discount”

                    if (yearDiff > 50)
                    {
                        fifteenPercent = (15 * sum) / 100;

                        reason += " \n Senior Citizen Discount";
                    }

                    //20% off if order total is more than £3000 – “High Value Order Discount”

                    if (sum > 3000)
                    {
                        twentyPercent = (20 * sum) / 100;

                        reason += " \n High Value Order Discount";
                    }

                    DisList.Text = reason + "\n " + "Multiple Discount Schema";
                    DisPrice.Text = (sum - (fivePercent + tenPercent + fifteenPercent + twentyPercent)).ToString();
                }

                string originalPrice = "";

                foreach (priceList pl in list)
                {
                    originalPrice += "Item no " + pl.id + " cost is " + pl.price;
                }

                OriPrice.Text = originalPrice;
            }
            catch(Exception ex)
            {
                MessageBox.Show("Try Again");
            }
        }
        public HttpResponseMessage Get(string productId)
        {
            HttpResponseMessage message = null;
            string token = HttpContext.Current.Request.Headers["Authorization"].Replace("Bearer ", "").Trim();
            upgradeProductListModel response = new upgradeProductListModel();

            try
            {
                if (dbconn.idbCheck(out dbres))
                {
                    string userCardNo  = string.Empty;
                    string userAdminNo = string.Empty;
                    if (dbconn.checkToken(token, out userCardNo, out userAdminNo))
                    {
                        string    oldProdEndDate = string.Empty;
                        DataTable dtOldProd      = dbconn.getTable(appServiceQry._getupProdState(userCardNo, productId));
                        if (dtOldProd.Rows.Count != 0)
                        {
                            oldProdEndDate = dtOldProd.Rows[0]["ENDDATE"].ToString();
                        }
                        else
                        {
                            oldProdEndDate = DateTime.Now.AddDays(-1).ToString(appConstantValues.DATE_TIME_FORMAT);
                        }
                        DataTable dtCh = dbconn.getTable(appServiceQry._getMainProducts(productId));
                        if (dtCh.Rows.Count != 0)
                        {
                            DataTable dtUp = dbconn.getTable(appServiceQry._getMainProducts(dtCh.Rows[0]["UPGRADE_PRODUCTS"].ToString()));
                            List <upgradeproductDetial> upProds = new List <upgradeproductDetial>();
                            foreach (DataRow dr in dtUp.Rows)
                            {
                                upgradeproductDetial upch = new upgradeproductDetial();
                                upch.productName = dr["PRODUCT_NAME_MON"].ToString();
                                string upNewProdId = dr["PRODUCT_ID"].ToString();
                                upch.productId  = upNewProdId;
                                upch.smsCode    = dr["SMS_CODE"].ToString();
                                upch.productImg = httpUtil.getProductLogoUrl(dr["PRODUCT_ID"].ToString());
                                List <priceList> priceList = new List <priceList>();
                                for (int i = 1; i < 5; i++)
                                {
                                    priceList prLn       = new priceList();
                                    int       newUpPrice = 0;
                                    string    endDateNew = string.Empty;
                                    if (i != 2)
                                    {
                                        prLn.month     = i.ToString();
                                        prLn.productId = upNewProdId;
                                        if (upgradeProductCalculator.calcDate(productId, oldProdEndDate, upNewProdId, i, out newUpPrice, out endDateNew))
                                        {
                                            prLn.price   = newUpPrice.ToString();
                                            prLn.endDate = endDateNew;
                                        }
                                        else
                                        {
                                            throw new InvalidOperationException("Ахиулах багцын үнэ бодоход алдаа гарлаа.");
                                        }
                                        priceList.Add(prLn);
                                    }
                                }
                                upch.priceList = priceList;
                                upProds.Add(upch);
                            }
                            response.isSuccess     = true;
                            response.resultCode    = HttpStatusCode.OK.ToString();
                            response.resultMessage = "success";
                            response.upProducts    = upProds;
                        }
                        else
                        {
                            response.isSuccess     = false;
                            response.resultCode    = HttpStatusCode.NotFound.ToString();
                            response.resultMessage = appConstantValues.MSG_NOFOUND;
                        }
                    }
                    else
                    {
                        response.isSuccess     = false;
                        response.resultCode    = HttpStatusCode.Unauthorized.ToString();
                        response.resultMessage = appConstantValues.MSG_EXPIRED;
                    }
                }
                else
                {
                    response.isSuccess     = false;
                    response.resultCode    = HttpStatusCode.NotFound.ToString();
                    response.resultMessage = appConstantValues.MSG_INTERNAL_ERROR;
                    LogWriter._error(TAG, dbres);
                }
            }
            catch (Exception ex)
            {
                exceptionManager.ManageException(ex, TAG);
                response.isSuccess     = false;
                response.resultCode    = HttpStatusCode.NotFound.ToString();
                response.resultMessage = appConstantValues.MSG_INTERNAL_ERROR;
            }
            message = Request.CreateResponse(HttpStatusCode.OK, response);
            string req = string.Format(@"PRODUCT: [{0}]", productId);

            LogWriter._upgradeProduct(TAG, string.Format("IP: [{0}], Request: [{1}], Response: [{2}], Token: [{3}]", httpUtil.GetClientIPAddress(HttpContext.Current.Request), req, serializer.Serialize(response), token));
            return(message);
        }
Beispiel #3
0
 public void MarkAsModified(priceList item)
 {
 }