protected void btnUpload_Click(object sender, EventArgs e)
        {
            try
            {
                // Before attempting to save the file, verify
                // that the FileUpload control contains a file.
                if (fuPhoto.HasFile)
                {
                    // Call a helper method routine to save the file.
                    SaveFile(fuPhoto.PostedFile);
                    lblMessage.Text = "File uploaded";
                }
                else
                {
                    savePath = Server.MapPath("Images");
                    string fileName = "CoverNull.png";
                    string pathToCheck = Path.Combine(savePath, fileName);

                    Book book = new Book();
                    book.PhotoName = pathToCheck;
                    User user = new User();
                    user = (User)Session["User"];
                    book.Title = txtTitle.Text;
                    book.Price = txtPrice.Text;
                    book.BookTypeID = new Guid(ddlGenre.SelectedValue);
                    user.Books.List.Add(book);
                    user.Save();
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            book = (Book)Session["Book"];
            book.BookTypeID = new Guid(ddlGenre.SelectedValue);
            book.Title = txtTitle.Text;
            book.Price = txtPrice.Text;
            if (fuPhoto.HasFile)
            {

                savePath = Server.MapPath("Images");
                string fileName = fuPhoto.FileName;
                string pathToCheck = Path.Combine(savePath, fileName);

                book.PhotoName = pathToCheck;

            }
            else
            {
                savePath = Server.MapPath("Images");
                book.PhotoName = Path.Combine(savePath, book.ID + book.MimeType);
            }
            User user = new User();
            user = (User)Session["User"];
            user.Books.List.Add(book);
            user.Save();
        }
Exemple #3
0
        public BookList GetAll()
        {
            _list.Clear();
            Database db = new Database("Books");
            db.Command.CommandType = System.Data.CommandType.StoredProcedure;
            db.Command.CommandText = "tblBookGETALL";
            DataTable dt = db.ExecuteQuery();
            //dgvStudent.DataSource = dt;
            foreach (DataRow dr in dt.Rows)
            {
                Book s = new Book();
                s.Initialize(dr);
                s.InitializeBusinessData(dr);
                s.IsDirty = false;
                s.IsNew = false;
                s.evtIsSavable += new IsSavableHandler(s_evtIsSavable);
                _list.Add(s);
            }

            return this;
        }
Exemple #4
0
        public BookList GetByBookTypeID(Guid bookTypeID)
        {
            _list.Clear();
            Database db = new Database("Books");
            db.Command.CommandType = System.Data.CommandType.StoredProcedure;
            db.Command.CommandText = "tblBookGETBYBOOKTYPEID";
            db.Command.Parameters.Add("@BookTypeID", SqlDbType.UniqueIdentifier).Value = bookTypeID;
            DataTable dt = db.ExecuteQuery();
            //dgvStudent.DataSource = dt;
            foreach (DataRow dr in dt.Rows)
            {
                Book s = new Book();
                s.Initialize(dr);
                s.InitializeBusinessData(dr);
                s.IsDirty = false;
                s.IsNew = false;
                s.evtIsSavable += new IsSavableHandler(s_evtIsSavable);
                _list.Add(s);
            }

            return this;
        }
Exemple #5
0
        private Boolean Insert(Database db)
        {
            Book book = new Book();

            try
            {
                db.Command.Parameters.Clear();
                db.Command.CommandType = CommandType.StoredProcedure;
                db.Command.CommandText = "tblBookINSERT";
                base.Initialize(db.Command, Guid.Empty);
                db.Command.Parameters.Add("@BookTypeID", SqlDbType.UniqueIdentifier).Value = _BookTypeID;
                db.Command.Parameters.Add("@Title", SqlDbType.VarChar).Value = _Title;
                db.Command.Parameters.Add("@Price", SqlDbType.VarChar).Value = _Price;
                db.Command.Parameters.Add("@BookCover", SqlDbType.Image).Value = PhotoHelper.Photo.FileToByteArray(_PhotoName);
                db.Command.Parameters.Add("@MimeType", SqlDbType.VarChar).Value = Path.GetExtension(_PhotoName);
                db.ExecuteNonQueryWithTransaction();
                base.Initialize(db.Command);
                return true;
            }
            catch (Exception ex)
            {
                throw;
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["User"] == null)
     {
         Response.Redirect("default.aspx");
     }
     if (!Page.IsPostBack)
     {
         GetGenreData();
         if (Request.QueryString["BookID"] != null)
         {
             book = new Book();
             btnUpload.Visible = false;
             btnSave.Visible = true;
             book = book.GetByID(new Guid(Request.QueryString["BookID"]));
             txtTitle.Text = book.Title;
             txtPrice.Text = book.Price;
             ddlGenre.SelectedValue = book.BookTypeID.ToString();
             Session["Book"] = book;
         }
         else
         {
             btnSave.Visible = false;
         }
     }
 }
        void SaveFile(HttpPostedFile file)
        {
            // Specify the path to save the uploaded file to.
             savePath = Server.MapPath("Images");

            // Get the name of the file to upload.
            string fileName = fuPhoto.FileName;

            // Create the path and file name to check for duplicates.
            string pathToCheck = Path.Combine(savePath, fileName);

            // Create a temporary file name to use for checking duplicates.
            string tempfileName = "";

            // Check to see if a file already exists with the
            // same name as the file to upload.
            if (System.IO.File.Exists(pathToCheck))
            {
                int counter = 2;
                while (System.IO.File.Exists(pathToCheck) == true)
                {
                    // if a file with this name already exists,
                    // prefix the filename with a number.
                    tempfileName = counter.ToString() + fileName;
                    pathToCheck = Path.Combine(savePath, tempfileName);
                    counter++;
                }

                fileName = tempfileName;

                // Notify the user that the file name was changed.
                lblMessage.Text = "A file with the same name already exists." +
                    "<br />Your file was saved as " + fileName;

                // Append the name of the file to upload to the path.
                savePath = Path.Combine(savePath, fileName);

                // Call the SaveAs method to save the uploaded
                // file to the specified directory.
                fuPhoto.SaveAs(savePath);

                Book book = new Book();
                book.PhotoName = savePath;
                User user = new User();
                user = (User)Session["User"];
                book.Title = txtTitle.Text;
                book.Price = txtPrice.Text;
                book.BookTypeID = new Guid(ddlGenre.SelectedValue);
                user.Books.List.Add(book);
                user.Save();
            }
            else
            {
                // Append the name of the file to upload to the path.
                savePath = Path.Combine(savePath, fileName);

                // Call the SaveAs method to save the uploaded
                // file to the specified directory.
                fuPhoto.SaveAs(savePath);

                ////XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                Book book = new Book();
                book.PhotoName = savePath;
                User user = new User();
                user = (User)Session["User"];
                book.Title = txtTitle.Text;
                book.Price = txtPrice.Text;
                book.BookTypeID = new Guid(ddlGenre.SelectedValue);
                user.Books.List.Add(book);
                user.Save();

                // Notify the user that the file was saved successfully.

                lblMessage.Text = "Your file was uploaded successfully.";
                //Response.Redirect("UploadPhoto.aspx");
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     book = book.GetByID(new Guid(Request.QueryString["BookID"]));
 }