Esempio n. 1
0
 public DataTable GetDownloadsByType(string DownloadType, lw.CTE.Enum.DownloadStatus Status)
 {
     return(GetDownloads(string.Format("(Type='{0}' or UniqueName='{0}') and Status={1}",
                                       StringUtils.SQLEncode(DownloadType),
                                       (int)Status
                                       )));
 }
Esempio n. 2
0
        public int AddDownload(int DownloadTypeId, string Title, string Description, HttpPostedFile file,
                               SqlDateTime Date, lw.CTE.Enum.DownloadStatus Status)
        {
            if (file.ContentLength == 0)
            {
                throw new Exception("File is empty");
            }
            if (!Directory.Exists(DownloadsTemp))
            {
                Directory.CreateDirectory(DownloadsTemp);
            }

            string saveTo = Path.Combine(DownloadsTemp, Path.GetFileName(file.FileName));

            file.SaveAs(saveTo);
            if (String.IsNullOrEmpty(Title))
            {
                Title = Path.GetFileNameWithoutExtension(file.FileName);
            }
            return(AddDownload(DownloadTypeId, Title, Description, Path.GetFileName(file.FileName), Date, Status));
        }
Esempio n. 3
0
        public void UpdateDownload(int DownloadId, string Title, string Description, int DownloadTypeId, lw.CTE.Enum.DownloadStatus Status, int?Sort)
        {
            DataRow   downloadType = GetDownloadType(DownloadTypeId);
            DataTable dt           = GetDownloads(string.Format("DownloadId={0}",
                                                                DownloadId));

            if (downloadType == null)
            {
                throw new Exception("Invalid Download Type");
            }

            if (downloadType["TypeId"] != dt.Rows[0]["DownloadType"])
            {
                string _pathFrom = Path.Combine(DownloadsFolder, dt.Rows[0]["UniqueName"].ToString());

                string FileName = dt.Rows[0]["FileName"].ToString();
                string file     = Path.Combine(_pathFrom, FileName);

                string _pathTo = Path.Combine(DownloadsFolder, downloadType["UniqueName"].ToString());

                if (!Directory.Exists(_pathTo))
                {
                    Directory.CreateDirectory(_pathTo);
                }

                string pathTo = Path.Combine(_pathTo, FileName);

                if (File.Exists(file))
                {
                    File.Move(file, pathTo);
                }
            }

            string sql = string.Format(@"Update Downloads set DateModified='{0}', 
										DownloadType={1}, Status={2}, Description=N'{3}'{4}, Sort={6} where DownloadId={5}"                                        ,
                                       DateTime.Now, DownloadTypeId,
                                       (byte)Status, StringUtils.SQLEncode(Description),
                                       Title == null ? "" : string.Format(", Title=N'{0}'", StringUtils.SQLEncode(Title)),
                                       DownloadId, Sort == null ? 1000 : Sort);

            DBUtils.ExecuteQuery(sql, _lib);
        }
Esempio n. 4
0
 public void UpdateDownload(int DownloadId, string Title, string Description, int DownloadTypeId, lw.CTE.Enum.DownloadStatus Status)
 {
     UpdateDownload(DownloadId, Title, Description, DownloadTypeId, Status, null);
 }
Esempio n. 5
0
        public int AddDownload(int DownloadTypeId, string Title, string Description, string FileName,
                               SqlDateTime Date, lw.CTE.Enum.DownloadStatus Status)
        {
            DataRow downloadType = GetDownloadType(DownloadTypeId);

            if (downloadType == null)
            {
                DataTable types = GetDownloadTypes();
                if (types.Rows.Count > 0)
                {
                    downloadType   = types.Rows[0];
                    DownloadTypeId = (int)downloadType["TypeId"];
                }
                else
                {
                    throw new Exception("Download Type cannot be empty.");
                }
            }
            string file     = Path.Combine(DownloadsTemp, FileName);
            long   fileSize = 0;

            if (!File.Exists(file))
            {
                //throw (new Exception("File Not Found!"));
            }
            else
            {
                if (GetDownloads(string.Format("Title=N'{0}' and DownloadType={1}",
                                               StringUtils.SQLEncode(Title), DownloadTypeId)).Rows.Count > 0)
                {
                    File.Delete(file);
                    throw new Exception("File Already Exist!");
                }
                FileName = StringUtils.ToURL(Title) + Path.GetExtension(FileName);
                string _path = Path.Combine(DownloadsFolder, downloadType["UniqueName"].ToString());
                if (!Directory.Exists(_path))
                {
                    Directory.CreateDirectory(_path);
                }

                string pathTo = Path.Combine(_path, FileName);
                if (File.Exists(pathTo))
                {
                    File.Delete(pathTo);
                }

                File.Move(file, pathTo);

                file = pathTo;

                if (File.Exists(file))
                {
                    FileInfo fi = new FileInfo(pathTo);
                    if (Date.IsNull)
                    {
                        Date = fi.CreationTime;
                    }
                    fileSize = fi.Length;
                }
            }
            string sql = string.Format(@"Insert into Downloads (Title, Description, DateAdded, 
										DateModified, DownloadType, FileName, FileSize, Status, Sort) values 
										(N'{0}', N'{1}', '{2}', '{3}', {4}, N'{5}', {6},{7},{8});
										select @@Identity as DownloadId"                                        ,
                                       StringUtils.SQLEncode(Title),
                                       StringUtils.SQLEncode(Description), Date.Value,
                                       DateTime.Now, DownloadTypeId, FileName,
                                       fileSize,
                                       (byte)Status, 1000);

            DataTable dt = DBUtils.GetDataSet(sql, cte.lib).Tables[0];

            return(Int32.Parse(dt.Rows[0]["DownloadId"].ToString()));
        }