Exemplo n.º 1
0
        public bool Insert()
        {
            bool Successful = false;

            using (new Impersonator()) {
                SqlConnection conn = DataSource.Conn();
                try {
                    DateTime   timeStamp = DateTime.UtcNow;
                    string     sql       = @"Insert INTO dbo.TrngModules 
										(Name
										,Description
										,Directory
										,URL
										,AdminURL
										,ImageURL
										,DBVersion
										,DisplayIndex
										,IsActive
										,CreatedBy
										,CreatedOn
										,ModifiedBy
										,ModifiedOn)
							Values
										(@Name
										,@Description
										,@Directory
										,@URL
										,@AdminURL
										,@ImageURL
										,@DBVersion
										,@DisplayIndex
										,@IsActive
										,@CreatedBy
										,@CreatedOn
										,@ModifiedBy
										,@ModifiedOn)
							SELECT @ID = SCOPE_IDENTITY()"                            ;
                    SqlCommand cmd       = new SqlCommand(sql, conn);
                    cmd.Parameters.AddWithValue("@Name", _Name);
                    cmd.Parameters.AddWithValue("@Description", _Description);
                    cmd.Parameters.AddWithValue("@Directory", _Directory);
                    cmd.Parameters.AddWithValue("@URL", _URL);
                    cmd.Parameters.AddWithValue("@AdminURL", _AdminURL);
                    cmd.Parameters.AddWithValue("@ImageURL", _ImageURL);
                    cmd.Parameters.AddWithValue("@DBVersion", _DBVersion);
                    cmd.Parameters.AddWithValue("@DisplayIndex", _DisplayIndex);
                    cmd.Parameters.AddWithValue("@IsActive", _IsActive);
                    cmd.Parameters.AddWithValue("@CreatedBy", _CreatedBy);
                    cmd.Parameters.AddWithValue("@CreatedOn", _CreatedOn);
                    cmd.Parameters.AddWithValue("@ModifiedBy", _ModifiedBy);
                    cmd.Parameters.AddWithValue("@ModifiedOn", _ModifiedOn);
                    SqlParameter prmID = cmd.Parameters.Add("@ID", SqlDbType.Int);
                    prmID.Direction = ParameterDirection.Output;
                    if (conn.State != ConnectionState.Open)
                    {
                        conn.Open();
                    }
                    cmd.ExecuteNonQuery();
                    _ID        = int.Parse(prmID.Value.ToString());
                    Successful = true;
                } catch (SqlException sqlex) {
                    Error.WriteError(sqlex);
                    _ErrorMessage = sqlex.Message;
                } catch (Exception ex) {
                    Error.WriteError(ex);
                    _ErrorMessage = ex.Message;
                } finally {
                    if (conn.State != ConnectionState.Closed)
                    {
                        conn.Close();
                    }
                }
            }
            return(Successful);
        }
Exemplo n.º 2
0
        public bool Insert()
        {
            bool Successful = false;

            using (new Impersonator()) {
                SqlConnection conn = DataSource.Conn();
                try {
                    DateTime   TimeStamp = DateTime.UtcNow;
                    string     sql       = @"INSERT INTO dbo.TrngSets 
			                                (Name,
										Description,
										OrgGroupID,
										IsDefault,
										CreatedBy,
										CreatedOn,
										ModifiedBy,
										ModifiedOn)
			                            VALUES
			                                (@Name,
										@Description,
										@OrgGroupID,
										@IsDefault,
										@CreatedBy,
										@CreatedOn,
										@ModifiedBy,
										@ModifiedOn)
			                            SELECT @ID = SCOPE_IDENTITY()"            ;
                    SqlCommand cmd       = new SqlCommand(sql, conn);
                    cmd.Parameters.AddWithValue("@Name", _Name);
                    cmd.Parameters.AddWithValue("@Description", _Description);
                    cmd.Parameters.AddWithValue("@OrgGroupID", _OrgGroupID);
                    cmd.Parameters.AddWithValue("@IsDefault", _IsDefault);
                    cmd.Parameters.AddWithValue("@CreatedBy", _CreatedBy);
                    cmd.Parameters.AddWithValue("@CreatedOn", TimeStamp);
                    cmd.Parameters.AddWithValue("@ModifiedBy", _ModifiedBy);
                    cmd.Parameters.AddWithValue("@ModifiedOn", TimeStamp);
                    SqlParameter prmID = cmd.Parameters.Add("@ID", SqlDbType.Int);
                    prmID.Direction = ParameterDirection.Output;
                    if (conn.State != ConnectionState.Open)
                    {
                        conn.Open();
                    }
                    cmd.ExecuteNonQuery();
                    _ID         = int.Parse(prmID.Value.ToString());
                    _CreatedOn  = TimeStamp;
                    _ModifiedOn = TimeStamp;
                    Successful  = true;
                } catch (SqlException sqlex) {
                    Error.WriteError(sqlex);
                    _ErrorMessage = sqlex.Message;
                } catch (Exception ex) {
                    Error.WriteError(ex);
                    _ErrorMessage = ex.Message;
                } finally {
                    if (conn.State != ConnectionState.Closed)
                    {
                        conn.Close();
                    }
                }
            }
            return(Successful);
        }