Beispiel #1
0
        public AttachmentIcon AddAttachment(ShortRequestWithAttachments shortRequestWithAttachments)
        {
            System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();

            if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return(null);
            }

            FileInfo fi = new FileInfo(dialog.FileName);

            byte[] content = new byte[Convert.ToInt32(fi.Length)];
            new FileStream(dialog.FileName, FileMode.Open, FileAccess.ReadWrite).Read(content, 0, Convert.ToInt32(fi.Length));

            AttachmentType type           = new AttachmentType();
            AttachmentData attachmentData = new AttachmentData();

            attachmentData.AttachmentTypeId = 3;
            if (shortRequestWithAttachments.attachmentList.Count != 0)
            {
                attachmentData.ordinalNumber = shortRequestWithAttachments.attachmentList.Max(i => i.ordinalNumber) + 1;
            }
            else
            {
                attachmentData.ordinalNumber = 0;
            }

            attachmentData.RequestId = shortRequestWithAttachments.Request.Id;
            attachmentData.content   = content;
            attachmentData.FileName  = System.IO.Path.GetFileName(dialog.FileName);
            contract.AddAttachment(attachmentData);
            MessageBox.Show("Вложение добавлено");

            AttachmentIcon result = new AttachmentIcon(new ShortAttachmentData()
            {
                id               = attachmentData.id,
                FileName         = attachmentData.FileName,
                AttachmentTypeId = attachmentData.AttachmentTypeId,
                ordinalNumber    = attachmentData.ordinalNumber,
                RequestId        = attachmentData.RequestId
            }, false);

            return(result);
        }