コード例 #1
0
ファイル: MStore.cs プロジェクト: vuongthai91/ERP-CMR-DMS
        }       //	beforeSave

        /// <summary>
        ///	Create EMail from Request User
        /// </summary>
        /// <param name="toEMail">recipient</param>
        /// <param name="toName">tomail</param>
        /// <param name="subject">subject</param>
        /// <param name="message">message</param>
        /// <returns>Email</returns>
        public EMail CreateEMail(String toEMail, String toName,
                                 String subject, String message)
        {
            if (toEMail == null || toEMail.Length == 0)
            {
                _log.Warning("No To");
                return(null);
            }

            //
            EMail   email  = null;
            MClient client = MClient.Get(GetCtx(), GetAD_Client_ID());

            if (client.IsServerEMail() && Ini.IsClient())
            {
                //MessageBox.Show("Get Connection Problem");
                //Server server = CConnection.get().getServer();

                try
                {
                    //if (server != null)
                    if (!DataBase.DB.IsConnected())
                    {
                        email = CreateEMail(toEMail, toName, subject, message);
                    }

                    //{	//	See ServerBean
                    //    email = server.CreateEMail(GetCtx(), GetAD_Client_ID(),
                    //        toEMail, toName, subject, message);

                    //}
                    else
                    {
                        log.Log(Level.WARNING, "No AppsServer");
                    }
                }
                catch (Exception ex)
                {
                    log.Log(Level.SEVERE, GetName() + " - AppsServer error", ex);
                }
            }
            String from = GetWStoreEMail();

            if (from == null || from.Length == 0)
            {
                from = client.GetRequestEMail();
            }
            if (email == null)
            {
                email = new EMail(client,
                                  from, client.GetName(), toEMail, toName,
                                  subject, message);
            }
            //	Authorizetion
            if (client.IsSmtpAuthorization())
            {
                if (GetWStoreEMail() != null && GetWStoreUser() != null && GetWStoreUserPW() != null)
                {
                    email.CreateAuthenticator(GetWStoreUser(), GetWStoreUserPW());
                }
                else
                {
                    email.CreateAuthenticator(client.GetRequestUser(), client.GetRequestUserPW());
                }
            }
            //	Bcc
            email.AddBcc(from);
            //
            return(email);
        }
コード例 #2
0
        }       //	prepare

        /// <summary>
        /// Perrform process.
        /// </summary>
        /// <returns>Message to be translated</returns>
        protected override String DoIt()
        {
            log.Info("");
            long start = CommonFunctions.CurrentTimeMillis();// System.currentTimeMillis();

            //	Test
            if (_client.GetSmtpHost() == null || _client.GetSmtpHost().Length == 0)
            {
                throw new Exception("No Client SMTP Info");
            }
            if (_client.GetRequestEMail() == null)
            {
                throw new Exception("No Client Request User");
            }

            //	Asset selected
            if (_A_Asset_ID != 0)
            {
                String msg = DeliverIt(_A_Asset_ID);
                AddLog(_A_Asset_ID, null, null, msg);
                return(msg);
            }
            //
            StringBuilder sql = new StringBuilder("SELECT A_Asset_ID, GuaranteeDate "
                                                  + "FROM A_Asset a"
                                                  + " INNER JOIN M_Product p ON (a.M_Product_ID=p.M_Product_ID) "
                                                  + "WHERE ");

            if (_A_Asset_Group_ID != 0 && _A_Asset_Group_ID != -1)
            {
                sql.Append("a.A_Asset_Group_ID=").Append(_A_Asset_Group_ID).Append(" AND ");
            }
            if (_M_Product_ID != 0)
            {
                sql.Append("p.M_Product_ID=").Append(_M_Product_ID).Append(" AND ");
            }
            if (_C_BPartner_ID != 0)
            {
                sql.Append("a.C_BPartner_ID=").Append(_C_BPartner_ID).Append(" AND ");
            }
            String s = sql.ToString();

            if (s.EndsWith(" WHERE "))
            {
                throw new Exception("@RestrictSelection@");
            }
            //	No mail to expired
            if (_NoGuarantee_MailText_ID == 0)
            {
                sql.Append("TRUNC(GuaranteeDate,'DD') >= ").Append(DB.TO_DATE(_GuaranteeDate, true));
                s = sql.ToString();
            }
            //	Clean up
            if (s.EndsWith(" AND "))
            {
                s = sql.ToString().Substring(0, sql.Length - 5);
            }
            //
            int         count     = 0;
            int         errors    = 0;
            int         reminders = 0;
            IDataReader idr       = null;

            try
            {
                idr = DB.ExecuteReader(s);
                while (idr.Read())
                {
                    int      A_Asset_ID    = Util.GetValueOfInt(idr[0]);      // rs.getInt(1);
                    DateTime?GuaranteeDate = Util.GetValueOfDateTime(idr[1]); // rs.getTimestamp(2);

                    //	Guarantee Expired
                    //if (GuaranteeDate.Value != null && GuaranteeDate.before(m_GuaranteeDate))
                    if (GuaranteeDate.Value != null && GuaranteeDate.Value < _GuaranteeDate)
                    {
                        if (_NoGuarantee_MailText_ID != 0)
                        {
                            SendNoGuaranteeMail(A_Asset_ID, _NoGuarantee_MailText_ID, Get_Trx());
                            reminders++;
                        }
                    }
                    else //	Guarantee valid
                    {
                        String msg = DeliverIt(A_Asset_ID);
                        AddLog(A_Asset_ID, null, null, msg);
                        if (msg.StartsWith("** "))
                        {
                            errors++;
                        }
                        else
                        {
                            count++;
                        }
                    }
                }
                idr.Close();
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                log.Log(Level.SEVERE, s, e);
            }

            log.Info("Count=" + count + ", Errors=" + errors + ", Reminder=" + reminders
                     + " - " + (CommonFunctions.CurrentTimeMillis() - start) + "ms");
            return("@Sent@=" + count + " - @Errors@=" + errors);
        }       //	doIt