Exemplo n.º 1
0
        static private List <ItemTy> ReadScalarList <ItemTy>(SafeDataReader dr)
        {
            List <ItemTy> rval = new List <ItemTy>();

            //if (!typeof(ItemTy).IsPrimitive)
            //{
            //    throw new Exception(
            //        "Attempted to use scalar reader for non-scalar type!");
            //}

            while (dr.Read())
            {
                rval.Add((ItemTy)dr.GetValue(0));
            }

            return(rval);
        }
Exemplo n.º 2
0
        static private ItemTy ReadSingleScalar <ItemTy>(SafeDataReader dr)
        {
            ItemTy rval = default(ItemTy);

            if (!typeof(ItemTy).IsPrimitive)
            {
                throw new Exception(
                          "Attempted to use scalar reader for non-scalar type!");
            }

            if (dr.Read())
            {
                rval = (ItemTy)dr.GetValue(0);
            }

            return(rval);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Saves the object to persistant storage, using a given
        /// SQL connection and transaction.
        /// </summary>
        /// <param name="tr"></param>
        public void Save(SqlTransaction tr)
        {
            SafeDataReader dr = null;

            if (!IsDirty)
            {
                return;
            }

            List <BrokenRule> rulesBroken = GetBrokenRules();

            if (rulesBroken.Count > 0)
            {
                throw new BrokenRuleException(this, rulesBroken);
            }

            try
            {
                SqlCommand cmd = tr.Connection.CreateCommand();
                cmd.Transaction = tr;

                FillSaveCmd(cmd);

                dr = new SafeDataReader(cmd.ExecuteReader());
                if (dr.Read())
                {
                    PostSave(dr);
                }
            }
            finally
            {
                if ((dr != null) && !dr.IsClosed)
                {
                    dr.Close();
                }
            }

            SaveSubItems(tr);
            MarkClean();
            m_isNew = false;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the parameters for the named stored proc and fills
        /// the m_params list with the details of that parameter.
        /// </summary>
        private void LoadParameters()
        {
            SqlConnection cn = new SqlConnection(Helpers.CnnStr());
            IDataReader   dr = null;

            cn.Open();

            try
            {
                SqlCommand cmd = cn.CreateCommand();

                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "SELECT " +
                                  "PARAMETER_NAME AS name, " +
                                  "DATA_TYPE AS type, " +
                                  "CHARACTER_MAXIMUM_LENGTH AS max_length " +
                                  "FROM INFORMATION_SCHEMA.PARAMETERS " +
                                  "WHERE SPECIFIC_NAME = @name";

                cmd.Prepare();
                cmd.Parameters.AddWithValue("@name", Name);

                dr = new SafeDataReader(cmd.ExecuteReader());

                while (dr.Read())
                {
                    ProcSearchParam p = new ProcSearchParam(dr);
                    m_params.Add(p.Name, p);
                }
            }
            finally
            {
                if ((dr != null) && !dr.IsClosed)
                {
                    dr.Close();
                }

                cn.Close();
            }
        }
Exemplo n.º 5
0
        public static RobotList <OrgCustomField> GetOrgCustomFields(Organization org)
        {
            RobotList <OrgCustomField> rval = new RobotList <OrgCustomField>();
            SqlConnection  cn = new SqlConnection(Helpers.CnnStr());
            SafeDataReader dr = null;
            SqlTransaction tr;
            SqlCommand     cmd;

            cn.Open();
            tr = cn.BeginTransaction(IsolationLevel.ReadCommitted);
            try
            {
                cmd             = cn.CreateCommand();
                cmd.Transaction = tr;

                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "usp_GetOrgCustomFields";

                cmd.Parameters.AddWithValue("@org_id", org.Id);
                dr = new SafeDataReader(cmd.ExecuteReader());

                while (dr.Read())
                {
                    int defId = dr.GetInt32(dr.GetOrdinal("def_id"));

                    CustomFieldDef def =
                        CustomFieldDef.AllDefs.Find(CustomFieldDef.ById, defId);

                    if (def == null)
                    {
                        continue;
                    }

                    OrgCustomField cf = new OrgCustomField(def, org);

                    cf.DoLoad(dr);
                    rval.Add(cf);
                }

                dr.Close();
                tr.Commit();
            }
            catch
            {
                tr.Rollback();
                throw;
            }
            finally
            {
                if ((dr != null) && !dr.IsClosed)
                {
                    dr.Close();
                }

                cn.Close();
            }

            /*
             * Make sure all the currently defined custom field definitions
             * are listed.
             */
            foreach (CustomFieldDef def in CustomFieldDef.AllDefs)
            {
                OrgCustomField cf = rval.Find(
                    delegate(OrgCustomField obj, CustomFieldDef p)
                {
                    return(obj.Def == p);
                }, def);

                if (cf == null)
                {
                    cf = new OrgCustomField(def, org);
                    rval.Add(cf);
                }
            }

            return(rval);
        }