예제 #1
0
        public static ContentDownloadInfo GetInfo(int content_ID, int downloadId)
        {
            ContentDownloadInfo retVal = null;
            var dbConn = new SqlConnection(AppEnv.ConnectionString);
            var dbCmd  = new SqlCommand("CMS_ContentDownload_GetInfo", dbConn)
            {
                CommandType = CommandType.StoredProcedure
            };

            dbCmd.Parameters.AddWithValue("@Content_ID", content_ID);
            dbCmd.Parameters.AddWithValue("@Download_ID", downloadId);
            try
            {
                dbConn.Open();
                var dr = dbCmd.ExecuteReader();
                if (dr.Read())
                {
                    retVal             = new ContentDownloadInfo();
                    retVal.Content_ID  = ConvertUtility.ToInt32(dr["Content_ID"]);
                    retVal.Download_ID = ConvertUtility.ToInt32(dr["Download_ID"]);
                    retVal.Priority    = ConvertUtility.ToInt32(dr["Priority"]);
                }
                if (dr != null)
                {
                    dr.Close();
                }
            }
            finally
            {
                dbConn.Close();
            }
            return(retVal);
        }
예제 #2
0
        public static void Update(ContentDownloadInfo contentDownloadInfo)
        {
            var dbConn = new SqlConnection(AppEnv.ConnectionString);
            var dbCmd  = new SqlCommand("CMS_ContentDownload_Update", dbConn)
            {
                CommandType = CommandType.StoredProcedure
            };

            dbCmd.Parameters.AddWithValue("@Content_ID", contentDownloadInfo.Content_ID);
            dbCmd.Parameters.AddWithValue("@Download_ID", contentDownloadInfo.Download_ID);
            dbCmd.Parameters.AddWithValue("@Priority", contentDownloadInfo.Priority);
            try
            {
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
            }
            finally
            {
                dbConn.Close();
            }
        }
예제 #3
0
        public static int Insert(ContentDownloadInfo contentDownloadInfo)
        {
            var dbConn = new SqlConnection(AppEnv.ConnectionString);
            var dbCmd  = new SqlCommand("CMS_ContentDownload_Insert", dbConn)
            {
                CommandType = CommandType.StoredProcedure
            };

            dbCmd.Parameters.AddWithValue("@Content_ID", contentDownloadInfo.Content_ID);
            dbCmd.Parameters.AddWithValue("@Download_ID", contentDownloadInfo.Download_ID);
            dbCmd.Parameters.AddWithValue("@Priority", contentDownloadInfo.Priority);
            dbCmd.Parameters.AddWithValue("@RETURN_VALUE", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
            try
            {
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
                return((int)dbCmd.Parameters["@RETURN_VALUE"].Value);
            }
            finally
            {
                dbConn.Close();
            }
        }
예제 #4
0
        private static ContentDownloadInfo CreateEntityFromReader(IDataReader reader)
        {
            var item = new ContentDownloadInfo();

            try { if (!reader.IsDBNull(reader.GetOrdinal("Content_ID")))
                  {
                      item.Content_ID = ConvertUtility.ToInt32(reader["Content_ID"]);
                  }
            }
            catch { }
            try { if (!reader.IsDBNull(reader.GetOrdinal("Download_ID")))
                  {
                      item.Download_ID = ConvertUtility.ToInt32(reader["Download_ID"]);
                  }
            }
            catch { }
            try { if (!reader.IsDBNull(reader.GetOrdinal("Priority")))
                  {
                      item.Priority = ConvertUtility.ToInt32(reader["Priority"]);
                  }
            }
            catch { }
            return(item);
        }
예제 #5
0
        protected void btnAddNew_Click(object sender, EventArgs e)
        {
            var    dirUpload = AppEnv.UploadDocument;
            double filesize  = 0;
            string extension = "";

            string fileAvatarPath = "", newfileAvatarName = "";
            var    info = new DownloadInfo();

            if (txtFile.PostedFile.FileName.Length > 0)
            {
                var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(txtFile.PostedFile.FileName);
                if (fileNameWithoutExtension != null)
                {
                    string filename = fileNameWithoutExtension.Replace(" ", "_").Replace("#", "_");
                    var    s        = Path.GetExtension(txtFile.PostedFile.FileName);
                    if (s != null)
                    {
                        extension = s.ToLower();
                    }

                    newfileAvatarName = filename + "_" + DateTime.Now.ToString("mmss") + txtFile.PostedFile.FileName.Substring(txtFile.PostedFile.FileName.LastIndexOf('.'));
                }
                txtFile.PostedFile.SaveAs(Server.MapPath(dirUpload) + newfileAvatarName);
                double filesizeb = txtFile.PostedFile.ContentLength;
                filesize = filesizeb / (1024 * 1024);

                fileAvatarPath = dirUpload + newfileAvatarName;
            }
            else
            {
                fileAvatarPath = "";
            }


            if (fileAvatarPath.Length > 0)
            {
                if (txtName.Text.Length > 0)
                {
                    info.Download_Name = ConvertUtility.ToString(txtName.Text);
                }
                else
                {
                    info.Download_Name = newfileAvatarName;
                }
                info.Download_Description = txtTeaser.Text;
                info.Download_File        = fileAvatarPath;
                info.Download_Extension   = extension;
                info.Download_Visible     = chkVisible.Checked;
                info.Download_CreateDate  = DateTime.Now;
                info.Download_FileSize    = ConvertUtility.ToDouble(filesize.ToString("#0.00"));
                info.Download_View        = 0;
                info.User_ID = ConvertUtility.ToInt32(ckid);


                try
                {
                    var fileId = DownloadDB.Insert(info);

                    var contentDownloadInfo = new ContentDownloadInfo();
                    contentDownloadInfo.Content_ID  = _contentId;
                    contentDownloadInfo.Download_ID = fileId;
                    contentDownloadInfo.Priority    = 0;

                    ContentDownloadDB.Insert(contentDownloadInfo);

                    Response.Redirect(Request.RawUrl + "#idTab3");

                    lblStatusUpdate.Text = lblStatusUpdate2.Text = MiscUtility.UPDATE_SUCCESS;
                }
                catch
                {
                    lblStatusUpdate.Text = lblStatusUpdate2.Text = MiscUtility.UPDATE_ERROR;
                }
            }
        }