Ejemplo n.º 1
0
        public override void TableRowSaving(ISaveDataTriggerArgs args)
        {
            // pre-row save trigger
            if (args.SaveMode == SaveMode.Insert || args.SaveMode == SaveMode.Update)
            {
                var helper = args.Helper;

                // 5) all quants >=0
                if (helper.FieldExists("quantity_on_hand") && Convert.ToDouble(helper.GetValue("quantity_on_hand", 0.0, true)) < 0.0)
                {
                    args.Cancel("quantity_on_hand must not be negative");
                }
                if (helper.FieldExists("distribution_critical_quantity") && Convert.ToDouble(helper.GetValue("distribution_critical_quantity", 0.0, true)) < 0.0)
                {
                    args.Cancel("distribution_critical_quantity must not be negative");
                }
                if (helper.FieldExists("distribution_default_quantity") && Convert.ToDouble(helper.GetValue("distribution_default_quantity", 0.0, true)) < 0.0)
                {
                    args.Cancel("distribution_default_quantity must not be negative");
                }
                if (helper.FieldExists("regeneration_critical_quantity") && Convert.ToDouble(helper.GetValue("regeneration_critical_quantity", 0.0, true)) < 0.0)
                {
                    args.Cancel("regeneration_critical_quantity must not be negative");
                }
            }
        }
Ejemplo n.º 2
0
 public override void TableRowSaving(ISaveDataTriggerArgs args)
 {
     if (args.SaveMode == SaveMode.Insert)
     {
         fillMaintenancePolicyValues(args);
     }
 }
