Пример #1
0
        /// <summary>
        /// 获得所有任务清单
        /// </summary>
        /// <returns>IList[Tasks]()</returns>
        public IList <Tasks> GetTaskList()
        {
            IList <Tasks>    task = new List <Tasks>();
            Tasks            t    = null;
            OracleDataReader dr;

            try
            {
                string sql = "select * from qm_task where taskstate = 'Y' order by taskcreatetime desc";
                dr = qmdb.ExecuteReader(CommandType.Text, sql);
                while (dr.Read())
                {
                    t                = new Tasks();
                    t.idx            = dr["IDX"].ToString();
                    t.taskClsType    = dr["TASKCLSTYPE"].ToString();
                    t.taskCount      = dr["TASKCOUNT"].ToString();
                    t.taskCreateTime = DateTime.Parse(dr["TASKCREATETIME"].ToString());
                    if (dr["TASKLASTSTARTTIME"].ToString() != "")
                    {
                        t.taskLastStartTime = DateTime.Parse(dr["TASKLASTSTARTTIME"].ToString());
                    }
                    if (dr["TASKLASTENDTIME"].ToString() != "")
                    {
                        t.taskLastEndTime = DateTime.Parse(dr["TASKLASTENDTIME"].ToString());
                    }
                    if (dr["TASKLASTERRORTIME"].ToString() != "")
                    {
                        t.taskLastErrorTime = DateTime.Parse(dr["TASKLASTERRORTIME"].ToString());
                    }
                    if (dr["TASKERRORCOUNT"].ToString() != "")
                    {
                        t.taskErrorCount = int.Parse(dr["TASKERRORCOUNT"].ToString());
                    }
                    t.taskType  = dr["TASKTYPE"].ToString();
                    t.taskDBCon = dr["TASKDBCON"].ToString();
                    t.taskParm  = dr["TASKPARM"].ToString();
                    t.taskFile  = dr["TASKFILE"].ToString();
                    //t.taskExpFile = dr["TASKEXPFILE"].ToString();
                    t.taskName   = dr["TASKNAME"].ToString();
                    t.taskState  = dr["TASKSTATE"].ToString();
                    t.taskCron   = dr["TASKCRON"].ToString();
                    t.taskRemark = dr["TASKREMARK"].ToString();
                    t.taskSendby = dr["TASKSENDBY"].ToString();
                    task.Add(t);
                }
                dr.Close();
            }
            catch (QMException ex)
            {
                throw ex;
            }
            finally
            {
                qmdb.Disponse();
            }

            return(task);
        }
Пример #2
0
        /// <summary>
        /// 新的任务记录
        /// </summary>
        /// <param name="t">任务记录类</param>
        public void Insert(TaskLog t)
        {
            try
            {
                string sql = @"insert into qm_tasklog
                                    (idx,
                                     taskid,
                                     type,
                                     server,
                                     createtime,
                                     message) 
                            values
                                    (:idx,
                                     :taskid,
                                     :type,
                                     :server,
                                     :createtime,
                                     :message)";

                OracleParameter[] param = new OracleParameter[]
                {
                    new OracleParameter(":idx", t.idx),
                    new OracleParameter(":taskid", t.taskid),
                    new OracleParameter(":type", t.type),
                    new OracleParameter(":server", t.server),
                    new OracleParameter(":createtime", t.createtime),
                    new OracleParameter(":message", t.message)
                };

                qmdb.ExecuteNonQuery(sql, CommandType.Text, param);
            }
            catch (QMException ex)
            {
                throw ex;
                log.Error(string.Format("TaskLogData=>Insert ERROR:{0}", ex.Message));
            }
            finally
            {
                qmdb.Disponse();
            }
        }
Пример #3
0
 public override void Dispose()
 {
     db.Disponse();
     base.Dispose();
 }
