Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["selectedID"] != null)
            {
                int selectedID = (int)Session["selectedID"];

                goods = new Goods();
                GoodsActions goodsActions = new GoodsActions();
                goods = goodsActions.FindSelectedGoods(selectedID);
                DataSourceAdapterBinding dataSourceAdapterBinding = new DataSourceAdapterBinding();
                GoodsPreview1.DataSource = dataSourceAdapterBinding.AdapterFill(goods);
            }
        }
        public DataSourceAdapter AdapterFill(Goods goods)
        {
            DataSourceAdapter dataSourceAdapter = new DataSourceAdapter();

            dataSourceAdapter.Name = goods.Name;
            dataSourceAdapter.Price = goods.Price.ToString();
            dataSourceAdapter.IsDiscount = goods.IsDiscount;
            dataSourceAdapter.Discount = goods.Discount.ToString();

            dataSourceAdapter.ImageURL = "GetBigImage.aspx?imgID=" + goods.ID;

            return dataSourceAdapter;
        }
Exemplo n.º 3
0
        public void ButtonAdd_Click(object sender, EventArgs e)
        {
            string name = TextBoxName.Text;
            float price;
            float.TryParse(TextBoxPrice.Text, out price);
            bool isDiscount = CheckBox1.Checked;
            int discount;
            int.TryParse(TextBoxDiscount.Text, out discount);
            byte[] image = null;
            byte[] miniImage = null;

            if (FileUploadImage.HasFile)
            {
                image = FileUploadImage.FileBytes;
            }

            if (FileUploadMiniImage.HasFile)
            {
                miniImage = FileUploadMiniImage.FileBytes;
            }

            var args = new ButtonSubmitEventArgs(name, price, isDiscount, discount,
                image, miniImage);


            ButtonAdd_OnClick(args);

            var goods = new Goods();
            goods.Name = name;
            goods.Price = price;
            goods.IsDiscount = isDiscount;

            if (discount > 0)
            {
                goods.Discount = discount;    
            }
            
            goods.AdditionDate = DateTime.Now;

            var goodsImages = new GoodsImages();
            goodsImages.Image = image;
            goodsImages.MiniImage = miniImage;

            GoodsActions goodsActions = new GoodsActions();
            goodsActions.AddGoods(goods, goodsImages, goodsID);
            Response.Redirect("~/Administrator/GoodsPreview.aspx");   
        }
Exemplo n.º 4
0
        public void SaveEditGoods(Goods goods, GoodsImages goodsImages, int goodsID)
        {
            using (Sessions.NewSession = Sessions.SessionFactory.OpenSession())
            {
                using (var transaction = Sessions.NewSession.BeginTransaction())
                {
                    var entity = Sessions.NewSession.Get<Goods>(goodsID);
                    entity.Name = goods.Name;
                    entity.Price = goods.Price;
                    entity.Discount = goods.Discount;
                    entity.IsDiscount = goods.IsDiscount;
                    Sessions.NewSession.SaveOrUpdate(entity);
                    Sessions.NewSession.Flush();

                    var images = (from q in Sessions.NewSession.Linq<GoodsImages>()
                                      where q.Goods.ID == goodsID
                                      select q).FirstOrDefault<GoodsImages>();

                    if (goodsImages.Image != null)
                    {
                        images.Image = goodsImages.Image; 
                    }
                    if (goodsImages.MiniImage != null)
                    {
                        images.MiniImage = goodsImages.MiniImage;
                    }

                    Sessions.NewSession.SaveOrUpdate(images);
                    Sessions.NewSession.Flush();

                    transaction.Commit();
                }
            }
        }
Exemplo n.º 5
0
        public int AddGoods(Goods goods, GoodsImages goodsImages, int categoryID)
        {
            using (Sessions.NewSession = Sessions.SessionFactory.OpenSession())
            {
                using (var transaction = Sessions.NewSession.BeginTransaction())
                {
                    //write goods in db
                    Sessions.NewSession.SaveOrUpdate(goods);
                    Sessions.NewSession.Flush();

                    //write relations in db
                    var entity = new RelationsCategoriesGoods();
                    entity.Categories = Sessions.NewSession.Get<Categories>(categoryID);
                    entity.Goods = Sessions.NewSession.Get<Goods>(goods.ID);
                    Sessions.NewSession.SaveOrUpdate(entity);
                    Sessions.NewSession.Flush();
                    
                    //write images in db
                    goodsImages.Goods = Sessions.NewSession.Get<Goods>(goods.ID);
                    Sessions.NewSession.SaveOrUpdate(goodsImages);
                    Sessions.NewSession.Flush();

                    transaction.Commit();
                }
            }

            return goodsImages.ID;
        }
Exemplo n.º 6
0
 public void SaveEditGoods(Goods goods, GoodsImages goodsImages, int goodsID)
 {
     GoodsCRUD goodsCRUD = new GoodsCRUD();
     goodsCRUD.SaveEditGoods(goods, goodsImages, goodsID);
 }
Exemplo n.º 7
0
 public int AddGoods(Goods goods, GoodsImages goodsImages, int categotyID)
 {
     GoodsCRUD goodsCRUD = new GoodsCRUD();
     return goodsCRUD.AddGoods(goods, goodsImages, categotyID);
 }