Пример #1
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (!HasWriteAccess) return;

            if (txtName.Text.Trim().Length == 0)
            {
                MessageBox.Show(Lang.TransA("Please enter name!"), Misc.MessageType.Error);
                return;
            }

            AffiliateBanner affiliateBanner = new AffiliateBanner();

            affiliateBanner.Name = txtName.Text.Trim();

            if (fuAffiliateBannerImage.HasFile)
            {
                System.Drawing.Image image = null;
                try
                {
                    image = System.Drawing.Image.FromStream
                        (fuAffiliateBannerImage.PostedFile.InputStream);
                }
                catch
                {
                    MessageBox.Show(Lang.TransA("Invalid image!"), Misc.MessageType.Error);
                    return;
                }

                affiliateBanner.Image = image;
            }
            else
            {
                MessageBox.Show(Lang.TransA("Invalid image!"), Misc.MessageType.Error);
                return;
            }

            affiliateBanner.Save();

            loadAffiliateBanners();
            mvAffiliateBanners.SetActiveView(viewAffiliateBanners);
        }
Пример #2
0
        /// <summary>
        /// Fetches affiliate banners by specified arguments.
        /// It returns an empty array if there are no affiliate banners in DB by specified arguments.
        /// If these arguments are null it returns all affiliate banners from DB.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="name">The name.</param>
        /// <param name="deleted">The deleted.</param>
        /// <returns></returns>
        private static AffiliateBanner[] Fetch(int? id, string name, bool? deleted)
        {
            using (SqlConnection conn = Config.DB.Open())
            {
                SqlDataReader reader = SqlHelper.ExecuteReader(conn, "FetchAffiliateBanners", id, name, deleted);

                List<AffiliateBanner> lAffiliateBanners = new List<AffiliateBanner>();

                while (reader.Read())
                {
                    AffiliateBanner affiliateBanner = new AffiliateBanner();

                    affiliateBanner.id = (int) reader["ID"];
                    affiliateBanner.name = (string) reader["Name"];
                    affiliateBanner.deleted = (bool) reader["Deleted"];

                    lAffiliateBanners.Add(affiliateBanner);
                }

                return lAffiliateBanners.ToArray();
            }
        }