// Token: 0x06001B00 RID: 6912 RVA: 0x00066904 File Offset: 0x00064B04
            private void CopyAttachment(IAttachment attachment, IItem draftItem, out IAttachment newAttachment, out AttachmentId newAttachmentId)
            {
                newAttachment = this.factory.CloneAttachment(attachment, draftItem);
                if (newAttachment is IStreamAttachment)
                {
                    newAttachment.FileName = GetWacAttachmentInfo.Implementation.GenerateDocumentNameForEditing(attachment.FileName, this.userDisplayName);
                }
                else
                {
                    newAttachment.FileName = attachment.FileName;
                }
                newAttachmentId = newAttachment.Id;
                this.ResultAttachmentExtension = newAttachment.FileExtension;
                IReferenceAttachment referenceAttachment = newAttachment as IReferenceAttachment;

                if (referenceAttachment != null)
                {
                    this.ResultAttachmentContentUrl    = referenceAttachment.AttachLongPathName;
                    this.ResultAttachmentWebServiceUrl = referenceAttachment.ProviderEndpointUrl;
                    this.ResultAttachmentProviderType  = referenceAttachment.ProviderType;
                }
                newAttachment.IsInline = false;
                newAttachment.Save();
                draftItem.Save(SaveMode.NoConflictResolutionForceSave);
            }
 /// <summary>
 /// Handles the Click event of the cmdEditSave control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected void cmdEditSave_Click(object sender, EventArgs e)
 {
     try
     {
         IAttachment attachment = EntityFactory.GetById <IAttachment>(txtAttachId1.Value);
         if (attachment != null)
         {
             bool bIsActivityInsert = IsActivityInsert();
             bool bIsHistoryInsert  = IsHistoryInsert();
             attachment.Description = txtEditDesc.Text;
             if (Path.GetExtension(attachment.FileName).ToUpper() == ".URL" && !String.IsNullOrEmpty(txtEditURL.Text))
             {
                 if (!bIsActivityInsert && !bIsHistoryInsert)
                 {
                     attachment.UpdateURLAttachment(txtEditURL.Text);
                 }
                 else
                 {
                     Rules.UpdateTempURLAttachment(attachment, txtEditURL.Text);
                 }
             }
             else if (uplEditUpload.UploadedFiles.Count > 0)
             {
                 UploadedFile file = uplEditUpload.UploadedFiles[0];
                 if (file != null && !String.IsNullOrEmpty(file.FileName))
                 {
                     if (!bIsActivityInsert && !bIsHistoryInsert)
                     {
                         attachment.UpdateFileAttachment(WriteToFile(file));
                     }
                     else
                     {
                         Rules.UpdateTempFileAttachment(attachment, WriteToFile(file));
                     }
                 }
             }
             else
             {
                 attachment.Save();
             }
             LoadAttachments();
         }
         hideAdds();
     }
     catch (Exception ex)
     {
         log.Error(ex.Message);
         throw;
     }
 }