Пример #4
0
        /// <summary>
        /// 导出excel
        /// </summary>
        public void TryRun(string sendby = "MAIL")
        {
            try
            {
                IList <TasksN2M> m_parms = null;
                m_parms = parms.Where(x => x.refname == "SQL").ToList();
                header  = m_parms.Where(x => x.attrname == "HEADER").FirstOrDefault().attrval;
                inmail  = parms.Where(x => x.refname == "MAIL" && x.attrname == "INMAIL").FirstOrDefault().attrval;
                DataSet ds = db.ExecuteDataset(sql);

                log.Debug(string.Format("[SqlExpJob] 导出文件{0},{1},{2},{3},{4}", title, filepath, filename + filedate, filetype, sql));

                if (filetype == "TXT")
                {
                    QMText txt = new QMText();
                    if (inmail == "X")
                    {
                        body = txt.Export(ds.Tables[0], header);
                    }
                    if (txt.Export(ds.Tables[0], header, filepath, out error) == false)
                    {
                        log.Fatal(string.Format("[SqlExpJob] 导出文件异常{0}", error));
                        //filepath = "";
                    }
                    else
                    {
                        log.Debug("[SqlExpJob] 导出成功");
                    }
                }
                else if (filetype == "CSV")
                {
                    QMText txt = new QMText();
                    body = txt.Export(ds.Tables[0], header);
                    if (txt.ExportCSV(ds.Tables[0], header, filepath, out error) == false)
                    {
                        log.Fatal(string.Format("[SqlExpJob] 导出文件异常{0}", error));
                        //filepath = "";
                    }
                    else
                    {
                        log.Debug("[SqlExpJob] 导出成功");
                    }
                }
                else
                {
                    IExcel ex = new QMExcel(title, filepath);
                    if (ex.Export(ds.Tables[0], title, filepath, out error) == false)
                    {
                        log.Fatal(string.Format("[SqlExpJob] 导出文件异常{0}", error));
                        //filepath = "";
                    }
                    else
                    {
                        log.Debug("[SqlExpJob] 导出成功");
                    }
                }

                foreach (var item in sendby.Split('+'))
                {
                    switch (item)
                    {
                    case "MAIL":
                        try
                        {
                            IMail mail = new QMMail();
                            mail.AddAttachment(filepath);
                            m_parms      = parms.Where(x => x.refname == "MAIL").ToList();
                            mail.Subject = m_parms.Where(x => x.attrname == "SUBJECT").FirstOrDefault().attrval +
                                           DateTime.Now.ToString(m_parms.Where(x => x.attrname == "SUBDATE").FirstOrDefault().attrval);
                            mail.AddBody(m_parms.Where(x => x.attrname == "BODY").FirstOrDefault().attrval + body, reportid);

                            foreach (var parm in m_parms.Where(x => x.attrname == "TO" || x.attrname == "CC" || x.attrname == "BCC"))
                            {
                                switch (parm.attrname)
                                {
                                case "TO":
                                    mail.AddRecipient(parm.attrval);
                                    break;

                                case "CC":
                                    mail.AddRecipientCC(parm.attrval);
                                    break;

                                case "BCC":
                                    mail.AddRecipientBCC(parm.attrval);
                                    break;
                                }
                            }

                            if (mail.Send())
                            {
                                log.Debug("[MAIL] 发送成功");
                            }
                            else
                            {
                                log.Fatal("[MAIL] 发送失败");
                                throw new QMException("[MAIL] 发送失败");
                            }
                        }
                        catch (QMException ex)
                        {
                            log.Fatal(string.Format("[MAIL] 发送失败,{0}", ex.Message + ex.StackTrace));
                            throw ex;
                        }
                        catch (SystemException sex)
                        {
                            log.Fatal(string.Format("[MAIL] 发送失败,{0}", sex.Message + sex.StackTrace));
                            throw sex;
                        }

                        break;

                    case "FTP":
                        try
                        {
                            QMFtp ftp = new QMFtp();
                            m_parms    = parms.Where(x => x.refname == "FTP").ToList();
                            ftp.server = m_parms.Where(x => x.attrname == "SERVER").FirstOrDefault().attrval;
                            ftp.user   = m_parms.Where(x => x.attrname == "ACCOUNT").FirstOrDefault().attrval;
                            ftp.pass   = m_parms.Where(x => x.attrname == "PASSWORD").FirstOrDefault().attrval;
                            string path = m_parms.Where(x => x.attrname == "RMOTEPATH").FirstOrDefault().attrval;
                            ftp.ChangeDir(path);
                            log.Debug("[FTP]目录切换成功");
                            if (ftp.OpenUpload(filepath, path + '/' + filename + filedate + '.' + filetype, false))
                            {
                                log.Debug(string.Format("[FTP]开始上传{0},{1}", filepath, path + '/' + filename + '.' + filetype));
                                long size = ftp.DoUpload();
                                log.Debug(string.Format("[FTP]文件大小:{0}", size));
                            }
                            else
                            {
                                log.Fatal("[FTP]上传失败");
                            }

                            ftp.Disconnect();
                            log.Debug("[FTP] 上传成功");
                        }
                        catch (QMException ex)
                        {
                            log.Fatal(string.Format("[FTP] 发送失败,{0}", ex.Message));
                            throw ex;
                        }
                        catch (SystemException sex)
                        {
                            log.Fatal(string.Format("[FTP] 发送失败,{0}", sex.Message + sex.StackTrace));
                            throw sex;
                        }
                        break;

                    case "SFTP":

                        break;
                    }
                }

                QMFile.Delete(filepath);
                log.Debug("[SqlExpJob] 附件删除成功");
            }
            catch (QMException ex)
            {
                log.Fatal(string.Format("[SqlExpJob] 异常{0}", ex.Message));
                throw ex;
            }
            catch (SystemException sex)
            {
                log.Fatal(string.Format("[SqlExpJob] 异常{0}", sex.Message));
                throw sex;
            }
            finally
            {
                db.Disponse();
            }
        }