Esempio n. 1
0
    public int InsCustomer(string CustomerName, int CustomerTypeID, out int NewRowID)
    {
        int RC = -1; //Used to trap the Stored Procedure's return code
        IParameterFactory objParams = new CustomersParameterFactory(CustomerName: CustomerName, CustomerTypeID: CustomerTypeID);
        string strSQLCode = @"Exec @RC = pInsCustomer " +
                        "  @CustomerName = '" + CustomerName + "'" + // Don't forget the SINGLE Quotes!!!
                        ", @CustomerTypeID = " + CustomerTypeID.ToString() + 
                        ", @NewRowID = @NewRowID Out;";
        try
        {
            this.Context.ObjectContext.ExecuteStoreCommand(strSQLCode
                                                        , objParams.Parmeters["RC"]
                                                        , objParams.Parmeters["CustomerName"]
                                                        , objParams.Parmeters["CustomerTypeID"]
                                                        , objParams.Parmeters["NewRowID"]
                                                        );
            //Get the new row ID created by the table's Identity feature
            if (objParams.Parmeters["NewRowID"].Value is DBNull) 
            { NewRowID = 0; } //if the insert has failed, then set this to an arbitrary number
            else { NewRowID = (int)objParams.Parmeters["NewRowID"].Value; } //else send it back as output

            //Trap or return the Stored Procedure's return code
            RC = (int)objParams.Parmeters["RC"].Value;
            if ( RC < 0)
            { throw new Exception("Error reported in Stored Procedure: " + objParams.Parmeters["RC"].Value.ToString()); }
        }
        catch (Exception)
        {
            throw;
        }
        return RC;
    }
Esempio n. 2
0
    public int InsCustomer(string CustomerName, int CustomerTypeID, out int NewRowID)
    {
        int RC; //Used to trap the Stored Procedure's return code
        IParameterFactory objParms = new CustomersParameterFactory(CustomerName: CustomerName, CustomerTypeID: CustomerTypeID);
        string strSQLCode = @"Exec @RC = pInsCustomer " +
                        "  @CustomerName = '" + CustomerName + "'" + // Don't forget the SINGLE Quotes!!!
                        ", @CustomerTypeID = " + CustomerTypeID.ToString() + 
                        ", @NewRowID = @NewRowID Out;";
        try
        {
            this.Context.ObjectContext.ExecuteStoreCommand(strSQLCode
                                                        , objParms.Parmeters["RC"]
                                                        , objParms.Parmeters["CustomerName"]
                                                        , objParms.Parmeters["CustomerTypeID"]
                                                        , objParms.Parmeters["NewRowID"]
                                                        );
            //Get the new row ID created by the table's Identity feature
            if (objParms.Parmeters["NewRowID"].Value is DBNull) 
            { NewRowID = 0; } //if the insert has failed, then set this to an arbitrary number
            else { NewRowID = (int)objParms.Parmeters["NewRowID"].Value; } //else send it back as output

            //Trap or return the Stored Procedure's return code
            RC = (int)objParms.Parmeters["RC"].Value;
            if ( RC < 0)
            { throw new Exception("Error reported in Stored Procedure: " + objParms.Parmeters["RC"].Value.ToString()); }
        }
        catch (Exception)
        {
            throw;
        }
        return (int)objParms.Parmeters["RC"].Value;
    }
Esempio n. 3
0
 public int UpdCustomer(int CustomerID, string CustomerName, int CustomerTypeID)
 {
     IParameterFactory objParms = new CustomersParameterFactory(CustomerName: CustomerName, CustomerTypeID: CustomerTypeID); 
     string strSQLCode = @"Exec @RC = pUpdCustomer " +
                     "  @CustomerID = " + CustomerID.ToString() +
                     ", @CustomerName = '" + CustomerName + "'" +  // Don't forget the SINGLE Quotes!!!
                     ", @CustomerTypeID = " + CustomerTypeID.ToString();
     try
     {
         this.Context.ObjectContext.ExecuteStoreCommand(strSQLCode
                                                     , objParms.Parmeters["RC"]
                                                     , objParms.Parmeters["CustomerID"]
                                                     , objParms.Parmeters["CustomerName"]
                                                     , objParms.Parmeters["CustomerTypeID"]
                                                     );
         //Trap or return the Stored Procedure's return code
         if ((int)objParms.Parmeters["RC"].Value < 0)
         { throw new Exception("Error reported in Stored Procedure: " + objParms.Parmeters["RC"].Value.ToString()); }
     }
     catch (Exception)
     {
         throw;
     }
     return (int)objParms.Parmeters["RC"].Value;
 }
Esempio n. 4
0
    public int DelCustomer(int CustomerID)
    {
        IParameterFactory objParms = new CustomersParameterFactory(CustomerID: CustomerID);
        string strSQLCode = @"Exec @RC = pDelCustomer @CustomerID = " + CustomerID.ToString() + ";";
        try
        {
            this.Context.ObjectContext.ExecuteStoreCommand(strSQLCode
                                                          , objParms.Parmeters["RC"]
                                                          , objParms.Parmeters["CustomerID"]);

            //Trap or return the Stored Procedure's return code
            if ((int)objParms.Parmeters["RC"].Value < 0)
            { throw new Exception("Error reported in Stored Procedure: " + objParms.Parmeters["RC"].Value.ToString()); }
        }
        catch (Exception)
        {
            throw;
        }
        return (int)objParms.Parmeters["RC"].Value;
    }
