Exemplo n.º 1
0
        /*********************************************************
        * UPDATE STATEMENTS
        *********************************************************/

        public void UpdateTaskScheduler(UpdateQuery update)
        {
            // Insert the Import into the database
            Database db = new Database(this.newDatabase);

            db.Update(update);
        }
Exemplo n.º 2
0
        public void Update(UpdateQuery update)
        {
            using (MySqlConnection con = Connect())
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    // Prepare query
                    cmd.Connection  = con;
                    cmd.CommandText = update.GetQuery();
                    cmd.Prepare();

                    // Get values and fields
                    List <string> valuesList  = update.GetAllValues();
                    string[]      valuesArray = valuesList.ToArray();
                    string[]      fields      = update.fields;

                    // Enter parameters
                    try
                    {
                        for (int i = 0; i < valuesArray.Length; ++i)
                        {
                            cmd.Parameters.AddWithValue("@" + fields[i], valuesArray[i]);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Database Error: \r\nQuery: " + update.GetQuery() + "\r\n" + ex.ToString());
                    }

                    // Execute query
                    try
                    {
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Database Error: \r\nQuery: " + update.GetQuery() + "\r\n" + ex.ToString());
                    }

                    con.Close();
                }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Requests the report to be generated by the task Id. Must be provided a data connection to
        /// access the database methods.
        /// </summary>
        /// <param name="data">Handles database methods</param>
        /// <param name="taskId">Integer - task Id</param>
        private void ProcessTask(Data data, int taskId)
        {
            string exportFile = null;
            try
            {
                int accountId = data.GetAccountIdForDatabase();

                if(accountId==281)
                {

                    if(taskId==1)
                    {

                //accountId = 282;
                //taskId = 1;
                //accountId = 259;
                //taskId = 1;

                // Send request to server to generate report and return file name
                exportFile = this.SendRequest(accountId, taskId);

                exportFile = Regex.Replace(exportFile, @"\s", "");
              //  exportFile = "509542_08072015054608.pdf";

                // Check for null response
                if (exportFile == null)
                {
                    // Get task name
                    string taskName = data.GetScheduledTaskName(taskId);

                    // Log a warning
                    Log.Warning(String.Format(
                        "Scheduled task returned false for account: {0}, task scheduled: {1}, task name:",
                        accountId,
                        taskId,
                        taskName
                    ));

                    // Email the issue to admins
                    this.EmailIssue(taskName);

                    return;
                }

                // Assign response as new file
                file = new FileInfo(exportFile);

                // task[0] = timecycle_id | task[1] = content_id | task[2] = sctNextRun | task[3] = sctDescription | task[4] = sctEmailSubject
                string[] task     = data.GetScheduledTask(taskId);

                // Get email list
                string[] emails   = data.GetScheduledTaskEmailList(taskId);

                // Get report type
                string reportType = data.GetReportNameByContentId(Convert.ToInt32(task[1]));

                // Send the emails
                this.EmailTask(emails, task[3], task[4]);

                // Set next run time
                DateTime d = Convert.ToDateTime(task[2]);
                TimeSpan lastRunTime = new TimeSpan(d.Hour, d.Minute, d.Second);
                DateTime lastRunDateTime = DateTime.Today.Add(lastRunTime);

                // Create last run and next run
                string lastRun = lastRunDateTime.ToString("yyyy-MM-dd HH:mm:ss");
                string nextRun = Utility.AddTimeCycle(lastRun, Convert.ToInt32(task[0]));

                // Update task
                UpdateQuery update = new UpdateQuery();
                update.SetTable("scheduledtask");
                update.SetFields(new string[] { "sctNextRun", "sctLastRun" });
                update.SetId(taskId.ToString());
                update.AddRowValue(nextRun);
                update.AddRowValue(lastRun);

                // Enter into database
                data.UpdateTaskScheduler(update);

                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("Task process error:\r\n" + ex.ToString());
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Updates the last check row in the table
        /// </summary>
        private void UpdateLastCheck()
        {
            Database db = new Database(this.database);

            UpdateQuery update = new UpdateQuery();
            update.SetTable("welfarecheck");
            update.SetFields(new string[] { "welLastCheck" });
            update.AddRowValue(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            update.SetId(this.welfareId.ToString());

            db.Update(update);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Set the loop pre-warned status to true
        /// </summary>
        private void UpdatePreWarning()
        {
            Database db = new Database(this.database);

            UpdateQuery update = new UpdateQuery();
            update.SetTable("loop");
            update.SetFields(new string[] { "looPreWarned" });
            update.AddRowValue(1.ToString());
            update.SetId(this.loopId.ToString());

            db.Update(update);

            this.preWarned = true;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Updates the last completion row in the table
        /// </summary>
        /// <param name="dt"></param>
        private void UpdateLastCompletion(DateTime dt)
        {
            Database db = new Database(this.database);

            UpdateQuery update = new UpdateQuery();
            update.SetTable("loop");
            update.SetFields(new string[] { "looLastCompletion" });
            update.AddRowValue(dt.ToString("yyyy-MM-dd HH:mm:ss"));
            update.SetId(this.loopId.ToString());

            db.Update(update);

            this.lastCompletion = dt;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Updates the last check row in the table
        /// </summary>
        private void UpdateLastCheck()
        {
            Database db = new Database(this.database);
            DateTime dt = DateTime.Now;

            UpdateQuery update = new UpdateQuery();
            update.SetTable("loop");
            update.SetFields(new string[] { "looLastCheck", "looPreWarned" });
            update.AddRowValue(dt.ToString("yyyy-MM-dd HH:mm:ss"));
            update.AddRowValue(0.ToString());
            update.SetId(this.loopId.ToString());

            db.Update(update);

            this.lastCheck = dt;
        }
Exemplo n.º 8
0
        private void UpdateLastCheck(int HighRiskRecord_Id)
        {
            Database db = new Database(this.database);

            UpdateQuery update = new UpdateQuery();
            update.SetTable("checkpointhighrisk");
            update.SetFields(new string[] { "chrLastCheck" });
            update.AddRowValue(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"));
            update.SetId(HighRiskRecord_Id.ToString());

            db.Update(update);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Writes data to the database for the records and sets the chrStartDate and chrLastCheck
        /// </summary>
        /// <param name="HighRiskData"></param>
        private void CheckandInitialiseNullRecords(CheckPointHighRisk HighRiskRecord)
        {
            Database db = new Database(this.database);

            UpdateQuery update = new UpdateQuery();
            update.SetTable("checkpointhighrisk");
            update.SetFields(new string[] { "chrLastCheck", "chrStartTime" });

            string _nullDateTime = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
            List<string> _nullDates = new List<string>();
            _nullDates.Add(_nullDateTime);
            _nullDates.Add(_nullDateTime);

            update.SetRowValues(_nullDates);
            update.SetId(HighRiskRecord.id.ToString());

            db.Update(update);
        }
Exemplo n.º 10
0
        public void Update(UpdateQuery update)
        {
            using (MySqlConnection con = Connect())
            using (MySqlCommand cmd    = new MySqlCommand())
            {
                // Prepare query
                cmd.Connection  = con;
                cmd.CommandText = update.GetQuery();
                cmd.Prepare();

                // Get values and fields
                List<string> valuesList = update.GetAllValues();
                string[] valuesArray    = valuesList.ToArray();
                string[] fields         = update.fields;

                // Enter parameters
                try
                {
                    for (int i = 0; i < valuesArray.Length; ++i)
                        cmd.Parameters.AddWithValue("@" + fields[i], valuesArray[i]);
                }
                catch (Exception ex)
                {
                    Log.Error("Database Error: \r\nQuery: " + update.GetQuery() + "\r\n" + ex.ToString());
                }

                // Execute query
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    Log.Error("Database Error: \r\nQuery: " + update.GetQuery() + "\r\n" + ex.ToString());
                }

                con.Close();
            }
        }
Exemplo n.º 11
0
 /*********************************************************
  * UPDATE STATEMENTS
  *********************************************************/
 public void UpdateTaskScheduler(UpdateQuery update)
 {
     // Insert the Import into the database
     Database db = new Database(this.newDatabase);
     db.Update(update);
 }