Beispiel #1
0
        protected override void Execute(CodeActivityContext context)
        {
            string      pathName    = PathName.Get(context);
            MimeMessage mailMessage = MimeMessageAttachs.Get(context);

            try
            {
                if (!Directory.Exists(pathName))
                {
                    Directory.CreateDirectory(pathName);
                }
                List <string> list = new List <string>();
                foreach (MimePart attachment in mailMessage.Attachments)
                {
                    using (var cancel = new System.Threading.CancellationTokenSource())
                    {
                        string fileName = attachment.FileName;
                        string filePath = pathName + "\\" + fileName;
                        using (var stream = File.Create(filePath))
                        {
                            attachment.Content.DecodeTo(stream, cancel.Token);
                            list.Add(filePath);
                        }
                    }
                }
                AttachFiles.Set(context, list.ToArray());
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "保存附件失败", e.Message);
            }
        }
        protected void gvAttachFiles_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) {

                String attachFileId = ((Label)e.Row.FindControl("lblAttachFileId")).Text;
                String fileStatus   = ((Label)e.Row.FindControl("lblFileStatus")).Text;
                //Only For 0-1 Element
                //AttachFile attachFile = AttachFiles.Single(a => a.ID == attachFileId && a.FILE_STATUS==fileStatus);
                //Only For one more Element
                AttachFile attachFile = AttachFiles.FirstOrDefault(a => a.ID == attachFileId && a.FILE_STATUS == fileStatus);
                if (attachFile != null)
                {
                    LinkButton lbnEditGv = (LinkButton)e.Row.FindControl("lbnEditGv");
                    LinkButton hplView   = (LinkButton)e.Row.FindControl("hplView");
                    LinkButton hplDelete = (LinkButton)e.Row.FindControl("hplDelete");
                    LinkButton hplCancel = (LinkButton)e.Row.FindControl("hplCancel");

                    Label lblDocumentName = (Label)e.Row.FindControl("lblDocumentName");
                    lblDocumentName.Text = ddlDocumentType.Items.FindByValue(attachFile.ATTACH_FILE_TYPE).Text;

                    //if (hplView != null) hplView.OnClientClick = LinkPopUp(attachFile.ATTACH_FILE_PATH);
                    if (_modeForm == DTO.DataActionMode.View)
                    {
                        BindingRowModeView(attachFile, lbnEditGv, hplView, hplDelete, hplCancel, e);
                    }
                    else
                    {
                        BindingRowMode(attachFile, lbnEditGv, hplView, hplDelete, hplCancel, e);
                    }
                }
                //}
            }
        }
Beispiel #3
0
    private void AttachFiles(byte[] _file, Int64 size, string contentype, string mimetype, string filename, int messageid)
    {
        using (IheariCrmEntities db = new IheariCrmEntities())
        {
            AttachFiles obj = new AttachFiles();
            obj.MessageID   = messageid;
            obj.ContentType = contentype;
            obj.SizeFiles   = size;
            obj.MimeType    = mimetype;
            obj.FileName    = filename;
            obj.Filebinary  = _file;

            db.AttachFiles.Add(obj);
            db.SaveChanges();
        }
    }
Beispiel #4
0
        public virtual void DeleteAttach(String id)
        {
            if (_attachFiles.Where(a => a.ID == id).Count() <= 0)
            {
                throw new RegistrationException(Resources.errorBaseRegistration_004);
            }

            AttachFilesIAS.AttachFile attachFile = AttachFiles.Where(a => a.ID == id).Single();
            using (FileService.FileTransferServiceClient svc = new FileService.FileTransferServiceClient())
            {
                //DeleteFileResponse response = svc.DeleteFile(new DeleteFileRequest() { TargetFileName = attachFile.ATTACH_FILE_PATH });
                //if (response.Code != "0000")
                //    throw new RegistrationException(response.Message);

                _attachFiles.Remove(attachFile);
            }
        }