Esempio n. 5
0
    public IEnumerable<Customer> SelCustomer(int CustomerID = 0, string CustomerName = "", int CustomerTypeID = 0)
    {
        IParameterFactory objParms = new CustomersParameterFactory(CustomerID: CustomerID, CustomerName: CustomerName, CustomerTypeID: CustomerTypeID);
        string strSQLCode;
        List<Customer> objResults;
        if (CustomerID == 0)
        {
            strSQLCode = @"Exec @RC = pSelCustomer";
        }
        else
        {
            strSQLCode = @"Exec @RC = pSelCustomer " +
                            "  @CustomerID = " + CustomerID.ToString() +
                            ", @CustomerName = '" + CustomerName + "'" +  // Don't forget the SINGLE Quotes!!!
                            ", @CustomerTypeID = " + CustomerTypeID.ToString();
        }
        try
        {
            ObjectResult<Customer> objData = this.Context.ObjectContext.ExecuteStoreQuery<Customer>(strSQLCode
                                                        , objParms.Parmeters["RC"]
                                                        , objParms.Parmeters["CustomerID"]
                                                        , objParms.Parmeters["CustomerName"]
                                                        , objParms.Parmeters["CustomerTypeID"]
                                                        );
            if (objData != null)
            { objResults = objData.ToList<Customer>(); }
            else
            {
                objResults = new List<Customer>();
                objResults.Add(new Customer() { CustomerID = -0, CustomerName = "no rows found", CustomerTypeID = -1 });
            }

            if ((int)objParms.Parmeters["RC"].Value < 0)
            { throw new Exception("Error reported in Stored Procedure!"); }
        }
        catch (Exception)
        {
            throw;
        }
        return objResults;
    }
Esempio n. 6
0
    public IEnumerable<Customer> SelCustomer(int CustomerID = 0, string CustomerName = "", int CustomerTypeID = 0)
    {
        IParameterFactory objParams = new CustomersParameterFactory(CustomerID: CustomerID, CustomerName: CustomerName, CustomerTypeID: CustomerTypeID);
        string strSQLCode;
        List<Customer> objResults;
        if (CustomerID == 0)
        {
            strSQLCode = @"Exec @RC = pSelCustomer";
        }
        else
        {
            strSQLCode = @"Exec @RC = pSelCustomer " +
                            "  @CustomerID = " + CustomerID.ToString() +
                            ", @CustomerName = '" + CustomerName + "'" +  // Don't forget the SINGLE Quotes!!!
                            ", @CustomerTypeID = " + CustomerTypeID.ToString();
        }
        try
        {
            ObjectResult<Customer> objData = this.Context.ObjectContext.ExecuteStoreQuery<Customer>(strSQLCode
                                                        , objParams.Parmeters["RC"]
                                                        , objParams.Parmeters["CustomerID"]
                                                        , objParams.Parmeters["CustomerName"]
                                                        , objParams.Parmeters["CustomerTypeID"]
                                                        );
            if (objData != null)
            { objResults = objData.ToList<Customer>(); }
            else
            {
                objResults = new List<Customer>();
                objResults.Add(new Customer() { CustomerID = -0, CustomerName = "no rows found", CustomerTypeID = -1 });
            }

            if ((int)objParams.Parmeters["RC"].Value < 0)
            { throw new Exception("Error reported in Stored Procedure!"); }
        }
        catch (Exception)
        {
            throw;
        }
        return objResults;
    }
Esempio n. 7
0
    public int DelCustomer(int CustomerID)
    {
        int RC = -1; //Used to trap the Stored Procedure's return code
        IParameterFactory objParams = new CustomersParameterFactory(CustomerID: CustomerID);
        string strSQLCode = @"Exec @RC = pDelCustomer @CustomerID = " + CustomerID.ToString() + ";";
        try
        {
            this.Context.ObjectContext.ExecuteStoreCommand(strSQLCode
                                                          , objParams.Parmeters["RC"]
                                                          , objParams.Parmeters["CustomerID"]);

            //Trap or return the Stored Procedure's return code
            if ((int)objParams.Parmeters["RC"].Value < 0)
            { throw new Exception("Error reported in Stored Procedure: " + objParams.Parmeters["RC"].Value.ToString()); }
        }
        catch (Exception)
        {
            throw;
        }
        return RC;
    }
Esempio n. 8
0
 public int UpdCustomer(int CustomerID, string CustomerName, int CustomerTypeID)
 {
     int RC = -1; //Used to trap the Stored Procedure's return code
     IParameterFactory objParams = new CustomersParameterFactory(CustomerName: CustomerName, CustomerTypeID: CustomerTypeID); 
     string strSQLCode = @"Exec @RC = pUpdCustomer " +
                     "  @CustomerID = " + CustomerID.ToString() +
                     ", @CustomerName = '" + CustomerName + "'" +  // Don't forget the SINGLE Quotes!!!
                     ", @CustomerTypeID = " + CustomerTypeID.ToString();
     try
     {
         this.Context.ObjectContext.ExecuteStoreCommand(strSQLCode
                                                     , objParams.Parmeters["RC"]
                                                     , objParams.Parmeters["CustomerID"]
                                                     , objParams.Parmeters["CustomerName"]
                                                     , objParams.Parmeters["CustomerTypeID"]
                                                     );
         //Trap or return the Stored Procedure's return code
         if ((int)objParams.Parmeters["RC"].Value < 0)
         { throw new Exception("Error reported in Stored Procedure: " + objParams.Parmeters["RC"].Value.ToString()); }
     }
     catch (Exception)
     {
         throw;
     }
     return RC;
 }