Ejemplo n.º 3
0
        public override void TableRowSaving(ISaveDataTriggerArgs args)
        {
            if (args.SaveMode == SaveMode.Insert || args.SaveMode == SaveMode.Update)
            {
                var helper = args.Helper;

                // 1) Make sure at least 1 of number, fullname is filled in
                if (helper.AllFieldsExist("ipr_number", "ipr_full_name") && helper.IsValueEmpty("ipr_number") && helper.IsValueEmpty("ipr_full_name"))
                {
                    args.Cancel("Incomplete accession_ipr, must have either ipr_number or ipr_full_name.");
                }

                // 2) do not allow expired_date > current date
                if (helper.FieldExists("expired_date") && !helper.IsValueEmpty("expired_date") &&
                    Convert.ToDateTime(helper.GetValue("expired_date", null, true)) > DateTime.UtcNow)
                {
                    args.Cancel("Expired date cannot exceed the current date.");
                }

                // 3) do not allow issued date > expired date
                if (helper.AllFieldsExist("issued_date", "expired_date") && !helper.IsValueEmpty("issued_date") && !helper.IsValueEmpty("expired_date"))
                {
                    DateTime issued  = Convert.ToDateTime(helper.GetValue("issued_date", null, true));
                    DateTime expired = Convert.ToDateTime(helper.GetValue("expired_date", null, true));
                    if (expired < issued)
                    {
                        args.Cancel("Issued date cannot exceed expired date.");
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public override void TableRowSaving(ISaveDataTriggerArgs args)
        {
            // pre-row save trigger
            // no need to check mode?

            if (args.SaveMode == SaveMode.Insert || args.SaveMode == SaveMode.Update || args.SaveMode == SaveMode.Delete)
            {
                var h = args.Helper;
                if (h.FieldExists("form_type_code"))
                {
                    string ivt = "SD";
                    if (args.SaveMode != SaveMode.Delete)
                    {
                        ivt = h.GetValue("form_type_code", "", true).ToString();
                    }
                    string ivto = h.GetOriginalValue("form_type_code", "").ToString();

                    if (ivt == "**" || ivto == "**")
                    {
                        args.Cancel("You can not insert, update or delete the system inventory row.");
                        return;
                    }
                }
            }
        }
        public void TableRowSaving(ISaveDataTriggerArgs args)
        {
            if (args.Table != null && args.Table.TableName.ToLower() == "accession")
            {
                if (args.SaveMode == SaveMode.Delete)
                {
                    // if the only record left is the default inventory association record, we need to auto-delete it before the accession is deleted.
                    var h           = args.Helper;
                    var accessionID = (int)(h.GetOriginalValue("accession_id", -1));

                    DataTable dt = args.ReadData("select form_type_code, inventory_id from inventory where accession_id = :accessionid",
                                                 new DataParameters(":accessionid", accessionID, DbType.Int32));
                    int inventoryIdToDelete = -1;
                    if (dt.Rows.Count == 1)
                    {
                        if (dt.Rows[0]["form_type_code", DataRowVersion.Original].ToString() == "**")
                        {
                            inventoryIdToDelete = Toolkit.ToInt32(dt.Rows[0]["inventory_id", DataRowVersion.Original], -1);
                        }
                    }

                    if (inventoryIdToDelete > -1)
                    {
                        // only 1 inventory record exists and it's a '**' (the default record we initially auto-created when the accession was created).
                        // try to delete it (if there are other records which are pointing at it, this will bomb, which is exactly what we want)
                        args.WriteData("delete from inventory where inventory_id = :inventoryid", new DataParameters(":inventoryid", inventoryIdToDelete, DbType.Int32));
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public void TableRowSaved(ISaveDataTriggerArgs args)
 {
     // post-row save trigger
     if (args.SaveMode == SaveMode.Insert)
     {
         if (!args.Helper.IsValueEmpty("web_order_request_item_id"))
         {
             int?woriID = (int?)(args.Helper.GetValue("web_order_request_item_id", null, true));
             if (woriID > 0)
             {
                 // update web_order_request_item table status
                 args.WriteData(@"
                 update
                     web_order_request_item
                 set
                     status_code = 'ACCEPTED',
                     modified_date = :modifieddate
                 where
                     status_code = 'NEW' and
                     web_order_request_item_id = :woriID
                 ", ":modifieddate", DateTime.UtcNow, ":woriID", woriID);
             }
         }
     }
 }
        private int getSystemMaintenancePolicyID(ISaveDataTriggerArgs args)
        {
            var cm = CacheManager.Get("InventoryMaintPolicy");

            var sysPolicyID = Toolkit.ToInt32(cm["sys_ID"], -1);

            if (sysPolicyID < 1)
            {
                var dt = args.ReadData("select inventory_maint_policy_id from inventory_maint_policy where maintenance_name = 'SYSTEM'");
                if (dt.Rows.Count == 0)
                {
                    var sysCoopID = getSystemCooperatorID(args);

                    // the "SYSTEM" maint policy does not exist.  create it.
                    sysPolicyID = args.WriteData(@"
insert into 
    inventory_maint_policy 
(maintenance_name, form_type_code, is_auto_deducted, distribution_default_form_code, created_date, created_by, owned_date, owned_by) 
    values 
('SYSTEM', '**', 'N', '**', :now1, :who1, :now2, :who2)
", true, "inventory_maint_policy_id", ":now1", DateTime.UtcNow, DbType.DateTime2, ":who1", sysCoopID, DbType.Int32, ":now2", DateTime.UtcNow, DbType.DateTime2, ":who2", sysCoopID, DbType.Int32);


                    // throw new InvalidOperationException("There is no record in the inventory_maint_policy table with maintenance_name = 'SYSTEM'.  This record is required by the GRIN-Global middle tier to function properly.");
                }
                else
                {
                    sysPolicyID = Toolkit.ToInt32(dt.Rows[0]["inventory_maint_policy_id"], -1);
                }
                cm["sys_ID"] = sysPolicyID;
            }

            return(sysPolicyID);
        }
Ejemplo n.º 8
0
        public override void TableRowSaving(ISaveDataTriggerArgs args)
        {
            if (args.SaveMode == SaveMode.Insert || args.SaveMode == SaveMode.Update)
            {
                var helper = args.Helper;

                // 1) on type ID-CHECK require cooperator link
                // GC check if cno is filled on an ID-CHECK
                if (helper.AllFieldsExist("annotation_type_code", "annotation_cooperator_id") && helper.GetValue("annotation_type_code", "", true).ToString().ToUpper() == "ID-CHECK" && helper.IsValueEmpty("annotation_cooperator_id"))
                {
                    args.Cancel("Cooperator must be supplied for ID-CHECK.");
                }

                // 2) Null out order number if type NOM-CHANGE
                if (helper.AllFieldsExist("annotation_type_code", "order_request_id") && helper.GetValue("annotation_type_code", "", true).ToString().ToUpper() == "NOM-CHANGE" && !helper.IsValueEmpty("order_request_id"))
                {
                    helper.SetValue("order_request_id", DBNull.Value, typeof(int), false);
                }

                // 3) set oldtaxno to current acc species name when type = 'Re-IDENT' and oldtaxno is null
                if (helper.AllFieldsExist("annotation_type_code", "old_taxonomy_species_id") && helper.GetValue("annotation_type_code", "", true).ToString().ToUpper() == "RE-IDENT" && helper.IsValueEmpty("old_taxonomy_species_id"))
                {
                    int ivid  = (int)helper.GetValue("inventory_id", 0, true);
                    var dtAcc = args.ReadData(@"SELECT taxonomy_species_id FROM accession a INNER JOIN inventory i ON a.accession_id = i.accession_id WHERE inventory_id = :ivid",
                                              ":ivid", ivid, DbType.Int32);
                    if (dtAcc.Rows.Count > 0)
                    {
                        helper.SetValueIfFieldExistsAndIsEmpty("old_taxonomy_species_id", dtAcc.Rows[0]["taxonomy_species_id"]);
                    }
                }

                //4) newtaxno must be a valid taxon on RE-IDENT action
                if (helper.AllFieldsExist("annotation_type_code", "new_taxonomy_species_id") &&
                    helper.GetValue("annotation_type_code", "", true).ToString().ToUpper() == "RE-IDENT" &&
                    !helper.IsValueEmpty("new_taxonomy_species_id"))
                {
                    int tsid  = (int)helper.GetValue("new_taxonomy_species_id", 0, true);
                    var dtTax = args.ReadData(@"SELECT current_taxonomy_species_id, synonym_code FROM taxonomy_species WHERE taxonomy_species_id = :tsid AND taxonomy_species_id = current_taxonomy_species_id",
                                              ":tsid", tsid, DbType.Int32);
                    if (dtTax.Rows.Count < 1)
                    {
                        args.Cancel("New taxonomy must be valid for RE-IDENT.");
                    }
                }

                // 5) on type ID-CHECK set oldtaxno to current acc taxon
                if (helper.AllFieldsExist("annotation_type_code", "old_taxonomy_species_id") &&
                    helper.GetValue("annotation_type_code", "", true).ToString().ToUpper() == "ID-CHECK")
                {
                    int ivid  = (int)helper.GetValue("inventory_id", 0, true);
                    var dtAcc = args.ReadData(@"SELECT taxonomy_species_id FROM accession a INNER JOIN inventory i ON a.accession_id = i.accession_id WHERE inventory_id = :ivid",
                                              ":ivid", ivid, DbType.Int32);
                    if (dtAcc.Rows.Count > 0)
                    {
                        helper.SetValueIfFieldExistsAndIsEmpty("old_taxonomy_species_id", dtAcc.Rows[0]["taxonomy_species_id"]);
                    }
                }
            }
        }
 public override void TableRowSaving(ISaveDataTriggerArgs args)
 {
     // maint policy function moved to additional data trigger
     //if (args.SaveMode == SaveMode.Insert)
     //{
     //fillMaintenancePolicyValues(args);
     //}
 }
Ejemplo n.º 10
0
 public override void TableRowSaved(ISaveDataTriggerArgs args)
 {
     // post-row save trigger
     if (args.SaveMode == SaveMode.Update && tsidChanged)
     {
         // 6) Create a RE-IDENT annotation_label row if species changed
         CreateAnnotation(args, args.NewPrimaryKeyID, oldtsid, newtsid, "RE-IDENT");
     }
 }
Ejemplo n.º 11
0
 public override void TableRowSaved(ISaveDataTriggerArgs args)
 {
     // post-row save trigger
     if (args.SaveMode == SaveMode.Insert && tsidChanged)
     {
         CreateAnnotation(args, args.NewPrimaryKeyID, oldtsid, newtsid, "RECEIVED");
         //} else if (args.SaveMode == SaveMode.Update && tsidChanged) {
         //    CreateAnnotation(args, args.NewPrimaryKeyID, oldtsid, newtsid, "RE-IDENT");
     }
 }
Ejemplo n.º 12
0
 public override void TableRowSaved(ISaveDataTriggerArgs args)
 {
     if (args.SaveMode == SaveMode.Insert || args.SaveMode == SaveMode.Update)
     {
         if (args.Helper.IsValueEmpty("percent_viable"))
         {
             args.WriteData("update inventory_viability set percent_viable = percent_dormant + percent_normal where inventory_viability_id = " + args.NewPrimaryKeyID);
         }
     }
 }
Ejemplo n.º 13
0
 public void DataViewSaved(ISaveDataTriggerArgs args, int successfulSaveCount, int failedSaveCount)
 {
     if (args.IsCancelled)
     {
         ((SaveDataTriggerArgs)args).DataManager.Rollback();
     }
     else
     {
         ((SaveDataTriggerArgs)args).DataManager.Commit();
     }
 }
        public override void TableRowSaving(ISaveDataTriggerArgs args)
        {
            if (args.SaveMode == SaveMode.Insert || args.SaveMode == SaveMode.Update)
            {
                var helper = args.Helper;

                // 2) require both lat and long if either
                if (helper.AllFieldsExist("latitude", "longitude"))
                {
                    //args.Cancel("both logitude and latitude exist");
                    if (!helper.IsValueEmpty("latitude") && helper.IsValueEmpty("longitude"))
                    {
                        args.Cancel("must have logitude if latitude entered");
                    }
                    if (helper.IsValueEmpty("latitude") && !helper.IsValueEmpty("longitude"))
                    {
                        args.Cancel("must have latitude if logitude entered");
                    }
                }

                if (helper.AllFieldsExist("geography_id") && !helper.IsValueEmpty("geography_id"))
                {
                    int gid   = (int)helper.GetValue("geography_id", 0, true);
                    var dtGeo = args.ReadData(@"SELECT current_geography_id, country_code FROM geography WHERE geography_id = :gid", ":gid", gid, DbType.Int32);
                    if (dtGeo.Rows.Count < 1)
                    {
                        args.Cancel("Geography could not be validated.");
                    }
                    else
                    {
                        int    currentid = (int)dtGeo.Rows[0]["current_geography_id"];
                        string iso3      = dtGeo.Rows[0]["country_code"].ToString();

                        // Use current geo
                        if (gid != currentid)
                        {
                            helper.SetValue("geography_id", currentid, typeof(int), false);
                            dtGeo = args.ReadData(@"SELECT current_geography_id, country_code FROM geography WHERE geography_id = :gid", ":gid", gid, DbType.Int32);
                            if (dtGeo.Rows.Count < 1)
                            {
                                args.Cancel("Current geography could not be validated.");
                            }
                        }

                        // 1) Only allow link to valid geo
                        int num;
                        if (int.TryParse(iso3, out num))
                        {
                            args.Cancel("Cannot use invalid geography with a numeric contry code");
                        }
                    }
                }
            }
        }
Ejemplo n.º 15
0
        public void TableSaved(ISaveDataTriggerArgs args, int successfulSaveCount, int failedSaveCount)
        {
            var name = args.Table.TableName.ToLower();

            if (name.StartsWith("sys_") || name == "app_resource")
            {
                // need to make sure the caches are cleared if data is saved these tables
                // note this temporarily slows things down because each new request coming in will
                // require a database hit, so be careful what tables you add here.
                CacheManager.ClearAll();
            }
        }
Ejemplo n.º 16
0
        public override void TableRowSaved(ISaveDataTriggerArgs args)
        {
            // post-row save trigger
            if (args.SaveMode == SaveMode.Insert || args.SaveMode == SaveMode.Update)
            {
                var helper = args.Helper;
                //    args.WriteData("update inventory_viability set percent_viable = percent_dormant + percent_normal where inventory_viability_id = " + args.NewPrimaryKeyID);
                //    note = helper.GetOriginalValue("web_availability_note", "").ToString();
                //    newNote = helper.GetValue("web_availability_note", "", true).ToString();
                if (noteChanged)
                {
                    var dtEmails = args.ReadData(@"select distinct wu.user_name, LTRIM(RTRIM(LTRIM(COALESCE(a.accession_number_part1, '') + ' ') + LTRIM(COALESCE(convert(varchar, a.accession_number_part2), '') + ' ') + COALESCE(a.accession_number_part3, ''))) AS PI_Number
                                    from inventory i, accession a, web_user wu, web_user_cart wuc, web_user_cart_item wuci 
                                    where i.accession_id = a.accession_id 
                                    and a.accession_id = wuci.accession_id
                                    and wuci.web_user_cart_id = wuc.web_user_cart_id
                                    and wuc.web_user_id = wu.web_user_id
                                    and wuc.cart_type_code = 'favorites'
                                    and i.accession_id =:accessionid", ":accessionid", helper.GetValue("accession_id", 0, true), DbType.Int32);

                    if (dtEmails.Rows.Count > 0)
                    {
                        string emailTo = "";
                        string pi      = dtEmails.Rows[0]["PI_Number"].ToString();

                        foreach (DataRow dr in dtEmails.Rows)
                        {
                            emailTo += dr["user_name"].ToString() + "; ";
                        }

                        StringBuilder sb = new StringBuilder();
                        //string CRLF = "\r\n";
                        sb.Append("Web availability changed for item ").Append(pi).Append(" in your favorites list."); // TODO: need more email text here

                        try
                        {
                            // hard code 'email from' as [email protected], need to use something to be configured
                            Email.Send(emailTo,
                                       "*****@*****.**",
                                       "",
                                       "",
                                       "GRIN-GLOBAL - Inventory Availabilty Change Notice",
                                       sb.ToString());
                        }
                        catch (Exception ex)
                        {
                            string s = ex.Message; // debug
                        }
                    }
                }
            }
        }
Ejemplo n.º 17
0
        public override void TableRowSaved(ISaveDataTriggerArgs args)
        {
            if (args.SaveMode == SaveMode.Insert)
            {
                var h = args.Helper;

                if (h.IsValueEmpty("current_taxonomy_genus_id"))
                {
                    // make current_taxonomy_genus_id field match the taxonomy_genus_id field
                    args.WriteData(@"update taxonomy_genus set current_taxonomy_genus_id = :id1 where taxonomy_genus_id = :id2", ":id1", args.NewPrimaryKeyID, DbType.Int32, ":id2", args.NewPrimaryKeyID, DbType.Int32);
                }
                // 6a   handle qual will only warn, row will still be saved

                /*"IF :NEW.qual IS NOT NULL THEN
                 * t_code := rtrim(:NEW.qual);
                 * main.verify_code('PROD','GN','QUAL','%',t_code);
                 * :NEW.qual := t_code;
                 * IF :NEW.validgno = :NEW.gno AND :NEW.qual <> '~' THEN
                 * raise_application_error (-20000,
                 * 'Only tilde (~) allowed for QUAL in accepted names.');
                 * END IF;
                 * ELSIF :NEW.validgno <> :NEW.gno THEN
                 * :NEW.qual := '=';
                 * END IF;
                 * "*/
                if (h.FieldExists("qualifying_code"))
                {
                    string qual     = h.GetValue("qualifying_code", "", true).ToString();
                    int    gno      = (int)h.GetValue("taxonomy_genus_id", 0, true);
                    int    validgno = (int)h.GetValue("current_taxonomy_genus_id", 0, true);
                    if (validgno == 0)
                    {
                        validgno = gno;
                    }

                    if (gno == validgno && !h.IsValueEmpty("qualifying_code"))
                    {
                        if (qual != "~")
                        {
                            args.Cancel("WARNING: only tilde (~) allowed for QUAL in accepted names. Redit the row and correct it.");
                            return;
                        }
                    }

                    // 6 b set qual to = if null and synonym
                    if (gno != validgno && h.IsValueEmpty("qualifying_code"))
                    {
                        args.WriteData(@"update taxonomy_genus set qualifying_code = '=' where taxonomy_genus_id = :id1", ":id1", args.NewPrimaryKeyID, DbType.Int32);
                    }
                }
            }
        }
Ejemplo n.º 18
0
        public void TableSaved(ISaveDataTriggerArgs args, int successfulSaveCount, int failedSaveCount)
        {
            if (args.SaveOptions.SkipSearchEngineUpdates)
            {
                // caller elects to skip search engine updates.  usually means an import is happening
                // and they will manually rebuild the indexes when they are done.
                return;
            }

            // if there were any that are still pending (i.e. count was smaller than the last grouping of rows)
            // we need to be sure to update them...
            updateSearchEngine(args);
        }
Ejemplo n.º 19
0
        public override void TableRowSaving(ISaveDataTriggerArgs args)
        {
            if (args.SaveMode == SaveMode.Insert || args.SaveMode == SaveMode.Update)
            {
                var helper = args.Helper;

                // 1) Make sure at least released date or pedigree itself entered
                if (helper.AllFieldsExist("description", "released_date") && helper.IsValueEmpty("description") && helper.IsValueEmpty("released_date"))
                {
                    args.Cancel("Incomplete accession_pedigree, must have either released_date or description.");
                }
            }
        }
Ejemplo n.º 20
0
 public override void TableRowSaving(ISaveDataTriggerArgs args)
 {
     if (args.SaveMode == SaveMode.Insert || args.SaveMode == SaveMode.Update)
     {
         // pre-row save trigger
         note    = args.Helper.GetOriginalValue("web_availability_note", "").ToString();
         newNote = args.Helper.GetValue("web_availability_note", "", true).ToString();
         if (note != newNote)
         {
             noteChanged = true;
         }
     }
 }
        public void DataViewRowSaving(ISaveDataTriggerArgs args)
        {
            string tableName = null;
            string pkValue   = null;

            if (args.Dataview.Tables != null && args.Dataview.Tables.Count > 0)
            {
                tableName = args.Dataview.PrimaryKeyTableName;
            }

            var args2 = args as SaveDataTriggerArgs;

            switch (args2.SaveMode)
            {
            case SaveMode.Update:
                if (!args2.SecureData.CanUpdate(args2.DataManager, args.RowToSave, args.RowInDatabase, args.Dataview))
                {
                    if (args.Dataview.PrimaryKeyNames != null && args.Dataview.PrimaryKeyNames.Count > 0 && args.Dataview.Tables.Count > 0)
                    {
                        pkValue = args.RowToSave[args.Dataview.PrimaryKeyNames[0]].ToString();
                    }
                    throw Library.DataPermissionException(args2.SecureData.SysUserName, tableName, Permission.Update, new string[] { pkValue });
                }
                break;

            case SaveMode.Delete:
                if (!args2.SecureData.CanDelete(args2.DataManager, args.RowToSave, args.RowInDatabase, args.Dataview))
                {
                    pkValue = args.RowToSave[args.Dataview.PrimaryKeyNames[0], DataRowVersion.Original].ToString();
                    throw Library.DataPermissionException(args2.SecureData.SysUserName, tableName, Permission.Delete, new string[] { pkValue });
                }
                break;

            case SaveMode.Insert:
                if (!args2.SecureData.CanCreate(args2.DataManager, args.RowToSave, args.RowInDatabase, args.Dataview))
                {
                    if (args.Dataview.PrimaryKeyNames != null && args.Dataview.PrimaryKeyNames.Count > 0 && args.Dataview.Tables.Count > 0)
                    {
                        pkValue = args.RowToSave[args.Dataview.PrimaryKeyNames[0]].ToString();
                    }
//                        pkValue = args.OriginalPrimaryKeyID.ToString();
                    throw Library.DataPermissionException(args2.SecureData.SysUserName, tableName, Permission.Create, new string[] { pkValue });
                }
                break;

            case SaveMode.Unknown:
            case SaveMode.None:
            default:
                break;
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Returns true if both field esist and aren't null and the first is before the second
        /// </summary>
        /// <param name="args"></param>
        /// <param name="firstDate"></param>
        /// <returns></returns>
        private bool DateIsBefore(ISaveDataTriggerArgs args, string firstDate, string secondDate)
        {
            var helper = args.Helper;

            if (helper.AllFieldsExist(firstDate, secondDate) && !helper.IsValueEmpty(firstDate) && !helper.IsValueEmpty(secondDate) &&
                Convert.ToDateTime(helper.GetValue(firstDate, null, true)) < Convert.ToDateTime(helper.GetValue(secondDate, null, true)))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public override void TableRowSaved(ISaveDataTriggerArgs args)
        {
            if (args.SaveMode == SaveMode.Insert)
            {
                var h = args.Helper;

                // make current_taxonomy_family_id field match the taxonomy_family_id field
                if (h.IsValueEmpty("current_taxonomy_family_id"))
                {
                    //           args.WriteData(@"update taxonomy_family set current_taxonomy_family_id = :id1 where taxonomy_family_id = :id2", ":id1", args.NewPrimaryKeyID, DbType.Int32, ":id2", args.NewPrimaryKeyID, DbType.Int32);
                    args.WriteData(@"update taxonomy_family set current_taxonomy_family_id = taxonomy_family_id where taxonomy_family_id = :id1", ":id1", args.NewPrimaryKeyID, DbType.Int32);
                }
            }
        }
Ejemplo n.º 24
0
        public override void TableRowSaving(ISaveDataTriggerArgs args)
        {
            if (args.SaveMode == SaveMode.Update)
            {
                var helper = args.Helper;

                oldtsid = (int)helper.GetOriginalValue("taxonomy_species_id", 0);
                newtsid = (int)helper.GetValue("taxonomy_species_id", 0, true);

                if (oldtsid != newtsid)
                {
                    tsidChanged = true;
                }
            }
        }
        public void TableRowSaving(ISaveDataTriggerArgs args)
        {
            // pre-row save trigger

            if (args.SaveMode == SaveMode.Insert || args.SaveMode == SaveMode.Update)
            {
                var helper = args.Helper;

                // 1) require units if quantity filled in
                if (helper.AllFieldsExist("quantity", "quantity_unit_code") && !helper.IsValueEmpty("quantity") && helper.IsValueEmpty("quantity_unit_code"))
                {
                    args.Cancel("must have quantity_unit_code if quantity entered");
                }
            }
        }
Ejemplo n.º 26
0
        public override void TableRowSaving(ISaveDataTriggerArgs args)
        {
            // pre-row save trigger
            if (args.SaveMode == SaveMode.Insert)
            {
                var helper = args.Helper;

                // check that the final recipient has a category code
                var dtCoop = args.ReadData(@"SELECT category_code FROM cooperator WHERE cooperator_id = :coopid AND category_code IS NOT NULL", ":coopid", helper.GetValue("final_recipient_cooperator_id", 0, true), DbType.Int32);
                if (dtCoop.Rows.Count < 1)
                {
                    args.Cancel("Final recipient cooperator must have a category");
                }
            }
        }
Ejemplo n.º 27
0
        public override void TableRowSaving(ISaveDataTriggerArgs args)
        {
            if (args.SaveMode == SaveMode.Insert || args.SaveMode == SaveMode.Update)
            {
                var helper = args.Helper;

                // 1) must have default dist quantity if autodeduct (debit set)
                if (helper.AllFieldsExist("is_auto_deducted", "distribution_default_quantity") &&
                    helper.GetValue("is_auto_deducted", "", true).ToString().ToUpper() == "Y" &&
                    helper.IsValueEmpty("distribution_default_quantity"))
                {
                    args.Cancel("must have distribution_default_quantity if is_auto_deducted");
                }

                // 2) must have default critical dist cutoff if autodeduct
                if (helper.AllFieldsExist("is_auto_deducted", "distribution_critical_quantity") &&
                    helper.GetValue("is_auto_deducted", "", true).ToString().ToUpper() == "Y" &&
                    helper.IsValueEmpty("distribution_critical_quantity"))
                {
                    args.Cancel("must have distribution_critical_quantity if is_auto_deducted");
                }
                // 3) if default form is null set it to form_type
                if (helper.AllFieldsExist("distribution_default_form_code", "form_type_code"))
                {
                    helper.SetValueIfFieldExistsAndIsEmpty("distribution_default_form_code", helper.GetValue("form_type_code", "", true).ToString());
                }

                // 4) must have default dist units if dist quant and vice versa
                if (helper.AllFieldsExist("distribution_default_quantity", "distribution_unit_code") && !helper.IsValueEmpty("distribution_default_quantity") && helper.IsValueEmpty("distribution_unit_code"))
                {
                    args.Cancel("Must have distribution_unit_code if distribution_default_quantity is not null.");
                }

                // 5) all quants >= 0
                if (helper.FieldExists("distribution_default_quantity") && Convert.ToDouble(helper.GetValue("distribution_default_quantity", 0.0, true)) < 0.0)
                {
                    args.Cancel("distribution_default_quantity must not be negative");
                }
                if (helper.FieldExists("distribution_critical_quantity") && Convert.ToDouble(helper.GetValue("distribution_critical_quantity", 0.0, true)) < 0.0)
                {
                    args.Cancel("distribution_critical_quantity must not be negative");
                }
                if (helper.FieldExists("regeneration_critical_quantity") && Convert.ToDouble(helper.GetValue("regeneration_critical_quantity", 0.0, true)) < 0.0)
                {
                    args.Cancel("regeneration_critical_quantity must not be negative");
                }
            }
        }
Ejemplo n.º 28
0
        public override void TableRowSaving(ISaveDataTriggerArgs args)
        {
            // pre-row save trigger
            if (args.SaveMode == SaveMode.Insert || args.SaveMode == SaveMode.Update)
            {
                var helper = args.Helper;

                // 4) if debit set (auto deduct) toggle LOW/AVAIL based on dist critical - N
                //
                //    IF :NEW.debit = 'Y' THEN
                //        IF (nvl(:NEW.onhand,0) <= nvl(:NEW.dcritical,0))
                //            AND (:NEW.status = 'AVAIL') THEN
                //            :NEW.status := 'LOW';
                //        ELSIF (nvl(:NEW.onhand,0) > nvl(:NEW.dcritical,0))
                //            AND (:NEW.status = 'LOW') THEN
                //            :NEW.status := 'AVAIL';
                //        END IF;
                //    END IF;

                if (helper.AllFieldsExist("is_auto_deducted", "quantity_on_hand", "distribution_critical_quantity") && helper.GetValue("is_auto_deducted", "N", true).ToString().ToUpper() == "Y")
                {
                    double onHand   = Convert.ToDouble(helper.GetValue("quantity_on_hand", 0.0, true));
                    double critical = Convert.ToDouble(helper.GetValue("distribution_critical_quantity", 0.0, true));
                    if (onHand <= critical)
                    {
                        if (helper.FieldExists("availability_status_code") && helper.GetValue("availability_status_code", "", true).ToString().ToUpper() == "AVAIL")
                        {
                            helper.SetValue("availability_status_code", "LOW", null, false);
                            if (helper.FieldExists("is_available") && helper.GetValue("is_available", "Y", true).ToString().ToUpper() == "Y")
                            {
                                helper.SetValue("is_available", "N", null, false);
                            }
                        }
                    }
                    else if (onHand > critical)
                    {
                        if (helper.FieldExists("availability_status_code") && helper.GetValue("availability_status_code", "", true).ToString().ToUpper() == "LOW")
                        {
                            helper.SetValue("availability_status_code", "AVAIL", null, false);
                            if (helper.FieldExists("is_available") && helper.GetValue("is_available", "N", true).ToString().ToUpper() == "N")
                            {
                                helper.SetValue("is_available", "Y", null, false);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 29
0
        public override void TableRowSaving(ISaveDataTriggerArgs args)
        {
            if (args.SaveMode == SaveMode.Insert || args.SaveMode == SaveMode.Update)
            {
                var helper = args.Helper;

                // 1) make sure expected date > established date

                /* if (helper.AllFieldsExist("expected_release_date", "established_date") && !helper.IsValueEmpty("expected_release_date") && !helper.IsValueEmpty("established_date")) {
                 *  DateTime expected = Convert.ToDateTime(helper.GetValue("expected_release_date", null, true));
                 *  DateTime established = Convert.ToDateTime(helper.GetValue("established_date", null, true));
                 *  if (expected < established) {
                 *      args.Cancel("Expected date must exceed or equal the date established.");
                 *  }
                 * }
                 */
                if (DateIsBefore(args, "expected_release_date", "established_date"))
                {
                    args.Cancel("Expected date must exceed or equal the date established.");
                }

                // 2) make sure expected date > entered date
                if (DateIsBefore(args, "expected_release_date", "entered_date"))
                {
                    args.Cancel("Expected date must exceed or equal the entered date.");
                }

                // 3) make sure released date > entered date
                if (DateIsBefore(args, "released_date", "entered_date"))
                {
                    args.Cancel("Released date must exceed or equal the entered date.");
                }

                // 4) make sure released date > established date
                if (DateIsBefore(args, "released_date", "established_date"))
                {
                    args.Cancel("Released date must exceed or equal the established date.");
                }

                // 5) make sure released date <= current date
                if (helper.FieldExists("released_date") && !helper.IsValueEmpty("released_date") &&
                    Convert.ToDateTime(helper.GetValue("released_date", null, true)) > DateTime.UtcNow)
                {
                    args.Cancel("released_date cannot exceed the current date.");
                }
            }
        }
Ejemplo n.º 30
0
        public void TableSaved(ISaveDataTriggerArgs args, int successfulSaveCount, int failedSaveCount)
        {
            switch (args.SaveMode)
            {
            case SaveMode.Delete:
                break;

            case SaveMode.Insert:
                break;

            case SaveMode.Update:
                break;

            default:
                throw new NotImplementedException(getDisplayMember("TestDataTrigger{TableSaved}", "SaveMode.{0} not implemented in Test.TableSaved()", args.SaveMode.ToString()));
            }
        }