Beispiel #1
0
        private void EditAlert_Click(object sender, EventArgs e)
        {
            Alert alert;
            int   row, alertId;

            row = V.GetFocusedDataSourceRowIndex();
            if (row < 0)
            {
                return;
            }
            alertId = (int)DataTable.Rows[row]["AlertId"];
            alertId = AlertProperties.Edit(alertId, out alert);             // may cancel also
            if (alertId > 0)
            {
                SetDataRow(DataTable.Rows[row], alert);
            }

            else if (alertId < 0)             // cancelled alert
            {
                DataTable.Rows.RemoveAt(row);
            }

            Grid.Refresh();
            return;
        }
Beispiel #2
0
        /// <summary>
        /// Edit alert properties
        /// </summary>

        void EditAlert()
        {
            int   alertId = 0;
            Alert alert;

            if (Query.UserObject.Id <= 0)             // query been saved?
            {
                MessageBoxMx.ShowError("This query must be saved before an alert can be defined on it.");
                return;
            }

            if (!Alert.QueryValidForAlert(Query))
            {
                return;                                               // be sure it is valid
            }
            if (!QbUtil.CanRunQueryInBackground(Query))
            {
                return;                                                     // further validity checks
            }
            int newAlertId = AlertProperties.Edit(Query.UserObject.Id, out alert);

            if (newAlertId == 0)
            {
                return;                              // no change
            }
            SetAlertText(alert);
            return;
        }
Beispiel #3
0
        private void NewAlert_Click(object sender, EventArgs e)
        {
            Alert alert;
            int   queryId, alertId;

            queryId = 0;
            if (QbUtil.Query != null && QbUtil.Query.UserObject.Id > 0 &&
                Alert.GetAlertByQueryId(QbUtil.Query.UserObject.Id) == null)
            {
                queryId = QbUtil.Query.UserObject.Id;
            }
            alertId = AlertProperties.Edit(queryId, out alert);             // new alert
            if (alertId > 0)
            {
                DataRow dr = DataTable.NewRow();
                SetDataRow(dr, alert);
                DataTable.Rows.Add(dr);
                Grid.Refresh();
            }

            return;
        }
Beispiel #4
0
        /// <summary>
        /// Edit an alert
        /// </summary>
        /// <param name="objectId">AlertId or QueryId to edit alert for</param>
        /// <param name="alert">New alert content</param>
        /// <returns>-1 if alert deleted, 0 if edit cancelled, alertId if successfully edited</returns>

        public static int Edit(
            int objectId,
            out Alert alert)
        {
            alert = null;
            int        alertId = 0;
            UserObject auo     = null;         // alert user object
            UserObject quo     = null;

            if (objectId > 0)             // read existing alert/query header
            {
                UserObject uo = UserObjectDao.ReadHeader(objectId);
                if (uo == null)
                {
                    throw new Exception("UserObject not found " + objectId.ToString());
                }
                if (uo.Type == UserObjectType.Alert)                 // editing existing alert
                {
                    auo                   = uo;
                    alertId               = objectId;
                    alert                 = Alert.GetAlertFromUserObject(auo, false);
                    quo                   = UserObjectDao.ReadHeader(alert.QueryObjId);
                    alert.QueryName       = quo.Name;
                    alert.LastQueryUpdate = quo.UpdateDateTime;
                }

                else if (uo.Type == UserObjectType.Query)                 // edit any alert associated with existing query
                {
                    quo   = uo;
                    alert = Alert.GetAlertByQueryId(uo.Id);
                    if (alert != null)
                    {
                        alertId               = alert.Id;
                        alert.QueryName       = quo.Name;
                        alert.LastQueryUpdate = quo.UpdateDateTime;
                    }
                }

                else
                {
                    throw new Exception("UserObject not alert or query " + objectId.ToString());
                }
            }

            if (alertId == 0)             // create basic new alert object
            {
                alert = new Alert(quo);
            }

            if (Instance == null)
            {
                Instance = new AlertProperties();
            }
            Instance.Setup(alert, quo);

            DialogResult dr = Instance.ShowDialog(SessionManager.ActiveForm);

            if (dr == DialogResult.Abort)             // alert deleted
            {
                alert = null;
                return(-1);
            }
            else if (dr == DialogResult.Cancel)
            {
                return(0);                                            // edit cancelled
            }
            else
            {
                return(Instance.Alert.Id);             // successfully created/edited, return the userobject id
            }
        }