示例#1
0
        private void addPromotion()
        {
            PromotionInfo promotion = new PromotionInfo();

            promotion.promotion_code = txtPromotionCode.Text;

            promotion.promotion_type = int.Parse(ddlPromotonType.SelectedValue);
            float percent;

            float.TryParse(txtDiscountPercent.Text, out percent);
            promotion.discount_percent = percent;

            float value;

            float.TryParse(txtDiscountValue.Text, out value);

            promotion.discount_value  = value;
            promotion.free_product_id = txtFreeProductId.Text;
            int free;

            int.TryParse(txtFreeAmount.Text, out free);


            float completePrice;

            float.TryParse(txtCompletePrice.Text, out completePrice);

            promotion.complete_price = completePrice;

            promotion.free_amount = free;
            promotion.title       = txtTitle.Text;
            promotion.description = txtDesciption.Text;

            if (fileImage.HasFile)
            {
                var    current      = fileImage.PostedFile;
                string exttension   = System.IO.Path.GetExtension(current.FileName);
                string newNameImage = Guid.NewGuid().ToString();
                current.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Images/"), newNameImage + exttension));
                listofuploadedfiles.Text += String.Format("{0}<br />", newNameImage + exttension);
                promotion.image           = newNameImage + exttension;
            }
            promotion.create_by     = (SessionApp.user_info == null) ? "No Login" : SessionApp.user_info.user_name;
            promotion.lastupdate_by = (SessionApp.user_info == null) ? "No Login" : SessionApp.user_info.user_name;
            var result = PromotionController.AddPromotion(promotion);

            if (result == null)
            {
                ShowMessage(Page, "เพิ่มผิดพลาด");
            }
            else
            {
                ShowMessage(Page, "เพิ่มสำเร็จ");
            }
        }