Exemplo n.º 1
0
        public string DownloadAttachment(Ctx ctx, string fileName, int AD_Attachment_ID, int AD_AttachmentLine_ID)
        {
            MAttachment att = new MAttachment(ctx, AD_Attachment_ID, null);

            return(att.GetFile(AD_AttachmentLine_ID));
        }
        private string SendEmailWithAttachment(string Subject, string Message, DataSet ds1, int AD_Org_ID, int Ad_Client_ID)
        {
            string Check = "";
            int    count = 0;
            string res   = "";

            List <string> EmailLst = new List <string>(); //!string.IsNullOrEmpty(EmailIDs) ? EmailIDs.Split(',').ToList() : null;

            int UpdatedBy = GetCtx().GetAD_User_ID();

            sendmail = new VAdvantage.Utility.EMail(GetCtx(), "", "", "", "", "", "", true, false);
            string isConfigExist = sendmail.IsConfigurationExist(GetCtx());

            if (isConfigExist != "OK")
            {
                log.SaveError("Check email configuration", "");
                return(Msg.GetMsg(GetCtx(), "VIS_CheckMailConfig"));
            }

            if (ds1 != null && ds1.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
                {
                    if (Util.GetValueOfString(ds1.Tables[0].Rows[i]["NOTIFICATIONTYPE"]) == "A" ||
                        Util.GetValueOfString(ds1.Tables[0].Rows[i]["NOTIFICATIONTYPE"]) == "B" ||
                        Util.GetValueOfString(ds1.Tables[0].Rows[i]["NOTIFICATIONTYPE"]) == "E" ||
                        Util.GetValueOfString(ds1.Tables[0].Rows[i]["NOTIFICATIONTYPE"]) == "L")
                    {
                        sendmail.AddBcc(Util.GetValueOfString(ds1.Tables[0].Rows[i]["EMAIL"]));
                    }
                }

                sendmail.SetSubject(Subject);
                sendmail.SetMessageText(Message);

                MAttachment mAttach  = GetFileAttachment(GetTable_ID(), GetRecord_ID(), GetCtx());
                string      filePath = "";

                if (mAttach != null && mAttach.AD_Attachment_ID > 0)
                {
                    if (mAttach == null)
                    {
                        return("");
                    }
                    if (mAttach.IsFromHTML())
                    {
                        for (int i = 0; i < mAttach._lines.Count; i++)
                        {
                            filePath = System.IO.Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, "TempDownload");
                            filePath = System.IO.Path.Combine(filePath, mAttach.GetFile(mAttach._lines[i].Line_ID));
                            if (filePath.IndexOf("ERROR") > -1)
                            {
                                continue;
                            }
                            filePath = System.IO.Path.Combine(filePath, mAttach._lines[i].FileName);
                            sendmail.AddAttachment(new FileInfo(filePath));
                        }
                    }
                    else
                    {
                        foreach (MAttachmentEntry entry in mAttach.GetEntries())
                        {
                            sendmail.AddAttachment(entry.GetData(), entry.GetName());
                        }
                    }
                }

                Check = sendmail.Send();
                if (Check == "OK")
                {
                    count++;
                }
            }

            if (ds1 != null && ds1.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
                {
                    if (Util.GetValueOfString(ds1.Tables[0].Rows[i]["NOTIFICATIONTYPE"]) == "B" ||
                        Util.GetValueOfString(ds1.Tables[0].Rows[i]["NOTIFICATIONTYPE"]) == "C" ||
                        Util.GetValueOfString(ds1.Tables[0].Rows[i]["NOTIFICATIONTYPE"]) == "N")
                    {
                        SendNotice(Message, Util.GetValueOfInt(ds1.Tables[0].Rows[i]["AD_USER_ID"]), AD_Org_ID, Ad_Client_ID);
                    }
                }
            }

            if (count > 0)
            {
                log.Fine("Email Sent Successfully");
                res = Msg.GetMsg(GetCtx(), "VIS_EmailSent");

                string sql = "UPDATE OFFICEMEMO SET PUBLISHDATE = " + GlobalVariable.TO_DATE(System.DateTime.Now, false) + ", PUBLISHTIME = " + GlobalVariable.TO_DATE(System.DateTime.Now, false) + ", PROCESSED = 'Y' WHERE OFFICEMEMO_ID = " + _OfficeMemoID;
                DB.ExecuteQuery(sql, null, null);
            }
            else
            {
                log.SaveError("Email Not Sent", "");
                res = Msg.GetMsg(GetCtx(), "VIS_EmailNotSent");
            }

            return(res);
        }