using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Exferia_EntityFramework.Script_Actualizacion
{
    class Scripts_Version_1312
    {
        public static Version G_VRS_VERSION = new Version("1.3.1.2");
        public static long G_LNG_VERSION = 1312;
        public static int G_INT_TIPO = 0;
        public static string G_STR_SCRIPT =
                                     //BORRAR campo tipoVenta a la tabla MAE_Clientes
                                     "IF exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='tipoVenta' AND TABLE_NAME = 'MAE_Clientes' " +
                                      ") " +
                                    "BEGIN " +
                                        " ALTER TABLE MAE_Clientes DROP COLUMN [tipoVenta] " +
                                    "END " +
                                     //BORRAR campo facturaAduana a la tabla VTA_FacturasCabecera
                                     "IF exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='facturaAduana' AND TABLE_NAME = 'VTA_FacturasCabecera' " +
                                      ") " +
                                    "BEGIN " +
                                        " ALTER TABLE VTA_FacturasCabecera DROP COLUMN [facturaAduana] " +
                                    "END " +
                                     //BORRAR campo bienesInversion a la tabla VTA_FacturasCabecera
                                     "IF exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='bienesInversion' AND TABLE_NAME = 'VTA_FacturasCabecera' " +
                                      ") " +
                                    "BEGIN " +
                                        " ALTER TABLE VTA_FacturasCabecera DROP COLUMN [bienesInversion] " +
                                    "END " +
                                     //BORRAR campo gasto a la tabla VTA_FacturasCabecera
                                     "IF exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='gasto' AND TABLE_NAME = 'VTA_FacturasCabecera' " +
                                      ") " +
                                    "BEGIN " +
                                        " ALTER TABLE VTA_FacturasCabecera DROP COLUMN [gasto] " +
                                    "END " +
                                     //BORRAR campo clienteArrendamiento a la tabla VTA_FacturasCabecera
                                     "IF exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='clienteArrendamiento' AND TABLE_NAME = 'VTA_FacturasCabecera' " +
                                      ") " +
                                    "BEGIN " +
                                        " ALTER TABLE VTA_FacturasCabecera DROP COLUMN [clienteArrendamiento] " +
                                    "END " +
                                    //AÑADIR el campo criterioCaja a la tabla MAE_Clientes
                                    "IF not exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='criterioCaja' AND TABLE_NAME = 'MAE_Clientes' " +
                                      ") " +
                                    "BEGIN " +
                                        " ALTER TABLE [MAE_Clientes]ADD[criterioCaja] bit NULL " +
                                    "END " +
                                     //CAMBIAR NOMBRE DEL CAMPO noDeclararModelo190 a noDeclararModelosOficiales de la tabla VTA_FacturasCabecera
                                     "IF exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='noDeclararModelo190' AND TABLE_NAME = 'VTA_FacturasCabecera' " +
                                      ") " +
                                    "BEGIN " +
                                        "IF exists " +
                                        "( " +
                                        "    SELECT * " +
                                        "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                        "    WHERE COLUMN_NAME='noDeclararModelosOficiales' AND TABLE_NAME = 'VTA_FacturasCabecera' " +
                                        ") " +
                                            "BEGIN " +
                                                " ALTER TABLE VTA_FacturasCabecera DROP COLUMN [noDeclararModelo190] " +
                                            "END " +
                                        " ELSE " +
                                            "BEGIN " +
                                                " EXEC sp_RENAME 'VTA_FacturasCabecera.noDeclararModelo190', 'noDeclararModelosOficiales', 'COLUMN' " +
                                            "END " +
                                    "END " +
                                     //CAMBIAR NOMBRE DEL CAMPO noModelo347 a noDeclararModelosOficiales de la tabla MAE_Clientes
                                     "IF exists " +
                                      "( " +
                                      "    SELECT * " +
                                      "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                      "    WHERE COLUMN_NAME='noModelo347' AND TABLE_NAME = 'MAE_Clientes' " +
                                      ") " +
                                    "BEGIN " +
                                        "IF exists " +
                                        "( " +
                                        "    SELECT * " +
                                        "    FROM INFORMATION_SCHEMA.COLUMNS " +
                                        "    WHERE COLUMN_NAME='noDeclararModelosOficiales' AND TABLE_NAME = 'MAE_Clientes' " +
                                        ") " +
                                            "BEGIN " +
                                                " ALTER TABLE MAE_Clientes DROP COLUMN [noModelo347] " +
                                            "END " +
                                        " ELSE " +
                                            "BEGIN " +
                                                " EXEC sp_RENAME 'MAE_Clientes.noModelo347', 'noDeclararModelosOficiales', 'COLUMN' " +
                                            "END " +
                                    "END ";














    }
}