Beispiel #5
0
        protected void btnUploadFile_Click(object sender, EventArgs e)
        {
            string tempFileName = Path.GetFileName(fulFile.PostedFile.FileName);

            bool invalid = validateFileType(tempFileName);

            if (ddlRequestLicenseType.SelectedIndex != 0)
            {
                if (ddlTypeAttachment.SelectedIndex != 0)
                {
                    if (tempFileName != string.Empty)
                    {
                        FileInfo f           = new FileInfo(tempFileName);
                        string   surNameFile = f.Extension;

                        string fileName = string.Empty;

                        var TypeFile = AttachFiles.Where(w => w.ATTACH_FILE_TYPE == ddlTypeAttachment.SelectedValue).FirstOrDefault();


                        string        yearMonthDay = DateTime.Now.ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
                        string        hourMinSec   = DateTime.Now.ToString("HHmmss", System.Globalization.CultureInfo.InvariantCulture);
                        DirectoryInfo DirInfo      = new DirectoryInfo(Server.MapPath(mapPath) + this.TempFolderOracle);

                        if (invalid)
                        {
                            if (UserProfile.IdCard != string.Empty)
                            {
                                var attFileImage = this.GetDocumentTypeIsImage.Where(w => w.Id == ddlTypeAttachment.SelectedValue).FirstOrDefault();

                                if (attFileImage != null)
                                {
                                    if (TypeFile == null)
                                    {
                                        tempFileName = "_" + UserProfile.IdCard + "_" + ddlRequestLicenseType.SelectedValue + surNameFile;

                                        UploadFileImage(tempFileName);

                                        string[] _fileName = tempFileName.Split('_');

                                        string masterFileName = _fileName[1] + "_" + _fileName[2];

                                        //*** Create Folder ***//
                                        if (!DirInfo.Exists)
                                        {
                                            DirInfo.Create();

                                            fulFile.PostedFile.SaveAs(Server.MapPath(mapPath + "/" + this.TempFolderOracle + "/" + masterFileName));

                                            ddlTypeAttachment.SelectedIndex = 0;
                                            txtDetail.Text = string.Empty;
                                        }
                                        else
                                        {
                                            fulFile.PostedFile.SaveAs(Server.MapPath(mapPath + "/" + this.TempFolderOracle + "/" + masterFileName));

                                            ddlTypeAttachment.SelectedIndex = 0;
                                            txtDetail.Text = string.Empty;
                                        }
                                    }
                                    else
                                    {
                                        UCModalError.ShowMessageError = SysMessage.PleaseDeleteFile;
                                        UCModalError.ShowModalError();

                                        ddlTypeAttachment.SelectedIndex = 0;
                                        txtDetail.Text = string.Empty;
                                    }
                                }
                                else
                                {
                                    //Upload File Normal
                                    if (TypeFile == null)
                                    {
                                        tempFileName = "_" + UserProfile.IdCard + "_" + ddlRequestLicenseType.SelectedValue + "_" + ddlTypeAttachment.SelectedValue + surNameFile;

                                        UploadFile(tempFileName);

                                        string[] _fileName = tempFileName.Split('_');

                                        string masterFileName = _fileName[1] + "_" + _fileName[2] + "_" + _fileName[3];

                                        //*** Create Folder ***//
                                        if (!DirInfo.Exists)
                                        {
                                            DirInfo.Create();

                                            fulFile.PostedFile.SaveAs(Server.MapPath(mapPath + "/" + this.TempFolderOracle + "/" + masterFileName));

                                            ddlTypeAttachment.SelectedIndex = 0;
                                            txtDetail.Text = string.Empty;
                                        }
                                        else
                                        {
                                            fulFile.PostedFile.SaveAs(Server.MapPath(mapPath + "/" + this.TempFolderOracle + "/" + masterFileName));

                                            ddlTypeAttachment.SelectedIndex = 0;
                                            txtDetail.Text = string.Empty;
                                        }
                                    }
                                    else
                                    {
                                        tempFileName = "_" + UserProfile.IdCard + "_" + ddlTypeAttachment.SelectedValue + "_" + yearMonthDay + hourMinSec + surNameFile;

                                        UploadFile(tempFileName);

                                        string[] _fileName = tempFileName.Split('_');

                                        string masterFileName = _fileName[1] + "_" + _fileName[2] + "_" + _fileName[3];

                                        //*** Create Folder ***//
                                        if (!DirInfo.Exists)
                                        {
                                            DirInfo.Create();

                                            fulFile.PostedFile.SaveAs(Server.MapPath(mapPath + "/" + this.TempFolderOracle + "/" + masterFileName));

                                            ddlTypeAttachment.SelectedIndex = 0;
                                            txtDetail.Text = string.Empty;
                                        }
                                        else
                                        {
                                            fulFile.PostedFile.SaveAs(Server.MapPath(mapPath + "/" + this.TempFolderOracle + "/" + masterFileName));

                                            ddlTypeAttachment.SelectedIndex = 0;
                                            txtDetail.Text = string.Empty;
                                        }

                                        //UCModalError.ShowMessageError = SysMessage.PleaseSelectFile;
                                        //UCModalError.ShowModalError();


                                        UCModalError.ShowMessageError = SysMessage.PleaseDeleteFile;
                                        UCModalError.ShowModalError();

                                        ddlTypeAttachment.SelectedIndex = 0;
                                        txtDetail.Text = string.Empty;
                                    }
                                }
                            }
                            else
                            {
                                UCModalError.ShowMessageError = SysMessage.PleaseInputIDNumber;
                                UCModalError.ShowModalError();

                                ddlTypeAttachment.SelectedIndex = 0;
                                txtDetail.Text = string.Empty;
                            }
                        }
                        else
                        {
                            //UCModalError.ShowMessageError = SysMessage.PleaseSelectFile;
                            //UCModalError.ShowModalError();

                            ddlTypeAttachment.SelectedIndex = 0;
                            txtDetail.Text = string.Empty;
                        }
                    }
                    else
                    {
                        UCModalError.ShowMessageError = SysMessage.PleaseChooseFile;
                        UCModalError.ShowModalError();

                        ddlTypeAttachment.SelectedIndex = 0;
                        txtDetail.Text = string.Empty;
                    }
                }
                else
                {
                    UCModalError.ShowMessageError = SysMessage.PleaseSelectFile;
                    UCModalError.ShowModalError();

                    ddlTypeAttachment.SelectedIndex = 0;
                    txtDetail.Text = string.Empty;
                }

                UpdatePanelUpload.Update();
            }
            else
            {
            }
        }
