Пример #1
0
        public void guardarDatosDeTabla()
        {
            Worksheet             activeSheet              = ((Worksheet)Globals.ThisAddIn.Application.Application.ActiveSheet);
            int                   row                      = 2;
            int                   col                      = 1;
            List <List <string> > listaDeDatosCrudosNew    = JsonConvert.DeserializeObject <List <List <string> > >(fe.ReadProperty("listaDeDatosCrudosNew", activeSheet.CustomProperties));
            List <List <string> > listaDeDatosActualizados = new List <List <string> >();
            List <string>         llavesPrimarias          = new List <string>();
            int                   endCol                   = Convert.ToInt32(fe.ReadProperty("endCol", activeSheet.CustomProperties));
            int                   index                    = Convert.ToInt32(fe.ReadProperty("idLlavePrimaria", activeSheet.CustomProperties));

            while (((Microsoft.Office.Interop.Excel.Range)activeSheet.Cells[row, col]).Value2 != null)
            {
                List <string> datos_act = new List <string>();

                for (int y = 1; y <= endCol; y++)
                {
                    var data_ = ((Microsoft.Office.Interop.Excel.Range)activeSheet.Cells[row, col]).Value2;
                    if (data_ is double)
                    {
                        data_ = ((double)((Microsoft.Office.Interop.Excel.Range)activeSheet.Cells[row, col]).Value2).ToString();
                    }

                    if (data_ == null)
                    {
                        datos_act.Add("");
                    }
                    else
                    {
                        datos_act.Add(data_);
                    }

                    if (index == y - 1)
                    {
                        llavesPrimarias.Add(data_);
                    }
                    col++;
                }
                row++;
                col = 1;
                listaDeDatosActualizados.Add(datos_act);
            }

            if (llavesPrimarias.Count.ToString() == llavesPrimarias.Distinct().Count().ToString())
            {
                revisarInformacion(listaDeDatosActualizados, listaDeDatosCrudosNew);
            }
            else
            {
                MessageBox.Show("No se puede actualizar por que hay llaves repetidas.");
            }
        }
Пример #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            //It is checked that a valid table is selected in the table combobox
            if (comboBox2.Text != "")
            {
                //A worksheet is created to show the data and assign the necessary variables
                Worksheet activeSheet = (Worksheet)Globals.ThisAddIn.Application.Worksheets.Add();
                //Set the name of the active sheet
                activeSheet.Name = comboBox2.Text;

                /*
                 *  It is validated if the variables were already created in the properties of the sheet
                 *  (this is done to be able to use the validations of changes when the excel is saved)
                 */
                if (fe.ReadProperty("conexionSeleccionada", activeSheet.CustomProperties) == null)
                {
                    //If the property is not created,it is established.
                    //In this case a custom property is established for the connection to the table
                    activeSheet.CustomProperties.Add("conexionSeleccionada", JsonConvert.SerializeObject(conexionSeleccionada));
                }
                iniciarDatos(comboBox2.Text);
                this.Close();
            }
            else
            {
                MessageBox.Show("You must select a table to show the data.");
            }
        }
Пример #3
0
        public void Application_WorkbookOpen(Workbook Doc)
        {
            Sheets sheets = Doc.Worksheets;

            connections         con = new connections();
            funcionesEspeciales fe  = new funcionesEspeciales();

            foreach (Worksheet sheet in sheets)
            {
                if (fe.ReadProperty("conexionSeleccionada", sheet.CustomProperties) != null)
                {
                    DocEvents_ChangeEventHandler EventDel_CellsChange = new DocEvents_ChangeEventHandler(con.WorksheetChangeEventHandler);
                    sheet.Change += EventDel_CellsChange;
                }
            }
        }