step to add new store procedure

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 年 前
what is the step to add a new procedure? does nopCommerce use any codegen?
13 年 前
Nevermind, look like 1.7 will use Entity Framwork. i'll wait for that

dealkk wrote:
what is the step to add a new procedure? does nopCommerce use any codegen?
13 年 前
1) I use my own class DatabaseUpgradeHelper. This class provide UpgradeDatabase() function:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NopSolutions.NopCommerce.BusinessLogic.Configuration;
using Server = System.Web.HttpServerUtility;


namespace NopSolutions.NopCommerce.Web.StoreIntegration
{
    public class DatabaseUpgradeHelper : NopSolutions.NopCommerce.Web.Install.InstallPage
    {
        private HttpContext httpContext;


        public DatabaseUpgradeHelper()
        {
        }

        public DatabaseUpgradeHelper(HttpContext context)
        {
            httpContext = context;
        }


        public String UpgradeDatabase()
        {
            string scriptsFolder = httpContext.Server.MapPath("~/StoreIntegration/Scripts");

            string upgradeFile = string.Format(@"{0}\{1}", scriptsFolder, "DatabaseUpgrade.sql");

            return proceedSQLScripts(upgradeFile, NopConfig.ConnectionString);
        }
    }
}


2) I call UpgradeDatabase() function in my web-service page (or other page):

        [WebMethod]
        public String ChangeDatabase()
        {
            return new DatabaseUpgradeHelper(HttpContext.Current).UpgradeDatabase();
        }


3)Create your own DatabaseUpgrade.sql script.
13 年 前
example of calling a stored procedure:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using NopSolutions.NopCommerce.BusinessLogic.Configuration;
using NopSolutions.NopCommerce.DataAccess;
using NopSolutions.NopCommerce.BusinessLogic.Products;
using System.Data;
using System.Data.Common;

namespace NopSolutions.NopCommerce.Web.Store
{
    public class MyClass
    {
        public static void MyProcedure()
        {
            Database db = new SqlDatabase(NopConfig.ConnectionString);

            DbCommand dbCommand = db.GetStoredProcCommand("Your_procedure_name");

            db.AddInParameter(dbCommand, "FirstParametr", DbType.Int32, 54321);
            db.AddInParameter(dbCommand, "SecondParametr", DbType.String, "12345");

            if (db.ExecuteNonQuery(dbCommand) > 0)
            {
                //success
            }

            //OR
            //using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            //{
                //if (dataReader.Read())
                //{
                    //Int32 i = NopSqlDataHelper.GetInt(dataReader, "qqqq");
                    //String str = NopSqlDataHelper.GetString(dataReader, "wwww");
                //}
            //}
        }
    }
}
13 年 前
I don't understand:

what is "DatabaseUpgrade.sql " and where is proceedSQLScripts(upgradeFile, NopConfig.ConnectionString);


I also need to add new column to the database table. how do i update dataacess/bussinesslogic
13 年 前
proceedSQLScripts: please see NopCommerceStore\Install\install.aspx.cs file.

DatabaseUpgrade.sql - file containing sql commands, for example:

--Nop_StoreIntegration_ProductsIdsConnector TABLE
IF NOT EXISTS
(
  SELECT 1
  FROM sysobjects
  WHERE id = OBJECT_ID(N'[dbo].[Nop_StoreIntegration_ProductsIdsConnector]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1
)
BEGIN
  CREATE TABLE [dbo].[Nop_StoreIntegration_ProductsIdsConnector]
  (
    [StoreId] [int] CONSTRAINT UQ_Nop_StoreIntegration_ProductsIdsConnector_StoreId UNIQUE NOT NULL,
    [OneCId] [nvarchar](16) CONSTRAINT UQ_Nop_StoreIntegration_ProductsIdsConnector_OneCId UNIQUE NOT NULL
  )
END
GO



--Nop_StoreIntegration_ProductsIdsConnector_Insert PROCEDURE
IF EXISTS
(
  SELECT *
  FROM dbo.sysobjects
  WHERE id = OBJECT_ID(N'[dbo].[Nop_StoreIntegration_ProductsIdsConnector_Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1
)
DROP PROCEDURE [dbo].[Nop_StoreIntegration_ProductsIdsConnector_Insert]
GO
CREATE PROCEDURE [dbo].[Nop_StoreIntegration_ProductsIdsConnector_Insert]
(
  @StoreId int,
  @OneCId nvarchar(16)
)
AS
BEGIN
  INSERT
  INTO [Nop_StoreIntegration_ProductsIdsConnector]
  (
    [StoreId],
    [OneCId]
  )
  VALUES
  (
    @StoreId,
    @OneCId
  )
END
GO


On my site file is located in the following location NopCommerceStore\StoreIntegration\Scripts. When I need to change the database structure I change DatabaseUpgrade.sql file over FTP and I remotely call the ChangeDatabase() web method from another my application.
This way I can remotely change the structure of the database which is located at the hosting.

I also need to add new column to the database table. how do i update dataacess/bussinesslogic
please see https://www.nopcommerce.com/boards/t/2654/new-product-fields.aspx

also use "Search Forums".
13 年 前
hi can you make website let me know can tell me how much thanks
13 年 前
Sorry. I develop a site just for the company in which I work.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.