Exemple #3
0
        public static void btnPrint_OnClickStep(IRNReportDetails form, EventArgs args)
        {
            // TODO: Complete business rule implementation
            IAttachment attachment = null;
            string      pluginid   = string.Empty;


            Sage.Entity.Interfaces.IRNReport parentEntity = form.CurrentEntity as Sage.Entity.Interfaces.IRNReport;


            if (ReportsHelper.GetPluginId("RNReport:Irnreport", out pluginid))
            {
                WebReportingClass reporting = new WebReportingClass();

                Sage.Platform.Data.IDataService datasvc = MySlx.Data.CurrentConnection;
                Sage.Entity.Interfaces.IUser    user    = MySlx.Security.CurrentSalesLogixUser;

                string tempPath         = Rules.GetTempAttachmentPath();
                string ConnectionString = datasvc.GetConnectionString();


                string report = reporting.GenerateReport(ConnectionString, datasvc.Server, DatabaseServer.dsMSSQL, tempPath, false, false, "RNREPORT.RNREPORTID", "", pluginid, "", "", "", "SELECT RNREPORT.RNREPORTID FROM RNREPORT", string.Format("(RNREPORT.RNREPORTID = '{0}')", parentEntity.Id), user.Id.ToString(), user.UserName.ToString());

                ReportDocument doc = new ReportDocument();

                report = string.Format("{0}run\\{1}", tempPath, report);

                doc.Load(report);

                string filename = string.Format("{0}\\{1}_v{2}.pdf", Rules.GetAttachmentPath(), parentEntity.ReferenceNumber.Replace(" ", "_"), 1);

                doc.ExportToDisk(ExportFormatType.PortableDocFormat, filename);

                doc.Close();

                attachment             = Sage.Platform.EntityFactory.Create <IAttachment>();
                attachment.Description = string.Format("{0} v{1}", parentEntity.ReferenceNumber, 1);
                attachment.InsertFileAttachment(filename);
                attachment.RNREPORTID = Convert.ToString(parentEntity.Id);

                attachment.Save();

                System.IO.File.Delete(report);
            }
        }
            // Token: 0x06001AFF RID: 6911 RVA: 0x0006673C File Offset: 0x0006493C
            private void UploadAttachment(IAttachment attachment, IItem draftItem, out IAttachment newAttachment, out AttachmentId newAttachmentId)
            {
                IStreamAttachment streamAttachment = attachment as IStreamAttachment;

                if (streamAttachment == null)
                {
                    throw new InvalidOperationException("UploadAttachment requires a stream attachment, but was given a " + attachment.GetType().Name);
                }
                UploadItemAsyncResult uploadItemAsyncResult;

                using (Stream contentStream = streamAttachment.GetContentStream())
                {
                    byte[] array = new byte[contentStream.Length];
                    while (contentStream.Position != contentStream.Length)
                    {
                        int count = (int)Math.Min(4000L, contentStream.Length - contentStream.Position);
                        contentStream.Read(array, (int)contentStream.Position, count);
                    }
                    CancellationToken cancellationToken = default(CancellationToken);
                    uploadItemAsyncResult = this.provider.UploadItemSync(array, attachment.FileName, cancellationToken);
                }
                if (uploadItemAsyncResult.ResultCode != AttachmentResultCode.Success)
                {
                    throw new GetWacAttachmentInfo.AttachmentUploadException(uploadItemAsyncResult.ResultCode.ToString());
                }
                UserContext userContext = UserContextManager.GetUserContext(CallContext.Current.HttpContext, CallContext.Current.EffectiveCaller, true);

                this.ResultAttachmentWebServiceUrl = uploadItemAsyncResult.Item.ProviderEndpointUrl;
                this.ResultAttachmentProviderType  = uploadItemAsyncResult.Item.ProviderType.ToString();
                this.ResultAttachmentContentUrl    = this.provider.GetItemAbsoulteUrl(userContext, uploadItemAsyncResult.Item.Location, uploadItemAsyncResult.Item.ProviderEndpointUrl, null, null);
                this.ResultAttachmentExtension     = attachment.FileExtension;
                IReferenceAttachment referenceAttachment = (IReferenceAttachment)this.factory.CreateAttachment(draftItem, AttachmentType.Reference);

                newAttachment   = referenceAttachment;
                newAttachmentId = newAttachment.Id;
                referenceAttachment.AttachLongPathName  = this.ResultAttachmentContentUrl;
                referenceAttachment.ProviderEndpointUrl = this.ResultAttachmentWebServiceUrl;
                referenceAttachment.ProviderType        = this.ResultAttachmentProviderType;
                referenceAttachment.FileName            = attachment.FileName;
                newAttachment.IsInline = false;
                newAttachment.Save();
                draftItem.Save(SaveMode.NoConflictResolutionForceSave);
            }
    /// <summary>
    /// Handles the Click event of the cmdUpload control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void cmdUpload_Click(object sender, EventArgs e)
    {
        try
        {
            WorkItem workItem             = PageWorkItem;
            bool     bIsActivityInsert    = IsActivityInsert();
            bool     bIsHistoryInsert     = IsHistoryInsert();
            string   strTempAssociationID = string.Empty;

            if (bIsActivityInsert || bIsHistoryInsert)
            {
                if (workItem != null)
                {
                    object oStrTempAssociationID = workItem.State["TempAssociationID"];
                    if (oStrTempAssociationID != null)
                    {
                        strTempAssociationID = oStrTempAssociationID.ToString();
                    }
                }
            }

            string attachPath;
            if (!bIsActivityInsert && !bIsHistoryInsert)
            {
                attachPath = Rules.GetAttachmentPath();
            }
            else
            {
                /* When in Insert mode we keep the attachments in a special location, in case the operation gets cancelled out. */
                attachPath = Rules.GetTempAttachmentPath();
            }

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

            if (!String.IsNullOrEmpty(txtInsertURL.Text))
            {
                if (String.IsNullOrEmpty(txtInsertDesc.Text))
                {
                    return;
                }

                string url    = "URL=";
                Random random = new Random();
                //string urlFile = random.Next(9999) + "-" + txtInsertDesc.Text + "-" + random.Next(9999) + ".URL";
                string urlFile = Guid.NewGuid().ToString() + ".URL";
                string path    = attachPath + "/" + urlFile;
                if (!txtInsertURL.Text.Contains("://"))
                {
                    url += "http:\\\\";
                }
                FileStream   newFile      = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                StreamWriter streamWriter = new StreamWriter(newFile);
                streamWriter.WriteLine("[InternetShortcut]");
                streamWriter.WriteLine(url + txtInsertURL.Text);
                streamWriter.WriteLine("IconIndex=0");
                streamWriter.Close();
                newFile.Close();

                IAttachment attachment = EntityFactory.Create <IAttachment>();
                attachment.Description = txtInsertDesc.Text;
                attachment.FileName    = urlFile;

                if (!bIsActivityInsert && !bIsHistoryInsert)
                {
                    attachment.InsertURLAttachment(path);
                }
                else
                {
                    if (string.IsNullOrEmpty(strTempAssociationID) ||
                        (workItem != null) && (System.Convert.ToString(workItem.State["TempAssociationID"]) == strTempAssociationID))
                    {
                        /* Save to get an ID used for temp purposes. */

                        IUserService userServ = ApplicationContext.Current.Services.Get <IUserService>();
                        strTempAssociationID = userServ.UserId;
                        //attachment.Save();

                        if (workItem != null)
                        {
                            workItem.State["TempAssociationID"] = strTempAssociationID;
                        }
                    }
                    Rules.InsertTempURLAttachment(attachment, EntityContext.EntityType, strTempAssociationID, path);
                }

                txtInsertURL.Text  = String.Empty;
                txtInsertDesc.Text = String.Empty;
                LoadAttachments();
            }
            else if (uplInsertUpload.UploadedFiles.Count > 0)
            {
                UploadedFile file = uplInsertUpload.UploadedFiles[0];
                if (file != null)
                {
                    IAttachment attachment = EntityFactory.Create <IAttachment>();
                    attachment.Description = txtInsertDesc.Text;
                    if (String.IsNullOrEmpty(txtInsertDesc.Text))
                    {
                        attachment.Description = file.GetNameWithoutExtension();
                    }
                    if (!bIsActivityInsert && !bIsHistoryInsert)
                    {
                        attachment.InsertFileAttachment(WriteToFile(file));
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(strTempAssociationID) ||
                            (workItem != null) && (System.Convert.ToString(workItem.State["TempAssociationID"]) == strTempAssociationID))
                        {
                            attachment.FileName = Path.GetFileName(file.FileName); //ie sends up the full path, ff sends up just the filename
                            /* Save to get an ID used for temp purposes. */
                            attachment.Save();
                            IUserService userServ = ApplicationContext.Current.Services.Get <IUserService>();
                            strTempAssociationID = userServ.UserId; // If we use the attachment id it fails when they try to insert an item with 2 attachments
                            if (workItem != null)
                            {
                                workItem.State["TempAssociationID"] = strTempAssociationID;
                            }
                        }
                        Rules.InsertTempFileAttachment(attachment, EntityContext.EntityType, strTempAssociationID, WriteToFile(file));
                    }
                    txtInsertDesc.Text = String.Empty;
                    LoadAttachments();
                }
            }
            else
            {
                DialogService.ShowMessage(GetLocalResourceObject("Error_UnableToLoad_lz").ToString());
                log.Warn(GetLocalResourceObject("Error_UnableToLoad_lz").ToString());
            }
            hideAdds();
        }
        catch (Exception ex)
        {
            log.Error(ex.Message);
            DialogService.ShowMessage(ex.Message);
        }
    }