Пример #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Entities.File entity = new Entities.File();
            try
            {
                entity.FileID = base.GetInt32("ID");

                switch (base.Operation)
                {
                    case "D":
                        {
                            string fileName = ServiceFactory.CreateConfigurationService.DeleteFile(entity);

                            if (fileName.Contains(".zip"))
                            {
                                fileName = fileName.Replace("default.zip", "");
                                if (System.IO.Directory.Exists(Server.MapPath(Param.DocumentLibrary) + fileName))
                                    System.IO.Directory.Delete(Server.MapPath(Param.DocumentLibrary) + fileName,true);
                            }
                            if (System.IO.File.Exists(Server.MapPath(Param.DocumentLibrary) + fileName))
                                System.IO.File.Delete(Server.MapPath(Param.DocumentLibrary) + fileName);

                            break;
                        }
                    case "U":
                        {
                            entity.FileID = base.GetInt32("ID");

                            entity.SubTypeID = Int32.Parse(ddlSubType.SelectedValue);
                            entity.IsEnabled = chkEnabled.Checked;

                            ServiceFactory.CreateConfigurationService.UpdateFile(entity);
                            break;
                        }
                    case "I":
                        {
                            entity = SaveFile();

                            if (entity != null)
                            {
                                entity.FileID = base.GetInt32("ID");
                                entity.Created = DateTime.Now;
                                entity.UserID = UAC.UserID;
                                entity.SubTypeID = Int32.Parse(ddlSubType.SelectedValue);
                                entity.IsEnabled = chkEnabled.Checked;

                                ServiceFactory.CreateConfigurationService.InsertFile(entity);
                            }
                            break;
                        }
                }
                Response.Redirect("FileList.aspx", false);
            }
            catch (Exception ex)
            {
                base.SetMessage(lblMessage, MessageType.Error, ResourceMessages.UnexpectedErrorMessage);
            }
        }
Пример #2
0
        public string DeleteFile(File file)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var files = from item in context.Files
                            where item.FileID == file.FileID
                            select item;

                File entity = files.FirstOrDefault();

                if ((entity != null))
                {
                    context.DeleteObject(entity);
                    context.SaveChanges();
                }
                return entity.FileName;
            }
        }
Пример #3
0
        public Entities.File SaveFile()
        {
            if (FileUploadControl.HasFile)
            {
                Entities.File result = new Entities.File();
                Entities.SubType subType = ServiceFactory.CreateConfigurationService.SelectSubType(null, Int32.Parse(ddlSubType.SelectedValue), null, true).FirstOrDefault();
                string extension = Path.GetExtension(FileUploadControl.FileName);
                string filename = Path.GetFileName(FileUploadControl.FileName);
                string aux = filename.Replace(extension, "");

                try
                {
                    if (extension.ToLower().Equals(".zip") && subType.Name.Equals("HTML Report"))
                    {
                        string saveName = aux + extension;
                        FileUploadControl.SaveAs(Server.MapPath(Param.DocumentLibrary) + saveName);

                        result.FileName = ServiceFactory.CreateConfigurationService.ExtractHTMLFiles(Server.MapPath(Param.DocumentLibrary) + saveName);
                        result.ContentType = "text/html";

                        if (System.IO.File.Exists(Server.MapPath(Param.DocumentLibrary) + saveName))
                            System.IO.File.Delete(Server.MapPath(Param.DocumentLibrary) + saveName);
                    }
                    else
                    {
                        string saveName = aux + DateTime.Now.ToString("_ddMMyyyy") + extension;
                        result.ContentType = FileUploadControl.PostedFile.ContentType;
                        FileUploadControl.SaveAs(Server.MapPath(Param.DocumentLibrary) + saveName);
                        result.FileName = saveName;
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                return result;
            }
            return null;
        }
Пример #4
0
        public void UpdateFile(File file)
        {
            using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
            {
                var files = from item in context.Files
                            where item.FileID == file.FileID
                            select item;

                File entity = files.FirstOrDefault();

                if ((entity != null))
                {
                    entity.SubTypeID = file.SubTypeID;
                    entity.IsEnabled = file.IsEnabled;

                    context.SaveChanges();
                }
            }
        }
Пример #5
0
 public void InsertFile(File file)
 {
     using (ConfigurationDataContext context = new ConfigurationDataContext(Utility.GetConnectionString(configurationDataContext)))
     {
         context.AddToFiles(file);
         context.SaveChanges();
     }
 }
 /// <summary>
 /// Create a new File object.
 /// </summary>
 /// <param name="fileID">Initial value of the FileID property.</param>
 /// <param name="userID">Initial value of the UserID property.</param>
 /// <param name="subTypeID">Initial value of the SubTypeID property.</param>
 /// <param name="fileName">Initial value of the FileName property.</param>
 /// <param name="contentType">Initial value of the ContentType property.</param>
 /// <param name="created">Initial value of the Created property.</param>
 /// <param name="isEnabled">Initial value of the IsEnabled property.</param>
 public static File CreateFile(global::System.Int32 fileID, global::System.Int32 userID, global::System.Int32 subTypeID, global::System.String fileName, global::System.String contentType, global::System.DateTime created, global::System.Boolean isEnabled)
 {
     File file = new File();
     file.FileID = fileID;
     file.UserID = userID;
     file.SubTypeID = subTypeID;
     file.FileName = fileName;
     file.ContentType = contentType;
     file.Created = created;
     file.IsEnabled = isEnabled;
     return file;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Files EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToFiles(File file)
 {
     base.AddObject("Files", file);
 }