Beispiel #6
0
    protected void btnSend_Click(object sender, EventArgs e)
    {
        int    memberid    = LoginManager.MemberID("ihcrm");
        string subject     = WebUtility.HtmlEncode(txtsubject.Text);
        string shomarename = WebUtility.HtmlEncode(txtshomarename.Text);

        if (subject.Length == 0)
        {
            lblresult.Text = "Please Enter Subject"; lblresult.ForeColor = Color.Red; return;
        }
        string body = WebUtility.HtmlEncode(radeditor.Content);

        if (body.Length < 1)
        {
            lblresult.Text = "The Body Text is Very Short"; lblresult.ForeColor = Color.Red; return;
        }
        if (totalBytes > MaxTotalBytes)
        {
            lblresult.Text = "Maximum file Size is 10 MB"; lblresult.ForeColor = Color.Red; return;
        }
        int messageid;

        using (var context = new IheariCrmEntities())
        {
            using (var db = context.Database.BeginTransaction())
            {
                try
                {
                    Message obj = new Message();
                    obj.MemberID    = memberid;
                    obj.DateCreate  = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
                    obj.Title       = subject;
                    obj.TextBody    = body;
                    obj.ShomareName = shomarename;
                    obj.IPAddress   = Request.UserHostAddress.ToString();
                    obj.TrashBox    = false;
                    if (totalBytes > 0)
                    {
                        obj.SizeAttach = totalBytes.ToString();
                        obj.ISattach   = true;
                    }
                    else
                    {
                        obj.ISattach = false;
                    }
                    obj.ISattach = true;
                    context.Message.Add(obj);
                    messageid = obj.ID;

                    IList <RadTreeNode> nodeCollection = RadTileList1.CheckedNodes;
                    List <Send_Recive>  Lst            = new List <Send_Recive>();

                    int _c = 0;
                    foreach (RadTreeNode node in nodeCollection)
                    {
                        if (node.Nodes.Count == 0)
                        {
                            _c = _c + 1;
                            Lst.Add(new Send_Recive
                            {
                                MessegaeID       = messageid,
                                Memeber_ReciveID = int.Parse(node.Value),
                                Visit            = false, TrashBox = false
                            });
                        }
                    }
                    if (_c == 0)
                    {
                        lblresult.Text = "You Must Select the Reciver"; lblresult.ForeColor = Color.Red; return;
                    }
                    context.Send_Recive.AddRange(Lst);

                    foreach (UploadedFile file in RadAsyncUpload1.UploadedFiles)
                    {
                        UploadedFileInfo uploadedFileInfo = new UploadedFileInfo(file);
                        UploadedFiles.Add(uploadedFileInfo);
                        string fna             = uploadedFileInfo.FileName;
                        Stream fileStream      = file.InputStream;
                        byte[] attachmentBytes = new byte[fileStream.Length];
                        fileStream.Read(attachmentBytes, 0, Convert.ToInt32(fileStream.Length));
                        AttachFiles obj3 = new AttachFiles();
                        obj3.MessageID   = messageid;
                        obj3.ContentType = uploadedFileInfo.ContentType;
                        obj3.SizeFiles   = uploadedFileInfo.ContentLength;
                        obj3.MimeType    = null;
                        obj3.FileName    = uploadedFileInfo.FileName;
                        obj3.Filebinary  = attachmentBytes;

                        context.AttachFiles.Add(obj3);
                    }

                    context.SaveChanges();
                    db.Commit();
                    Response.Redirect("Default.aspx?m=sent");
                }
                catch (Exception ex)
                {
                    db.Rollback();

                    Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                    Response.Redirect("Default.aspx?m=send&er=1");
                }
            }
        }
    }