Exemple #1
0
        private void SaveAttachment(int Id, byte[] data, string fileName, EnumAttachmentRefType refType, FileFormat fileFormat)
        {
            Guid guid = SaveFile(data, fileName);

            ScaleAttachments attachments = new ScaleAttachments();

            attachments.Document_Name  = fileName;// "Thumb-Image.jpeg";
            attachments.Document_RefId = guid;
            attachments.Document_Size  = data.LongLength;
            attachments.Document_Title = fileName;
            attachments.Document_Type  = fileFormat.ToString();
            attachments.Ref_Type       = (int)refType;

            attachments.Updated_By        = User.Identity.Name;
            attachments.Created_By        = User.Identity.Name;
            attachments.Created_Date      = DateTime.Now;
            attachments.Last_Updated_Date = DateTime.Now;
            attachments.Parent            = new Scale {
                ID = Id
            };

            string destinationPath;
            string sourcePath;

            FilelHelper fileHelper = new FilelHelper();

            destinationPath = fileHelper.GetSourceDirByFileRefId(attachments.Document_RefId.ToString());     // Path.Combine(Configuration.GetsmARTDocPath(), Scale.Document_RefId.ToString());
            sourcePath      = fileHelper.GetTempSourceDirByFileRefId(attachments.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), Scale.Document_RefId.ToString());

            attachments.Document_Path = fileHelper.GetFilePath(sourcePath);

            if (Id > 0)
            {
                fileHelper.MoveFile(attachments.Document_Name, sourcePath, destinationPath);
                ScaleAttachmentsLibrary ScaleLibrary = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                attachments.Document_Name = fileName;
                ScaleAttachments scaleAttachment = ScaleLibrary.Add(attachments);
            }
            else
            {
                if (Session["ScaleAttachments"] == null)
                {
                    Session["ScaleAttachments"] = new List <ScaleAttachments>();
                }
                IList <ScaleAttachments> iList = (IList <ScaleAttachments>)Session["ScaleAttachments"];
                iList.Add(attachments);
            }
        }
        private void SaveThumbScannerAttachment(int Id, byte[] data, string fileName, EnumAttachmentRefType refType, FileFormat fileFormat, bool updateParty = true)
        {
            Guid guid = SaveFile(data, string.Format("{0}.{1}", fileName, fileFormat.ToString()));

            ScaleAttachments attachments = new ScaleAttachments();

            attachments.Document_Name  = string.Format("{0}.{1}", fileName, fileFormat.ToString());// "Thumb-Image.jpeg";
            attachments.Document_RefId = guid;
            attachments.Document_Size  = data.LongLength;
            attachments.Document_Title = "Thumb-Image";
            attachments.Document_Type  = "jpeg";
            attachments.Ref_Type       = (int)refType;

            attachments.Updated_By        = User.Identity.Name;
            attachments.Created_By        = User.Identity.Name;
            attachments.Created_Date      = DateTime.Now;
            attachments.Last_Updated_Date = DateTime.Now;
            attachments.Parent            = new Scale {
                ID = Id
            };

            string destinationPath;
            string sourcePath;

            FilelHelper fileHelper = new FilelHelper();

            destinationPath = fileHelper.GetSourceDirByFileRefId(attachments.Document_RefId.ToString());     // Path.Combine(Configuration.GetsmARTDocPath(), Scale.Document_RefId.ToString());
            sourcePath      = fileHelper.GetTempSourceDirByFileRefId(attachments.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), Scale.Document_RefId.ToString());

            attachments.Document_Path = fileHelper.GetFilePath(sourcePath);

            if (Id > 0)
            {
                fileHelper.MoveFile(attachments.Document_Name, sourcePath, destinationPath);
                ScaleAttachmentsLibrary ScaleLibrary = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                attachments.Document_Name = string.Format("{0}.{1}", fileName, "jpg");
                ScaleAttachments scaleAttachment = ScaleLibrary.Add(attachments);

                if (updateParty)
                {
                    Scale        scale    = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetByID(Id.ToString(), new string[] { "Party_ID" });
                    PartyLibrary partyLib = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                    Party        party    = partyLib.GetByID(scale.Party_ID.ID.ToString());
                    if (party != null)
                    {
                        party.PhotoRefId = scaleAttachment.Document_RefId.ToString();
                        partyLib.Modify(party);
                    }
                }
            }
            else
            {
                if (Session["ScaleAttachments"] == null)
                {
                    Session["ScaleAttachments"] = new List <ScaleAttachments>();
                }

                IList <ScaleAttachments> iList = (IList <ScaleAttachments>)Session["ScaleAttachments"];
                iList.Add(attachments);
            }
        }