예제 #1
0
        protected void GenerarArchivo(oPlantilla _Template, string _DestinationPath, string _Tipo)
        {
            string _Path = Configuration.Path;
            // el nombre de una Key debe incluir un root valido.
            const string userRoot = "HKEY_CURRENT_USER";
            const string subkey   = "Software\\Microsoft\\Office\\Excel\\Addins\\SAT.Dictamenes.SIPRED.Client";
            const string keyName  = userRoot + "\\" + subkey;

            object addInName = "SAT.Dictamenes.SIPRED.Client";

            File.Copy($"{_Path}\\templates\\{_Template.Nombre}", _DestinationPath);

            Registry.SetValue(keyName, "LoadBehavior", 0);
            Globals.ThisAddIn.Application.COMAddIns.Item(ref addInName).Connect = false;
            Globals.ThisAddIn.Application.Visible = true;
            try
            {
                Globals.ThisAddIn.Application.Workbooks.Open(_DestinationPath);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error al abrir el archivo [{_DestinationPath}]: {ex.Message.ToString()}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Libro Actual de Excel.
            Excel.Worksheet xlSht;
            Excel.Workbook  wb    = Globals.ThisAddIn.Application.ActiveWorkbook;
            int             count = wb.Worksheets.Count;

            xlSht      = (Excel.Worksheet)wb.Worksheets.Add(Type.Missing, wb.Worksheets[count], Type.Missing, Type.Missing);
            xlSht.Name = "SIPRED";
            wb.Save();

            this.TopMost = false;
            this.Enabled = false;
            this.Hide();
            FormulasComprobaciones _Formulas = new FormulasComprobaciones();

            _Formulas._Form     = this;
            _Formulas._Template = _Template;
            _Formulas._Tipo     = _Tipo;
            _Formulas._formulas = true;
            _Formulas._Open     = false;
            _Formulas.ShowDialog();
        }
예제 #2
0
        private void btnTransferir_Click(object sender, RibbonControlEventArgs e)
        {
            if (_Connection)
            {
                string _Path = "";

                const string userRoot  = "HKEY_CURRENT_USER";
                const string subkey    = "Software\\Microsoft\\Office\\Excel\\Addins\\SAT.Dictamenes.SIPRED.Client";
                const string keyName   = userRoot + "\\" + subkey;
                object       addInName = "SAT.Dictamenes.SIPRED.Client";

                Registry.SetValue(keyName, "LoadBehavior", 0);
                Globals.ThisAddIn.Application.COMAddIns.Item(ref addInName).Connect = false;
                Globals.ThisAddIn.Application.Visible = true;
                Excel.Workbook wb = Globals.ThisAddIn.Application.ActiveWorkbook;

                if (wb == null)
                {
                    MessageBox.Show("Archivo no válido, favor de generar el archivo mediante el AddIn D.SAT", "Información Incorrecta", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                try
                {
                    _Path = Globals.ThisAddIn.Application.ActiveWorkbook.FullName;
                }
                catch (Exception ex) { }

                //wb.Close();

                FileInfo _Excel = new FileInfo(_Path == null || _Path == "" ? "C:\\ArchivoNoValido.xlsx" : _Path);

                if (_Excel.Extension != ".xlsm")
                {
                    MessageBox.Show("Archivo no válido, favor de generar el archivo mediante el AddIn D.SAT", "Información Incorrecta", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                //try
                //{
                //    Globals.ThisAddIn.Application.Workbooks.Open(_Path);
                //}
                //catch (Exception ex)
                //{ }

                //Libro Actual de Excel.
                Excel.Worksheet xlSht;
                wb = Globals.ThisAddIn.Application.ActiveWorkbook;
                int  count    = wb.Worksheets.Count;
                bool _existeS = false;

                for (int _wCount = 1; _wCount <= count; _wCount++)
                {
                    string _sName = wb.Worksheets[_wCount].Name;

                    if (_sName == "SIPRED")
                    {
                        _existeS = true;
                    }
                }

                if (!_existeS)
                {
                    xlSht      = (Excel.Worksheet)wb.Worksheets.Add(Type.Missing, wb.Worksheets[count], Type.Missing, Type.Missing);
                    xlSht.Name = "SIPRED";
                }
                wb.Save();

                //btnOpen_Click(sender, e);
                btnSave.Visible = false;
                FormulasComprobaciones form = new FormulasComprobaciones();
                form._formulas = false;
                form._Open     = false;
                form.TopMost   = false;
                form.ShowDialog();
            }
            else
            {
                MessageBox.Show(_Message, _Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #3
0
        private void btnGenerar_Click(object sender, EventArgs e)
        {
            List <string> _Messages = new List <string>();

            bool _Key        = true;
            bool _Connection = new lSerializados().CheckConnection(Configuration.UrlConnection);

            this.pgbFile.Visible = true;
            int progress = 0;

            progress += 10;

            if (!_Connection)
            {
                for (int x = 10; x <= 100; x++)
                {
                    pgbFile.Value        = 100 - x;
                    this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "%";
                    System.Threading.Thread.Sleep(1500);
                    x += 10;
                }
                MessageBox.Show("No existe conexión con el servidor de datos... Contacte a un Administrador de Red para ver las opciones de conexión.", "Conexión de Red", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
            else
            {
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "% [Obtener Tipos de Plantillas]"));
                //System.Threading.Thread.Sleep(100);
                KeyValuePair <bool, string[]> _TiposPlantillas = new lSerializados().ObtenerTiposPlantillas();
                progress     += 10;
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "% [Obtener Cruces]"));
                //System.Threading.Thread.Sleep(1000);
                KeyValuePair <bool, string[]> _Cruces = new lSerializados().ObtenerCruces();
                progress     += 20;
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "% [Obtener Plantillas]"));
                //System.Threading.Thread.Sleep(1000);
                KeyValuePair <bool, string[]> _Plantillas = new lSerializados().ObtenerPlantillas();
                progress     += 10;
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "% [Obtener Comprobaciones]"));
                //System.Threading.Thread.Sleep(1000);
                KeyValuePair <bool, string[]> _Comprobaciones = new lSerializados().ObtenerComprobaciones();
                progress     += 20;
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "% [Obtener Validación Cruces]"));
                //System.Threading.Thread.Sleep(1000);
                KeyValuePair <bool, string[]> _Validaciones = new lSerializados().ObtenerValidacionCruces();
                progress     += 10;
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "% [Obtener Indices]"));
                //System.Threading.Thread.Sleep(1000);
                KeyValuePair <bool, string[]> _Indices = new lSerializados().ObtenerIndices();
                progress     += 10;
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "%"));
                //System.Threading.Thread.Sleep(1000);
                KeyValuePair <bool, string[]> _Masiva = new lSerializados().ObtenerConversionMasiva();
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "%"));
                //System.Threading.Thread.Sleep(1000);

                _Key = (!_TiposPlantillas.Key || !_Cruces.Key || !_Plantillas.Key || !_Comprobaciones.Key || !_Validaciones.Key || !_Indices.Key || !_Masiva.Key);
                _Messages.AddRange(_TiposPlantillas.Value);
                _Messages.AddRange(_Cruces.Value);
                _Messages.AddRange(_Plantillas.Value);
                _Messages.AddRange(_Comprobaciones.Value);
                _Messages.AddRange(_Validaciones.Value);
                _Messages.AddRange(_Indices.Value);
                _Messages.AddRange(_Masiva.Value);
                progress     += 10;
                pgbFile.Value = progress;
                Invoke(new System.Action(() => this.gbProgress.Text = "Progreso " + this.pgbFile.Value + "% [Proceso Finalizado]"));
                //System.Threading.Thread.Sleep(1000);

                string _Message = "Los Archivos fueron creados con éxito. Vuelva a cargar la pantalla de [" + _window + "]. ";
                if (_Update)
                {
                    _Message = "Los Archivos fueron actualizados con éxito. Vuelva a cargar la pantalla de [" + _window + "]. ";
                }
                if (_Process)
                {
                    _Message = "Los Archivos fueron creados con éxito. Click en el botón de Ok para continuar con el proceso.";

                    if (_Update)
                    {
                        _Message = "Los Archivos fueron actualizados con éxito. Click en el botón de Ok para continuar con el proceso.";
                    }
                    if (_Automatic)
                    {
                        _Message = "El Archivo de Comprobaciones fue actualizado con éxito. Click en el botón de Ok para continuar con el proceso.";
                    }
                }

                KeyValuePair <bool, System.Data.DataTable> _TipoPlantilla = new lSerializados().ObtenerUpdate();
                String _Path = Configuration.Path;

                foreach (DataRow _Row in _TipoPlantilla.Value.Rows)
                {
                    string _IdTipoPlantilla    = _Row["IdTipoPlantilla"].ToString();
                    string _Fecha_Modificacion = _Row["Fecha_Modificacion"].ToString();

                    if (File.Exists(_Path + "\\jsons\\Update" + _IdTipoPlantilla + ".txt"))
                    {
                        File.Delete(_Path + "\\jsons\\Update" + _IdTipoPlantilla + ".txt");
                    }
                    StreamWriter sw = new StreamWriter(_Path + "\\Jsons\\Update" + _IdTipoPlantilla + ".txt");
                    sw.WriteLine(_Fecha_Modificacion);
                    sw.Close();
                }

                if (_Automatic)
                {
                    this.Hide();
                }

                MessageBox.Show(_Message, "Archivos Base", MessageBoxButtons.OK, MessageBoxIcon.Information);

                if (_Automatic)
                {
                    this.TopMost = false;
                    this.Enabled = false;
                    //this.Hide();
                    FormulasComprobaciones _Formulas = new FormulasComprobaciones();
                    _Formulas._Form     = this;
                    _Formulas._Template = _Template;
                    _Formulas._Tipo     = _Tipo;
                    _Formulas._formulas = true;
                    _Formulas._Open     = false;
                    _Formulas.Show();
                }

                if (!_Process)
                {
                    _Form.Close();
                }
                this.Close();
            }
        }