Esempio n. 1
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);
            }
        }
    /// <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);
        }
    }